blob: 2630553087f86ebd7cf8796f02a73f370877a932 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060037#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060038#include "vkrenderframework.h"
39#include <limits.h>
40#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060041
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042#define GLM_FORCE_RADIANS
43#include "glm/glm.hpp"
44#include <glm/gtc/matrix_transform.hpp>
45
Dustin Gravesffa90fa2016-05-06 11:20:38 -060046#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060047#define MEM_TRACKER_TESTS 1
48#define OBJ_TRACKER_TESTS 1
49#define DRAW_STATE_TESTS 1
50#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120051#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060052#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060053#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060054
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055//--------------------------------------------------------------------------------------
56// Mesh and VertexFormat Data
57//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070058struct Vertex {
59 float posX, posY, posZ, posW; // Position data
60 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061};
62
Karl Schultz6addd812016-02-02 17:17:23 -070063#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050064
65typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070066 BsoFailNone = 0x00000000,
67 BsoFailLineWidth = 0x00000001,
68 BsoFailDepthBias = 0x00000002,
69 BsoFailViewport = 0x00000004,
70 BsoFailScissor = 0x00000008,
71 BsoFailBlend = 0x00000010,
72 BsoFailDepthBounds = 0x00000020,
73 BsoFailStencilReadMask = 0x00000040,
74 BsoFailStencilWriteMask = 0x00000080,
75 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060076 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060077 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050085};
86
Mark Lobodzinskice751c62016-09-08 10:45:35 -060087static const char bindStateVertShaderText[] = "#version 450\n"
88 "vec2 vertices[3];\n"
89 "out gl_PerVertex {\n"
90 " vec4 gl_Position;\n"
91 "};\n"
92 "void main() {\n"
93 " vertices[0] = vec2(-1.0, -1.0);\n"
94 " vertices[1] = vec2( 1.0, -1.0);\n"
95 " vertices[2] = vec2( 0.0, 1.0);\n"
96 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
97 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060099static const char bindStateFragShaderText[] = "#version 450\n"
100 "\n"
101 "layout(location = 0) out vec4 uFragColor;\n"
102 "void main(){\n"
103 " uFragColor = vec4(0,1,0,1);\n"
104 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500105
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600106static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
107 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
108 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600109
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600110// ErrorMonitor Usage:
111//
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600112// Call SetDesiredFailureMsg with: a string to be compared against all
113// encountered log messages, or a validation error enum identifying
114// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
115// will match all log messages. logMsg will return true for skipCall
116// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117//
118// Call DesiredMsgFound to determine if the desired failure message
119// was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600120class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700121 public:
122 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600123 test_platform_thread_create_mutex(&m_mutex);
124 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200125 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700126 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600127 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600128 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129
Dustin Graves48458142016-04-29 16:11:55 -0600130 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
131
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600132 // ErrorMonitor will look for an error message containing the specified string
Karl Schultz6addd812016-02-02 17:17:23 -0700133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600134 // Also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600136 m_failure_message_strings.clear();
137 // If we are looking for a matching string, ignore any IDs
138 m_desired_message_ids.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600139 m_otherMsgs.clear();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600140 m_desired_message_strings.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700141 m_msgFound = VK_FALSE;
142 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600143 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600144 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600145
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600146 // ErrorMonitor will look for a message ID matching the specified one
147 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
148 // Also discard all collected messages to this point
149 test_platform_thread_lock_mutex(&m_mutex);
150 m_failure_message_strings.clear();
151 // If we are looking for IDs don't look for strings
152 m_desired_message_strings.clear();
153 m_otherMsgs.clear();
154 m_desired_message_ids.insert(msg_id);
155 m_msgFound = VK_FALSE;
156 m_msgFlags = msgFlags;
157 test_platform_thread_unlock_mutex(&m_mutex);
158 }
159
160 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600162 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600163 if (m_bailout != NULL) {
164 *m_bailout = true;
165 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600167 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600168
169 for (auto desired_msg : m_desired_message_strings) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600170 if (desired_msg.length() == 0) {
171 // An empty desired_msg string "" indicates a positive test - not expecting an error.
172 // Return true to avoid calling layers/driver with this error.
173 // And don't erase the "" string, so it remains if another error is found.
174 result = VK_TRUE;
175 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600176 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600177 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600178 m_msgFound = VK_TRUE;
179 result = VK_TRUE;
180 // We only want one match for each expected error so remove from set here
181 // Since we're about the break the loop it's ok to remove from set we're iterating over
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600182 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600183 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186 for (auto desired_id : m_desired_message_ids) {
187 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
188 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
189 // Return true to avoid calling layers/driver with this error.
190 result = VK_TRUE;
191 } else if (desired_id == message_code) {
192 // Double-check that the string matches the error enum
193 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
194 found_expected = true;
195 result = VK_TRUE;
196 m_msgFound = VK_TRUE;
197 m_desired_message_ids.erase(desired_id);
198 break;
199 } else {
200 // Treat this message as a regular unexpected error, but print a warning jic
201 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
202 errorString.c_str(), desired_id, validation_error_map[desired_id]);
203 }
204 }
205 }
206
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600207 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200208 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600209 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600210 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600211 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600212 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600213 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600214
Karl Schultz6addd812016-02-02 17:17:23 -0700215 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600216
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600217 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
218
Karl Schultz6addd812016-02-02 17:17:23 -0700219 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600220
Karl Schultz6addd812016-02-02 17:17:23 -0700221 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600222
Karl Schultz6addd812016-02-02 17:17:23 -0700223 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600224 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600225 if (otherMsgs.size()) {
226 cout << "Other error messages logged for this test were:" << endl;
227 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
228 cout << " " << *iter << endl;
229 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600230 }
231 }
232
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600233 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200234
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600235 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
236 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
237 m_msgFlags = message_flag_mask;
238 // Match ANY message matching specified type
239 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200240 }
241
242 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600243 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200244 if (!DesiredMsgFound()) {
245 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600246 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600247 FAIL() << "Did not receive expected error '" << desired_msg << "'";
248 }
Tony Barbour59b42282016-11-03 13:31:28 -0600249 for (auto desired_id : m_desired_message_ids) {
250 FAIL() << "Did not receive expected error '" << desired_id << "'";
251 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200252 }
253 }
254
255 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600256 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200257 if (DesiredMsgFound()) {
258 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600259 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600260 FAIL() << "Expected to succeed but got error: " << msg;
261 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262 }
263 }
264
Karl Schultz6addd812016-02-02 17:17:23 -0700265 private:
266 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600267 std::unordered_set<uint32_t>m_desired_message_ids;
268 std::unordered_set<string> m_desired_message_strings;
269 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700270 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600271 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700272 bool *m_bailout;
273 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600274};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500275
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600276static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
277 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
278 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600279 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
280 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600281 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600282 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600283 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600284}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500285
Karl Schultz6addd812016-02-02 17:17:23 -0700286class VkLayerTest : public VkRenderFramework {
287 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800288 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
289 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600290 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
291 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700292 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
294 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700295 }
Tony Barbour300a6082015-04-07 13:44:53 -0600296
Tony Barbourfe3351b2015-07-28 10:17:20 -0600297 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600298 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800299 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600300 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
301 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700302 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700304 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600305 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700306 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600307 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
308 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
309 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700310 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
311 }
312 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
313 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
314 }
315
316 protected:
317 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600318 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600319
320 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600321 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600322 std::vector<const char *> instance_extension_names;
323 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600324
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700325 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600326 /*
327 * Since CreateDbgMsgCallback is an instance level extension call
328 * any extension / layer that utilizes that feature also needs
329 * to be enabled at create instance time.
330 */
Karl Schultz6addd812016-02-02 17:17:23 -0700331 // Use Threading layer first to protect others from
332 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700333 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600334 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800335 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700336 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800337 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600338 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700339 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600340
Ian Elliott2c1daf52016-05-12 09:41:46 -0600341 if (m_enableWSI) {
342 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
343 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
344#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
345#if defined(VK_USE_PLATFORM_ANDROID_KHR)
346 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
347#endif // VK_USE_PLATFORM_ANDROID_KHR
348#if defined(VK_USE_PLATFORM_MIR_KHR)
349 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_MIR_KHR
351#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
352 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
353#endif // VK_USE_PLATFORM_WAYLAND_KHR
354#if defined(VK_USE_PLATFORM_WIN32_KHR)
355 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_WIN32_KHR
357#endif // NEED_TO_TEST_THIS_ON_PLATFORM
358#if defined(VK_USE_PLATFORM_XCB_KHR)
359 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
360#elif defined(VK_USE_PLATFORM_XLIB_KHR)
361 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
362#endif // VK_USE_PLATFORM_XLIB_KHR
363 }
364
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600365 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600366 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800367 this->app_info.pApplicationName = "layer_tests";
368 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600369 this->app_info.pEngineName = "unittest";
370 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600371 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600372
Tony Barbour15524c32015-04-29 17:34:29 -0600373 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600374 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600375 }
376
377 virtual void TearDown() {
378 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600379 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600380 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600381 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600382
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600383 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600384};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500385
Karl Schultz6addd812016-02-02 17:17:23 -0700386VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600387 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600388
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800389 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600390
391 /*
392 * For render test all drawing happens in a single render pass
393 * on a single command buffer.
394 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200395 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800396 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600397 }
398
399 return result;
400}
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600403 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600404
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200405 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800406 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200407 }
Tony Barbour300a6082015-04-07 13:44:53 -0600408
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600410
411 return result;
412}
413
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600414void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500415 // Create identity matrix
416 int i;
417 struct vktriangle_vs_uniform data;
418
419 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700420 glm::mat4 View = glm::mat4(1.0f);
421 glm::mat4 Model = glm::mat4(1.0f);
422 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700424 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425
426 memcpy(&data.mvp, &MVP[0][0], matrixSize);
427
Karl Schultz6addd812016-02-02 17:17:23 -0700428 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600429 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500430 };
431
Karl Schultz6addd812016-02-02 17:17:23 -0700432 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 data.position[i][0] = tri_data[i].posX;
434 data.position[i][1] = tri_data[i].posY;
435 data.position[i][2] = tri_data[i].posZ;
436 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700437 data.color[i][0] = tri_data[i].r;
438 data.color[i][1] = tri_data[i].g;
439 data.color[i][2] = tri_data[i].b;
440 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500441 }
442
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 ASSERT_NO_FATAL_FAILURE(InitViewport());
444
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200445 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
446 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Karl Schultz6addd812016-02-02 17:17:23 -0700448 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600449 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
451 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800452 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 pipelineobj.AddShader(&vs);
454 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 if (failMask & BsoFailLineWidth) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600457 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600458 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600459 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
460 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600461 }
462 if (failMask & BsoFailDepthBias) {
463 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600464 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600465 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600466 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600467 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600468 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600469 }
Karl Schultz6addd812016-02-02 17:17:23 -0700470 // Viewport and scissors must stay in synch or other errors will occur than
471 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 if (failMask & BsoFailViewport) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
474 }
475 if (failMask & BsoFailScissor) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
477 }
478 if (failMask & BsoFailBlend) {
479 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600480 VkPipelineColorBlendAttachmentState att_state = {};
481 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
482 att_state.blendEnable = VK_TRUE;
483 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600484 }
485 if (failMask & BsoFailDepthBounds) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
487 }
488 if (failMask & BsoFailStencilReadMask) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
490 }
491 if (failMask & BsoFailStencilWriteMask) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
493 }
494 if (failMask & BsoFailStencilReference) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
496 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500497
498 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600499 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600502 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
Tony Barbourfe3351b2015-07-28 10:17:20 -0600504 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500505
506 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600507 if (failMask & BsoFailIndexBuffer) {
508 // Use DrawIndexed w/o an index buffer bound
509 DrawIndexed(3, 1, 0, 0, 0);
510 } else {
511 Draw(3, 1, 0, 0);
512 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500513
Mark Muellerd4914412016-06-13 17:52:06 -0600514 if (failMask & BsoFailCmdClearAttachments) {
515 VkClearAttachment color_attachment = {};
516 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
517 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
518 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
519
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600520 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600521 }
522
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500523 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600524 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500525
Tony Barbourfe3351b2015-07-28 10:17:20 -0600526 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500527}
528
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600529void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
530 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500531 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500533 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600534 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500535 }
536
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800537 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700538 // Make sure depthWriteEnable is set so that Depth fail test will work
539 // correctly
540 // Make sure stencilTestEnable is set so that Stencil fail test will work
541 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600542 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800543 stencil.failOp = VK_STENCIL_OP_KEEP;
544 stencil.passOp = VK_STENCIL_OP_KEEP;
545 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
546 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600547
548 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
549 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600550 ds_ci.pNext = NULL;
551 ds_ci.depthTestEnable = VK_FALSE;
552 ds_ci.depthWriteEnable = VK_TRUE;
553 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
554 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600555 if (failMask & BsoFailDepthBounds) {
556 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600557 ds_ci.maxDepthBounds = 0.0f;
558 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600559 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600560 ds_ci.stencilTestEnable = VK_TRUE;
561 ds_ci.front = stencil;
562 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600563
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600564 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600565 pipelineobj.SetViewport(m_viewports);
566 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800567 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600568 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600569 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800570 commandBuffer->BindPipeline(pipelineobj);
571 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500572}
573
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600574class VkPositiveLayerTest : public VkLayerTest {
575 public:
576 protected:
577};
578
Ian Elliott2c1daf52016-05-12 09:41:46 -0600579class VkWsiEnabledLayerTest : public VkLayerTest {
580 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 protected:
582 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600583};
584
Mark Muellerdfe37552016-07-07 14:47:42 -0600585class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600586 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600587 enum eTestEnFlags {
588 eDoubleDelete,
589 eInvalidDeviceOffset,
590 eInvalidMemoryOffset,
591 eBindNullBuffer,
592 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600593 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600594 };
595
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600596 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600597
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
599 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600600 return true;
601 }
602 VkDeviceSize offset_limit = 0;
603 if (eInvalidMemoryOffset == aTestFlag) {
604 VkBuffer vulkanBuffer;
605 VkBufferCreateInfo buffer_create_info = {};
606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
607 buffer_create_info.size = 32;
608 buffer_create_info.usage = aBufferUsage;
609
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600610 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600611 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600614 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
615 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
617 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600618 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600620 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600622 }
623 if (eOffsetAlignment < offset_limit) {
624 return true;
625 }
626 return false;
627 }
628
629 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
631 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
633 if (eBindNullBuffer == aTestFlag) {
634 VulkanMemory = 0;
635 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
636 } else {
637 VkBufferCreateInfo buffer_create_info = {};
638 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
639 buffer_create_info.size = 32;
640 buffer_create_info.usage = aBufferUsage;
641
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600643
644 CreateCurrent = true;
645
646 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600647 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600648
649 VkMemoryAllocateInfo memory_allocate_info = {};
650 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
651 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
653 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600654 if (!pass) {
655 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
656 return;
657 }
658
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600659 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600660 AllocateCurrent = true;
661 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
663 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 BoundCurrent = true;
665
666 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
667 }
668 }
669
670 ~VkBufferTest() {
671 if (CreateCurrent) {
672 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
673 }
674 if (AllocateCurrent) {
675 if (InvalidDeleteEn) {
676 union {
677 VkDeviceMemory device_memory;
678 unsigned long long index_access;
679 } bad_index;
680
681 bad_index.device_memory = VulkanMemory;
682 bad_index.index_access++;
683
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600684 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600685 }
686 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
687 }
688 }
689
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600690 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600691
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600692 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600693
694 void TestDoubleDestroy() {
695 // Destroy the buffer but leave the flag set, which will cause
696 // the buffer to be destroyed again in the destructor.
697 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600701 bool AllocateCurrent;
702 bool BoundCurrent;
703 bool CreateCurrent;
704 bool InvalidDeleteEn;
705
706 VkBuffer VulkanBuffer;
707 VkDevice VulkanDevice;
708 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600709};
710
711class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600712 public:
713 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600714 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600716 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600717 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
718 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 BindIdGenerator++; // NB: This can wrap w/misuse
720
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600721 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
722 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
725 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
726 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
727 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
728 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600729
730 unsigned i = 0;
731 do {
732 VertexInputAttributeDescription[i].binding = BindId;
733 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
735 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600736 i++;
737 } while (AttributeCount < i);
738
739 i = 0;
740 do {
741 VertexInputBindingDescription[i].binding = BindId;
742 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600743 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600744 i++;
745 } while (BindingCount < i);
746 }
747
748 ~VkVerticesObj() {
749 if (VertexInputAttributeDescription) {
750 delete[] VertexInputAttributeDescription;
751 }
752 if (VertexInputBindingDescription) {
753 delete[] VertexInputBindingDescription;
754 }
755 }
756
757 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
759 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600760 return true;
761 }
762
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600763 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600764 VkDeviceSize *offsetList;
765 unsigned offsetCount;
766
767 if (aOffsetCount) {
768 offsetList = aOffsetList;
769 offsetCount = aOffsetCount;
770 } else {
771 offsetList = new VkDeviceSize[1]();
772 offsetCount = 1;
773 }
774
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600775 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600776 BoundCurrent = true;
777
778 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600779 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600780 }
781 }
782
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600783 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600784 static uint32_t BindIdGenerator;
785
786 bool BoundCurrent;
787 unsigned AttributeCount;
788 unsigned BindingCount;
789 uint32_t BindId;
790
791 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
792 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
793 VkVertexInputBindingDescription *VertexInputBindingDescription;
794 VkConstantBufferObj VulkanMemoryBuffer;
795};
796
797uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500798// ********************************************************************************************************************
799// ********************************************************************************************************************
800// ********************************************************************************************************************
801// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600802#if PARAMETER_VALIDATION_TESTS
803TEST_F(VkLayerTest, RequiredParameter) {
804 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
805 "pointer, array, and array count parameters");
806
807 ASSERT_NO_FATAL_FAILURE(InitState());
808
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600810 // Specify NULL for a pointer to a handle
811 // Expected to trigger an error with
812 // parameter_validation::validate_required_pointer
813 vkGetPhysicalDeviceFeatures(gpu(), NULL);
814 m_errorMonitor->VerifyFound();
815
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
817 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600818 // Specify NULL for pointer to array count
819 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600820 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600821 m_errorMonitor->VerifyFound();
822
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 // Specify 0 for a required array count
825 // Expected to trigger an error with parameter_validation::validate_array
826 VkViewport view_port = {};
827 m_commandBuffer->SetViewport(0, 0, &view_port);
828 m_errorMonitor->VerifyFound();
829
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for a required array
832 // Expected to trigger an error with parameter_validation::validate_array
833 m_commandBuffer->SetViewport(0, 1, NULL);
834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify VK_NULL_HANDLE for a required handle
838 // Expected to trigger an error with
839 // parameter_validation::validate_required_handle
840 vkUnmapMemory(device(), VK_NULL_HANDLE);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
844 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600845 // Specify VK_NULL_HANDLE for a required handle array entry
846 // Expected to trigger an error with
847 // parameter_validation::validate_required_handle_array
848 VkFence fence = VK_NULL_HANDLE;
849 vkResetFences(device(), 1, &fence);
850 m_errorMonitor->VerifyFound();
851
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600853 // Specify NULL for a required struct pointer
854 // Expected to trigger an error with
855 // parameter_validation::validate_struct_type
856 VkDeviceMemory memory = VK_NULL_HANDLE;
857 vkAllocateMemory(device(), NULL, NULL, &memory);
858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600861 // Specify 0 for a required VkFlags parameter
862 // Expected to trigger an error with parameter_validation::validate_flags
863 m_commandBuffer->SetStencilReference(0, 0);
864 m_errorMonitor->VerifyFound();
865
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600867 // Specify 0 for a required VkFlags array entry
868 // Expected to trigger an error with
869 // parameter_validation::validate_flags_array
870 VkSemaphore semaphore = VK_NULL_HANDLE;
871 VkPipelineStageFlags stageFlags = 0;
872 VkSubmitInfo submitInfo = {};
873 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
874 submitInfo.waitSemaphoreCount = 1;
875 submitInfo.pWaitSemaphores = &semaphore;
876 submitInfo.pWaitDstStageMask = &stageFlags;
877 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
878 m_errorMonitor->VerifyFound();
879}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600880
Dustin Gravesfce74c02016-05-10 11:42:58 -0600881TEST_F(VkLayerTest, ReservedParameter) {
882 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
883
884 ASSERT_NO_FATAL_FAILURE(InitState());
885
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600887 // Specify 0 for a reserved VkFlags parameter
888 // Expected to trigger an error with
889 // parameter_validation::validate_reserved_flags
890 VkEvent event_handle = VK_NULL_HANDLE;
891 VkEventCreateInfo event_info = {};
892 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
893 event_info.flags = 1;
894 vkCreateEvent(device(), &event_info, NULL, &event_handle);
895 m_errorMonitor->VerifyFound();
896}
897
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600898TEST_F(VkLayerTest, InvalidStructSType) {
899 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
900 "structure's sType field");
901
902 ASSERT_NO_FATAL_FAILURE(InitState());
903
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600905 // Zero struct memory, effectively setting sType to
906 // VK_STRUCTURE_TYPE_APPLICATION_INFO
907 // Expected to trigger an error with
908 // parameter_validation::validate_struct_type
909 VkMemoryAllocateInfo alloc_info = {};
910 VkDeviceMemory memory = VK_NULL_HANDLE;
911 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
912 m_errorMonitor->VerifyFound();
913
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915 // Zero struct memory, effectively setting sType to
916 // VK_STRUCTURE_TYPE_APPLICATION_INFO
917 // Expected to trigger an error with
918 // parameter_validation::validate_struct_type_array
919 VkSubmitInfo submit_info = {};
920 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
921 m_errorMonitor->VerifyFound();
922}
923
924TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600925 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600926
927 ASSERT_NO_FATAL_FAILURE(InitState());
928
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600930 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600931 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600932 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600933 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600934 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600935 // Zero-initialization will provide the correct sType
936 VkApplicationInfo app_info = {};
937 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
938 event_alloc_info.pNext = &app_info;
939 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
940 m_errorMonitor->VerifyFound();
941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
943 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
945 // a function that has allowed pNext structure types and specify
946 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600947 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600948 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600949 VkMemoryAllocateInfo memory_alloc_info = {};
950 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
951 memory_alloc_info.pNext = &app_info;
952 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600953 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600954}
Dustin Graves5d33d532016-05-09 16:21:12 -0600955
956TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600957 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600958
959 ASSERT_NO_FATAL_FAILURE(InitState());
960
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
962 "range of the core VkFormat "
963 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600964 // Specify an invalid VkFormat value
965 // Expected to trigger an error with
966 // parameter_validation::validate_ranged_enum
967 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600968 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600969 m_errorMonitor->VerifyFound();
970
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 // Specify an invalid VkFlags bitmask value
973 // Expected to trigger an error with parameter_validation::validate_flags
974 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600975 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
976 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600977 m_errorMonitor->VerifyFound();
978
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 // Specify an invalid VkFlags array entry
981 // Expected to trigger an error with
982 // parameter_validation::validate_flags_array
983 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600984 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600985 VkSubmitInfo submit_info = {};
986 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
987 submit_info.waitSemaphoreCount = 1;
988 submit_info.pWaitSemaphores = &semaphore;
989 submit_info.pWaitDstStageMask = &stage_flags;
990 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
991 m_errorMonitor->VerifyFound();
992
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 // Specify an invalid VkBool32 value
995 // Expected to trigger a warning with
996 // parameter_validation::validate_bool32
997 VkSampler sampler = VK_NULL_HANDLE;
998 VkSamplerCreateInfo sampler_info = {};
999 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1000 sampler_info.pNext = NULL;
1001 sampler_info.magFilter = VK_FILTER_NEAREST;
1002 sampler_info.minFilter = VK_FILTER_NEAREST;
1003 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1004 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1005 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1006 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1007 sampler_info.mipLodBias = 1.0;
1008 sampler_info.maxAnisotropy = 1;
1009 sampler_info.compareEnable = VK_FALSE;
1010 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1011 sampler_info.minLod = 1.0;
1012 sampler_info.maxLod = 1.0;
1013 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1014 sampler_info.unnormalizedCoordinates = VK_FALSE;
1015 // Not VK_TRUE or VK_FALSE
1016 sampler_info.anisotropyEnable = 3;
1017 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1018 m_errorMonitor->VerifyFound();
1019}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001020
1021TEST_F(VkLayerTest, FailedReturnValue) {
1022 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1023
1024 ASSERT_NO_FATAL_FAILURE(InitState());
1025
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001026 // Find an unsupported image format
1027 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1028 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1029 VkFormat format = static_cast<VkFormat>(f);
1030 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001031 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001032 unsupported = format;
1033 break;
1034 }
1035 }
1036
1037 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1039 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001040 // Specify an unsupported VkFormat value to generate a
1041 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1042 // Expected to trigger a warning from
1043 // parameter_validation::validate_result
1044 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001045 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1046 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1048 m_errorMonitor->VerifyFound();
1049 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001050}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001051
1052TEST_F(VkLayerTest, UpdateBufferAlignment) {
1053 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001054 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001055
1056 ASSERT_NO_FATAL_FAILURE(InitState());
1057
1058 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1059 vk_testing::Buffer buffer;
1060 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1061
1062 BeginCommandBuffer();
1063 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1066 m_errorMonitor->VerifyFound();
1067
1068 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1071 m_errorMonitor->VerifyFound();
1072
1073 // Introduce failure by using dataSize that is < 0
1074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001075 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1077 m_errorMonitor->VerifyFound();
1078
1079 // Introduce failure by using dataSize that is > 65536
1080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001081 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001082 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1083 m_errorMonitor->VerifyFound();
1084
1085 EndCommandBuffer();
1086}
1087
1088TEST_F(VkLayerTest, FillBufferAlignment) {
1089 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1090
1091 ASSERT_NO_FATAL_FAILURE(InitState());
1092
1093 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1094 vk_testing::Buffer buffer;
1095 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1096
1097 BeginCommandBuffer();
1098
1099 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1102 m_errorMonitor->VerifyFound();
1103
1104 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001106 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1107 m_errorMonitor->VerifyFound();
1108
1109 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001111 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1112 m_errorMonitor->VerifyFound();
1113
1114 EndCommandBuffer();
1115}
Dustin Graves40f35822016-06-23 11:12:53 -06001116
Cortd889ff92016-07-27 09:51:27 -07001117TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1118 VkResult err;
1119
1120 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001121 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001122
1123 ASSERT_NO_FATAL_FAILURE(InitState());
1124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1125
1126 std::vector<const char *> device_extension_names;
1127 auto features = m_device->phy().features();
1128 // Artificially disable support for non-solid fill modes
1129 features.fillModeNonSolid = false;
1130 // The sacrificial device object
1131 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1132
1133 VkRenderpassObj render_pass(&test_device);
1134
1135 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1136 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1137 pipeline_layout_ci.setLayoutCount = 0;
1138 pipeline_layout_ci.pSetLayouts = NULL;
1139
1140 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001141 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001142 ASSERT_VK_SUCCESS(err);
1143
1144 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1145 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1146 rs_ci.pNext = nullptr;
1147 rs_ci.lineWidth = 1.0f;
1148 rs_ci.rasterizerDiscardEnable = true;
1149
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001150 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1151 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001152
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001153 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1155 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001156 {
1157 VkPipelineObj pipe(&test_device);
1158 pipe.AddShader(&vs);
1159 pipe.AddShader(&fs);
1160 pipe.AddColorAttachment();
1161 // Introduce failure by setting unsupported polygon mode
1162 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1163 pipe.SetRasterization(&rs_ci);
1164 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1165 }
1166 m_errorMonitor->VerifyFound();
1167
1168 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1170 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001171 {
1172 VkPipelineObj pipe(&test_device);
1173 pipe.AddShader(&vs);
1174 pipe.AddShader(&fs);
1175 pipe.AddColorAttachment();
1176 // Introduce failure by setting unsupported polygon mode
1177 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1178 pipe.SetRasterization(&rs_ci);
1179 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1180 }
1181 m_errorMonitor->VerifyFound();
1182
Cortd889ff92016-07-27 09:51:27 -07001183 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1184}
1185
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001186#endif // PARAMETER_VALIDATION_TESTS
1187
Tobin Ehlis0788f522015-05-26 16:11:58 -06001188#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001189#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001190TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001191{
1192 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001193 VkFenceCreateInfo fenceInfo = {};
1194 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1195 fenceInfo.pNext = NULL;
1196 fenceInfo.flags = 0;
1197
Mike Weiblencce7ec72016-10-17 19:33:05 -06001198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001199
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001200 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001201
1202 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1203 vk_testing::Buffer buffer;
1204 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001205
Tony Barbourfe3351b2015-07-28 10:17:20 -06001206 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001207 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001208 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001209
1210 testFence.init(*m_device, fenceInfo);
1211
1212 // Bypass framework since it does the waits automatically
1213 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001214 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001215 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1216 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001217 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001218 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001219 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001220 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001221 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001222 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001223 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001224
1225 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001226 ASSERT_VK_SUCCESS( err );
1227
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001229 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001230
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001231 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232}
1233
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001235{
1236 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001237 VkFenceCreateInfo fenceInfo = {};
1238 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1239 fenceInfo.pNext = NULL;
1240 fenceInfo.flags = 0;
1241
Mike Weiblencce7ec72016-10-17 19:33:05 -06001242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001243
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001244 ASSERT_NO_FATAL_FAILURE(InitState());
1245 ASSERT_NO_FATAL_FAILURE(InitViewport());
1246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1247
Tony Barbourfe3351b2015-07-28 10:17:20 -06001248 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001249 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001250 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251
1252 testFence.init(*m_device, fenceInfo);
1253
1254 // Bypass framework since it does the waits automatically
1255 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001256 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001257 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1258 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001259 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001260 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001261 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001262 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001263 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001264 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001265 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001266
1267 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001268 ASSERT_VK_SUCCESS( err );
1269
Jon Ashburnf19916e2016-01-11 13:12:43 -07001270 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001271 VkCommandBufferBeginInfo info = {};
1272 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1273 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001274 info.renderPass = VK_NULL_HANDLE;
1275 info.subpass = 0;
1276 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001277 info.occlusionQueryEnable = VK_FALSE;
1278 info.queryFlags = 0;
1279 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001280
1281 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001282 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001283
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001284 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001285}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001286#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001287
Tobin Ehlisf11be982016-05-11 13:52:53 -06001288TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1289 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1290 "buffer and image to memory such that they will alias.");
1291 VkResult err;
1292 bool pass;
1293 ASSERT_NO_FATAL_FAILURE(InitState());
1294
Tobin Ehlis077ded32016-05-12 17:39:13 -06001295 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001296 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001297 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001298 VkDeviceMemory mem; // buffer will be bound first
1299 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001300 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001301
1302 VkBufferCreateInfo buf_info = {};
1303 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1304 buf_info.pNext = NULL;
1305 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1306 buf_info.size = 256;
1307 buf_info.queueFamilyIndexCount = 0;
1308 buf_info.pQueueFamilyIndices = NULL;
1309 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1310 buf_info.flags = 0;
1311 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1312 ASSERT_VK_SUCCESS(err);
1313
Tobin Ehlis077ded32016-05-12 17:39:13 -06001314 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001315
1316 VkImageCreateInfo image_create_info = {};
1317 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1318 image_create_info.pNext = NULL;
1319 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1320 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1321 image_create_info.extent.width = 64;
1322 image_create_info.extent.height = 64;
1323 image_create_info.extent.depth = 1;
1324 image_create_info.mipLevels = 1;
1325 image_create_info.arrayLayers = 1;
1326 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001327 // Image tiling must be optimal to trigger error when aliasing linear buffer
1328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001329 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1330 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1331 image_create_info.queueFamilyIndexCount = 0;
1332 image_create_info.pQueueFamilyIndices = NULL;
1333 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1334 image_create_info.flags = 0;
1335
Tobin Ehlisf11be982016-05-11 13:52:53 -06001336 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1337 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001338 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1339 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001340
Tobin Ehlis077ded32016-05-12 17:39:13 -06001341 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1342
1343 VkMemoryAllocateInfo alloc_info = {};
1344 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1345 alloc_info.pNext = NULL;
1346 alloc_info.memoryTypeIndex = 0;
1347 // Ensure memory is big enough for both bindings
1348 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001349 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1350 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001351 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001352 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001353 vkDestroyImage(m_device->device(), image, NULL);
1354 return;
1355 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001356 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1357 ASSERT_VK_SUCCESS(err);
1358 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1359 ASSERT_VK_SUCCESS(err);
1360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001362 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001363 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1364 m_errorMonitor->VerifyFound();
1365
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001366 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001367 // aliasing buffer2
1368 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1369 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001370 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1371 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001372 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001373 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001375 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001376 m_errorMonitor->VerifyFound();
1377
1378 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001379 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001380 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001381 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001382 vkFreeMemory(m_device->device(), mem, NULL);
1383 vkFreeMemory(m_device->device(), mem_img, NULL);
1384}
1385
Tobin Ehlis35372522016-05-12 08:32:31 -06001386TEST_F(VkLayerTest, InvalidMemoryMapping) {
1387 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1388 VkResult err;
1389 bool pass;
1390 ASSERT_NO_FATAL_FAILURE(InitState());
1391
1392 VkBuffer buffer;
1393 VkDeviceMemory mem;
1394 VkMemoryRequirements mem_reqs;
1395
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001396 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1397
Tobin Ehlis35372522016-05-12 08:32:31 -06001398 VkBufferCreateInfo buf_info = {};
1399 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1400 buf_info.pNext = NULL;
1401 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1402 buf_info.size = 256;
1403 buf_info.queueFamilyIndexCount = 0;
1404 buf_info.pQueueFamilyIndices = NULL;
1405 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1406 buf_info.flags = 0;
1407 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1408 ASSERT_VK_SUCCESS(err);
1409
1410 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1411 VkMemoryAllocateInfo alloc_info = {};
1412 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1413 alloc_info.pNext = NULL;
1414 alloc_info.memoryTypeIndex = 0;
1415
1416 // Ensure memory is big enough for both bindings
1417 static const VkDeviceSize allocation_size = 0x10000;
1418 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001419 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001420 if (!pass) {
1421 vkDestroyBuffer(m_device->device(), buffer, NULL);
1422 return;
1423 }
1424 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1425 ASSERT_VK_SUCCESS(err);
1426
1427 uint8_t *pData;
1428 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001430 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1431 m_errorMonitor->VerifyFound();
1432 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001433 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001434 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1436 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1437 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001438 m_errorMonitor->VerifyFound();
1439
1440 // Unmap the memory to avoid re-map error
1441 vkUnmapMemory(m_device->device(), mem);
1442 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1444 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1445 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001446 m_errorMonitor->VerifyFound();
1447 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1449 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001450 m_errorMonitor->VerifyFound();
1451 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001453 vkUnmapMemory(m_device->device(), mem);
1454 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001455
Tobin Ehlis35372522016-05-12 08:32:31 -06001456 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001457 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001458 ASSERT_VK_SUCCESS(err);
1459 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001460 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001461 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001462 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001464 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1465 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001466
Tobin Ehlis35372522016-05-12 08:32:31 -06001467 // Now flush range that oversteps mapped range
1468 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001469 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001470 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001471 mmr.offset = atom_size;
1472 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1474 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1475 m_errorMonitor->VerifyFound();
1476
1477 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1478 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001479 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001480 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001481 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001482 mmr.size = VK_WHOLE_SIZE;
1483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001484 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1485 m_errorMonitor->VerifyFound();
1486
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001487 // Some platforms have an atomsize of 1 which makes the test meaningless
1488 if (atom_size > 3) {
1489 // Now with an offset NOT a multiple of the device limit
1490 vkUnmapMemory(m_device->device(), mem);
1491 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1492 ASSERT_VK_SUCCESS(err);
1493 mmr.offset = 3; // Not a multiple of atom_size
1494 mmr.size = VK_WHOLE_SIZE;
1495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1496 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1497 m_errorMonitor->VerifyFound();
1498
1499 // Now with a size NOT a multiple of the device limit
1500 vkUnmapMemory(m_device->device(), mem);
1501 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1502 ASSERT_VK_SUCCESS(err);
1503 mmr.offset = atom_size;
1504 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1506 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1507 m_errorMonitor->VerifyFound();
1508 }
1509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001510 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1511 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001512 if (!pass) {
1513 vkFreeMemory(m_device->device(), mem, NULL);
1514 vkDestroyBuffer(m_device->device(), buffer, NULL);
1515 return;
1516 }
1517 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1518 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1519
1520 vkDestroyBuffer(m_device->device(), buffer, NULL);
1521 vkFreeMemory(m_device->device(), mem, NULL);
1522}
1523
Chris Forbes09368e42016-10-13 11:59:22 +13001524#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001525TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1526 VkResult err;
1527 bool pass;
1528
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001529 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1530 // following declaration (which is temporarily being moved below):
1531 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001532 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001533 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001534 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001535 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001536 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001537 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001538
1539 ASSERT_NO_FATAL_FAILURE(InitState());
1540
Ian Elliott3f06ce52016-04-29 14:46:21 -06001541#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1542#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1543 // Use the functions from the VK_KHR_android_surface extension without
1544 // enabling that extension:
1545
1546 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001547 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1549 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001550 pass = (err != VK_SUCCESS);
1551 ASSERT_TRUE(pass);
1552 m_errorMonitor->VerifyFound();
1553#endif // VK_USE_PLATFORM_ANDROID_KHR
1554
Ian Elliott3f06ce52016-04-29 14:46:21 -06001555#if defined(VK_USE_PLATFORM_MIR_KHR)
1556 // Use the functions from the VK_KHR_mir_surface extension without enabling
1557 // that extension:
1558
1559 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001560 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001562 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1563 pass = (err != VK_SUCCESS);
1564 ASSERT_TRUE(pass);
1565 m_errorMonitor->VerifyFound();
1566
1567 // Tell whether an mir_connection supports presentation:
1568 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1570 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001571 m_errorMonitor->VerifyFound();
1572#endif // VK_USE_PLATFORM_MIR_KHR
1573
Ian Elliott3f06ce52016-04-29 14:46:21 -06001574#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1575 // Use the functions from the VK_KHR_wayland_surface extension without
1576 // enabling that extension:
1577
1578 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001579 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1581 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001582 pass = (err != VK_SUCCESS);
1583 ASSERT_TRUE(pass);
1584 m_errorMonitor->VerifyFound();
1585
1586 // Tell whether an wayland_display supports presentation:
1587 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1589 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001590 m_errorMonitor->VerifyFound();
1591#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001592#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001593
Ian Elliott3f06ce52016-04-29 14:46:21 -06001594#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001595 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1596 // TO NON-LINUX PLATFORMS:
1597 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001598 // Use the functions from the VK_KHR_win32_surface extension without
1599 // enabling that extension:
1600
1601 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001602 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1604 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001605 pass = (err != VK_SUCCESS);
1606 ASSERT_TRUE(pass);
1607 m_errorMonitor->VerifyFound();
1608
1609 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001611 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001612 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001613// Set this (for now, until all platforms are supported and tested):
1614#define NEED_TO_TEST_THIS_ON_PLATFORM
1615#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001616#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001617 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1618 // TO NON-LINUX PLATFORMS:
1619 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001620#endif
1621#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001622 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1623 // that extension:
1624
1625 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001626 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001628 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1629 pass = (err != VK_SUCCESS);
1630 ASSERT_TRUE(pass);
1631 m_errorMonitor->VerifyFound();
1632
1633 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001634 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001635 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1637 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001638 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001639// Set this (for now, until all platforms are supported and tested):
1640#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001641#endif // VK_USE_PLATFORM_XCB_KHR
1642
Ian Elliott12630812016-04-29 14:35:43 -06001643#if defined(VK_USE_PLATFORM_XLIB_KHR)
1644 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1645 // that extension:
1646
1647 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001648 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001650 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1651 pass = (err != VK_SUCCESS);
1652 ASSERT_TRUE(pass);
1653 m_errorMonitor->VerifyFound();
1654
1655 // Tell whether an Xlib VisualID supports presentation:
1656 Display *dpy = NULL;
1657 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001659 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1660 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001661// Set this (for now, until all platforms are supported and tested):
1662#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001663#endif // VK_USE_PLATFORM_XLIB_KHR
1664
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001665// Use the functions from the VK_KHR_surface extension without enabling
1666// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001667
Ian Elliott489eec02016-05-05 14:12:44 -06001668#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001669 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001671 vkDestroySurfaceKHR(instance(), surface, NULL);
1672 m_errorMonitor->VerifyFound();
1673
1674 // Check if surface supports presentation:
1675 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001677 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1678 pass = (err != VK_SUCCESS);
1679 ASSERT_TRUE(pass);
1680 m_errorMonitor->VerifyFound();
1681
1682 // Check surface capabilities:
1683 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1685 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001686 pass = (err != VK_SUCCESS);
1687 ASSERT_TRUE(pass);
1688 m_errorMonitor->VerifyFound();
1689
1690 // Check surface formats:
1691 uint32_t format_count = 0;
1692 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1694 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001695 pass = (err != VK_SUCCESS);
1696 ASSERT_TRUE(pass);
1697 m_errorMonitor->VerifyFound();
1698
1699 // Check surface present modes:
1700 uint32_t present_mode_count = 0;
1701 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1703 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001704 pass = (err != VK_SUCCESS);
1705 ASSERT_TRUE(pass);
1706 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001707#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001708
Ian Elliott1c32c772016-04-28 14:47:13 -06001709 // Use the functions from the VK_KHR_swapchain extension without enabling
1710 // that extension:
1711
1712 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001714 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1715 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001716 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001717 pass = (err != VK_SUCCESS);
1718 ASSERT_TRUE(pass);
1719 m_errorMonitor->VerifyFound();
1720
1721 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1723 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001724 pass = (err != VK_SUCCESS);
1725 ASSERT_TRUE(pass);
1726 m_errorMonitor->VerifyFound();
1727
Chris Forbeseb7d5502016-09-13 18:19:21 +12001728 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1729 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1730 VkFence fence;
1731 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1732
Ian Elliott1c32c772016-04-28 14:47:13 -06001733 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001735 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001736 pass = (err != VK_SUCCESS);
1737 ASSERT_TRUE(pass);
1738 m_errorMonitor->VerifyFound();
1739
Chris Forbeseb7d5502016-09-13 18:19:21 +12001740 vkDestroyFence(m_device->device(), fence, nullptr);
1741
Ian Elliott1c32c772016-04-28 14:47:13 -06001742 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001743 //
1744 // NOTE: Currently can't test this because a real swapchain is needed (as
1745 // opposed to the fake one we created) in order for the layer to lookup the
1746 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001747
1748 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001750 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1751 m_errorMonitor->VerifyFound();
1752}
Chris Forbes09368e42016-10-13 11:59:22 +13001753#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001754
Karl Schultz6addd812016-02-02 17:17:23 -07001755TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1756 VkResult err;
1757 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001758
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1760 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001761
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001762 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001763
1764 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001765 VkImage image;
1766 VkDeviceMemory mem;
1767 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001768
Karl Schultz6addd812016-02-02 17:17:23 -07001769 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1770 const int32_t tex_width = 32;
1771 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001772
Tony Barboureb254902015-07-15 12:50:33 -06001773 VkImageCreateInfo image_create_info = {};
1774 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001775 image_create_info.pNext = NULL;
1776 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1777 image_create_info.format = tex_format;
1778 image_create_info.extent.width = tex_width;
1779 image_create_info.extent.height = tex_height;
1780 image_create_info.extent.depth = 1;
1781 image_create_info.mipLevels = 1;
1782 image_create_info.arrayLayers = 1;
1783 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1784 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1785 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1786 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001787 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001788
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001789 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001790 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001791 mem_alloc.pNext = NULL;
1792 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001793
Chia-I Wuf7458c52015-10-26 21:10:41 +08001794 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001795 ASSERT_VK_SUCCESS(err);
1796
Karl Schultz6addd812016-02-02 17:17:23 -07001797 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001798
Mark Lobodzinski23065352015-05-29 09:32:35 -05001799 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001800
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001801 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Karl Schultz6addd812016-02-02 17:17:23 -07001802 if (!pass) { // If we can't find any unmappable memory this test doesn't
1803 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001804 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001805 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001806 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001807
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001808 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001809 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001810 ASSERT_VK_SUCCESS(err);
1811
1812 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001813 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001814 ASSERT_VK_SUCCESS(err);
1815
1816 // Map memory as if to initialize the image
1817 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001818 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001819
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001820 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001821
Chia-I Wuf7458c52015-10-26 21:10:41 +08001822 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001823 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001824}
1825
Karl Schultz6addd812016-02-02 17:17:23 -07001826TEST_F(VkLayerTest, RebindMemory) {
1827 VkResult err;
1828 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001829
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001831
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001832 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001833
1834 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001835 VkImage image;
1836 VkDeviceMemory mem1;
1837 VkDeviceMemory mem2;
1838 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001839
Karl Schultz6addd812016-02-02 17:17:23 -07001840 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1841 const int32_t tex_width = 32;
1842 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001843
Tony Barboureb254902015-07-15 12:50:33 -06001844 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001845 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1846 image_create_info.pNext = NULL;
1847 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1848 image_create_info.format = tex_format;
1849 image_create_info.extent.width = tex_width;
1850 image_create_info.extent.height = tex_height;
1851 image_create_info.extent.depth = 1;
1852 image_create_info.mipLevels = 1;
1853 image_create_info.arrayLayers = 1;
1854 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1855 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1856 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1857 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001858
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001859 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001860 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1861 mem_alloc.pNext = NULL;
1862 mem_alloc.allocationSize = 0;
1863 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001864
Karl Schultz6addd812016-02-02 17:17:23 -07001865 // Introduce failure, do NOT set memProps to
1866 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001867 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001868 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001869 ASSERT_VK_SUCCESS(err);
1870
Karl Schultz6addd812016-02-02 17:17:23 -07001871 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001872
1873 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001874 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001875 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001876
1877 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001878 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001879 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001880 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001881 ASSERT_VK_SUCCESS(err);
1882
1883 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001884 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001885 ASSERT_VK_SUCCESS(err);
1886
Karl Schultz6addd812016-02-02 17:17:23 -07001887 // Introduce validation failure, try to bind a different memory object to
1888 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001889 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001890
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001891 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001892
Chia-I Wuf7458c52015-10-26 21:10:41 +08001893 vkDestroyImage(m_device->device(), image, NULL);
1894 vkFreeMemory(m_device->device(), mem1, NULL);
1895 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001896}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001897
Karl Schultz6addd812016-02-02 17:17:23 -07001898TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001899 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001900
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1902 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001903
1904 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001905 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1906 fenceInfo.pNext = NULL;
1907 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001908
Tony Barbour300a6082015-04-07 13:44:53 -06001909 ASSERT_NO_FATAL_FAILURE(InitState());
1910 ASSERT_NO_FATAL_FAILURE(InitViewport());
1911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1912
Tony Barbourfe3351b2015-07-28 10:17:20 -06001913 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001914 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001915 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001916
1917 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001918
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001919 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001920 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1921 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001922 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001923 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001924 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001925 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001926 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001927 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001928 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001929
1930 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001931 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001932
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001933 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001934}
Chris Forbes4e44c912016-06-16 10:20:00 +12001935
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001936TEST_F(VkLayerTest, InvalidUsageBits) {
1937 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1938 "Initialize buffer with wrong usage then perform copy expecting errors "
1939 "from both the image and the buffer (2 calls)");
1940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001941
1942 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001943 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001944 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001945 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001946 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001947
Tony Barbourf92621a2016-05-02 14:28:12 -06001948 VkImageView dsv;
1949 VkImageViewCreateInfo dsvci = {};
1950 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1951 dsvci.image = image.handle();
1952 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1953 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1954 dsvci.subresourceRange.layerCount = 1;
1955 dsvci.subresourceRange.baseMipLevel = 0;
1956 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001957 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001958
Tony Barbourf92621a2016-05-02 14:28:12 -06001959 // Create a view with depth / stencil aspect for image with different usage
1960 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001961
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001962 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001963
1964 // Initialize buffer with TRANSFER_DST usage
1965 vk_testing::Buffer buffer;
1966 VkMemoryPropertyFlags reqs = 0;
1967 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1968 VkBufferImageCopy region = {};
1969 region.bufferRowLength = 128;
1970 region.bufferImageHeight = 128;
1971 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1972 region.imageSubresource.layerCount = 1;
1973 region.imageExtent.height = 16;
1974 region.imageExtent.width = 16;
1975 region.imageExtent.depth = 1;
1976
Tony Barbourf92621a2016-05-02 14:28:12 -06001977 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1978 // TRANSFER_DST
1979 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001980
Chris Forbesda581202016-10-06 18:25:26 +13001981 // two separate errors from this call:
1982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1984
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001985 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1986 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001987 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001988}
Tony Barbour75d79f02016-08-30 09:39:07 -06001989
Tony Barbour75d79f02016-08-30 09:39:07 -06001990
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001991#endif // MEM_TRACKER_TESTS
1992
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001993#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001994
1995TEST_F(VkLayerTest, LeakAnObject) {
1996 VkResult err;
1997
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001998 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001999
2000 // Note that we have to create a new device since destroying the
2001 // framework's device causes Teardown() to fail and just calling Teardown
2002 // will destroy the errorMonitor.
2003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002005
2006 ASSERT_NO_FATAL_FAILURE(InitState());
2007
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002008 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002009 std::vector<VkDeviceQueueCreateInfo> queue_info;
2010 queue_info.reserve(queue_props.size());
2011 std::vector<std::vector<float>> queue_priorities;
2012 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2013 VkDeviceQueueCreateInfo qi = {};
2014 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2015 qi.pNext = NULL;
2016 qi.queueFamilyIndex = i;
2017 qi.queueCount = queue_props[i].queueCount;
2018 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2019 qi.pQueuePriorities = queue_priorities[i].data();
2020 queue_info.push_back(qi);
2021 }
2022
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002023 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002024
2025 // The sacrificial device object
2026 VkDevice testDevice;
2027 VkDeviceCreateInfo device_create_info = {};
2028 auto features = m_device->phy().features();
2029 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2030 device_create_info.pNext = NULL;
2031 device_create_info.queueCreateInfoCount = queue_info.size();
2032 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002033 device_create_info.enabledLayerCount = 0;
2034 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002035 device_create_info.pEnabledFeatures = &features;
2036 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2037 ASSERT_VK_SUCCESS(err);
2038
2039 VkFence fence;
2040 VkFenceCreateInfo fence_create_info = {};
2041 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2042 fence_create_info.pNext = NULL;
2043 fence_create_info.flags = 0;
2044 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2045 ASSERT_VK_SUCCESS(err);
2046
2047 // Induce failure by not calling vkDestroyFence
2048 vkDestroyDevice(testDevice, NULL);
2049 m_errorMonitor->VerifyFound();
2050}
2051
2052TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2053
2054 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2055 "attempt to delete them from another.");
2056
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002058
Cody Northropc31a84f2016-08-22 10:41:47 -06002059 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002060 VkCommandPool command_pool_one;
2061 VkCommandPool command_pool_two;
2062
2063 VkCommandPoolCreateInfo pool_create_info{};
2064 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2065 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2066 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2067
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002068 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002069
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002070 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002071
2072 VkCommandBuffer command_buffer[9];
2073 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002074 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002075 command_buffer_allocate_info.commandPool = command_pool_one;
2076 command_buffer_allocate_info.commandBufferCount = 9;
2077 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002078 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002079
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002080 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002081
2082 m_errorMonitor->VerifyFound();
2083
2084 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2085 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2086}
2087
2088TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2089 VkResult err;
2090
2091 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002092 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002093
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002095
2096 ASSERT_NO_FATAL_FAILURE(InitState());
2097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2098
2099 VkDescriptorPoolSize ds_type_count = {};
2100 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2101 ds_type_count.descriptorCount = 1;
2102
2103 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2104 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2105 ds_pool_ci.pNext = NULL;
2106 ds_pool_ci.flags = 0;
2107 ds_pool_ci.maxSets = 1;
2108 ds_pool_ci.poolSizeCount = 1;
2109 ds_pool_ci.pPoolSizes = &ds_type_count;
2110
2111 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002112 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002113 ASSERT_VK_SUCCESS(err);
2114
2115 // Create a second descriptor pool
2116 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002117 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002118 ASSERT_VK_SUCCESS(err);
2119
2120 VkDescriptorSetLayoutBinding dsl_binding = {};
2121 dsl_binding.binding = 0;
2122 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2123 dsl_binding.descriptorCount = 1;
2124 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2125 dsl_binding.pImmutableSamplers = NULL;
2126
2127 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2128 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2129 ds_layout_ci.pNext = NULL;
2130 ds_layout_ci.bindingCount = 1;
2131 ds_layout_ci.pBindings = &dsl_binding;
2132
2133 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002134 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002135 ASSERT_VK_SUCCESS(err);
2136
2137 VkDescriptorSet descriptorSet;
2138 VkDescriptorSetAllocateInfo alloc_info = {};
2139 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2140 alloc_info.descriptorSetCount = 1;
2141 alloc_info.descriptorPool = ds_pool_one;
2142 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002143 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002144 ASSERT_VK_SUCCESS(err);
2145
2146 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2147
2148 m_errorMonitor->VerifyFound();
2149
2150 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2151 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2152 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2153}
2154
2155TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002157
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002158 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002159
2160 ASSERT_NO_FATAL_FAILURE(InitState());
2161
2162 // Pass bogus handle into GetImageMemoryRequirements
2163 VkMemoryRequirements mem_reqs;
2164 uint64_t fakeImageHandle = 0xCADECADE;
2165 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2166
2167 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2168
2169 m_errorMonitor->VerifyFound();
2170}
2171
Karl Schultz6addd812016-02-02 17:17:23 -07002172TEST_F(VkLayerTest, PipelineNotBound) {
2173 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002174
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002175 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002176
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002178
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002179 ASSERT_NO_FATAL_FAILURE(InitState());
2180 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002181
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002182 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002183 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2184 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002185
2186 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002187 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2188 ds_pool_ci.pNext = NULL;
2189 ds_pool_ci.maxSets = 1;
2190 ds_pool_ci.poolSizeCount = 1;
2191 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002192
2193 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002194 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002195 ASSERT_VK_SUCCESS(err);
2196
2197 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002198 dsl_binding.binding = 0;
2199 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2200 dsl_binding.descriptorCount = 1;
2201 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2202 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002203
2204 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002205 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2206 ds_layout_ci.pNext = NULL;
2207 ds_layout_ci.bindingCount = 1;
2208 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002209
2210 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002211 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002212 ASSERT_VK_SUCCESS(err);
2213
2214 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002215 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002216 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002217 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002218 alloc_info.descriptorPool = ds_pool;
2219 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002220 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002221 ASSERT_VK_SUCCESS(err);
2222
2223 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002224 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2225 pipeline_layout_ci.pNext = NULL;
2226 pipeline_layout_ci.setLayoutCount = 1;
2227 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002228
2229 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002230 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002231 ASSERT_VK_SUCCESS(err);
2232
Mark Youngad779052016-01-06 14:26:04 -07002233 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002234
2235 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002236 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002237
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002238 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002239
Chia-I Wuf7458c52015-10-26 21:10:41 +08002240 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2241 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2242 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002243}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002244
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002245TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2246 VkResult err;
2247
2248 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2249 "during bind[Buffer|Image]Memory time");
2250
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002251 ASSERT_NO_FATAL_FAILURE(InitState());
2252
2253 // Create an image, allocate memory, set a bad typeIndex and then try to
2254 // bind it
2255 VkImage image;
2256 VkDeviceMemory mem;
2257 VkMemoryRequirements mem_reqs;
2258 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2259 const int32_t tex_width = 32;
2260 const int32_t tex_height = 32;
2261
2262 VkImageCreateInfo image_create_info = {};
2263 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2264 image_create_info.pNext = NULL;
2265 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2266 image_create_info.format = tex_format;
2267 image_create_info.extent.width = tex_width;
2268 image_create_info.extent.height = tex_height;
2269 image_create_info.extent.depth = 1;
2270 image_create_info.mipLevels = 1;
2271 image_create_info.arrayLayers = 1;
2272 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2273 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2274 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2275 image_create_info.flags = 0;
2276
2277 VkMemoryAllocateInfo mem_alloc = {};
2278 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2279 mem_alloc.pNext = NULL;
2280 mem_alloc.allocationSize = 0;
2281 mem_alloc.memoryTypeIndex = 0;
2282
2283 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2284 ASSERT_VK_SUCCESS(err);
2285
2286 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2287 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002288
2289 // Introduce Failure, select invalid TypeIndex
2290 VkPhysicalDeviceMemoryProperties memory_info;
2291
2292 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2293 unsigned int i;
2294 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2295 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2296 mem_alloc.memoryTypeIndex = i;
2297 break;
2298 }
2299 }
2300 if (i >= memory_info.memoryTypeCount) {
2301 printf("No invalid memory type index could be found; skipped.\n");
2302 vkDestroyImage(m_device->device(), image, NULL);
2303 return;
2304 }
2305
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002307
2308 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2309 ASSERT_VK_SUCCESS(err);
2310
2311 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2312 (void)err;
2313
2314 m_errorMonitor->VerifyFound();
2315
2316 vkDestroyImage(m_device->device(), image, NULL);
2317 vkFreeMemory(m_device->device(), mem, NULL);
2318}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002319
Karl Schultz6addd812016-02-02 17:17:23 -07002320TEST_F(VkLayerTest, BindInvalidMemory) {
2321 VkResult err;
2322 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002323
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002325
Tobin Ehlisec598302015-09-15 15:02:17 -06002326 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002327
2328 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002329 VkImage image;
2330 VkDeviceMemory mem;
2331 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002332
Karl Schultz6addd812016-02-02 17:17:23 -07002333 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2334 const int32_t tex_width = 32;
2335 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002336
2337 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002338 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2339 image_create_info.pNext = NULL;
2340 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2341 image_create_info.format = tex_format;
2342 image_create_info.extent.width = tex_width;
2343 image_create_info.extent.height = tex_height;
2344 image_create_info.extent.depth = 1;
2345 image_create_info.mipLevels = 1;
2346 image_create_info.arrayLayers = 1;
2347 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2348 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2349 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2350 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002351
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002352 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002353 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2354 mem_alloc.pNext = NULL;
2355 mem_alloc.allocationSize = 0;
2356 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002357
Chia-I Wuf7458c52015-10-26 21:10:41 +08002358 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002359 ASSERT_VK_SUCCESS(err);
2360
Karl Schultz6addd812016-02-02 17:17:23 -07002361 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002362
2363 mem_alloc.allocationSize = mem_reqs.size;
2364
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002365 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002366 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002367
2368 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002369 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002370 ASSERT_VK_SUCCESS(err);
2371
2372 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002373 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002374
2375 // Try to bind free memory that has been freed
2376 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2377 // This may very well return an error.
2378 (void)err;
2379
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002380 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002381
Chia-I Wuf7458c52015-10-26 21:10:41 +08002382 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002383}
2384
Karl Schultz6addd812016-02-02 17:17:23 -07002385TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2386 VkResult err;
2387 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002388
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002390
Tobin Ehlisec598302015-09-15 15:02:17 -06002391 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002392
Karl Schultz6addd812016-02-02 17:17:23 -07002393 // Create an image object, allocate memory, destroy the object and then try
2394 // to bind it
2395 VkImage image;
2396 VkDeviceMemory mem;
2397 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002398
Karl Schultz6addd812016-02-02 17:17:23 -07002399 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2400 const int32_t tex_width = 32;
2401 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002402
2403 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002404 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2405 image_create_info.pNext = NULL;
2406 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2407 image_create_info.format = tex_format;
2408 image_create_info.extent.width = tex_width;
2409 image_create_info.extent.height = tex_height;
2410 image_create_info.extent.depth = 1;
2411 image_create_info.mipLevels = 1;
2412 image_create_info.arrayLayers = 1;
2413 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2414 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2415 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2416 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002417
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002418 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002419 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2420 mem_alloc.pNext = NULL;
2421 mem_alloc.allocationSize = 0;
2422 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002423
Chia-I Wuf7458c52015-10-26 21:10:41 +08002424 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002425 ASSERT_VK_SUCCESS(err);
2426
Karl Schultz6addd812016-02-02 17:17:23 -07002427 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002428
2429 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002430 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002431 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002432
2433 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002434 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002435 ASSERT_VK_SUCCESS(err);
2436
2437 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002438 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002439 ASSERT_VK_SUCCESS(err);
2440
2441 // Now Try to bind memory to this destroyed object
2442 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2443 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002444 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002445
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002446 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002447
Chia-I Wuf7458c52015-10-26 21:10:41 +08002448 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002449}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002450
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002451#endif // OBJ_TRACKER_TESTS
2452
Tobin Ehlis0788f522015-05-26 16:11:58 -06002453#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002454
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002455TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2456 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2457
2458 ASSERT_NO_FATAL_FAILURE(InitState());
2459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2460
2461 VkVertexInputBindingDescription input_binding;
2462 memset(&input_binding, 0, sizeof(input_binding));
2463
2464 VkVertexInputAttributeDescription input_attribs;
2465 memset(&input_attribs, 0, sizeof(input_attribs));
2466
2467 // Pick a really bad format for this purpose and make sure it should fail
2468 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2469 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2470 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2471 printf("Format unsuitable for test; skipped.\n");
2472 return;
2473 }
2474
2475 input_attribs.location = 0;
2476 char const *vsSource = "#version 450\n"
2477 "\n"
2478 "out gl_PerVertex {\n"
2479 " vec4 gl_Position;\n"
2480 "};\n"
2481 "void main(){\n"
2482 " gl_Position = vec4(1);\n"
2483 "}\n";
2484 char const *fsSource = "#version 450\n"
2485 "\n"
2486 "layout(location=0) out vec4 color;\n"
2487 "void main(){\n"
2488 " color = vec4(1);\n"
2489 "}\n";
2490
2491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2492 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2493 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2494
2495 VkPipelineObj pipe(m_device);
2496 pipe.AddColorAttachment();
2497 pipe.AddShader(&vs);
2498 pipe.AddShader(&fs);
2499
2500 pipe.AddVertexInputBindings(&input_binding, 1);
2501 pipe.AddVertexInputAttribs(&input_attribs, 1);
2502
2503 VkDescriptorSetObj descriptorSet(m_device);
2504 descriptorSet.AppendDummy();
2505 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2506
2507 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2508
2509 m_errorMonitor->VerifyFound();
2510}
2511
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002512TEST_F(VkLayerTest, ImageSampleCounts) {
2513
2514 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2515 "validation errors.");
2516 ASSERT_NO_FATAL_FAILURE(InitState());
2517
2518 VkMemoryPropertyFlags reqs = 0;
2519 VkImageCreateInfo image_create_info = {};
2520 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2521 image_create_info.pNext = NULL;
2522 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2523 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2524 image_create_info.extent.width = 256;
2525 image_create_info.extent.height = 256;
2526 image_create_info.extent.depth = 1;
2527 image_create_info.mipLevels = 1;
2528 image_create_info.arrayLayers = 1;
2529 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2530 image_create_info.flags = 0;
2531
2532 VkImageBlit blit_region = {};
2533 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2534 blit_region.srcSubresource.baseArrayLayer = 0;
2535 blit_region.srcSubresource.layerCount = 1;
2536 blit_region.srcSubresource.mipLevel = 0;
2537 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2538 blit_region.dstSubresource.baseArrayLayer = 0;
2539 blit_region.dstSubresource.layerCount = 1;
2540 blit_region.dstSubresource.mipLevel = 0;
2541
2542 // Create two images, the source with sampleCount = 2, and attempt to blit
2543 // between them
2544 {
2545 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002546 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002547 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002548 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002549 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002550 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002551 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002552 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002553 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2555 "of VK_SAMPLE_COUNT_2_BIT but "
2556 "must be VK_SAMPLE_COUNT_1_BIT");
2557 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2558 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002559 m_errorMonitor->VerifyFound();
2560 m_commandBuffer->EndCommandBuffer();
2561 }
2562
2563 // Create two images, the dest with sampleCount = 4, and attempt to blit
2564 // between them
2565 {
2566 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002567 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002568 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002569 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002570 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002571 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002572 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002573 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002574 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2576 "of VK_SAMPLE_COUNT_4_BIT but "
2577 "must be VK_SAMPLE_COUNT_1_BIT");
2578 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2579 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002580 m_errorMonitor->VerifyFound();
2581 m_commandBuffer->EndCommandBuffer();
2582 }
2583
2584 VkBufferImageCopy copy_region = {};
2585 copy_region.bufferRowLength = 128;
2586 copy_region.bufferImageHeight = 128;
2587 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2588 copy_region.imageSubresource.layerCount = 1;
2589 copy_region.imageExtent.height = 64;
2590 copy_region.imageExtent.width = 64;
2591 copy_region.imageExtent.depth = 1;
2592
2593 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2594 // buffer to image
2595 {
2596 vk_testing::Buffer src_buffer;
2597 VkMemoryPropertyFlags reqs = 0;
2598 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2599 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002600 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002601 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002602 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002603 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2605 "of VK_SAMPLE_COUNT_8_BIT but "
2606 "must be VK_SAMPLE_COUNT_1_BIT");
2607 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2608 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002609 m_errorMonitor->VerifyFound();
2610 m_commandBuffer->EndCommandBuffer();
2611 }
2612
2613 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2614 // image to buffer
2615 {
2616 vk_testing::Buffer dst_buffer;
2617 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2618 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002619 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002620 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002621 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002622 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2624 "of VK_SAMPLE_COUNT_2_BIT but "
2625 "must be VK_SAMPLE_COUNT_1_BIT");
2626 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002627 dst_buffer.handle(), 1, &copy_region);
2628 m_errorMonitor->VerifyFound();
2629 m_commandBuffer->EndCommandBuffer();
2630 }
2631}
2632
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002633TEST_F(VkLayerTest, BlitImageFormats) {
2634
2635 // Image blit with mismatched formats
2636 const char * expected_message =
2637 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2638 " the other one must also have signed/unsigned integer format";
2639
2640 ASSERT_NO_FATAL_FAILURE(InitState());
2641
2642 VkImageObj src_image(m_device);
2643 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2644 VkImageObj dst_image(m_device);
2645 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2646 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002647 dst_image2.init(64, 64, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002648
2649 VkImageBlit blitRegion = {};
2650 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2651 blitRegion.srcSubresource.baseArrayLayer = 0;
2652 blitRegion.srcSubresource.layerCount = 1;
2653 blitRegion.srcSubresource.mipLevel = 0;
2654 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2655 blitRegion.dstSubresource.baseArrayLayer = 0;
2656 blitRegion.dstSubresource.layerCount = 1;
2657 blitRegion.dstSubresource.mipLevel = 0;
2658
2659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2660
2661 // Unsigned int vs not an int
2662 BeginCommandBuffer();
2663 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2664 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2665
2666 m_errorMonitor->VerifyFound();
2667
2668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2669
2670 // Unsigned int vs signed int
2671 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2672 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2673
2674 m_errorMonitor->VerifyFound();
2675
2676 EndCommandBuffer();
2677}
2678
2679
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002680TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2681 VkResult err;
2682 bool pass;
2683
2684 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2685 ASSERT_NO_FATAL_FAILURE(InitState());
2686
2687 // If w/d/h granularity is 1, test is not meaningful
2688 // TODO: When virtual device limits are available, create a set of limits for this test that
2689 // will always have a granularity of > 1 for w, h, and d
2690 auto index = m_device->graphics_queue_node_index_;
2691 auto queue_family_properties = m_device->phy().queue_properties();
2692
2693 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2694 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2695 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2696 return;
2697 }
2698
2699 // Create two images of different types and try to copy between them
2700 VkImage srcImage;
2701 VkImage dstImage;
2702 VkDeviceMemory srcMem;
2703 VkDeviceMemory destMem;
2704 VkMemoryRequirements memReqs;
2705
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002706 VkImageCreateInfo image_create_info = {};
2707 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2708 image_create_info.pNext = NULL;
2709 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2710 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2711 image_create_info.extent.width = 32;
2712 image_create_info.extent.height = 32;
2713 image_create_info.extent.depth = 1;
2714 image_create_info.mipLevels = 1;
2715 image_create_info.arrayLayers = 4;
2716 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2717 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2718 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2719 image_create_info.flags = 0;
2720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002721 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002722 ASSERT_VK_SUCCESS(err);
2723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002724 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002725 ASSERT_VK_SUCCESS(err);
2726
2727 // Allocate memory
2728 VkMemoryAllocateInfo memAlloc = {};
2729 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2730 memAlloc.pNext = NULL;
2731 memAlloc.allocationSize = 0;
2732 memAlloc.memoryTypeIndex = 0;
2733
2734 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2735 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002736 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002737 ASSERT_TRUE(pass);
2738 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2739 ASSERT_VK_SUCCESS(err);
2740
2741 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2742 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002743 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002744 ASSERT_VK_SUCCESS(err);
2745 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2746 ASSERT_VK_SUCCESS(err);
2747
2748 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2749 ASSERT_VK_SUCCESS(err);
2750 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2751 ASSERT_VK_SUCCESS(err);
2752
2753 BeginCommandBuffer();
2754 VkImageCopy copyRegion;
2755 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2756 copyRegion.srcSubresource.mipLevel = 0;
2757 copyRegion.srcSubresource.baseArrayLayer = 0;
2758 copyRegion.srcSubresource.layerCount = 1;
2759 copyRegion.srcOffset.x = 0;
2760 copyRegion.srcOffset.y = 0;
2761 copyRegion.srcOffset.z = 0;
2762 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2763 copyRegion.dstSubresource.mipLevel = 0;
2764 copyRegion.dstSubresource.baseArrayLayer = 0;
2765 copyRegion.dstSubresource.layerCount = 1;
2766 copyRegion.dstOffset.x = 0;
2767 copyRegion.dstOffset.y = 0;
2768 copyRegion.dstOffset.z = 0;
2769 copyRegion.extent.width = 1;
2770 copyRegion.extent.height = 1;
2771 copyRegion.extent.depth = 1;
2772
2773 // Introduce failure by setting srcOffset to a bad granularity value
2774 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2776 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002777 m_errorMonitor->VerifyFound();
2778
2779 // Introduce failure by setting extent to a bad granularity value
2780 copyRegion.srcOffset.y = 0;
2781 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2783 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002784 m_errorMonitor->VerifyFound();
2785
2786 // Now do some buffer/image copies
2787 vk_testing::Buffer buffer;
2788 VkMemoryPropertyFlags reqs = 0;
2789 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2790 VkBufferImageCopy region = {};
2791 region.bufferOffset = 0;
2792 region.bufferRowLength = 3;
2793 region.bufferImageHeight = 128;
2794 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2795 region.imageSubresource.layerCount = 1;
2796 region.imageExtent.height = 16;
2797 region.imageExtent.width = 16;
2798 region.imageExtent.depth = 1;
2799 region.imageOffset.x = 0;
2800 region.imageOffset.y = 0;
2801 region.imageOffset.z = 0;
2802
2803 // Introduce failure by setting bufferRowLength to a bad granularity value
2804 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2806 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2807 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002808 m_errorMonitor->VerifyFound();
2809 region.bufferRowLength = 128;
2810
2811 // Introduce failure by setting bufferOffset to a bad granularity value
2812 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2814 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2815 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002816 m_errorMonitor->VerifyFound();
2817 region.bufferOffset = 0;
2818
2819 // Introduce failure by setting bufferImageHeight to a bad granularity value
2820 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2822 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2823 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002824 m_errorMonitor->VerifyFound();
2825 region.bufferImageHeight = 128;
2826
2827 // Introduce failure by setting imageExtent to a bad granularity value
2828 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2830 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2831 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002832 m_errorMonitor->VerifyFound();
2833 region.imageExtent.width = 16;
2834
2835 // Introduce failure by setting imageOffset to a bad granularity value
2836 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2838 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2839 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002840 m_errorMonitor->VerifyFound();
2841
2842 EndCommandBuffer();
2843
2844 vkDestroyImage(m_device->device(), srcImage, NULL);
2845 vkDestroyImage(m_device->device(), dstImage, NULL);
2846 vkFreeMemory(m_device->device(), srcMem, NULL);
2847 vkFreeMemory(m_device->device(), destMem, NULL);
2848}
2849
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002850TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002851 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2852 "attempt to submit them on a queue created in a different "
2853 "queue family.");
2854
Cody Northropc31a84f2016-08-22 10:41:47 -06002855 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002856 // This test is meaningless unless we have multiple queue families
2857 auto queue_family_properties = m_device->phy().queue_properties();
2858 if (queue_family_properties.size() < 2) {
2859 return;
2860 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002862 // Get safe index of another queue family
2863 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2864 ASSERT_NO_FATAL_FAILURE(InitState());
2865 // Create a second queue using a different queue family
2866 VkQueue other_queue;
2867 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2868
2869 // Record an empty cmd buffer
2870 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2871 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2872 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2873 vkEndCommandBuffer(m_commandBuffer->handle());
2874
2875 // And submit on the wrong queue
2876 VkSubmitInfo submit_info = {};
2877 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2878 submit_info.commandBufferCount = 1;
2879 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002880 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002881
2882 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002883}
2884
Chris Forbes4c24a922016-11-16 08:59:10 +13002885TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2886 ASSERT_NO_FATAL_FAILURE(InitState());
2887
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002888 // There are no attachments, but refer to attachment 0.
2889 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002890 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002891 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2892 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002893 };
2894
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002895 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2896 nullptr,
2897 0,
2898 0,
2899 nullptr,
2900 1,
2901 subpasses,
2902 0,
2903 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002904 VkRenderPass rp;
2905
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002906 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002908 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002909 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2910 m_errorMonitor->VerifyFound();
2911}
2912
Chris Forbesa58c4522016-09-28 15:19:39 +13002913TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2914 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2915 ASSERT_NO_FATAL_FAILURE(InitState());
2916
2917 // A renderpass with two subpasses, both writing the same attachment.
2918 VkAttachmentDescription attach[] = {
2919 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2920 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2921 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2922 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2923 },
2924 };
2925 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2926 VkSubpassDescription subpasses[] = {
2927 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2928 1, &ref, nullptr, nullptr, 0, nullptr },
2929 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2930 1, &ref, nullptr, nullptr, 0, nullptr },
2931 };
2932 VkSubpassDependency dep = {
2933 0, 1,
2934 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2935 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2936 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2937 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2938 VK_DEPENDENCY_BY_REGION_BIT
2939 };
2940 VkRenderPassCreateInfo rpci = {
2941 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2942 0, 1, attach, 2, subpasses, 1, &dep
2943 };
2944 VkRenderPass rp;
2945 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2946 ASSERT_VK_SUCCESS(err);
2947
2948 VkImageObj image(m_device);
2949 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2950 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2951 VK_IMAGE_TILING_OPTIMAL, 0);
2952 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2953
2954 VkFramebufferCreateInfo fbci = {
2955 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2956 0, rp, 1, &imageView, 32, 32, 1
2957 };
2958 VkFramebuffer fb;
2959 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2960 ASSERT_VK_SUCCESS(err);
2961
2962 char const *vsSource =
2963 "#version 450\n"
2964 "void main() { gl_Position = vec4(1); }\n";
2965 char const *fsSource =
2966 "#version 450\n"
2967 "layout(location=0) out vec4 color;\n"
2968 "void main() { color = vec4(1); }\n";
2969
2970 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2971 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2972 VkPipelineObj pipe(m_device);
2973 pipe.AddColorAttachment();
2974 pipe.AddShader(&vs);
2975 pipe.AddShader(&fs);
2976 VkViewport view_port = {};
2977 m_viewports.push_back(view_port);
2978 pipe.SetViewport(m_viewports);
2979 VkRect2D rect = {};
2980 m_scissors.push_back(rect);
2981 pipe.SetScissor(m_scissors);
2982
2983 VkPipelineLayoutCreateInfo plci = {
2984 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2985 0, 0, nullptr, 0, nullptr
2986 };
2987 VkPipelineLayout pl;
2988 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2989 ASSERT_VK_SUCCESS(err);
2990 pipe.CreateVKPipeline(pl, rp);
2991
2992 BeginCommandBuffer();
2993
2994 VkRenderPassBeginInfo rpbi = {
2995 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2996 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
2997 };
2998
2999 // subtest 1: bind in the wrong subpass
3000 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3001 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3003 "built for subpass 0 but used in subpass 1");
3004 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3005 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3006 m_errorMonitor->VerifyFound();
3007
3008 vkCmdEndRenderPass(m_commandBuffer->handle());
3009
3010 // subtest 2: bind in correct subpass, then transition to next subpass
3011 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3012 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3013 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3015 "built for subpass 0 but used in subpass 1");
3016 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3017 m_errorMonitor->VerifyFound();
3018
3019 vkCmdEndRenderPass(m_commandBuffer->handle());
3020
3021 EndCommandBuffer();
3022
3023 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3024 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3025 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3026}
3027
Tony Barbour4e919972016-08-09 13:27:40 -06003028TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3029 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3030 "with extent outside of framebuffer");
3031 ASSERT_NO_FATAL_FAILURE(InitState());
3032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3035 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003036
3037 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3038 m_renderPassBeginInfo.renderArea.extent.width = 257;
3039 m_renderPassBeginInfo.renderArea.extent.height = 257;
3040 BeginCommandBuffer();
3041 m_errorMonitor->VerifyFound();
3042}
3043
3044TEST_F(VkLayerTest, DisabledIndependentBlend) {
3045 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3046 "blend and then specifying different blend states for two "
3047 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003048 VkPhysicalDeviceFeatures features = {};
3049 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003050 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003051
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3053 "Invalid Pipeline CreateInfo: If independent blend feature not "
3054 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003055
Cody Northropc31a84f2016-08-22 10:41:47 -06003056 VkDescriptorSetObj descriptorSet(m_device);
3057 descriptorSet.AppendDummy();
3058 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003059
Cody Northropc31a84f2016-08-22 10:41:47 -06003060 VkPipelineObj pipeline(m_device);
3061 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003062 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003063 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003064
Cody Northropc31a84f2016-08-22 10:41:47 -06003065 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3066 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3067 att_state1.blendEnable = VK_TRUE;
3068 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3069 att_state2.blendEnable = VK_FALSE;
3070 pipeline.AddColorAttachment(0, &att_state1);
3071 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003072 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003073 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003074}
3075
3076TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3077 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3078 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003079 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003080
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3082 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003083
3084 // Create a renderPass with a single color attachment
3085 VkAttachmentReference attach = {};
3086 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3087 VkSubpassDescription subpass = {};
3088 VkRenderPassCreateInfo rpci = {};
3089 rpci.subpassCount = 1;
3090 rpci.pSubpasses = &subpass;
3091 rpci.attachmentCount = 1;
3092 VkAttachmentDescription attach_desc = {};
3093 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3094 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3095 rpci.pAttachments = &attach_desc;
3096 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3097 VkRenderPass rp;
3098 subpass.pDepthStencilAttachment = &attach;
3099 subpass.pColorAttachments = NULL;
3100 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3101 m_errorMonitor->VerifyFound();
3102}
3103
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003104TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3105 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3106 "attachment reference of VK_ATTACHMENT_UNUSED");
3107
3108 ASSERT_NO_FATAL_FAILURE(InitState());
3109 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3110
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003112
3113 VkAttachmentReference color_attach = {};
3114 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3115 color_attach.attachment = 0;
3116 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3117 VkSubpassDescription subpass = {};
3118 subpass.colorAttachmentCount = 1;
3119 subpass.pColorAttachments = &color_attach;
3120 subpass.preserveAttachmentCount = 1;
3121 subpass.pPreserveAttachments = &preserve_attachment;
3122
3123 VkRenderPassCreateInfo rpci = {};
3124 rpci.subpassCount = 1;
3125 rpci.pSubpasses = &subpass;
3126 rpci.attachmentCount = 1;
3127 VkAttachmentDescription attach_desc = {};
3128 attach_desc.format = VK_FORMAT_UNDEFINED;
3129 rpci.pAttachments = &attach_desc;
3130 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3131 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003132 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003133
3134 m_errorMonitor->VerifyFound();
3135
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003136 if (result == VK_SUCCESS) {
3137 vkDestroyRenderPass(m_device->device(), rp, NULL);
3138 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003139}
3140
Chris Forbesc5389742016-06-29 11:49:23 +12003141TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003142 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3143 "when the source of a subpass multisample resolve "
3144 "does not have multiple samples.");
3145
Chris Forbesc5389742016-06-29 11:49:23 +12003146 ASSERT_NO_FATAL_FAILURE(InitState());
3147
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3149 "Subpass 0 requests multisample resolve from attachment 0 which has "
3150 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003151
3152 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003153 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3154 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3155 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3156 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3157 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3158 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003159 };
3160
3161 VkAttachmentReference color = {
3162 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3163 };
3164
3165 VkAttachmentReference resolve = {
3166 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3167 };
3168
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003169 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003170
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003171 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003172
3173 VkRenderPass rp;
3174 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3175
3176 m_errorMonitor->VerifyFound();
3177
3178 if (err == VK_SUCCESS)
3179 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3180}
3181
3182TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003183 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3184 "when a subpass multisample resolve operation is "
3185 "requested, and the destination of that resolve has "
3186 "multiple samples.");
3187
Chris Forbesc5389742016-06-29 11:49:23 +12003188 ASSERT_NO_FATAL_FAILURE(InitState());
3189
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3191 "Subpass 0 requests multisample resolve into attachment 1, which "
3192 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003193
3194 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003195 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3196 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3197 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3198 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3199 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3200 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003201 };
3202
3203 VkAttachmentReference color = {
3204 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3205 };
3206
3207 VkAttachmentReference resolve = {
3208 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3209 };
3210
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003211 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003212
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003213 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003214
3215 VkRenderPass rp;
3216 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3217
3218 m_errorMonitor->VerifyFound();
3219
3220 if (err == VK_SUCCESS)
3221 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3222}
3223
Chris Forbes3f128ef2016-06-29 14:58:53 +12003224TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003225 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3226 "when the color and depth attachments used by a subpass "
3227 "have inconsistent sample counts");
3228
Chris Forbes3f128ef2016-06-29 14:58:53 +12003229 ASSERT_NO_FATAL_FAILURE(InitState());
3230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3232 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003233
3234 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003235 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3236 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3237 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3238 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3239 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3240 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003241 };
3242
3243 VkAttachmentReference color[] = {
3244 {
3245 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3246 },
3247 {
3248 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3249 },
3250 };
3251
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003252 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003253
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003254 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003255
3256 VkRenderPass rp;
3257 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3258
3259 m_errorMonitor->VerifyFound();
3260
3261 if (err == VK_SUCCESS)
3262 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3263}
3264
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003265TEST_F(VkLayerTest, FramebufferCreateErrors) {
3266 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003267 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003268 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003269 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3270 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3271 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3272 " 6. Framebuffer attachment where dimensions don't match\n"
3273 " 7. Framebuffer attachment w/o identity swizzle\n"
3274 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003275
3276 ASSERT_NO_FATAL_FAILURE(InitState());
3277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3278
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3280 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3281 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003282
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003283 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003284 VkAttachmentReference attach = {};
3285 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3286 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003287 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003288 VkRenderPassCreateInfo rpci = {};
3289 rpci.subpassCount = 1;
3290 rpci.pSubpasses = &subpass;
3291 rpci.attachmentCount = 1;
3292 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003293 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003294 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003295 rpci.pAttachments = &attach_desc;
3296 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3297 VkRenderPass rp;
3298 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3299 ASSERT_VK_SUCCESS(err);
3300
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003301 VkImageView ivs[2];
3302 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3303 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003304 VkFramebufferCreateInfo fb_info = {};
3305 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3306 fb_info.pNext = NULL;
3307 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003308 // Set mis-matching attachmentCount
3309 fb_info.attachmentCount = 2;
3310 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003311 fb_info.width = 100;
3312 fb_info.height = 100;
3313 fb_info.layers = 1;
3314
3315 VkFramebuffer fb;
3316 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3317
3318 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003319 if (err == VK_SUCCESS) {
3320 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3321 }
3322 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003323
3324 // Create a renderPass with a depth-stencil attachment created with
3325 // IMAGE_USAGE_COLOR_ATTACHMENT
3326 // Add our color attachment to pDepthStencilAttachment
3327 subpass.pDepthStencilAttachment = &attach;
3328 subpass.pColorAttachments = NULL;
3329 VkRenderPass rp_ds;
3330 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3331 ASSERT_VK_SUCCESS(err);
3332 // Set correct attachment count, but attachment has COLOR usage bit set
3333 fb_info.attachmentCount = 1;
3334 fb_info.renderPass = rp_ds;
3335
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003337 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3338
3339 m_errorMonitor->VerifyFound();
3340 if (err == VK_SUCCESS) {
3341 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3342 }
3343 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003344
3345 // Create new renderpass with alternate attachment format from fb
3346 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3347 subpass.pDepthStencilAttachment = NULL;
3348 subpass.pColorAttachments = &attach;
3349 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3350 ASSERT_VK_SUCCESS(err);
3351
3352 // Cause error due to mis-matched formats between rp & fb
3353 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3354 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3356 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003357 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3358
3359 m_errorMonitor->VerifyFound();
3360 if (err == VK_SUCCESS) {
3361 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3362 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003363 vkDestroyRenderPass(m_device->device(), rp, NULL);
3364
3365 // Create new renderpass with alternate sample count from fb
3366 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3367 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3368 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3369 ASSERT_VK_SUCCESS(err);
3370
3371 // Cause error due to mis-matched sample count between rp & fb
3372 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3374 "that do not match the "
3375 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003376 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3377
3378 m_errorMonitor->VerifyFound();
3379 if (err == VK_SUCCESS) {
3380 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3381 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003382
3383 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003384
3385 // Create a custom imageView with non-1 mip levels
3386 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003387 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003388 ASSERT_TRUE(image.initialized());
3389
3390 VkImageView view;
3391 VkImageViewCreateInfo ivci = {};
3392 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3393 ivci.image = image.handle();
3394 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3395 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3396 ivci.subresourceRange.layerCount = 1;
3397 ivci.subresourceRange.baseMipLevel = 0;
3398 // Set level count 2 (only 1 is allowed for FB attachment)
3399 ivci.subresourceRange.levelCount = 2;
3400 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3401 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3402 ASSERT_VK_SUCCESS(err);
3403 // Re-create renderpass to have matching sample count
3404 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3405 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3406 ASSERT_VK_SUCCESS(err);
3407
3408 fb_info.renderPass = rp;
3409 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003411 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3412
3413 m_errorMonitor->VerifyFound();
3414 if (err == VK_SUCCESS) {
3415 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3416 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003417 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003418 // Update view to original color buffer and grow FB dimensions too big
3419 fb_info.pAttachments = ivs;
3420 fb_info.height = 1024;
3421 fb_info.width = 1024;
3422 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3424 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003425 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3426
3427 m_errorMonitor->VerifyFound();
3428 if (err == VK_SUCCESS) {
3429 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3430 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003431 // Create view attachment with non-identity swizzle
3432 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3433 ivci.image = image.handle();
3434 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3435 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3436 ivci.subresourceRange.layerCount = 1;
3437 ivci.subresourceRange.baseMipLevel = 0;
3438 ivci.subresourceRange.levelCount = 1;
3439 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3440 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3441 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3442 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3443 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3444 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3445 ASSERT_VK_SUCCESS(err);
3446
3447 fb_info.pAttachments = &view;
3448 fb_info.height = 100;
3449 fb_info.width = 100;
3450 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3452 "framebuffer attachments must have "
3453 "been created with the identity "
3454 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003455 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3456
3457 m_errorMonitor->VerifyFound();
3458 if (err == VK_SUCCESS) {
3459 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3460 }
3461 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003462 // Request fb that exceeds max dimensions
3463 // reset attachment to color attachment
3464 fb_info.pAttachments = ivs;
3465 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3466 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3467 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3469 "dimensions exceed physical device "
3470 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003471 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3472
3473 m_errorMonitor->VerifyFound();
3474 if (err == VK_SUCCESS) {
3475 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3476 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003477
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003478 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003479}
3480
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003481TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003482 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3483 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003484
Cody Northropc31a84f2016-08-22 10:41:47 -06003485 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003486 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3488 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003489 m_errorMonitor->VerifyFound();
3490}
3491
3492TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003493 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3494 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003495
Cody Northropc31a84f2016-08-22 10:41:47 -06003496 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003497 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3499 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003500 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003501}
3502
3503TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003504 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3505 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003506
Cody Northropc31a84f2016-08-22 10:41:47 -06003507 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003508 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003510 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003511 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003512}
3513
3514TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003515 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3516 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003517
Cody Northropc31a84f2016-08-22 10:41:47 -06003518 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003519 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003521 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003522 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003523}
3524
Cortd713fe82016-07-27 09:51:27 -07003525TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003526 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3527 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003528
3529 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003530 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3532 "Dynamic blend constants state not set for this command buffer");
3533 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003534 m_errorMonitor->VerifyFound();
3535}
3536
3537TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003538 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3539 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003540
3541 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003542 if (!m_device->phy().features().depthBounds) {
3543 printf("Device does not support depthBounds test; skipped.\n");
3544 return;
3545 }
3546 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3548 "Dynamic depth bounds state not set for this command buffer");
3549 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003550 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003551}
3552
3553TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003554 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3555 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003556
3557 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003558 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3560 "Dynamic stencil read mask state not set for this command buffer");
3561 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003562 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003563}
3564
3565TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003566 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3567 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003568
3569 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003570 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3572 "Dynamic stencil write mask state not set for this command buffer");
3573 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003574 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003575}
3576
3577TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003578 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3579 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003580
3581 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003582 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3584 "Dynamic stencil reference state not set for this command buffer");
3585 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003586 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003587}
3588
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003589TEST_F(VkLayerTest, IndexBufferNotBound) {
3590 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003591
3592 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3594 "Index buffer object not bound to this command buffer when Indexed ");
3595 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003596 m_errorMonitor->VerifyFound();
3597}
3598
Karl Schultz6addd812016-02-02 17:17:23 -07003599TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3601 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3602 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003603
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003604 ASSERT_NO_FATAL_FAILURE(InitState());
3605 ASSERT_NO_FATAL_FAILURE(InitViewport());
3606 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3607
Karl Schultz6addd812016-02-02 17:17:23 -07003608 // We luck out b/c by default the framework creates CB w/ the
3609 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003610 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003611 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003612 EndCommandBuffer();
3613
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003614 // Bypass framework since it does the waits automatically
3615 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003616 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003617 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3618 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003619 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003620 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003621 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003622 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003623 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003624 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003625 submit_info.pSignalSemaphores = NULL;
3626
Chris Forbes40028e22016-06-13 09:59:34 +12003627 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003628 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003629 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003630
Karl Schultz6addd812016-02-02 17:17:23 -07003631 // Cause validation error by re-submitting cmd buffer that should only be
3632 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003633 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003634 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003635
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003636 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003637}
3638
Karl Schultz6addd812016-02-02 17:17:23 -07003639TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003640 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07003641 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003642
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
3644 "type "
3645 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003646
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003647 ASSERT_NO_FATAL_FAILURE(InitState());
3648 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003649
Karl Schultz6addd812016-02-02 17:17:23 -07003650 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3651 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003652 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003653 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3654 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003655
3656 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003657 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3658 ds_pool_ci.pNext = NULL;
3659 ds_pool_ci.flags = 0;
3660 ds_pool_ci.maxSets = 1;
3661 ds_pool_ci.poolSizeCount = 1;
3662 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003663
3664 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003665 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003666 ASSERT_VK_SUCCESS(err);
3667
3668 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003669 dsl_binding.binding = 0;
3670 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3671 dsl_binding.descriptorCount = 1;
3672 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3673 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003674
3675 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003676 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3677 ds_layout_ci.pNext = NULL;
3678 ds_layout_ci.bindingCount = 1;
3679 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003680
3681 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003682 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003683 ASSERT_VK_SUCCESS(err);
3684
3685 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003686 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003687 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003688 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003689 alloc_info.descriptorPool = ds_pool;
3690 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003691 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003692
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003693 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003694
Chia-I Wuf7458c52015-10-26 21:10:41 +08003695 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3696 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003697}
3698
Karl Schultz6addd812016-02-02 17:17:23 -07003699TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3700 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003701
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3703 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3704 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003705
Tobin Ehlise735c692015-10-08 13:13:50 -06003706 ASSERT_NO_FATAL_FAILURE(InitState());
3707 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003708
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003709 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003710 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3711 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003712
3713 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003714 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3715 ds_pool_ci.pNext = NULL;
3716 ds_pool_ci.maxSets = 1;
3717 ds_pool_ci.poolSizeCount = 1;
3718 ds_pool_ci.flags = 0;
3719 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3720 // app can only call vkResetDescriptorPool on this pool.;
3721 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003722
3723 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003724 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003725 ASSERT_VK_SUCCESS(err);
3726
3727 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003728 dsl_binding.binding = 0;
3729 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3730 dsl_binding.descriptorCount = 1;
3731 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3732 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003733
3734 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003735 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3736 ds_layout_ci.pNext = NULL;
3737 ds_layout_ci.bindingCount = 1;
3738 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003739
3740 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003741 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003742 ASSERT_VK_SUCCESS(err);
3743
3744 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003745 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003746 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003747 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003748 alloc_info.descriptorPool = ds_pool;
3749 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003750 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003751 ASSERT_VK_SUCCESS(err);
3752
3753 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003754 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003755
Chia-I Wuf7458c52015-10-26 21:10:41 +08003756 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3757 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003758}
3759
Karl Schultz6addd812016-02-02 17:17:23 -07003760TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003761 // Attempt to clear Descriptor Pool with bad object.
3762 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003763
3764 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003766 uint64_t fake_pool_handle = 0xbaad6001;
3767 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3768 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003769 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003770}
3771
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003772TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003773 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3774 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003775 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003776 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003777
3778 uint64_t fake_set_handle = 0xbaad6001;
3779 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003780 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003782
3783 ASSERT_NO_FATAL_FAILURE(InitState());
3784
3785 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3786 layout_bindings[0].binding = 0;
3787 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3788 layout_bindings[0].descriptorCount = 1;
3789 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3790 layout_bindings[0].pImmutableSamplers = NULL;
3791
3792 VkDescriptorSetLayout descriptor_set_layout;
3793 VkDescriptorSetLayoutCreateInfo dslci = {};
3794 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3795 dslci.pNext = NULL;
3796 dslci.bindingCount = 1;
3797 dslci.pBindings = layout_bindings;
3798 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003799 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003800
3801 VkPipelineLayout pipeline_layout;
3802 VkPipelineLayoutCreateInfo plci = {};
3803 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3804 plci.pNext = NULL;
3805 plci.setLayoutCount = 1;
3806 plci.pSetLayouts = &descriptor_set_layout;
3807 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003808 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003809
3810 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003811 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3812 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003813 m_errorMonitor->VerifyFound();
3814 EndCommandBuffer();
3815 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3816 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003817}
3818
Karl Schultz6addd812016-02-02 17:17:23 -07003819TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003820 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3821 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003822 uint64_t fake_layout_handle = 0xbaad6001;
3823 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003825 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003826 VkPipelineLayout pipeline_layout;
3827 VkPipelineLayoutCreateInfo plci = {};
3828 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3829 plci.pNext = NULL;
3830 plci.setLayoutCount = 1;
3831 plci.pSetLayouts = &bad_layout;
3832 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3833
3834 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003835}
3836
Mark Muellerd4914412016-06-13 17:52:06 -06003837TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3838 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3839 "1) A uniform buffer update must have a valid buffer index."
3840 "2) When using an array of descriptors in a single WriteDescriptor,"
3841 " the descriptor types and stageflags must all be the same."
3842 "3) Immutable Sampler state must match across descriptors");
3843
3844 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003845 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3846 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3847 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3848 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3849 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003850
Mark Muellerd4914412016-06-13 17:52:06 -06003851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3852
3853 ASSERT_NO_FATAL_FAILURE(InitState());
3854 VkDescriptorPoolSize ds_type_count[4] = {};
3855 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3856 ds_type_count[0].descriptorCount = 1;
3857 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3858 ds_type_count[1].descriptorCount = 1;
3859 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3860 ds_type_count[2].descriptorCount = 1;
3861 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3862 ds_type_count[3].descriptorCount = 1;
3863
3864 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3865 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3866 ds_pool_ci.maxSets = 1;
3867 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3868 ds_pool_ci.pPoolSizes = ds_type_count;
3869
3870 VkDescriptorPool ds_pool;
3871 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3872 ASSERT_VK_SUCCESS(err);
3873
Mark Muellerb9896722016-06-16 09:54:29 -06003874 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003875 layout_binding[0].binding = 0;
3876 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3877 layout_binding[0].descriptorCount = 1;
3878 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3879 layout_binding[0].pImmutableSamplers = NULL;
3880
3881 layout_binding[1].binding = 1;
3882 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3883 layout_binding[1].descriptorCount = 1;
3884 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3885 layout_binding[1].pImmutableSamplers = NULL;
3886
3887 VkSamplerCreateInfo sampler_ci = {};
3888 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3889 sampler_ci.pNext = NULL;
3890 sampler_ci.magFilter = VK_FILTER_NEAREST;
3891 sampler_ci.minFilter = VK_FILTER_NEAREST;
3892 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3893 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3894 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3895 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3896 sampler_ci.mipLodBias = 1.0;
3897 sampler_ci.anisotropyEnable = VK_FALSE;
3898 sampler_ci.maxAnisotropy = 1;
3899 sampler_ci.compareEnable = VK_FALSE;
3900 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3901 sampler_ci.minLod = 1.0;
3902 sampler_ci.maxLod = 1.0;
3903 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3904 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3905 VkSampler sampler;
3906
3907 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3908 ASSERT_VK_SUCCESS(err);
3909
3910 layout_binding[2].binding = 2;
3911 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3912 layout_binding[2].descriptorCount = 1;
3913 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3914 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3915
Mark Muellerd4914412016-06-13 17:52:06 -06003916 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3917 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3918 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3919 ds_layout_ci.pBindings = layout_binding;
3920 VkDescriptorSetLayout ds_layout;
3921 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3922 ASSERT_VK_SUCCESS(err);
3923
3924 VkDescriptorSetAllocateInfo alloc_info = {};
3925 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3926 alloc_info.descriptorSetCount = 1;
3927 alloc_info.descriptorPool = ds_pool;
3928 alloc_info.pSetLayouts = &ds_layout;
3929 VkDescriptorSet descriptorSet;
3930 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3931 ASSERT_VK_SUCCESS(err);
3932
3933 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3934 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3935 pipeline_layout_ci.pNext = NULL;
3936 pipeline_layout_ci.setLayoutCount = 1;
3937 pipeline_layout_ci.pSetLayouts = &ds_layout;
3938
3939 VkPipelineLayout pipeline_layout;
3940 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3941 ASSERT_VK_SUCCESS(err);
3942
Mark Mueller5c838ce2016-06-16 09:54:29 -06003943 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003944 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3945 descriptor_write.dstSet = descriptorSet;
3946 descriptor_write.dstBinding = 0;
3947 descriptor_write.descriptorCount = 1;
3948 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3949
Mark Mueller5c838ce2016-06-16 09:54:29 -06003950 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003951 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3952 m_errorMonitor->VerifyFound();
3953
3954 // Create a buffer to update the descriptor with
3955 uint32_t qfi = 0;
3956 VkBufferCreateInfo buffCI = {};
3957 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3958 buffCI.size = 1024;
3959 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3960 buffCI.queueFamilyIndexCount = 1;
3961 buffCI.pQueueFamilyIndices = &qfi;
3962
3963 VkBuffer dyub;
3964 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3965 ASSERT_VK_SUCCESS(err);
3966 VkDescriptorBufferInfo buffInfo = {};
3967 buffInfo.buffer = dyub;
3968 buffInfo.offset = 0;
3969 buffInfo.range = 1024;
3970
3971 descriptor_write.pBufferInfo = &buffInfo;
3972 descriptor_write.descriptorCount = 2;
3973
Mark Mueller5c838ce2016-06-16 09:54:29 -06003974 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3976 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3977 m_errorMonitor->VerifyFound();
3978
Mark Mueller5c838ce2016-06-16 09:54:29 -06003979 // 3) The second descriptor has a null_ptr pImmutableSamplers and
3980 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06003981 descriptor_write.dstBinding = 1;
3982 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06003983
Mark Mueller5c838ce2016-06-16 09:54:29 -06003984 // Make pImageInfo index non-null to avoid complaints of it missing
3985 VkDescriptorImageInfo imageInfo = {};
3986 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3987 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06003988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
3989 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3990 m_errorMonitor->VerifyFound();
3991
Mark Muellerd4914412016-06-13 17:52:06 -06003992 vkDestroyBuffer(m_device->device(), dyub, NULL);
3993 vkDestroySampler(m_device->device(), sampler, NULL);
3994 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3995 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3996 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3997}
3998
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003999TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4000 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4001 "due to a buffer dependency being destroyed.");
4002 ASSERT_NO_FATAL_FAILURE(InitState());
4003
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004004 VkBuffer buffer;
4005 VkDeviceMemory mem;
4006 VkMemoryRequirements mem_reqs;
4007
4008 VkBufferCreateInfo buf_info = {};
4009 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004010 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004011 buf_info.size = 256;
4012 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4013 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4014 ASSERT_VK_SUCCESS(err);
4015
4016 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4017
4018 VkMemoryAllocateInfo alloc_info = {};
4019 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4020 alloc_info.allocationSize = 256;
4021 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004022 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004023 if (!pass) {
4024 vkDestroyBuffer(m_device->device(), buffer, NULL);
4025 return;
4026 }
4027 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4028 ASSERT_VK_SUCCESS(err);
4029
4030 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4031 ASSERT_VK_SUCCESS(err);
4032
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004033 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004034 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004035 m_commandBuffer->EndCommandBuffer();
4036
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004038 // Destroy buffer dependency prior to submit to cause ERROR
4039 vkDestroyBuffer(m_device->device(), buffer, NULL);
4040
4041 VkSubmitInfo submit_info = {};
4042 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4043 submit_info.commandBufferCount = 1;
4044 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4045 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4046
4047 m_errorMonitor->VerifyFound();
4048 vkFreeMemory(m_device->handle(), mem, NULL);
4049}
4050
Tobin Ehlisea413442016-09-28 10:23:59 -06004051TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4052 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4053
4054 ASSERT_NO_FATAL_FAILURE(InitState());
4055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4056
4057 VkDescriptorPoolSize ds_type_count;
4058 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4059 ds_type_count.descriptorCount = 1;
4060
4061 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4062 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4063 ds_pool_ci.maxSets = 1;
4064 ds_pool_ci.poolSizeCount = 1;
4065 ds_pool_ci.pPoolSizes = &ds_type_count;
4066
4067 VkDescriptorPool ds_pool;
4068 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4069 ASSERT_VK_SUCCESS(err);
4070
4071 VkDescriptorSetLayoutBinding layout_binding;
4072 layout_binding.binding = 0;
4073 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4074 layout_binding.descriptorCount = 1;
4075 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4076 layout_binding.pImmutableSamplers = NULL;
4077
4078 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4079 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4080 ds_layout_ci.bindingCount = 1;
4081 ds_layout_ci.pBindings = &layout_binding;
4082 VkDescriptorSetLayout ds_layout;
4083 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4084 ASSERT_VK_SUCCESS(err);
4085
4086 VkDescriptorSetAllocateInfo alloc_info = {};
4087 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4088 alloc_info.descriptorSetCount = 1;
4089 alloc_info.descriptorPool = ds_pool;
4090 alloc_info.pSetLayouts = &ds_layout;
4091 VkDescriptorSet descriptor_set;
4092 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4093 ASSERT_VK_SUCCESS(err);
4094
4095 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4096 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4097 pipeline_layout_ci.pNext = NULL;
4098 pipeline_layout_ci.setLayoutCount = 1;
4099 pipeline_layout_ci.pSetLayouts = &ds_layout;
4100
4101 VkPipelineLayout pipeline_layout;
4102 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4103 ASSERT_VK_SUCCESS(err);
4104
4105 VkBuffer buffer;
4106 uint32_t queue_family_index = 0;
4107 VkBufferCreateInfo buffer_create_info = {};
4108 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4109 buffer_create_info.size = 1024;
4110 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4111 buffer_create_info.queueFamilyIndexCount = 1;
4112 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4113
4114 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4115 ASSERT_VK_SUCCESS(err);
4116
4117 VkMemoryRequirements memory_reqs;
4118 VkDeviceMemory buffer_memory;
4119
4120 VkMemoryAllocateInfo memory_info = {};
4121 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4122 memory_info.allocationSize = 0;
4123 memory_info.memoryTypeIndex = 0;
4124
4125 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4126 memory_info.allocationSize = memory_reqs.size;
4127 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4128 ASSERT_TRUE(pass);
4129
4130 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4131 ASSERT_VK_SUCCESS(err);
4132 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4133 ASSERT_VK_SUCCESS(err);
4134
4135 VkBufferView view;
4136 VkBufferViewCreateInfo bvci = {};
4137 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4138 bvci.buffer = buffer;
4139 bvci.format = VK_FORMAT_R8_UNORM;
4140 bvci.range = VK_WHOLE_SIZE;
4141
4142 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4143 ASSERT_VK_SUCCESS(err);
4144
4145 VkWriteDescriptorSet descriptor_write = {};
4146 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4147 descriptor_write.dstSet = descriptor_set;
4148 descriptor_write.dstBinding = 0;
4149 descriptor_write.descriptorCount = 1;
4150 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4151 descriptor_write.pTexelBufferView = &view;
4152
4153 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4154
4155 char const *vsSource = "#version 450\n"
4156 "\n"
4157 "out gl_PerVertex { \n"
4158 " vec4 gl_Position;\n"
4159 "};\n"
4160 "void main(){\n"
4161 " gl_Position = vec4(1);\n"
4162 "}\n";
4163 char const *fsSource = "#version 450\n"
4164 "\n"
4165 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4166 "layout(location=0) out vec4 x;\n"
4167 "void main(){\n"
4168 " x = imageLoad(s, 0);\n"
4169 "}\n";
4170 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4171 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4172 VkPipelineObj pipe(m_device);
4173 pipe.AddShader(&vs);
4174 pipe.AddShader(&fs);
4175 pipe.AddColorAttachment();
4176 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4177
4178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4180
4181 BeginCommandBuffer();
4182 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4183 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4184 VkRect2D scissor = {{0, 0}, {16, 16}};
4185 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4186 // Bind pipeline to cmd buffer
4187 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4188 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4189 &descriptor_set, 0, nullptr);
4190 Draw(1, 0, 0, 0);
4191 EndCommandBuffer();
4192
4193 // Delete BufferView in order to invalidate cmd buffer
4194 vkDestroyBufferView(m_device->device(), view, NULL);
4195 // Now attempt submit of cmd buffer
4196 VkSubmitInfo submit_info = {};
4197 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4198 submit_info.commandBufferCount = 1;
4199 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4200 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4201 m_errorMonitor->VerifyFound();
4202
4203 // Clean-up
4204 vkDestroyBuffer(m_device->device(), buffer, NULL);
4205 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4206 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4207 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4208 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4209}
4210
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004211TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4212 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4213 "due to an image dependency being destroyed.");
4214 ASSERT_NO_FATAL_FAILURE(InitState());
4215
4216 VkImage image;
4217 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4218 VkImageCreateInfo image_create_info = {};
4219 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4220 image_create_info.pNext = NULL;
4221 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4222 image_create_info.format = tex_format;
4223 image_create_info.extent.width = 32;
4224 image_create_info.extent.height = 32;
4225 image_create_info.extent.depth = 1;
4226 image_create_info.mipLevels = 1;
4227 image_create_info.arrayLayers = 1;
4228 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4229 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004230 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004231 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004232 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004233 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004234 // Have to bind memory to image before recording cmd in cmd buffer using it
4235 VkMemoryRequirements mem_reqs;
4236 VkDeviceMemory image_mem;
4237 bool pass;
4238 VkMemoryAllocateInfo mem_alloc = {};
4239 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4240 mem_alloc.pNext = NULL;
4241 mem_alloc.memoryTypeIndex = 0;
4242 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4243 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004244 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004245 ASSERT_TRUE(pass);
4246 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4247 ASSERT_VK_SUCCESS(err);
4248 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4249 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004250
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004251 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004252 VkClearColorValue ccv;
4253 ccv.float32[0] = 1.0f;
4254 ccv.float32[1] = 1.0f;
4255 ccv.float32[2] = 1.0f;
4256 ccv.float32[3] = 1.0f;
4257 VkImageSubresourceRange isr = {};
4258 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004259 isr.baseArrayLayer = 0;
4260 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004261 isr.layerCount = 1;
4262 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004263 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004264 m_commandBuffer->EndCommandBuffer();
4265
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004267 // Destroy image dependency prior to submit to cause ERROR
4268 vkDestroyImage(m_device->device(), image, NULL);
4269
4270 VkSubmitInfo submit_info = {};
4271 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4272 submit_info.commandBufferCount = 1;
4273 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4274 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4275
4276 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004277 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004278}
4279
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004280TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4281 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4282 "due to a framebuffer image dependency being destroyed.");
4283 VkFormatProperties format_properties;
4284 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004285 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4286 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004287 return;
4288 }
4289
4290 ASSERT_NO_FATAL_FAILURE(InitState());
4291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4292
4293 VkImageCreateInfo image_ci = {};
4294 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4295 image_ci.pNext = NULL;
4296 image_ci.imageType = VK_IMAGE_TYPE_2D;
4297 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4298 image_ci.extent.width = 32;
4299 image_ci.extent.height = 32;
4300 image_ci.extent.depth = 1;
4301 image_ci.mipLevels = 1;
4302 image_ci.arrayLayers = 1;
4303 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4304 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004305 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004306 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4307 image_ci.flags = 0;
4308 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004309 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004310
4311 VkMemoryRequirements memory_reqs;
4312 VkDeviceMemory image_memory;
4313 bool pass;
4314 VkMemoryAllocateInfo memory_info = {};
4315 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4316 memory_info.pNext = NULL;
4317 memory_info.allocationSize = 0;
4318 memory_info.memoryTypeIndex = 0;
4319 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4320 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004321 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004322 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004323 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004324 ASSERT_VK_SUCCESS(err);
4325 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4326 ASSERT_VK_SUCCESS(err);
4327
4328 VkImageViewCreateInfo ivci = {
4329 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4330 nullptr,
4331 0,
4332 image,
4333 VK_IMAGE_VIEW_TYPE_2D,
4334 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004335 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004336 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4337 };
4338 VkImageView view;
4339 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4340 ASSERT_VK_SUCCESS(err);
4341
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004342 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004343 VkFramebuffer fb;
4344 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4345 ASSERT_VK_SUCCESS(err);
4346
4347 // Just use default renderpass with our framebuffer
4348 m_renderPassBeginInfo.framebuffer = fb;
4349 // Create Null cmd buffer for submit
4350 BeginCommandBuffer();
4351 EndCommandBuffer();
4352 // Destroy image attached to framebuffer to invalidate cmd buffer
4353 vkDestroyImage(m_device->device(), image, NULL);
4354 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004356 QueueCommandBuffer(false);
4357 m_errorMonitor->VerifyFound();
4358
4359 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4360 vkDestroyImageView(m_device->device(), view, nullptr);
4361 vkFreeMemory(m_device->device(), image_memory, nullptr);
4362}
4363
Tobin Ehlisb329f992016-10-12 13:20:29 -06004364TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4365 TEST_DESCRIPTION("Delete in-use framebuffer.");
4366 VkFormatProperties format_properties;
4367 VkResult err = VK_SUCCESS;
4368 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4369
4370 ASSERT_NO_FATAL_FAILURE(InitState());
4371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4372
4373 VkImageObj image(m_device);
4374 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4375 ASSERT_TRUE(image.initialized());
4376 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4377
4378 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4379 VkFramebuffer fb;
4380 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4381 ASSERT_VK_SUCCESS(err);
4382
4383 // Just use default renderpass with our framebuffer
4384 m_renderPassBeginInfo.framebuffer = fb;
4385 // Create Null cmd buffer for submit
4386 BeginCommandBuffer();
4387 EndCommandBuffer();
4388 // Submit cmd buffer to put it in-flight
4389 VkSubmitInfo submit_info = {};
4390 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4391 submit_info.commandBufferCount = 1;
4392 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4393 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4394 // Destroy framebuffer while in-flight
4395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4396 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4397 m_errorMonitor->VerifyFound();
4398 // Wait for queue to complete so we can safely destroy everything
4399 vkQueueWaitIdle(m_device->m_queue);
4400 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4401}
4402
Tobin Ehlis88becd72016-09-21 14:33:41 -06004403TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4404 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4405 VkFormatProperties format_properties;
4406 VkResult err = VK_SUCCESS;
4407 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004408
4409 ASSERT_NO_FATAL_FAILURE(InitState());
4410 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4411
4412 VkImageCreateInfo image_ci = {};
4413 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4414 image_ci.pNext = NULL;
4415 image_ci.imageType = VK_IMAGE_TYPE_2D;
4416 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4417 image_ci.extent.width = 256;
4418 image_ci.extent.height = 256;
4419 image_ci.extent.depth = 1;
4420 image_ci.mipLevels = 1;
4421 image_ci.arrayLayers = 1;
4422 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4423 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004424 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004425 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4426 image_ci.flags = 0;
4427 VkImage image;
4428 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4429
4430 VkMemoryRequirements memory_reqs;
4431 VkDeviceMemory image_memory;
4432 bool pass;
4433 VkMemoryAllocateInfo memory_info = {};
4434 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4435 memory_info.pNext = NULL;
4436 memory_info.allocationSize = 0;
4437 memory_info.memoryTypeIndex = 0;
4438 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4439 memory_info.allocationSize = memory_reqs.size;
4440 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4441 ASSERT_TRUE(pass);
4442 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4443 ASSERT_VK_SUCCESS(err);
4444 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4445 ASSERT_VK_SUCCESS(err);
4446
4447 VkImageViewCreateInfo ivci = {
4448 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4449 nullptr,
4450 0,
4451 image,
4452 VK_IMAGE_VIEW_TYPE_2D,
4453 VK_FORMAT_B8G8R8A8_UNORM,
4454 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4455 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4456 };
4457 VkImageView view;
4458 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4459 ASSERT_VK_SUCCESS(err);
4460
4461 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4462 VkFramebuffer fb;
4463 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4464 ASSERT_VK_SUCCESS(err);
4465
4466 // Just use default renderpass with our framebuffer
4467 m_renderPassBeginInfo.framebuffer = fb;
4468 // Create Null cmd buffer for submit
4469 BeginCommandBuffer();
4470 EndCommandBuffer();
4471 // Submit cmd buffer to put it (and attached imageView) in-flight
4472 VkSubmitInfo submit_info = {};
4473 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4474 submit_info.commandBufferCount = 1;
4475 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4476 // Submit cmd buffer to put framebuffer and children in-flight
4477 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4478 // Destroy image attached to framebuffer while in-flight
4479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4480 vkDestroyImage(m_device->device(), image, NULL);
4481 m_errorMonitor->VerifyFound();
4482 // Wait for queue to complete so we can safely destroy image and other objects
4483 vkQueueWaitIdle(m_device->m_queue);
4484 vkDestroyImage(m_device->device(), image, NULL);
4485 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4486 vkDestroyImageView(m_device->device(), view, nullptr);
4487 vkFreeMemory(m_device->device(), image_memory, nullptr);
4488}
4489
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004490TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4491 TEST_DESCRIPTION("Delete in-use renderPass.");
4492
4493 ASSERT_NO_FATAL_FAILURE(InitState());
4494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4495
4496 // Create simple renderpass
4497 VkAttachmentReference attach = {};
4498 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4499 VkSubpassDescription subpass = {};
4500 subpass.pColorAttachments = &attach;
4501 VkRenderPassCreateInfo rpci = {};
4502 rpci.subpassCount = 1;
4503 rpci.pSubpasses = &subpass;
4504 rpci.attachmentCount = 1;
4505 VkAttachmentDescription attach_desc = {};
4506 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4507 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4508 rpci.pAttachments = &attach_desc;
4509 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4510 VkRenderPass rp;
4511 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4512 ASSERT_VK_SUCCESS(err);
4513
4514 // Create a pipeline that uses the given renderpass
4515 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4516 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4517
4518 VkPipelineLayout pipeline_layout;
4519 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4520 ASSERT_VK_SUCCESS(err);
4521
4522 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4523 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4524 vp_state_ci.viewportCount = 1;
4525 VkViewport vp = {}; // Just need dummy vp to point to
4526 vp_state_ci.pViewports = &vp;
4527 vp_state_ci.scissorCount = 1;
4528 VkRect2D scissors = {}; // Dummy scissors to point to
4529 vp_state_ci.pScissors = &scissors;
4530
4531 VkPipelineShaderStageCreateInfo shaderStages[2];
4532 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4533
4534 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4535 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4536 // but add it to be able to run on more devices
4537 shaderStages[0] = vs.GetStageCreateInfo();
4538 shaderStages[1] = fs.GetStageCreateInfo();
4539
4540 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4541 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4542
4543 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4544 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4545 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4546
4547 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4548 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4549 rs_ci.rasterizerDiscardEnable = true;
4550 rs_ci.lineWidth = 1.0f;
4551
4552 VkPipelineColorBlendAttachmentState att = {};
4553 att.blendEnable = VK_FALSE;
4554 att.colorWriteMask = 0xf;
4555
4556 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4557 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4558 cb_ci.attachmentCount = 1;
4559 cb_ci.pAttachments = &att;
4560
4561 VkGraphicsPipelineCreateInfo gp_ci = {};
4562 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4563 gp_ci.stageCount = 2;
4564 gp_ci.pStages = shaderStages;
4565 gp_ci.pVertexInputState = &vi_ci;
4566 gp_ci.pInputAssemblyState = &ia_ci;
4567 gp_ci.pViewportState = &vp_state_ci;
4568 gp_ci.pRasterizationState = &rs_ci;
4569 gp_ci.pColorBlendState = &cb_ci;
4570 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4571 gp_ci.layout = pipeline_layout;
4572 gp_ci.renderPass = rp;
4573
4574 VkPipelineCacheCreateInfo pc_ci = {};
4575 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4576
4577 VkPipeline pipeline;
4578 VkPipelineCache pipe_cache;
4579 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4580 ASSERT_VK_SUCCESS(err);
4581
4582 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4583 ASSERT_VK_SUCCESS(err);
4584 // Bind pipeline to cmd buffer, will also bind renderpass
4585 m_commandBuffer->BeginCommandBuffer();
4586 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4587 m_commandBuffer->EndCommandBuffer();
4588
4589 VkSubmitInfo submit_info = {};
4590 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4591 submit_info.commandBufferCount = 1;
4592 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4593 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4594
4595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4596 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4597 m_errorMonitor->VerifyFound();
4598
4599 // Wait for queue to complete so we can safely destroy everything
4600 vkQueueWaitIdle(m_device->m_queue);
4601 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4602 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4603 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4604 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4605}
4606
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004607TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004608 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004609 ASSERT_NO_FATAL_FAILURE(InitState());
4610
4611 VkImage image;
4612 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4613 VkImageCreateInfo image_create_info = {};
4614 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4615 image_create_info.pNext = NULL;
4616 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4617 image_create_info.format = tex_format;
4618 image_create_info.extent.width = 32;
4619 image_create_info.extent.height = 32;
4620 image_create_info.extent.depth = 1;
4621 image_create_info.mipLevels = 1;
4622 image_create_info.arrayLayers = 1;
4623 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4624 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004625 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004626 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004627 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004628 ASSERT_VK_SUCCESS(err);
4629 // Have to bind memory to image before recording cmd in cmd buffer using it
4630 VkMemoryRequirements mem_reqs;
4631 VkDeviceMemory image_mem;
4632 bool pass;
4633 VkMemoryAllocateInfo mem_alloc = {};
4634 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4635 mem_alloc.pNext = NULL;
4636 mem_alloc.memoryTypeIndex = 0;
4637 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4638 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004639 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004640 ASSERT_TRUE(pass);
4641 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4642 ASSERT_VK_SUCCESS(err);
4643
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004644 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004646 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004647
4648 m_commandBuffer->BeginCommandBuffer();
4649 VkClearColorValue ccv;
4650 ccv.float32[0] = 1.0f;
4651 ccv.float32[1] = 1.0f;
4652 ccv.float32[2] = 1.0f;
4653 ccv.float32[3] = 1.0f;
4654 VkImageSubresourceRange isr = {};
4655 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4656 isr.baseArrayLayer = 0;
4657 isr.baseMipLevel = 0;
4658 isr.layerCount = 1;
4659 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004660 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004661 m_commandBuffer->EndCommandBuffer();
4662
4663 m_errorMonitor->VerifyFound();
4664 vkDestroyImage(m_device->device(), image, NULL);
4665 vkFreeMemory(m_device->device(), image_mem, nullptr);
4666}
4667
4668TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004669 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004670 ASSERT_NO_FATAL_FAILURE(InitState());
4671
4672 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004673 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004674 VK_IMAGE_TILING_OPTIMAL, 0);
4675 ASSERT_TRUE(image.initialized());
4676
4677 VkBuffer buffer;
4678 VkDeviceMemory mem;
4679 VkMemoryRequirements mem_reqs;
4680
4681 VkBufferCreateInfo buf_info = {};
4682 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004683 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004684 buf_info.size = 256;
4685 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4686 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4687 ASSERT_VK_SUCCESS(err);
4688
4689 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4690
4691 VkMemoryAllocateInfo alloc_info = {};
4692 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4693 alloc_info.allocationSize = 256;
4694 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004695 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004696 if (!pass) {
4697 vkDestroyBuffer(m_device->device(), buffer, NULL);
4698 return;
4699 }
4700 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4701 ASSERT_VK_SUCCESS(err);
4702
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004703 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004705 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004706 VkBufferImageCopy region = {};
4707 region.bufferRowLength = 128;
4708 region.bufferImageHeight = 128;
4709 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4710
4711 region.imageSubresource.layerCount = 1;
4712 region.imageExtent.height = 4;
4713 region.imageExtent.width = 4;
4714 region.imageExtent.depth = 1;
4715 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004716 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4717 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004718 m_commandBuffer->EndCommandBuffer();
4719
4720 m_errorMonitor->VerifyFound();
4721
4722 vkDestroyBuffer(m_device->device(), buffer, NULL);
4723 vkFreeMemory(m_device->handle(), mem, NULL);
4724}
4725
Tobin Ehlis85940f52016-07-07 16:57:21 -06004726TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4727 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4728 "due to an event dependency being destroyed.");
4729 ASSERT_NO_FATAL_FAILURE(InitState());
4730
4731 VkEvent event;
4732 VkEventCreateInfo evci = {};
4733 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4734 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4735 ASSERT_VK_SUCCESS(result);
4736
4737 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004738 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004739 m_commandBuffer->EndCommandBuffer();
4740
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004742 // Destroy event dependency prior to submit to cause ERROR
4743 vkDestroyEvent(m_device->device(), event, NULL);
4744
4745 VkSubmitInfo submit_info = {};
4746 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4747 submit_info.commandBufferCount = 1;
4748 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4749 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4750
4751 m_errorMonitor->VerifyFound();
4752}
4753
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004754TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4755 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4756 "due to a query pool dependency being destroyed.");
4757 ASSERT_NO_FATAL_FAILURE(InitState());
4758
4759 VkQueryPool query_pool;
4760 VkQueryPoolCreateInfo qpci{};
4761 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4762 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4763 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004764 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004765 ASSERT_VK_SUCCESS(result);
4766
4767 m_commandBuffer->BeginCommandBuffer();
4768 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4769 m_commandBuffer->EndCommandBuffer();
4770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004772 // Destroy query pool dependency prior to submit to cause ERROR
4773 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4774
4775 VkSubmitInfo submit_info = {};
4776 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4777 submit_info.commandBufferCount = 1;
4778 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4779 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4780
4781 m_errorMonitor->VerifyFound();
4782}
4783
Tobin Ehlis24130d92016-07-08 15:50:53 -06004784TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4785 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4786 "due to a pipeline dependency being destroyed.");
4787 ASSERT_NO_FATAL_FAILURE(InitState());
4788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4789
4790 VkResult err;
4791
4792 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4793 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4794
4795 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004796 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004797 ASSERT_VK_SUCCESS(err);
4798
4799 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4800 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4801 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004802 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004803 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004804 vp_state_ci.scissorCount = 1;
4805 VkRect2D scissors = {}; // Dummy scissors to point to
4806 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004807
4808 VkPipelineShaderStageCreateInfo shaderStages[2];
4809 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4810
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004811 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4812 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4813 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004814 shaderStages[0] = vs.GetStageCreateInfo();
4815 shaderStages[1] = fs.GetStageCreateInfo();
4816
4817 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4818 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4819
4820 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4821 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4822 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4823
4824 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4825 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004826 rs_ci.rasterizerDiscardEnable = true;
4827 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004828
4829 VkPipelineColorBlendAttachmentState att = {};
4830 att.blendEnable = VK_FALSE;
4831 att.colorWriteMask = 0xf;
4832
4833 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4834 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4835 cb_ci.attachmentCount = 1;
4836 cb_ci.pAttachments = &att;
4837
4838 VkGraphicsPipelineCreateInfo gp_ci = {};
4839 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4840 gp_ci.stageCount = 2;
4841 gp_ci.pStages = shaderStages;
4842 gp_ci.pVertexInputState = &vi_ci;
4843 gp_ci.pInputAssemblyState = &ia_ci;
4844 gp_ci.pViewportState = &vp_state_ci;
4845 gp_ci.pRasterizationState = &rs_ci;
4846 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004847 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4848 gp_ci.layout = pipeline_layout;
4849 gp_ci.renderPass = renderPass();
4850
4851 VkPipelineCacheCreateInfo pc_ci = {};
4852 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4853
4854 VkPipeline pipeline;
4855 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004856 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004857 ASSERT_VK_SUCCESS(err);
4858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004859 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004860 ASSERT_VK_SUCCESS(err);
4861
4862 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004863 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004864 m_commandBuffer->EndCommandBuffer();
4865 // Now destroy pipeline in order to cause error when submitting
4866 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4867
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004869
4870 VkSubmitInfo submit_info = {};
4871 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4872 submit_info.commandBufferCount = 1;
4873 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4874 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4875
4876 m_errorMonitor->VerifyFound();
4877 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4878 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4879}
4880
Tobin Ehlis31289162016-08-17 14:57:58 -06004881TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4882 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4883 "due to a bound descriptor set with a buffer dependency "
4884 "being destroyed.");
4885 ASSERT_NO_FATAL_FAILURE(InitState());
4886 ASSERT_NO_FATAL_FAILURE(InitViewport());
4887 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4888
4889 VkDescriptorPoolSize ds_type_count = {};
4890 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4891 ds_type_count.descriptorCount = 1;
4892
4893 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4894 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4895 ds_pool_ci.pNext = NULL;
4896 ds_pool_ci.maxSets = 1;
4897 ds_pool_ci.poolSizeCount = 1;
4898 ds_pool_ci.pPoolSizes = &ds_type_count;
4899
4900 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004901 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004902 ASSERT_VK_SUCCESS(err);
4903
4904 VkDescriptorSetLayoutBinding dsl_binding = {};
4905 dsl_binding.binding = 0;
4906 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4907 dsl_binding.descriptorCount = 1;
4908 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4909 dsl_binding.pImmutableSamplers = NULL;
4910
4911 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4912 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4913 ds_layout_ci.pNext = NULL;
4914 ds_layout_ci.bindingCount = 1;
4915 ds_layout_ci.pBindings = &dsl_binding;
4916 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004917 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004918 ASSERT_VK_SUCCESS(err);
4919
4920 VkDescriptorSet descriptorSet;
4921 VkDescriptorSetAllocateInfo alloc_info = {};
4922 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4923 alloc_info.descriptorSetCount = 1;
4924 alloc_info.descriptorPool = ds_pool;
4925 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004926 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004927 ASSERT_VK_SUCCESS(err);
4928
4929 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4930 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4931 pipeline_layout_ci.pNext = NULL;
4932 pipeline_layout_ci.setLayoutCount = 1;
4933 pipeline_layout_ci.pSetLayouts = &ds_layout;
4934
4935 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004936 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004937 ASSERT_VK_SUCCESS(err);
4938
4939 // Create a buffer to update the descriptor with
4940 uint32_t qfi = 0;
4941 VkBufferCreateInfo buffCI = {};
4942 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4943 buffCI.size = 1024;
4944 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4945 buffCI.queueFamilyIndexCount = 1;
4946 buffCI.pQueueFamilyIndices = &qfi;
4947
4948 VkBuffer buffer;
4949 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4950 ASSERT_VK_SUCCESS(err);
4951 // Allocate memory and bind to buffer so we can make it to the appropriate
4952 // error
4953 VkMemoryAllocateInfo mem_alloc = {};
4954 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4955 mem_alloc.pNext = NULL;
4956 mem_alloc.allocationSize = 1024;
4957 mem_alloc.memoryTypeIndex = 0;
4958
4959 VkMemoryRequirements memReqs;
4960 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004961 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004962 if (!pass) {
4963 vkDestroyBuffer(m_device->device(), buffer, NULL);
4964 return;
4965 }
4966
4967 VkDeviceMemory mem;
4968 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4969 ASSERT_VK_SUCCESS(err);
4970 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4971 ASSERT_VK_SUCCESS(err);
4972 // Correctly update descriptor to avoid "NOT_UPDATED" error
4973 VkDescriptorBufferInfo buffInfo = {};
4974 buffInfo.buffer = buffer;
4975 buffInfo.offset = 0;
4976 buffInfo.range = 1024;
4977
4978 VkWriteDescriptorSet descriptor_write;
4979 memset(&descriptor_write, 0, sizeof(descriptor_write));
4980 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4981 descriptor_write.dstSet = descriptorSet;
4982 descriptor_write.dstBinding = 0;
4983 descriptor_write.descriptorCount = 1;
4984 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4985 descriptor_write.pBufferInfo = &buffInfo;
4986
4987 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4988
4989 // Create PSO to be used for draw-time errors below
4990 char const *vsSource = "#version 450\n"
4991 "\n"
4992 "out gl_PerVertex { \n"
4993 " vec4 gl_Position;\n"
4994 "};\n"
4995 "void main(){\n"
4996 " gl_Position = vec4(1);\n"
4997 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004998 char const *fsSource = "#version 450\n"
4999 "\n"
5000 "layout(location=0) out vec4 x;\n"
5001 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5002 "void main(){\n"
5003 " x = vec4(bar.y);\n"
5004 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005005 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5006 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5007 VkPipelineObj pipe(m_device);
5008 pipe.AddShader(&vs);
5009 pipe.AddShader(&fs);
5010 pipe.AddColorAttachment();
5011 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5012
5013 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005014 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5015 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5016 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005017 Draw(1, 0, 0, 0);
5018 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005020 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5021 vkDestroyBuffer(m_device->device(), buffer, NULL);
5022 // Attempt to submit cmd buffer
5023 VkSubmitInfo submit_info = {};
5024 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5025 submit_info.commandBufferCount = 1;
5026 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5027 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5028 m_errorMonitor->VerifyFound();
5029 // Cleanup
5030 vkFreeMemory(m_device->device(), mem, NULL);
5031
5032 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5033 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5034 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5035}
5036
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005037TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5038 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5039 "due to a bound descriptor sets with a combined image "
5040 "sampler having their image, sampler, and descriptor set "
5041 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005042 "submit associated cmd buffers. Attempt to destroy a "
5043 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005044 ASSERT_NO_FATAL_FAILURE(InitState());
5045 ASSERT_NO_FATAL_FAILURE(InitViewport());
5046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5047
5048 VkDescriptorPoolSize ds_type_count = {};
5049 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5050 ds_type_count.descriptorCount = 1;
5051
5052 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5053 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5054 ds_pool_ci.pNext = NULL;
5055 ds_pool_ci.maxSets = 1;
5056 ds_pool_ci.poolSizeCount = 1;
5057 ds_pool_ci.pPoolSizes = &ds_type_count;
5058
5059 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005060 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005061 ASSERT_VK_SUCCESS(err);
5062
5063 VkDescriptorSetLayoutBinding dsl_binding = {};
5064 dsl_binding.binding = 0;
5065 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5066 dsl_binding.descriptorCount = 1;
5067 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5068 dsl_binding.pImmutableSamplers = NULL;
5069
5070 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5071 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5072 ds_layout_ci.pNext = NULL;
5073 ds_layout_ci.bindingCount = 1;
5074 ds_layout_ci.pBindings = &dsl_binding;
5075 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005076 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005077 ASSERT_VK_SUCCESS(err);
5078
5079 VkDescriptorSet descriptorSet;
5080 VkDescriptorSetAllocateInfo alloc_info = {};
5081 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5082 alloc_info.descriptorSetCount = 1;
5083 alloc_info.descriptorPool = ds_pool;
5084 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005085 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005086 ASSERT_VK_SUCCESS(err);
5087
5088 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5089 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5090 pipeline_layout_ci.pNext = NULL;
5091 pipeline_layout_ci.setLayoutCount = 1;
5092 pipeline_layout_ci.pSetLayouts = &ds_layout;
5093
5094 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005095 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005096 ASSERT_VK_SUCCESS(err);
5097
5098 // Create images to update the descriptor with
5099 VkImage image;
5100 VkImage image2;
5101 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5102 const int32_t tex_width = 32;
5103 const int32_t tex_height = 32;
5104 VkImageCreateInfo image_create_info = {};
5105 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5106 image_create_info.pNext = NULL;
5107 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5108 image_create_info.format = tex_format;
5109 image_create_info.extent.width = tex_width;
5110 image_create_info.extent.height = tex_height;
5111 image_create_info.extent.depth = 1;
5112 image_create_info.mipLevels = 1;
5113 image_create_info.arrayLayers = 1;
5114 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5115 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5116 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5117 image_create_info.flags = 0;
5118 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5119 ASSERT_VK_SUCCESS(err);
5120 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5121 ASSERT_VK_SUCCESS(err);
5122
5123 VkMemoryRequirements memory_reqs;
5124 VkDeviceMemory image_memory;
5125 bool pass;
5126 VkMemoryAllocateInfo memory_info = {};
5127 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5128 memory_info.pNext = NULL;
5129 memory_info.allocationSize = 0;
5130 memory_info.memoryTypeIndex = 0;
5131 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5132 // Allocate enough memory for both images
5133 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005134 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005135 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005136 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005137 ASSERT_VK_SUCCESS(err);
5138 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5139 ASSERT_VK_SUCCESS(err);
5140 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005141 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005142 ASSERT_VK_SUCCESS(err);
5143
5144 VkImageViewCreateInfo image_view_create_info = {};
5145 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5146 image_view_create_info.image = image;
5147 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5148 image_view_create_info.format = tex_format;
5149 image_view_create_info.subresourceRange.layerCount = 1;
5150 image_view_create_info.subresourceRange.baseMipLevel = 0;
5151 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005152 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005153
5154 VkImageView view;
5155 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005156 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005157 ASSERT_VK_SUCCESS(err);
5158 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005159 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005160 ASSERT_VK_SUCCESS(err);
5161 // Create Samplers
5162 VkSamplerCreateInfo sampler_ci = {};
5163 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5164 sampler_ci.pNext = NULL;
5165 sampler_ci.magFilter = VK_FILTER_NEAREST;
5166 sampler_ci.minFilter = VK_FILTER_NEAREST;
5167 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5168 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5169 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5170 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5171 sampler_ci.mipLodBias = 1.0;
5172 sampler_ci.anisotropyEnable = VK_FALSE;
5173 sampler_ci.maxAnisotropy = 1;
5174 sampler_ci.compareEnable = VK_FALSE;
5175 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5176 sampler_ci.minLod = 1.0;
5177 sampler_ci.maxLod = 1.0;
5178 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5179 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5180 VkSampler sampler;
5181 VkSampler sampler2;
5182 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5183 ASSERT_VK_SUCCESS(err);
5184 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5185 ASSERT_VK_SUCCESS(err);
5186 // Update descriptor with image and sampler
5187 VkDescriptorImageInfo img_info = {};
5188 img_info.sampler = sampler;
5189 img_info.imageView = view;
5190 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5191
5192 VkWriteDescriptorSet descriptor_write;
5193 memset(&descriptor_write, 0, sizeof(descriptor_write));
5194 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5195 descriptor_write.dstSet = descriptorSet;
5196 descriptor_write.dstBinding = 0;
5197 descriptor_write.descriptorCount = 1;
5198 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5199 descriptor_write.pImageInfo = &img_info;
5200
5201 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5202
5203 // Create PSO to be used for draw-time errors below
5204 char const *vsSource = "#version 450\n"
5205 "\n"
5206 "out gl_PerVertex { \n"
5207 " vec4 gl_Position;\n"
5208 "};\n"
5209 "void main(){\n"
5210 " gl_Position = vec4(1);\n"
5211 "}\n";
5212 char const *fsSource = "#version 450\n"
5213 "\n"
5214 "layout(set=0, binding=0) uniform sampler2D s;\n"
5215 "layout(location=0) out vec4 x;\n"
5216 "void main(){\n"
5217 " x = texture(s, vec2(1));\n"
5218 "}\n";
5219 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5220 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5221 VkPipelineObj pipe(m_device);
5222 pipe.AddShader(&vs);
5223 pipe.AddShader(&fs);
5224 pipe.AddColorAttachment();
5225 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5226
5227 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005229 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005230 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5231 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5232 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005233 Draw(1, 0, 0, 0);
5234 EndCommandBuffer();
5235 // Destroy sampler invalidates the cmd buffer, causing error on submit
5236 vkDestroySampler(m_device->device(), sampler, NULL);
5237 // Attempt to submit cmd buffer
5238 VkSubmitInfo submit_info = {};
5239 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5240 submit_info.commandBufferCount = 1;
5241 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5242 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5243 m_errorMonitor->VerifyFound();
5244 // Now re-update descriptor with valid sampler and delete image
5245 img_info.sampler = sampler2;
5246 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005248 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005249 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5250 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5251 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005252 Draw(1, 0, 0, 0);
5253 EndCommandBuffer();
5254 // Destroy image invalidates the cmd buffer, causing error on submit
5255 vkDestroyImage(m_device->device(), image, NULL);
5256 // Attempt to submit cmd buffer
5257 submit_info = {};
5258 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5259 submit_info.commandBufferCount = 1;
5260 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5261 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5262 m_errorMonitor->VerifyFound();
5263 // Now update descriptor to be valid, but then free descriptor
5264 img_info.imageView = view2;
5265 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005267 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005268 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5269 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5270 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005271 Draw(1, 0, 0, 0);
5272 EndCommandBuffer();
5273 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005275 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005276 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005277 // Attempt to submit cmd buffer
5278 submit_info = {};
5279 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5280 submit_info.commandBufferCount = 1;
5281 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5282 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5283 m_errorMonitor->VerifyFound();
5284 // Cleanup
5285 vkFreeMemory(m_device->device(), image_memory, NULL);
5286 vkDestroySampler(m_device->device(), sampler2, NULL);
5287 vkDestroyImage(m_device->device(), image2, NULL);
5288 vkDestroyImageView(m_device->device(), view, NULL);
5289 vkDestroyImageView(m_device->device(), view2, NULL);
5290 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5291 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5292 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5293}
5294
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005295TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5296 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5297 ASSERT_NO_FATAL_FAILURE(InitState());
5298 ASSERT_NO_FATAL_FAILURE(InitViewport());
5299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5300
5301 VkDescriptorPoolSize ds_type_count = {};
5302 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5303 ds_type_count.descriptorCount = 1;
5304
5305 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5306 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5307 ds_pool_ci.pNext = NULL;
5308 ds_pool_ci.maxSets = 1;
5309 ds_pool_ci.poolSizeCount = 1;
5310 ds_pool_ci.pPoolSizes = &ds_type_count;
5311
5312 VkDescriptorPool ds_pool;
5313 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5314 ASSERT_VK_SUCCESS(err);
5315
5316 VkDescriptorSetLayoutBinding dsl_binding = {};
5317 dsl_binding.binding = 0;
5318 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5319 dsl_binding.descriptorCount = 1;
5320 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5321 dsl_binding.pImmutableSamplers = NULL;
5322
5323 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5324 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5325 ds_layout_ci.pNext = NULL;
5326 ds_layout_ci.bindingCount = 1;
5327 ds_layout_ci.pBindings = &dsl_binding;
5328 VkDescriptorSetLayout ds_layout;
5329 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5330 ASSERT_VK_SUCCESS(err);
5331
5332 VkDescriptorSet descriptor_set;
5333 VkDescriptorSetAllocateInfo alloc_info = {};
5334 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5335 alloc_info.descriptorSetCount = 1;
5336 alloc_info.descriptorPool = ds_pool;
5337 alloc_info.pSetLayouts = &ds_layout;
5338 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5339 ASSERT_VK_SUCCESS(err);
5340
5341 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5342 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5343 pipeline_layout_ci.pNext = NULL;
5344 pipeline_layout_ci.setLayoutCount = 1;
5345 pipeline_layout_ci.pSetLayouts = &ds_layout;
5346
5347 VkPipelineLayout pipeline_layout;
5348 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5349 ASSERT_VK_SUCCESS(err);
5350
5351 // Create image to update the descriptor with
5352 VkImageObj image(m_device);
5353 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5354 ASSERT_TRUE(image.initialized());
5355
5356 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5357 // Create Sampler
5358 VkSamplerCreateInfo sampler_ci = {};
5359 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5360 sampler_ci.pNext = NULL;
5361 sampler_ci.magFilter = VK_FILTER_NEAREST;
5362 sampler_ci.minFilter = VK_FILTER_NEAREST;
5363 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5364 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5365 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5366 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5367 sampler_ci.mipLodBias = 1.0;
5368 sampler_ci.anisotropyEnable = VK_FALSE;
5369 sampler_ci.maxAnisotropy = 1;
5370 sampler_ci.compareEnable = VK_FALSE;
5371 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5372 sampler_ci.minLod = 1.0;
5373 sampler_ci.maxLod = 1.0;
5374 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5375 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5376 VkSampler sampler;
5377 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5378 ASSERT_VK_SUCCESS(err);
5379 // Update descriptor with image and sampler
5380 VkDescriptorImageInfo img_info = {};
5381 img_info.sampler = sampler;
5382 img_info.imageView = view;
5383 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5384
5385 VkWriteDescriptorSet descriptor_write;
5386 memset(&descriptor_write, 0, sizeof(descriptor_write));
5387 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5388 descriptor_write.dstSet = descriptor_set;
5389 descriptor_write.dstBinding = 0;
5390 descriptor_write.descriptorCount = 1;
5391 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5392 descriptor_write.pImageInfo = &img_info;
5393
5394 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5395
5396 // Create PSO to be used for draw-time errors below
5397 char const *vsSource = "#version 450\n"
5398 "\n"
5399 "out gl_PerVertex { \n"
5400 " vec4 gl_Position;\n"
5401 "};\n"
5402 "void main(){\n"
5403 " gl_Position = vec4(1);\n"
5404 "}\n";
5405 char const *fsSource = "#version 450\n"
5406 "\n"
5407 "layout(set=0, binding=0) uniform sampler2D s;\n"
5408 "layout(location=0) out vec4 x;\n"
5409 "void main(){\n"
5410 " x = texture(s, vec2(1));\n"
5411 "}\n";
5412 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5413 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5414 VkPipelineObj pipe(m_device);
5415 pipe.AddShader(&vs);
5416 pipe.AddShader(&fs);
5417 pipe.AddColorAttachment();
5418 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5419
5420 BeginCommandBuffer();
5421 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5422 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5423 &descriptor_set, 0, NULL);
5424 Draw(1, 0, 0, 0);
5425 EndCommandBuffer();
5426 // Submit cmd buffer to put pool in-flight
5427 VkSubmitInfo submit_info = {};
5428 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5429 submit_info.commandBufferCount = 1;
5430 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5431 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5432 // Destroy pool while in-flight, causing error
5433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5434 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5435 m_errorMonitor->VerifyFound();
5436 vkQueueWaitIdle(m_device->m_queue);
5437 // Cleanup
5438 vkDestroySampler(m_device->device(), sampler, NULL);
5439 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5440 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5441 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5442}
5443
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005444TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5445 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5446 ASSERT_NO_FATAL_FAILURE(InitState());
5447 ASSERT_NO_FATAL_FAILURE(InitViewport());
5448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5449
5450 VkDescriptorPoolSize ds_type_count = {};
5451 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5452 ds_type_count.descriptorCount = 1;
5453
5454 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5455 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5456 ds_pool_ci.pNext = NULL;
5457 ds_pool_ci.maxSets = 1;
5458 ds_pool_ci.poolSizeCount = 1;
5459 ds_pool_ci.pPoolSizes = &ds_type_count;
5460
5461 VkDescriptorPool ds_pool;
5462 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5463 ASSERT_VK_SUCCESS(err);
5464
5465 VkDescriptorSetLayoutBinding dsl_binding = {};
5466 dsl_binding.binding = 0;
5467 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5468 dsl_binding.descriptorCount = 1;
5469 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5470 dsl_binding.pImmutableSamplers = NULL;
5471
5472 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5473 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5474 ds_layout_ci.pNext = NULL;
5475 ds_layout_ci.bindingCount = 1;
5476 ds_layout_ci.pBindings = &dsl_binding;
5477 VkDescriptorSetLayout ds_layout;
5478 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5479 ASSERT_VK_SUCCESS(err);
5480
5481 VkDescriptorSet descriptorSet;
5482 VkDescriptorSetAllocateInfo alloc_info = {};
5483 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5484 alloc_info.descriptorSetCount = 1;
5485 alloc_info.descriptorPool = ds_pool;
5486 alloc_info.pSetLayouts = &ds_layout;
5487 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5488 ASSERT_VK_SUCCESS(err);
5489
5490 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5491 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5492 pipeline_layout_ci.pNext = NULL;
5493 pipeline_layout_ci.setLayoutCount = 1;
5494 pipeline_layout_ci.pSetLayouts = &ds_layout;
5495
5496 VkPipelineLayout pipeline_layout;
5497 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5498 ASSERT_VK_SUCCESS(err);
5499
5500 // Create images to update the descriptor with
5501 VkImage image;
5502 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5503 const int32_t tex_width = 32;
5504 const int32_t tex_height = 32;
5505 VkImageCreateInfo image_create_info = {};
5506 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5507 image_create_info.pNext = NULL;
5508 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5509 image_create_info.format = tex_format;
5510 image_create_info.extent.width = tex_width;
5511 image_create_info.extent.height = tex_height;
5512 image_create_info.extent.depth = 1;
5513 image_create_info.mipLevels = 1;
5514 image_create_info.arrayLayers = 1;
5515 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5516 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5517 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5518 image_create_info.flags = 0;
5519 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5520 ASSERT_VK_SUCCESS(err);
5521 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5522 VkMemoryRequirements memory_reqs;
5523 VkDeviceMemory image_memory;
5524 bool pass;
5525 VkMemoryAllocateInfo memory_info = {};
5526 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5527 memory_info.pNext = NULL;
5528 memory_info.allocationSize = 0;
5529 memory_info.memoryTypeIndex = 0;
5530 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5531 // Allocate enough memory for image
5532 memory_info.allocationSize = memory_reqs.size;
5533 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5534 ASSERT_TRUE(pass);
5535 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5536 ASSERT_VK_SUCCESS(err);
5537 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5538 ASSERT_VK_SUCCESS(err);
5539
5540 VkImageViewCreateInfo image_view_create_info = {};
5541 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5542 image_view_create_info.image = image;
5543 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5544 image_view_create_info.format = tex_format;
5545 image_view_create_info.subresourceRange.layerCount = 1;
5546 image_view_create_info.subresourceRange.baseMipLevel = 0;
5547 image_view_create_info.subresourceRange.levelCount = 1;
5548 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5549
5550 VkImageView view;
5551 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5552 ASSERT_VK_SUCCESS(err);
5553 // Create Samplers
5554 VkSamplerCreateInfo sampler_ci = {};
5555 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5556 sampler_ci.pNext = NULL;
5557 sampler_ci.magFilter = VK_FILTER_NEAREST;
5558 sampler_ci.minFilter = VK_FILTER_NEAREST;
5559 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5560 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5561 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5562 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5563 sampler_ci.mipLodBias = 1.0;
5564 sampler_ci.anisotropyEnable = VK_FALSE;
5565 sampler_ci.maxAnisotropy = 1;
5566 sampler_ci.compareEnable = VK_FALSE;
5567 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5568 sampler_ci.minLod = 1.0;
5569 sampler_ci.maxLod = 1.0;
5570 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5571 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5572 VkSampler sampler;
5573 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5574 ASSERT_VK_SUCCESS(err);
5575 // Update descriptor with image and sampler
5576 VkDescriptorImageInfo img_info = {};
5577 img_info.sampler = sampler;
5578 img_info.imageView = view;
5579 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5580
5581 VkWriteDescriptorSet descriptor_write;
5582 memset(&descriptor_write, 0, sizeof(descriptor_write));
5583 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5584 descriptor_write.dstSet = descriptorSet;
5585 descriptor_write.dstBinding = 0;
5586 descriptor_write.descriptorCount = 1;
5587 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5588 descriptor_write.pImageInfo = &img_info;
5589 // Break memory binding and attempt update
5590 vkFreeMemory(m_device->device(), image_memory, nullptr);
5591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005592 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5594 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5595 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5596 m_errorMonitor->VerifyFound();
5597 // Cleanup
5598 vkDestroyImage(m_device->device(), image, NULL);
5599 vkDestroySampler(m_device->device(), sampler, NULL);
5600 vkDestroyImageView(m_device->device(), view, NULL);
5601 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5602 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5603 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5604}
5605
Karl Schultz6addd812016-02-02 17:17:23 -07005606TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005607 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5608 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005609 // Create a valid cmd buffer
5610 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005611 uint64_t fake_pipeline_handle = 0xbaad6001;
5612 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005613 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5615
5616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005617 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005618 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005619 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005620
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005621 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005623 Draw(1, 0, 0, 0);
5624 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005625
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005626 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005628 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005629 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5630 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005631}
5632
Karl Schultz6addd812016-02-02 17:17:23 -07005633TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005634 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005635 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005636
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005638
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005639 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005640 ASSERT_NO_FATAL_FAILURE(InitViewport());
5641 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005642 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005643 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5644 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005645
5646 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005647 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5648 ds_pool_ci.pNext = NULL;
5649 ds_pool_ci.maxSets = 1;
5650 ds_pool_ci.poolSizeCount = 1;
5651 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005652
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005653 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005654 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005655 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005656
Tony Barboureb254902015-07-15 12:50:33 -06005657 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005658 dsl_binding.binding = 0;
5659 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5660 dsl_binding.descriptorCount = 1;
5661 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5662 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005663
Tony Barboureb254902015-07-15 12:50:33 -06005664 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005665 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5666 ds_layout_ci.pNext = NULL;
5667 ds_layout_ci.bindingCount = 1;
5668 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005669 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005670 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005671 ASSERT_VK_SUCCESS(err);
5672
5673 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005674 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005675 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005676 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005677 alloc_info.descriptorPool = ds_pool;
5678 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005679 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005680 ASSERT_VK_SUCCESS(err);
5681
Tony Barboureb254902015-07-15 12:50:33 -06005682 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005683 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5684 pipeline_layout_ci.pNext = NULL;
5685 pipeline_layout_ci.setLayoutCount = 1;
5686 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005687
5688 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005689 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005690 ASSERT_VK_SUCCESS(err);
5691
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005692 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005693 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005694 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005695 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005696
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005697 VkPipelineObj pipe(m_device);
5698 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005699 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005700 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005701 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005702
5703 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005704 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5705 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5706 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005707
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005708 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005709
Chia-I Wuf7458c52015-10-26 21:10:41 +08005710 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5711 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5712 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005713}
5714
Karl Schultz6addd812016-02-02 17:17:23 -07005715TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005716 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005717 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5720 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005721
5722 ASSERT_NO_FATAL_FAILURE(InitState());
5723 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005724 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5725 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005726
5727 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005728 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5729 ds_pool_ci.pNext = NULL;
5730 ds_pool_ci.maxSets = 1;
5731 ds_pool_ci.poolSizeCount = 1;
5732 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005733
5734 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005735 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005736 ASSERT_VK_SUCCESS(err);
5737
5738 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005739 dsl_binding.binding = 0;
5740 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5741 dsl_binding.descriptorCount = 1;
5742 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5743 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005744
5745 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005746 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5747 ds_layout_ci.pNext = NULL;
5748 ds_layout_ci.bindingCount = 1;
5749 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005750 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005751 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005752 ASSERT_VK_SUCCESS(err);
5753
5754 VkDescriptorSet descriptorSet;
5755 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005756 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005757 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005758 alloc_info.descriptorPool = ds_pool;
5759 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005760 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005761 ASSERT_VK_SUCCESS(err);
5762
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005763 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005764 VkWriteDescriptorSet descriptor_write;
5765 memset(&descriptor_write, 0, sizeof(descriptor_write));
5766 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5767 descriptor_write.dstSet = descriptorSet;
5768 descriptor_write.dstBinding = 0;
5769 descriptor_write.descriptorCount = 1;
5770 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5771 descriptor_write.pTexelBufferView = &view;
5772
5773 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5774
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005775 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005776
5777 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5778 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5779}
5780
Mark Youngd339ba32016-05-30 13:28:35 -06005781TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005782 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has no memory bound to it.");
Mark Youngd339ba32016-05-30 13:28:35 -06005783
5784 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005786 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005787
5788 ASSERT_NO_FATAL_FAILURE(InitState());
5789
5790 // Create a buffer with no bound memory and then attempt to create
5791 // a buffer view.
5792 VkBufferCreateInfo buff_ci = {};
5793 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005794 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005795 buff_ci.size = 256;
5796 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5797 VkBuffer buffer;
5798 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5799 ASSERT_VK_SUCCESS(err);
5800
5801 VkBufferViewCreateInfo buff_view_ci = {};
5802 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5803 buff_view_ci.buffer = buffer;
5804 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5805 buff_view_ci.range = VK_WHOLE_SIZE;
5806 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005807 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005808
5809 m_errorMonitor->VerifyFound();
5810 vkDestroyBuffer(m_device->device(), buffer, NULL);
5811 // If last error is success, it still created the view, so delete it.
5812 if (err == VK_SUCCESS) {
5813 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5814 }
5815}
5816
Karl Schultz6addd812016-02-02 17:17:23 -07005817TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5818 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5819 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005820 // 1. No dynamicOffset supplied
5821 // 2. Too many dynamicOffsets supplied
5822 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005823 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5825 "0 dynamicOffsets are left in "
5826 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005827
5828 ASSERT_NO_FATAL_FAILURE(InitState());
5829 ASSERT_NO_FATAL_FAILURE(InitViewport());
5830 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5831
5832 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005833 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5834 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005835
5836 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005837 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5838 ds_pool_ci.pNext = NULL;
5839 ds_pool_ci.maxSets = 1;
5840 ds_pool_ci.poolSizeCount = 1;
5841 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005842
5843 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005844 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005845 ASSERT_VK_SUCCESS(err);
5846
5847 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005848 dsl_binding.binding = 0;
5849 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5850 dsl_binding.descriptorCount = 1;
5851 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5852 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005853
5854 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005855 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5856 ds_layout_ci.pNext = NULL;
5857 ds_layout_ci.bindingCount = 1;
5858 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005859 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005860 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005861 ASSERT_VK_SUCCESS(err);
5862
5863 VkDescriptorSet descriptorSet;
5864 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005865 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005866 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005867 alloc_info.descriptorPool = ds_pool;
5868 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005869 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005870 ASSERT_VK_SUCCESS(err);
5871
5872 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005873 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5874 pipeline_layout_ci.pNext = NULL;
5875 pipeline_layout_ci.setLayoutCount = 1;
5876 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005877
5878 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005879 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005880 ASSERT_VK_SUCCESS(err);
5881
5882 // Create a buffer to update the descriptor with
5883 uint32_t qfi = 0;
5884 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005885 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5886 buffCI.size = 1024;
5887 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5888 buffCI.queueFamilyIndexCount = 1;
5889 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005890
5891 VkBuffer dyub;
5892 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5893 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005894 // Allocate memory and bind to buffer so we can make it to the appropriate
5895 // error
5896 VkMemoryAllocateInfo mem_alloc = {};
5897 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5898 mem_alloc.pNext = NULL;
5899 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005900 mem_alloc.memoryTypeIndex = 0;
5901
5902 VkMemoryRequirements memReqs;
5903 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005904 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005905 if (!pass) {
5906 vkDestroyBuffer(m_device->device(), dyub, NULL);
5907 return;
5908 }
5909
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005910 VkDeviceMemory mem;
5911 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5912 ASSERT_VK_SUCCESS(err);
5913 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5914 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005915 // Correctly update descriptor to avoid "NOT_UPDATED" error
5916 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005917 buffInfo.buffer = dyub;
5918 buffInfo.offset = 0;
5919 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005920
5921 VkWriteDescriptorSet descriptor_write;
5922 memset(&descriptor_write, 0, sizeof(descriptor_write));
5923 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5924 descriptor_write.dstSet = descriptorSet;
5925 descriptor_write.dstBinding = 0;
5926 descriptor_write.descriptorCount = 1;
5927 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5928 descriptor_write.pBufferInfo = &buffInfo;
5929
5930 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5931
5932 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005933 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5934 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005935 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005936 uint32_t pDynOff[2] = {512, 756};
5937 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5939 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5940 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5941 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005942 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005943 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5945 "offset 0 and range 1024 that "
5946 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005947 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005948 char const *vsSource = "#version 450\n"
5949 "\n"
5950 "out gl_PerVertex { \n"
5951 " vec4 gl_Position;\n"
5952 "};\n"
5953 "void main(){\n"
5954 " gl_Position = vec4(1);\n"
5955 "}\n";
5956 char const *fsSource = "#version 450\n"
5957 "\n"
5958 "layout(location=0) out vec4 x;\n"
5959 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5960 "void main(){\n"
5961 " x = vec4(bar.y);\n"
5962 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005963 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5964 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5965 VkPipelineObj pipe(m_device);
5966 pipe.AddShader(&vs);
5967 pipe.AddShader(&fs);
5968 pipe.AddColorAttachment();
5969 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5970
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005971 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005972 // This update should succeed, but offset size of 512 will overstep buffer
5973 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005974 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5975 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005976 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005977 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005978
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005979 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005980 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005981
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005982 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005983 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005984 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5985}
5986
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005987TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
5988 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
5989 "that doesn't have memory bound");
5990 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005992 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5994 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005995
5996 ASSERT_NO_FATAL_FAILURE(InitState());
5997 ASSERT_NO_FATAL_FAILURE(InitViewport());
5998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5999
6000 VkDescriptorPoolSize ds_type_count = {};
6001 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6002 ds_type_count.descriptorCount = 1;
6003
6004 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6005 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6006 ds_pool_ci.pNext = NULL;
6007 ds_pool_ci.maxSets = 1;
6008 ds_pool_ci.poolSizeCount = 1;
6009 ds_pool_ci.pPoolSizes = &ds_type_count;
6010
6011 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006012 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006013 ASSERT_VK_SUCCESS(err);
6014
6015 VkDescriptorSetLayoutBinding dsl_binding = {};
6016 dsl_binding.binding = 0;
6017 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6018 dsl_binding.descriptorCount = 1;
6019 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6020 dsl_binding.pImmutableSamplers = NULL;
6021
6022 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6023 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6024 ds_layout_ci.pNext = NULL;
6025 ds_layout_ci.bindingCount = 1;
6026 ds_layout_ci.pBindings = &dsl_binding;
6027 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006028 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006029 ASSERT_VK_SUCCESS(err);
6030
6031 VkDescriptorSet descriptorSet;
6032 VkDescriptorSetAllocateInfo alloc_info = {};
6033 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6034 alloc_info.descriptorSetCount = 1;
6035 alloc_info.descriptorPool = ds_pool;
6036 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006037 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006038 ASSERT_VK_SUCCESS(err);
6039
6040 // Create a buffer to update the descriptor with
6041 uint32_t qfi = 0;
6042 VkBufferCreateInfo buffCI = {};
6043 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6044 buffCI.size = 1024;
6045 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6046 buffCI.queueFamilyIndexCount = 1;
6047 buffCI.pQueueFamilyIndices = &qfi;
6048
6049 VkBuffer dyub;
6050 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6051 ASSERT_VK_SUCCESS(err);
6052
6053 // Attempt to update descriptor without binding memory to it
6054 VkDescriptorBufferInfo buffInfo = {};
6055 buffInfo.buffer = dyub;
6056 buffInfo.offset = 0;
6057 buffInfo.range = 1024;
6058
6059 VkWriteDescriptorSet descriptor_write;
6060 memset(&descriptor_write, 0, sizeof(descriptor_write));
6061 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6062 descriptor_write.dstSet = descriptorSet;
6063 descriptor_write.dstBinding = 0;
6064 descriptor_write.descriptorCount = 1;
6065 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6066 descriptor_write.pBufferInfo = &buffInfo;
6067
6068 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6069 m_errorMonitor->VerifyFound();
6070
6071 vkDestroyBuffer(m_device->device(), dyub, NULL);
6072 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6073 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6074}
6075
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006076TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006077 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006078 ASSERT_NO_FATAL_FAILURE(InitState());
6079 ASSERT_NO_FATAL_FAILURE(InitViewport());
6080 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6081
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006082 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006083 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006084 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6085 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6086 pipeline_layout_ci.pushConstantRangeCount = 1;
6087 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6088
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006089 //
6090 // Check for invalid push constant ranges in pipeline layouts.
6091 //
6092 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006093 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006094 char const *msg;
6095 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006096
Karl Schultzc81037d2016-05-12 08:11:23 -06006097 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6098 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6099 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6100 "vkCreatePipelineLayout() call has push constants index 0 with "
6101 "size 0."},
6102 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6103 "vkCreatePipelineLayout() call has push constants index 0 with "
6104 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006105 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006106 "vkCreatePipelineLayout() call has push constants index 0 with "
6107 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006108 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006109 "vkCreatePipelineLayout() call has push constants index 0 with "
6110 "size 0."},
6111 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6112 "vkCreatePipelineLayout() call has push constants index 0 with "
6113 "offset 1. Offset must"},
6114 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6115 "vkCreatePipelineLayout() call has push constants index 0 "
6116 "with offset "},
6117 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6118 "vkCreatePipelineLayout() call has push constants "
6119 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006120 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006121 "vkCreatePipelineLayout() call has push constants index 0 "
6122 "with offset "},
6123 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6124 "vkCreatePipelineLayout() call has push "
6125 "constants index 0 with offset "},
6126 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6127 "vkCreatePipelineLayout() call has push "
6128 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006129 }};
6130
6131 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006132 for (const auto &iter : range_tests) {
6133 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6135 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006136 m_errorMonitor->VerifyFound();
6137 if (VK_SUCCESS == err) {
6138 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6139 }
6140 }
6141
6142 // Check for invalid stage flag
6143 pc_range.offset = 0;
6144 pc_range.size = 16;
6145 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006146 m_errorMonitor->SetDesiredFailureMsg(
6147 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6148 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006149 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006150 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006151 if (VK_SUCCESS == err) {
6152 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6153 }
6154
6155 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006156 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006157 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006158 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006159 char const *msg;
6160 };
6161
Karl Schultzc81037d2016-05-12 08:11:23 -06006162 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006163 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6164 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6165 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6166 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6167 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006168 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006169 {
6170 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6171 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6172 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6173 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6174 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006175 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006176 },
6177 {
6178 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6179 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6180 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6181 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6182 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006183 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006184 },
6185 {
6186 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6187 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6188 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6189 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6190 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006191 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006192 },
6193 {
6194 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6195 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6196 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6197 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6198 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006199 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006200 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006201
Karl Schultzc81037d2016-05-12 08:11:23 -06006202 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006203 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006204 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6206 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006207 m_errorMonitor->VerifyFound();
6208 if (VK_SUCCESS == err) {
6209 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6210 }
6211 }
6212
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006213 //
6214 // CmdPushConstants tests
6215 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006216 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006217
6218 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006219 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6220 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006221 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6222 "vkCmdPushConstants() call has push constants with size 1. Size "
6223 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006224 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006225 "vkCmdPushConstants() call has push constants with size 1. Size "
6226 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006227 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006228 "vkCmdPushConstants() call has push constants with offset 1. "
6229 "Offset must be a multiple of 4."},
6230 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6231 "vkCmdPushConstants() call has push constants with offset 1. "
6232 "Offset must be a multiple of 4."},
6233 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6234 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6235 "0x1 not within flag-matching ranges in pipeline layout"},
6236 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6237 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6238 "0x1 not within flag-matching ranges in pipeline layout"},
6239 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6240 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6241 "0x1 not within flag-matching ranges in pipeline layout"},
6242 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6243 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6244 "0x1 not within flag-matching ranges in pipeline layout"},
6245 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6246 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6247 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006248 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006249 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6250 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006251 }};
6252
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006253 BeginCommandBuffer();
6254
6255 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006256 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006257 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006258 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006259 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006260 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006261 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006262 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006263 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6265 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006266 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006267 m_errorMonitor->VerifyFound();
6268 }
6269
6270 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006272 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006273 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006274 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006275
Karl Schultzc81037d2016-05-12 08:11:23 -06006276 // overlapping range tests with cmd
6277 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6278 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6279 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6280 "0x1 not within flag-matching ranges in pipeline layout"},
6281 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6282 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6283 "0x1 not within flag-matching ranges in pipeline layout"},
6284 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6285 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6286 "0x1 not within flag-matching ranges in pipeline layout"},
6287 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006288 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006289 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006290 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6291 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006292 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006293 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006294 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006295 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006296 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006297 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6299 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006300 iter.range.size, dummy_values);
6301 m_errorMonitor->VerifyFound();
6302 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006303 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6304
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006305 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006306}
6307
Karl Schultz6addd812016-02-02 17:17:23 -07006308TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006309 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006310 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006311
6312 ASSERT_NO_FATAL_FAILURE(InitState());
6313 ASSERT_NO_FATAL_FAILURE(InitViewport());
6314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6315
Mike Stroyanb8a61002016-06-20 16:00:28 -06006316 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6317 VkImageTiling tiling;
6318 VkFormatProperties format_properties;
6319 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006320 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006321 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006322 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006323 tiling = VK_IMAGE_TILING_OPTIMAL;
6324 } else {
6325 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6326 "skipped.\n");
6327 return;
6328 }
6329
Tobin Ehlis559c6382015-11-05 09:52:49 -07006330 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6331 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006332 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6333 ds_type_count[0].descriptorCount = 10;
6334 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6335 ds_type_count[1].descriptorCount = 2;
6336 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6337 ds_type_count[2].descriptorCount = 2;
6338 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6339 ds_type_count[3].descriptorCount = 5;
6340 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6341 // type
6342 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6343 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6344 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006345
6346 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006347 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6348 ds_pool_ci.pNext = NULL;
6349 ds_pool_ci.maxSets = 5;
6350 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6351 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006352
6353 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006354 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006355 ASSERT_VK_SUCCESS(err);
6356
6357 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6358 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006359 dsl_binding[0].binding = 0;
6360 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6361 dsl_binding[0].descriptorCount = 5;
6362 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6363 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006364
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006365 // Create layout identical to set0 layout but w/ different stageFlags
6366 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006367 dsl_fs_stage_only.binding = 0;
6368 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6369 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006370 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6371 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006372 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006373 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006374 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6375 ds_layout_ci.pNext = NULL;
6376 ds_layout_ci.bindingCount = 1;
6377 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006378 static const uint32_t NUM_LAYOUTS = 4;
6379 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006380 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006381 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6382 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006383 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006384 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006385 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006386 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006387 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006388 dsl_binding[0].binding = 0;
6389 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006390 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006391 dsl_binding[1].binding = 1;
6392 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6393 dsl_binding[1].descriptorCount = 2;
6394 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6395 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006396 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006397 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006398 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006399 ASSERT_VK_SUCCESS(err);
6400 dsl_binding[0].binding = 0;
6401 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006402 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006403 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006404 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006405 ASSERT_VK_SUCCESS(err);
6406 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006407 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006408 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006409 ASSERT_VK_SUCCESS(err);
6410
6411 static const uint32_t NUM_SETS = 4;
6412 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6413 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006414 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006415 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006416 alloc_info.descriptorPool = ds_pool;
6417 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006418 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006419 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006420 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006421 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006422 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006423 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006424 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006425
6426 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006427 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6428 pipeline_layout_ci.pNext = NULL;
6429 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6430 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006431
6432 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006433 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006434 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006435 // Create pipelineLayout with only one setLayout
6436 pipeline_layout_ci.setLayoutCount = 1;
6437 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006438 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006439 ASSERT_VK_SUCCESS(err);
6440 // Create pipelineLayout with 2 descriptor setLayout at index 0
6441 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6442 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006443 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006444 ASSERT_VK_SUCCESS(err);
6445 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6446 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6447 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006448 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006449 ASSERT_VK_SUCCESS(err);
6450 // Create pipelineLayout with UB type, but stageFlags for FS only
6451 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6452 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006453 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006454 ASSERT_VK_SUCCESS(err);
6455 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6456 VkDescriptorSetLayout pl_bad_s0[2] = {};
6457 pl_bad_s0[0] = ds_layout_fs_only;
6458 pl_bad_s0[1] = ds_layout[1];
6459 pipeline_layout_ci.setLayoutCount = 2;
6460 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6461 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006462 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006463 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006464
6465 // Create a buffer to update the descriptor with
6466 uint32_t qfi = 0;
6467 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006468 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6469 buffCI.size = 1024;
6470 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6471 buffCI.queueFamilyIndexCount = 1;
6472 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006473
6474 VkBuffer dyub;
6475 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6476 ASSERT_VK_SUCCESS(err);
6477 // Correctly update descriptor to avoid "NOT_UPDATED" error
6478 static const uint32_t NUM_BUFFS = 5;
6479 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006480 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006481 buffInfo[i].buffer = dyub;
6482 buffInfo[i].offset = 0;
6483 buffInfo[i].range = 1024;
6484 }
Karl Schultz6addd812016-02-02 17:17:23 -07006485 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006486 const int32_t tex_width = 32;
6487 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006488 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006489 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6490 image_create_info.pNext = NULL;
6491 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6492 image_create_info.format = tex_format;
6493 image_create_info.extent.width = tex_width;
6494 image_create_info.extent.height = tex_height;
6495 image_create_info.extent.depth = 1;
6496 image_create_info.mipLevels = 1;
6497 image_create_info.arrayLayers = 1;
6498 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006499 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006500 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006501 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006502 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6503 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006504
Karl Schultz6addd812016-02-02 17:17:23 -07006505 VkMemoryRequirements memReqs;
6506 VkDeviceMemory imageMem;
6507 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006508 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006509 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6510 memAlloc.pNext = NULL;
6511 memAlloc.allocationSize = 0;
6512 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006513 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6514 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006515 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006516 ASSERT_TRUE(pass);
6517 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6518 ASSERT_VK_SUCCESS(err);
6519 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6520 ASSERT_VK_SUCCESS(err);
6521
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006522 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006523 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6524 image_view_create_info.image = image;
6525 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6526 image_view_create_info.format = tex_format;
6527 image_view_create_info.subresourceRange.layerCount = 1;
6528 image_view_create_info.subresourceRange.baseMipLevel = 0;
6529 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006530 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006531
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006532 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006533 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006534 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006535 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006536 imageInfo[0].imageView = view;
6537 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6538 imageInfo[1].imageView = view;
6539 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006540 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006541 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006542 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006543 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006544
6545 static const uint32_t NUM_SET_UPDATES = 3;
6546 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6547 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6548 descriptor_write[0].dstSet = descriptorSet[0];
6549 descriptor_write[0].dstBinding = 0;
6550 descriptor_write[0].descriptorCount = 5;
6551 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6552 descriptor_write[0].pBufferInfo = buffInfo;
6553 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6554 descriptor_write[1].dstSet = descriptorSet[1];
6555 descriptor_write[1].dstBinding = 0;
6556 descriptor_write[1].descriptorCount = 2;
6557 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6558 descriptor_write[1].pImageInfo = imageInfo;
6559 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6560 descriptor_write[2].dstSet = descriptorSet[1];
6561 descriptor_write[2].dstBinding = 1;
6562 descriptor_write[2].descriptorCount = 2;
6563 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006564 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006565
6566 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006567
Tobin Ehlis88452832015-12-03 09:40:56 -07006568 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006569 char const *vsSource = "#version 450\n"
6570 "\n"
6571 "out gl_PerVertex {\n"
6572 " vec4 gl_Position;\n"
6573 "};\n"
6574 "void main(){\n"
6575 " gl_Position = vec4(1);\n"
6576 "}\n";
6577 char const *fsSource = "#version 450\n"
6578 "\n"
6579 "layout(location=0) out vec4 x;\n"
6580 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6581 "void main(){\n"
6582 " x = vec4(bar.y);\n"
6583 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006584 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6585 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006586 VkPipelineObj pipe(m_device);
6587 pipe.AddShader(&vs);
6588 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006589 pipe.AddColorAttachment();
6590 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006591
6592 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006593
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006594 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006595 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6596 // of PSO
6597 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6598 // cmd_pipeline.c
6599 // due to the fact that cmd_alloc_dset_data() has not been called in
6600 // cmd_bind_graphics_pipeline()
6601 // TODO : Want to cause various binding incompatibility issues here to test
6602 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006603 // First cause various verify_layout_compatibility() fails
6604 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006605 // verify_set_layout_compatibility fail cases:
6606 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6608 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6609 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006610 m_errorMonitor->VerifyFound();
6611
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006612 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6614 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6615 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006616 m_errorMonitor->VerifyFound();
6617
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006618 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006619 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6620 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6622 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6623 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006624 m_errorMonitor->VerifyFound();
6625
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006626 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6627 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6629 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6630 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006631 m_errorMonitor->VerifyFound();
6632
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006633 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6634 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6636 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6637 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6638 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006639 m_errorMonitor->VerifyFound();
6640
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006641 // Cause INFO messages due to disturbing previously bound Sets
6642 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006643 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6644 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006645 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6647 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6648 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006649 m_errorMonitor->VerifyFound();
6650
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006651 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6652 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006653 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6655 "any subsequent sets were disturbed ");
6656 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6657 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006658 m_errorMonitor->VerifyFound();
6659
Tobin Ehlis10fad692016-07-07 12:00:36 -06006660 // Now that we're done actively using the pipelineLayout that gfx pipeline
6661 // was created with, we should be able to delete it. Do that now to verify
6662 // that validation obeys pipelineLayout lifetime
6663 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6664
Tobin Ehlis88452832015-12-03 09:40:56 -07006665 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006666 // 1. Error due to not binding required set (we actually use same code as
6667 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006668 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6669 &descriptorSet[0], 0, NULL);
6670 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6671 &descriptorSet[1], 0, NULL);
6672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07006673 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006674 m_errorMonitor->VerifyFound();
6675
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006676 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006677 // 2. Error due to bound set not being compatible with PSO's
6678 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006679 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6680 &descriptorSet[0], 0, NULL);
6681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006682 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006683 m_errorMonitor->VerifyFound();
6684
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006685 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006686 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006687 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6688 }
6689 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006690 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006691 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6692 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006693 vkFreeMemory(m_device->device(), imageMem, NULL);
6694 vkDestroyImage(m_device->device(), image, NULL);
6695 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006696}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006697
Karl Schultz6addd812016-02-02 17:17:23 -07006698TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006699
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6701 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006702
6703 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006704 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006705 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006706 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006707
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006708 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006709}
6710
Karl Schultz6addd812016-02-02 17:17:23 -07006711TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6712 VkResult err;
6713 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006714
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006716
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006717 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006718
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006719 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006720 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006721 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006722 cmd.commandPool = m_commandPool;
6723 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006724 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006725
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006726 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006727 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006728
6729 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006730 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006731 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006732 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006733 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006734 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006735 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006736
6737 // The error should be caught by validation of the BeginCommandBuffer call
6738 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6739
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006740 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006741 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006742}
6743
Karl Schultz6addd812016-02-02 17:17:23 -07006744TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006745 // Cause error due to Begin while recording CB
6746 // Then cause 2 errors for attempting to reset CB w/o having
6747 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6748 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006750
6751 ASSERT_NO_FATAL_FAILURE(InitState());
6752
6753 // Calls AllocateCommandBuffers
6754 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6755
Karl Schultz6addd812016-02-02 17:17:23 -07006756 // Force the failure by setting the Renderpass and Framebuffer fields with
6757 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006758 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006759 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006760 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6761 cmd_buf_info.pNext = NULL;
6762 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006763 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006764
6765 // Begin CB to transition to recording state
6766 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6767 // Can't re-begin. This should trigger error
6768 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006769 m_errorMonitor->VerifyFound();
6770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006772 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6773 // Reset attempt will trigger error due to incorrect CommandPool state
6774 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006775 m_errorMonitor->VerifyFound();
6776
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006778 // Transition CB to RECORDED state
6779 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6780 // Now attempting to Begin will implicitly reset, which triggers error
6781 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006782 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006783}
6784
Karl Schultz6addd812016-02-02 17:17:23 -07006785TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006786 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006787 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006788
Mike Weiblencce7ec72016-10-17 19:33:05 -06006789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006790
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006791 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006793
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006794 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006795 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6796 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006797
6798 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006799 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6800 ds_pool_ci.pNext = NULL;
6801 ds_pool_ci.maxSets = 1;
6802 ds_pool_ci.poolSizeCount = 1;
6803 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006804
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006805 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006806 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006807 ASSERT_VK_SUCCESS(err);
6808
Tony Barboureb254902015-07-15 12:50:33 -06006809 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006810 dsl_binding.binding = 0;
6811 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6812 dsl_binding.descriptorCount = 1;
6813 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6814 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006815
Tony Barboureb254902015-07-15 12:50:33 -06006816 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006817 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6818 ds_layout_ci.pNext = NULL;
6819 ds_layout_ci.bindingCount = 1;
6820 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006821
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006822 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006823 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006824 ASSERT_VK_SUCCESS(err);
6825
6826 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006827 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006828 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006829 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006830 alloc_info.descriptorPool = ds_pool;
6831 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006832 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006833 ASSERT_VK_SUCCESS(err);
6834
Tony Barboureb254902015-07-15 12:50:33 -06006835 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006836 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6837 pipeline_layout_ci.setLayoutCount = 1;
6838 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006839
6840 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006841 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006842 ASSERT_VK_SUCCESS(err);
6843
Tobin Ehlise68360f2015-10-01 11:15:13 -06006844 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006845 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006846
6847 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006848 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6849 vp_state_ci.scissorCount = 1;
6850 vp_state_ci.pScissors = &sc;
6851 vp_state_ci.viewportCount = 1;
6852 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006853
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006854 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6855 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6856 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6857 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6858 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6859 rs_state_ci.depthClampEnable = VK_FALSE;
6860 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6861 rs_state_ci.depthBiasEnable = VK_FALSE;
6862
Tony Barboureb254902015-07-15 12:50:33 -06006863 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006864 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6865 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006866 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006867 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6868 gp_ci.layout = pipeline_layout;
6869 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006870
6871 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006872 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6873 pc_ci.initialDataSize = 0;
6874 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006875
6876 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006877 VkPipelineCache pipelineCache;
6878
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006879 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006880 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006881 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006882
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006883 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006884
Chia-I Wuf7458c52015-10-26 21:10:41 +08006885 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6886 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6887 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6888 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006889}
Tobin Ehlis912df022015-09-17 08:46:18 -06006890/*// TODO : This test should be good, but needs Tess support in compiler to run
6891TEST_F(VkLayerTest, InvalidPatchControlPoints)
6892{
6893 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006894 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006895
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006897 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6898primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006899
Tobin Ehlis912df022015-09-17 08:46:18 -06006900 ASSERT_NO_FATAL_FAILURE(InitState());
6901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006902
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006903 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006904 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006905 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006906
6907 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6908 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6909 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006910 ds_pool_ci.poolSizeCount = 1;
6911 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006912
6913 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006914 err = vkCreateDescriptorPool(m_device->device(),
6915VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006916 ASSERT_VK_SUCCESS(err);
6917
6918 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006919 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006920 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006921 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006922 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6923 dsl_binding.pImmutableSamplers = NULL;
6924
6925 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006926 ds_layout_ci.sType =
6927VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006928 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006929 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006930 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006931
6932 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006933 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6934&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006935 ASSERT_VK_SUCCESS(err);
6936
6937 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006938 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6939VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006940 ASSERT_VK_SUCCESS(err);
6941
6942 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006943 pipeline_layout_ci.sType =
6944VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006945 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006946 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006947 pipeline_layout_ci.pSetLayouts = &ds_layout;
6948
6949 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006950 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6951&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006952 ASSERT_VK_SUCCESS(err);
6953
6954 VkPipelineShaderStageCreateInfo shaderStages[3];
6955 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6956
Karl Schultz6addd812016-02-02 17:17:23 -07006957 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6958this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006959 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006960 VkShaderObj
6961tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6962this);
6963 VkShaderObj
6964te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6965this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006966
Karl Schultz6addd812016-02-02 17:17:23 -07006967 shaderStages[0].sType =
6968VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006969 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006970 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006971 shaderStages[1].sType =
6972VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006973 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006974 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006975 shaderStages[2].sType =
6976VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006977 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006978 shaderStages[2].shader = te.handle();
6979
6980 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006981 iaCI.sType =
6982VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006983 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006984
6985 VkPipelineTessellationStateCreateInfo tsCI = {};
6986 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6987 tsCI.patchControlPoints = 0; // This will cause an error
6988
6989 VkGraphicsPipelineCreateInfo gp_ci = {};
6990 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6991 gp_ci.pNext = NULL;
6992 gp_ci.stageCount = 3;
6993 gp_ci.pStages = shaderStages;
6994 gp_ci.pVertexInputState = NULL;
6995 gp_ci.pInputAssemblyState = &iaCI;
6996 gp_ci.pTessellationState = &tsCI;
6997 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006998 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006999 gp_ci.pMultisampleState = NULL;
7000 gp_ci.pDepthStencilState = NULL;
7001 gp_ci.pColorBlendState = NULL;
7002 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7003 gp_ci.layout = pipeline_layout;
7004 gp_ci.renderPass = renderPass();
7005
7006 VkPipelineCacheCreateInfo pc_ci = {};
7007 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7008 pc_ci.pNext = NULL;
7009 pc_ci.initialSize = 0;
7010 pc_ci.initialData = 0;
7011 pc_ci.maxSize = 0;
7012
7013 VkPipeline pipeline;
7014 VkPipelineCache pipelineCache;
7015
Karl Schultz6addd812016-02-02 17:17:23 -07007016 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7017&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007018 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007019 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7020&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007021
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007022 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007023
Chia-I Wuf7458c52015-10-26 21:10:41 +08007024 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7025 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7026 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7027 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007028}
7029*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06007030// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07007031TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007032 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7035 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007036
Tobin Ehlise68360f2015-10-01 11:15:13 -06007037 ASSERT_NO_FATAL_FAILURE(InitState());
7038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007039
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007040 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007041 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7042 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007043
7044 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007045 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7046 ds_pool_ci.maxSets = 1;
7047 ds_pool_ci.poolSizeCount = 1;
7048 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007049
7050 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007051 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007052 ASSERT_VK_SUCCESS(err);
7053
7054 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007055 dsl_binding.binding = 0;
7056 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7057 dsl_binding.descriptorCount = 1;
7058 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007059
7060 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007061 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7062 ds_layout_ci.bindingCount = 1;
7063 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007064
7065 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007066 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007067 ASSERT_VK_SUCCESS(err);
7068
7069 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007070 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007071 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007072 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007073 alloc_info.descriptorPool = ds_pool;
7074 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007075 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007076 ASSERT_VK_SUCCESS(err);
7077
7078 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007079 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7080 pipeline_layout_ci.setLayoutCount = 1;
7081 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007082
7083 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007084 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007085 ASSERT_VK_SUCCESS(err);
7086
7087 VkViewport vp = {}; // Just need dummy vp to point to
7088
7089 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007090 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7091 vp_state_ci.scissorCount = 0;
7092 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7093 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007094
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007095 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7096 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7097 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7098 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7099 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7100 rs_state_ci.depthClampEnable = VK_FALSE;
7101 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7102 rs_state_ci.depthBiasEnable = VK_FALSE;
7103
Cody Northropeb3a6c12015-10-05 14:44:45 -06007104 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007105 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007106
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007107 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7108 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7109 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007110 shaderStages[0] = vs.GetStageCreateInfo();
7111 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007112
7113 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007114 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7115 gp_ci.stageCount = 2;
7116 gp_ci.pStages = shaderStages;
7117 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007118 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007119 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7120 gp_ci.layout = pipeline_layout;
7121 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007122
7123 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007124 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007125
7126 VkPipeline pipeline;
7127 VkPipelineCache pipelineCache;
7128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007129 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007130 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007131 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007132
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007133 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007134
Chia-I Wuf7458c52015-10-26 21:10:41 +08007135 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7136 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7137 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7138 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007139}
Karl Schultz6addd812016-02-02 17:17:23 -07007140// Don't set viewport state in PSO. This is an error b/c we always need this
7141// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007142// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007143TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007144 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007145 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007146
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007148
Tobin Ehlise68360f2015-10-01 11:15:13 -06007149 ASSERT_NO_FATAL_FAILURE(InitState());
7150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007151
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007152 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007153 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7154 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007155
7156 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007157 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7158 ds_pool_ci.maxSets = 1;
7159 ds_pool_ci.poolSizeCount = 1;
7160 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007161
7162 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007163 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007164 ASSERT_VK_SUCCESS(err);
7165
7166 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007167 dsl_binding.binding = 0;
7168 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7169 dsl_binding.descriptorCount = 1;
7170 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007171
7172 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007173 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7174 ds_layout_ci.bindingCount = 1;
7175 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007176
7177 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007178 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007179 ASSERT_VK_SUCCESS(err);
7180
7181 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007182 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007183 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007184 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007185 alloc_info.descriptorPool = ds_pool;
7186 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007187 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007188 ASSERT_VK_SUCCESS(err);
7189
7190 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007191 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7192 pipeline_layout_ci.setLayoutCount = 1;
7193 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007194
7195 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007196 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007197 ASSERT_VK_SUCCESS(err);
7198
7199 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7200 // Set scissor as dynamic to avoid second error
7201 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007202 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7203 dyn_state_ci.dynamicStateCount = 1;
7204 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007205
Cody Northropeb3a6c12015-10-05 14:44:45 -06007206 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007207 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007209 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7210 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7211 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007212 shaderStages[0] = vs.GetStageCreateInfo();
7213 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007214
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007215 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7216 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7217 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7218 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7219 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7220 rs_state_ci.depthClampEnable = VK_FALSE;
7221 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7222 rs_state_ci.depthBiasEnable = VK_FALSE;
7223
Tobin Ehlise68360f2015-10-01 11:15:13 -06007224 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007225 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7226 gp_ci.stageCount = 2;
7227 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007228 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007229 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7230 // should cause validation error
7231 gp_ci.pDynamicState = &dyn_state_ci;
7232 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7233 gp_ci.layout = pipeline_layout;
7234 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007235
7236 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007237 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007238
7239 VkPipeline pipeline;
7240 VkPipelineCache pipelineCache;
7241
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007242 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007243 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007244 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007245
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007246 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007247
Chia-I Wuf7458c52015-10-26 21:10:41 +08007248 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7249 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7250 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7251 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007252}
7253// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007254// Then run second test where dynamic scissor count doesn't match PSO scissor
7255// count
7256TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7257 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007258
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7260 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007261
Tobin Ehlise68360f2015-10-01 11:15:13 -06007262 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007263
7264 if (!m_device->phy().features().multiViewport) {
7265 printf("Device does not support multiple viewports/scissors; skipped.\n");
7266 return;
7267 }
7268
Tobin Ehlise68360f2015-10-01 11:15:13 -06007269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007270
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007271 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007272 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7273 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007274
7275 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007276 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7277 ds_pool_ci.maxSets = 1;
7278 ds_pool_ci.poolSizeCount = 1;
7279 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007280
7281 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007282 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007283 ASSERT_VK_SUCCESS(err);
7284
7285 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007286 dsl_binding.binding = 0;
7287 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7288 dsl_binding.descriptorCount = 1;
7289 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007290
7291 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007292 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7293 ds_layout_ci.bindingCount = 1;
7294 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007295
7296 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007297 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007298 ASSERT_VK_SUCCESS(err);
7299
7300 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007301 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007302 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007303 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007304 alloc_info.descriptorPool = ds_pool;
7305 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007306 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007307 ASSERT_VK_SUCCESS(err);
7308
7309 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007310 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7311 pipeline_layout_ci.setLayoutCount = 1;
7312 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007313
7314 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007315 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007316 ASSERT_VK_SUCCESS(err);
7317
7318 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007319 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7320 vp_state_ci.viewportCount = 1;
7321 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7322 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007323 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007324
7325 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7326 // Set scissor as dynamic to avoid that error
7327 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007328 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7329 dyn_state_ci.dynamicStateCount = 1;
7330 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007331
Cody Northropeb3a6c12015-10-05 14:44:45 -06007332 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007333 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007334
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007335 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7336 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7337 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007338 shaderStages[0] = vs.GetStageCreateInfo();
7339 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007340
Cody Northropf6622dc2015-10-06 10:33:21 -06007341 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7342 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7343 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007344 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007345 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007346 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007347 vi_ci.pVertexAttributeDescriptions = nullptr;
7348
7349 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7350 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7351 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7352
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007353 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007354 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007355 rs_ci.pNext = nullptr;
7356
Mark Youngc89c6312016-03-31 16:03:20 -06007357 VkPipelineColorBlendAttachmentState att = {};
7358 att.blendEnable = VK_FALSE;
7359 att.colorWriteMask = 0xf;
7360
Cody Northropf6622dc2015-10-06 10:33:21 -06007361 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7362 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7363 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007364 cb_ci.attachmentCount = 1;
7365 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007366
Tobin Ehlise68360f2015-10-01 11:15:13 -06007367 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007368 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7369 gp_ci.stageCount = 2;
7370 gp_ci.pStages = shaderStages;
7371 gp_ci.pVertexInputState = &vi_ci;
7372 gp_ci.pInputAssemblyState = &ia_ci;
7373 gp_ci.pViewportState = &vp_state_ci;
7374 gp_ci.pRasterizationState = &rs_ci;
7375 gp_ci.pColorBlendState = &cb_ci;
7376 gp_ci.pDynamicState = &dyn_state_ci;
7377 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7378 gp_ci.layout = pipeline_layout;
7379 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007380
7381 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007382 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007383
7384 VkPipeline pipeline;
7385 VkPipelineCache pipelineCache;
7386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007387 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007388 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007389 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007390
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007391 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007392
Tobin Ehlisd332f282015-10-02 11:00:56 -06007393 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007394 // First need to successfully create the PSO from above by setting
7395 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by pipeline state object, ");
Karl Schultz6addd812016-02-02 17:17:23 -07007397
7398 VkViewport vp = {}; // Just need dummy vp to point to
7399 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007400 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007401 ASSERT_VK_SUCCESS(err);
7402 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007403 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007404 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007405 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007406 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007407 Draw(1, 0, 0, 0);
7408
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007409 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007410
7411 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7412 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7413 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7414 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007415 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007416}
7417// Create PSO w/o non-zero scissorCount but no scissor data
7418// Then run second test where dynamic viewportCount doesn't match PSO
7419// viewportCount
7420TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7421 VkResult err;
7422
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
Karl Schultz6addd812016-02-02 17:17:23 -07007424
7425 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007426
7427 if (!m_device->phy().features().multiViewport) {
7428 printf("Device does not support multiple viewports/scissors; skipped.\n");
7429 return;
7430 }
7431
Karl Schultz6addd812016-02-02 17:17:23 -07007432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7433
7434 VkDescriptorPoolSize ds_type_count = {};
7435 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7436 ds_type_count.descriptorCount = 1;
7437
7438 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7439 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7440 ds_pool_ci.maxSets = 1;
7441 ds_pool_ci.poolSizeCount = 1;
7442 ds_pool_ci.pPoolSizes = &ds_type_count;
7443
7444 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007445 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007446 ASSERT_VK_SUCCESS(err);
7447
7448 VkDescriptorSetLayoutBinding dsl_binding = {};
7449 dsl_binding.binding = 0;
7450 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7451 dsl_binding.descriptorCount = 1;
7452 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7453
7454 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7455 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7456 ds_layout_ci.bindingCount = 1;
7457 ds_layout_ci.pBindings = &dsl_binding;
7458
7459 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007460 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007461 ASSERT_VK_SUCCESS(err);
7462
7463 VkDescriptorSet descriptorSet;
7464 VkDescriptorSetAllocateInfo alloc_info = {};
7465 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7466 alloc_info.descriptorSetCount = 1;
7467 alloc_info.descriptorPool = ds_pool;
7468 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007469 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007470 ASSERT_VK_SUCCESS(err);
7471
7472 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7473 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7474 pipeline_layout_ci.setLayoutCount = 1;
7475 pipeline_layout_ci.pSetLayouts = &ds_layout;
7476
7477 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007478 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007479 ASSERT_VK_SUCCESS(err);
7480
7481 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7482 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7483 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007484 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007485 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007486 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007487
7488 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7489 // Set scissor as dynamic to avoid that error
7490 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7491 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7492 dyn_state_ci.dynamicStateCount = 1;
7493 dyn_state_ci.pDynamicStates = &vp_state;
7494
7495 VkPipelineShaderStageCreateInfo shaderStages[2];
7496 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7497
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007498 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7499 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7500 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007501 shaderStages[0] = vs.GetStageCreateInfo();
7502 shaderStages[1] = fs.GetStageCreateInfo();
7503
7504 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7505 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7506 vi_ci.pNext = nullptr;
7507 vi_ci.vertexBindingDescriptionCount = 0;
7508 vi_ci.pVertexBindingDescriptions = nullptr;
7509 vi_ci.vertexAttributeDescriptionCount = 0;
7510 vi_ci.pVertexAttributeDescriptions = nullptr;
7511
7512 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7513 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7514 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7515
7516 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7517 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7518 rs_ci.pNext = nullptr;
7519
Mark Youngc89c6312016-03-31 16:03:20 -06007520 VkPipelineColorBlendAttachmentState att = {};
7521 att.blendEnable = VK_FALSE;
7522 att.colorWriteMask = 0xf;
7523
Karl Schultz6addd812016-02-02 17:17:23 -07007524 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7525 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7526 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007527 cb_ci.attachmentCount = 1;
7528 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007529
7530 VkGraphicsPipelineCreateInfo gp_ci = {};
7531 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7532 gp_ci.stageCount = 2;
7533 gp_ci.pStages = shaderStages;
7534 gp_ci.pVertexInputState = &vi_ci;
7535 gp_ci.pInputAssemblyState = &ia_ci;
7536 gp_ci.pViewportState = &vp_state_ci;
7537 gp_ci.pRasterizationState = &rs_ci;
7538 gp_ci.pColorBlendState = &cb_ci;
7539 gp_ci.pDynamicState = &dyn_state_ci;
7540 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7541 gp_ci.layout = pipeline_layout;
7542 gp_ci.renderPass = renderPass();
7543
7544 VkPipelineCacheCreateInfo pc_ci = {};
7545 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7546
7547 VkPipeline pipeline;
7548 VkPipelineCache pipelineCache;
7549
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007550 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007551 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007552 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007553
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007554 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007555
7556 // Now hit second fail case where we set scissor w/ different count than PSO
7557 // First need to successfully create the PSO from above by setting
7558 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007560
Tobin Ehlisd332f282015-10-02 11:00:56 -06007561 VkRect2D sc = {}; // Just need dummy vp to point to
7562 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007563 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007564 ASSERT_VK_SUCCESS(err);
7565 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007566 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007567 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007568 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007569 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007570 Draw(1, 0, 0, 0);
7571
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007572 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007573
Chia-I Wuf7458c52015-10-26 21:10:41 +08007574 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7575 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7576 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7577 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007578 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007579}
7580
Mark Young7394fdd2016-03-31 14:56:43 -06007581TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7582 VkResult err;
7583
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007585
7586 ASSERT_NO_FATAL_FAILURE(InitState());
7587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7588
7589 VkDescriptorPoolSize ds_type_count = {};
7590 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7591 ds_type_count.descriptorCount = 1;
7592
7593 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7594 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7595 ds_pool_ci.maxSets = 1;
7596 ds_pool_ci.poolSizeCount = 1;
7597 ds_pool_ci.pPoolSizes = &ds_type_count;
7598
7599 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007600 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007601 ASSERT_VK_SUCCESS(err);
7602
7603 VkDescriptorSetLayoutBinding dsl_binding = {};
7604 dsl_binding.binding = 0;
7605 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7606 dsl_binding.descriptorCount = 1;
7607 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7608
7609 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7610 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7611 ds_layout_ci.bindingCount = 1;
7612 ds_layout_ci.pBindings = &dsl_binding;
7613
7614 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007615 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007616 ASSERT_VK_SUCCESS(err);
7617
7618 VkDescriptorSet descriptorSet;
7619 VkDescriptorSetAllocateInfo alloc_info = {};
7620 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7621 alloc_info.descriptorSetCount = 1;
7622 alloc_info.descriptorPool = ds_pool;
7623 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007624 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007625 ASSERT_VK_SUCCESS(err);
7626
7627 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7628 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7629 pipeline_layout_ci.setLayoutCount = 1;
7630 pipeline_layout_ci.pSetLayouts = &ds_layout;
7631
7632 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007633 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007634 ASSERT_VK_SUCCESS(err);
7635
7636 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7637 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7638 vp_state_ci.scissorCount = 1;
7639 vp_state_ci.pScissors = NULL;
7640 vp_state_ci.viewportCount = 1;
7641 vp_state_ci.pViewports = NULL;
7642
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007643 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007644 // Set scissor as dynamic to avoid that error
7645 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7646 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7647 dyn_state_ci.dynamicStateCount = 2;
7648 dyn_state_ci.pDynamicStates = dynamic_states;
7649
7650 VkPipelineShaderStageCreateInfo shaderStages[2];
7651 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7652
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007653 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7654 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007655 this); // TODO - We shouldn't need a fragment shader
7656 // but add it to be able to run on more devices
7657 shaderStages[0] = vs.GetStageCreateInfo();
7658 shaderStages[1] = fs.GetStageCreateInfo();
7659
7660 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7661 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7662 vi_ci.pNext = nullptr;
7663 vi_ci.vertexBindingDescriptionCount = 0;
7664 vi_ci.pVertexBindingDescriptions = nullptr;
7665 vi_ci.vertexAttributeDescriptionCount = 0;
7666 vi_ci.pVertexAttributeDescriptions = nullptr;
7667
7668 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7669 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7670 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7671
7672 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7673 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7674 rs_ci.pNext = nullptr;
7675
Mark Young47107952016-05-02 15:59:55 -06007676 // Check too low (line width of -1.0f).
7677 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007678
7679 VkPipelineColorBlendAttachmentState att = {};
7680 att.blendEnable = VK_FALSE;
7681 att.colorWriteMask = 0xf;
7682
7683 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7684 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7685 cb_ci.pNext = nullptr;
7686 cb_ci.attachmentCount = 1;
7687 cb_ci.pAttachments = &att;
7688
7689 VkGraphicsPipelineCreateInfo gp_ci = {};
7690 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7691 gp_ci.stageCount = 2;
7692 gp_ci.pStages = shaderStages;
7693 gp_ci.pVertexInputState = &vi_ci;
7694 gp_ci.pInputAssemblyState = &ia_ci;
7695 gp_ci.pViewportState = &vp_state_ci;
7696 gp_ci.pRasterizationState = &rs_ci;
7697 gp_ci.pColorBlendState = &cb_ci;
7698 gp_ci.pDynamicState = &dyn_state_ci;
7699 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7700 gp_ci.layout = pipeline_layout;
7701 gp_ci.renderPass = renderPass();
7702
7703 VkPipelineCacheCreateInfo pc_ci = {};
7704 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7705
7706 VkPipeline pipeline;
7707 VkPipelineCache pipelineCache;
7708
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007709 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007710 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007711 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007712
7713 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007714 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007715
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007717
7718 // Check too high (line width of 65536.0f).
7719 rs_ci.lineWidth = 65536.0f;
7720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007721 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007722 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007723 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007724
7725 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007726 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007729
7730 dyn_state_ci.dynamicStateCount = 3;
7731
7732 rs_ci.lineWidth = 1.0f;
7733
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007734 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007735 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007736 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007737 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007738 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007739
7740 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007741 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007742 m_errorMonitor->VerifyFound();
7743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007745
7746 // Check too high with dynamic setting.
7747 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7748 m_errorMonitor->VerifyFound();
7749 EndCommandBuffer();
7750
7751 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7752 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7753 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7754 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007755 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007756}
7757
Karl Schultz6addd812016-02-02 17:17:23 -07007758TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007759 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7761 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007762
7763 ASSERT_NO_FATAL_FAILURE(InitState());
7764 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007765
Tony Barbourfe3351b2015-07-28 10:17:20 -06007766 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007767 // Don't care about RenderPass handle b/c error should be flagged before
7768 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007769 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007770
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007771 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007772}
7773
Karl Schultz6addd812016-02-02 17:17:23 -07007774TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007775 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7777 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007778
7779 ASSERT_NO_FATAL_FAILURE(InitState());
7780 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007781
Tony Barbourfe3351b2015-07-28 10:17:20 -06007782 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007783 // Just create a dummy Renderpass that's non-NULL so we can get to the
7784 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007785 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007786
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007787 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007788}
7789
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007790TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7791 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7792 "the number of renderPass attachments that use loadOp"
7793 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7794
7795 ASSERT_NO_FATAL_FAILURE(InitState());
7796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7797
7798 // Create a renderPass with a single attachment that uses loadOp CLEAR
7799 VkAttachmentReference attach = {};
7800 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7801 VkSubpassDescription subpass = {};
7802 subpass.inputAttachmentCount = 1;
7803 subpass.pInputAttachments = &attach;
7804 VkRenderPassCreateInfo rpci = {};
7805 rpci.subpassCount = 1;
7806 rpci.pSubpasses = &subpass;
7807 rpci.attachmentCount = 1;
7808 VkAttachmentDescription attach_desc = {};
7809 attach_desc.format = VK_FORMAT_UNDEFINED;
7810 // Set loadOp to CLEAR
7811 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7812 rpci.pAttachments = &attach_desc;
7813 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7814 VkRenderPass rp;
7815 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7816
7817 VkCommandBufferInheritanceInfo hinfo = {};
7818 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7819 hinfo.renderPass = VK_NULL_HANDLE;
7820 hinfo.subpass = 0;
7821 hinfo.framebuffer = VK_NULL_HANDLE;
7822 hinfo.occlusionQueryEnable = VK_FALSE;
7823 hinfo.queryFlags = 0;
7824 hinfo.pipelineStatistics = 0;
7825 VkCommandBufferBeginInfo info = {};
7826 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7827 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7828 info.pInheritanceInfo = &hinfo;
7829
7830 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7831 VkRenderPassBeginInfo rp_begin = {};
7832 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7833 rp_begin.pNext = NULL;
7834 rp_begin.renderPass = renderPass();
7835 rp_begin.framebuffer = framebuffer();
7836 rp_begin.clearValueCount = 0; // Should be 1
7837
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7839 "there must be at least 1 entries in "
7840 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007841
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007842 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007843
7844 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007845
7846 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007847}
7848
Cody Northrop3bb4d962016-05-09 16:15:57 -06007849TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7850
7851 TEST_DESCRIPTION("End a command buffer with an active render pass");
7852
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7854 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007855
7856 ASSERT_NO_FATAL_FAILURE(InitState());
7857 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7858
7859 // The framework's BeginCommandBuffer calls CreateRenderPass
7860 BeginCommandBuffer();
7861
7862 // Call directly into vkEndCommandBuffer instead of the
7863 // the framework's EndCommandBuffer, which inserts a
7864 // vkEndRenderPass
7865 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7866
7867 m_errorMonitor->VerifyFound();
7868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007869 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7870 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007871}
7872
Karl Schultz6addd812016-02-02 17:17:23 -07007873TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007874 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7876 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007877
7878 ASSERT_NO_FATAL_FAILURE(InitState());
7879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007880
7881 // Renderpass is started here
7882 BeginCommandBuffer();
7883
7884 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007885 vk_testing::Buffer dstBuffer;
7886 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007887
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007888 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007889
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007890 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007891}
7892
Karl Schultz6addd812016-02-02 17:17:23 -07007893TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007894 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7896 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007897
7898 ASSERT_NO_FATAL_FAILURE(InitState());
7899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007900
7901 // Renderpass is started here
7902 BeginCommandBuffer();
7903
7904 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007905 vk_testing::Buffer dstBuffer;
7906 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007907
Karl Schultz6addd812016-02-02 17:17:23 -07007908 VkDeviceSize dstOffset = 0;
7909 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007910 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007912 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007913
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007914 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007915}
7916
Karl Schultz6addd812016-02-02 17:17:23 -07007917TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007918 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7920 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007921
7922 ASSERT_NO_FATAL_FAILURE(InitState());
7923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007924
7925 // Renderpass is started here
7926 BeginCommandBuffer();
7927
Michael Lentine0a369f62016-02-03 16:51:46 -06007928 VkClearColorValue clear_color;
7929 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007930 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7931 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7932 const int32_t tex_width = 32;
7933 const int32_t tex_height = 32;
7934 VkImageCreateInfo image_create_info = {};
7935 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7936 image_create_info.pNext = NULL;
7937 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7938 image_create_info.format = tex_format;
7939 image_create_info.extent.width = tex_width;
7940 image_create_info.extent.height = tex_height;
7941 image_create_info.extent.depth = 1;
7942 image_create_info.mipLevels = 1;
7943 image_create_info.arrayLayers = 1;
7944 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7945 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7946 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007947
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007948 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007949 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007950
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007951 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007952
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007953 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007954
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007955 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007956}
7957
Karl Schultz6addd812016-02-02 17:17:23 -07007958TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007959 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7961 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007962
7963 ASSERT_NO_FATAL_FAILURE(InitState());
7964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007965
7966 // Renderpass is started here
7967 BeginCommandBuffer();
7968
7969 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007970 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007971 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7972 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7973 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7974 image_create_info.extent.width = 64;
7975 image_create_info.extent.height = 64;
7976 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7977 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007978
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007979 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007980 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007981
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007982 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007983
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007984 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7985 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007986
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007987 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007988}
7989
Karl Schultz6addd812016-02-02 17:17:23 -07007990TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007991 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007992 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007993
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
7995 "must be issued inside an active "
7996 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007997
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007998 ASSERT_NO_FATAL_FAILURE(InitState());
7999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008000
8001 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008002 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008003 ASSERT_VK_SUCCESS(err);
8004
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008005 VkClearAttachment color_attachment;
8006 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8007 color_attachment.clearValue.color.float32[0] = 0;
8008 color_attachment.clearValue.color.float32[1] = 0;
8009 color_attachment.clearValue.color.float32[2] = 0;
8010 color_attachment.clearValue.color.float32[3] = 0;
8011 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008012 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008013 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008014
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008015 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008016}
8017
Chris Forbes3b97e932016-09-07 11:29:24 +12008018TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8019 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8020 "called too many times in a renderpass instance");
8021
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8023 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008024
8025 ASSERT_NO_FATAL_FAILURE(InitState());
8026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8027
8028 BeginCommandBuffer();
8029
8030 // error here.
8031 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8032 m_errorMonitor->VerifyFound();
8033
8034 EndCommandBuffer();
8035}
8036
Chris Forbes6d624702016-09-07 13:57:05 +12008037TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8038 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8039 "called before the final subpass has been reached");
8040
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8042 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008043
8044 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008045 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8046 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008047
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008048 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008049
8050 VkRenderPass rp;
8051 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8052 ASSERT_VK_SUCCESS(err);
8053
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008054 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008055
8056 VkFramebuffer fb;
8057 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8058 ASSERT_VK_SUCCESS(err);
8059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008060 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008061
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008062 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {16, 16}}, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008063
8064 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8065
8066 // Error here.
8067 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8068 m_errorMonitor->VerifyFound();
8069
8070 // Clean up.
8071 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8072 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8073}
8074
Karl Schultz9e66a292016-04-21 15:57:51 -06008075TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8076 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8078 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008079
8080 ASSERT_NO_FATAL_FAILURE(InitState());
8081 BeginCommandBuffer();
8082
8083 VkBufferMemoryBarrier buf_barrier = {};
8084 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8085 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8086 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8087 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8088 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8089 buf_barrier.buffer = VK_NULL_HANDLE;
8090 buf_barrier.offset = 0;
8091 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008092 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8093 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008094
8095 m_errorMonitor->VerifyFound();
8096}
8097
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008098TEST_F(VkLayerTest, InvalidBarriers) {
8099 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8100
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008102
8103 ASSERT_NO_FATAL_FAILURE(InitState());
8104 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8105
8106 VkMemoryBarrier mem_barrier = {};
8107 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8108 mem_barrier.pNext = NULL;
8109 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8110 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8111 BeginCommandBuffer();
8112 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008113 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008114 &mem_barrier, 0, nullptr, 0, nullptr);
8115 m_errorMonitor->VerifyFound();
8116
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008118 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008119 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008120 ASSERT_TRUE(image.initialized());
8121 VkImageMemoryBarrier img_barrier = {};
8122 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8123 img_barrier.pNext = NULL;
8124 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8125 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8126 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8127 // New layout can't be UNDEFINED
8128 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8129 img_barrier.image = image.handle();
8130 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8131 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8132 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8133 img_barrier.subresourceRange.baseArrayLayer = 0;
8134 img_barrier.subresourceRange.baseMipLevel = 0;
8135 img_barrier.subresourceRange.layerCount = 1;
8136 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008137 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8138 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008139 m_errorMonitor->VerifyFound();
8140 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8141
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8143 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008144 // baseArrayLayer + layerCount must be <= image's arrayLayers
8145 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008146 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8147 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008148 m_errorMonitor->VerifyFound();
8149 img_barrier.subresourceRange.baseArrayLayer = 0;
8150
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008152 // baseMipLevel + levelCount must be <= image's mipLevels
8153 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008154 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8155 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008156 m_errorMonitor->VerifyFound();
8157 img_barrier.subresourceRange.baseMipLevel = 0;
8158
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Buffer Barriers cannot be used during a render pass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008160 vk_testing::Buffer buffer;
8161 buffer.init(*m_device, 256);
8162 VkBufferMemoryBarrier buf_barrier = {};
8163 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8164 buf_barrier.pNext = NULL;
8165 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8166 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8167 buf_barrier.buffer = buffer.handle();
8168 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8169 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8170 buf_barrier.offset = 0;
8171 buf_barrier.size = VK_WHOLE_SIZE;
8172 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008173 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8174 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008175 m_errorMonitor->VerifyFound();
8176 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8177
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008179 buf_barrier.offset = 257;
8180 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008181 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8182 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008183 m_errorMonitor->VerifyFound();
8184 buf_barrier.offset = 0;
8185
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008187 buf_barrier.size = 257;
8188 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008189 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8190 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008191 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008192
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008193 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008194 m_errorMonitor->SetDesiredFailureMsg(
8195 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8196 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8197 m_errorMonitor->SetDesiredFailureMsg(
8198 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8199 "Depth/stencil image formats must have at least one of VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008200 VkDepthStencilObj ds_image(m_device);
8201 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8202 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008203 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8204 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008205 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008206 // Use of COLOR aspect on DS image is error
8207 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008208 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8209 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008210 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008211 // Now test depth-only
8212 VkFormatProperties format_props;
8213
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008214 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8215 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8217 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8219 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008220 VkDepthStencilObj d_image(m_device);
8221 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8222 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008223 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008224 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008225 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008226 // Use of COLOR aspect on depth image is error
8227 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008228 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8229 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008230 m_errorMonitor->VerifyFound();
8231 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008232 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8233 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008234 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8236 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008237 VkDepthStencilObj s_image(m_device);
8238 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8239 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008240 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008241 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008242 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008243 // Use of COLOR aspect on depth image is error
8244 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008245 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8246 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008247 m_errorMonitor->VerifyFound();
8248 }
8249 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8251 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8253 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008254 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008255 c_image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008256 ASSERT_TRUE(c_image.initialized());
8257 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8258 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8259 img_barrier.image = c_image.handle();
8260 // Set aspect to depth (non-color)
8261 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008262 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8263 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008264 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008265}
8266
Tony Barbour18ba25c2016-09-29 13:42:40 -06008267TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8268 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8269
8270 m_errorMonitor->SetDesiredFailureMsg(
8271 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8272 "must have required access bit");
8273 ASSERT_NO_FATAL_FAILURE(InitState());
8274 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008275 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06008276 ASSERT_TRUE(image.initialized());
8277
8278 VkImageMemoryBarrier barrier = {};
8279 VkImageSubresourceRange range;
8280 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8281 barrier.srcAccessMask = 0;
8282 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8283 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8284 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8285 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8286 barrier.image = image.handle();
8287 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8288 range.baseMipLevel = 0;
8289 range.levelCount = 1;
8290 range.baseArrayLayer = 0;
8291 range.layerCount = 1;
8292 barrier.subresourceRange = range;
8293 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8294 cmdbuf.BeginCommandBuffer();
8295 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8296 &barrier);
8297 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8298 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8299 barrier.srcAccessMask = 0;
8300 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8301 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8302 &barrier);
8303
8304 m_errorMonitor->VerifyFound();
8305}
8306
Karl Schultz6addd812016-02-02 17:17:23 -07008307TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008308 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008309 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008310
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008312
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008313 ASSERT_NO_FATAL_FAILURE(InitState());
8314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008315 uint32_t qfi = 0;
8316 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008317 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8318 buffCI.size = 1024;
8319 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8320 buffCI.queueFamilyIndexCount = 1;
8321 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008322
8323 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008324 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008325 ASSERT_VK_SUCCESS(err);
8326
8327 BeginCommandBuffer();
8328 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008329 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8330 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008331 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008332 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008333
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008334 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008335
Chia-I Wuf7458c52015-10-26 21:10:41 +08008336 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008337}
8338
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008339TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8340 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8342 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8343 "of the indices specified when the device was created, via the "
8344 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008345
8346 ASSERT_NO_FATAL_FAILURE(InitState());
8347 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8348 VkBufferCreateInfo buffCI = {};
8349 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8350 buffCI.size = 1024;
8351 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8352 buffCI.queueFamilyIndexCount = 1;
8353 // Introduce failure by specifying invalid queue_family_index
8354 uint32_t qfi = 777;
8355 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008356 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008357
8358 VkBuffer ib;
8359 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8360
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008361 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008362 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008363}
8364
Karl Schultz6addd812016-02-02 17:17:23 -07008365TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008366TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008367 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008368
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008369 ASSERT_NO_FATAL_FAILURE(InitState());
8370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008371
Chris Forbesf29a84f2016-10-06 18:39:28 +13008372 // An empty primary command buffer
8373 VkCommandBufferObj cb(m_device, m_commandPool);
8374 cb.BeginCommandBuffer();
8375 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008376
Chris Forbesf29a84f2016-10-06 18:39:28 +13008377 m_commandBuffer->BeginCommandBuffer();
8378 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8379 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008380
Chris Forbesf29a84f2016-10-06 18:39:28 +13008381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8382 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008383 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008384}
8385
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008386TEST_F(VkLayerTest, DSUsageBitsErrors) {
8387 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8388 "that do not have correct usage bits sets.");
8389 VkResult err;
8390
8391 ASSERT_NO_FATAL_FAILURE(InitState());
8392 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8393 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8394 ds_type_count[i].type = VkDescriptorType(i);
8395 ds_type_count[i].descriptorCount = 1;
8396 }
8397 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8398 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8399 ds_pool_ci.pNext = NULL;
8400 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8401 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8402 ds_pool_ci.pPoolSizes = ds_type_count;
8403
8404 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008405 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008406 ASSERT_VK_SUCCESS(err);
8407
8408 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008409 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008410 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8411 dsl_binding[i].binding = 0;
8412 dsl_binding[i].descriptorType = VkDescriptorType(i);
8413 dsl_binding[i].descriptorCount = 1;
8414 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8415 dsl_binding[i].pImmutableSamplers = NULL;
8416 }
8417
8418 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8419 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8420 ds_layout_ci.pNext = NULL;
8421 ds_layout_ci.bindingCount = 1;
8422 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8423 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8424 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008425 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008426 ASSERT_VK_SUCCESS(err);
8427 }
8428 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8429 VkDescriptorSetAllocateInfo alloc_info = {};
8430 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8431 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8432 alloc_info.descriptorPool = ds_pool;
8433 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008434 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008435 ASSERT_VK_SUCCESS(err);
8436
8437 // Create a buffer & bufferView to be used for invalid updates
8438 VkBufferCreateInfo buff_ci = {};
8439 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8440 // This usage is not valid for any descriptor type
8441 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8442 buff_ci.size = 256;
8443 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8444 VkBuffer buffer;
8445 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8446 ASSERT_VK_SUCCESS(err);
8447
8448 VkBufferViewCreateInfo buff_view_ci = {};
8449 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8450 buff_view_ci.buffer = buffer;
8451 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8452 buff_view_ci.range = VK_WHOLE_SIZE;
8453 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008454 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008455 ASSERT_VK_SUCCESS(err);
8456
8457 // Create an image to be used for invalid updates
8458 VkImageCreateInfo image_ci = {};
8459 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8460 image_ci.imageType = VK_IMAGE_TYPE_2D;
8461 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8462 image_ci.extent.width = 64;
8463 image_ci.extent.height = 64;
8464 image_ci.extent.depth = 1;
8465 image_ci.mipLevels = 1;
8466 image_ci.arrayLayers = 1;
8467 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8468 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8469 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8470 // This usage is not valid for any descriptor type
8471 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8472 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8473 VkImage image;
8474 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8475 ASSERT_VK_SUCCESS(err);
8476 // Bind memory to image
8477 VkMemoryRequirements mem_reqs;
8478 VkDeviceMemory image_mem;
8479 bool pass;
8480 VkMemoryAllocateInfo mem_alloc = {};
8481 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8482 mem_alloc.pNext = NULL;
8483 mem_alloc.allocationSize = 0;
8484 mem_alloc.memoryTypeIndex = 0;
8485 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8486 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008487 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008488 ASSERT_TRUE(pass);
8489 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8490 ASSERT_VK_SUCCESS(err);
8491 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8492 ASSERT_VK_SUCCESS(err);
8493 // Now create view for image
8494 VkImageViewCreateInfo image_view_ci = {};
8495 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8496 image_view_ci.image = image;
8497 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8498 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8499 image_view_ci.subresourceRange.layerCount = 1;
8500 image_view_ci.subresourceRange.baseArrayLayer = 0;
8501 image_view_ci.subresourceRange.levelCount = 1;
8502 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8503 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008504 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008505 ASSERT_VK_SUCCESS(err);
8506
8507 VkDescriptorBufferInfo buff_info = {};
8508 buff_info.buffer = buffer;
8509 VkDescriptorImageInfo img_info = {};
8510 img_info.imageView = image_view;
8511 VkWriteDescriptorSet descriptor_write = {};
8512 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8513 descriptor_write.dstBinding = 0;
8514 descriptor_write.descriptorCount = 1;
8515 descriptor_write.pTexelBufferView = &buff_view;
8516 descriptor_write.pBufferInfo = &buff_info;
8517 descriptor_write.pImageInfo = &img_info;
8518
8519 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008520 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8521 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8522 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8523 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8524 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8525 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8526 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8527 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8528 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8529 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8530 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008531 // Start loop at 1 as SAMPLER desc type has no usage bit error
8532 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8533 descriptor_write.descriptorType = VkDescriptorType(i);
8534 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008536
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008537 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008538
8539 m_errorMonitor->VerifyFound();
8540 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8541 }
8542 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8543 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008544 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008545 vkDestroyImageView(m_device->device(), image_view, NULL);
8546 vkDestroyBuffer(m_device->device(), buffer, NULL);
8547 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008548 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008549 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8550}
8551
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008552TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008553 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8554 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8555 "1. offset value greater than buffer size\n"
8556 "2. range value of 0\n"
8557 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008558 VkResult err;
8559
8560 ASSERT_NO_FATAL_FAILURE(InitState());
8561 VkDescriptorPoolSize ds_type_count = {};
8562 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8563 ds_type_count.descriptorCount = 1;
8564
8565 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8566 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8567 ds_pool_ci.pNext = NULL;
8568 ds_pool_ci.maxSets = 1;
8569 ds_pool_ci.poolSizeCount = 1;
8570 ds_pool_ci.pPoolSizes = &ds_type_count;
8571
8572 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008573 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008574 ASSERT_VK_SUCCESS(err);
8575
8576 // Create layout with single uniform buffer descriptor
8577 VkDescriptorSetLayoutBinding dsl_binding = {};
8578 dsl_binding.binding = 0;
8579 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8580 dsl_binding.descriptorCount = 1;
8581 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8582 dsl_binding.pImmutableSamplers = NULL;
8583
8584 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8585 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8586 ds_layout_ci.pNext = NULL;
8587 ds_layout_ci.bindingCount = 1;
8588 ds_layout_ci.pBindings = &dsl_binding;
8589 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008590 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008591 ASSERT_VK_SUCCESS(err);
8592
8593 VkDescriptorSet descriptor_set = {};
8594 VkDescriptorSetAllocateInfo alloc_info = {};
8595 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8596 alloc_info.descriptorSetCount = 1;
8597 alloc_info.descriptorPool = ds_pool;
8598 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008599 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008600 ASSERT_VK_SUCCESS(err);
8601
8602 // Create a buffer to be used for invalid updates
8603 VkBufferCreateInfo buff_ci = {};
8604 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8605 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8606 buff_ci.size = 256;
8607 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8608 VkBuffer buffer;
8609 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8610 ASSERT_VK_SUCCESS(err);
8611 // Have to bind memory to buffer before descriptor update
8612 VkMemoryAllocateInfo mem_alloc = {};
8613 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8614 mem_alloc.pNext = NULL;
8615 mem_alloc.allocationSize = 256;
8616 mem_alloc.memoryTypeIndex = 0;
8617
8618 VkMemoryRequirements mem_reqs;
8619 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008620 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008621 if (!pass) {
8622 vkDestroyBuffer(m_device->device(), buffer, NULL);
8623 return;
8624 }
8625
8626 VkDeviceMemory mem;
8627 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8628 ASSERT_VK_SUCCESS(err);
8629 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8630 ASSERT_VK_SUCCESS(err);
8631
8632 VkDescriptorBufferInfo buff_info = {};
8633 buff_info.buffer = buffer;
8634 // First make offset 1 larger than buffer size
8635 buff_info.offset = 257;
8636 buff_info.range = VK_WHOLE_SIZE;
8637 VkWriteDescriptorSet descriptor_write = {};
8638 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8639 descriptor_write.dstBinding = 0;
8640 descriptor_write.descriptorCount = 1;
8641 descriptor_write.pTexelBufferView = nullptr;
8642 descriptor_write.pBufferInfo = &buff_info;
8643 descriptor_write.pImageInfo = nullptr;
8644
8645 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8646 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008648
8649 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8650
8651 m_errorMonitor->VerifyFound();
8652 // Now cause error due to range of 0
8653 buff_info.offset = 0;
8654 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8656 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008657
8658 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8659
8660 m_errorMonitor->VerifyFound();
8661 // Now cause error due to range exceeding buffer size - offset
8662 buff_info.offset = 128;
8663 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " range is 200 which is greater than buffer size ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008665
8666 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8667
8668 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008669 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008670 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8671 vkDestroyBuffer(m_device->device(), buffer, NULL);
8672 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8673 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8674}
8675
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008676TEST_F(VkLayerTest, DSAspectBitsErrors) {
8677 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8678 // are set, but could expand this test to hit more cases.
8679 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8680 "that do not have correct aspect bits sets.");
8681 VkResult err;
8682
8683 ASSERT_NO_FATAL_FAILURE(InitState());
8684 VkDescriptorPoolSize ds_type_count = {};
8685 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8686 ds_type_count.descriptorCount = 1;
8687
8688 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8689 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8690 ds_pool_ci.pNext = NULL;
8691 ds_pool_ci.maxSets = 5;
8692 ds_pool_ci.poolSizeCount = 1;
8693 ds_pool_ci.pPoolSizes = &ds_type_count;
8694
8695 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008696 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008697 ASSERT_VK_SUCCESS(err);
8698
8699 VkDescriptorSetLayoutBinding dsl_binding = {};
8700 dsl_binding.binding = 0;
8701 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8702 dsl_binding.descriptorCount = 1;
8703 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8704 dsl_binding.pImmutableSamplers = NULL;
8705
8706 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8707 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8708 ds_layout_ci.pNext = NULL;
8709 ds_layout_ci.bindingCount = 1;
8710 ds_layout_ci.pBindings = &dsl_binding;
8711 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008712 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008713 ASSERT_VK_SUCCESS(err);
8714
8715 VkDescriptorSet descriptor_set = {};
8716 VkDescriptorSetAllocateInfo alloc_info = {};
8717 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8718 alloc_info.descriptorSetCount = 1;
8719 alloc_info.descriptorPool = ds_pool;
8720 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008721 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008722 ASSERT_VK_SUCCESS(err);
8723
8724 // Create an image to be used for invalid updates
8725 VkImageCreateInfo image_ci = {};
8726 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8727 image_ci.imageType = VK_IMAGE_TYPE_2D;
8728 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8729 image_ci.extent.width = 64;
8730 image_ci.extent.height = 64;
8731 image_ci.extent.depth = 1;
8732 image_ci.mipLevels = 1;
8733 image_ci.arrayLayers = 1;
8734 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8735 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8736 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8737 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8738 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8739 VkImage image;
8740 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8741 ASSERT_VK_SUCCESS(err);
8742 // Bind memory to image
8743 VkMemoryRequirements mem_reqs;
8744 VkDeviceMemory image_mem;
8745 bool pass;
8746 VkMemoryAllocateInfo mem_alloc = {};
8747 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8748 mem_alloc.pNext = NULL;
8749 mem_alloc.allocationSize = 0;
8750 mem_alloc.memoryTypeIndex = 0;
8751 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8752 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008753 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008754 ASSERT_TRUE(pass);
8755 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8756 ASSERT_VK_SUCCESS(err);
8757 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8758 ASSERT_VK_SUCCESS(err);
8759 // Now create view for image
8760 VkImageViewCreateInfo image_view_ci = {};
8761 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8762 image_view_ci.image = image;
8763 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8764 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8765 image_view_ci.subresourceRange.layerCount = 1;
8766 image_view_ci.subresourceRange.baseArrayLayer = 0;
8767 image_view_ci.subresourceRange.levelCount = 1;
8768 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008769 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008770
8771 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008772 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008773 ASSERT_VK_SUCCESS(err);
8774
8775 VkDescriptorImageInfo img_info = {};
8776 img_info.imageView = image_view;
8777 VkWriteDescriptorSet descriptor_write = {};
8778 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8779 descriptor_write.dstBinding = 0;
8780 descriptor_write.descriptorCount = 1;
8781 descriptor_write.pTexelBufferView = NULL;
8782 descriptor_write.pBufferInfo = NULL;
8783 descriptor_write.pImageInfo = &img_info;
8784 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8785 descriptor_write.dstSet = descriptor_set;
8786 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8787 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008789
8790 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8791
8792 m_errorMonitor->VerifyFound();
8793 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8794 vkDestroyImage(m_device->device(), image, NULL);
8795 vkFreeMemory(m_device->device(), image_mem, NULL);
8796 vkDestroyImageView(m_device->device(), image_view, NULL);
8797 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8798 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8799}
8800
Karl Schultz6addd812016-02-02 17:17:23 -07008801TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008802 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008803 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008804
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8806 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8807 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008808
Tobin Ehlis3b780662015-05-28 12:11:26 -06008809 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008810 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008811 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008812 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8813 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008814
8815 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008816 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8817 ds_pool_ci.pNext = NULL;
8818 ds_pool_ci.maxSets = 1;
8819 ds_pool_ci.poolSizeCount = 1;
8820 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008821
Tobin Ehlis3b780662015-05-28 12:11:26 -06008822 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008823 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008824 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008825 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008826 dsl_binding.binding = 0;
8827 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8828 dsl_binding.descriptorCount = 1;
8829 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8830 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008831
Tony Barboureb254902015-07-15 12:50:33 -06008832 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008833 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8834 ds_layout_ci.pNext = NULL;
8835 ds_layout_ci.bindingCount = 1;
8836 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008837
Tobin Ehlis3b780662015-05-28 12:11:26 -06008838 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008839 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008840 ASSERT_VK_SUCCESS(err);
8841
8842 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008843 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008844 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008845 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008846 alloc_info.descriptorPool = ds_pool;
8847 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008848 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008849 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008850
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008851 VkSamplerCreateInfo sampler_ci = {};
8852 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8853 sampler_ci.pNext = NULL;
8854 sampler_ci.magFilter = VK_FILTER_NEAREST;
8855 sampler_ci.minFilter = VK_FILTER_NEAREST;
8856 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8857 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8858 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8859 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8860 sampler_ci.mipLodBias = 1.0;
8861 sampler_ci.anisotropyEnable = VK_FALSE;
8862 sampler_ci.maxAnisotropy = 1;
8863 sampler_ci.compareEnable = VK_FALSE;
8864 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8865 sampler_ci.minLod = 1.0;
8866 sampler_ci.maxLod = 1.0;
8867 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8868 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8869 VkSampler sampler;
8870 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8871 ASSERT_VK_SUCCESS(err);
8872
8873 VkDescriptorImageInfo info = {};
8874 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008875
8876 VkWriteDescriptorSet descriptor_write;
8877 memset(&descriptor_write, 0, sizeof(descriptor_write));
8878 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008879 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008880 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008881 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008882 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008883 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008884
8885 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8886
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008887 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008888
Chia-I Wuf7458c52015-10-26 21:10:41 +08008889 vkDestroySampler(m_device->device(), sampler, NULL);
8890 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8891 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008892}
8893
Karl Schultz6addd812016-02-02 17:17:23 -07008894TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008895 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008896 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008897
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8899 " binding #0 with 1 total descriptors but update of 1 descriptors "
8900 "starting at binding offset of 0 combined with update array element "
8901 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008902
Tobin Ehlis3b780662015-05-28 12:11:26 -06008903 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008904 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008905 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008906 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8907 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008908
8909 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008910 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8911 ds_pool_ci.pNext = NULL;
8912 ds_pool_ci.maxSets = 1;
8913 ds_pool_ci.poolSizeCount = 1;
8914 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008915
Tobin Ehlis3b780662015-05-28 12:11:26 -06008916 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008917 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008918 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008919
Tony Barboureb254902015-07-15 12:50:33 -06008920 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008921 dsl_binding.binding = 0;
8922 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8923 dsl_binding.descriptorCount = 1;
8924 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8925 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008926
8927 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008928 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8929 ds_layout_ci.pNext = NULL;
8930 ds_layout_ci.bindingCount = 1;
8931 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008932
Tobin Ehlis3b780662015-05-28 12:11:26 -06008933 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008934 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008935 ASSERT_VK_SUCCESS(err);
8936
8937 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008938 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008939 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008940 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008941 alloc_info.descriptorPool = ds_pool;
8942 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008943 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008944 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008945
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008946 // Correctly update descriptor to avoid "NOT_UPDATED" error
8947 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008948 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008949 buff_info.offset = 0;
8950 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008951
8952 VkWriteDescriptorSet descriptor_write;
8953 memset(&descriptor_write, 0, sizeof(descriptor_write));
8954 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008955 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008956 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008957 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008958 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8959 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008960
8961 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8962
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008963 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008964
Chia-I Wuf7458c52015-10-26 21:10:41 +08008965 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8966 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008967}
8968
Karl Schultz6addd812016-02-02 17:17:23 -07008969TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07008970 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07008971 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008972
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07008973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008974
Tobin Ehlis3b780662015-05-28 12:11:26 -06008975 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008976 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008977 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008978 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8979 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008980
8981 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008982 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8983 ds_pool_ci.pNext = NULL;
8984 ds_pool_ci.maxSets = 1;
8985 ds_pool_ci.poolSizeCount = 1;
8986 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008987
Tobin Ehlis3b780662015-05-28 12:11:26 -06008988 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008989 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008990 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008991
Tony Barboureb254902015-07-15 12:50:33 -06008992 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008993 dsl_binding.binding = 0;
8994 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8995 dsl_binding.descriptorCount = 1;
8996 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8997 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008998
8999 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009000 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9001 ds_layout_ci.pNext = NULL;
9002 ds_layout_ci.bindingCount = 1;
9003 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009004 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009005 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009006 ASSERT_VK_SUCCESS(err);
9007
9008 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009009 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009010 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009011 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009012 alloc_info.descriptorPool = ds_pool;
9013 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009014 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009015 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009016
Tony Barboureb254902015-07-15 12:50:33 -06009017 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009018 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9019 sampler_ci.pNext = NULL;
9020 sampler_ci.magFilter = VK_FILTER_NEAREST;
9021 sampler_ci.minFilter = VK_FILTER_NEAREST;
9022 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9023 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9024 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9025 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9026 sampler_ci.mipLodBias = 1.0;
9027 sampler_ci.anisotropyEnable = VK_FALSE;
9028 sampler_ci.maxAnisotropy = 1;
9029 sampler_ci.compareEnable = VK_FALSE;
9030 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9031 sampler_ci.minLod = 1.0;
9032 sampler_ci.maxLod = 1.0;
9033 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9034 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009035
Tobin Ehlis3b780662015-05-28 12:11:26 -06009036 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009037 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009038 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009039
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009040 VkDescriptorImageInfo info = {};
9041 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009042
9043 VkWriteDescriptorSet descriptor_write;
9044 memset(&descriptor_write, 0, sizeof(descriptor_write));
9045 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009046 descriptor_write.dstSet = descriptorSet;
9047 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009048 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009049 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009050 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009051 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009052
9053 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9054
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009055 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009056
Chia-I Wuf7458c52015-10-26 21:10:41 +08009057 vkDestroySampler(m_device->device(), sampler, NULL);
9058 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9059 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009060}
9061
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009062TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9063 // Create layout w/ empty binding and attempt to update it
9064 VkResult err;
9065
9066 ASSERT_NO_FATAL_FAILURE(InitState());
9067
9068 VkDescriptorPoolSize ds_type_count = {};
9069 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9070 ds_type_count.descriptorCount = 1;
9071
9072 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9073 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9074 ds_pool_ci.pNext = NULL;
9075 ds_pool_ci.maxSets = 1;
9076 ds_pool_ci.poolSizeCount = 1;
9077 ds_pool_ci.pPoolSizes = &ds_type_count;
9078
9079 VkDescriptorPool ds_pool;
9080 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9081 ASSERT_VK_SUCCESS(err);
9082
9083 VkDescriptorSetLayoutBinding dsl_binding = {};
9084 dsl_binding.binding = 0;
9085 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9086 dsl_binding.descriptorCount = 0;
9087 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9088 dsl_binding.pImmutableSamplers = NULL;
9089
9090 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9091 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9092 ds_layout_ci.pNext = NULL;
9093 ds_layout_ci.bindingCount = 1;
9094 ds_layout_ci.pBindings = &dsl_binding;
9095 VkDescriptorSetLayout ds_layout;
9096 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9097 ASSERT_VK_SUCCESS(err);
9098
9099 VkDescriptorSet descriptor_set;
9100 VkDescriptorSetAllocateInfo alloc_info = {};
9101 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9102 alloc_info.descriptorSetCount = 1;
9103 alloc_info.descriptorPool = ds_pool;
9104 alloc_info.pSetLayouts = &ds_layout;
9105 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9106 ASSERT_VK_SUCCESS(err);
9107
9108 VkSamplerCreateInfo sampler_ci = {};
9109 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9110 sampler_ci.magFilter = VK_FILTER_NEAREST;
9111 sampler_ci.minFilter = VK_FILTER_NEAREST;
9112 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9113 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9114 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9115 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9116 sampler_ci.mipLodBias = 1.0;
9117 sampler_ci.maxAnisotropy = 1;
9118 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9119 sampler_ci.minLod = 1.0;
9120 sampler_ci.maxLod = 1.0;
9121 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9122
9123 VkSampler sampler;
9124 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9125 ASSERT_VK_SUCCESS(err);
9126
9127 VkDescriptorImageInfo info = {};
9128 info.sampler = sampler;
9129
9130 VkWriteDescriptorSet descriptor_write;
9131 memset(&descriptor_write, 0, sizeof(descriptor_write));
9132 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9133 descriptor_write.dstSet = descriptor_set;
9134 descriptor_write.dstBinding = 0;
9135 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9136 // This is the wrong type, but empty binding error will be flagged first
9137 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9138 descriptor_write.pImageInfo = &info;
9139
9140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9141 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9142 m_errorMonitor->VerifyFound();
9143
9144 vkDestroySampler(m_device->device(), sampler, NULL);
9145 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9146 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9147}
9148
Karl Schultz6addd812016-02-02 17:17:23 -07009149TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9150 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9151 // types
9152 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009153
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009155
Tobin Ehlis3b780662015-05-28 12:11:26 -06009156 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009157
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009158 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009159 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9160 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009161
9162 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009163 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9164 ds_pool_ci.pNext = NULL;
9165 ds_pool_ci.maxSets = 1;
9166 ds_pool_ci.poolSizeCount = 1;
9167 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009168
Tobin Ehlis3b780662015-05-28 12:11:26 -06009169 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009170 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009171 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009172 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009173 dsl_binding.binding = 0;
9174 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9175 dsl_binding.descriptorCount = 1;
9176 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9177 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009178
Tony Barboureb254902015-07-15 12:50:33 -06009179 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009180 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9181 ds_layout_ci.pNext = NULL;
9182 ds_layout_ci.bindingCount = 1;
9183 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009184
Tobin Ehlis3b780662015-05-28 12:11:26 -06009185 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009186 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009187 ASSERT_VK_SUCCESS(err);
9188
9189 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009190 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009191 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009192 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009193 alloc_info.descriptorPool = ds_pool;
9194 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009195 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009196 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009197
Tony Barboureb254902015-07-15 12:50:33 -06009198 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009199 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9200 sampler_ci.pNext = NULL;
9201 sampler_ci.magFilter = VK_FILTER_NEAREST;
9202 sampler_ci.minFilter = VK_FILTER_NEAREST;
9203 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9204 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9205 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9206 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9207 sampler_ci.mipLodBias = 1.0;
9208 sampler_ci.anisotropyEnable = VK_FALSE;
9209 sampler_ci.maxAnisotropy = 1;
9210 sampler_ci.compareEnable = VK_FALSE;
9211 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9212 sampler_ci.minLod = 1.0;
9213 sampler_ci.maxLod = 1.0;
9214 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9215 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009216 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009217 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009218 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009219
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009220 VkDescriptorImageInfo info = {};
9221 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009222
9223 VkWriteDescriptorSet descriptor_write;
9224 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009225 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009226 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009227 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009228 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009229 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009230 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009231
9232 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9233
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009234 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009235
Chia-I Wuf7458c52015-10-26 21:10:41 +08009236 vkDestroySampler(m_device->device(), sampler, NULL);
9237 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9238 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009239}
9240
Karl Schultz6addd812016-02-02 17:17:23 -07009241TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009242 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009243 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009244
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9246 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009247
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009248 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009249 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9250 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009251 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009252 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9253 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009254
9255 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009256 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9257 ds_pool_ci.pNext = NULL;
9258 ds_pool_ci.maxSets = 1;
9259 ds_pool_ci.poolSizeCount = 1;
9260 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009261
9262 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009263 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009264 ASSERT_VK_SUCCESS(err);
9265
9266 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009267 dsl_binding.binding = 0;
9268 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9269 dsl_binding.descriptorCount = 1;
9270 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9271 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009272
9273 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009274 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9275 ds_layout_ci.pNext = NULL;
9276 ds_layout_ci.bindingCount = 1;
9277 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009278 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009279 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009280 ASSERT_VK_SUCCESS(err);
9281
9282 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009283 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009284 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009285 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009286 alloc_info.descriptorPool = ds_pool;
9287 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009288 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009289 ASSERT_VK_SUCCESS(err);
9290
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009291 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009292
9293 VkDescriptorImageInfo descriptor_info;
9294 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9295 descriptor_info.sampler = sampler;
9296
9297 VkWriteDescriptorSet descriptor_write;
9298 memset(&descriptor_write, 0, sizeof(descriptor_write));
9299 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009300 descriptor_write.dstSet = descriptorSet;
9301 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009302 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009303 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9304 descriptor_write.pImageInfo = &descriptor_info;
9305
9306 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9307
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009308 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009309
Chia-I Wuf7458c52015-10-26 21:10:41 +08009310 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9311 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009312}
9313
Karl Schultz6addd812016-02-02 17:17:23 -07009314TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9315 // Create a single combined Image/Sampler descriptor and send it an invalid
9316 // imageView
9317 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009318
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9320 "image sampler descriptor failed due "
9321 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009322
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009323 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009324 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009325 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9326 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009327
9328 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009329 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9330 ds_pool_ci.pNext = NULL;
9331 ds_pool_ci.maxSets = 1;
9332 ds_pool_ci.poolSizeCount = 1;
9333 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009334
9335 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009336 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009337 ASSERT_VK_SUCCESS(err);
9338
9339 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009340 dsl_binding.binding = 0;
9341 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9342 dsl_binding.descriptorCount = 1;
9343 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9344 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009345
9346 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009347 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9348 ds_layout_ci.pNext = NULL;
9349 ds_layout_ci.bindingCount = 1;
9350 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009351 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009352 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009353 ASSERT_VK_SUCCESS(err);
9354
9355 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009356 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009357 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009358 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009359 alloc_info.descriptorPool = ds_pool;
9360 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009361 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009362 ASSERT_VK_SUCCESS(err);
9363
9364 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009365 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9366 sampler_ci.pNext = NULL;
9367 sampler_ci.magFilter = VK_FILTER_NEAREST;
9368 sampler_ci.minFilter = VK_FILTER_NEAREST;
9369 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9370 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9371 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9372 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9373 sampler_ci.mipLodBias = 1.0;
9374 sampler_ci.anisotropyEnable = VK_FALSE;
9375 sampler_ci.maxAnisotropy = 1;
9376 sampler_ci.compareEnable = VK_FALSE;
9377 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9378 sampler_ci.minLod = 1.0;
9379 sampler_ci.maxLod = 1.0;
9380 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9381 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009382
9383 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009384 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009385 ASSERT_VK_SUCCESS(err);
9386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009387 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009388
9389 VkDescriptorImageInfo descriptor_info;
9390 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9391 descriptor_info.sampler = sampler;
9392 descriptor_info.imageView = view;
9393
9394 VkWriteDescriptorSet descriptor_write;
9395 memset(&descriptor_write, 0, sizeof(descriptor_write));
9396 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009397 descriptor_write.dstSet = descriptorSet;
9398 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009399 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009400 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9401 descriptor_write.pImageInfo = &descriptor_info;
9402
9403 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9404
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009405 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009406
Chia-I Wuf7458c52015-10-26 21:10:41 +08009407 vkDestroySampler(m_device->device(), sampler, NULL);
9408 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9409 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009410}
9411
Karl Schultz6addd812016-02-02 17:17:23 -07009412TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9413 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9414 // into the other
9415 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009416
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9418 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9419 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009420
Tobin Ehlis04356f92015-10-27 16:35:27 -06009421 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009422 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009423 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009424 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9425 ds_type_count[0].descriptorCount = 1;
9426 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9427 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009428
9429 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009430 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9431 ds_pool_ci.pNext = NULL;
9432 ds_pool_ci.maxSets = 1;
9433 ds_pool_ci.poolSizeCount = 2;
9434 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009435
9436 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009437 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009438 ASSERT_VK_SUCCESS(err);
9439 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009440 dsl_binding[0].binding = 0;
9441 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9442 dsl_binding[0].descriptorCount = 1;
9443 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9444 dsl_binding[0].pImmutableSamplers = NULL;
9445 dsl_binding[1].binding = 1;
9446 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9447 dsl_binding[1].descriptorCount = 1;
9448 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9449 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009450
9451 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009452 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9453 ds_layout_ci.pNext = NULL;
9454 ds_layout_ci.bindingCount = 2;
9455 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009456
9457 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009458 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009459 ASSERT_VK_SUCCESS(err);
9460
9461 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009462 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009463 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009464 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009465 alloc_info.descriptorPool = ds_pool;
9466 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009468 ASSERT_VK_SUCCESS(err);
9469
9470 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009471 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9472 sampler_ci.pNext = NULL;
9473 sampler_ci.magFilter = VK_FILTER_NEAREST;
9474 sampler_ci.minFilter = VK_FILTER_NEAREST;
9475 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9476 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9477 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9478 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9479 sampler_ci.mipLodBias = 1.0;
9480 sampler_ci.anisotropyEnable = VK_FALSE;
9481 sampler_ci.maxAnisotropy = 1;
9482 sampler_ci.compareEnable = VK_FALSE;
9483 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9484 sampler_ci.minLod = 1.0;
9485 sampler_ci.maxLod = 1.0;
9486 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9487 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009488
9489 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009490 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009491 ASSERT_VK_SUCCESS(err);
9492
9493 VkDescriptorImageInfo info = {};
9494 info.sampler = sampler;
9495
9496 VkWriteDescriptorSet descriptor_write;
9497 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9498 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009499 descriptor_write.dstSet = descriptorSet;
9500 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009501 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009502 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9503 descriptor_write.pImageInfo = &info;
9504 // This write update should succeed
9505 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9506 // Now perform a copy update that fails due to type mismatch
9507 VkCopyDescriptorSet copy_ds_update;
9508 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9509 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9510 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009511 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009512 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009513 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009514 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009515 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9516
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009517 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009518 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06009520 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9521 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9522 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009523 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009524 copy_ds_update.dstSet = descriptorSet;
9525 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009526 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009527 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9528
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009529 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009530
Tobin Ehlis04356f92015-10-27 16:35:27 -06009531 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9533 "update array offset of 0 and update of "
9534 "5 descriptors oversteps total number "
9535 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009536
Tobin Ehlis04356f92015-10-27 16:35:27 -06009537 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9538 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9539 copy_ds_update.srcSet = descriptorSet;
9540 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009541 copy_ds_update.dstSet = descriptorSet;
9542 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009543 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009544 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9545
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009546 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009547
Chia-I Wuf7458c52015-10-26 21:10:41 +08009548 vkDestroySampler(m_device->device(), sampler, NULL);
9549 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9550 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009551}
9552
Karl Schultz6addd812016-02-02 17:17:23 -07009553TEST_F(VkLayerTest, NumSamplesMismatch) {
9554 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9555 // sampleCount
9556 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009557
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009559
Tobin Ehlis3b780662015-05-28 12:11:26 -06009560 ASSERT_NO_FATAL_FAILURE(InitState());
9561 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009562 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009563 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009564 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009565
9566 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009567 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9568 ds_pool_ci.pNext = NULL;
9569 ds_pool_ci.maxSets = 1;
9570 ds_pool_ci.poolSizeCount = 1;
9571 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009572
Tobin Ehlis3b780662015-05-28 12:11:26 -06009573 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009574 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009575 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009576
Tony Barboureb254902015-07-15 12:50:33 -06009577 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009578 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009579 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009580 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009581 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9582 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009583
Tony Barboureb254902015-07-15 12:50:33 -06009584 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9585 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9586 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009587 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009588 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009589
Tobin Ehlis3b780662015-05-28 12:11:26 -06009590 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009591 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009592 ASSERT_VK_SUCCESS(err);
9593
9594 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009595 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009596 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009597 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009598 alloc_info.descriptorPool = ds_pool;
9599 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009600 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009601 ASSERT_VK_SUCCESS(err);
9602
Tony Barboureb254902015-07-15 12:50:33 -06009603 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009604 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009605 pipe_ms_state_ci.pNext = NULL;
9606 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9607 pipe_ms_state_ci.sampleShadingEnable = 0;
9608 pipe_ms_state_ci.minSampleShading = 1.0;
9609 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009610
Tony Barboureb254902015-07-15 12:50:33 -06009611 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009612 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9613 pipeline_layout_ci.pNext = NULL;
9614 pipeline_layout_ci.setLayoutCount = 1;
9615 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009616
9617 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009618 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009619 ASSERT_VK_SUCCESS(err);
9620
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009621 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9622 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9623 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009624 VkPipelineObj pipe(m_device);
9625 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009626 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009627 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009628 pipe.SetMSAA(&pipe_ms_state_ci);
9629 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009630
Tony Barbourfe3351b2015-07-28 10:17:20 -06009631 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009632 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009633
Mark Young29927482016-05-04 14:38:51 -06009634 // Render triangle (the error should trigger on the attempt to draw).
9635 Draw(3, 1, 0, 0);
9636
9637 // Finalize recording of the command buffer
9638 EndCommandBuffer();
9639
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009640 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009641
Chia-I Wuf7458c52015-10-26 21:10:41 +08009642 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9643 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9644 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009645}
Mark Young29927482016-05-04 14:38:51 -06009646
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009647TEST_F(VkLayerTest, RenderPassIncompatible) {
9648 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9649 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009650 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009651 VkResult err;
9652
9653 ASSERT_NO_FATAL_FAILURE(InitState());
9654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9655
9656 VkDescriptorSetLayoutBinding dsl_binding = {};
9657 dsl_binding.binding = 0;
9658 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9659 dsl_binding.descriptorCount = 1;
9660 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9661 dsl_binding.pImmutableSamplers = NULL;
9662
9663 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9664 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9665 ds_layout_ci.pNext = NULL;
9666 ds_layout_ci.bindingCount = 1;
9667 ds_layout_ci.pBindings = &dsl_binding;
9668
9669 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009670 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009671 ASSERT_VK_SUCCESS(err);
9672
9673 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9674 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9675 pipeline_layout_ci.pNext = NULL;
9676 pipeline_layout_ci.setLayoutCount = 1;
9677 pipeline_layout_ci.pSetLayouts = &ds_layout;
9678
9679 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009680 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009681 ASSERT_VK_SUCCESS(err);
9682
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009683 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9684 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9685 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009686 // Create a renderpass that will be incompatible with default renderpass
9687 VkAttachmentReference attach = {};
9688 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9689 VkAttachmentReference color_att = {};
9690 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9691 VkSubpassDescription subpass = {};
9692 subpass.inputAttachmentCount = 1;
9693 subpass.pInputAttachments = &attach;
9694 subpass.colorAttachmentCount = 1;
9695 subpass.pColorAttachments = &color_att;
9696 VkRenderPassCreateInfo rpci = {};
9697 rpci.subpassCount = 1;
9698 rpci.pSubpasses = &subpass;
9699 rpci.attachmentCount = 1;
9700 VkAttachmentDescription attach_desc = {};
9701 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009702 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9703 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009704 rpci.pAttachments = &attach_desc;
9705 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9706 VkRenderPass rp;
9707 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9708 VkPipelineObj pipe(m_device);
9709 pipe.AddShader(&vs);
9710 pipe.AddShader(&fs);
9711 pipe.AddColorAttachment();
9712 VkViewport view_port = {};
9713 m_viewports.push_back(view_port);
9714 pipe.SetViewport(m_viewports);
9715 VkRect2D rect = {};
9716 m_scissors.push_back(rect);
9717 pipe.SetScissor(m_scissors);
9718 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9719
9720 VkCommandBufferInheritanceInfo cbii = {};
9721 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9722 cbii.renderPass = rp;
9723 cbii.subpass = 0;
9724 VkCommandBufferBeginInfo cbbi = {};
9725 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9726 cbbi.pInheritanceInfo = &cbii;
9727 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9728 VkRenderPassBeginInfo rpbi = {};
9729 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9730 rpbi.framebuffer = m_framebuffer;
9731 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009732 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9733 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009734
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009736 // Render triangle (the error should trigger on the attempt to draw).
9737 Draw(3, 1, 0, 0);
9738
9739 // Finalize recording of the command buffer
9740 EndCommandBuffer();
9741
9742 m_errorMonitor->VerifyFound();
9743
9744 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9745 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9746 vkDestroyRenderPass(m_device->device(), rp, NULL);
9747}
9748
Mark Youngc89c6312016-03-31 16:03:20 -06009749TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9750 // Create Pipeline where the number of blend attachments doesn't match the
9751 // number of color attachments. In this case, we don't add any color
9752 // blend attachments even though we have a color attachment.
9753 VkResult err;
9754
9755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009756 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009757
9758 ASSERT_NO_FATAL_FAILURE(InitState());
9759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9760 VkDescriptorPoolSize ds_type_count = {};
9761 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9762 ds_type_count.descriptorCount = 1;
9763
9764 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9765 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9766 ds_pool_ci.pNext = NULL;
9767 ds_pool_ci.maxSets = 1;
9768 ds_pool_ci.poolSizeCount = 1;
9769 ds_pool_ci.pPoolSizes = &ds_type_count;
9770
9771 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009772 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009773 ASSERT_VK_SUCCESS(err);
9774
9775 VkDescriptorSetLayoutBinding dsl_binding = {};
9776 dsl_binding.binding = 0;
9777 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9778 dsl_binding.descriptorCount = 1;
9779 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9780 dsl_binding.pImmutableSamplers = NULL;
9781
9782 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9783 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9784 ds_layout_ci.pNext = NULL;
9785 ds_layout_ci.bindingCount = 1;
9786 ds_layout_ci.pBindings = &dsl_binding;
9787
9788 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009789 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009790 ASSERT_VK_SUCCESS(err);
9791
9792 VkDescriptorSet descriptorSet;
9793 VkDescriptorSetAllocateInfo alloc_info = {};
9794 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9795 alloc_info.descriptorSetCount = 1;
9796 alloc_info.descriptorPool = ds_pool;
9797 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009798 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009799 ASSERT_VK_SUCCESS(err);
9800
9801 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009802 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009803 pipe_ms_state_ci.pNext = NULL;
9804 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9805 pipe_ms_state_ci.sampleShadingEnable = 0;
9806 pipe_ms_state_ci.minSampleShading = 1.0;
9807 pipe_ms_state_ci.pSampleMask = NULL;
9808
9809 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9810 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9811 pipeline_layout_ci.pNext = NULL;
9812 pipeline_layout_ci.setLayoutCount = 1;
9813 pipeline_layout_ci.pSetLayouts = &ds_layout;
9814
9815 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009816 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009817 ASSERT_VK_SUCCESS(err);
9818
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009819 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9820 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9821 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009822 VkPipelineObj pipe(m_device);
9823 pipe.AddShader(&vs);
9824 pipe.AddShader(&fs);
9825 pipe.SetMSAA(&pipe_ms_state_ci);
9826 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9827
9828 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009829 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009830
Mark Young29927482016-05-04 14:38:51 -06009831 // Render triangle (the error should trigger on the attempt to draw).
9832 Draw(3, 1, 0, 0);
9833
9834 // Finalize recording of the command buffer
9835 EndCommandBuffer();
9836
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009837 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009838
9839 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9840 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9841 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9842}
Mark Young29927482016-05-04 14:38:51 -06009843
Mark Muellerd4914412016-06-13 17:52:06 -06009844TEST_F(VkLayerTest, MissingClearAttachment) {
9845 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9846 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009847 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009849 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009850
9851 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9852 m_errorMonitor->VerifyFound();
9853}
9854
Karl Schultz6addd812016-02-02 17:17:23 -07009855TEST_F(VkLayerTest, ClearCmdNoDraw) {
9856 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9857 // to issuing a Draw
9858 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009859
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009861 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009862
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009863 ASSERT_NO_FATAL_FAILURE(InitState());
9864 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009865
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009866 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009867 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9868 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009869
9870 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009871 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9872 ds_pool_ci.pNext = NULL;
9873 ds_pool_ci.maxSets = 1;
9874 ds_pool_ci.poolSizeCount = 1;
9875 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009876
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009877 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009878 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009879 ASSERT_VK_SUCCESS(err);
9880
Tony Barboureb254902015-07-15 12:50:33 -06009881 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009882 dsl_binding.binding = 0;
9883 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9884 dsl_binding.descriptorCount = 1;
9885 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9886 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009887
Tony Barboureb254902015-07-15 12:50:33 -06009888 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009889 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9890 ds_layout_ci.pNext = NULL;
9891 ds_layout_ci.bindingCount = 1;
9892 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009893
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009894 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009895 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009896 ASSERT_VK_SUCCESS(err);
9897
9898 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009899 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009900 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009901 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009902 alloc_info.descriptorPool = ds_pool;
9903 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009904 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009905 ASSERT_VK_SUCCESS(err);
9906
Tony Barboureb254902015-07-15 12:50:33 -06009907 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009908 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009909 pipe_ms_state_ci.pNext = NULL;
9910 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9911 pipe_ms_state_ci.sampleShadingEnable = 0;
9912 pipe_ms_state_ci.minSampleShading = 1.0;
9913 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009914
Tony Barboureb254902015-07-15 12:50:33 -06009915 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009916 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9917 pipeline_layout_ci.pNext = NULL;
9918 pipeline_layout_ci.setLayoutCount = 1;
9919 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009920
9921 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009922 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009923 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009924
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009925 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009926 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009927 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009928 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009929
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009930 VkPipelineObj pipe(m_device);
9931 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009932 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009933 pipe.SetMSAA(&pipe_ms_state_ci);
9934 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009935
9936 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009937
Karl Schultz6addd812016-02-02 17:17:23 -07009938 // Main thing we care about for this test is that the VkImage obj we're
9939 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009940 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009941 VkClearAttachment color_attachment;
9942 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9943 color_attachment.clearValue.color.float32[0] = 1.0;
9944 color_attachment.clearValue.color.float32[1] = 1.0;
9945 color_attachment.clearValue.color.float32[2] = 1.0;
9946 color_attachment.clearValue.color.float32[3] = 1.0;
9947 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009948 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009949
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009950 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009951
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009952 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009953
Chia-I Wuf7458c52015-10-26 21:10:41 +08009954 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9955 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9956 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009957}
9958
Karl Schultz6addd812016-02-02 17:17:23 -07009959TEST_F(VkLayerTest, VtxBufferBadIndex) {
9960 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009961
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9963 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009964
Tobin Ehlis502480b2015-06-24 15:53:07 -06009965 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009966 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009967 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009968
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009969 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009970 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9971 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009972
9973 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009974 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9975 ds_pool_ci.pNext = NULL;
9976 ds_pool_ci.maxSets = 1;
9977 ds_pool_ci.poolSizeCount = 1;
9978 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009979
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009980 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009981 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009982 ASSERT_VK_SUCCESS(err);
9983
Tony Barboureb254902015-07-15 12:50:33 -06009984 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009985 dsl_binding.binding = 0;
9986 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9987 dsl_binding.descriptorCount = 1;
9988 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9989 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009990
Tony Barboureb254902015-07-15 12:50:33 -06009991 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009992 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9993 ds_layout_ci.pNext = NULL;
9994 ds_layout_ci.bindingCount = 1;
9995 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009996
Tobin Ehlis502480b2015-06-24 15:53:07 -06009997 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009998 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009999 ASSERT_VK_SUCCESS(err);
10000
10001 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010002 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010003 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010004 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010005 alloc_info.descriptorPool = ds_pool;
10006 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010007 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010008 ASSERT_VK_SUCCESS(err);
10009
Tony Barboureb254902015-07-15 12:50:33 -060010010 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010011 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010012 pipe_ms_state_ci.pNext = NULL;
10013 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10014 pipe_ms_state_ci.sampleShadingEnable = 0;
10015 pipe_ms_state_ci.minSampleShading = 1.0;
10016 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010017
Tony Barboureb254902015-07-15 12:50:33 -060010018 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010019 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10020 pipeline_layout_ci.pNext = NULL;
10021 pipeline_layout_ci.setLayoutCount = 1;
10022 pipeline_layout_ci.pSetLayouts = &ds_layout;
10023 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010024
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010025 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010026 ASSERT_VK_SUCCESS(err);
10027
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010028 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10029 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10030 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010031 VkPipelineObj pipe(m_device);
10032 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010033 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010034 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010035 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010036 pipe.SetViewport(m_viewports);
10037 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010038 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010039
10040 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010041 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010042 // Don't care about actual data, just need to get to draw to flag error
10043 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010044 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010045 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010046 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010047
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010048 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010049
Chia-I Wuf7458c52015-10-26 21:10:41 +080010050 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10051 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10052 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010053}
Mark Muellerdfe37552016-07-07 14:47:42 -060010054
Mark Mueller2ee294f2016-08-04 12:59:48 -060010055TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10056 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10057 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010058 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010060 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10061 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010062
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010063 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10064 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010066 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010067
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010069 // The following test fails with recent NVidia drivers.
10070 // By the time core_validation is reached, the NVidia
10071 // driver has sanitized the invalid condition and core_validation
10072 // is not introduced to the failure condition. This is not the case
10073 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010074 // uint32_t count = static_cast<uint32_t>(~0);
10075 // VkPhysicalDevice physical_device;
10076 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10077 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010078
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010080 float queue_priority = 0.0;
10081
10082 VkDeviceQueueCreateInfo queue_create_info = {};
10083 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10084 queue_create_info.queueCount = 1;
10085 queue_create_info.pQueuePriorities = &queue_priority;
10086 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10087
10088 VkPhysicalDeviceFeatures features = m_device->phy().features();
10089 VkDevice testDevice;
10090 VkDeviceCreateInfo device_create_info = {};
10091 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10092 device_create_info.queueCreateInfoCount = 1;
10093 device_create_info.pQueueCreateInfos = &queue_create_info;
10094 device_create_info.pEnabledFeatures = &features;
10095 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10096 m_errorMonitor->VerifyFound();
10097
10098 queue_create_info.queueFamilyIndex = 1;
10099
10100 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10101 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10102 for (unsigned i = 0; i < feature_count; i++) {
10103 if (VK_FALSE == feature_array[i]) {
10104 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010106 device_create_info.pEnabledFeatures = &features;
10107 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10108 m_errorMonitor->VerifyFound();
10109 break;
10110 }
10111 }
10112}
10113
10114TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10115 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10116 "End a command buffer with a query still in progress.");
10117
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010118 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10119 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10120 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010121
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010122 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010123
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010125
10126 ASSERT_NO_FATAL_FAILURE(InitState());
10127
10128 VkEvent event;
10129 VkEventCreateInfo event_create_info{};
10130 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10131 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10132
Mark Mueller2ee294f2016-08-04 12:59:48 -060010133 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010134 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010135
10136 BeginCommandBuffer();
10137
10138 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010139 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 -060010140 ASSERT_TRUE(image.initialized());
10141 VkImageMemoryBarrier img_barrier = {};
10142 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10143 img_barrier.pNext = NULL;
10144 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10145 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10146 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10147 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10148 img_barrier.image = image.handle();
10149 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010150
10151 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10152 // that layer validation catches the case when it is not.
10153 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010154 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10155 img_barrier.subresourceRange.baseArrayLayer = 0;
10156 img_barrier.subresourceRange.baseMipLevel = 0;
10157 img_barrier.subresourceRange.layerCount = 1;
10158 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010159 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10160 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010161 m_errorMonitor->VerifyFound();
10162
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010164
10165 VkQueryPool query_pool;
10166 VkQueryPoolCreateInfo query_pool_create_info = {};
10167 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10168 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10169 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010170 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010171
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010172 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010173 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10174
10175 vkEndCommandBuffer(m_commandBuffer->handle());
10176 m_errorMonitor->VerifyFound();
10177
10178 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10179 vkDestroyEvent(m_device->device(), event, nullptr);
10180}
10181
Mark Muellerdfe37552016-07-07 14:47:42 -060010182TEST_F(VkLayerTest, VertexBufferInvalid) {
10183 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10184 "delete a buffer twice, use an invalid offset for each "
10185 "buffer type, and attempt to bind a null buffer");
10186
10187 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10188 "using deleted buffer ";
10189 const char *double_destroy_message = "Cannot free buffer 0x";
10190 const char *invalid_offset_message = "vkBindBufferMemory(): "
10191 "memoryOffset is 0x";
10192 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10193 "storage memoryOffset "
10194 "is 0x";
10195 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10196 "texel memoryOffset "
10197 "is 0x";
10198 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10199 "uniform memoryOffset "
10200 "is 0x";
10201 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
10202 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -060010203 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010204
10205 ASSERT_NO_FATAL_FAILURE(InitState());
10206 ASSERT_NO_FATAL_FAILURE(InitViewport());
10207 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10208
10209 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010210 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010211 pipe_ms_state_ci.pNext = NULL;
10212 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10213 pipe_ms_state_ci.sampleShadingEnable = 0;
10214 pipe_ms_state_ci.minSampleShading = 1.0;
10215 pipe_ms_state_ci.pSampleMask = nullptr;
10216
10217 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10218 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10219 VkPipelineLayout pipeline_layout;
10220
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010221 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010222 ASSERT_VK_SUCCESS(err);
10223
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010224 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10225 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010226 VkPipelineObj pipe(m_device);
10227 pipe.AddShader(&vs);
10228 pipe.AddShader(&fs);
10229 pipe.AddColorAttachment();
10230 pipe.SetMSAA(&pipe_ms_state_ci);
10231 pipe.SetViewport(m_viewports);
10232 pipe.SetScissor(m_scissors);
10233 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10234
10235 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010236 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010237
10238 {
10239 // Create and bind a vertex buffer in a reduced scope, which will cause
10240 // it to be deleted upon leaving this scope
10241 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010242 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010243 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10244 draw_verticies.AddVertexInputToPipe(pipe);
10245 }
10246
10247 Draw(1, 0, 0, 0);
10248
10249 EndCommandBuffer();
10250
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010252 QueueCommandBuffer(false);
10253 m_errorMonitor->VerifyFound();
10254
10255 {
10256 // Create and bind a vertex buffer in a reduced scope, and delete it
10257 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010258 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010260 buffer_test.TestDoubleDestroy();
10261 }
10262 m_errorMonitor->VerifyFound();
10263
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010264 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010265 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10267 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10268 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010269 m_errorMonitor->VerifyFound();
10270 }
10271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010272 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10273 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010274 // Create and bind a memory buffer with an invalid offset again,
10275 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10277 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10278 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010279 m_errorMonitor->VerifyFound();
10280 }
10281
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010282 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010283 // Create and bind a memory buffer with an invalid offset again, but
10284 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10286 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10287 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010288 m_errorMonitor->VerifyFound();
10289 }
10290
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010291 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010292 // Create and bind a memory buffer with an invalid offset again, but
10293 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10295 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10296 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010297 m_errorMonitor->VerifyFound();
10298 }
10299
10300 {
10301 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10303 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10304 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010305 m_errorMonitor->VerifyFound();
10306 }
10307
10308 {
10309 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10311 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10312 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010313 }
10314 m_errorMonitor->VerifyFound();
10315
10316 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10317}
10318
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010319// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10320TEST_F(VkLayerTest, InvalidImageLayout) {
10321 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010322 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10323 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010324 // 3 in ValidateCmdBufImageLayouts
10325 // * -1 Attempt to submit cmd buf w/ deleted image
10326 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10327 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10329 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010330
10331 ASSERT_NO_FATAL_FAILURE(InitState());
10332 // Create src & dst images to use for copy operations
10333 VkImage src_image;
10334 VkImage dst_image;
10335
10336 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10337 const int32_t tex_width = 32;
10338 const int32_t tex_height = 32;
10339
10340 VkImageCreateInfo image_create_info = {};
10341 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10342 image_create_info.pNext = NULL;
10343 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10344 image_create_info.format = tex_format;
10345 image_create_info.extent.width = tex_width;
10346 image_create_info.extent.height = tex_height;
10347 image_create_info.extent.depth = 1;
10348 image_create_info.mipLevels = 1;
10349 image_create_info.arrayLayers = 4;
10350 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10351 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10352 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10353 image_create_info.flags = 0;
10354
10355 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10356 ASSERT_VK_SUCCESS(err);
10357 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10358 ASSERT_VK_SUCCESS(err);
10359
10360 BeginCommandBuffer();
10361 VkImageCopy copyRegion;
10362 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10363 copyRegion.srcSubresource.mipLevel = 0;
10364 copyRegion.srcSubresource.baseArrayLayer = 0;
10365 copyRegion.srcSubresource.layerCount = 1;
10366 copyRegion.srcOffset.x = 0;
10367 copyRegion.srcOffset.y = 0;
10368 copyRegion.srcOffset.z = 0;
10369 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10370 copyRegion.dstSubresource.mipLevel = 0;
10371 copyRegion.dstSubresource.baseArrayLayer = 0;
10372 copyRegion.dstSubresource.layerCount = 1;
10373 copyRegion.dstOffset.x = 0;
10374 copyRegion.dstOffset.y = 0;
10375 copyRegion.dstOffset.z = 0;
10376 copyRegion.extent.width = 1;
10377 copyRegion.extent.height = 1;
10378 copyRegion.extent.depth = 1;
10379 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10380 m_errorMonitor->VerifyFound();
10381 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10383 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10384 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010385 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10386 m_errorMonitor->VerifyFound();
10387 // Final src error is due to bad layout type
10388 m_errorMonitor->SetDesiredFailureMsg(
10389 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10390 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10391 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10392 m_errorMonitor->VerifyFound();
10393 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10395 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010396 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10397 m_errorMonitor->VerifyFound();
10398 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10400 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10401 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010402 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10403 m_errorMonitor->VerifyFound();
10404 m_errorMonitor->SetDesiredFailureMsg(
10405 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10406 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10407 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10408 m_errorMonitor->VerifyFound();
10409 // Now cause error due to bad image layout transition in PipelineBarrier
10410 VkImageMemoryBarrier image_barrier[1] = {};
10411 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10412 image_barrier[0].image = src_image;
10413 image_barrier[0].subresourceRange.layerCount = 2;
10414 image_barrier[0].subresourceRange.levelCount = 2;
10415 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10417 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10418 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10419 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10420 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010421 m_errorMonitor->VerifyFound();
10422
10423 // Finally some layout errors at RenderPass create time
10424 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10425 VkAttachmentReference attach = {};
10426 // perf warning for GENERAL layout w/ non-DS input attachment
10427 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10428 VkSubpassDescription subpass = {};
10429 subpass.inputAttachmentCount = 1;
10430 subpass.pInputAttachments = &attach;
10431 VkRenderPassCreateInfo rpci = {};
10432 rpci.subpassCount = 1;
10433 rpci.pSubpasses = &subpass;
10434 rpci.attachmentCount = 1;
10435 VkAttachmentDescription attach_desc = {};
10436 attach_desc.format = VK_FORMAT_UNDEFINED;
10437 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010438 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010439 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10441 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010442 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10443 m_errorMonitor->VerifyFound();
10444 // error w/ non-general layout
10445 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10446
10447 m_errorMonitor->SetDesiredFailureMsg(
10448 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10449 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10450 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10451 m_errorMonitor->VerifyFound();
10452 subpass.inputAttachmentCount = 0;
10453 subpass.colorAttachmentCount = 1;
10454 subpass.pColorAttachments = &attach;
10455 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10456 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10458 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010459 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10460 m_errorMonitor->VerifyFound();
10461 // error w/ non-color opt or GENERAL layout for color attachment
10462 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10463 m_errorMonitor->SetDesiredFailureMsg(
10464 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10465 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10466 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10467 m_errorMonitor->VerifyFound();
10468 subpass.colorAttachmentCount = 0;
10469 subpass.pDepthStencilAttachment = &attach;
10470 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10471 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10473 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010474 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10475 m_errorMonitor->VerifyFound();
10476 // error w/ non-ds opt or GENERAL layout for color attachment
10477 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10479 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10480 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010481 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10482 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010483 // For this error we need a valid renderpass so create default one
10484 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10485 attach.attachment = 0;
10486 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10487 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10488 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10489 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10490 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10491 // Can't do a CLEAR load on READ_ONLY initialLayout
10492 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10493 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10494 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10496 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10497 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010498 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10499 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010500
10501 vkDestroyImage(m_device->device(), src_image, NULL);
10502 vkDestroyImage(m_device->device(), dst_image, NULL);
10503}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010504
Tobin Ehlise0936662016-10-11 08:10:51 -060010505TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10506 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10507 VkResult err;
10508
10509 ASSERT_NO_FATAL_FAILURE(InitState());
10510
10511 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10512 VkImageTiling tiling;
10513 VkFormatProperties format_properties;
10514 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10515 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10516 tiling = VK_IMAGE_TILING_LINEAR;
10517 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10518 tiling = VK_IMAGE_TILING_OPTIMAL;
10519 } else {
10520 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10521 "skipped.\n");
10522 return;
10523 }
10524
10525 VkDescriptorPoolSize ds_type = {};
10526 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10527 ds_type.descriptorCount = 1;
10528
10529 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10530 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10531 ds_pool_ci.maxSets = 1;
10532 ds_pool_ci.poolSizeCount = 1;
10533 ds_pool_ci.pPoolSizes = &ds_type;
10534 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10535
10536 VkDescriptorPool ds_pool;
10537 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10538 ASSERT_VK_SUCCESS(err);
10539
10540 VkDescriptorSetLayoutBinding dsl_binding = {};
10541 dsl_binding.binding = 0;
10542 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10543 dsl_binding.descriptorCount = 1;
10544 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10545 dsl_binding.pImmutableSamplers = NULL;
10546
10547 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10548 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10549 ds_layout_ci.pNext = NULL;
10550 ds_layout_ci.bindingCount = 1;
10551 ds_layout_ci.pBindings = &dsl_binding;
10552
10553 VkDescriptorSetLayout ds_layout;
10554 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10555 ASSERT_VK_SUCCESS(err);
10556
10557 VkDescriptorSetAllocateInfo alloc_info = {};
10558 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10559 alloc_info.descriptorSetCount = 1;
10560 alloc_info.descriptorPool = ds_pool;
10561 alloc_info.pSetLayouts = &ds_layout;
10562 VkDescriptorSet descriptor_set;
10563 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10564 ASSERT_VK_SUCCESS(err);
10565
10566 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10567 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10568 pipeline_layout_ci.pNext = NULL;
10569 pipeline_layout_ci.setLayoutCount = 1;
10570 pipeline_layout_ci.pSetLayouts = &ds_layout;
10571 VkPipelineLayout pipeline_layout;
10572 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10573 ASSERT_VK_SUCCESS(err);
10574
10575 VkImageObj image(m_device);
10576 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10577 ASSERT_TRUE(image.initialized());
10578 VkImageView view = image.targetView(tex_format);
10579
10580 VkDescriptorImageInfo image_info = {};
10581 image_info.imageView = view;
10582 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10583
10584 VkWriteDescriptorSet descriptor_write = {};
10585 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10586 descriptor_write.dstSet = descriptor_set;
10587 descriptor_write.dstBinding = 0;
10588 descriptor_write.descriptorCount = 1;
10589 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10590 descriptor_write.pImageInfo = &image_info;
10591
10592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10593 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10594 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10595 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10596 m_errorMonitor->VerifyFound();
10597
10598 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10599 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10600 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10601 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10602}
10603
Mark Mueller93b938f2016-08-18 10:27:40 -060010604TEST_F(VkLayerTest, SimultaneousUse) {
10605 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10606 "in primary and secondary command buffers.");
10607
10608 ASSERT_NO_FATAL_FAILURE(InitState());
10609 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10610
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010611 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010612 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10613 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010614
10615 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010616 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010617 command_buffer_allocate_info.commandPool = m_commandPool;
10618 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10619 command_buffer_allocate_info.commandBufferCount = 1;
10620
10621 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010622 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010623 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10624 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010625 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010626 command_buffer_inheritance_info.renderPass = m_renderPass;
10627 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10628 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010629 command_buffer_begin_info.flags =
10630 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010631 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10632
10633 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010634 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10635 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010636 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010637 vkEndCommandBuffer(secondary_command_buffer);
10638
Mark Mueller93b938f2016-08-18 10:27:40 -060010639 VkSubmitInfo submit_info = {};
10640 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10641 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010642 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010643 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010644
Mark Mueller4042b652016-09-05 22:52:21 -060010645 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010646 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10648 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010649 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010650 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10651 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010652
10653 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010654 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10655
Mark Mueller4042b652016-09-05 22:52:21 -060010656 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010657 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010658 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010659
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10661 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010662 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010663 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10664 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010665}
10666
Mark Mueller917f6bc2016-08-30 10:57:19 -060010667TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10668 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10669 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010670 "Delete objects that are inuse. Call VkQueueSubmit "
10671 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010672
10673 ASSERT_NO_FATAL_FAILURE(InitState());
10674 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10675
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010676 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10677 const char *cannot_delete_event_message = "Cannot delete event 0x";
10678 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10679 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010680
10681 BeginCommandBuffer();
10682
10683 VkEvent event;
10684 VkEventCreateInfo event_create_info = {};
10685 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10686 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010687 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010688
Mark Muellerc8d441e2016-08-23 17:36:00 -060010689 EndCommandBuffer();
10690 vkDestroyEvent(m_device->device(), event, nullptr);
10691
10692 VkSubmitInfo submit_info = {};
10693 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10694 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010695 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010697 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10698 m_errorMonitor->VerifyFound();
10699
10700 m_errorMonitor->SetDesiredFailureMsg(0, "");
10701 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10702
10703 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10704
Mark Mueller917f6bc2016-08-30 10:57:19 -060010705 VkSemaphoreCreateInfo semaphore_create_info = {};
10706 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10707 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010708 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010709 VkFenceCreateInfo fence_create_info = {};
10710 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10711 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010712 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010713
10714 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010715 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010716 descriptor_pool_type_count.descriptorCount = 1;
10717
10718 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10719 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10720 descriptor_pool_create_info.maxSets = 1;
10721 descriptor_pool_create_info.poolSizeCount = 1;
10722 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010723 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010724
10725 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010726 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010727
10728 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010729 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010730 descriptorset_layout_binding.descriptorCount = 1;
10731 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10732
10733 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010734 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010735 descriptorset_layout_create_info.bindingCount = 1;
10736 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10737
10738 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010739 ASSERT_VK_SUCCESS(
10740 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010741
10742 VkDescriptorSet descriptorset;
10743 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010744 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010745 descriptorset_allocate_info.descriptorSetCount = 1;
10746 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10747 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010748 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010749
Mark Mueller4042b652016-09-05 22:52:21 -060010750 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10751
10752 VkDescriptorBufferInfo buffer_info = {};
10753 buffer_info.buffer = buffer_test.GetBuffer();
10754 buffer_info.offset = 0;
10755 buffer_info.range = 1024;
10756
10757 VkWriteDescriptorSet write_descriptor_set = {};
10758 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10759 write_descriptor_set.dstSet = descriptorset;
10760 write_descriptor_set.descriptorCount = 1;
10761 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10762 write_descriptor_set.pBufferInfo = &buffer_info;
10763
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010764 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010765
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010766 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10767 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010768
10769 VkPipelineObj pipe(m_device);
10770 pipe.AddColorAttachment();
10771 pipe.AddShader(&vs);
10772 pipe.AddShader(&fs);
10773
10774 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010775 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010776 pipeline_layout_create_info.setLayoutCount = 1;
10777 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10778
10779 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010780 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010781
10782 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10783
Mark Muellerc8d441e2016-08-23 17:36:00 -060010784 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010785 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010786
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010787 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10788 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10789 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010790
Mark Muellerc8d441e2016-08-23 17:36:00 -060010791 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010792
Mark Mueller917f6bc2016-08-30 10:57:19 -060010793 submit_info.signalSemaphoreCount = 1;
10794 submit_info.pSignalSemaphores = &semaphore;
10795 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010796
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010798 vkDestroyEvent(m_device->device(), event, nullptr);
10799 m_errorMonitor->VerifyFound();
10800
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010802 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10803 m_errorMonitor->VerifyFound();
10804
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010806 vkDestroyFence(m_device->device(), fence, nullptr);
10807 m_errorMonitor->VerifyFound();
10808
Tobin Ehlis122207b2016-09-01 08:50:06 -070010809 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010810 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10811 vkDestroyFence(m_device->device(), fence, nullptr);
10812 vkDestroyEvent(m_device->device(), event, nullptr);
10813 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010814 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010815 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10816}
10817
Tobin Ehlis2adda372016-09-01 08:51:06 -070010818TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10819 TEST_DESCRIPTION("Delete in-use query pool.");
10820
10821 ASSERT_NO_FATAL_FAILURE(InitState());
10822 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10823
10824 VkQueryPool query_pool;
10825 VkQueryPoolCreateInfo query_pool_ci{};
10826 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10827 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10828 query_pool_ci.queryCount = 1;
10829 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10830 BeginCommandBuffer();
10831 // Reset query pool to create binding with cmd buffer
10832 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10833
10834 EndCommandBuffer();
10835
10836 VkSubmitInfo submit_info = {};
10837 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10838 submit_info.commandBufferCount = 1;
10839 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10840 // Submit cmd buffer and then destroy query pool while in-flight
10841 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10842
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010844 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10845 m_errorMonitor->VerifyFound();
10846
10847 vkQueueWaitIdle(m_device->m_queue);
10848 // Now that cmd buffer done we can safely destroy query_pool
10849 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10850}
10851
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010852TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10853 TEST_DESCRIPTION("Delete in-use pipeline.");
10854
10855 ASSERT_NO_FATAL_FAILURE(InitState());
10856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10857
10858 // Empty pipeline layout used for binding PSO
10859 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10860 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10861 pipeline_layout_ci.setLayoutCount = 0;
10862 pipeline_layout_ci.pSetLayouts = NULL;
10863
10864 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010865 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010866 ASSERT_VK_SUCCESS(err);
10867
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010869 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010870 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10871 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010872 // Store pipeline handle so we can actually delete it before test finishes
10873 VkPipeline delete_this_pipeline;
10874 { // Scope pipeline so it will be auto-deleted
10875 VkPipelineObj pipe(m_device);
10876 pipe.AddShader(&vs);
10877 pipe.AddShader(&fs);
10878 pipe.AddColorAttachment();
10879 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10880 delete_this_pipeline = pipe.handle();
10881
10882 BeginCommandBuffer();
10883 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010884 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010885
10886 EndCommandBuffer();
10887
10888 VkSubmitInfo submit_info = {};
10889 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10890 submit_info.commandBufferCount = 1;
10891 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10892 // Submit cmd buffer and then pipeline destroyed while in-flight
10893 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10894 } // Pipeline deletion triggered here
10895 m_errorMonitor->VerifyFound();
10896 // Make sure queue finished and then actually delete pipeline
10897 vkQueueWaitIdle(m_device->m_queue);
10898 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10899 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10900}
10901
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010902TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10903 TEST_DESCRIPTION("Delete in-use imageView.");
10904
10905 ASSERT_NO_FATAL_FAILURE(InitState());
10906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10907
10908 VkDescriptorPoolSize ds_type_count;
10909 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10910 ds_type_count.descriptorCount = 1;
10911
10912 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10913 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10914 ds_pool_ci.maxSets = 1;
10915 ds_pool_ci.poolSizeCount = 1;
10916 ds_pool_ci.pPoolSizes = &ds_type_count;
10917
10918 VkDescriptorPool ds_pool;
10919 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10920 ASSERT_VK_SUCCESS(err);
10921
10922 VkSamplerCreateInfo sampler_ci = {};
10923 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10924 sampler_ci.pNext = NULL;
10925 sampler_ci.magFilter = VK_FILTER_NEAREST;
10926 sampler_ci.minFilter = VK_FILTER_NEAREST;
10927 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10928 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10929 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10930 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10931 sampler_ci.mipLodBias = 1.0;
10932 sampler_ci.anisotropyEnable = VK_FALSE;
10933 sampler_ci.maxAnisotropy = 1;
10934 sampler_ci.compareEnable = VK_FALSE;
10935 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10936 sampler_ci.minLod = 1.0;
10937 sampler_ci.maxLod = 1.0;
10938 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10939 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10940 VkSampler sampler;
10941
10942 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10943 ASSERT_VK_SUCCESS(err);
10944
10945 VkDescriptorSetLayoutBinding layout_binding;
10946 layout_binding.binding = 0;
10947 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10948 layout_binding.descriptorCount = 1;
10949 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10950 layout_binding.pImmutableSamplers = NULL;
10951
10952 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10953 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10954 ds_layout_ci.bindingCount = 1;
10955 ds_layout_ci.pBindings = &layout_binding;
10956 VkDescriptorSetLayout ds_layout;
10957 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10958 ASSERT_VK_SUCCESS(err);
10959
10960 VkDescriptorSetAllocateInfo alloc_info = {};
10961 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10962 alloc_info.descriptorSetCount = 1;
10963 alloc_info.descriptorPool = ds_pool;
10964 alloc_info.pSetLayouts = &ds_layout;
10965 VkDescriptorSet descriptor_set;
10966 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10967 ASSERT_VK_SUCCESS(err);
10968
10969 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10970 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10971 pipeline_layout_ci.pNext = NULL;
10972 pipeline_layout_ci.setLayoutCount = 1;
10973 pipeline_layout_ci.pSetLayouts = &ds_layout;
10974
10975 VkPipelineLayout pipeline_layout;
10976 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10977 ASSERT_VK_SUCCESS(err);
10978
10979 VkImageObj image(m_device);
10980 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
10981 ASSERT_TRUE(image.initialized());
10982
10983 VkImageView view;
10984 VkImageViewCreateInfo ivci = {};
10985 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10986 ivci.image = image.handle();
10987 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10988 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
10989 ivci.subresourceRange.layerCount = 1;
10990 ivci.subresourceRange.baseMipLevel = 0;
10991 ivci.subresourceRange.levelCount = 1;
10992 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10993
10994 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
10995 ASSERT_VK_SUCCESS(err);
10996
10997 VkDescriptorImageInfo image_info{};
10998 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10999 image_info.imageView = view;
11000 image_info.sampler = sampler;
11001
11002 VkWriteDescriptorSet descriptor_write = {};
11003 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11004 descriptor_write.dstSet = descriptor_set;
11005 descriptor_write.dstBinding = 0;
11006 descriptor_write.descriptorCount = 1;
11007 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11008 descriptor_write.pImageInfo = &image_info;
11009
11010 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11011
11012 // Create PSO to use the sampler
11013 char const *vsSource = "#version 450\n"
11014 "\n"
11015 "out gl_PerVertex { \n"
11016 " vec4 gl_Position;\n"
11017 "};\n"
11018 "void main(){\n"
11019 " gl_Position = vec4(1);\n"
11020 "}\n";
11021 char const *fsSource = "#version 450\n"
11022 "\n"
11023 "layout(set=0, binding=0) uniform sampler2D s;\n"
11024 "layout(location=0) out vec4 x;\n"
11025 "void main(){\n"
11026 " x = texture(s, vec2(1));\n"
11027 "}\n";
11028 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11029 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11030 VkPipelineObj pipe(m_device);
11031 pipe.AddShader(&vs);
11032 pipe.AddShader(&fs);
11033 pipe.AddColorAttachment();
11034 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11035
11036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
11037
11038 BeginCommandBuffer();
11039 // Bind pipeline to cmd buffer
11040 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11041 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11042 &descriptor_set, 0, nullptr);
11043 Draw(1, 0, 0, 0);
11044 EndCommandBuffer();
11045 // Submit cmd buffer then destroy sampler
11046 VkSubmitInfo submit_info = {};
11047 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11048 submit_info.commandBufferCount = 1;
11049 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11050 // Submit cmd buffer and then destroy imageView while in-flight
11051 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11052
11053 vkDestroyImageView(m_device->device(), view, nullptr);
11054 m_errorMonitor->VerifyFound();
11055 vkQueueWaitIdle(m_device->m_queue);
11056 // Now we can actually destroy imageView
11057 vkDestroyImageView(m_device->device(), view, NULL);
11058 vkDestroySampler(m_device->device(), sampler, nullptr);
11059 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11060 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11061 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11062}
11063
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011064TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11065 TEST_DESCRIPTION("Delete in-use bufferView.");
11066
11067 ASSERT_NO_FATAL_FAILURE(InitState());
11068 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11069
11070 VkDescriptorPoolSize ds_type_count;
11071 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11072 ds_type_count.descriptorCount = 1;
11073
11074 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11075 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11076 ds_pool_ci.maxSets = 1;
11077 ds_pool_ci.poolSizeCount = 1;
11078 ds_pool_ci.pPoolSizes = &ds_type_count;
11079
11080 VkDescriptorPool ds_pool;
11081 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11082 ASSERT_VK_SUCCESS(err);
11083
11084 VkDescriptorSetLayoutBinding layout_binding;
11085 layout_binding.binding = 0;
11086 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11087 layout_binding.descriptorCount = 1;
11088 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11089 layout_binding.pImmutableSamplers = NULL;
11090
11091 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11092 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11093 ds_layout_ci.bindingCount = 1;
11094 ds_layout_ci.pBindings = &layout_binding;
11095 VkDescriptorSetLayout ds_layout;
11096 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11097 ASSERT_VK_SUCCESS(err);
11098
11099 VkDescriptorSetAllocateInfo alloc_info = {};
11100 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11101 alloc_info.descriptorSetCount = 1;
11102 alloc_info.descriptorPool = ds_pool;
11103 alloc_info.pSetLayouts = &ds_layout;
11104 VkDescriptorSet descriptor_set;
11105 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11106 ASSERT_VK_SUCCESS(err);
11107
11108 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11109 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11110 pipeline_layout_ci.pNext = NULL;
11111 pipeline_layout_ci.setLayoutCount = 1;
11112 pipeline_layout_ci.pSetLayouts = &ds_layout;
11113
11114 VkPipelineLayout pipeline_layout;
11115 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11116 ASSERT_VK_SUCCESS(err);
11117
11118 VkBuffer buffer;
11119 uint32_t queue_family_index = 0;
11120 VkBufferCreateInfo buffer_create_info = {};
11121 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11122 buffer_create_info.size = 1024;
11123 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11124 buffer_create_info.queueFamilyIndexCount = 1;
11125 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11126
11127 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11128 ASSERT_VK_SUCCESS(err);
11129
11130 VkMemoryRequirements memory_reqs;
11131 VkDeviceMemory buffer_memory;
11132
11133 VkMemoryAllocateInfo memory_info = {};
11134 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11135 memory_info.allocationSize = 0;
11136 memory_info.memoryTypeIndex = 0;
11137
11138 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11139 memory_info.allocationSize = memory_reqs.size;
11140 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11141 ASSERT_TRUE(pass);
11142
11143 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11144 ASSERT_VK_SUCCESS(err);
11145 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11146 ASSERT_VK_SUCCESS(err);
11147
11148 VkBufferView view;
11149 VkBufferViewCreateInfo bvci = {};
11150 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11151 bvci.buffer = buffer;
11152 bvci.format = VK_FORMAT_R8_UNORM;
11153 bvci.range = VK_WHOLE_SIZE;
11154
11155 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11156 ASSERT_VK_SUCCESS(err);
11157
11158 VkWriteDescriptorSet descriptor_write = {};
11159 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11160 descriptor_write.dstSet = descriptor_set;
11161 descriptor_write.dstBinding = 0;
11162 descriptor_write.descriptorCount = 1;
11163 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11164 descriptor_write.pTexelBufferView = &view;
11165
11166 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11167
11168 char const *vsSource = "#version 450\n"
11169 "\n"
11170 "out gl_PerVertex { \n"
11171 " vec4 gl_Position;\n"
11172 "};\n"
11173 "void main(){\n"
11174 " gl_Position = vec4(1);\n"
11175 "}\n";
11176 char const *fsSource = "#version 450\n"
11177 "\n"
11178 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11179 "layout(location=0) out vec4 x;\n"
11180 "void main(){\n"
11181 " x = imageLoad(s, 0);\n"
11182 "}\n";
11183 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11184 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11185 VkPipelineObj pipe(m_device);
11186 pipe.AddShader(&vs);
11187 pipe.AddShader(&fs);
11188 pipe.AddColorAttachment();
11189 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11190
11191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11192
11193 BeginCommandBuffer();
11194 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11195 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11196 VkRect2D scissor = {{0, 0}, {16, 16}};
11197 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11198 // Bind pipeline to cmd buffer
11199 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11200 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11201 &descriptor_set, 0, nullptr);
11202 Draw(1, 0, 0, 0);
11203 EndCommandBuffer();
11204
11205 VkSubmitInfo submit_info = {};
11206 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11207 submit_info.commandBufferCount = 1;
11208 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11209 // Submit cmd buffer and then destroy bufferView while in-flight
11210 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11211
11212 vkDestroyBufferView(m_device->device(), view, nullptr);
11213 m_errorMonitor->VerifyFound();
11214 vkQueueWaitIdle(m_device->m_queue);
11215 // Now we can actually destroy bufferView
11216 vkDestroyBufferView(m_device->device(), view, NULL);
11217 vkDestroyBuffer(m_device->device(), buffer, NULL);
11218 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11219 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11220 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11221 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11222}
11223
Tobin Ehlis209532e2016-09-07 13:52:18 -060011224TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11225 TEST_DESCRIPTION("Delete in-use sampler.");
11226
11227 ASSERT_NO_FATAL_FAILURE(InitState());
11228 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11229
11230 VkDescriptorPoolSize ds_type_count;
11231 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11232 ds_type_count.descriptorCount = 1;
11233
11234 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11235 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11236 ds_pool_ci.maxSets = 1;
11237 ds_pool_ci.poolSizeCount = 1;
11238 ds_pool_ci.pPoolSizes = &ds_type_count;
11239
11240 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011241 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011242 ASSERT_VK_SUCCESS(err);
11243
11244 VkSamplerCreateInfo sampler_ci = {};
11245 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11246 sampler_ci.pNext = NULL;
11247 sampler_ci.magFilter = VK_FILTER_NEAREST;
11248 sampler_ci.minFilter = VK_FILTER_NEAREST;
11249 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11250 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11251 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11252 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11253 sampler_ci.mipLodBias = 1.0;
11254 sampler_ci.anisotropyEnable = VK_FALSE;
11255 sampler_ci.maxAnisotropy = 1;
11256 sampler_ci.compareEnable = VK_FALSE;
11257 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11258 sampler_ci.minLod = 1.0;
11259 sampler_ci.maxLod = 1.0;
11260 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11261 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11262 VkSampler sampler;
11263
11264 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11265 ASSERT_VK_SUCCESS(err);
11266
11267 VkDescriptorSetLayoutBinding layout_binding;
11268 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011269 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011270 layout_binding.descriptorCount = 1;
11271 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11272 layout_binding.pImmutableSamplers = NULL;
11273
11274 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11275 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11276 ds_layout_ci.bindingCount = 1;
11277 ds_layout_ci.pBindings = &layout_binding;
11278 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011279 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011280 ASSERT_VK_SUCCESS(err);
11281
11282 VkDescriptorSetAllocateInfo alloc_info = {};
11283 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11284 alloc_info.descriptorSetCount = 1;
11285 alloc_info.descriptorPool = ds_pool;
11286 alloc_info.pSetLayouts = &ds_layout;
11287 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011288 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011289 ASSERT_VK_SUCCESS(err);
11290
11291 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11292 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11293 pipeline_layout_ci.pNext = NULL;
11294 pipeline_layout_ci.setLayoutCount = 1;
11295 pipeline_layout_ci.pSetLayouts = &ds_layout;
11296
11297 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011298 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011299 ASSERT_VK_SUCCESS(err);
11300
11301 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011302 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 -060011303 ASSERT_TRUE(image.initialized());
11304
11305 VkImageView view;
11306 VkImageViewCreateInfo ivci = {};
11307 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11308 ivci.image = image.handle();
11309 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11310 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11311 ivci.subresourceRange.layerCount = 1;
11312 ivci.subresourceRange.baseMipLevel = 0;
11313 ivci.subresourceRange.levelCount = 1;
11314 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11315
11316 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11317 ASSERT_VK_SUCCESS(err);
11318
11319 VkDescriptorImageInfo image_info{};
11320 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11321 image_info.imageView = view;
11322 image_info.sampler = sampler;
11323
11324 VkWriteDescriptorSet descriptor_write = {};
11325 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11326 descriptor_write.dstSet = descriptor_set;
11327 descriptor_write.dstBinding = 0;
11328 descriptor_write.descriptorCount = 1;
11329 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11330 descriptor_write.pImageInfo = &image_info;
11331
11332 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11333
11334 // Create PSO to use the sampler
11335 char const *vsSource = "#version 450\n"
11336 "\n"
11337 "out gl_PerVertex { \n"
11338 " vec4 gl_Position;\n"
11339 "};\n"
11340 "void main(){\n"
11341 " gl_Position = vec4(1);\n"
11342 "}\n";
11343 char const *fsSource = "#version 450\n"
11344 "\n"
11345 "layout(set=0, binding=0) uniform sampler2D s;\n"
11346 "layout(location=0) out vec4 x;\n"
11347 "void main(){\n"
11348 " x = texture(s, vec2(1));\n"
11349 "}\n";
11350 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11351 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11352 VkPipelineObj pipe(m_device);
11353 pipe.AddShader(&vs);
11354 pipe.AddShader(&fs);
11355 pipe.AddColorAttachment();
11356 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11357
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011359
11360 BeginCommandBuffer();
11361 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011362 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11363 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11364 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011365 Draw(1, 0, 0, 0);
11366 EndCommandBuffer();
11367 // Submit cmd buffer then destroy sampler
11368 VkSubmitInfo submit_info = {};
11369 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11370 submit_info.commandBufferCount = 1;
11371 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11372 // Submit cmd buffer and then destroy sampler while in-flight
11373 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11374
11375 vkDestroySampler(m_device->device(), sampler, nullptr);
11376 m_errorMonitor->VerifyFound();
11377 vkQueueWaitIdle(m_device->m_queue);
11378 // Now we can actually destroy sampler
11379 vkDestroySampler(m_device->device(), sampler, nullptr);
11380 vkDestroyImageView(m_device->device(), view, NULL);
11381 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11382 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11383 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11384}
11385
Mark Mueller1cd9f412016-08-25 13:23:52 -060011386TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011387 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011388 "signaled but not waited on by the queue. Wait on a "
11389 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011390
11391 ASSERT_NO_FATAL_FAILURE(InitState());
11392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11393
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011394 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11395 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11396 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011397
11398 BeginCommandBuffer();
11399 EndCommandBuffer();
11400
11401 VkSemaphoreCreateInfo semaphore_create_info = {};
11402 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11403 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011404 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011405 VkSubmitInfo submit_info = {};
11406 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11407 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011408 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011409 submit_info.signalSemaphoreCount = 1;
11410 submit_info.pSignalSemaphores = &semaphore;
11411 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11412 m_errorMonitor->SetDesiredFailureMsg(0, "");
11413 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11414 BeginCommandBuffer();
11415 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011417 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11418 m_errorMonitor->VerifyFound();
11419
Mark Mueller1cd9f412016-08-25 13:23:52 -060011420 VkFenceCreateInfo fence_create_info = {};
11421 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11422 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011423 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011424
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011426 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11427 m_errorMonitor->VerifyFound();
11428
Mark Mueller4042b652016-09-05 22:52:21 -060011429 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011430 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011431 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11432}
11433
Tobin Ehlis4af23302016-07-19 10:50:30 -060011434TEST_F(VkLayerTest, FramebufferIncompatible) {
11435 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11436 "that does not match the framebuffer for the active "
11437 "renderpass.");
11438 ASSERT_NO_FATAL_FAILURE(InitState());
11439 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11440
11441 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011442 VkAttachmentDescription attachment = {0,
11443 VK_FORMAT_B8G8R8A8_UNORM,
11444 VK_SAMPLE_COUNT_1_BIT,
11445 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11446 VK_ATTACHMENT_STORE_OP_STORE,
11447 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11448 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11449 VK_IMAGE_LAYOUT_UNDEFINED,
11450 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011451
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011452 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011453
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011454 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011455
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011456 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011457
11458 VkRenderPass rp;
11459 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11460 ASSERT_VK_SUCCESS(err);
11461
11462 // A compatible framebuffer.
11463 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011464 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 -060011465 ASSERT_TRUE(image.initialized());
11466
11467 VkImageViewCreateInfo ivci = {
11468 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11469 nullptr,
11470 0,
11471 image.handle(),
11472 VK_IMAGE_VIEW_TYPE_2D,
11473 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011474 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11475 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011476 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11477 };
11478 VkImageView view;
11479 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11480 ASSERT_VK_SUCCESS(err);
11481
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011482 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011483 VkFramebuffer fb;
11484 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11485 ASSERT_VK_SUCCESS(err);
11486
11487 VkCommandBufferAllocateInfo cbai = {};
11488 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11489 cbai.commandPool = m_commandPool;
11490 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11491 cbai.commandBufferCount = 1;
11492
11493 VkCommandBuffer sec_cb;
11494 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11495 ASSERT_VK_SUCCESS(err);
11496 VkCommandBufferBeginInfo cbbi = {};
11497 VkCommandBufferInheritanceInfo cbii = {};
11498 cbii.renderPass = renderPass();
11499 cbii.framebuffer = fb;
11500 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11501 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011502 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 -060011503 cbbi.pInheritanceInfo = &cbii;
11504 vkBeginCommandBuffer(sec_cb, &cbbi);
11505 vkEndCommandBuffer(sec_cb);
11506
Chris Forbes3400bc52016-09-13 18:10:34 +120011507 VkCommandBufferBeginInfo cbbi2 = {
11508 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11509 0, nullptr
11510 };
11511 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11512 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011513
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011515 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011516 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11517 m_errorMonitor->VerifyFound();
11518 // Cleanup
11519 vkDestroyImageView(m_device->device(), view, NULL);
11520 vkDestroyRenderPass(m_device->device(), rp, NULL);
11521 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11522}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011523
11524TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11525 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11526 "invalid value. If logicOp is not available, attempt to "
11527 "use it and verify that we see the correct error.");
11528 ASSERT_NO_FATAL_FAILURE(InitState());
11529 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11530
11531 auto features = m_device->phy().features();
11532 // Set the expected error depending on whether or not logicOp available
11533 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11535 "enabled, logicOpEnable must be "
11536 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011537 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011539 }
11540 // Create a pipeline using logicOp
11541 VkResult err;
11542
11543 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11544 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11545
11546 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011547 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011548 ASSERT_VK_SUCCESS(err);
11549
11550 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11551 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11552 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011553 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011554 vp_state_ci.pViewports = &vp;
11555 vp_state_ci.scissorCount = 1;
11556 VkRect2D scissors = {}; // Dummy scissors to point to
11557 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011558
11559 VkPipelineShaderStageCreateInfo shaderStages[2];
11560 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11561
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011562 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11563 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011564 shaderStages[0] = vs.GetStageCreateInfo();
11565 shaderStages[1] = fs.GetStageCreateInfo();
11566
11567 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11568 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11569
11570 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11571 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11572 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11573
11574 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11575 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011576 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011577
11578 VkPipelineColorBlendAttachmentState att = {};
11579 att.blendEnable = VK_FALSE;
11580 att.colorWriteMask = 0xf;
11581
11582 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11583 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11584 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11585 cb_ci.logicOpEnable = VK_TRUE;
11586 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11587 cb_ci.attachmentCount = 1;
11588 cb_ci.pAttachments = &att;
11589
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011590 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11591 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11592 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11593
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011594 VkGraphicsPipelineCreateInfo gp_ci = {};
11595 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11596 gp_ci.stageCount = 2;
11597 gp_ci.pStages = shaderStages;
11598 gp_ci.pVertexInputState = &vi_ci;
11599 gp_ci.pInputAssemblyState = &ia_ci;
11600 gp_ci.pViewportState = &vp_state_ci;
11601 gp_ci.pRasterizationState = &rs_ci;
11602 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011603 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011604 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11605 gp_ci.layout = pipeline_layout;
11606 gp_ci.renderPass = renderPass();
11607
11608 VkPipelineCacheCreateInfo pc_ci = {};
11609 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11610
11611 VkPipeline pipeline;
11612 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011613 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011614 ASSERT_VK_SUCCESS(err);
11615
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011616 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011617 m_errorMonitor->VerifyFound();
11618 if (VK_SUCCESS == err) {
11619 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11620 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011621 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11622 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11623}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011624#endif // DRAW_STATE_TESTS
11625
Tobin Ehlis0788f522015-05-26 16:11:58 -060011626#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011627#if GTEST_IS_THREADSAFE
11628struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011629 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011630 VkEvent event;
11631 bool bailout;
11632};
11633
Karl Schultz6addd812016-02-02 17:17:23 -070011634extern "C" void *AddToCommandBuffer(void *arg) {
11635 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011636
Mike Stroyana6d14942016-07-13 15:10:05 -060011637 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011638 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011639 if (data->bailout) {
11640 break;
11641 }
11642 }
11643 return NULL;
11644}
11645
Karl Schultz6addd812016-02-02 17:17:23 -070011646TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011647 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011648
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011650
Mike Stroyanaccf7692015-05-12 16:00:45 -060011651 ASSERT_NO_FATAL_FAILURE(InitState());
11652 ASSERT_NO_FATAL_FAILURE(InitViewport());
11653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11654
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011655 // Calls AllocateCommandBuffers
11656 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011657
11658 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011659 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011660
11661 VkEventCreateInfo event_info;
11662 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011663 VkResult err;
11664
11665 memset(&event_info, 0, sizeof(event_info));
11666 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11667
Chia-I Wuf7458c52015-10-26 21:10:41 +080011668 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011669 ASSERT_VK_SUCCESS(err);
11670
Mike Stroyanaccf7692015-05-12 16:00:45 -060011671 err = vkResetEvent(device(), event);
11672 ASSERT_VK_SUCCESS(err);
11673
11674 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011675 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011676 data.event = event;
11677 data.bailout = false;
11678 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011679
11680 // First do some correct operations using multiple threads.
11681 // Add many entries to command buffer from another thread.
11682 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11683 // Make non-conflicting calls from this thread at the same time.
11684 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011685 uint32_t count;
11686 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011687 }
11688 test_platform_thread_join(thread, NULL);
11689
11690 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011691 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011692 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011693 // Add many entries to command buffer from this thread at the same time.
11694 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011695
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011696 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011697 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011698
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011699 m_errorMonitor->SetBailout(NULL);
11700
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011701 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011702
Chia-I Wuf7458c52015-10-26 21:10:41 +080011703 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011704}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011705#endif // GTEST_IS_THREADSAFE
11706#endif // THREADING_TESTS
11707
Chris Forbes9f7ff632015-05-25 11:13:08 +120011708#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011709TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011710 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11711 "with an impossible code size");
11712
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011714
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011715 ASSERT_NO_FATAL_FAILURE(InitState());
11716 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11717
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011718 VkShaderModule module;
11719 VkShaderModuleCreateInfo moduleCreateInfo;
11720 struct icd_spv_header spv;
11721
11722 spv.magic = ICD_SPV_MAGIC;
11723 spv.version = ICD_SPV_VERSION;
11724 spv.gen_magic = 0;
11725
11726 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11727 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011728 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011729 moduleCreateInfo.codeSize = 4;
11730 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011731 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011732
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011733 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011734}
11735
Karl Schultz6addd812016-02-02 17:17:23 -070011736TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011737 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11738 "with a bad magic number");
11739
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011741
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011742 ASSERT_NO_FATAL_FAILURE(InitState());
11743 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11744
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011745 VkShaderModule module;
11746 VkShaderModuleCreateInfo moduleCreateInfo;
11747 struct icd_spv_header spv;
11748
11749 spv.magic = ~ICD_SPV_MAGIC;
11750 spv.version = ICD_SPV_VERSION;
11751 spv.gen_magic = 0;
11752
11753 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11754 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011755 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011756 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11757 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011758 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011759
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011760 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011761}
11762
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011763#if 0
11764// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011765TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011767 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011768
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011769 ASSERT_NO_FATAL_FAILURE(InitState());
11770 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11771
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011772 VkShaderModule module;
11773 VkShaderModuleCreateInfo moduleCreateInfo;
11774 struct icd_spv_header spv;
11775
11776 spv.magic = ICD_SPV_MAGIC;
11777 spv.version = ~ICD_SPV_VERSION;
11778 spv.gen_magic = 0;
11779
11780 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11781 moduleCreateInfo.pNext = NULL;
11782
Karl Schultz6addd812016-02-02 17:17:23 -070011783 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011784 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11785 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011786 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011787
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011788 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011789}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011790#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011791
Karl Schultz6addd812016-02-02 17:17:23 -070011792TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011793 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11794 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011796
Chris Forbes9f7ff632015-05-25 11:13:08 +120011797 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011798 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011799
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011800 char const *vsSource = "#version 450\n"
11801 "\n"
11802 "layout(location=0) out float x;\n"
11803 "out gl_PerVertex {\n"
11804 " vec4 gl_Position;\n"
11805 "};\n"
11806 "void main(){\n"
11807 " gl_Position = vec4(1);\n"
11808 " x = 0;\n"
11809 "}\n";
11810 char const *fsSource = "#version 450\n"
11811 "\n"
11812 "layout(location=0) out vec4 color;\n"
11813 "void main(){\n"
11814 " color = vec4(1);\n"
11815 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011816
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011817 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11818 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011819
11820 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011821 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011822 pipe.AddShader(&vs);
11823 pipe.AddShader(&fs);
11824
Chris Forbes9f7ff632015-05-25 11:13:08 +120011825 VkDescriptorSetObj descriptorSet(m_device);
11826 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011827 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011828
Tony Barbour5781e8f2015-08-04 16:23:11 -060011829 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011830
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011831 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011832}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011833
Mark Mueller098c9cb2016-09-08 09:01:57 -060011834TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11835 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11836
11837 ASSERT_NO_FATAL_FAILURE(InitState());
11838 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11839
11840 const char *bad_specialization_message =
11841 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11842
11843 char const *vsSource =
11844 "#version 450\n"
11845 "\n"
11846 "out gl_PerVertex {\n"
11847 " vec4 gl_Position;\n"
11848 "};\n"
11849 "void main(){\n"
11850 " gl_Position = vec4(1);\n"
11851 "}\n";
11852
11853 char const *fsSource =
11854 "#version 450\n"
11855 "\n"
11856 "layout (constant_id = 0) const float r = 0.0f;\n"
11857 "layout(location = 0) out vec4 uFragColor;\n"
11858 "void main(){\n"
11859 " uFragColor = vec4(r,1,0,1);\n"
11860 "}\n";
11861
11862 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11863 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11864
11865 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11866 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11867
11868 VkPipelineLayout pipeline_layout;
11869 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11870
11871 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11872 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11873 vp_state_create_info.viewportCount = 1;
11874 VkViewport viewport = {};
11875 vp_state_create_info.pViewports = &viewport;
11876 vp_state_create_info.scissorCount = 1;
11877 VkRect2D scissors = {};
11878 vp_state_create_info.pScissors = &scissors;
11879
11880 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11881
11882 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11883 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11884 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11885 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11886
11887 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11888 vs.GetStageCreateInfo(),
11889 fs.GetStageCreateInfo()
11890 };
11891
11892 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11893 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11894
11895 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11896 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11897 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11898
11899 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11900 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11901 rasterization_state_create_info.pNext = nullptr;
11902 rasterization_state_create_info.lineWidth = 1.0f;
11903 rasterization_state_create_info.rasterizerDiscardEnable = true;
11904
11905 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11906 color_blend_attachment_state.blendEnable = VK_FALSE;
11907 color_blend_attachment_state.colorWriteMask = 0xf;
11908
11909 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11910 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11911 color_blend_state_create_info.attachmentCount = 1;
11912 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11913
11914 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11915 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11916 graphicspipe_create_info.stageCount = 2;
11917 graphicspipe_create_info.pStages = shader_stage_create_info;
11918 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11919 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11920 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11921 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11922 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11923 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11924 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11925 graphicspipe_create_info.layout = pipeline_layout;
11926 graphicspipe_create_info.renderPass = renderPass();
11927
11928 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
11929 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11930
11931 VkPipelineCache pipelineCache;
11932 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
11933
11934 // This structure maps constant ids to data locations.
11935 const VkSpecializationMapEntry entry =
11936 // id, offset, size
11937 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
11938
11939 uint32_t data = 1;
11940
11941 // Set up the info describing spec map and data
11942 const VkSpecializationInfo specialization_info = {
11943 1,
11944 &entry,
11945 1 * sizeof(float),
11946 &data,
11947 };
11948 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
11949
11950 VkPipeline pipeline;
11951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
11952 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
11953 m_errorMonitor->VerifyFound();
11954
11955 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
11956 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11957}
11958
11959TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
11960 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11961
11962 ASSERT_NO_FATAL_FAILURE(InitState());
11963 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11964
11965 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
11966
11967 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
11968 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11969 descriptor_pool_type_count[0].descriptorCount = 1;
11970 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11971 descriptor_pool_type_count[1].descriptorCount = 1;
11972
11973 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11974 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11975 descriptor_pool_create_info.maxSets = 1;
11976 descriptor_pool_create_info.poolSizeCount = 2;
11977 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
11978 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11979
11980 VkDescriptorPool descriptorset_pool;
11981 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11982
11983 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11984 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11985 descriptorset_layout_binding.descriptorCount = 1;
11986 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11987
11988 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11989 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11990 descriptorset_layout_create_info.bindingCount = 1;
11991 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11992
11993 VkDescriptorSetLayout descriptorset_layout;
11994 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
11995
11996 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11997 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11998 descriptorset_allocate_info.descriptorSetCount = 1;
11999 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12000 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12001 VkDescriptorSet descriptorset;
12002 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12003
12004 // Challenge core_validation with a non uniform buffer type.
12005 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12006
Mark Mueller098c9cb2016-09-08 09:01:57 -060012007 char const *vsSource =
12008 "#version 450\n"
12009 "\n"
12010 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12011 " mat4 mvp;\n"
12012 "} ubuf;\n"
12013 "out gl_PerVertex {\n"
12014 " vec4 gl_Position;\n"
12015 "};\n"
12016 "void main(){\n"
12017 " gl_Position = ubuf.mvp * vec4(1);\n"
12018 "}\n";
12019
12020 char const *fsSource =
12021 "#version 450\n"
12022 "\n"
12023 "layout(location = 0) out vec4 uFragColor;\n"
12024 "void main(){\n"
12025 " uFragColor = vec4(0,1,0,1);\n"
12026 "}\n";
12027
12028 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12029 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12030
12031 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12032 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12033 pipeline_layout_create_info.setLayoutCount = 1;
12034 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12035
12036 VkPipelineLayout pipeline_layout;
12037 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12038
12039 VkPipelineObj pipe(m_device);
12040 pipe.AddColorAttachment();
12041 pipe.AddShader(&vs);
12042 pipe.AddShader(&fs);
12043
12044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12045 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12046 m_errorMonitor->VerifyFound();
12047
12048 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12049 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12050 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12051}
12052
12053TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12054 TEST_DESCRIPTION(
12055 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12056
12057 ASSERT_NO_FATAL_FAILURE(InitState());
12058 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12059
12060 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12061
12062 VkDescriptorPoolSize descriptor_pool_type_count = {};
12063 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12064 descriptor_pool_type_count.descriptorCount = 1;
12065
12066 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12067 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12068 descriptor_pool_create_info.maxSets = 1;
12069 descriptor_pool_create_info.poolSizeCount = 1;
12070 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12071 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12072
12073 VkDescriptorPool descriptorset_pool;
12074 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12075
12076 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12077 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12078 descriptorset_layout_binding.descriptorCount = 1;
12079 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12080 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12081
12082 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12083 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12084 descriptorset_layout_create_info.bindingCount = 1;
12085 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12086
12087 VkDescriptorSetLayout descriptorset_layout;
12088 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12089 nullptr, &descriptorset_layout));
12090
12091 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12092 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12093 descriptorset_allocate_info.descriptorSetCount = 1;
12094 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12095 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12096 VkDescriptorSet descriptorset;
12097 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12098
12099 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12100
Mark Mueller098c9cb2016-09-08 09:01:57 -060012101 char const *vsSource =
12102 "#version 450\n"
12103 "\n"
12104 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12105 " mat4 mvp;\n"
12106 "} ubuf;\n"
12107 "out gl_PerVertex {\n"
12108 " vec4 gl_Position;\n"
12109 "};\n"
12110 "void main(){\n"
12111 " gl_Position = ubuf.mvp * vec4(1);\n"
12112 "}\n";
12113
12114 char const *fsSource =
12115 "#version 450\n"
12116 "\n"
12117 "layout(location = 0) out vec4 uFragColor;\n"
12118 "void main(){\n"
12119 " uFragColor = vec4(0,1,0,1);\n"
12120 "}\n";
12121
12122 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12123 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12124
12125 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12126 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12127 pipeline_layout_create_info.setLayoutCount = 1;
12128 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12129
12130 VkPipelineLayout pipeline_layout;
12131 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12132
12133 VkPipelineObj pipe(m_device);
12134 pipe.AddColorAttachment();
12135 pipe.AddShader(&vs);
12136 pipe.AddShader(&fs);
12137
12138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12139 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12140 m_errorMonitor->VerifyFound();
12141
12142 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12143 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12144 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12145}
12146
12147TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12148 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12149 "accessible from the current shader stage.");
12150
12151 ASSERT_NO_FATAL_FAILURE(InitState());
12152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12153
12154 const char *push_constant_not_accessible_message =
12155 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12156
12157 char const *vsSource =
12158 "#version 450\n"
12159 "\n"
12160 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12161 "out gl_PerVertex {\n"
12162 " vec4 gl_Position;\n"
12163 "};\n"
12164 "void main(){\n"
12165 " gl_Position = vec4(consts.x);\n"
12166 "}\n";
12167
12168 char const *fsSource =
12169 "#version 450\n"
12170 "\n"
12171 "layout(location = 0) out vec4 uFragColor;\n"
12172 "void main(){\n"
12173 " uFragColor = vec4(0,1,0,1);\n"
12174 "}\n";
12175
12176 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12177 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12178
12179 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12180 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12181
12182 // Set up a push constant range
12183 VkPushConstantRange push_constant_ranges = {};
12184 // Set to the wrong stage to challenge core_validation
12185 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12186 push_constant_ranges.size = 4;
12187
12188 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12189 pipeline_layout_create_info.pushConstantRangeCount = 1;
12190
12191 VkPipelineLayout pipeline_layout;
12192 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12193
12194 VkPipelineObj pipe(m_device);
12195 pipe.AddColorAttachment();
12196 pipe.AddShader(&vs);
12197 pipe.AddShader(&fs);
12198
12199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12200 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12201 m_errorMonitor->VerifyFound();
12202
12203 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12204}
12205
12206TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12207 TEST_DESCRIPTION(
12208 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12209
12210 ASSERT_NO_FATAL_FAILURE(InitState());
12211 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12212
12213 const char *feature_not_enabled_message =
12214 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12215
12216 // Some awkward steps are required to test with custom device features.
12217 std::vector<const char *> device_extension_names;
12218 auto features = m_device->phy().features();
12219 // Disable support for 64 bit floats
12220 features.shaderFloat64 = false;
12221 // The sacrificial device object
12222 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12223
12224 char const *vsSource = "#version 450\n"
12225 "\n"
12226 "out gl_PerVertex {\n"
12227 " vec4 gl_Position;\n"
12228 "};\n"
12229 "void main(){\n"
12230 " gl_Position = vec4(1);\n"
12231 "}\n";
12232 char const *fsSource = "#version 450\n"
12233 "\n"
12234 "layout(location=0) out vec4 color;\n"
12235 "void main(){\n"
12236 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12237 " color = vec4(green);\n"
12238 "}\n";
12239
12240 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12241 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12242
12243 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012244
12245 VkPipelineObj pipe(&test_device);
12246 pipe.AddColorAttachment();
12247 pipe.AddShader(&vs);
12248 pipe.AddShader(&fs);
12249
12250 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12251 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12252 VkPipelineLayout pipeline_layout;
12253 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12254
12255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12256 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12257 m_errorMonitor->VerifyFound();
12258
12259 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12260}
12261
12262TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12263 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12264
12265 ASSERT_NO_FATAL_FAILURE(InitState());
12266 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12267
12268 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12269
12270 char const *vsSource = "#version 450\n"
12271 "\n"
12272 "out gl_PerVertex {\n"
12273 " vec4 gl_Position;\n"
12274 "};\n"
12275 "layout(xfb_buffer = 1) out;"
12276 "void main(){\n"
12277 " gl_Position = vec4(1);\n"
12278 "}\n";
12279 char const *fsSource = "#version 450\n"
12280 "\n"
12281 "layout(location=0) out vec4 color;\n"
12282 "void main(){\n"
12283 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12284 " color = vec4(green);\n"
12285 "}\n";
12286
12287 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12288 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12289
12290 VkPipelineObj pipe(m_device);
12291 pipe.AddColorAttachment();
12292 pipe.AddShader(&vs);
12293 pipe.AddShader(&fs);
12294
12295 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12296 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12297 VkPipelineLayout pipeline_layout;
12298 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12299
12300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12301 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12302 m_errorMonitor->VerifyFound();
12303
12304 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12305}
12306
Karl Schultz6addd812016-02-02 17:17:23 -070012307TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012308 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12309 "which is not present in the outputs of the previous stage");
12310
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012312
Chris Forbes59cb88d2015-05-25 11:13:13 +120012313 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012315
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012316 char const *vsSource = "#version 450\n"
12317 "\n"
12318 "out gl_PerVertex {\n"
12319 " vec4 gl_Position;\n"
12320 "};\n"
12321 "void main(){\n"
12322 " gl_Position = vec4(1);\n"
12323 "}\n";
12324 char const *fsSource = "#version 450\n"
12325 "\n"
12326 "layout(location=0) in float x;\n"
12327 "layout(location=0) out vec4 color;\n"
12328 "void main(){\n"
12329 " color = vec4(x);\n"
12330 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012331
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012332 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12333 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012334
12335 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012336 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012337 pipe.AddShader(&vs);
12338 pipe.AddShader(&fs);
12339
Chris Forbes59cb88d2015-05-25 11:13:13 +120012340 VkDescriptorSetObj descriptorSet(m_device);
12341 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012342 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012343
Tony Barbour5781e8f2015-08-04 16:23:11 -060012344 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012345
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012346 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012347}
12348
Karl Schultz6addd812016-02-02 17:17:23 -070012349TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012350 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12351 "within an interace block, which is not present in the outputs "
12352 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012354
12355 ASSERT_NO_FATAL_FAILURE(InitState());
12356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12357
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012358 char const *vsSource = "#version 450\n"
12359 "\n"
12360 "out gl_PerVertex {\n"
12361 " vec4 gl_Position;\n"
12362 "};\n"
12363 "void main(){\n"
12364 " gl_Position = vec4(1);\n"
12365 "}\n";
12366 char const *fsSource = "#version 450\n"
12367 "\n"
12368 "in block { layout(location=0) float x; } ins;\n"
12369 "layout(location=0) out vec4 color;\n"
12370 "void main(){\n"
12371 " color = vec4(ins.x);\n"
12372 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012373
12374 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12375 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12376
12377 VkPipelineObj pipe(m_device);
12378 pipe.AddColorAttachment();
12379 pipe.AddShader(&vs);
12380 pipe.AddShader(&fs);
12381
12382 VkDescriptorSetObj descriptorSet(m_device);
12383 descriptorSet.AppendDummy();
12384 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12385
12386 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12387
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012388 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012389}
12390
Karl Schultz6addd812016-02-02 17:17:23 -070012391TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012392 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012393 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12395 "output arr[2] of float32' vs 'ptr to "
12396 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012397
12398 ASSERT_NO_FATAL_FAILURE(InitState());
12399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12400
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012401 char const *vsSource = "#version 450\n"
12402 "\n"
12403 "layout(location=0) out float x[2];\n"
12404 "out gl_PerVertex {\n"
12405 " vec4 gl_Position;\n"
12406 "};\n"
12407 "void main(){\n"
12408 " x[0] = 0; x[1] = 0;\n"
12409 " gl_Position = vec4(1);\n"
12410 "}\n";
12411 char const *fsSource = "#version 450\n"
12412 "\n"
12413 "layout(location=0) in float x[3];\n"
12414 "layout(location=0) out vec4 color;\n"
12415 "void main(){\n"
12416 " color = vec4(x[0] + x[1] + x[2]);\n"
12417 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012418
12419 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12420 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12421
12422 VkPipelineObj pipe(m_device);
12423 pipe.AddColorAttachment();
12424 pipe.AddShader(&vs);
12425 pipe.AddShader(&fs);
12426
12427 VkDescriptorSetObj descriptorSet(m_device);
12428 descriptorSet.AppendDummy();
12429 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12430
12431 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12432
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012433 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012434}
12435
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012436
Karl Schultz6addd812016-02-02 17:17:23 -070012437TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012438 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012439 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012441
Chris Forbesb56af562015-05-25 11:13:17 +120012442 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012444
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012445 char const *vsSource = "#version 450\n"
12446 "\n"
12447 "layout(location=0) out int x;\n"
12448 "out gl_PerVertex {\n"
12449 " vec4 gl_Position;\n"
12450 "};\n"
12451 "void main(){\n"
12452 " x = 0;\n"
12453 " gl_Position = vec4(1);\n"
12454 "}\n";
12455 char const *fsSource = "#version 450\n"
12456 "\n"
12457 "layout(location=0) in float x;\n" /* VS writes int */
12458 "layout(location=0) out vec4 color;\n"
12459 "void main(){\n"
12460 " color = vec4(x);\n"
12461 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012462
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012463 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12464 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012465
12466 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012467 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012468 pipe.AddShader(&vs);
12469 pipe.AddShader(&fs);
12470
Chris Forbesb56af562015-05-25 11:13:17 +120012471 VkDescriptorSetObj descriptorSet(m_device);
12472 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012473 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012474
Tony Barbour5781e8f2015-08-04 16:23:11 -060012475 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012476
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012477 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012478}
12479
Karl Schultz6addd812016-02-02 17:17:23 -070012480TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012481 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012482 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012483 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012485
12486 ASSERT_NO_FATAL_FAILURE(InitState());
12487 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12488
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012489 char const *vsSource = "#version 450\n"
12490 "\n"
12491 "out block { layout(location=0) int x; } outs;\n"
12492 "out gl_PerVertex {\n"
12493 " vec4 gl_Position;\n"
12494 "};\n"
12495 "void main(){\n"
12496 " outs.x = 0;\n"
12497 " gl_Position = vec4(1);\n"
12498 "}\n";
12499 char const *fsSource = "#version 450\n"
12500 "\n"
12501 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12502 "layout(location=0) out vec4 color;\n"
12503 "void main(){\n"
12504 " color = vec4(ins.x);\n"
12505 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012506
12507 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12508 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12509
12510 VkPipelineObj pipe(m_device);
12511 pipe.AddColorAttachment();
12512 pipe.AddShader(&vs);
12513 pipe.AddShader(&fs);
12514
12515 VkDescriptorSetObj descriptorSet(m_device);
12516 descriptorSet.AppendDummy();
12517 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12518
12519 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12520
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012521 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012522}
12523
12524TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012525 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012526 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012527 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012528 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 +130012529
12530 ASSERT_NO_FATAL_FAILURE(InitState());
12531 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12532
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012533 char const *vsSource = "#version 450\n"
12534 "\n"
12535 "out block { layout(location=1) float x; } outs;\n"
12536 "out gl_PerVertex {\n"
12537 " vec4 gl_Position;\n"
12538 "};\n"
12539 "void main(){\n"
12540 " outs.x = 0;\n"
12541 " gl_Position = vec4(1);\n"
12542 "}\n";
12543 char const *fsSource = "#version 450\n"
12544 "\n"
12545 "in block { layout(location=0) float x; } ins;\n"
12546 "layout(location=0) out vec4 color;\n"
12547 "void main(){\n"
12548 " color = vec4(ins.x);\n"
12549 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012550
12551 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12552 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12553
12554 VkPipelineObj pipe(m_device);
12555 pipe.AddColorAttachment();
12556 pipe.AddShader(&vs);
12557 pipe.AddShader(&fs);
12558
12559 VkDescriptorSetObj descriptorSet(m_device);
12560 descriptorSet.AppendDummy();
12561 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12562
12563 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12564
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012565 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012566}
12567
12568TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012569 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012570 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012571 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012572 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 +130012573
12574 ASSERT_NO_FATAL_FAILURE(InitState());
12575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12576
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012577 char const *vsSource = "#version 450\n"
12578 "\n"
12579 "out block { layout(location=0, component=0) float x; } outs;\n"
12580 "out gl_PerVertex {\n"
12581 " vec4 gl_Position;\n"
12582 "};\n"
12583 "void main(){\n"
12584 " outs.x = 0;\n"
12585 " gl_Position = vec4(1);\n"
12586 "}\n";
12587 char const *fsSource = "#version 450\n"
12588 "\n"
12589 "in block { layout(location=0, component=1) float x; } ins;\n"
12590 "layout(location=0) out vec4 color;\n"
12591 "void main(){\n"
12592 " color = vec4(ins.x);\n"
12593 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012594
12595 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12596 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12597
12598 VkPipelineObj pipe(m_device);
12599 pipe.AddColorAttachment();
12600 pipe.AddShader(&vs);
12601 pipe.AddShader(&fs);
12602
12603 VkDescriptorSetObj descriptorSet(m_device);
12604 descriptorSet.AppendDummy();
12605 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12606
12607 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12608
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012609 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012610}
12611
Karl Schultz6addd812016-02-02 17:17:23 -070012612TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012613 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12614 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012616
Chris Forbesde136e02015-05-25 11:13:28 +120012617 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012618 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012619
12620 VkVertexInputBindingDescription input_binding;
12621 memset(&input_binding, 0, sizeof(input_binding));
12622
12623 VkVertexInputAttributeDescription input_attrib;
12624 memset(&input_attrib, 0, sizeof(input_attrib));
12625 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12626
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012627 char const *vsSource = "#version 450\n"
12628 "\n"
12629 "out gl_PerVertex {\n"
12630 " vec4 gl_Position;\n"
12631 "};\n"
12632 "void main(){\n"
12633 " gl_Position = vec4(1);\n"
12634 "}\n";
12635 char const *fsSource = "#version 450\n"
12636 "\n"
12637 "layout(location=0) out vec4 color;\n"
12638 "void main(){\n"
12639 " color = vec4(1);\n"
12640 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012641
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012642 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12643 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012644
12645 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012646 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012647 pipe.AddShader(&vs);
12648 pipe.AddShader(&fs);
12649
12650 pipe.AddVertexInputBindings(&input_binding, 1);
12651 pipe.AddVertexInputAttribs(&input_attrib, 1);
12652
Chris Forbesde136e02015-05-25 11:13:28 +120012653 VkDescriptorSetObj descriptorSet(m_device);
12654 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012655 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012656
Tony Barbour5781e8f2015-08-04 16:23:11 -060012657 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012658
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012659 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012660}
12661
Karl Schultz6addd812016-02-02 17:17:23 -070012662TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012663 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12664 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012666
12667 ASSERT_NO_FATAL_FAILURE(InitState());
12668 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12669
12670 VkVertexInputBindingDescription input_binding;
12671 memset(&input_binding, 0, sizeof(input_binding));
12672
12673 VkVertexInputAttributeDescription input_attrib;
12674 memset(&input_attrib, 0, sizeof(input_attrib));
12675 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12676
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012677 char const *vsSource = "#version 450\n"
12678 "\n"
12679 "layout(location=1) in float x;\n"
12680 "out gl_PerVertex {\n"
12681 " vec4 gl_Position;\n"
12682 "};\n"
12683 "void main(){\n"
12684 " gl_Position = vec4(x);\n"
12685 "}\n";
12686 char const *fsSource = "#version 450\n"
12687 "\n"
12688 "layout(location=0) out vec4 color;\n"
12689 "void main(){\n"
12690 " color = vec4(1);\n"
12691 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012692
12693 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12694 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12695
12696 VkPipelineObj pipe(m_device);
12697 pipe.AddColorAttachment();
12698 pipe.AddShader(&vs);
12699 pipe.AddShader(&fs);
12700
12701 pipe.AddVertexInputBindings(&input_binding, 1);
12702 pipe.AddVertexInputAttribs(&input_attrib, 1);
12703
12704 VkDescriptorSetObj descriptorSet(m_device);
12705 descriptorSet.AppendDummy();
12706 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12707
12708 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12709
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012710 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012711}
12712
Karl Schultz6addd812016-02-02 17:17:23 -070012713TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012714 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012715 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012716 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 -060012717
Chris Forbes62e8e502015-05-25 11:13:29 +120012718 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012719 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012720
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012721 char const *vsSource = "#version 450\n"
12722 "\n"
12723 "layout(location=0) in vec4 x;\n" /* not provided */
12724 "out gl_PerVertex {\n"
12725 " vec4 gl_Position;\n"
12726 "};\n"
12727 "void main(){\n"
12728 " gl_Position = x;\n"
12729 "}\n";
12730 char const *fsSource = "#version 450\n"
12731 "\n"
12732 "layout(location=0) out vec4 color;\n"
12733 "void main(){\n"
12734 " color = vec4(1);\n"
12735 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012736
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012737 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12738 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012739
12740 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012741 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012742 pipe.AddShader(&vs);
12743 pipe.AddShader(&fs);
12744
Chris Forbes62e8e502015-05-25 11:13:29 +120012745 VkDescriptorSetObj descriptorSet(m_device);
12746 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012747 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012748
Tony Barbour5781e8f2015-08-04 16:23:11 -060012749 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012750
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012751 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012752}
12753
Karl Schultz6addd812016-02-02 17:17:23 -070012754TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012755 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12756 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012757 "vertex shader input that consumes it");
12758 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 -060012759
Chris Forbesc97d98e2015-05-25 11:13:31 +120012760 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012761 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012762
12763 VkVertexInputBindingDescription input_binding;
12764 memset(&input_binding, 0, sizeof(input_binding));
12765
12766 VkVertexInputAttributeDescription input_attrib;
12767 memset(&input_attrib, 0, sizeof(input_attrib));
12768 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12769
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012770 char const *vsSource = "#version 450\n"
12771 "\n"
12772 "layout(location=0) in int x;\n" /* attrib provided float */
12773 "out gl_PerVertex {\n"
12774 " vec4 gl_Position;\n"
12775 "};\n"
12776 "void main(){\n"
12777 " gl_Position = vec4(x);\n"
12778 "}\n";
12779 char const *fsSource = "#version 450\n"
12780 "\n"
12781 "layout(location=0) out vec4 color;\n"
12782 "void main(){\n"
12783 " color = vec4(1);\n"
12784 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012785
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012786 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12787 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012788
12789 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012790 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012791 pipe.AddShader(&vs);
12792 pipe.AddShader(&fs);
12793
12794 pipe.AddVertexInputBindings(&input_binding, 1);
12795 pipe.AddVertexInputAttribs(&input_attrib, 1);
12796
Chris Forbesc97d98e2015-05-25 11:13:31 +120012797 VkDescriptorSetObj descriptorSet(m_device);
12798 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012799 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012800
Tony Barbour5781e8f2015-08-04 16:23:11 -060012801 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012802
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012803 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012804}
12805
Chris Forbesc68b43c2016-04-06 11:18:47 +120012806TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012807 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12808 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12810 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012811
12812 ASSERT_NO_FATAL_FAILURE(InitState());
12813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12814
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012815 char const *vsSource = "#version 450\n"
12816 "\n"
12817 "out gl_PerVertex {\n"
12818 " vec4 gl_Position;\n"
12819 "};\n"
12820 "void main(){\n"
12821 " gl_Position = vec4(1);\n"
12822 "}\n";
12823 char const *fsSource = "#version 450\n"
12824 "\n"
12825 "layout(location=0) out vec4 color;\n"
12826 "void main(){\n"
12827 " color = vec4(1);\n"
12828 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012829
12830 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12831 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12832
12833 VkPipelineObj pipe(m_device);
12834 pipe.AddColorAttachment();
12835 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012836 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012837 pipe.AddShader(&fs);
12838
12839 VkDescriptorSetObj descriptorSet(m_device);
12840 descriptorSet.AppendDummy();
12841 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12842
12843 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12844
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012845 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012846}
12847
Chris Forbes82ff92a2016-09-09 10:50:24 +120012848TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12850 "No entrypoint found named `foo`");
12851
12852 ASSERT_NO_FATAL_FAILURE(InitState());
12853 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12854
12855 char const *vsSource = "#version 450\n"
12856 "out gl_PerVertex {\n"
12857 " vec4 gl_Position;\n"
12858 "};\n"
12859 "void main(){\n"
12860 " gl_Position = vec4(0);\n"
12861 "}\n";
12862 char const *fsSource = "#version 450\n"
12863 "\n"
12864 "layout(location=0) out vec4 color;\n"
12865 "void main(){\n"
12866 " color = vec4(1);\n"
12867 "}\n";
12868
12869 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12870 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12871
12872 VkPipelineObj pipe(m_device);
12873 pipe.AddColorAttachment();
12874 pipe.AddShader(&vs);
12875 pipe.AddShader(&fs);
12876
12877 VkDescriptorSetObj descriptorSet(m_device);
12878 descriptorSet.AppendDummy();
12879 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12880
12881 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12882
12883 m_errorMonitor->VerifyFound();
12884}
12885
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012886TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12887 m_errorMonitor->SetDesiredFailureMsg(
12888 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12889 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12890 "uses a depth/stencil attachment");
12891
12892 ASSERT_NO_FATAL_FAILURE(InitState());
12893 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12894
12895 char const *vsSource = "#version 450\n"
12896 "void main(){ gl_Position = vec4(0); }\n";
12897 char const *fsSource = "#version 450\n"
12898 "\n"
12899 "layout(location=0) out vec4 color;\n"
12900 "void main(){\n"
12901 " color = vec4(1);\n"
12902 "}\n";
12903
12904 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12905 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12906
12907 VkPipelineObj pipe(m_device);
12908 pipe.AddColorAttachment();
12909 pipe.AddShader(&vs);
12910 pipe.AddShader(&fs);
12911
12912 VkDescriptorSetObj descriptorSet(m_device);
12913 descriptorSet.AppendDummy();
12914 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12915
12916 VkAttachmentDescription attachments[] = {
12917 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12918 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12919 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12920 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12921 },
12922 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12923 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12924 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12925 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12926 },
12927 };
12928 VkAttachmentReference refs[] = {
12929 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
12930 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
12931 };
12932 VkSubpassDescription subpass = {
12933 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
12934 1, &refs[0], nullptr, &refs[1],
12935 0, nullptr
12936 };
12937 VkRenderPassCreateInfo rpci = {
12938 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
12939 0, 2, attachments, 1, &subpass, 0, nullptr
12940 };
12941 VkRenderPass rp;
12942 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12943 ASSERT_VK_SUCCESS(err);
12944
12945 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
12946
12947 m_errorMonitor->VerifyFound();
12948
12949 vkDestroyRenderPass(m_device->device(), rp, nullptr);
12950}
12951
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012952TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012953 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
12954 "the TCS without the patch decoration, but consumed in the TES "
12955 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
12957 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120012958
12959 ASSERT_NO_FATAL_FAILURE(InitState());
12960 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12961
Chris Forbesc1e852d2016-04-04 19:26:42 +120012962 if (!m_device->phy().features().tessellationShader) {
12963 printf("Device does not support tessellation shaders; skipped.\n");
12964 return;
12965 }
12966
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012967 char const *vsSource = "#version 450\n"
12968 "void main(){}\n";
12969 char const *tcsSource = "#version 450\n"
12970 "layout(location=0) out int x[];\n"
12971 "layout(vertices=3) out;\n"
12972 "void main(){\n"
12973 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
12974 " gl_TessLevelInner[0] = 1;\n"
12975 " x[gl_InvocationID] = gl_InvocationID;\n"
12976 "}\n";
12977 char const *tesSource = "#version 450\n"
12978 "layout(triangles, equal_spacing, cw) in;\n"
12979 "layout(location=0) patch in int x;\n"
12980 "out gl_PerVertex { vec4 gl_Position; };\n"
12981 "void main(){\n"
12982 " gl_Position.xyz = gl_TessCoord;\n"
12983 " gl_Position.w = x;\n"
12984 "}\n";
12985 char const *fsSource = "#version 450\n"
12986 "layout(location=0) out vec4 color;\n"
12987 "void main(){\n"
12988 " color = vec4(1);\n"
12989 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120012990
12991 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12992 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
12993 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
12994 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12995
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012996 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
12997 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012998
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012999 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013000
13001 VkPipelineObj pipe(m_device);
13002 pipe.SetInputAssembly(&iasci);
13003 pipe.SetTessellation(&tsci);
13004 pipe.AddColorAttachment();
13005 pipe.AddShader(&vs);
13006 pipe.AddShader(&tcs);
13007 pipe.AddShader(&tes);
13008 pipe.AddShader(&fs);
13009
13010 VkDescriptorSetObj descriptorSet(m_device);
13011 descriptorSet.AppendDummy();
13012 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13013
13014 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13015
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013016 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013017}
13018
Karl Schultz6addd812016-02-02 17:17:23 -070013019TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013020 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13021 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13023 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013024
Chris Forbes280ba2c2015-06-12 11:16:41 +120013025 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013027
13028 /* Two binding descriptions for binding 0 */
13029 VkVertexInputBindingDescription input_bindings[2];
13030 memset(input_bindings, 0, sizeof(input_bindings));
13031
13032 VkVertexInputAttributeDescription input_attrib;
13033 memset(&input_attrib, 0, sizeof(input_attrib));
13034 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013036 char const *vsSource = "#version 450\n"
13037 "\n"
13038 "layout(location=0) in float x;\n" /* attrib provided float */
13039 "out gl_PerVertex {\n"
13040 " vec4 gl_Position;\n"
13041 "};\n"
13042 "void main(){\n"
13043 " gl_Position = vec4(x);\n"
13044 "}\n";
13045 char const *fsSource = "#version 450\n"
13046 "\n"
13047 "layout(location=0) out vec4 color;\n"
13048 "void main(){\n"
13049 " color = vec4(1);\n"
13050 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013051
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013052 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13053 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013054
13055 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013056 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013057 pipe.AddShader(&vs);
13058 pipe.AddShader(&fs);
13059
13060 pipe.AddVertexInputBindings(input_bindings, 2);
13061 pipe.AddVertexInputAttribs(&input_attrib, 1);
13062
Chris Forbes280ba2c2015-06-12 11:16:41 +120013063 VkDescriptorSetObj descriptorSet(m_device);
13064 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013065 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013066
Tony Barbour5781e8f2015-08-04 16:23:11 -060013067 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013068
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013069 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013070}
Chris Forbes8f68b562015-05-25 11:13:32 +120013071
Karl Schultz6addd812016-02-02 17:17:23 -070013072TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013073 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013074 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013076
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013077 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013078
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013079 char const *vsSource = "#version 450\n"
13080 "\n"
13081 "out gl_PerVertex {\n"
13082 " vec4 gl_Position;\n"
13083 "};\n"
13084 "void main(){\n"
13085 " gl_Position = vec4(1);\n"
13086 "}\n";
13087 char const *fsSource = "#version 450\n"
13088 "\n"
13089 "void main(){\n"
13090 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013091
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013092 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13093 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013094
13095 VkPipelineObj pipe(m_device);
13096 pipe.AddShader(&vs);
13097 pipe.AddShader(&fs);
13098
Chia-I Wu08accc62015-07-07 11:50:03 +080013099 /* set up CB 0, not written */
13100 pipe.AddColorAttachment();
13101 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013102
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013103 VkDescriptorSetObj descriptorSet(m_device);
13104 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013105 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013106
Tony Barbour5781e8f2015-08-04 16:23:11 -060013107 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013108
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013109 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013110}
13111
Karl Schultz6addd812016-02-02 17:17:23 -070013112TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013113 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013114 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013116 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013117
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013118 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013119
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013120 char const *vsSource = "#version 450\n"
13121 "\n"
13122 "out gl_PerVertex {\n"
13123 " vec4 gl_Position;\n"
13124 "};\n"
13125 "void main(){\n"
13126 " gl_Position = vec4(1);\n"
13127 "}\n";
13128 char const *fsSource = "#version 450\n"
13129 "\n"
13130 "layout(location=0) out vec4 x;\n"
13131 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13132 "void main(){\n"
13133 " x = vec4(1);\n"
13134 " y = vec4(1);\n"
13135 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013136
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013137 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13138 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013139
13140 VkPipelineObj pipe(m_device);
13141 pipe.AddShader(&vs);
13142 pipe.AddShader(&fs);
13143
Chia-I Wu08accc62015-07-07 11:50:03 +080013144 /* set up CB 0, not written */
13145 pipe.AddColorAttachment();
13146 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013147 /* FS writes CB 1, but we don't configure it */
13148
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013149 VkDescriptorSetObj descriptorSet(m_device);
13150 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013151 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013152
Tony Barbour5781e8f2015-08-04 16:23:11 -060013153 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013154
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013155 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013156}
13157
Karl Schultz6addd812016-02-02 17:17:23 -070013158TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013159 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013160 "type of an fragment shader output variable, and the format of the corresponding attachment");
13161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013162
Chris Forbesa36d69e2015-05-25 11:13:44 +120013163 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013164
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013165 char const *vsSource = "#version 450\n"
13166 "\n"
13167 "out gl_PerVertex {\n"
13168 " vec4 gl_Position;\n"
13169 "};\n"
13170 "void main(){\n"
13171 " gl_Position = vec4(1);\n"
13172 "}\n";
13173 char const *fsSource = "#version 450\n"
13174 "\n"
13175 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13176 "void main(){\n"
13177 " x = ivec4(1);\n"
13178 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013179
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013180 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13181 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013182
13183 VkPipelineObj pipe(m_device);
13184 pipe.AddShader(&vs);
13185 pipe.AddShader(&fs);
13186
Chia-I Wu08accc62015-07-07 11:50:03 +080013187 /* set up CB 0; type is UNORM by default */
13188 pipe.AddColorAttachment();
13189 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013190
Chris Forbesa36d69e2015-05-25 11:13:44 +120013191 VkDescriptorSetObj descriptorSet(m_device);
13192 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013193 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013194
Tony Barbour5781e8f2015-08-04 16:23:11 -060013195 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013196
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013197 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013198}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013199
Karl Schultz6addd812016-02-02 17:17:23 -070013200TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013201 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13202 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013204
Chris Forbes556c76c2015-08-14 12:04:59 +120013205 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013207 char const *vsSource = "#version 450\n"
13208 "\n"
13209 "out gl_PerVertex {\n"
13210 " vec4 gl_Position;\n"
13211 "};\n"
13212 "void main(){\n"
13213 " gl_Position = vec4(1);\n"
13214 "}\n";
13215 char const *fsSource = "#version 450\n"
13216 "\n"
13217 "layout(location=0) out vec4 x;\n"
13218 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13219 "void main(){\n"
13220 " x = vec4(bar.y);\n"
13221 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013222
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013223 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13224 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013225
Chris Forbes556c76c2015-08-14 12:04:59 +120013226 VkPipelineObj pipe(m_device);
13227 pipe.AddShader(&vs);
13228 pipe.AddShader(&fs);
13229
13230 /* set up CB 0; type is UNORM by default */
13231 pipe.AddColorAttachment();
13232 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13233
13234 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013235 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013236
13237 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13238
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013239 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013240}
13241
Chris Forbes5c59e902016-02-26 16:56:09 +130013242TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013243 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13244 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013246
13247 ASSERT_NO_FATAL_FAILURE(InitState());
13248
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013249 char const *vsSource = "#version 450\n"
13250 "\n"
13251 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13252 "out gl_PerVertex {\n"
13253 " vec4 gl_Position;\n"
13254 "};\n"
13255 "void main(){\n"
13256 " gl_Position = vec4(consts.x);\n"
13257 "}\n";
13258 char const *fsSource = "#version 450\n"
13259 "\n"
13260 "layout(location=0) out vec4 x;\n"
13261 "void main(){\n"
13262 " x = vec4(1);\n"
13263 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013264
13265 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13266 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13267
13268 VkPipelineObj pipe(m_device);
13269 pipe.AddShader(&vs);
13270 pipe.AddShader(&fs);
13271
13272 /* set up CB 0; type is UNORM by default */
13273 pipe.AddColorAttachment();
13274 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13275
13276 VkDescriptorSetObj descriptorSet(m_device);
13277 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13278
13279 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13280
13281 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013282 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013283}
13284
Chris Forbes3fb17902016-08-22 14:57:55 +120013285TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13286 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13287 "which is not included in the subpass description");
13288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13289 "consumes input attachment index 0 but not provided in subpass");
13290
13291 ASSERT_NO_FATAL_FAILURE(InitState());
13292
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013293 char const *vsSource = "#version 450\n"
13294 "\n"
13295 "out gl_PerVertex {\n"
13296 " vec4 gl_Position;\n"
13297 "};\n"
13298 "void main(){\n"
13299 " gl_Position = vec4(1);\n"
13300 "}\n";
13301 char const *fsSource = "#version 450\n"
13302 "\n"
13303 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13304 "layout(location=0) out vec4 color;\n"
13305 "void main() {\n"
13306 " color = subpassLoad(x);\n"
13307 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013308
13309 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13310 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13311
13312 VkPipelineObj pipe(m_device);
13313 pipe.AddShader(&vs);
13314 pipe.AddShader(&fs);
13315 pipe.AddColorAttachment();
13316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13317
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013318 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13319 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013320 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013321 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013322 ASSERT_VK_SUCCESS(err);
13323
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013324 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013325 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013326 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013327 ASSERT_VK_SUCCESS(err);
13328
13329 // error here.
13330 pipe.CreateVKPipeline(pl, renderPass());
13331
13332 m_errorMonitor->VerifyFound();
13333
13334 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13335 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13336}
13337
Chris Forbes5a9a0472016-08-22 16:02:09 +120013338TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13339 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13340 "with a format having a different fundamental type");
13341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13342 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13343
13344 ASSERT_NO_FATAL_FAILURE(InitState());
13345
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013346 char const *vsSource = "#version 450\n"
13347 "\n"
13348 "out gl_PerVertex {\n"
13349 " vec4 gl_Position;\n"
13350 "};\n"
13351 "void main(){\n"
13352 " gl_Position = vec4(1);\n"
13353 "}\n";
13354 char const *fsSource = "#version 450\n"
13355 "\n"
13356 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13357 "layout(location=0) out vec4 color;\n"
13358 "void main() {\n"
13359 " color = subpassLoad(x);\n"
13360 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013361
13362 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13363 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13364
13365 VkPipelineObj pipe(m_device);
13366 pipe.AddShader(&vs);
13367 pipe.AddShader(&fs);
13368 pipe.AddColorAttachment();
13369 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013371 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13372 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013373 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013374 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013375 ASSERT_VK_SUCCESS(err);
13376
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013377 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013378 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013379 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013380 ASSERT_VK_SUCCESS(err);
13381
13382 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013383 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13384 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13385 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13386 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13387 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 +120013388 };
13389 VkAttachmentReference color = {
13390 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13391 };
13392 VkAttachmentReference input = {
13393 1, VK_IMAGE_LAYOUT_GENERAL,
13394 };
13395
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013396 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013397
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013398 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013399 VkRenderPass rp;
13400 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13401 ASSERT_VK_SUCCESS(err);
13402
13403 // error here.
13404 pipe.CreateVKPipeline(pl, rp);
13405
13406 m_errorMonitor->VerifyFound();
13407
13408 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13409 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13410 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13411}
13412
Chris Forbes541f7b02016-08-22 15:30:27 +120013413TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13414 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13415 "which is not included in the subpass description -- array case");
13416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13417 "consumes input attachment index 1 but not provided in subpass");
13418
13419 ASSERT_NO_FATAL_FAILURE(InitState());
13420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013421 char const *vsSource = "#version 450\n"
13422 "\n"
13423 "out gl_PerVertex {\n"
13424 " vec4 gl_Position;\n"
13425 "};\n"
13426 "void main(){\n"
13427 " gl_Position = vec4(1);\n"
13428 "}\n";
13429 char const *fsSource = "#version 450\n"
13430 "\n"
13431 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13432 "layout(location=0) out vec4 color;\n"
13433 "void main() {\n"
13434 " color = subpassLoad(xs[1]);\n"
13435 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013436
13437 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13438 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13439
13440 VkPipelineObj pipe(m_device);
13441 pipe.AddShader(&vs);
13442 pipe.AddShader(&fs);
13443 pipe.AddColorAttachment();
13444 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13445
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013446 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13447 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013448 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013449 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013450 ASSERT_VK_SUCCESS(err);
13451
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013452 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013453 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013454 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013455 ASSERT_VK_SUCCESS(err);
13456
13457 // error here.
13458 pipe.CreateVKPipeline(pl, renderPass());
13459
13460 m_errorMonitor->VerifyFound();
13461
13462 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13463 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13464}
13465
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013466TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013467 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13468 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013470
13471 ASSERT_NO_FATAL_FAILURE(InitState());
13472
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013473 char const *csSource = "#version 450\n"
13474 "\n"
13475 "layout(local_size_x=1) in;\n"
13476 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13477 "void main(){\n"
13478 " x = vec4(1);\n"
13479 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013480
13481 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13482
13483 VkDescriptorSetObj descriptorSet(m_device);
13484 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13485
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013486 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13487 nullptr,
13488 0,
13489 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13490 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13491 descriptorSet.GetPipelineLayout(),
13492 VK_NULL_HANDLE,
13493 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013494
13495 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013496 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013497
13498 m_errorMonitor->VerifyFound();
13499
13500 if (err == VK_SUCCESS) {
13501 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13502 }
13503}
13504
Chris Forbes22a9b092016-07-19 14:34:05 +120013505TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013506 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13507 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13509 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013510
13511 ASSERT_NO_FATAL_FAILURE(InitState());
13512
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013513 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13514 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013515 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013516 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013517 ASSERT_VK_SUCCESS(err);
13518
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013519 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013520 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013521 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013522 ASSERT_VK_SUCCESS(err);
13523
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013524 char const *csSource = "#version 450\n"
13525 "\n"
13526 "layout(local_size_x=1) in;\n"
13527 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13528 "void main() {\n"
13529 " x.x = 1.0f;\n"
13530 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013531 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13532
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013533 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13534 nullptr,
13535 0,
13536 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13537 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13538 pl,
13539 VK_NULL_HANDLE,
13540 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013541
13542 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013543 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013544
13545 m_errorMonitor->VerifyFound();
13546
13547 if (err == VK_SUCCESS) {
13548 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13549 }
13550
13551 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13552 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13553}
13554
Chris Forbes50020592016-07-27 13:52:41 +120013555TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13556 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13557 "does not match the dimensionality declared in the shader");
13558
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013559 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 +120013560
13561 ASSERT_NO_FATAL_FAILURE(InitState());
13562 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13563
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013564 char const *vsSource = "#version 450\n"
13565 "\n"
13566 "out gl_PerVertex { vec4 gl_Position; };\n"
13567 "void main() { gl_Position = vec4(0); }\n";
13568 char const *fsSource = "#version 450\n"
13569 "\n"
13570 "layout(set=0, binding=0) uniform sampler3D s;\n"
13571 "layout(location=0) out vec4 color;\n"
13572 "void main() {\n"
13573 " color = texture(s, vec3(0));\n"
13574 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013575 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13576 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13577
13578 VkPipelineObj pipe(m_device);
13579 pipe.AddShader(&vs);
13580 pipe.AddShader(&fs);
13581 pipe.AddColorAttachment();
13582
13583 VkTextureObj texture(m_device, nullptr);
13584 VkSamplerObj sampler(m_device);
13585
13586 VkDescriptorSetObj descriptorSet(m_device);
13587 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13588 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13589
13590 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13591 ASSERT_VK_SUCCESS(err);
13592
13593 BeginCommandBuffer();
13594
13595 m_commandBuffer->BindPipeline(pipe);
13596 m_commandBuffer->BindDescriptorSet(descriptorSet);
13597
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013598 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013599 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013600 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013601 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13602
13603 // error produced here.
13604 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13605
13606 m_errorMonitor->VerifyFound();
13607
13608 EndCommandBuffer();
13609}
13610
Chris Forbes5533bfc2016-07-27 14:12:34 +120013611TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13612 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13613 "are consumed via singlesample images types in the shader, or vice versa.");
13614
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013616
13617 ASSERT_NO_FATAL_FAILURE(InitState());
13618 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13619
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013620 char const *vsSource = "#version 450\n"
13621 "\n"
13622 "out gl_PerVertex { vec4 gl_Position; };\n"
13623 "void main() { gl_Position = vec4(0); }\n";
13624 char const *fsSource = "#version 450\n"
13625 "\n"
13626 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13627 "layout(location=0) out vec4 color;\n"
13628 "void main() {\n"
13629 " color = texelFetch(s, ivec2(0), 0);\n"
13630 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013631 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13632 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13633
13634 VkPipelineObj pipe(m_device);
13635 pipe.AddShader(&vs);
13636 pipe.AddShader(&fs);
13637 pipe.AddColorAttachment();
13638
13639 VkTextureObj texture(m_device, nullptr);
13640 VkSamplerObj sampler(m_device);
13641
13642 VkDescriptorSetObj descriptorSet(m_device);
13643 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13644 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13645
13646 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13647 ASSERT_VK_SUCCESS(err);
13648
13649 BeginCommandBuffer();
13650
13651 m_commandBuffer->BindPipeline(pipe);
13652 m_commandBuffer->BindDescriptorSet(descriptorSet);
13653
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013654 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013655 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013656 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013657 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13658
13659 // error produced here.
13660 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13661
13662 m_errorMonitor->VerifyFound();
13663
13664 EndCommandBuffer();
13665}
13666
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013667#endif // SHADER_CHECKER_TESTS
13668
13669#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013670TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013672
13673 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013674
13675 // Create an image
13676 VkImage image;
13677
Karl Schultz6addd812016-02-02 17:17:23 -070013678 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13679 const int32_t tex_width = 32;
13680 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013681
13682 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013683 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13684 image_create_info.pNext = NULL;
13685 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13686 image_create_info.format = tex_format;
13687 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013688 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013689 image_create_info.extent.depth = 1;
13690 image_create_info.mipLevels = 1;
13691 image_create_info.arrayLayers = 1;
13692 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13693 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13694 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13695 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013696
13697 // Introduce error by sending down a bogus width extent
13698 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013699 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013700
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013701 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013702}
13703
Mark Youngc48c4c12016-04-11 14:26:49 -060013704TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13706 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013707
13708 ASSERT_NO_FATAL_FAILURE(InitState());
13709
13710 // Create an image
13711 VkImage image;
13712
13713 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13714 const int32_t tex_width = 32;
13715 const int32_t tex_height = 32;
13716
13717 VkImageCreateInfo image_create_info = {};
13718 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13719 image_create_info.pNext = NULL;
13720 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13721 image_create_info.format = tex_format;
13722 image_create_info.extent.width = tex_width;
13723 image_create_info.extent.height = tex_height;
13724 image_create_info.extent.depth = 1;
13725 image_create_info.mipLevels = 1;
13726 image_create_info.arrayLayers = 1;
13727 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13728 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13729 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13730 image_create_info.flags = 0;
13731
13732 // Introduce error by sending down a bogus width extent
13733 image_create_info.extent.width = 0;
13734 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13735
13736 m_errorMonitor->VerifyFound();
13737}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013738#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013739
Tobin Ehliscde08892015-09-22 10:11:37 -060013740#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070013741
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013742TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13743 TEST_DESCRIPTION("Create a render pass with an attachment description "
13744 "format set to VK_FORMAT_UNDEFINED");
13745
13746 ASSERT_NO_FATAL_FAILURE(InitState());
13747 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13748
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013750
13751 VkAttachmentReference color_attach = {};
13752 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13753 color_attach.attachment = 0;
13754 VkSubpassDescription subpass = {};
13755 subpass.colorAttachmentCount = 1;
13756 subpass.pColorAttachments = &color_attach;
13757
13758 VkRenderPassCreateInfo rpci = {};
13759 rpci.subpassCount = 1;
13760 rpci.pSubpasses = &subpass;
13761 rpci.attachmentCount = 1;
13762 VkAttachmentDescription attach_desc = {};
13763 attach_desc.format = VK_FORMAT_UNDEFINED;
13764 rpci.pAttachments = &attach_desc;
13765 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13766 VkRenderPass rp;
13767 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13768
13769 m_errorMonitor->VerifyFound();
13770
13771 if (result == VK_SUCCESS) {
13772 vkDestroyRenderPass(m_device->device(), rp, NULL);
13773 }
13774}
13775
Karl Schultz6addd812016-02-02 17:17:23 -070013776TEST_F(VkLayerTest, InvalidImageView) {
13777 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013778
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013780
Tobin Ehliscde08892015-09-22 10:11:37 -060013781 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013782
Mike Stroyana3082432015-09-25 13:39:21 -060013783 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013784 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013785
Karl Schultz6addd812016-02-02 17:17:23 -070013786 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13787 const int32_t tex_width = 32;
13788 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013789
13790 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013791 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13792 image_create_info.pNext = NULL;
13793 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13794 image_create_info.format = tex_format;
13795 image_create_info.extent.width = tex_width;
13796 image_create_info.extent.height = tex_height;
13797 image_create_info.extent.depth = 1;
13798 image_create_info.mipLevels = 1;
13799 image_create_info.arrayLayers = 1;
13800 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13801 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13802 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13803 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013804
Chia-I Wuf7458c52015-10-26 21:10:41 +080013805 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013806 ASSERT_VK_SUCCESS(err);
13807
13808 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013809 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13810 image_view_create_info.image = image;
13811 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13812 image_view_create_info.format = tex_format;
13813 image_view_create_info.subresourceRange.layerCount = 1;
13814 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13815 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013816 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013817
13818 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013819 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013820
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013821 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013822 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013823}
Mike Stroyana3082432015-09-25 13:39:21 -060013824
Mark Youngd339ba32016-05-30 13:28:35 -060013825TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13826 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013828 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013829
13830 ASSERT_NO_FATAL_FAILURE(InitState());
13831
13832 // Create an image and try to create a view with no memory backing the image
13833 VkImage image;
13834
13835 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13836 const int32_t tex_width = 32;
13837 const int32_t tex_height = 32;
13838
13839 VkImageCreateInfo image_create_info = {};
13840 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13841 image_create_info.pNext = NULL;
13842 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13843 image_create_info.format = tex_format;
13844 image_create_info.extent.width = tex_width;
13845 image_create_info.extent.height = tex_height;
13846 image_create_info.extent.depth = 1;
13847 image_create_info.mipLevels = 1;
13848 image_create_info.arrayLayers = 1;
13849 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13850 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13851 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13852 image_create_info.flags = 0;
13853
13854 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13855 ASSERT_VK_SUCCESS(err);
13856
13857 VkImageViewCreateInfo image_view_create_info = {};
13858 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13859 image_view_create_info.image = image;
13860 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13861 image_view_create_info.format = tex_format;
13862 image_view_create_info.subresourceRange.layerCount = 1;
13863 image_view_create_info.subresourceRange.baseMipLevel = 0;
13864 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013865 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013866
13867 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013868 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013869
13870 m_errorMonitor->VerifyFound();
13871 vkDestroyImage(m_device->device(), image, NULL);
13872 // If last error is success, it still created the view, so delete it.
13873 if (err == VK_SUCCESS) {
13874 vkDestroyImageView(m_device->device(), view, NULL);
13875 }
Mark Youngd339ba32016-05-30 13:28:35 -060013876}
13877
Karl Schultz6addd812016-02-02 17:17:23 -070013878TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013879 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013881 "formats must have ONLY the "
13882 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13884 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013885
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013886 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013887
Karl Schultz6addd812016-02-02 17:17:23 -070013888 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013889 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013890 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013891 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013892
13893 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013894 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013895 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013896 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13897 image_view_create_info.format = tex_format;
13898 image_view_create_info.subresourceRange.baseMipLevel = 0;
13899 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013900 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013901 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013902 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013903
13904 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013905 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013906
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013907 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013908}
13909
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013910TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013911 VkResult err;
13912 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013913
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13915 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013916
Mike Stroyana3082432015-09-25 13:39:21 -060013917 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013918
13919 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013920 VkImage srcImage;
13921 VkImage dstImage;
13922 VkDeviceMemory srcMem;
13923 VkDeviceMemory destMem;
13924 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013925
13926 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013927 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13928 image_create_info.pNext = NULL;
13929 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13930 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13931 image_create_info.extent.width = 32;
13932 image_create_info.extent.height = 32;
13933 image_create_info.extent.depth = 1;
13934 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013935 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070013936 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13937 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13938 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13939 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013940
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013941 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013942 ASSERT_VK_SUCCESS(err);
13943
Mark Lobodzinski867787a2016-10-14 11:49:55 -060013944 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013945 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013946 ASSERT_VK_SUCCESS(err);
13947
13948 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013949 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013950 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13951 memAlloc.pNext = NULL;
13952 memAlloc.allocationSize = 0;
13953 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013954
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060013955 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013956 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013957 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060013958 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013959 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013960 ASSERT_VK_SUCCESS(err);
13961
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013962 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013963 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013964 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013965 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013966 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013967 ASSERT_VK_SUCCESS(err);
13968
13969 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
13970 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013971 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013972 ASSERT_VK_SUCCESS(err);
13973
13974 BeginCommandBuffer();
13975 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013976 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060013977 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060013978 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013979 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060013980 copyRegion.srcOffset.x = 0;
13981 copyRegion.srcOffset.y = 0;
13982 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013983 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013984 copyRegion.dstSubresource.mipLevel = 0;
13985 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013986 // Introduce failure by forcing the dst layerCount to differ from src
13987 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013988 copyRegion.dstOffset.x = 0;
13989 copyRegion.dstOffset.y = 0;
13990 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013991 copyRegion.extent.width = 1;
13992 copyRegion.extent.height = 1;
13993 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013994 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060013995 EndCommandBuffer();
13996
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013997 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060013998
Chia-I Wuf7458c52015-10-26 21:10:41 +080013999 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014000 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014001 vkFreeMemory(m_device->device(), srcMem, NULL);
14002 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014003}
14004
Tony Barbourd6673642016-05-05 14:46:39 -060014005TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14006
14007 TEST_DESCRIPTION("Creating images with unsuported formats ");
14008
14009 ASSERT_NO_FATAL_FAILURE(InitState());
14010 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14011 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014012 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 -060014013 VK_IMAGE_TILING_OPTIMAL, 0);
14014 ASSERT_TRUE(image.initialized());
14015
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014016 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
14017 VkImageCreateInfo image_create_info;
14018 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14019 image_create_info.pNext = NULL;
14020 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14021 image_create_info.format = VK_FORMAT_UNDEFINED;
14022 image_create_info.extent.width = 32;
14023 image_create_info.extent.height = 32;
14024 image_create_info.extent.depth = 1;
14025 image_create_info.mipLevels = 1;
14026 image_create_info.arrayLayers = 1;
14027 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14028 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14029 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14030 image_create_info.flags = 0;
14031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14033 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014034
14035 VkImage localImage;
14036 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14037 m_errorMonitor->VerifyFound();
14038
Tony Barbourd6673642016-05-05 14:46:39 -060014039 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014040 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014041 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14042 VkFormat format = static_cast<VkFormat>(f);
14043 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014044 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014045 unsupported = format;
14046 break;
14047 }
14048 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014049
Tony Barbourd6673642016-05-05 14:46:39 -060014050 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014051 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014053
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014054 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014055 m_errorMonitor->VerifyFound();
14056 }
14057}
14058
14059TEST_F(VkLayerTest, ImageLayerViewTests) {
14060 VkResult ret;
14061 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14062
14063 ASSERT_NO_FATAL_FAILURE(InitState());
14064
14065 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014066 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 -060014067 VK_IMAGE_TILING_OPTIMAL, 0);
14068 ASSERT_TRUE(image.initialized());
14069
14070 VkImageView imgView;
14071 VkImageViewCreateInfo imgViewInfo = {};
14072 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14073 imgViewInfo.image = image.handle();
14074 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14075 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14076 imgViewInfo.subresourceRange.layerCount = 1;
14077 imgViewInfo.subresourceRange.baseMipLevel = 0;
14078 imgViewInfo.subresourceRange.levelCount = 1;
14079 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14080
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060014082 // View can't have baseMipLevel >= image's mipLevels - Expect
14083 // VIEW_CREATE_ERROR
14084 imgViewInfo.subresourceRange.baseMipLevel = 1;
14085 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14086 m_errorMonitor->VerifyFound();
14087 imgViewInfo.subresourceRange.baseMipLevel = 0;
14088
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014090 // View can't have baseArrayLayer >= image's arraySize - Expect
14091 // VIEW_CREATE_ERROR
14092 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14093 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14094 m_errorMonitor->VerifyFound();
14095 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14096
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14098 "pCreateInfo->subresourceRange."
14099 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014100 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14101 imgViewInfo.subresourceRange.levelCount = 0;
14102 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14103 m_errorMonitor->VerifyFound();
14104 imgViewInfo.subresourceRange.levelCount = 1;
14105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14107 "pCreateInfo->subresourceRange."
14108 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014109 m_errorMonitor->SetDesiredFailureMsg(
14110 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14111 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014112 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14113 imgViewInfo.subresourceRange.layerCount = 0;
14114 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14115 m_errorMonitor->VerifyFound();
14116 imgViewInfo.subresourceRange.layerCount = 1;
14117
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14120 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14121 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014122 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14123 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14124 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14125 m_errorMonitor->VerifyFound();
14126 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14129 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14130 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014131 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14132 // VIEW_CREATE_ERROR
14133 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14134 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14135 m_errorMonitor->VerifyFound();
14136 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14137
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14139 "differing formats but they must be "
14140 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014141 // TODO: Update framework to easily passing mutable flag into ImageObj init
14142 // For now just allowing image for this one test to not have memory bound
14143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14144 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014145 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14146 // VIEW_CREATE_ERROR
14147 VkImageCreateInfo mutImgInfo = image.create_info();
14148 VkImage mutImage;
14149 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014150 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014151 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14152 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14153 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14154 ASSERT_VK_SUCCESS(ret);
14155 imgViewInfo.image = mutImage;
14156 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14157 m_errorMonitor->VerifyFound();
14158 imgViewInfo.image = image.handle();
14159 vkDestroyImage(m_device->handle(), mutImage, NULL);
14160}
14161
14162TEST_F(VkLayerTest, MiscImageLayerTests) {
14163
14164 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14165
14166 ASSERT_NO_FATAL_FAILURE(InitState());
14167
14168 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014169 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 -060014170 VK_IMAGE_TILING_OPTIMAL, 0);
14171 ASSERT_TRUE(image.initialized());
14172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060014174 vk_testing::Buffer buffer;
14175 VkMemoryPropertyFlags reqs = 0;
14176 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14177 VkBufferImageCopy region = {};
14178 region.bufferRowLength = 128;
14179 region.bufferImageHeight = 128;
14180 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14181 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
14182 region.imageSubresource.layerCount = 0;
14183 region.imageExtent.height = 4;
14184 region.imageExtent.width = 4;
14185 region.imageExtent.depth = 1;
14186 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014187 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14188 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014189 m_errorMonitor->VerifyFound();
14190 region.imageSubresource.layerCount = 1;
14191
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014192 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14193 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14194 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
14196 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14197 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014198 m_errorMonitor->VerifyFound();
14199
14200 // BufferOffset must be a multiple of 4
14201 // Introduce failure by setting bufferOffset to a value not divisible by 4
14202 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
14204 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14205 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014206 m_errorMonitor->VerifyFound();
14207
14208 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14209 region.bufferOffset = 0;
14210 region.imageExtent.height = 128;
14211 region.imageExtent.width = 128;
14212 // Introduce failure by setting bufferRowLength > 0 but less than width
14213 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14215 "must be zero or greater-than-or-equal-to imageExtent.width");
14216 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14217 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014218 m_errorMonitor->VerifyFound();
14219
14220 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14221 region.bufferRowLength = 128;
14222 // Introduce failure by setting bufferRowHeight > 0 but less than height
14223 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14225 "must be zero or greater-than-or-equal-to imageExtent.height");
14226 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14227 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014228 m_errorMonitor->VerifyFound();
14229
14230 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
14232 "specify only COLOR or DEPTH or "
14233 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060014234 // Expect MISMATCHED_IMAGE_ASPECT
14235 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014236 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14237 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014238 m_errorMonitor->VerifyFound();
14239 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14240
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14242 "If the format of srcImage is a depth, stencil, depth stencil or "
14243 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014244 // Expect INVALID_FILTER
14245 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014246 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 -060014247 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014248 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 -060014249 VkImageBlit blitRegion = {};
14250 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14251 blitRegion.srcSubresource.baseArrayLayer = 0;
14252 blitRegion.srcSubresource.layerCount = 1;
14253 blitRegion.srcSubresource.mipLevel = 0;
14254 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14255 blitRegion.dstSubresource.baseArrayLayer = 0;
14256 blitRegion.dstSubresource.layerCount = 1;
14257 blitRegion.dstSubresource.mipLevel = 0;
14258
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014259 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14260 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014261 m_errorMonitor->VerifyFound();
14262
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014263 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14265 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14266 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014267 m_errorMonitor->VerifyFound();
14268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014270 VkImageMemoryBarrier img_barrier;
14271 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14272 img_barrier.pNext = NULL;
14273 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14274 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14275 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14276 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14277 img_barrier.image = image.handle();
14278 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14279 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14280 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14281 img_barrier.subresourceRange.baseArrayLayer = 0;
14282 img_barrier.subresourceRange.baseMipLevel = 0;
14283 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14284 img_barrier.subresourceRange.layerCount = 0;
14285 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014286 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14287 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014288 m_errorMonitor->VerifyFound();
14289 img_barrier.subresourceRange.layerCount = 1;
14290}
14291
14292TEST_F(VkLayerTest, ImageFormatLimits) {
14293
14294 TEST_DESCRIPTION("Exceed the limits of image format ");
14295
Cody Northropc31a84f2016-08-22 10:41:47 -060014296 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014298 VkImageCreateInfo image_create_info = {};
14299 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14300 image_create_info.pNext = NULL;
14301 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14302 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14303 image_create_info.extent.width = 32;
14304 image_create_info.extent.height = 32;
14305 image_create_info.extent.depth = 1;
14306 image_create_info.mipLevels = 1;
14307 image_create_info.arrayLayers = 1;
14308 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14309 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14310 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14311 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14312 image_create_info.flags = 0;
14313
14314 VkImage nullImg;
14315 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014316 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14317 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014318 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14319 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14320 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14321 m_errorMonitor->VerifyFound();
14322 image_create_info.extent.depth = 1;
14323
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014325 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14326 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14327 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14328 m_errorMonitor->VerifyFound();
14329 image_create_info.mipLevels = 1;
14330
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014332 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14333 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14334 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14335 m_errorMonitor->VerifyFound();
14336 image_create_info.arrayLayers = 1;
14337
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014339 int samples = imgFmtProps.sampleCounts >> 1;
14340 image_create_info.samples = (VkSampleCountFlagBits)samples;
14341 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14342 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14343 m_errorMonitor->VerifyFound();
14344 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14345
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14347 "VK_IMAGE_LAYOUT_UNDEFINED or "
14348 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014349 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14350 // Expect INVALID_LAYOUT
14351 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14352 m_errorMonitor->VerifyFound();
14353 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14354}
14355
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014356TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14357
14358 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014360
14361 ASSERT_NO_FATAL_FAILURE(InitState());
14362
14363 VkImageObj src_image(m_device);
14364 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14365 VkImageObj dst_image(m_device);
14366 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14367
14368 BeginCommandBuffer();
14369 VkImageCopy copy_region;
14370 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14371 copy_region.srcSubresource.mipLevel = 0;
14372 copy_region.srcSubresource.baseArrayLayer = 0;
14373 copy_region.srcSubresource.layerCount = 0;
14374 copy_region.srcOffset.x = 0;
14375 copy_region.srcOffset.y = 0;
14376 copy_region.srcOffset.z = 0;
14377 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14378 copy_region.dstSubresource.mipLevel = 0;
14379 copy_region.dstSubresource.baseArrayLayer = 0;
14380 copy_region.dstSubresource.layerCount = 0;
14381 copy_region.dstOffset.x = 0;
14382 copy_region.dstOffset.y = 0;
14383 copy_region.dstOffset.z = 0;
14384 copy_region.extent.width = 64;
14385 copy_region.extent.height = 64;
14386 copy_region.extent.depth = 1;
14387 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14388 &copy_region);
14389 EndCommandBuffer();
14390
14391 m_errorMonitor->VerifyFound();
14392}
14393
14394TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14395
14396 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014398
14399 ASSERT_NO_FATAL_FAILURE(InitState());
14400
14401 VkImageObj src_image(m_device);
14402 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14403 VkImageObj dst_image(m_device);
14404 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14405
14406 BeginCommandBuffer();
14407 VkImageCopy copy_region;
14408 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14409 copy_region.srcSubresource.mipLevel = 0;
14410 copy_region.srcSubresource.baseArrayLayer = 0;
14411 copy_region.srcSubresource.layerCount = 0;
14412 copy_region.srcOffset.x = 0;
14413 copy_region.srcOffset.y = 0;
14414 copy_region.srcOffset.z = 0;
14415 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14416 copy_region.dstSubresource.mipLevel = 0;
14417 copy_region.dstSubresource.baseArrayLayer = 0;
14418 copy_region.dstSubresource.layerCount = 0;
14419 copy_region.dstOffset.x = 0;
14420 copy_region.dstOffset.y = 0;
14421 copy_region.dstOffset.z = 0;
14422 copy_region.extent.width = 64;
14423 copy_region.extent.height = 64;
14424 copy_region.extent.depth = 1;
14425 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14426 &copy_region);
14427 EndCommandBuffer();
14428
14429 m_errorMonitor->VerifyFound();
14430}
14431
Karl Schultz6addd812016-02-02 17:17:23 -070014432TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014433 VkResult err;
14434 bool pass;
14435
14436 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14438 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014439
14440 ASSERT_NO_FATAL_FAILURE(InitState());
14441
14442 // Create two images of different types and try to copy between them
14443 VkImage srcImage;
14444 VkImage dstImage;
14445 VkDeviceMemory srcMem;
14446 VkDeviceMemory destMem;
14447 VkMemoryRequirements memReqs;
14448
14449 VkImageCreateInfo image_create_info = {};
14450 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14451 image_create_info.pNext = NULL;
14452 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14453 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14454 image_create_info.extent.width = 32;
14455 image_create_info.extent.height = 32;
14456 image_create_info.extent.depth = 1;
14457 image_create_info.mipLevels = 1;
14458 image_create_info.arrayLayers = 1;
14459 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14460 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14461 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14462 image_create_info.flags = 0;
14463
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014464 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014465 ASSERT_VK_SUCCESS(err);
14466
14467 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14468 // Introduce failure by creating second image with a different-sized format.
14469 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14470
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014471 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014472 ASSERT_VK_SUCCESS(err);
14473
14474 // Allocate memory
14475 VkMemoryAllocateInfo memAlloc = {};
14476 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14477 memAlloc.pNext = NULL;
14478 memAlloc.allocationSize = 0;
14479 memAlloc.memoryTypeIndex = 0;
14480
14481 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14482 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014483 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014484 ASSERT_TRUE(pass);
14485 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14486 ASSERT_VK_SUCCESS(err);
14487
14488 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14489 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014490 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014491 ASSERT_TRUE(pass);
14492 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14493 ASSERT_VK_SUCCESS(err);
14494
14495 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14496 ASSERT_VK_SUCCESS(err);
14497 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14498 ASSERT_VK_SUCCESS(err);
14499
14500 BeginCommandBuffer();
14501 VkImageCopy copyRegion;
14502 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14503 copyRegion.srcSubresource.mipLevel = 0;
14504 copyRegion.srcSubresource.baseArrayLayer = 0;
14505 copyRegion.srcSubresource.layerCount = 0;
14506 copyRegion.srcOffset.x = 0;
14507 copyRegion.srcOffset.y = 0;
14508 copyRegion.srcOffset.z = 0;
14509 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14510 copyRegion.dstSubresource.mipLevel = 0;
14511 copyRegion.dstSubresource.baseArrayLayer = 0;
14512 copyRegion.dstSubresource.layerCount = 0;
14513 copyRegion.dstOffset.x = 0;
14514 copyRegion.dstOffset.y = 0;
14515 copyRegion.dstOffset.z = 0;
14516 copyRegion.extent.width = 1;
14517 copyRegion.extent.height = 1;
14518 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014519 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014520 EndCommandBuffer();
14521
14522 m_errorMonitor->VerifyFound();
14523
14524 vkDestroyImage(m_device->device(), srcImage, NULL);
14525 vkDestroyImage(m_device->device(), dstImage, NULL);
14526 vkFreeMemory(m_device->device(), srcMem, NULL);
14527 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014528}
14529
Karl Schultz6addd812016-02-02 17:17:23 -070014530TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14531 VkResult err;
14532 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014533
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014534 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14536 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014537
Mike Stroyana3082432015-09-25 13:39:21 -060014538 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014539
14540 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014541 VkImage srcImage;
14542 VkImage dstImage;
14543 VkDeviceMemory srcMem;
14544 VkDeviceMemory destMem;
14545 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014546
14547 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014548 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14549 image_create_info.pNext = NULL;
14550 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14551 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14552 image_create_info.extent.width = 32;
14553 image_create_info.extent.height = 32;
14554 image_create_info.extent.depth = 1;
14555 image_create_info.mipLevels = 1;
14556 image_create_info.arrayLayers = 1;
14557 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14558 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14559 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14560 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014561
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014562 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014563 ASSERT_VK_SUCCESS(err);
14564
Karl Schultzbdb75952016-04-19 11:36:49 -060014565 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14566
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014567 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014568 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014569 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014570 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014571
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014572 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014573 ASSERT_VK_SUCCESS(err);
14574
14575 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014576 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014577 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14578 memAlloc.pNext = NULL;
14579 memAlloc.allocationSize = 0;
14580 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014581
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014582 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014583 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014584 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014585 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014586 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014587 ASSERT_VK_SUCCESS(err);
14588
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014589 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014590 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014591 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014592 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014593 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014594 ASSERT_VK_SUCCESS(err);
14595
14596 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14597 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014598 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014599 ASSERT_VK_SUCCESS(err);
14600
14601 BeginCommandBuffer();
14602 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014603 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014604 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014605 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014606 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014607 copyRegion.srcOffset.x = 0;
14608 copyRegion.srcOffset.y = 0;
14609 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014610 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014611 copyRegion.dstSubresource.mipLevel = 0;
14612 copyRegion.dstSubresource.baseArrayLayer = 0;
14613 copyRegion.dstSubresource.layerCount = 0;
14614 copyRegion.dstOffset.x = 0;
14615 copyRegion.dstOffset.y = 0;
14616 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014617 copyRegion.extent.width = 1;
14618 copyRegion.extent.height = 1;
14619 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014620 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014621 EndCommandBuffer();
14622
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014623 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014624
Chia-I Wuf7458c52015-10-26 21:10:41 +080014625 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014626 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014627 vkFreeMemory(m_device->device(), srcMem, NULL);
14628 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014629}
14630
Karl Schultz6addd812016-02-02 17:17:23 -070014631TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14632 VkResult err;
14633 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014634
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14636 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014637
Mike Stroyana3082432015-09-25 13:39:21 -060014638 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014639
14640 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014641 VkImage srcImage;
14642 VkImage dstImage;
14643 VkDeviceMemory srcMem;
14644 VkDeviceMemory destMem;
14645 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014646
14647 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014648 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14649 image_create_info.pNext = NULL;
14650 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14651 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14652 image_create_info.extent.width = 32;
14653 image_create_info.extent.height = 1;
14654 image_create_info.extent.depth = 1;
14655 image_create_info.mipLevels = 1;
14656 image_create_info.arrayLayers = 1;
14657 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14658 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14659 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14660 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014661
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014662 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014663 ASSERT_VK_SUCCESS(err);
14664
Karl Schultz6addd812016-02-02 17:17:23 -070014665 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014666
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014667 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014668 ASSERT_VK_SUCCESS(err);
14669
14670 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014671 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014672 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14673 memAlloc.pNext = NULL;
14674 memAlloc.allocationSize = 0;
14675 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014676
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014677 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014678 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014679 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014680 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014681 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014682 ASSERT_VK_SUCCESS(err);
14683
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014684 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014685 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014686 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014687 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014688 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014689 ASSERT_VK_SUCCESS(err);
14690
14691 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14692 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014693 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014694 ASSERT_VK_SUCCESS(err);
14695
14696 BeginCommandBuffer();
14697 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014698 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14699 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014700 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014701 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014702 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014703 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014704 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014705 resolveRegion.srcOffset.x = 0;
14706 resolveRegion.srcOffset.y = 0;
14707 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014708 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014709 resolveRegion.dstSubresource.mipLevel = 0;
14710 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014711 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014712 resolveRegion.dstOffset.x = 0;
14713 resolveRegion.dstOffset.y = 0;
14714 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014715 resolveRegion.extent.width = 1;
14716 resolveRegion.extent.height = 1;
14717 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014718 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014719 EndCommandBuffer();
14720
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014721 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014722
Chia-I Wuf7458c52015-10-26 21:10:41 +080014723 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014724 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014725 vkFreeMemory(m_device->device(), srcMem, NULL);
14726 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014727}
14728
Karl Schultz6addd812016-02-02 17:17:23 -070014729TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14730 VkResult err;
14731 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014732
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14734 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014735
Mike Stroyana3082432015-09-25 13:39:21 -060014736 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014737
Chris Forbesa7530692016-05-08 12:35:39 +120014738 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014739 VkImage srcImage;
14740 VkImage dstImage;
14741 VkDeviceMemory srcMem;
14742 VkDeviceMemory destMem;
14743 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014744
14745 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014746 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14747 image_create_info.pNext = NULL;
14748 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14749 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14750 image_create_info.extent.width = 32;
14751 image_create_info.extent.height = 1;
14752 image_create_info.extent.depth = 1;
14753 image_create_info.mipLevels = 1;
14754 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014755 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014756 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14757 // Note: Some implementations expect color attachment usage for any
14758 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014759 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014760 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014761
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014762 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014763 ASSERT_VK_SUCCESS(err);
14764
Karl Schultz6addd812016-02-02 17:17:23 -070014765 // Note: Some implementations expect color attachment usage for any
14766 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014767 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014768
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014769 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014770 ASSERT_VK_SUCCESS(err);
14771
14772 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014773 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014774 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14775 memAlloc.pNext = NULL;
14776 memAlloc.allocationSize = 0;
14777 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014778
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014779 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014780 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014781 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014782 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014783 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014784 ASSERT_VK_SUCCESS(err);
14785
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014786 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014787 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014788 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014789 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014790 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014791 ASSERT_VK_SUCCESS(err);
14792
14793 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14794 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014795 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014796 ASSERT_VK_SUCCESS(err);
14797
14798 BeginCommandBuffer();
14799 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014800 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14801 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014802 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014803 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014804 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014805 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014806 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014807 resolveRegion.srcOffset.x = 0;
14808 resolveRegion.srcOffset.y = 0;
14809 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014810 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014811 resolveRegion.dstSubresource.mipLevel = 0;
14812 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014813 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014814 resolveRegion.dstOffset.x = 0;
14815 resolveRegion.dstOffset.y = 0;
14816 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014817 resolveRegion.extent.width = 1;
14818 resolveRegion.extent.height = 1;
14819 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014820 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014821 EndCommandBuffer();
14822
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014823 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014824
Chia-I Wuf7458c52015-10-26 21:10:41 +080014825 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014826 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014827 vkFreeMemory(m_device->device(), srcMem, NULL);
14828 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014829}
14830
Karl Schultz6addd812016-02-02 17:17:23 -070014831TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14832 VkResult err;
14833 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014834
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14836 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014837
Mike Stroyana3082432015-09-25 13:39:21 -060014838 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014839
14840 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014841 VkImage srcImage;
14842 VkImage dstImage;
14843 VkDeviceMemory srcMem;
14844 VkDeviceMemory destMem;
14845 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014846
14847 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014848 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14849 image_create_info.pNext = NULL;
14850 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14851 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14852 image_create_info.extent.width = 32;
14853 image_create_info.extent.height = 1;
14854 image_create_info.extent.depth = 1;
14855 image_create_info.mipLevels = 1;
14856 image_create_info.arrayLayers = 1;
14857 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14858 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14859 // Note: Some implementations expect color attachment usage for any
14860 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014861 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014862 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014863
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014864 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014865 ASSERT_VK_SUCCESS(err);
14866
Karl Schultz6addd812016-02-02 17:17:23 -070014867 // Set format to something other than source image
14868 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14869 // Note: Some implementations expect color attachment usage for any
14870 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014871 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014872 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014873
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014874 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014875 ASSERT_VK_SUCCESS(err);
14876
14877 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014878 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014879 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14880 memAlloc.pNext = NULL;
14881 memAlloc.allocationSize = 0;
14882 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014883
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014884 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014885 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014886 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014887 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014888 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014889 ASSERT_VK_SUCCESS(err);
14890
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014891 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014892 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014893 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014894 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014895 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014896 ASSERT_VK_SUCCESS(err);
14897
14898 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14899 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014900 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014901 ASSERT_VK_SUCCESS(err);
14902
14903 BeginCommandBuffer();
14904 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014905 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14906 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014907 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014908 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014909 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014910 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014911 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014912 resolveRegion.srcOffset.x = 0;
14913 resolveRegion.srcOffset.y = 0;
14914 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014915 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014916 resolveRegion.dstSubresource.mipLevel = 0;
14917 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014918 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014919 resolveRegion.dstOffset.x = 0;
14920 resolveRegion.dstOffset.y = 0;
14921 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014922 resolveRegion.extent.width = 1;
14923 resolveRegion.extent.height = 1;
14924 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014925 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014926 EndCommandBuffer();
14927
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014928 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014929
Chia-I Wuf7458c52015-10-26 21:10:41 +080014930 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014931 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014932 vkFreeMemory(m_device->device(), srcMem, NULL);
14933 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014934}
14935
Karl Schultz6addd812016-02-02 17:17:23 -070014936TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
14937 VkResult err;
14938 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014939
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14941 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014942
Mike Stroyana3082432015-09-25 13:39:21 -060014943 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014944
14945 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014946 VkImage srcImage;
14947 VkImage dstImage;
14948 VkDeviceMemory srcMem;
14949 VkDeviceMemory destMem;
14950 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014951
14952 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014953 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14954 image_create_info.pNext = NULL;
14955 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14956 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14957 image_create_info.extent.width = 32;
14958 image_create_info.extent.height = 1;
14959 image_create_info.extent.depth = 1;
14960 image_create_info.mipLevels = 1;
14961 image_create_info.arrayLayers = 1;
14962 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14963 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14964 // Note: Some implementations expect color attachment usage for any
14965 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014966 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014967 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014968
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014969 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014970 ASSERT_VK_SUCCESS(err);
14971
Karl Schultz6addd812016-02-02 17:17:23 -070014972 image_create_info.imageType = VK_IMAGE_TYPE_1D;
14973 // Note: Some implementations expect color attachment usage for any
14974 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014975 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014976 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014977
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014978 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014979 ASSERT_VK_SUCCESS(err);
14980
14981 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014982 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014983 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14984 memAlloc.pNext = NULL;
14985 memAlloc.allocationSize = 0;
14986 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014987
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014988 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014989 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014990 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014991 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014992 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014993 ASSERT_VK_SUCCESS(err);
14994
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014995 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014996 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014997 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014998 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014999 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015000 ASSERT_VK_SUCCESS(err);
15001
15002 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15003 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015004 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015005 ASSERT_VK_SUCCESS(err);
15006
15007 BeginCommandBuffer();
15008 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015009 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15010 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015011 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015012 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015013 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015014 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015015 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015016 resolveRegion.srcOffset.x = 0;
15017 resolveRegion.srcOffset.y = 0;
15018 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015019 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015020 resolveRegion.dstSubresource.mipLevel = 0;
15021 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015022 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015023 resolveRegion.dstOffset.x = 0;
15024 resolveRegion.dstOffset.y = 0;
15025 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015026 resolveRegion.extent.width = 1;
15027 resolveRegion.extent.height = 1;
15028 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015029 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015030 EndCommandBuffer();
15031
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015032 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015033
Chia-I Wuf7458c52015-10-26 21:10:41 +080015034 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015035 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015036 vkFreeMemory(m_device->device(), srcMem, NULL);
15037 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015038}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015039
Karl Schultz6addd812016-02-02 17:17:23 -070015040TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015041 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015042 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15043 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015044 // The image format check comes 2nd in validation so we trigger it first,
15045 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015046 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015047
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15049 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015050
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015051 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015052
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015053 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015054 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15055 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015056
15057 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015058 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15059 ds_pool_ci.pNext = NULL;
15060 ds_pool_ci.maxSets = 1;
15061 ds_pool_ci.poolSizeCount = 1;
15062 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015063
15064 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015065 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015066 ASSERT_VK_SUCCESS(err);
15067
15068 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015069 dsl_binding.binding = 0;
15070 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15071 dsl_binding.descriptorCount = 1;
15072 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15073 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015074
15075 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015076 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15077 ds_layout_ci.pNext = NULL;
15078 ds_layout_ci.bindingCount = 1;
15079 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015080 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015081 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015082 ASSERT_VK_SUCCESS(err);
15083
15084 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015085 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015086 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015087 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015088 alloc_info.descriptorPool = ds_pool;
15089 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015090 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015091 ASSERT_VK_SUCCESS(err);
15092
Karl Schultz6addd812016-02-02 17:17:23 -070015093 VkImage image_bad;
15094 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015095 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015096 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015097 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015098 const int32_t tex_width = 32;
15099 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015100
15101 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015102 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15103 image_create_info.pNext = NULL;
15104 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15105 image_create_info.format = tex_format_bad;
15106 image_create_info.extent.width = tex_width;
15107 image_create_info.extent.height = tex_height;
15108 image_create_info.extent.depth = 1;
15109 image_create_info.mipLevels = 1;
15110 image_create_info.arrayLayers = 1;
15111 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15112 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015113 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015114 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015116 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015117 ASSERT_VK_SUCCESS(err);
15118 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015119 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15120 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015121 ASSERT_VK_SUCCESS(err);
15122
15123 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015124 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15125 image_view_create_info.image = image_bad;
15126 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15127 image_view_create_info.format = tex_format_bad;
15128 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15129 image_view_create_info.subresourceRange.baseMipLevel = 0;
15130 image_view_create_info.subresourceRange.layerCount = 1;
15131 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015132 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015133
15134 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015135 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015136
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015137 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015138
Chia-I Wuf7458c52015-10-26 21:10:41 +080015139 vkDestroyImage(m_device->device(), image_bad, NULL);
15140 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015141 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15142 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015143}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015144
15145TEST_F(VkLayerTest, ClearImageErrors) {
15146 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15147 "ClearDepthStencilImage with a color image.");
15148
15149 ASSERT_NO_FATAL_FAILURE(InitState());
15150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15151
15152 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15153 BeginCommandBuffer();
15154 m_commandBuffer->EndRenderPass();
15155
15156 // Color image
15157 VkClearColorValue clear_color;
15158 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15159 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15160 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15161 const int32_t img_width = 32;
15162 const int32_t img_height = 32;
15163 VkImageCreateInfo image_create_info = {};
15164 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15165 image_create_info.pNext = NULL;
15166 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15167 image_create_info.format = color_format;
15168 image_create_info.extent.width = img_width;
15169 image_create_info.extent.height = img_height;
15170 image_create_info.extent.depth = 1;
15171 image_create_info.mipLevels = 1;
15172 image_create_info.arrayLayers = 1;
15173 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15174 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15175 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15176
15177 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015178 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015179
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015180 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015181
15182 // Depth/Stencil image
15183 VkClearDepthStencilValue clear_value = {0};
15184 reqs = 0; // don't need HOST_VISIBLE DS image
15185 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15186 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15187 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15188 ds_image_create_info.extent.width = 64;
15189 ds_image_create_info.extent.height = 64;
15190 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15191 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15192
15193 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015194 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015195
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015196 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 -060015197
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015199
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015200 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015201 &color_range);
15202
15203 m_errorMonitor->VerifyFound();
15204
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15206 "image created without "
15207 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015208
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015209 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015210 &color_range);
15211
15212 m_errorMonitor->VerifyFound();
15213
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015214 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15216 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015217
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015218 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15219 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015220
15221 m_errorMonitor->VerifyFound();
15222}
Tobin Ehliscde08892015-09-22 10:11:37 -060015223#endif // IMAGE_TESTS
15224
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015225
15226// WSI Enabled Tests
15227//
Chris Forbes09368e42016-10-13 11:59:22 +130015228#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015229TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15230
15231#if defined(VK_USE_PLATFORM_XCB_KHR)
15232 VkSurfaceKHR surface = VK_NULL_HANDLE;
15233
15234 VkResult err;
15235 bool pass;
15236 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15237 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15238 // uint32_t swapchain_image_count = 0;
15239 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15240 // uint32_t image_index = 0;
15241 // VkPresentInfoKHR present_info = {};
15242
15243 ASSERT_NO_FATAL_FAILURE(InitState());
15244
15245 // Use the create function from one of the VK_KHR_*_surface extension in
15246 // order to create a surface, testing all known errors in the process,
15247 // before successfully creating a surface:
15248 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15250 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15251 pass = (err != VK_SUCCESS);
15252 ASSERT_TRUE(pass);
15253 m_errorMonitor->VerifyFound();
15254
15255 // Next, try to create a surface with the wrong
15256 // VkXcbSurfaceCreateInfoKHR::sType:
15257 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15258 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15260 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15261 pass = (err != VK_SUCCESS);
15262 ASSERT_TRUE(pass);
15263 m_errorMonitor->VerifyFound();
15264
15265 // Create a native window, and then correctly create a surface:
15266 xcb_connection_t *connection;
15267 xcb_screen_t *screen;
15268 xcb_window_t xcb_window;
15269 xcb_intern_atom_reply_t *atom_wm_delete_window;
15270
15271 const xcb_setup_t *setup;
15272 xcb_screen_iterator_t iter;
15273 int scr;
15274 uint32_t value_mask, value_list[32];
15275 int width = 1;
15276 int height = 1;
15277
15278 connection = xcb_connect(NULL, &scr);
15279 ASSERT_TRUE(connection != NULL);
15280 setup = xcb_get_setup(connection);
15281 iter = xcb_setup_roots_iterator(setup);
15282 while (scr-- > 0)
15283 xcb_screen_next(&iter);
15284 screen = iter.data;
15285
15286 xcb_window = xcb_generate_id(connection);
15287
15288 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15289 value_list[0] = screen->black_pixel;
15290 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15291
15292 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15293 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15294
15295 /* Magic code that will send notification when window is destroyed */
15296 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15297 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15298
15299 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15300 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15301 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15302 free(reply);
15303
15304 xcb_map_window(connection, xcb_window);
15305
15306 // Force the x/y coordinates to 100,100 results are identical in consecutive
15307 // runs
15308 const uint32_t coords[] = { 100, 100 };
15309 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15310
15311 // Finally, try to correctly create a surface:
15312 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15313 xcb_create_info.pNext = NULL;
15314 xcb_create_info.flags = 0;
15315 xcb_create_info.connection = connection;
15316 xcb_create_info.window = xcb_window;
15317 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15318 pass = (err == VK_SUCCESS);
15319 ASSERT_TRUE(pass);
15320
15321 // Check if surface supports presentation:
15322
15323 // 1st, do so without having queried the queue families:
15324 VkBool32 supported = false;
15325 // TODO: Get the following error to come out:
15326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15327 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15328 "function");
15329 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15330 pass = (err != VK_SUCCESS);
15331 // ASSERT_TRUE(pass);
15332 // m_errorMonitor->VerifyFound();
15333
15334 // Next, query a queue family index that's too large:
15335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15336 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15337 pass = (err != VK_SUCCESS);
15338 ASSERT_TRUE(pass);
15339 m_errorMonitor->VerifyFound();
15340
15341 // Finally, do so correctly:
15342 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15343 // SUPPORTED
15344 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15345 pass = (err == VK_SUCCESS);
15346 ASSERT_TRUE(pass);
15347
15348 // Before proceeding, try to create a swapchain without having called
15349 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15350 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15351 swapchain_create_info.pNext = NULL;
15352 swapchain_create_info.flags = 0;
15353 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15354 swapchain_create_info.surface = surface;
15355 swapchain_create_info.imageArrayLayers = 1;
15356 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15357 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15359 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15360 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15361 pass = (err != VK_SUCCESS);
15362 ASSERT_TRUE(pass);
15363 m_errorMonitor->VerifyFound();
15364
15365 // Get the surface capabilities:
15366 VkSurfaceCapabilitiesKHR surface_capabilities;
15367
15368 // Do so correctly (only error logged by this entrypoint is if the
15369 // extension isn't enabled):
15370 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15371 pass = (err == VK_SUCCESS);
15372 ASSERT_TRUE(pass);
15373
15374 // Get the surface formats:
15375 uint32_t surface_format_count;
15376
15377 // First, try without a pointer to surface_format_count:
15378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15379 "specified as NULL");
15380 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15381 pass = (err == VK_SUCCESS);
15382 ASSERT_TRUE(pass);
15383 m_errorMonitor->VerifyFound();
15384
15385 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15386 // correctly done a 1st try (to get the count):
15387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15388 surface_format_count = 0;
15389 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15390 pass = (err == VK_SUCCESS);
15391 ASSERT_TRUE(pass);
15392 m_errorMonitor->VerifyFound();
15393
15394 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15395 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15396 pass = (err == VK_SUCCESS);
15397 ASSERT_TRUE(pass);
15398
15399 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15400 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15401
15402 // Next, do a 2nd try with surface_format_count being set too high:
15403 surface_format_count += 5;
15404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15405 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15406 pass = (err == VK_SUCCESS);
15407 ASSERT_TRUE(pass);
15408 m_errorMonitor->VerifyFound();
15409
15410 // Finally, do a correct 1st and 2nd try:
15411 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15412 pass = (err == VK_SUCCESS);
15413 ASSERT_TRUE(pass);
15414 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15415 pass = (err == VK_SUCCESS);
15416 ASSERT_TRUE(pass);
15417
15418 // Get the surface present modes:
15419 uint32_t surface_present_mode_count;
15420
15421 // First, try without a pointer to surface_format_count:
15422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15423 "specified as NULL");
15424
15425 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15426 pass = (err == VK_SUCCESS);
15427 ASSERT_TRUE(pass);
15428 m_errorMonitor->VerifyFound();
15429
15430 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15431 // correctly done a 1st try (to get the count):
15432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15433 surface_present_mode_count = 0;
15434 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15435 (VkPresentModeKHR *)&surface_present_mode_count);
15436 pass = (err == VK_SUCCESS);
15437 ASSERT_TRUE(pass);
15438 m_errorMonitor->VerifyFound();
15439
15440 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15441 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15442 pass = (err == VK_SUCCESS);
15443 ASSERT_TRUE(pass);
15444
15445 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15446 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15447
15448 // Next, do a 2nd try with surface_format_count being set too high:
15449 surface_present_mode_count += 5;
15450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15451 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15452 pass = (err == VK_SUCCESS);
15453 ASSERT_TRUE(pass);
15454 m_errorMonitor->VerifyFound();
15455
15456 // Finally, do a correct 1st and 2nd try:
15457 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15458 pass = (err == VK_SUCCESS);
15459 ASSERT_TRUE(pass);
15460 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15461 pass = (err == VK_SUCCESS);
15462 ASSERT_TRUE(pass);
15463
15464 // Create a swapchain:
15465
15466 // First, try without a pointer to swapchain_create_info:
15467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15468 "specified as NULL");
15469
15470 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15471 pass = (err != VK_SUCCESS);
15472 ASSERT_TRUE(pass);
15473 m_errorMonitor->VerifyFound();
15474
15475 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15476 // sType:
15477 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15479
15480 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15481 pass = (err != VK_SUCCESS);
15482 ASSERT_TRUE(pass);
15483 m_errorMonitor->VerifyFound();
15484
15485 // Next, call with a NULL swapchain pointer:
15486 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15487 swapchain_create_info.pNext = NULL;
15488 swapchain_create_info.flags = 0;
15489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15490 "specified as NULL");
15491
15492 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15493 pass = (err != VK_SUCCESS);
15494 ASSERT_TRUE(pass);
15495 m_errorMonitor->VerifyFound();
15496
15497 // TODO: Enhance swapchain layer so that
15498 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15499
15500 // Next, call with a queue family index that's too large:
15501 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15502 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15503 swapchain_create_info.queueFamilyIndexCount = 2;
15504 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15506 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15507 pass = (err != VK_SUCCESS);
15508 ASSERT_TRUE(pass);
15509 m_errorMonitor->VerifyFound();
15510
15511 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15512 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15513 swapchain_create_info.queueFamilyIndexCount = 1;
15514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15515 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15516 "pCreateInfo->pQueueFamilyIndices).");
15517 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15518 pass = (err != VK_SUCCESS);
15519 ASSERT_TRUE(pass);
15520 m_errorMonitor->VerifyFound();
15521
15522 // Next, call with an invalid imageSharingMode:
15523 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15524 swapchain_create_info.queueFamilyIndexCount = 1;
15525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15526 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15527 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15528 pass = (err != VK_SUCCESS);
15529 ASSERT_TRUE(pass);
15530 m_errorMonitor->VerifyFound();
15531 // Fix for the future:
15532 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15533 // SUPPORTED
15534 swapchain_create_info.queueFamilyIndexCount = 0;
15535 queueFamilyIndex[0] = 0;
15536 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15537
15538 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15539 // Get the images from a swapchain:
15540 // Acquire an image from a swapchain:
15541 // Present an image to a swapchain:
15542 // Destroy the swapchain:
15543
15544 // TODOs:
15545 //
15546 // - Try destroying the device without first destroying the swapchain
15547 //
15548 // - Try destroying the device without first destroying the surface
15549 //
15550 // - Try destroying the surface without first destroying the swapchain
15551
15552 // Destroy the surface:
15553 vkDestroySurfaceKHR(instance(), surface, NULL);
15554
15555 // Tear down the window:
15556 xcb_destroy_window(connection, xcb_window);
15557 xcb_disconnect(connection);
15558
15559#else // VK_USE_PLATFORM_XCB_KHR
15560 return;
15561#endif // VK_USE_PLATFORM_XCB_KHR
15562}
Chris Forbes09368e42016-10-13 11:59:22 +130015563#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015564
15565//
15566// POSITIVE VALIDATION TESTS
15567//
15568// These tests do not expect to encounter ANY validation errors pass only if this is true
15569
Tobin Ehlise0006882016-11-03 10:14:28 -060015570TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15571 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15572 "by a transition in the primary.");
15573 VkResult err;
15574 m_errorMonitor->ExpectSuccess();
15575 ASSERT_NO_FATAL_FAILURE(InitState());
15576 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15577 // Allocate a secondary and primary cmd buffer
15578 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15579 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15580 command_buffer_allocate_info.commandPool = m_commandPool;
15581 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15582 command_buffer_allocate_info.commandBufferCount = 1;
15583
15584 VkCommandBuffer secondary_command_buffer;
15585 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15586 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15587 VkCommandBuffer primary_command_buffer;
15588 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15589 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15590 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15591 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15592 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15593 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15594 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15595
15596 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15597 ASSERT_VK_SUCCESS(err);
15598 VkImageObj image(m_device);
15599 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15600 ASSERT_TRUE(image.initialized());
15601 VkImageMemoryBarrier img_barrier = {};
15602 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15603 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15604 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15605 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15606 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15607 img_barrier.image = image.handle();
15608 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15609 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15610 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15611 img_barrier.subresourceRange.baseArrayLayer = 0;
15612 img_barrier.subresourceRange.baseMipLevel = 0;
15613 img_barrier.subresourceRange.layerCount = 1;
15614 img_barrier.subresourceRange.levelCount = 1;
15615 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15616 0, nullptr, 1, &img_barrier);
15617 err = vkEndCommandBuffer(secondary_command_buffer);
15618 ASSERT_VK_SUCCESS(err);
15619
15620 // Now update primary cmd buffer to execute secondary and transitions image
15621 command_buffer_begin_info.pInheritanceInfo = nullptr;
15622 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15623 ASSERT_VK_SUCCESS(err);
15624 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15625 VkImageMemoryBarrier img_barrier2 = {};
15626 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15627 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15628 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15629 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15630 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15631 img_barrier2.image = image.handle();
15632 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15633 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15634 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15635 img_barrier2.subresourceRange.baseArrayLayer = 0;
15636 img_barrier2.subresourceRange.baseMipLevel = 0;
15637 img_barrier2.subresourceRange.layerCount = 1;
15638 img_barrier2.subresourceRange.levelCount = 1;
15639 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15640 nullptr, 1, &img_barrier2);
15641 err = vkEndCommandBuffer(primary_command_buffer);
15642 ASSERT_VK_SUCCESS(err);
15643 VkSubmitInfo submit_info = {};
15644 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15645 submit_info.commandBufferCount = 1;
15646 submit_info.pCommandBuffers = &primary_command_buffer;
15647 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15648 ASSERT_VK_SUCCESS(err);
15649 m_errorMonitor->VerifyNotFound();
15650 err = vkDeviceWaitIdle(m_device->device());
15651 ASSERT_VK_SUCCESS(err);
15652 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15653 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15654}
15655
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015656// This is a positive test. No failures are expected.
15657TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15658 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15659 "is ignoring VkWriteDescriptorSet members that are not "
15660 "related to the descriptor type specified by "
15661 "VkWriteDescriptorSet::descriptorType. Correct "
15662 "validation behavior will result in the test running to "
15663 "completion without validation errors.");
15664
15665 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15666
15667 ASSERT_NO_FATAL_FAILURE(InitState());
15668
15669 // Image Case
15670 {
15671 m_errorMonitor->ExpectSuccess();
15672
15673 VkImage image;
15674 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15675 const int32_t tex_width = 32;
15676 const int32_t tex_height = 32;
15677 VkImageCreateInfo image_create_info = {};
15678 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15679 image_create_info.pNext = NULL;
15680 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15681 image_create_info.format = tex_format;
15682 image_create_info.extent.width = tex_width;
15683 image_create_info.extent.height = tex_height;
15684 image_create_info.extent.depth = 1;
15685 image_create_info.mipLevels = 1;
15686 image_create_info.arrayLayers = 1;
15687 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15688 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15689 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15690 image_create_info.flags = 0;
15691 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15692 ASSERT_VK_SUCCESS(err);
15693
15694 VkMemoryRequirements memory_reqs;
15695 VkDeviceMemory image_memory;
15696 bool pass;
15697 VkMemoryAllocateInfo memory_info = {};
15698 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15699 memory_info.pNext = NULL;
15700 memory_info.allocationSize = 0;
15701 memory_info.memoryTypeIndex = 0;
15702 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15703 memory_info.allocationSize = memory_reqs.size;
15704 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15705 ASSERT_TRUE(pass);
15706 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15707 ASSERT_VK_SUCCESS(err);
15708 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15709 ASSERT_VK_SUCCESS(err);
15710
15711 VkImageViewCreateInfo image_view_create_info = {};
15712 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15713 image_view_create_info.image = image;
15714 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15715 image_view_create_info.format = tex_format;
15716 image_view_create_info.subresourceRange.layerCount = 1;
15717 image_view_create_info.subresourceRange.baseMipLevel = 0;
15718 image_view_create_info.subresourceRange.levelCount = 1;
15719 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15720
15721 VkImageView view;
15722 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15723 ASSERT_VK_SUCCESS(err);
15724
15725 VkDescriptorPoolSize ds_type_count = {};
15726 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15727 ds_type_count.descriptorCount = 1;
15728
15729 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15730 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15731 ds_pool_ci.pNext = NULL;
15732 ds_pool_ci.maxSets = 1;
15733 ds_pool_ci.poolSizeCount = 1;
15734 ds_pool_ci.pPoolSizes = &ds_type_count;
15735
15736 VkDescriptorPool ds_pool;
15737 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15738 ASSERT_VK_SUCCESS(err);
15739
15740 VkDescriptorSetLayoutBinding dsl_binding = {};
15741 dsl_binding.binding = 0;
15742 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15743 dsl_binding.descriptorCount = 1;
15744 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15745 dsl_binding.pImmutableSamplers = NULL;
15746
15747 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15748 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15749 ds_layout_ci.pNext = NULL;
15750 ds_layout_ci.bindingCount = 1;
15751 ds_layout_ci.pBindings = &dsl_binding;
15752 VkDescriptorSetLayout ds_layout;
15753 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15754 ASSERT_VK_SUCCESS(err);
15755
15756 VkDescriptorSet descriptor_set;
15757 VkDescriptorSetAllocateInfo alloc_info = {};
15758 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15759 alloc_info.descriptorSetCount = 1;
15760 alloc_info.descriptorPool = ds_pool;
15761 alloc_info.pSetLayouts = &ds_layout;
15762 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15763 ASSERT_VK_SUCCESS(err);
15764
15765 VkDescriptorImageInfo image_info = {};
15766 image_info.imageView = view;
15767 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15768
15769 VkWriteDescriptorSet descriptor_write;
15770 memset(&descriptor_write, 0, sizeof(descriptor_write));
15771 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15772 descriptor_write.dstSet = descriptor_set;
15773 descriptor_write.dstBinding = 0;
15774 descriptor_write.descriptorCount = 1;
15775 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15776 descriptor_write.pImageInfo = &image_info;
15777
15778 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15779 // be
15780 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15781 // This will most likely produce a crash if the parameter_validation
15782 // layer
15783 // does not correctly ignore pBufferInfo.
15784 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15785 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15786
15787 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15788
15789 m_errorMonitor->VerifyNotFound();
15790
15791 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15792 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15793 vkDestroyImageView(m_device->device(), view, NULL);
15794 vkDestroyImage(m_device->device(), image, NULL);
15795 vkFreeMemory(m_device->device(), image_memory, NULL);
15796 }
15797
15798 // Buffer Case
15799 {
15800 m_errorMonitor->ExpectSuccess();
15801
15802 VkBuffer buffer;
15803 uint32_t queue_family_index = 0;
15804 VkBufferCreateInfo buffer_create_info = {};
15805 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15806 buffer_create_info.size = 1024;
15807 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15808 buffer_create_info.queueFamilyIndexCount = 1;
15809 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15810
15811 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15812 ASSERT_VK_SUCCESS(err);
15813
15814 VkMemoryRequirements memory_reqs;
15815 VkDeviceMemory buffer_memory;
15816 bool pass;
15817 VkMemoryAllocateInfo memory_info = {};
15818 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15819 memory_info.pNext = NULL;
15820 memory_info.allocationSize = 0;
15821 memory_info.memoryTypeIndex = 0;
15822
15823 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15824 memory_info.allocationSize = memory_reqs.size;
15825 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15826 ASSERT_TRUE(pass);
15827
15828 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15829 ASSERT_VK_SUCCESS(err);
15830 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15831 ASSERT_VK_SUCCESS(err);
15832
15833 VkDescriptorPoolSize ds_type_count = {};
15834 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15835 ds_type_count.descriptorCount = 1;
15836
15837 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15838 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15839 ds_pool_ci.pNext = NULL;
15840 ds_pool_ci.maxSets = 1;
15841 ds_pool_ci.poolSizeCount = 1;
15842 ds_pool_ci.pPoolSizes = &ds_type_count;
15843
15844 VkDescriptorPool ds_pool;
15845 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15846 ASSERT_VK_SUCCESS(err);
15847
15848 VkDescriptorSetLayoutBinding dsl_binding = {};
15849 dsl_binding.binding = 0;
15850 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15851 dsl_binding.descriptorCount = 1;
15852 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15853 dsl_binding.pImmutableSamplers = NULL;
15854
15855 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15856 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15857 ds_layout_ci.pNext = NULL;
15858 ds_layout_ci.bindingCount = 1;
15859 ds_layout_ci.pBindings = &dsl_binding;
15860 VkDescriptorSetLayout ds_layout;
15861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15862 ASSERT_VK_SUCCESS(err);
15863
15864 VkDescriptorSet descriptor_set;
15865 VkDescriptorSetAllocateInfo alloc_info = {};
15866 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15867 alloc_info.descriptorSetCount = 1;
15868 alloc_info.descriptorPool = ds_pool;
15869 alloc_info.pSetLayouts = &ds_layout;
15870 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15871 ASSERT_VK_SUCCESS(err);
15872
15873 VkDescriptorBufferInfo buffer_info = {};
15874 buffer_info.buffer = buffer;
15875 buffer_info.offset = 0;
15876 buffer_info.range = 1024;
15877
15878 VkWriteDescriptorSet descriptor_write;
15879 memset(&descriptor_write, 0, sizeof(descriptor_write));
15880 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15881 descriptor_write.dstSet = descriptor_set;
15882 descriptor_write.dstBinding = 0;
15883 descriptor_write.descriptorCount = 1;
15884 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15885 descriptor_write.pBufferInfo = &buffer_info;
15886
15887 // Set pImageInfo and pTexelBufferView to invalid values, which should
15888 // be
15889 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15890 // This will most likely produce a crash if the parameter_validation
15891 // layer
15892 // does not correctly ignore pImageInfo.
15893 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15894 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15895
15896 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15897
15898 m_errorMonitor->VerifyNotFound();
15899
15900 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15901 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15902 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15903 vkDestroyBuffer(m_device->device(), buffer, NULL);
15904 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15905 }
15906
15907 // Texel Buffer Case
15908 {
15909 m_errorMonitor->ExpectSuccess();
15910
15911 VkBuffer buffer;
15912 uint32_t queue_family_index = 0;
15913 VkBufferCreateInfo buffer_create_info = {};
15914 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15915 buffer_create_info.size = 1024;
15916 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15917 buffer_create_info.queueFamilyIndexCount = 1;
15918 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15919
15920 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15921 ASSERT_VK_SUCCESS(err);
15922
15923 VkMemoryRequirements memory_reqs;
15924 VkDeviceMemory buffer_memory;
15925 bool pass;
15926 VkMemoryAllocateInfo memory_info = {};
15927 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15928 memory_info.pNext = NULL;
15929 memory_info.allocationSize = 0;
15930 memory_info.memoryTypeIndex = 0;
15931
15932 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15933 memory_info.allocationSize = memory_reqs.size;
15934 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15935 ASSERT_TRUE(pass);
15936
15937 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15938 ASSERT_VK_SUCCESS(err);
15939 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15940 ASSERT_VK_SUCCESS(err);
15941
15942 VkBufferViewCreateInfo buff_view_ci = {};
15943 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
15944 buff_view_ci.buffer = buffer;
15945 buff_view_ci.format = VK_FORMAT_R8_UNORM;
15946 buff_view_ci.range = VK_WHOLE_SIZE;
15947 VkBufferView buffer_view;
15948 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
15949
15950 VkDescriptorPoolSize ds_type_count = {};
15951 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15952 ds_type_count.descriptorCount = 1;
15953
15954 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15955 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15956 ds_pool_ci.pNext = NULL;
15957 ds_pool_ci.maxSets = 1;
15958 ds_pool_ci.poolSizeCount = 1;
15959 ds_pool_ci.pPoolSizes = &ds_type_count;
15960
15961 VkDescriptorPool ds_pool;
15962 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15963 ASSERT_VK_SUCCESS(err);
15964
15965 VkDescriptorSetLayoutBinding dsl_binding = {};
15966 dsl_binding.binding = 0;
15967 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15968 dsl_binding.descriptorCount = 1;
15969 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15970 dsl_binding.pImmutableSamplers = NULL;
15971
15972 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15973 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15974 ds_layout_ci.pNext = NULL;
15975 ds_layout_ci.bindingCount = 1;
15976 ds_layout_ci.pBindings = &dsl_binding;
15977 VkDescriptorSetLayout ds_layout;
15978 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15979 ASSERT_VK_SUCCESS(err);
15980
15981 VkDescriptorSet descriptor_set;
15982 VkDescriptorSetAllocateInfo alloc_info = {};
15983 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15984 alloc_info.descriptorSetCount = 1;
15985 alloc_info.descriptorPool = ds_pool;
15986 alloc_info.pSetLayouts = &ds_layout;
15987 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15988 ASSERT_VK_SUCCESS(err);
15989
15990 VkWriteDescriptorSet descriptor_write;
15991 memset(&descriptor_write, 0, sizeof(descriptor_write));
15992 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15993 descriptor_write.dstSet = descriptor_set;
15994 descriptor_write.dstBinding = 0;
15995 descriptor_write.descriptorCount = 1;
15996 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15997 descriptor_write.pTexelBufferView = &buffer_view;
15998
15999 // Set pImageInfo and pBufferInfo to invalid values, which should be
16000 // ignored for descriptorType ==
16001 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16002 // This will most likely produce a crash if the parameter_validation
16003 // layer
16004 // does not correctly ignore pImageInfo and pBufferInfo.
16005 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16006 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16007
16008 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16009
16010 m_errorMonitor->VerifyNotFound();
16011
16012 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
16013 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16014 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16015 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16016 vkDestroyBuffer(m_device->device(), buffer, NULL);
16017 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16018 }
16019}
16020
Tobin Ehlisf7428442016-10-25 07:58:24 -060016021TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16022 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16023
16024 ASSERT_NO_FATAL_FAILURE(InitState());
16025 // Create layout where two binding #s are "1"
16026 static const uint32_t NUM_BINDINGS = 3;
16027 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16028 dsl_binding[0].binding = 1;
16029 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16030 dsl_binding[0].descriptorCount = 1;
16031 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16032 dsl_binding[0].pImmutableSamplers = NULL;
16033 dsl_binding[1].binding = 0;
16034 dsl_binding[1].descriptorCount = 1;
16035 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16036 dsl_binding[1].descriptorCount = 1;
16037 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16038 dsl_binding[1].pImmutableSamplers = NULL;
16039 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16040 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16041 dsl_binding[2].descriptorCount = 1;
16042 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16043 dsl_binding[2].pImmutableSamplers = NULL;
16044
16045 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16046 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16047 ds_layout_ci.pNext = NULL;
16048 ds_layout_ci.bindingCount = NUM_BINDINGS;
16049 ds_layout_ci.pBindings = dsl_binding;
16050 VkDescriptorSetLayout ds_layout;
16051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16052 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16053 m_errorMonitor->VerifyFound();
16054}
16055
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016056TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016057 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16058
16059 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016060
16061 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016062
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016063 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16064
16065 {
16066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16067 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16068 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16069 m_errorMonitor->VerifyFound();
16070 }
16071
16072 {
16073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16074 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16075 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16076 m_errorMonitor->VerifyFound();
16077 }
16078
16079 {
16080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16081 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16082 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16083 m_errorMonitor->VerifyFound();
16084 }
16085
16086 {
16087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16088 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16089 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16090 m_errorMonitor->VerifyFound();
16091 }
16092
16093 {
16094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16095 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16096 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16097 m_errorMonitor->VerifyFound();
16098 }
16099
16100 {
16101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16102 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16103 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16104 m_errorMonitor->VerifyFound();
16105 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016106
16107 {
16108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16109 VkRect2D scissor = {{-1, 0}, {16, 16}};
16110 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16111 m_errorMonitor->VerifyFound();
16112 }
16113
16114 {
16115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16116 VkRect2D scissor = {{0, -2}, {16, 16}};
16117 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16118 m_errorMonitor->VerifyFound();
16119 }
16120
16121 {
16122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16123 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16124 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16125 m_errorMonitor->VerifyFound();
16126 }
16127
16128 {
16129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16130 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16131 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16132 m_errorMonitor->VerifyFound();
16133 }
16134
16135 EndCommandBuffer();
16136}
16137
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016138// This is a positive test. No failures are expected.
16139TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16140 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16141 VkResult err;
16142
16143 ASSERT_NO_FATAL_FAILURE(InitState());
16144 m_errorMonitor->ExpectSuccess();
16145 VkDescriptorPoolSize ds_type_count = {};
16146 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16147 ds_type_count.descriptorCount = 2;
16148
16149 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16150 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16151 ds_pool_ci.pNext = NULL;
16152 ds_pool_ci.maxSets = 1;
16153 ds_pool_ci.poolSizeCount = 1;
16154 ds_pool_ci.pPoolSizes = &ds_type_count;
16155
16156 VkDescriptorPool ds_pool;
16157 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16158 ASSERT_VK_SUCCESS(err);
16159
16160 // Create layout with two uniform buffer descriptors w/ empty binding between them
16161 static const uint32_t NUM_BINDINGS = 3;
16162 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16163 dsl_binding[0].binding = 0;
16164 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16165 dsl_binding[0].descriptorCount = 1;
16166 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16167 dsl_binding[0].pImmutableSamplers = NULL;
16168 dsl_binding[1].binding = 1;
16169 dsl_binding[1].descriptorCount = 0; // empty binding
16170 dsl_binding[2].binding = 2;
16171 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16172 dsl_binding[2].descriptorCount = 1;
16173 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16174 dsl_binding[2].pImmutableSamplers = NULL;
16175
16176 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16177 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16178 ds_layout_ci.pNext = NULL;
16179 ds_layout_ci.bindingCount = NUM_BINDINGS;
16180 ds_layout_ci.pBindings = dsl_binding;
16181 VkDescriptorSetLayout ds_layout;
16182 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16183 ASSERT_VK_SUCCESS(err);
16184
16185 VkDescriptorSet descriptor_set = {};
16186 VkDescriptorSetAllocateInfo alloc_info = {};
16187 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16188 alloc_info.descriptorSetCount = 1;
16189 alloc_info.descriptorPool = ds_pool;
16190 alloc_info.pSetLayouts = &ds_layout;
16191 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16192 ASSERT_VK_SUCCESS(err);
16193
16194 // Create a buffer to be used for update
16195 VkBufferCreateInfo buff_ci = {};
16196 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16197 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16198 buff_ci.size = 256;
16199 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16200 VkBuffer buffer;
16201 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16202 ASSERT_VK_SUCCESS(err);
16203 // Have to bind memory to buffer before descriptor update
16204 VkMemoryAllocateInfo mem_alloc = {};
16205 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16206 mem_alloc.pNext = NULL;
16207 mem_alloc.allocationSize = 512; // one allocation for both buffers
16208 mem_alloc.memoryTypeIndex = 0;
16209
16210 VkMemoryRequirements mem_reqs;
16211 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16212 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16213 if (!pass) {
16214 vkDestroyBuffer(m_device->device(), buffer, NULL);
16215 return;
16216 }
16217
16218 VkDeviceMemory mem;
16219 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16220 ASSERT_VK_SUCCESS(err);
16221 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16222 ASSERT_VK_SUCCESS(err);
16223
16224 // Only update the descriptor at binding 2
16225 VkDescriptorBufferInfo buff_info = {};
16226 buff_info.buffer = buffer;
16227 buff_info.offset = 0;
16228 buff_info.range = VK_WHOLE_SIZE;
16229 VkWriteDescriptorSet descriptor_write = {};
16230 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16231 descriptor_write.dstBinding = 2;
16232 descriptor_write.descriptorCount = 1;
16233 descriptor_write.pTexelBufferView = nullptr;
16234 descriptor_write.pBufferInfo = &buff_info;
16235 descriptor_write.pImageInfo = nullptr;
16236 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16237 descriptor_write.dstSet = descriptor_set;
16238
16239 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16240
16241 m_errorMonitor->VerifyNotFound();
16242 // Cleanup
16243 vkFreeMemory(m_device->device(), mem, NULL);
16244 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16245 vkDestroyBuffer(m_device->device(), buffer, NULL);
16246 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16247}
16248
16249// This is a positive test. No failures are expected.
16250TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16251 VkResult err;
16252 bool pass;
16253
16254 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16255 "the buffer, create an image, and bind the same memory to "
16256 "it");
16257
16258 m_errorMonitor->ExpectSuccess();
16259
16260 ASSERT_NO_FATAL_FAILURE(InitState());
16261
16262 VkBuffer buffer;
16263 VkImage image;
16264 VkDeviceMemory mem;
16265 VkMemoryRequirements mem_reqs;
16266
16267 VkBufferCreateInfo buf_info = {};
16268 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16269 buf_info.pNext = NULL;
16270 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16271 buf_info.size = 256;
16272 buf_info.queueFamilyIndexCount = 0;
16273 buf_info.pQueueFamilyIndices = NULL;
16274 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16275 buf_info.flags = 0;
16276 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16277 ASSERT_VK_SUCCESS(err);
16278
16279 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16280
16281 VkMemoryAllocateInfo alloc_info = {};
16282 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16283 alloc_info.pNext = NULL;
16284 alloc_info.memoryTypeIndex = 0;
16285
16286 // Ensure memory is big enough for both bindings
16287 alloc_info.allocationSize = 0x10000;
16288
16289 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16290 if (!pass) {
16291 vkDestroyBuffer(m_device->device(), buffer, NULL);
16292 return;
16293 }
16294
16295 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16296 ASSERT_VK_SUCCESS(err);
16297
16298 uint8_t *pData;
16299 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16300 ASSERT_VK_SUCCESS(err);
16301
16302 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16303
16304 vkUnmapMemory(m_device->device(), mem);
16305
16306 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16307 ASSERT_VK_SUCCESS(err);
16308
16309 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16310 // memory. In fact, it was never used by the GPU.
16311 // Just be be sure, wait for idle.
16312 vkDestroyBuffer(m_device->device(), buffer, NULL);
16313 vkDeviceWaitIdle(m_device->device());
16314
16315 VkImageCreateInfo image_create_info = {};
16316 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16317 image_create_info.pNext = NULL;
16318 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16319 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16320 image_create_info.extent.width = 64;
16321 image_create_info.extent.height = 64;
16322 image_create_info.extent.depth = 1;
16323 image_create_info.mipLevels = 1;
16324 image_create_info.arrayLayers = 1;
16325 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16326 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16327 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16328 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16329 image_create_info.queueFamilyIndexCount = 0;
16330 image_create_info.pQueueFamilyIndices = NULL;
16331 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16332 image_create_info.flags = 0;
16333
16334 VkMemoryAllocateInfo mem_alloc = {};
16335 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16336 mem_alloc.pNext = NULL;
16337 mem_alloc.allocationSize = 0;
16338 mem_alloc.memoryTypeIndex = 0;
16339
16340 /* Create a mappable image. It will be the texture if linear images are ok
16341 * to be textures or it will be the staging image if they are not.
16342 */
16343 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16344 ASSERT_VK_SUCCESS(err);
16345
16346 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16347
16348 mem_alloc.allocationSize = mem_reqs.size;
16349
16350 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16351 if (!pass) {
16352 vkDestroyImage(m_device->device(), image, NULL);
16353 return;
16354 }
16355
16356 // VALIDATION FAILURE:
16357 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16358 ASSERT_VK_SUCCESS(err);
16359
16360 m_errorMonitor->VerifyNotFound();
16361
16362 vkFreeMemory(m_device->device(), mem, NULL);
16363 vkDestroyBuffer(m_device->device(), buffer, NULL);
16364 vkDestroyImage(m_device->device(), image, NULL);
16365}
16366
Tobin Ehlis953e8392016-11-17 10:54:13 -070016367TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16368 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16369 // We previously had a bug where dynamic offset of inactive bindings was still being used
16370 VkResult err;
16371 m_errorMonitor->ExpectSuccess();
16372
16373 ASSERT_NO_FATAL_FAILURE(InitState());
16374 ASSERT_NO_FATAL_FAILURE(InitViewport());
16375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16376
16377 VkDescriptorPoolSize ds_type_count = {};
16378 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16379 ds_type_count.descriptorCount = 3;
16380
16381 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16382 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16383 ds_pool_ci.pNext = NULL;
16384 ds_pool_ci.maxSets = 1;
16385 ds_pool_ci.poolSizeCount = 1;
16386 ds_pool_ci.pPoolSizes = &ds_type_count;
16387
16388 VkDescriptorPool ds_pool;
16389 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16390 ASSERT_VK_SUCCESS(err);
16391
16392 const uint32_t BINDING_COUNT = 3;
16393 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
16394 dsl_binding[0].binding = 0;
16395 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16396 dsl_binding[0].descriptorCount = 1;
16397 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16398 dsl_binding[0].pImmutableSamplers = NULL;
16399 dsl_binding[1].binding = 1;
16400 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16401 dsl_binding[1].descriptorCount = 1;
16402 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16403 dsl_binding[1].pImmutableSamplers = NULL;
16404 dsl_binding[2].binding = 2;
16405 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16406 dsl_binding[2].descriptorCount = 1;
16407 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16408 dsl_binding[2].pImmutableSamplers = NULL;
16409
16410 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16411 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16412 ds_layout_ci.pNext = NULL;
16413 ds_layout_ci.bindingCount = BINDING_COUNT;
16414 ds_layout_ci.pBindings = dsl_binding;
16415 VkDescriptorSetLayout ds_layout;
16416 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16417 ASSERT_VK_SUCCESS(err);
16418
16419 VkDescriptorSet descriptor_set;
16420 VkDescriptorSetAllocateInfo alloc_info = {};
16421 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16422 alloc_info.descriptorSetCount = 1;
16423 alloc_info.descriptorPool = ds_pool;
16424 alloc_info.pSetLayouts = &ds_layout;
16425 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16426 ASSERT_VK_SUCCESS(err);
16427
16428 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16429 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16430 pipeline_layout_ci.pNext = NULL;
16431 pipeline_layout_ci.setLayoutCount = 1;
16432 pipeline_layout_ci.pSetLayouts = &ds_layout;
16433
16434 VkPipelineLayout pipeline_layout;
16435 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16436 ASSERT_VK_SUCCESS(err);
16437
16438 // Create two buffers to update the descriptors with
16439 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16440 uint32_t qfi = 0;
16441 VkBufferCreateInfo buffCI = {};
16442 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16443 buffCI.size = 2048;
16444 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16445 buffCI.queueFamilyIndexCount = 1;
16446 buffCI.pQueueFamilyIndices = &qfi;
16447
16448 VkBuffer dyub1;
16449 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16450 ASSERT_VK_SUCCESS(err);
16451 // buffer2
16452 buffCI.size = 1024;
16453 VkBuffer dyub2;
16454 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16455 ASSERT_VK_SUCCESS(err);
16456 // Allocate memory and bind to buffers
16457 VkMemoryAllocateInfo mem_alloc[2] = {};
16458 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16459 mem_alloc[0].pNext = NULL;
16460 mem_alloc[0].memoryTypeIndex = 0;
16461 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16462 mem_alloc[1].pNext = NULL;
16463 mem_alloc[1].memoryTypeIndex = 0;
16464
16465 VkMemoryRequirements mem_reqs1;
16466 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16467 VkMemoryRequirements mem_reqs2;
16468 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16469 mem_alloc[0].allocationSize = mem_reqs1.size;
16470 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16471 mem_alloc[1].allocationSize = mem_reqs2.size;
16472 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16473 if (!pass) {
16474 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16475 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16476 return;
16477 }
16478
16479 VkDeviceMemory mem1;
16480 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16481 ASSERT_VK_SUCCESS(err);
16482 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
16483 ASSERT_VK_SUCCESS(err);
16484 VkDeviceMemory mem2;
16485 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
16486 ASSERT_VK_SUCCESS(err);
16487 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
16488 ASSERT_VK_SUCCESS(err);
16489 // Update descriptors
16490 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
16491 buff_info[0].buffer = dyub1;
16492 buff_info[0].offset = 0;
16493 buff_info[0].range = 256;
16494 buff_info[1].buffer = dyub1;
16495 buff_info[1].offset = 256;
16496 buff_info[1].range = 512;
16497 buff_info[2].buffer = dyub2;
16498 buff_info[2].offset = 0;
16499 buff_info[2].range = 512;
16500
16501 VkWriteDescriptorSet descriptor_write;
16502 memset(&descriptor_write, 0, sizeof(descriptor_write));
16503 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16504 descriptor_write.dstSet = descriptor_set;
16505 descriptor_write.dstBinding = 0;
16506 descriptor_write.descriptorCount = BINDING_COUNT;
16507 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16508 descriptor_write.pBufferInfo = buff_info;
16509
16510 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16511
16512 BeginCommandBuffer();
16513
16514 // Create PSO to be used for draw-time errors below
16515 char const *vsSource = "#version 450\n"
16516 "\n"
16517 "out gl_PerVertex { \n"
16518 " vec4 gl_Position;\n"
16519 "};\n"
16520 "void main(){\n"
16521 " gl_Position = vec4(1);\n"
16522 "}\n";
16523 char const *fsSource = "#version 450\n"
16524 "\n"
16525 "layout(location=0) out vec4 x;\n"
16526 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
16527 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
16528 "void main(){\n"
16529 " x = vec4(bar1.y) + vec4(bar2.y);\n"
16530 "}\n";
16531 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16532 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16533 VkPipelineObj pipe(m_device);
16534 pipe.SetViewport(m_viewports);
16535 pipe.SetScissor(m_scissors);
16536 pipe.AddShader(&vs);
16537 pipe.AddShader(&fs);
16538 pipe.AddColorAttachment();
16539 pipe.CreateVKPipeline(pipeline_layout, renderPass());
16540
16541 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
16542 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
16543 // we used to have a bug in this case.
16544 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
16545 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
16546 &descriptor_set, BINDING_COUNT, dyn_off);
16547 Draw(1, 0, 0, 0);
16548 m_errorMonitor->VerifyNotFound();
16549
16550 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16551 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16552 vkFreeMemory(m_device->device(), mem1, NULL);
16553 vkFreeMemory(m_device->device(), mem2, NULL);
16554
16555 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
16556 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16557 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16558}
16559
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016560TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16561
16562 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16563 "mapping while using VK_WHOLE_SIZE does not cause access "
16564 "violations");
16565 VkResult err;
16566 uint8_t *pData;
16567 ASSERT_NO_FATAL_FAILURE(InitState());
16568
16569 VkDeviceMemory mem;
16570 VkMemoryRequirements mem_reqs;
16571 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
16572 VkMemoryAllocateInfo alloc_info = {};
16573 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16574 alloc_info.pNext = NULL;
16575 alloc_info.memoryTypeIndex = 0;
16576
16577 static const VkDeviceSize allocation_size = 0x1000;
16578 alloc_info.allocationSize = allocation_size;
16579
16580 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16581 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16582 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16583 if (!pass) {
16584 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16585 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16586 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16587 if (!pass) {
16588 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16589 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16590 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16591 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16592 if (!pass) {
16593 return;
16594 }
16595 }
16596 }
16597
16598 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16599 ASSERT_VK_SUCCESS(err);
16600
16601 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16602 // mapped range
16603 m_errorMonitor->ExpectSuccess();
16604 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16605 ASSERT_VK_SUCCESS(err);
16606 VkMappedMemoryRange mmr = {};
16607 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16608 mmr.memory = mem;
16609 mmr.offset = 0;
16610 mmr.size = VK_WHOLE_SIZE;
16611 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16612 ASSERT_VK_SUCCESS(err);
16613 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16614 ASSERT_VK_SUCCESS(err);
16615 m_errorMonitor->VerifyNotFound();
16616 vkUnmapMemory(m_device->device(), mem);
16617
16618 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16619 // mapped range
16620 m_errorMonitor->ExpectSuccess();
16621 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16622 ASSERT_VK_SUCCESS(err);
16623 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16624 mmr.memory = mem;
16625 mmr.offset = 13;
16626 mmr.size = VK_WHOLE_SIZE;
16627 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16628 ASSERT_VK_SUCCESS(err);
16629 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16630 ASSERT_VK_SUCCESS(err);
16631 m_errorMonitor->VerifyNotFound();
16632 vkUnmapMemory(m_device->device(), mem);
16633
16634 // Map with prime offset and size
16635 // Flush/Invalidate subrange of mapped area with prime offset and size
16636 m_errorMonitor->ExpectSuccess();
16637 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16638 ASSERT_VK_SUCCESS(err);
16639 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16640 mmr.memory = mem;
16641 mmr.offset = allocation_size - 107;
16642 mmr.size = 61;
16643 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16644 ASSERT_VK_SUCCESS(err);
16645 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16646 ASSERT_VK_SUCCESS(err);
16647 m_errorMonitor->VerifyNotFound();
16648 vkUnmapMemory(m_device->device(), mem);
16649
16650 // Map without offset and flush WHOLE_SIZE with two separate offsets
16651 m_errorMonitor->ExpectSuccess();
16652 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16653 ASSERT_VK_SUCCESS(err);
16654 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16655 mmr.memory = mem;
16656 mmr.offset = allocation_size - 100;
16657 mmr.size = VK_WHOLE_SIZE;
16658 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16659 ASSERT_VK_SUCCESS(err);
16660 mmr.offset = allocation_size - 200;
16661 mmr.size = VK_WHOLE_SIZE;
16662 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16663 ASSERT_VK_SUCCESS(err);
16664 m_errorMonitor->VerifyNotFound();
16665 vkUnmapMemory(m_device->device(), mem);
16666
16667 vkFreeMemory(m_device->device(), mem, NULL);
16668}
16669
16670// This is a positive test. We used to expect error in this case but spec now allows it
16671TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16672 m_errorMonitor->ExpectSuccess();
16673 vk_testing::Fence testFence;
16674 VkFenceCreateInfo fenceInfo = {};
16675 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16676 fenceInfo.pNext = NULL;
16677
16678 ASSERT_NO_FATAL_FAILURE(InitState());
16679 testFence.init(*m_device, fenceInfo);
16680 VkFence fences[1] = { testFence.handle() };
16681 VkResult result = vkResetFences(m_device->device(), 1, fences);
16682 ASSERT_VK_SUCCESS(result);
16683
16684 m_errorMonitor->VerifyNotFound();
16685}
16686
16687TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16688 m_errorMonitor->ExpectSuccess();
16689
16690 ASSERT_NO_FATAL_FAILURE(InitState());
16691 VkResult err;
16692
16693 // Record (empty!) command buffer that can be submitted multiple times
16694 // simultaneously.
16695 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16696 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16697 m_commandBuffer->BeginCommandBuffer(&cbbi);
16698 m_commandBuffer->EndCommandBuffer();
16699
16700 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16701 VkFence fence;
16702 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16703 ASSERT_VK_SUCCESS(err);
16704
16705 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16706 VkSemaphore s1, s2;
16707 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16708 ASSERT_VK_SUCCESS(err);
16709 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16710 ASSERT_VK_SUCCESS(err);
16711
16712 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16713 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16714 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16715 ASSERT_VK_SUCCESS(err);
16716
16717 // Submit CB again, signaling s2.
16718 si.pSignalSemaphores = &s2;
16719 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16720 ASSERT_VK_SUCCESS(err);
16721
16722 // Wait for fence.
16723 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16724 ASSERT_VK_SUCCESS(err);
16725
16726 // CB is still in flight from second submission, but semaphore s1 is no
16727 // longer in flight. delete it.
16728 vkDestroySemaphore(m_device->device(), s1, nullptr);
16729
16730 m_errorMonitor->VerifyNotFound();
16731
16732 // Force device idle and clean up remaining objects
16733 vkDeviceWaitIdle(m_device->device());
16734 vkDestroySemaphore(m_device->device(), s2, nullptr);
16735 vkDestroyFence(m_device->device(), fence, nullptr);
16736}
16737
16738TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16739 m_errorMonitor->ExpectSuccess();
16740
16741 ASSERT_NO_FATAL_FAILURE(InitState());
16742 VkResult err;
16743
16744 // A fence created signaled
16745 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16746 VkFence f1;
16747 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16748 ASSERT_VK_SUCCESS(err);
16749
16750 // A fence created not
16751 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16752 VkFence f2;
16753 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16754 ASSERT_VK_SUCCESS(err);
16755
16756 // Submit the unsignaled fence
16757 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16758 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16759
16760 // Wait on both fences, with signaled first.
16761 VkFence fences[] = { f1, f2 };
16762 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16763
16764 // Should have both retired!
16765 vkDestroyFence(m_device->device(), f1, nullptr);
16766 vkDestroyFence(m_device->device(), f2, nullptr);
16767
16768 m_errorMonitor->VerifyNotFound();
16769}
16770
16771TEST_F(VkPositiveLayerTest, ValidUsage) {
16772 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16773 "doesn't generate validation errors");
16774
16775 ASSERT_NO_FATAL_FAILURE(InitState());
16776
16777 m_errorMonitor->ExpectSuccess();
16778 // Verify that we can create a view with usage INPUT_ATTACHMENT
16779 VkImageObj image(m_device);
16780 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16781 ASSERT_TRUE(image.initialized());
16782 VkImageView imageView;
16783 VkImageViewCreateInfo ivci = {};
16784 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16785 ivci.image = image.handle();
16786 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16787 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16788 ivci.subresourceRange.layerCount = 1;
16789 ivci.subresourceRange.baseMipLevel = 0;
16790 ivci.subresourceRange.levelCount = 1;
16791 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16792
16793 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16794 m_errorMonitor->VerifyNotFound();
16795 vkDestroyImageView(m_device->device(), imageView, NULL);
16796}
16797
16798// This is a positive test. No failures are expected.
16799TEST_F(VkPositiveLayerTest, BindSparse) {
16800 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16801 "and then free the memory");
16802
16803 ASSERT_NO_FATAL_FAILURE(InitState());
16804
16805 auto index = m_device->graphics_queue_node_index_;
16806 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16807 return;
16808
16809 m_errorMonitor->ExpectSuccess();
16810
16811 VkImage image;
16812 VkImageCreateInfo image_create_info = {};
16813 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16814 image_create_info.pNext = NULL;
16815 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16816 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16817 image_create_info.extent.width = 64;
16818 image_create_info.extent.height = 64;
16819 image_create_info.extent.depth = 1;
16820 image_create_info.mipLevels = 1;
16821 image_create_info.arrayLayers = 1;
16822 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16823 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16824 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16825 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16826 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16827 ASSERT_VK_SUCCESS(err);
16828
16829 VkMemoryRequirements memory_reqs;
16830 VkDeviceMemory memory_one, memory_two;
16831 bool pass;
16832 VkMemoryAllocateInfo memory_info = {};
16833 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16834 memory_info.pNext = NULL;
16835 memory_info.allocationSize = 0;
16836 memory_info.memoryTypeIndex = 0;
16837 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16838 // Find an image big enough to allow sparse mapping of 2 memory regions
16839 // Increase the image size until it is at least twice the
16840 // size of the required alignment, to ensure we can bind both
16841 // allocated memory blocks to the image on aligned offsets.
16842 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16843 vkDestroyImage(m_device->device(), image, nullptr);
16844 image_create_info.extent.width *= 2;
16845 image_create_info.extent.height *= 2;
16846 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16847 ASSERT_VK_SUCCESS(err);
16848 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16849 }
16850 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16851 // at the end of the first
16852 memory_info.allocationSize = memory_reqs.alignment;
16853 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16854 ASSERT_TRUE(pass);
16855 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16856 ASSERT_VK_SUCCESS(err);
16857 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16858 ASSERT_VK_SUCCESS(err);
16859 VkSparseMemoryBind binds[2];
16860 binds[0].flags = 0;
16861 binds[0].memory = memory_one;
16862 binds[0].memoryOffset = 0;
16863 binds[0].resourceOffset = 0;
16864 binds[0].size = memory_info.allocationSize;
16865 binds[1].flags = 0;
16866 binds[1].memory = memory_two;
16867 binds[1].memoryOffset = 0;
16868 binds[1].resourceOffset = memory_info.allocationSize;
16869 binds[1].size = memory_info.allocationSize;
16870
16871 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16872 opaqueBindInfo.image = image;
16873 opaqueBindInfo.bindCount = 2;
16874 opaqueBindInfo.pBinds = binds;
16875
16876 VkFence fence = VK_NULL_HANDLE;
16877 VkBindSparseInfo bindSparseInfo = {};
16878 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16879 bindSparseInfo.imageOpaqueBindCount = 1;
16880 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16881
16882 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16883 vkQueueWaitIdle(m_device->m_queue);
16884 vkDestroyImage(m_device->device(), image, NULL);
16885 vkFreeMemory(m_device->device(), memory_one, NULL);
16886 vkFreeMemory(m_device->device(), memory_two, NULL);
16887 m_errorMonitor->VerifyNotFound();
16888}
16889
16890TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16891 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16892 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16893 "the command buffer has prior knowledge of that "
16894 "attachment's layout.");
16895
16896 m_errorMonitor->ExpectSuccess();
16897
16898 ASSERT_NO_FATAL_FAILURE(InitState());
16899
16900 // A renderpass with one color attachment.
16901 VkAttachmentDescription attachment = { 0,
16902 VK_FORMAT_R8G8B8A8_UNORM,
16903 VK_SAMPLE_COUNT_1_BIT,
16904 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16905 VK_ATTACHMENT_STORE_OP_STORE,
16906 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16907 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16908 VK_IMAGE_LAYOUT_UNDEFINED,
16909 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16910
16911 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16912
16913 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16914
16915 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16916
16917 VkRenderPass rp;
16918 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16919 ASSERT_VK_SUCCESS(err);
16920
16921 // A compatible framebuffer.
16922 VkImageObj image(m_device);
16923 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16924 ASSERT_TRUE(image.initialized());
16925
16926 VkImageViewCreateInfo ivci = {
16927 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16928 nullptr,
16929 0,
16930 image.handle(),
16931 VK_IMAGE_VIEW_TYPE_2D,
16932 VK_FORMAT_R8G8B8A8_UNORM,
16933 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16934 VK_COMPONENT_SWIZZLE_IDENTITY },
16935 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16936 };
16937 VkImageView view;
16938 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16939 ASSERT_VK_SUCCESS(err);
16940
16941 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16942 VkFramebuffer fb;
16943 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16944 ASSERT_VK_SUCCESS(err);
16945
16946 // Record a single command buffer which uses this renderpass twice. The
16947 // bug is triggered at the beginning of the second renderpass, when the
16948 // command buffer already has a layout recorded for the attachment.
16949 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16950 BeginCommandBuffer();
16951 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16952 vkCmdEndRenderPass(m_commandBuffer->handle());
16953 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16954
16955 m_errorMonitor->VerifyNotFound();
16956
16957 vkCmdEndRenderPass(m_commandBuffer->handle());
16958 EndCommandBuffer();
16959
16960 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16961 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16962 vkDestroyImageView(m_device->device(), view, nullptr);
16963}
16964
16965TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
16966 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
16967 "command buffer, bind them together, then destroy "
16968 "command pool and framebuffer and verify there are no "
16969 "errors.");
16970
16971 m_errorMonitor->ExpectSuccess();
16972
16973 ASSERT_NO_FATAL_FAILURE(InitState());
16974
16975 // A renderpass with one color attachment.
16976 VkAttachmentDescription attachment = { 0,
16977 VK_FORMAT_R8G8B8A8_UNORM,
16978 VK_SAMPLE_COUNT_1_BIT,
16979 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16980 VK_ATTACHMENT_STORE_OP_STORE,
16981 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16982 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16983 VK_IMAGE_LAYOUT_UNDEFINED,
16984 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16985
16986 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16987
16988 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16989
16990 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16991
16992 VkRenderPass rp;
16993 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16994 ASSERT_VK_SUCCESS(err);
16995
16996 // A compatible framebuffer.
16997 VkImageObj image(m_device);
16998 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16999 ASSERT_TRUE(image.initialized());
17000
17001 VkImageViewCreateInfo ivci = {
17002 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17003 nullptr,
17004 0,
17005 image.handle(),
17006 VK_IMAGE_VIEW_TYPE_2D,
17007 VK_FORMAT_R8G8B8A8_UNORM,
17008 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17009 VK_COMPONENT_SWIZZLE_IDENTITY },
17010 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17011 };
17012 VkImageView view;
17013 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17014 ASSERT_VK_SUCCESS(err);
17015
17016 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17017 VkFramebuffer fb;
17018 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17019 ASSERT_VK_SUCCESS(err);
17020
17021 // Explicitly create a command buffer to bind the FB to so that we can then
17022 // destroy the command pool in order to implicitly free command buffer
17023 VkCommandPool command_pool;
17024 VkCommandPoolCreateInfo pool_create_info{};
17025 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17026 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17027 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17028 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17029
17030 VkCommandBuffer command_buffer;
17031 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17032 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17033 command_buffer_allocate_info.commandPool = command_pool;
17034 command_buffer_allocate_info.commandBufferCount = 1;
17035 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17036 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17037
17038 // Begin our cmd buffer with renderpass using our framebuffer
17039 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17040 VkCommandBufferBeginInfo begin_info{};
17041 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17042 vkBeginCommandBuffer(command_buffer, &begin_info);
17043
17044 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17045 vkCmdEndRenderPass(command_buffer);
17046 vkEndCommandBuffer(command_buffer);
17047 vkDestroyImageView(m_device->device(), view, nullptr);
17048 // Destroy command pool to implicitly free command buffer
17049 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17050 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17051 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17052 m_errorMonitor->VerifyNotFound();
17053}
17054
17055TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17056 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17057 "transitions for the first subpass");
17058
17059 m_errorMonitor->ExpectSuccess();
17060
17061 ASSERT_NO_FATAL_FAILURE(InitState());
17062
17063 // A renderpass with one color attachment.
17064 VkAttachmentDescription attachment = { 0,
17065 VK_FORMAT_R8G8B8A8_UNORM,
17066 VK_SAMPLE_COUNT_1_BIT,
17067 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17068 VK_ATTACHMENT_STORE_OP_STORE,
17069 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17070 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17071 VK_IMAGE_LAYOUT_UNDEFINED,
17072 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17073
17074 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17075
17076 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17077
17078 VkSubpassDependency dep = { 0,
17079 0,
17080 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17081 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17082 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17083 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17084 VK_DEPENDENCY_BY_REGION_BIT };
17085
17086 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17087
17088 VkResult err;
17089 VkRenderPass rp;
17090 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17091 ASSERT_VK_SUCCESS(err);
17092
17093 // A compatible framebuffer.
17094 VkImageObj image(m_device);
17095 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17096 ASSERT_TRUE(image.initialized());
17097
17098 VkImageViewCreateInfo ivci = {
17099 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17100 nullptr,
17101 0,
17102 image.handle(),
17103 VK_IMAGE_VIEW_TYPE_2D,
17104 VK_FORMAT_R8G8B8A8_UNORM,
17105 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17106 VK_COMPONENT_SWIZZLE_IDENTITY },
17107 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17108 };
17109 VkImageView view;
17110 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17111 ASSERT_VK_SUCCESS(err);
17112
17113 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17114 VkFramebuffer fb;
17115 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17116 ASSERT_VK_SUCCESS(err);
17117
17118 // Record a single command buffer which issues a pipeline barrier w/
17119 // image memory barrier for the attachment. This detects the previously
17120 // missing tracking of the subpass layout by throwing a validation error
17121 // if it doesn't occur.
17122 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17123 BeginCommandBuffer();
17124 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17125
17126 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17127 nullptr,
17128 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17129 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17130 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17131 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17132 VK_QUEUE_FAMILY_IGNORED,
17133 VK_QUEUE_FAMILY_IGNORED,
17134 image.handle(),
17135 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17136 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17137 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17138 &imb);
17139
17140 vkCmdEndRenderPass(m_commandBuffer->handle());
17141 m_errorMonitor->VerifyNotFound();
17142 EndCommandBuffer();
17143
17144 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17145 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17146 vkDestroyImageView(m_device->device(), view, nullptr);
17147}
17148
17149TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17150 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17151 "is used as a depth/stencil framebuffer attachment, the "
17152 "aspectMask is ignored and both depth and stencil image "
17153 "subresources are used.");
17154
17155 VkFormatProperties format_properties;
17156 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17157 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17158 return;
17159 }
17160
17161 m_errorMonitor->ExpectSuccess();
17162
17163 ASSERT_NO_FATAL_FAILURE(InitState());
17164
17165 VkAttachmentDescription attachment = { 0,
17166 VK_FORMAT_D32_SFLOAT_S8_UINT,
17167 VK_SAMPLE_COUNT_1_BIT,
17168 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17169 VK_ATTACHMENT_STORE_OP_STORE,
17170 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17171 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17172 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17173 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17174
17175 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17176
17177 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17178
17179 VkSubpassDependency dep = { 0,
17180 0,
17181 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17182 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17183 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17184 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17185 VK_DEPENDENCY_BY_REGION_BIT};
17186
17187 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17188
17189 VkResult err;
17190 VkRenderPass rp;
17191 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17192 ASSERT_VK_SUCCESS(err);
17193
17194 VkImageObj image(m_device);
17195 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17196 0x26, // usage
17197 VK_IMAGE_TILING_OPTIMAL, 0);
17198 ASSERT_TRUE(image.initialized());
17199 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17200
17201 VkImageViewCreateInfo ivci = {
17202 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17203 nullptr,
17204 0,
17205 image.handle(),
17206 VK_IMAGE_VIEW_TYPE_2D,
17207 VK_FORMAT_D32_SFLOAT_S8_UINT,
17208 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17209 { 0x2, 0, 1, 0, 1 },
17210 };
17211 VkImageView view;
17212 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17213 ASSERT_VK_SUCCESS(err);
17214
17215 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17216 VkFramebuffer fb;
17217 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17218 ASSERT_VK_SUCCESS(err);
17219
17220 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17221 BeginCommandBuffer();
17222 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17223
17224 VkImageMemoryBarrier imb = {};
17225 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17226 imb.pNext = nullptr;
17227 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17228 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17229 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17230 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17231 imb.srcQueueFamilyIndex = 0;
17232 imb.dstQueueFamilyIndex = 0;
17233 imb.image = image.handle();
17234 imb.subresourceRange.aspectMask = 0x6;
17235 imb.subresourceRange.baseMipLevel = 0;
17236 imb.subresourceRange.levelCount = 0x1;
17237 imb.subresourceRange.baseArrayLayer = 0;
17238 imb.subresourceRange.layerCount = 0x1;
17239
17240 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17241 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17242 &imb);
17243
17244 vkCmdEndRenderPass(m_commandBuffer->handle());
17245 EndCommandBuffer();
17246 QueueCommandBuffer(false);
17247 m_errorMonitor->VerifyNotFound();
17248
17249 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17250 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17251 vkDestroyImageView(m_device->device(), view, nullptr);
17252}
17253
17254TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17255 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17256 "errors, when an attachment reference is "
17257 "VK_ATTACHMENT_UNUSED");
17258
17259 m_errorMonitor->ExpectSuccess();
17260
17261 ASSERT_NO_FATAL_FAILURE(InitState());
17262
17263 // A renderpass with no attachments
17264 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17265
17266 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17267
17268 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17269
17270 VkRenderPass rp;
17271 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17272 ASSERT_VK_SUCCESS(err);
17273
17274 // A compatible framebuffer.
17275 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17276 VkFramebuffer fb;
17277 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17278 ASSERT_VK_SUCCESS(err);
17279
17280 // Record a command buffer which just begins and ends the renderpass. The
17281 // bug manifests in BeginRenderPass.
17282 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17283 BeginCommandBuffer();
17284 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17285 vkCmdEndRenderPass(m_commandBuffer->handle());
17286 m_errorMonitor->VerifyNotFound();
17287 EndCommandBuffer();
17288
17289 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17290 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17291}
17292
17293// This is a positive test. No errors are expected.
17294TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17295 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17296 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17297 VkResult result = VK_SUCCESS;
17298 VkImageFormatProperties formatProps;
17299 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17300 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17301 &formatProps);
17302 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17303 return;
17304 }
17305
17306 ASSERT_NO_FATAL_FAILURE(InitState());
17307 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17308 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17309 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17310 VkAttachmentDescription att = {};
17311 VkAttachmentReference ref = {};
17312 att.format = depth_stencil_fmt;
17313 att.samples = VK_SAMPLE_COUNT_1_BIT;
17314 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17315 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17316 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17317 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17318 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17319 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17320
17321 VkClearValue clear;
17322 clear.depthStencil.depth = 1.0;
17323 clear.depthStencil.stencil = 0;
17324 ref.attachment = 0;
17325 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17326
17327 VkSubpassDescription subpass = {};
17328 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17329 subpass.flags = 0;
17330 subpass.inputAttachmentCount = 0;
17331 subpass.pInputAttachments = NULL;
17332 subpass.colorAttachmentCount = 0;
17333 subpass.pColorAttachments = NULL;
17334 subpass.pResolveAttachments = NULL;
17335 subpass.pDepthStencilAttachment = &ref;
17336 subpass.preserveAttachmentCount = 0;
17337 subpass.pPreserveAttachments = NULL;
17338
17339 VkRenderPass rp;
17340 VkRenderPassCreateInfo rp_info = {};
17341 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17342 rp_info.attachmentCount = 1;
17343 rp_info.pAttachments = &att;
17344 rp_info.subpassCount = 1;
17345 rp_info.pSubpasses = &subpass;
17346 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17347 ASSERT_VK_SUCCESS(result);
17348
17349 VkImageView *depthView = m_depthStencil->BindInfo();
17350 VkFramebufferCreateInfo fb_info = {};
17351 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17352 fb_info.pNext = NULL;
17353 fb_info.renderPass = rp;
17354 fb_info.attachmentCount = 1;
17355 fb_info.pAttachments = depthView;
17356 fb_info.width = 100;
17357 fb_info.height = 100;
17358 fb_info.layers = 1;
17359 VkFramebuffer fb;
17360 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17361 ASSERT_VK_SUCCESS(result);
17362
17363 VkRenderPassBeginInfo rpbinfo = {};
17364 rpbinfo.clearValueCount = 1;
17365 rpbinfo.pClearValues = &clear;
17366 rpbinfo.pNext = NULL;
17367 rpbinfo.renderPass = rp;
17368 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17369 rpbinfo.renderArea.extent.width = 100;
17370 rpbinfo.renderArea.extent.height = 100;
17371 rpbinfo.renderArea.offset.x = 0;
17372 rpbinfo.renderArea.offset.y = 0;
17373 rpbinfo.framebuffer = fb;
17374
17375 VkFence fence = {};
17376 VkFenceCreateInfo fence_ci = {};
17377 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17378 fence_ci.pNext = nullptr;
17379 fence_ci.flags = 0;
17380 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17381 ASSERT_VK_SUCCESS(result);
17382
17383 m_commandBuffer->BeginCommandBuffer();
17384 m_commandBuffer->BeginRenderPass(rpbinfo);
17385 m_commandBuffer->EndRenderPass();
17386 m_commandBuffer->EndCommandBuffer();
17387 m_commandBuffer->QueueCommandBuffer(fence);
17388
17389 VkImageObj destImage(m_device);
17390 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17391 VK_IMAGE_TILING_OPTIMAL, 0);
17392 VkImageMemoryBarrier barrier = {};
17393 VkImageSubresourceRange range;
17394 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17395 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17396 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17397 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17398 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17399 barrier.image = m_depthStencil->handle();
17400 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17401 range.baseMipLevel = 0;
17402 range.levelCount = 1;
17403 range.baseArrayLayer = 0;
17404 range.layerCount = 1;
17405 barrier.subresourceRange = range;
17406 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17407 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17408 cmdbuf.BeginCommandBuffer();
17409 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17410 &barrier);
17411 barrier.srcAccessMask = 0;
17412 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17413 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17414 barrier.image = destImage.handle();
17415 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17416 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17417 &barrier);
17418 VkImageCopy cregion;
17419 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17420 cregion.srcSubresource.mipLevel = 0;
17421 cregion.srcSubresource.baseArrayLayer = 0;
17422 cregion.srcSubresource.layerCount = 1;
17423 cregion.srcOffset.x = 0;
17424 cregion.srcOffset.y = 0;
17425 cregion.srcOffset.z = 0;
17426 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17427 cregion.dstSubresource.mipLevel = 0;
17428 cregion.dstSubresource.baseArrayLayer = 0;
17429 cregion.dstSubresource.layerCount = 1;
17430 cregion.dstOffset.x = 0;
17431 cregion.dstOffset.y = 0;
17432 cregion.dstOffset.z = 0;
17433 cregion.extent.width = 100;
17434 cregion.extent.height = 100;
17435 cregion.extent.depth = 1;
17436 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17437 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17438 cmdbuf.EndCommandBuffer();
17439
17440 VkSubmitInfo submit_info;
17441 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17442 submit_info.pNext = NULL;
17443 submit_info.waitSemaphoreCount = 0;
17444 submit_info.pWaitSemaphores = NULL;
17445 submit_info.pWaitDstStageMask = NULL;
17446 submit_info.commandBufferCount = 1;
17447 submit_info.pCommandBuffers = &cmdbuf.handle();
17448 submit_info.signalSemaphoreCount = 0;
17449 submit_info.pSignalSemaphores = NULL;
17450
17451 m_errorMonitor->ExpectSuccess();
17452 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17453 m_errorMonitor->VerifyNotFound();
17454
17455 vkQueueWaitIdle(m_device->m_queue);
17456 vkDestroyFence(m_device->device(), fence, nullptr);
17457 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17458 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17459}
17460
17461// This is a positive test. No errors should be generated.
17462TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17463 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17464
17465 m_errorMonitor->ExpectSuccess();
17466 ASSERT_NO_FATAL_FAILURE(InitState());
17467
17468 VkEvent event;
17469 VkEventCreateInfo event_create_info{};
17470 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17471 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17472
17473 VkCommandPool command_pool;
17474 VkCommandPoolCreateInfo pool_create_info{};
17475 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17476 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17477 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17478 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17479
17480 VkCommandBuffer command_buffer;
17481 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17482 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17483 command_buffer_allocate_info.commandPool = command_pool;
17484 command_buffer_allocate_info.commandBufferCount = 1;
17485 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17486 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17487
17488 VkQueue queue = VK_NULL_HANDLE;
17489 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17490
17491 {
17492 VkCommandBufferBeginInfo begin_info{};
17493 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17494 vkBeginCommandBuffer(command_buffer, &begin_info);
17495
17496 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17497 nullptr, 0, nullptr);
17498 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17499 vkEndCommandBuffer(command_buffer);
17500 }
17501 {
17502 VkSubmitInfo submit_info{};
17503 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17504 submit_info.commandBufferCount = 1;
17505 submit_info.pCommandBuffers = &command_buffer;
17506 submit_info.signalSemaphoreCount = 0;
17507 submit_info.pSignalSemaphores = nullptr;
17508 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17509 }
17510 { vkSetEvent(m_device->device(), event); }
17511
17512 vkQueueWaitIdle(queue);
17513
17514 vkDestroyEvent(m_device->device(), event, nullptr);
17515 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17516 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17517
17518 m_errorMonitor->VerifyNotFound();
17519}
17520// This is a positive test. No errors should be generated.
17521TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17522 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17523
17524 ASSERT_NO_FATAL_FAILURE(InitState());
17525 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17526 return;
17527
17528 m_errorMonitor->ExpectSuccess();
17529
17530 VkQueryPool query_pool;
17531 VkQueryPoolCreateInfo query_pool_create_info{};
17532 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17533 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17534 query_pool_create_info.queryCount = 1;
17535 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17536
17537 VkCommandPool command_pool;
17538 VkCommandPoolCreateInfo pool_create_info{};
17539 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17540 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17541 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17542 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17543
17544 VkCommandBuffer command_buffer;
17545 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17546 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17547 command_buffer_allocate_info.commandPool = command_pool;
17548 command_buffer_allocate_info.commandBufferCount = 1;
17549 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17550 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17551
17552 VkCommandBuffer secondary_command_buffer;
17553 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17554 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17555
17556 VkQueue queue = VK_NULL_HANDLE;
17557 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17558
17559 uint32_t qfi = 0;
17560 VkBufferCreateInfo buff_create_info = {};
17561 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17562 buff_create_info.size = 1024;
17563 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17564 buff_create_info.queueFamilyIndexCount = 1;
17565 buff_create_info.pQueueFamilyIndices = &qfi;
17566
17567 VkResult err;
17568 VkBuffer buffer;
17569 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17570 ASSERT_VK_SUCCESS(err);
17571 VkMemoryAllocateInfo mem_alloc = {};
17572 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17573 mem_alloc.pNext = NULL;
17574 mem_alloc.allocationSize = 1024;
17575 mem_alloc.memoryTypeIndex = 0;
17576
17577 VkMemoryRequirements memReqs;
17578 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17579 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17580 if (!pass) {
17581 vkDestroyBuffer(m_device->device(), buffer, NULL);
17582 return;
17583 }
17584
17585 VkDeviceMemory mem;
17586 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17587 ASSERT_VK_SUCCESS(err);
17588 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17589 ASSERT_VK_SUCCESS(err);
17590
17591 VkCommandBufferInheritanceInfo hinfo = {};
17592 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17593 hinfo.renderPass = VK_NULL_HANDLE;
17594 hinfo.subpass = 0;
17595 hinfo.framebuffer = VK_NULL_HANDLE;
17596 hinfo.occlusionQueryEnable = VK_FALSE;
17597 hinfo.queryFlags = 0;
17598 hinfo.pipelineStatistics = 0;
17599
17600 {
17601 VkCommandBufferBeginInfo begin_info{};
17602 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17603 begin_info.pInheritanceInfo = &hinfo;
17604 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17605
17606 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17607 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17608
17609 vkEndCommandBuffer(secondary_command_buffer);
17610
17611 begin_info.pInheritanceInfo = nullptr;
17612 vkBeginCommandBuffer(command_buffer, &begin_info);
17613
17614 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17615 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17616
17617 vkEndCommandBuffer(command_buffer);
17618 }
17619 {
17620 VkSubmitInfo submit_info{};
17621 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17622 submit_info.commandBufferCount = 1;
17623 submit_info.pCommandBuffers = &command_buffer;
17624 submit_info.signalSemaphoreCount = 0;
17625 submit_info.pSignalSemaphores = nullptr;
17626 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17627 }
17628
17629 vkQueueWaitIdle(queue);
17630
17631 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17632 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17633 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17634 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17635 vkDestroyBuffer(m_device->device(), buffer, NULL);
17636 vkFreeMemory(m_device->device(), mem, NULL);
17637
17638 m_errorMonitor->VerifyNotFound();
17639}
17640
17641// This is a positive test. No errors should be generated.
17642TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17643 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17644
17645 ASSERT_NO_FATAL_FAILURE(InitState());
17646 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17647 return;
17648
17649 m_errorMonitor->ExpectSuccess();
17650
17651 VkQueryPool query_pool;
17652 VkQueryPoolCreateInfo query_pool_create_info{};
17653 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17654 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17655 query_pool_create_info.queryCount = 1;
17656 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17657
17658 VkCommandPool command_pool;
17659 VkCommandPoolCreateInfo pool_create_info{};
17660 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17661 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17662 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17663 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17664
17665 VkCommandBuffer command_buffer[2];
17666 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17667 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17668 command_buffer_allocate_info.commandPool = command_pool;
17669 command_buffer_allocate_info.commandBufferCount = 2;
17670 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17671 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17672
17673 VkQueue queue = VK_NULL_HANDLE;
17674 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17675
17676 uint32_t qfi = 0;
17677 VkBufferCreateInfo buff_create_info = {};
17678 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17679 buff_create_info.size = 1024;
17680 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17681 buff_create_info.queueFamilyIndexCount = 1;
17682 buff_create_info.pQueueFamilyIndices = &qfi;
17683
17684 VkResult err;
17685 VkBuffer buffer;
17686 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17687 ASSERT_VK_SUCCESS(err);
17688 VkMemoryAllocateInfo mem_alloc = {};
17689 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17690 mem_alloc.pNext = NULL;
17691 mem_alloc.allocationSize = 1024;
17692 mem_alloc.memoryTypeIndex = 0;
17693
17694 VkMemoryRequirements memReqs;
17695 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17696 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17697 if (!pass) {
17698 vkDestroyBuffer(m_device->device(), buffer, NULL);
17699 return;
17700 }
17701
17702 VkDeviceMemory mem;
17703 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17704 ASSERT_VK_SUCCESS(err);
17705 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17706 ASSERT_VK_SUCCESS(err);
17707
17708 {
17709 VkCommandBufferBeginInfo begin_info{};
17710 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17711 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17712
17713 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17714 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17715
17716 vkEndCommandBuffer(command_buffer[0]);
17717
17718 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17719
17720 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17721
17722 vkEndCommandBuffer(command_buffer[1]);
17723 }
17724 {
17725 VkSubmitInfo submit_info{};
17726 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17727 submit_info.commandBufferCount = 2;
17728 submit_info.pCommandBuffers = command_buffer;
17729 submit_info.signalSemaphoreCount = 0;
17730 submit_info.pSignalSemaphores = nullptr;
17731 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17732 }
17733
17734 vkQueueWaitIdle(queue);
17735
17736 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17737 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17738 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17739 vkDestroyBuffer(m_device->device(), buffer, NULL);
17740 vkFreeMemory(m_device->device(), mem, NULL);
17741
17742 m_errorMonitor->VerifyNotFound();
17743}
17744
Tony Barbourc46924f2016-11-04 11:49:52 -060017745TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017746 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17747
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017748 ASSERT_NO_FATAL_FAILURE(InitState());
17749 VkEvent event;
17750 VkEventCreateInfo event_create_info{};
17751 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17752 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17753
17754 VkCommandPool command_pool;
17755 VkCommandPoolCreateInfo pool_create_info{};
17756 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17757 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17758 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17759 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17760
17761 VkCommandBuffer command_buffer;
17762 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17763 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17764 command_buffer_allocate_info.commandPool = command_pool;
17765 command_buffer_allocate_info.commandBufferCount = 1;
17766 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17767 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17768
17769 VkQueue queue = VK_NULL_HANDLE;
17770 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17771
17772 {
17773 VkCommandBufferBeginInfo begin_info{};
17774 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17775 vkBeginCommandBuffer(command_buffer, &begin_info);
17776
17777 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017778 vkEndCommandBuffer(command_buffer);
17779 }
17780 {
17781 VkSubmitInfo submit_info{};
17782 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17783 submit_info.commandBufferCount = 1;
17784 submit_info.pCommandBuffers = &command_buffer;
17785 submit_info.signalSemaphoreCount = 0;
17786 submit_info.pSignalSemaphores = nullptr;
17787 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17788 }
17789 {
17790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17791 "command buffer.");
17792 vkSetEvent(m_device->device(), event);
17793 m_errorMonitor->VerifyFound();
17794 }
17795
17796 vkQueueWaitIdle(queue);
17797
17798 vkDestroyEvent(m_device->device(), event, nullptr);
17799 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17800 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17801}
17802
17803// This is a positive test. No errors should be generated.
17804TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17805 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17806 "run through a Submit & WaitForFences cycle 3 times. This "
17807 "previously revealed a bug so running this positive test "
17808 "to prevent a regression.");
17809 m_errorMonitor->ExpectSuccess();
17810
17811 ASSERT_NO_FATAL_FAILURE(InitState());
17812 VkQueue queue = VK_NULL_HANDLE;
17813 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17814
17815 static const uint32_t NUM_OBJECTS = 2;
17816 static const uint32_t NUM_FRAMES = 3;
17817 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17818 VkFence fences[NUM_OBJECTS] = {};
17819
17820 VkCommandPool cmd_pool;
17821 VkCommandPoolCreateInfo cmd_pool_ci = {};
17822 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17823 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17824 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17825 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17826 ASSERT_VK_SUCCESS(err);
17827
17828 VkCommandBufferAllocateInfo cmd_buf_info = {};
17829 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17830 cmd_buf_info.commandPool = cmd_pool;
17831 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17832 cmd_buf_info.commandBufferCount = 1;
17833
17834 VkFenceCreateInfo fence_ci = {};
17835 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17836 fence_ci.pNext = nullptr;
17837 fence_ci.flags = 0;
17838
17839 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17840 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17841 ASSERT_VK_SUCCESS(err);
17842 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17843 ASSERT_VK_SUCCESS(err);
17844 }
17845
17846 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17847 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17848 // Create empty cmd buffer
17849 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17850 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17851
17852 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17853 ASSERT_VK_SUCCESS(err);
17854 err = vkEndCommandBuffer(cmd_buffers[obj]);
17855 ASSERT_VK_SUCCESS(err);
17856
17857 VkSubmitInfo submit_info = {};
17858 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17859 submit_info.commandBufferCount = 1;
17860 submit_info.pCommandBuffers = &cmd_buffers[obj];
17861 // Submit cmd buffer and wait for fence
17862 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17863 ASSERT_VK_SUCCESS(err);
17864 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17865 ASSERT_VK_SUCCESS(err);
17866 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17867 ASSERT_VK_SUCCESS(err);
17868 }
17869 }
17870 m_errorMonitor->VerifyNotFound();
17871 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17872 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17873 vkDestroyFence(m_device->device(), fences[i], nullptr);
17874 }
17875}
17876// This is a positive test. No errors should be generated.
17877TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17878
17879 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17880 "submitted on separate queues followed by a QueueWaitIdle.");
17881
17882 ASSERT_NO_FATAL_FAILURE(InitState());
17883 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17884 return;
17885
17886 m_errorMonitor->ExpectSuccess();
17887
17888 VkSemaphore semaphore;
17889 VkSemaphoreCreateInfo semaphore_create_info{};
17890 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17891 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17892
17893 VkCommandPool command_pool;
17894 VkCommandPoolCreateInfo pool_create_info{};
17895 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17896 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17897 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17898 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17899
17900 VkCommandBuffer command_buffer[2];
17901 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17902 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17903 command_buffer_allocate_info.commandPool = command_pool;
17904 command_buffer_allocate_info.commandBufferCount = 2;
17905 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17906 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17907
17908 VkQueue queue = VK_NULL_HANDLE;
17909 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17910
17911 {
17912 VkCommandBufferBeginInfo begin_info{};
17913 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17914 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17915
17916 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17917 nullptr, 0, nullptr, 0, nullptr);
17918
17919 VkViewport viewport{};
17920 viewport.maxDepth = 1.0f;
17921 viewport.minDepth = 0.0f;
17922 viewport.width = 512;
17923 viewport.height = 512;
17924 viewport.x = 0;
17925 viewport.y = 0;
17926 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17927 vkEndCommandBuffer(command_buffer[0]);
17928 }
17929 {
17930 VkCommandBufferBeginInfo begin_info{};
17931 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17932 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17933
17934 VkViewport viewport{};
17935 viewport.maxDepth = 1.0f;
17936 viewport.minDepth = 0.0f;
17937 viewport.width = 512;
17938 viewport.height = 512;
17939 viewport.x = 0;
17940 viewport.y = 0;
17941 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17942 vkEndCommandBuffer(command_buffer[1]);
17943 }
17944 {
17945 VkSubmitInfo submit_info{};
17946 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17947 submit_info.commandBufferCount = 1;
17948 submit_info.pCommandBuffers = &command_buffer[0];
17949 submit_info.signalSemaphoreCount = 1;
17950 submit_info.pSignalSemaphores = &semaphore;
17951 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17952 }
17953 {
17954 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17955 VkSubmitInfo submit_info{};
17956 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17957 submit_info.commandBufferCount = 1;
17958 submit_info.pCommandBuffers = &command_buffer[1];
17959 submit_info.waitSemaphoreCount = 1;
17960 submit_info.pWaitSemaphores = &semaphore;
17961 submit_info.pWaitDstStageMask = flags;
17962 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17963 }
17964
17965 vkQueueWaitIdle(m_device->m_queue);
17966
17967 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17968 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17969 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17970
17971 m_errorMonitor->VerifyNotFound();
17972}
17973
17974// This is a positive test. No errors should be generated.
17975TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
17976
17977 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17978 "submitted on separate queues, the second having a fence"
17979 "followed by a QueueWaitIdle.");
17980
17981 ASSERT_NO_FATAL_FAILURE(InitState());
17982 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17983 return;
17984
17985 m_errorMonitor->ExpectSuccess();
17986
17987 VkFence fence;
17988 VkFenceCreateInfo fence_create_info{};
17989 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17990 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17991
17992 VkSemaphore semaphore;
17993 VkSemaphoreCreateInfo semaphore_create_info{};
17994 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17995 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17996
17997 VkCommandPool command_pool;
17998 VkCommandPoolCreateInfo pool_create_info{};
17999 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18000 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18001 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18002 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18003
18004 VkCommandBuffer command_buffer[2];
18005 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18006 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18007 command_buffer_allocate_info.commandPool = command_pool;
18008 command_buffer_allocate_info.commandBufferCount = 2;
18009 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18010 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18011
18012 VkQueue queue = VK_NULL_HANDLE;
18013 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18014
18015 {
18016 VkCommandBufferBeginInfo begin_info{};
18017 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18018 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18019
18020 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18021 nullptr, 0, nullptr, 0, nullptr);
18022
18023 VkViewport viewport{};
18024 viewport.maxDepth = 1.0f;
18025 viewport.minDepth = 0.0f;
18026 viewport.width = 512;
18027 viewport.height = 512;
18028 viewport.x = 0;
18029 viewport.y = 0;
18030 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18031 vkEndCommandBuffer(command_buffer[0]);
18032 }
18033 {
18034 VkCommandBufferBeginInfo begin_info{};
18035 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18036 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18037
18038 VkViewport viewport{};
18039 viewport.maxDepth = 1.0f;
18040 viewport.minDepth = 0.0f;
18041 viewport.width = 512;
18042 viewport.height = 512;
18043 viewport.x = 0;
18044 viewport.y = 0;
18045 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18046 vkEndCommandBuffer(command_buffer[1]);
18047 }
18048 {
18049 VkSubmitInfo submit_info{};
18050 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18051 submit_info.commandBufferCount = 1;
18052 submit_info.pCommandBuffers = &command_buffer[0];
18053 submit_info.signalSemaphoreCount = 1;
18054 submit_info.pSignalSemaphores = &semaphore;
18055 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18056 }
18057 {
18058 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18059 VkSubmitInfo submit_info{};
18060 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18061 submit_info.commandBufferCount = 1;
18062 submit_info.pCommandBuffers = &command_buffer[1];
18063 submit_info.waitSemaphoreCount = 1;
18064 submit_info.pWaitSemaphores = &semaphore;
18065 submit_info.pWaitDstStageMask = flags;
18066 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18067 }
18068
18069 vkQueueWaitIdle(m_device->m_queue);
18070
18071 vkDestroyFence(m_device->device(), fence, nullptr);
18072 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18073 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18074 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18075
18076 m_errorMonitor->VerifyNotFound();
18077}
18078
18079// This is a positive test. No errors should be generated.
18080TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18081
18082 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18083 "submitted on separate queues, the second having a fence"
18084 "followed by two consecutive WaitForFences calls on the same fence.");
18085
18086 ASSERT_NO_FATAL_FAILURE(InitState());
18087 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18088 return;
18089
18090 m_errorMonitor->ExpectSuccess();
18091
18092 VkFence fence;
18093 VkFenceCreateInfo fence_create_info{};
18094 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18095 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18096
18097 VkSemaphore semaphore;
18098 VkSemaphoreCreateInfo semaphore_create_info{};
18099 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18100 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18101
18102 VkCommandPool command_pool;
18103 VkCommandPoolCreateInfo pool_create_info{};
18104 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18105 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18106 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18107 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18108
18109 VkCommandBuffer command_buffer[2];
18110 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18111 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18112 command_buffer_allocate_info.commandPool = command_pool;
18113 command_buffer_allocate_info.commandBufferCount = 2;
18114 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18115 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18116
18117 VkQueue queue = VK_NULL_HANDLE;
18118 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18119
18120 {
18121 VkCommandBufferBeginInfo begin_info{};
18122 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18123 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18124
18125 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18126 nullptr, 0, nullptr, 0, nullptr);
18127
18128 VkViewport viewport{};
18129 viewport.maxDepth = 1.0f;
18130 viewport.minDepth = 0.0f;
18131 viewport.width = 512;
18132 viewport.height = 512;
18133 viewport.x = 0;
18134 viewport.y = 0;
18135 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18136 vkEndCommandBuffer(command_buffer[0]);
18137 }
18138 {
18139 VkCommandBufferBeginInfo begin_info{};
18140 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18141 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18142
18143 VkViewport viewport{};
18144 viewport.maxDepth = 1.0f;
18145 viewport.minDepth = 0.0f;
18146 viewport.width = 512;
18147 viewport.height = 512;
18148 viewport.x = 0;
18149 viewport.y = 0;
18150 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18151 vkEndCommandBuffer(command_buffer[1]);
18152 }
18153 {
18154 VkSubmitInfo submit_info{};
18155 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18156 submit_info.commandBufferCount = 1;
18157 submit_info.pCommandBuffers = &command_buffer[0];
18158 submit_info.signalSemaphoreCount = 1;
18159 submit_info.pSignalSemaphores = &semaphore;
18160 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18161 }
18162 {
18163 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18164 VkSubmitInfo submit_info{};
18165 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18166 submit_info.commandBufferCount = 1;
18167 submit_info.pCommandBuffers = &command_buffer[1];
18168 submit_info.waitSemaphoreCount = 1;
18169 submit_info.pWaitSemaphores = &semaphore;
18170 submit_info.pWaitDstStageMask = flags;
18171 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18172 }
18173
18174 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18175 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18176
18177 vkDestroyFence(m_device->device(), fence, nullptr);
18178 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18179 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18180 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18181
18182 m_errorMonitor->VerifyNotFound();
18183}
18184
18185TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18186
18187 ASSERT_NO_FATAL_FAILURE(InitState());
18188 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18189 printf("Test requires two queues, skipping\n");
18190 return;
18191 }
18192
18193 VkResult err;
18194
18195 m_errorMonitor->ExpectSuccess();
18196
18197 VkQueue q0 = m_device->m_queue;
18198 VkQueue q1 = nullptr;
18199 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18200 ASSERT_NE(q1, nullptr);
18201
18202 // An (empty) command buffer. We must have work in the first submission --
18203 // the layer treats unfenced work differently from fenced work.
18204 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18205 VkCommandPool pool;
18206 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18207 ASSERT_VK_SUCCESS(err);
18208 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18209 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18210 VkCommandBuffer cb;
18211 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18212 ASSERT_VK_SUCCESS(err);
18213 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18214 err = vkBeginCommandBuffer(cb, &cbbi);
18215 ASSERT_VK_SUCCESS(err);
18216 err = vkEndCommandBuffer(cb);
18217 ASSERT_VK_SUCCESS(err);
18218
18219 // A semaphore
18220 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18221 VkSemaphore s;
18222 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18223 ASSERT_VK_SUCCESS(err);
18224
18225 // First submission, to q0
18226 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18227
18228 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18229 ASSERT_VK_SUCCESS(err);
18230
18231 // Second submission, to q1, waiting on s
18232 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18233 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18234
18235 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18236 ASSERT_VK_SUCCESS(err);
18237
18238 // Wait for q0 idle
18239 err = vkQueueWaitIdle(q0);
18240 ASSERT_VK_SUCCESS(err);
18241
18242 // Command buffer should have been completed (it was on q0); reset the pool.
18243 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18244
18245 m_errorMonitor->VerifyNotFound();
18246
18247 // Force device completely idle and clean up resources
18248 vkDeviceWaitIdle(m_device->device());
18249 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18250 vkDestroySemaphore(m_device->device(), s, nullptr);
18251}
18252
18253// This is a positive test. No errors should be generated.
18254TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18255
18256 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18257 "submitted on separate queues, the second having a fence, "
18258 "followed by a WaitForFences call.");
18259
18260 ASSERT_NO_FATAL_FAILURE(InitState());
18261 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18262 return;
18263
18264 m_errorMonitor->ExpectSuccess();
18265
18266 ASSERT_NO_FATAL_FAILURE(InitState());
18267 VkFence fence;
18268 VkFenceCreateInfo fence_create_info{};
18269 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18270 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18271
18272 VkSemaphore semaphore;
18273 VkSemaphoreCreateInfo semaphore_create_info{};
18274 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18275 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18276
18277 VkCommandPool command_pool;
18278 VkCommandPoolCreateInfo pool_create_info{};
18279 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18280 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18281 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18282 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18283
18284 VkCommandBuffer command_buffer[2];
18285 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18286 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18287 command_buffer_allocate_info.commandPool = command_pool;
18288 command_buffer_allocate_info.commandBufferCount = 2;
18289 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18290 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18291
18292 VkQueue queue = VK_NULL_HANDLE;
18293 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18294
18295 {
18296 VkCommandBufferBeginInfo begin_info{};
18297 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18298 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18299
18300 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18301 nullptr, 0, nullptr, 0, nullptr);
18302
18303 VkViewport viewport{};
18304 viewport.maxDepth = 1.0f;
18305 viewport.minDepth = 0.0f;
18306 viewport.width = 512;
18307 viewport.height = 512;
18308 viewport.x = 0;
18309 viewport.y = 0;
18310 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18311 vkEndCommandBuffer(command_buffer[0]);
18312 }
18313 {
18314 VkCommandBufferBeginInfo begin_info{};
18315 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18316 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18317
18318 VkViewport viewport{};
18319 viewport.maxDepth = 1.0f;
18320 viewport.minDepth = 0.0f;
18321 viewport.width = 512;
18322 viewport.height = 512;
18323 viewport.x = 0;
18324 viewport.y = 0;
18325 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18326 vkEndCommandBuffer(command_buffer[1]);
18327 }
18328 {
18329 VkSubmitInfo submit_info{};
18330 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18331 submit_info.commandBufferCount = 1;
18332 submit_info.pCommandBuffers = &command_buffer[0];
18333 submit_info.signalSemaphoreCount = 1;
18334 submit_info.pSignalSemaphores = &semaphore;
18335 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18336 }
18337 {
18338 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18339 VkSubmitInfo submit_info{};
18340 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18341 submit_info.commandBufferCount = 1;
18342 submit_info.pCommandBuffers = &command_buffer[1];
18343 submit_info.waitSemaphoreCount = 1;
18344 submit_info.pWaitSemaphores = &semaphore;
18345 submit_info.pWaitDstStageMask = flags;
18346 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18347 }
18348
18349 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18350
18351 vkDestroyFence(m_device->device(), fence, nullptr);
18352 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18353 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18354 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18355
18356 m_errorMonitor->VerifyNotFound();
18357}
18358
18359// This is a positive test. No errors should be generated.
18360TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18361
18362 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18363 "on the same queue, sharing a signal/wait semaphore, the "
18364 "second having a fence, "
18365 "followed by a WaitForFences call.");
18366
18367 m_errorMonitor->ExpectSuccess();
18368
18369 ASSERT_NO_FATAL_FAILURE(InitState());
18370 VkFence fence;
18371 VkFenceCreateInfo fence_create_info{};
18372 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18373 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18374
18375 VkSemaphore semaphore;
18376 VkSemaphoreCreateInfo semaphore_create_info{};
18377 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18378 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18379
18380 VkCommandPool command_pool;
18381 VkCommandPoolCreateInfo pool_create_info{};
18382 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18383 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18384 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18385 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18386
18387 VkCommandBuffer command_buffer[2];
18388 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18389 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18390 command_buffer_allocate_info.commandPool = command_pool;
18391 command_buffer_allocate_info.commandBufferCount = 2;
18392 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18393 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18394
18395 {
18396 VkCommandBufferBeginInfo begin_info{};
18397 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18398 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18399
18400 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18401 nullptr, 0, nullptr, 0, nullptr);
18402
18403 VkViewport viewport{};
18404 viewport.maxDepth = 1.0f;
18405 viewport.minDepth = 0.0f;
18406 viewport.width = 512;
18407 viewport.height = 512;
18408 viewport.x = 0;
18409 viewport.y = 0;
18410 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18411 vkEndCommandBuffer(command_buffer[0]);
18412 }
18413 {
18414 VkCommandBufferBeginInfo begin_info{};
18415 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18416 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18417
18418 VkViewport viewport{};
18419 viewport.maxDepth = 1.0f;
18420 viewport.minDepth = 0.0f;
18421 viewport.width = 512;
18422 viewport.height = 512;
18423 viewport.x = 0;
18424 viewport.y = 0;
18425 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18426 vkEndCommandBuffer(command_buffer[1]);
18427 }
18428 {
18429 VkSubmitInfo submit_info{};
18430 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18431 submit_info.commandBufferCount = 1;
18432 submit_info.pCommandBuffers = &command_buffer[0];
18433 submit_info.signalSemaphoreCount = 1;
18434 submit_info.pSignalSemaphores = &semaphore;
18435 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18436 }
18437 {
18438 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18439 VkSubmitInfo submit_info{};
18440 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18441 submit_info.commandBufferCount = 1;
18442 submit_info.pCommandBuffers = &command_buffer[1];
18443 submit_info.waitSemaphoreCount = 1;
18444 submit_info.pWaitSemaphores = &semaphore;
18445 submit_info.pWaitDstStageMask = flags;
18446 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18447 }
18448
18449 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18450
18451 vkDestroyFence(m_device->device(), fence, nullptr);
18452 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18453 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18454 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18455
18456 m_errorMonitor->VerifyNotFound();
18457}
18458
18459// This is a positive test. No errors should be generated.
18460TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18461
18462 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18463 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18464 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18465
18466 m_errorMonitor->ExpectSuccess();
18467
18468 ASSERT_NO_FATAL_FAILURE(InitState());
18469 VkFence fence;
18470 VkFenceCreateInfo fence_create_info{};
18471 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18472 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18473
18474 VkCommandPool command_pool;
18475 VkCommandPoolCreateInfo pool_create_info{};
18476 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18477 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18478 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18479 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18480
18481 VkCommandBuffer command_buffer[2];
18482 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18483 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18484 command_buffer_allocate_info.commandPool = command_pool;
18485 command_buffer_allocate_info.commandBufferCount = 2;
18486 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18487 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18488
18489 {
18490 VkCommandBufferBeginInfo begin_info{};
18491 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18492 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18493
18494 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18495 nullptr, 0, nullptr, 0, nullptr);
18496
18497 VkViewport viewport{};
18498 viewport.maxDepth = 1.0f;
18499 viewport.minDepth = 0.0f;
18500 viewport.width = 512;
18501 viewport.height = 512;
18502 viewport.x = 0;
18503 viewport.y = 0;
18504 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18505 vkEndCommandBuffer(command_buffer[0]);
18506 }
18507 {
18508 VkCommandBufferBeginInfo begin_info{};
18509 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18510 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18511
18512 VkViewport viewport{};
18513 viewport.maxDepth = 1.0f;
18514 viewport.minDepth = 0.0f;
18515 viewport.width = 512;
18516 viewport.height = 512;
18517 viewport.x = 0;
18518 viewport.y = 0;
18519 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18520 vkEndCommandBuffer(command_buffer[1]);
18521 }
18522 {
18523 VkSubmitInfo submit_info{};
18524 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18525 submit_info.commandBufferCount = 1;
18526 submit_info.pCommandBuffers = &command_buffer[0];
18527 submit_info.signalSemaphoreCount = 0;
18528 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18529 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18530 }
18531 {
18532 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18533 VkSubmitInfo submit_info{};
18534 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18535 submit_info.commandBufferCount = 1;
18536 submit_info.pCommandBuffers = &command_buffer[1];
18537 submit_info.waitSemaphoreCount = 0;
18538 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18539 submit_info.pWaitDstStageMask = flags;
18540 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18541 }
18542
18543 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18544
18545 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18546 ASSERT_VK_SUCCESS(err);
18547
18548 vkDestroyFence(m_device->device(), fence, nullptr);
18549 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18550 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18551
18552 m_errorMonitor->VerifyNotFound();
18553}
18554
18555// This is a positive test. No errors should be generated.
18556TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18557
18558 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18559 "on the same queue, the second having a fence, followed "
18560 "by a WaitForFences call.");
18561
18562 m_errorMonitor->ExpectSuccess();
18563
18564 ASSERT_NO_FATAL_FAILURE(InitState());
18565 VkFence fence;
18566 VkFenceCreateInfo fence_create_info{};
18567 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18568 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18569
18570 VkCommandPool command_pool;
18571 VkCommandPoolCreateInfo pool_create_info{};
18572 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18573 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18574 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18575 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18576
18577 VkCommandBuffer command_buffer[2];
18578 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18579 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18580 command_buffer_allocate_info.commandPool = command_pool;
18581 command_buffer_allocate_info.commandBufferCount = 2;
18582 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18583 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18584
18585 {
18586 VkCommandBufferBeginInfo begin_info{};
18587 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18588 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18589
18590 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18591 nullptr, 0, nullptr, 0, nullptr);
18592
18593 VkViewport viewport{};
18594 viewport.maxDepth = 1.0f;
18595 viewport.minDepth = 0.0f;
18596 viewport.width = 512;
18597 viewport.height = 512;
18598 viewport.x = 0;
18599 viewport.y = 0;
18600 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18601 vkEndCommandBuffer(command_buffer[0]);
18602 }
18603 {
18604 VkCommandBufferBeginInfo begin_info{};
18605 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18606 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18607
18608 VkViewport viewport{};
18609 viewport.maxDepth = 1.0f;
18610 viewport.minDepth = 0.0f;
18611 viewport.width = 512;
18612 viewport.height = 512;
18613 viewport.x = 0;
18614 viewport.y = 0;
18615 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18616 vkEndCommandBuffer(command_buffer[1]);
18617 }
18618 {
18619 VkSubmitInfo submit_info{};
18620 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18621 submit_info.commandBufferCount = 1;
18622 submit_info.pCommandBuffers = &command_buffer[0];
18623 submit_info.signalSemaphoreCount = 0;
18624 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18625 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18626 }
18627 {
18628 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18629 VkSubmitInfo submit_info{};
18630 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18631 submit_info.commandBufferCount = 1;
18632 submit_info.pCommandBuffers = &command_buffer[1];
18633 submit_info.waitSemaphoreCount = 0;
18634 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18635 submit_info.pWaitDstStageMask = flags;
18636 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18637 }
18638
18639 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18640
18641 vkDestroyFence(m_device->device(), fence, nullptr);
18642 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18643 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18644
18645 m_errorMonitor->VerifyNotFound();
18646}
18647
18648// This is a positive test. No errors should be generated.
18649TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18650
18651 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18652 "QueueSubmit call followed by a WaitForFences call.");
18653 ASSERT_NO_FATAL_FAILURE(InitState());
18654
18655 m_errorMonitor->ExpectSuccess();
18656
18657 VkFence fence;
18658 VkFenceCreateInfo fence_create_info{};
18659 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18660 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18661
18662 VkSemaphore semaphore;
18663 VkSemaphoreCreateInfo semaphore_create_info{};
18664 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18665 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18666
18667 VkCommandPool command_pool;
18668 VkCommandPoolCreateInfo pool_create_info{};
18669 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18670 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18671 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18672 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18673
18674 VkCommandBuffer command_buffer[2];
18675 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18676 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18677 command_buffer_allocate_info.commandPool = command_pool;
18678 command_buffer_allocate_info.commandBufferCount = 2;
18679 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18680 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18681
18682 {
18683 VkCommandBufferBeginInfo begin_info{};
18684 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18685 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18686
18687 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18688 nullptr, 0, nullptr, 0, nullptr);
18689
18690 VkViewport viewport{};
18691 viewport.maxDepth = 1.0f;
18692 viewport.minDepth = 0.0f;
18693 viewport.width = 512;
18694 viewport.height = 512;
18695 viewport.x = 0;
18696 viewport.y = 0;
18697 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18698 vkEndCommandBuffer(command_buffer[0]);
18699 }
18700 {
18701 VkCommandBufferBeginInfo begin_info{};
18702 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18703 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18704
18705 VkViewport viewport{};
18706 viewport.maxDepth = 1.0f;
18707 viewport.minDepth = 0.0f;
18708 viewport.width = 512;
18709 viewport.height = 512;
18710 viewport.x = 0;
18711 viewport.y = 0;
18712 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18713 vkEndCommandBuffer(command_buffer[1]);
18714 }
18715 {
18716 VkSubmitInfo submit_info[2];
18717 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18718
18719 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18720 submit_info[0].pNext = NULL;
18721 submit_info[0].commandBufferCount = 1;
18722 submit_info[0].pCommandBuffers = &command_buffer[0];
18723 submit_info[0].signalSemaphoreCount = 1;
18724 submit_info[0].pSignalSemaphores = &semaphore;
18725 submit_info[0].waitSemaphoreCount = 0;
18726 submit_info[0].pWaitSemaphores = NULL;
18727 submit_info[0].pWaitDstStageMask = 0;
18728
18729 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18730 submit_info[1].pNext = NULL;
18731 submit_info[1].commandBufferCount = 1;
18732 submit_info[1].pCommandBuffers = &command_buffer[1];
18733 submit_info[1].waitSemaphoreCount = 1;
18734 submit_info[1].pWaitSemaphores = &semaphore;
18735 submit_info[1].pWaitDstStageMask = flags;
18736 submit_info[1].signalSemaphoreCount = 0;
18737 submit_info[1].pSignalSemaphores = NULL;
18738 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18739 }
18740
18741 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18742
18743 vkDestroyFence(m_device->device(), fence, nullptr);
18744 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18745 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18746 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18747
18748 m_errorMonitor->VerifyNotFound();
18749}
18750
18751TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18752 m_errorMonitor->ExpectSuccess();
18753
18754 ASSERT_NO_FATAL_FAILURE(InitState());
18755 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18756
18757 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18758 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18759
18760 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18761 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18762 m_errorMonitor->VerifyNotFound();
18763 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18764 m_errorMonitor->VerifyNotFound();
18765 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18766 m_errorMonitor->VerifyNotFound();
18767
18768 m_commandBuffer->EndCommandBuffer();
18769 m_errorMonitor->VerifyNotFound();
18770}
18771
18772TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18773 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18774 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18775 "has a valid layout, and a second subpass then uses a "
18776 "valid *READ_ONLY* layout.");
18777 m_errorMonitor->ExpectSuccess();
18778 ASSERT_NO_FATAL_FAILURE(InitState());
18779
18780 VkAttachmentReference attach[2] = {};
18781 attach[0].attachment = 0;
18782 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18783 attach[1].attachment = 0;
18784 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18785 VkSubpassDescription subpasses[2] = {};
18786 // First subpass clears DS attach on load
18787 subpasses[0].pDepthStencilAttachment = &attach[0];
18788 // 2nd subpass reads in DS as input attachment
18789 subpasses[1].inputAttachmentCount = 1;
18790 subpasses[1].pInputAttachments = &attach[1];
18791 VkAttachmentDescription attach_desc = {};
18792 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18793 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18794 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18795 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18796 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18797 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18798 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18799 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18800 VkRenderPassCreateInfo rpci = {};
18801 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18802 rpci.attachmentCount = 1;
18803 rpci.pAttachments = &attach_desc;
18804 rpci.subpassCount = 2;
18805 rpci.pSubpasses = subpasses;
18806
18807 // Now create RenderPass and verify no errors
18808 VkRenderPass rp;
18809 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18810 m_errorMonitor->VerifyNotFound();
18811
18812 vkDestroyRenderPass(m_device->device(), rp, NULL);
18813}
18814
18815TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18816 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18817 "as vertex attributes");
18818 m_errorMonitor->ExpectSuccess();
18819
18820 ASSERT_NO_FATAL_FAILURE(InitState());
18821 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18822
18823 VkVertexInputBindingDescription input_binding;
18824 memset(&input_binding, 0, sizeof(input_binding));
18825
18826 VkVertexInputAttributeDescription input_attribs[2];
18827 memset(input_attribs, 0, sizeof(input_attribs));
18828
18829 for (int i = 0; i < 2; i++) {
18830 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18831 input_attribs[i].location = i;
18832 }
18833
18834 char const *vsSource = "#version 450\n"
18835 "\n"
18836 "layout(location=0) in mat2x4 x;\n"
18837 "out gl_PerVertex {\n"
18838 " vec4 gl_Position;\n"
18839 "};\n"
18840 "void main(){\n"
18841 " gl_Position = x[0] + x[1];\n"
18842 "}\n";
18843 char const *fsSource = "#version 450\n"
18844 "\n"
18845 "layout(location=0) out vec4 color;\n"
18846 "void main(){\n"
18847 " color = vec4(1);\n"
18848 "}\n";
18849
18850 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18851 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18852
18853 VkPipelineObj pipe(m_device);
18854 pipe.AddColorAttachment();
18855 pipe.AddShader(&vs);
18856 pipe.AddShader(&fs);
18857
18858 pipe.AddVertexInputBindings(&input_binding, 1);
18859 pipe.AddVertexInputAttribs(input_attribs, 2);
18860
18861 VkDescriptorSetObj descriptorSet(m_device);
18862 descriptorSet.AppendDummy();
18863 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18864
18865 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18866
18867 /* expect success */
18868 m_errorMonitor->VerifyNotFound();
18869}
18870
18871TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18872 m_errorMonitor->ExpectSuccess();
18873
18874 ASSERT_NO_FATAL_FAILURE(InitState());
18875 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18876
18877 VkVertexInputBindingDescription input_binding;
18878 memset(&input_binding, 0, sizeof(input_binding));
18879
18880 VkVertexInputAttributeDescription input_attribs[2];
18881 memset(input_attribs, 0, sizeof(input_attribs));
18882
18883 for (int i = 0; i < 2; i++) {
18884 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18885 input_attribs[i].location = i;
18886 }
18887
18888 char const *vsSource = "#version 450\n"
18889 "\n"
18890 "layout(location=0) in vec4 x[2];\n"
18891 "out gl_PerVertex {\n"
18892 " vec4 gl_Position;\n"
18893 "};\n"
18894 "void main(){\n"
18895 " gl_Position = x[0] + x[1];\n"
18896 "}\n";
18897 char const *fsSource = "#version 450\n"
18898 "\n"
18899 "layout(location=0) out vec4 color;\n"
18900 "void main(){\n"
18901 " color = vec4(1);\n"
18902 "}\n";
18903
18904 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18905 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18906
18907 VkPipelineObj pipe(m_device);
18908 pipe.AddColorAttachment();
18909 pipe.AddShader(&vs);
18910 pipe.AddShader(&fs);
18911
18912 pipe.AddVertexInputBindings(&input_binding, 1);
18913 pipe.AddVertexInputAttribs(input_attribs, 2);
18914
18915 VkDescriptorSetObj descriptorSet(m_device);
18916 descriptorSet.AppendDummy();
18917 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18918
18919 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18920
18921 m_errorMonitor->VerifyNotFound();
18922}
18923
18924TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18925 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18926 "through multiple vertex shader inputs, each consuming a different "
18927 "subset of the components.");
18928 m_errorMonitor->ExpectSuccess();
18929
18930 ASSERT_NO_FATAL_FAILURE(InitState());
18931 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18932
18933 VkVertexInputBindingDescription input_binding;
18934 memset(&input_binding, 0, sizeof(input_binding));
18935
18936 VkVertexInputAttributeDescription input_attribs[3];
18937 memset(input_attribs, 0, sizeof(input_attribs));
18938
18939 for (int i = 0; i < 3; i++) {
18940 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18941 input_attribs[i].location = i;
18942 }
18943
18944 char const *vsSource = "#version 450\n"
18945 "\n"
18946 "layout(location=0) in vec4 x;\n"
18947 "layout(location=1) in vec3 y1;\n"
18948 "layout(location=1, component=3) in float y2;\n"
18949 "layout(location=2) in vec4 z;\n"
18950 "out gl_PerVertex {\n"
18951 " vec4 gl_Position;\n"
18952 "};\n"
18953 "void main(){\n"
18954 " gl_Position = x + vec4(y1, y2) + z;\n"
18955 "}\n";
18956 char const *fsSource = "#version 450\n"
18957 "\n"
18958 "layout(location=0) out vec4 color;\n"
18959 "void main(){\n"
18960 " color = vec4(1);\n"
18961 "}\n";
18962
18963 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18964 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18965
18966 VkPipelineObj pipe(m_device);
18967 pipe.AddColorAttachment();
18968 pipe.AddShader(&vs);
18969 pipe.AddShader(&fs);
18970
18971 pipe.AddVertexInputBindings(&input_binding, 1);
18972 pipe.AddVertexInputAttribs(input_attribs, 3);
18973
18974 VkDescriptorSetObj descriptorSet(m_device);
18975 descriptorSet.AppendDummy();
18976 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18977
18978 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18979
18980 m_errorMonitor->VerifyNotFound();
18981}
18982
18983TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
18984 m_errorMonitor->ExpectSuccess();
18985
18986 ASSERT_NO_FATAL_FAILURE(InitState());
18987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18988
18989 char const *vsSource = "#version 450\n"
18990 "out gl_PerVertex {\n"
18991 " vec4 gl_Position;\n"
18992 "};\n"
18993 "void main(){\n"
18994 " gl_Position = vec4(0);\n"
18995 "}\n";
18996 char const *fsSource = "#version 450\n"
18997 "\n"
18998 "layout(location=0) out vec4 color;\n"
18999 "void main(){\n"
19000 " color = vec4(1);\n"
19001 "}\n";
19002
19003 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19004 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19005
19006 VkPipelineObj pipe(m_device);
19007 pipe.AddColorAttachment();
19008 pipe.AddShader(&vs);
19009 pipe.AddShader(&fs);
19010
19011 VkDescriptorSetObj descriptorSet(m_device);
19012 descriptorSet.AppendDummy();
19013 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19014
19015 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19016
19017 m_errorMonitor->VerifyNotFound();
19018}
19019
19020TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19021 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19022 "set out in 14.1.3: fundamental type must match, and producer side must "
19023 "have at least as many components");
19024 m_errorMonitor->ExpectSuccess();
19025
19026 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19027
19028 ASSERT_NO_FATAL_FAILURE(InitState());
19029 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19030
19031 char const *vsSource = "#version 450\n"
19032 "out gl_PerVertex {\n"
19033 " vec4 gl_Position;\n"
19034 "};\n"
19035 "layout(location=0) out vec3 x;\n"
19036 "layout(location=1) out ivec3 y;\n"
19037 "layout(location=2) out vec3 z;\n"
19038 "void main(){\n"
19039 " gl_Position = vec4(0);\n"
19040 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19041 "}\n";
19042 char const *fsSource = "#version 450\n"
19043 "\n"
19044 "layout(location=0) out vec4 color;\n"
19045 "layout(location=0) in float x;\n"
19046 "layout(location=1) flat in int y;\n"
19047 "layout(location=2) in vec2 z;\n"
19048 "void main(){\n"
19049 " color = vec4(1 + x + y + z.x);\n"
19050 "}\n";
19051
19052 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19053 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19054
19055 VkPipelineObj pipe(m_device);
19056 pipe.AddColorAttachment();
19057 pipe.AddShader(&vs);
19058 pipe.AddShader(&fs);
19059
19060 VkDescriptorSetObj descriptorSet(m_device);
19061 descriptorSet.AppendDummy();
19062 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19063
19064 VkResult err = VK_SUCCESS;
19065 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19066 ASSERT_VK_SUCCESS(err);
19067
19068 m_errorMonitor->VerifyNotFound();
19069}
19070
19071TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19072 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19073 "passed between the TCS and TES stages");
19074 m_errorMonitor->ExpectSuccess();
19075
19076 ASSERT_NO_FATAL_FAILURE(InitState());
19077 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19078
19079 if (!m_device->phy().features().tessellationShader) {
19080 printf("Device does not support tessellation shaders; skipped.\n");
19081 return;
19082 }
19083
19084 char const *vsSource = "#version 450\n"
19085 "void main(){}\n";
19086 char const *tcsSource = "#version 450\n"
19087 "layout(location=0) out int x[];\n"
19088 "layout(vertices=3) out;\n"
19089 "void main(){\n"
19090 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19091 " gl_TessLevelInner[0] = 1;\n"
19092 " x[gl_InvocationID] = gl_InvocationID;\n"
19093 "}\n";
19094 char const *tesSource = "#version 450\n"
19095 "layout(triangles, equal_spacing, cw) in;\n"
19096 "layout(location=0) in int x[];\n"
19097 "out gl_PerVertex { vec4 gl_Position; };\n"
19098 "void main(){\n"
19099 " gl_Position.xyz = gl_TessCoord;\n"
19100 " gl_Position.w = x[0] + x[1] + x[2];\n"
19101 "}\n";
19102 char const *fsSource = "#version 450\n"
19103 "layout(location=0) out vec4 color;\n"
19104 "void main(){\n"
19105 " color = vec4(1);\n"
19106 "}\n";
19107
19108 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19109 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19110 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19111 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19112
19113 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19114 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19115
19116 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19117
19118 VkPipelineObj pipe(m_device);
19119 pipe.SetInputAssembly(&iasci);
19120 pipe.SetTessellation(&tsci);
19121 pipe.AddColorAttachment();
19122 pipe.AddShader(&vs);
19123 pipe.AddShader(&tcs);
19124 pipe.AddShader(&tes);
19125 pipe.AddShader(&fs);
19126
19127 VkDescriptorSetObj descriptorSet(m_device);
19128 descriptorSet.AppendDummy();
19129 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19130
19131 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19132
19133 m_errorMonitor->VerifyNotFound();
19134}
19135
19136TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19137 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19138 "interface block passed into the geometry shader. This "
19139 "is interesting because the 'extra' array level is not "
19140 "present on the member type, but on the block instance.");
19141 m_errorMonitor->ExpectSuccess();
19142
19143 ASSERT_NO_FATAL_FAILURE(InitState());
19144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19145
19146 if (!m_device->phy().features().geometryShader) {
19147 printf("Device does not support geometry shaders; skipped.\n");
19148 return;
19149 }
19150
19151 char const *vsSource = "#version 450\n"
19152 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19153 "void main(){\n"
19154 " vs_out.x = vec4(1);\n"
19155 "}\n";
19156 char const *gsSource = "#version 450\n"
19157 "layout(triangles) in;\n"
19158 "layout(triangle_strip, max_vertices=3) out;\n"
19159 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19160 "out gl_PerVertex { vec4 gl_Position; };\n"
19161 "void main() {\n"
19162 " gl_Position = gs_in[0].x;\n"
19163 " EmitVertex();\n"
19164 "}\n";
19165 char const *fsSource = "#version 450\n"
19166 "layout(location=0) out vec4 color;\n"
19167 "void main(){\n"
19168 " color = vec4(1);\n"
19169 "}\n";
19170
19171 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19172 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19173 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19174
19175 VkPipelineObj pipe(m_device);
19176 pipe.AddColorAttachment();
19177 pipe.AddShader(&vs);
19178 pipe.AddShader(&gs);
19179 pipe.AddShader(&fs);
19180
19181 VkDescriptorSetObj descriptorSet(m_device);
19182 descriptorSet.AppendDummy();
19183 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19184
19185 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19186
19187 m_errorMonitor->VerifyNotFound();
19188}
19189
19190TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19191 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19192 "attributes. This is interesting because they consume multiple "
19193 "locations.");
19194 m_errorMonitor->ExpectSuccess();
19195
19196 ASSERT_NO_FATAL_FAILURE(InitState());
19197 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19198
19199 if (!m_device->phy().features().shaderFloat64) {
19200 printf("Device does not support 64bit vertex attributes; skipped.\n");
19201 return;
19202 }
19203
19204 VkVertexInputBindingDescription input_bindings[1];
19205 memset(input_bindings, 0, sizeof(input_bindings));
19206
19207 VkVertexInputAttributeDescription input_attribs[4];
19208 memset(input_attribs, 0, sizeof(input_attribs));
19209 input_attribs[0].location = 0;
19210 input_attribs[0].offset = 0;
19211 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19212 input_attribs[1].location = 2;
19213 input_attribs[1].offset = 32;
19214 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19215 input_attribs[2].location = 4;
19216 input_attribs[2].offset = 64;
19217 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19218 input_attribs[3].location = 6;
19219 input_attribs[3].offset = 96;
19220 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19221
19222 char const *vsSource = "#version 450\n"
19223 "\n"
19224 "layout(location=0) in dmat4 x;\n"
19225 "out gl_PerVertex {\n"
19226 " vec4 gl_Position;\n"
19227 "};\n"
19228 "void main(){\n"
19229 " gl_Position = vec4(x[0][0]);\n"
19230 "}\n";
19231 char const *fsSource = "#version 450\n"
19232 "\n"
19233 "layout(location=0) out vec4 color;\n"
19234 "void main(){\n"
19235 " color = vec4(1);\n"
19236 "}\n";
19237
19238 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19239 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19240
19241 VkPipelineObj pipe(m_device);
19242 pipe.AddColorAttachment();
19243 pipe.AddShader(&vs);
19244 pipe.AddShader(&fs);
19245
19246 pipe.AddVertexInputBindings(input_bindings, 1);
19247 pipe.AddVertexInputAttribs(input_attribs, 4);
19248
19249 VkDescriptorSetObj descriptorSet(m_device);
19250 descriptorSet.AppendDummy();
19251 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19252
19253 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19254
19255 m_errorMonitor->VerifyNotFound();
19256}
19257
19258TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19259 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19260 m_errorMonitor->ExpectSuccess();
19261
19262 ASSERT_NO_FATAL_FAILURE(InitState());
19263
19264 char const *vsSource = "#version 450\n"
19265 "\n"
19266 "out gl_PerVertex {\n"
19267 " vec4 gl_Position;\n"
19268 "};\n"
19269 "void main(){\n"
19270 " gl_Position = vec4(1);\n"
19271 "}\n";
19272 char const *fsSource = "#version 450\n"
19273 "\n"
19274 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19275 "layout(location=0) out vec4 color;\n"
19276 "void main() {\n"
19277 " color = subpassLoad(x);\n"
19278 "}\n";
19279
19280 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19281 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19282
19283 VkPipelineObj pipe(m_device);
19284 pipe.AddShader(&vs);
19285 pipe.AddShader(&fs);
19286 pipe.AddColorAttachment();
19287 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19288
19289 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19290 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19291 VkDescriptorSetLayout dsl;
19292 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19293 ASSERT_VK_SUCCESS(err);
19294
19295 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19296 VkPipelineLayout pl;
19297 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19298 ASSERT_VK_SUCCESS(err);
19299
19300 VkAttachmentDescription descs[2] = {
19301 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19302 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19303 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19304 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19305 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19306 };
19307 VkAttachmentReference color = {
19308 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19309 };
19310 VkAttachmentReference input = {
19311 1, VK_IMAGE_LAYOUT_GENERAL,
19312 };
19313
19314 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19315
19316 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19317 VkRenderPass rp;
19318 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19319 ASSERT_VK_SUCCESS(err);
19320
19321 // should be OK. would go wrong here if it's going to...
19322 pipe.CreateVKPipeline(pl, rp);
19323
19324 m_errorMonitor->VerifyNotFound();
19325
19326 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19327 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19328 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19329}
19330
19331TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19332 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19333 "descriptor-backed resource which is not provided, but the shader does not "
19334 "statically use it. This is interesting because it requires compute pipelines "
19335 "to have a proper descriptor use walk, which they didn't for some time.");
19336 m_errorMonitor->ExpectSuccess();
19337
19338 ASSERT_NO_FATAL_FAILURE(InitState());
19339
19340 char const *csSource = "#version 450\n"
19341 "\n"
19342 "layout(local_size_x=1) in;\n"
19343 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19344 "void main(){\n"
19345 " // x is not used.\n"
19346 "}\n";
19347
19348 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19349
19350 VkDescriptorSetObj descriptorSet(m_device);
19351 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19352
19353 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19354 nullptr,
19355 0,
19356 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19357 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19358 descriptorSet.GetPipelineLayout(),
19359 VK_NULL_HANDLE,
19360 -1 };
19361
19362 VkPipeline pipe;
19363 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19364
19365 m_errorMonitor->VerifyNotFound();
19366
19367 if (err == VK_SUCCESS) {
19368 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19369 }
19370}
19371
19372TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19373 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19374 "sampler portion of a combined image + sampler");
19375 m_errorMonitor->ExpectSuccess();
19376
19377 ASSERT_NO_FATAL_FAILURE(InitState());
19378
19379 VkDescriptorSetLayoutBinding bindings[] = {
19380 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19381 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19382 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19383 };
19384 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19385 VkDescriptorSetLayout dsl;
19386 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19387 ASSERT_VK_SUCCESS(err);
19388
19389 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19390 VkPipelineLayout pl;
19391 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19392 ASSERT_VK_SUCCESS(err);
19393
19394 char const *csSource = "#version 450\n"
19395 "\n"
19396 "layout(local_size_x=1) in;\n"
19397 "layout(set=0, binding=0) uniform sampler s;\n"
19398 "layout(set=0, binding=1) uniform texture2D t;\n"
19399 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19400 "void main() {\n"
19401 " x = texture(sampler2D(t, s), vec2(0));\n"
19402 "}\n";
19403 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19404
19405 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19406 nullptr,
19407 0,
19408 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19409 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19410 pl,
19411 VK_NULL_HANDLE,
19412 -1 };
19413
19414 VkPipeline pipe;
19415 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19416
19417 m_errorMonitor->VerifyNotFound();
19418
19419 if (err == VK_SUCCESS) {
19420 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19421 }
19422
19423 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19424 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19425}
19426
19427TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19428 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19429 "image portion of a combined image + sampler");
19430 m_errorMonitor->ExpectSuccess();
19431
19432 ASSERT_NO_FATAL_FAILURE(InitState());
19433
19434 VkDescriptorSetLayoutBinding bindings[] = {
19435 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19436 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19437 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19438 };
19439 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19440 VkDescriptorSetLayout dsl;
19441 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19442 ASSERT_VK_SUCCESS(err);
19443
19444 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19445 VkPipelineLayout pl;
19446 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19447 ASSERT_VK_SUCCESS(err);
19448
19449 char const *csSource = "#version 450\n"
19450 "\n"
19451 "layout(local_size_x=1) in;\n"
19452 "layout(set=0, binding=0) uniform texture2D t;\n"
19453 "layout(set=0, binding=1) uniform sampler s;\n"
19454 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19455 "void main() {\n"
19456 " x = texture(sampler2D(t, s), vec2(0));\n"
19457 "}\n";
19458 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19459
19460 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19461 nullptr,
19462 0,
19463 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19464 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19465 pl,
19466 VK_NULL_HANDLE,
19467 -1 };
19468
19469 VkPipeline pipe;
19470 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19471
19472 m_errorMonitor->VerifyNotFound();
19473
19474 if (err == VK_SUCCESS) {
19475 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19476 }
19477
19478 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19479 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19480}
19481
19482TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19483 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19484 "both the sampler and the image of a combined image+sampler "
19485 "but via separate variables");
19486 m_errorMonitor->ExpectSuccess();
19487
19488 ASSERT_NO_FATAL_FAILURE(InitState());
19489
19490 VkDescriptorSetLayoutBinding bindings[] = {
19491 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19492 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19493 };
19494 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19495 VkDescriptorSetLayout dsl;
19496 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19497 ASSERT_VK_SUCCESS(err);
19498
19499 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19500 VkPipelineLayout pl;
19501 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19502 ASSERT_VK_SUCCESS(err);
19503
19504 char const *csSource = "#version 450\n"
19505 "\n"
19506 "layout(local_size_x=1) in;\n"
19507 "layout(set=0, binding=0) uniform texture2D t;\n"
19508 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19509 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19510 "void main() {\n"
19511 " x = texture(sampler2D(t, s), vec2(0));\n"
19512 "}\n";
19513 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19514
19515 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19516 nullptr,
19517 0,
19518 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19519 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19520 pl,
19521 VK_NULL_HANDLE,
19522 -1 };
19523
19524 VkPipeline pipe;
19525 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19526
19527 m_errorMonitor->VerifyNotFound();
19528
19529 if (err == VK_SUCCESS) {
19530 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19531 }
19532
19533 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19534 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19535}
19536
19537TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19538 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19539
19540 ASSERT_NO_FATAL_FAILURE(InitState());
19541
19542 // Positive test to check parameter_validation and unique_objects support
19543 // for NV_dedicated_allocation
19544 uint32_t extension_count = 0;
19545 bool supports_nv_dedicated_allocation = false;
19546 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19547 ASSERT_VK_SUCCESS(err);
19548
19549 if (extension_count > 0) {
19550 std::vector<VkExtensionProperties> available_extensions(extension_count);
19551
19552 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19553 ASSERT_VK_SUCCESS(err);
19554
19555 for (const auto &extension_props : available_extensions) {
19556 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19557 supports_nv_dedicated_allocation = true;
19558 }
19559 }
19560 }
19561
19562 if (supports_nv_dedicated_allocation) {
19563 m_errorMonitor->ExpectSuccess();
19564
19565 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19566 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19567 dedicated_buffer_create_info.pNext = nullptr;
19568 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19569
19570 uint32_t queue_family_index = 0;
19571 VkBufferCreateInfo buffer_create_info = {};
19572 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19573 buffer_create_info.pNext = &dedicated_buffer_create_info;
19574 buffer_create_info.size = 1024;
19575 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19576 buffer_create_info.queueFamilyIndexCount = 1;
19577 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19578
19579 VkBuffer buffer;
19580 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19581 ASSERT_VK_SUCCESS(err);
19582
19583 VkMemoryRequirements memory_reqs;
19584 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19585
19586 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19587 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19588 dedicated_memory_info.pNext = nullptr;
19589 dedicated_memory_info.buffer = buffer;
19590 dedicated_memory_info.image = VK_NULL_HANDLE;
19591
19592 VkMemoryAllocateInfo memory_info = {};
19593 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19594 memory_info.pNext = &dedicated_memory_info;
19595 memory_info.allocationSize = memory_reqs.size;
19596
19597 bool pass;
19598 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19599 ASSERT_TRUE(pass);
19600
19601 VkDeviceMemory buffer_memory;
19602 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19603 ASSERT_VK_SUCCESS(err);
19604
19605 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19606 ASSERT_VK_SUCCESS(err);
19607
19608 vkDestroyBuffer(m_device->device(), buffer, NULL);
19609 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19610
19611 m_errorMonitor->VerifyNotFound();
19612 }
19613}
19614
19615TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19616 VkResult err;
19617
19618 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19619
19620 ASSERT_NO_FATAL_FAILURE(InitState());
19621 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19622
19623 std::vector<const char *> device_extension_names;
19624 auto features = m_device->phy().features();
19625 // Artificially disable support for non-solid fill modes
19626 features.fillModeNonSolid = false;
19627 // The sacrificial device object
19628 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19629
19630 VkRenderpassObj render_pass(&test_device);
19631
19632 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19633 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19634 pipeline_layout_ci.setLayoutCount = 0;
19635 pipeline_layout_ci.pSetLayouts = NULL;
19636
19637 VkPipelineLayout pipeline_layout;
19638 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19639 ASSERT_VK_SUCCESS(err);
19640
19641 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19642 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19643 rs_ci.pNext = nullptr;
19644 rs_ci.lineWidth = 1.0f;
19645 rs_ci.rasterizerDiscardEnable = true;
19646
19647 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19648 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19649
19650 // Set polygonMode=FILL. No error is expected
19651 m_errorMonitor->ExpectSuccess();
19652 {
19653 VkPipelineObj pipe(&test_device);
19654 pipe.AddShader(&vs);
19655 pipe.AddShader(&fs);
19656 pipe.AddColorAttachment();
19657 // Set polygonMode to a good value
19658 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19659 pipe.SetRasterization(&rs_ci);
19660 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19661 }
19662 m_errorMonitor->VerifyNotFound();
19663
19664 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19665}
19666
19667TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19668 VkResult err;
19669 ASSERT_NO_FATAL_FAILURE(InitState());
19670 ASSERT_NO_FATAL_FAILURE(InitViewport());
19671 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19672
19673 VkPipelineLayout pipeline_layout;
19674 VkPushConstantRange pc_range = {};
19675 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19676 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19677 pipeline_layout_ci.pushConstantRangeCount = 1;
19678 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19679
19680 //
19681 // Check for invalid push constant ranges in pipeline layouts.
19682 //
19683 struct PipelineLayoutTestCase {
19684 VkPushConstantRange const range;
19685 char const *msg;
19686 };
19687
19688 // Check for overlapping ranges
19689 const uint32_t ranges_per_test = 5;
19690 struct OverlappingRangeTestCase {
19691 VkPushConstantRange const ranges[ranges_per_test];
19692 char const *msg;
19693 };
19694
19695 // Run some positive tests to make sure overlap checking in the layer is OK
19696 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19697 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19698 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19699 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19700 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19701 "" },
19702 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19703 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19704 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19705 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19706 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19707 "" } } };
19708 for (const auto &iter : overlapping_range_tests_pos) {
19709 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19710 m_errorMonitor->ExpectSuccess();
19711 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19712 m_errorMonitor->VerifyNotFound();
19713 if (VK_SUCCESS == err) {
19714 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19715 }
19716 }
19717
19718 //
19719 // CmdPushConstants tests
19720 //
19721 const uint8_t dummy_values[100] = {};
19722
19723 BeginCommandBuffer();
19724
19725 // positive overlapping range tests with cmd
19726 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19727 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19728 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19729 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19730 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19731 } };
19732
19733 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19734 const VkPushConstantRange pc_range4[] = {
19735 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19736 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19737 };
19738
19739 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19740 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19741 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19742 ASSERT_VK_SUCCESS(err);
19743 for (const auto &iter : cmd_overlap_tests_pos) {
19744 m_errorMonitor->ExpectSuccess();
19745 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19746 iter.range.size, dummy_values);
19747 m_errorMonitor->VerifyNotFound();
19748 }
19749 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19750
19751 EndCommandBuffer();
19752}
19753
19754
19755
19756
19757
19758
19759
19760#if 0 // A few devices have issues with this test so disabling for now
19761TEST_F(VkPositiveLayerTest, LongFenceChain)
19762{
19763 m_errorMonitor->ExpectSuccess();
19764
19765 ASSERT_NO_FATAL_FAILURE(InitState());
19766 VkResult err;
19767
19768 std::vector<VkFence> fences;
19769
19770 const int chainLength = 32768;
19771
19772 for (int i = 0; i < chainLength; i++) {
19773 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19774 VkFence fence;
19775 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19776 ASSERT_VK_SUCCESS(err);
19777
19778 fences.push_back(fence);
19779
19780 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19781 0, nullptr, 0, nullptr };
19782 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19783 ASSERT_VK_SUCCESS(err);
19784
19785 }
19786
19787 // BOOM, stack overflow.
19788 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19789
19790 for (auto fence : fences)
19791 vkDestroyFence(m_device->device(), fence, nullptr);
19792
19793 m_errorMonitor->VerifyNotFound();
19794}
19795#endif
19796
19797
Cody Northrop1242dfd2016-07-13 17:24:59 -060019798#if defined(ANDROID) && defined(VALIDATION_APK)
19799static bool initialized = false;
19800static bool active = false;
19801
19802// Convert Intents to argv
19803// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019804std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019805 std::vector<std::string> args;
19806 JavaVM &vm = *app.activity->vm;
19807 JNIEnv *p_env;
19808 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19809 return args;
19810
19811 JNIEnv &env = *p_env;
19812 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019813 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019814 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019815 jmethodID get_string_extra_method =
19816 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019817 jvalue get_string_extra_args;
19818 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019819 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019820
19821 std::string args_str;
19822 if (extra_str) {
19823 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19824 args_str = extra_utf;
19825 env.ReleaseStringUTFChars(extra_str, extra_utf);
19826 env.DeleteLocalRef(extra_str);
19827 }
19828
19829 env.DeleteLocalRef(get_string_extra_args.l);
19830 env.DeleteLocalRef(intent);
19831 vm.DetachCurrentThread();
19832
19833 // split args_str
19834 std::stringstream ss(args_str);
19835 std::string arg;
19836 while (std::getline(ss, arg, ' ')) {
19837 if (!arg.empty())
19838 args.push_back(arg);
19839 }
19840
19841 return args;
19842}
19843
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019844static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019845
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019846static void processCommand(struct android_app *app, int32_t cmd) {
19847 switch (cmd) {
19848 case APP_CMD_INIT_WINDOW: {
19849 if (app->window) {
19850 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019851 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019852 break;
19853 }
19854 case APP_CMD_GAINED_FOCUS: {
19855 active = true;
19856 break;
19857 }
19858 case APP_CMD_LOST_FOCUS: {
19859 active = false;
19860 break;
19861 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019862 }
19863}
19864
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019865void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019866 app_dummy();
19867
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019868 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019869
19870 int vulkanSupport = InitVulkan();
19871 if (vulkanSupport == 0) {
19872 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19873 return;
19874 }
19875
19876 app->onAppCmd = processCommand;
19877 app->onInputEvent = processInput;
19878
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019879 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019880 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019881 struct android_poll_source *source;
19882 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019883 if (source) {
19884 source->process(app, source);
19885 }
19886
19887 if (app->destroyRequested != 0) {
19888 VkTestFramework::Finish();
19889 return;
19890 }
19891 }
19892
19893 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019894 // Use the following key to send arguments to gtest, i.e.
19895 // --es args "--gtest_filter=-VkLayerTest.foo"
19896 const char key[] = "args";
19897 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019899 std::string filter = "";
19900 if (args.size() > 0) {
19901 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19902 filter += args[0];
19903 } else {
19904 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19905 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019906
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019907 int argc = 2;
19908 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19909 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019910
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019911 // Route output to files until we can override the gtest output
19912 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19913 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019914
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019915 ::testing::InitGoogleTest(&argc, argv);
19916 VkTestFramework::InitArgs(&argc, argv);
19917 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019918
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019919 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019920
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019921 if (result != 0) {
19922 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19923 } else {
19924 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19925 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019926
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019927 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019928
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019929 fclose(stdout);
19930 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019931
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019932 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019933
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019934 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019935 }
19936 }
19937}
19938#endif
19939
Tony Barbour300a6082015-04-07 13:44:53 -060019940int main(int argc, char **argv) {
19941 int result;
19942
Cody Northrop8e54a402016-03-08 22:25:52 -070019943#ifdef ANDROID
19944 int vulkanSupport = InitVulkan();
19945 if (vulkanSupport == 0)
19946 return 1;
19947#endif
19948
Tony Barbour300a6082015-04-07 13:44:53 -060019949 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060019950 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060019951
19952 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
19953
19954 result = RUN_ALL_TESTS();
19955
Tony Barbour6918cd52015-04-09 12:58:51 -060019956 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060019957 return result;
19958}