blob: 91f855b1853c4009d6f2a83b6107a4e2bea020ec [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060037#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060038#include "vkrenderframework.h"
39#include <limits.h>
40#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060041
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042#define GLM_FORCE_RADIANS
43#include "glm/glm.hpp"
44#include <glm/gtc/matrix_transform.hpp>
45
Dustin Gravesffa90fa2016-05-06 11:20:38 -060046#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060047#define MEM_TRACKER_TESTS 1
48#define OBJ_TRACKER_TESTS 1
49#define DRAW_STATE_TESTS 1
50#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120051#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060052#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060053#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060054
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055//--------------------------------------------------------------------------------------
56// Mesh and VertexFormat Data
57//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070058struct Vertex {
59 float posX, posY, posZ, posW; // Position data
60 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061};
62
Karl Schultz6addd812016-02-02 17:17:23 -070063#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050064
65typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070066 BsoFailNone = 0x00000000,
67 BsoFailLineWidth = 0x00000001,
68 BsoFailDepthBias = 0x00000002,
69 BsoFailViewport = 0x00000004,
70 BsoFailScissor = 0x00000008,
71 BsoFailBlend = 0x00000010,
72 BsoFailDepthBounds = 0x00000020,
73 BsoFailStencilReadMask = 0x00000040,
74 BsoFailStencilWriteMask = 0x00000080,
75 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060076 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060077 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050085};
86
Mark Lobodzinskice751c62016-09-08 10:45:35 -060087static const char bindStateVertShaderText[] = "#version 450\n"
88 "vec2 vertices[3];\n"
89 "out gl_PerVertex {\n"
90 " vec4 gl_Position;\n"
91 "};\n"
92 "void main() {\n"
93 " vertices[0] = vec2(-1.0, -1.0);\n"
94 " vertices[1] = vec2( 1.0, -1.0);\n"
95 " vertices[2] = vec2( 0.0, 1.0);\n"
96 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
97 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060099static const char bindStateFragShaderText[] = "#version 450\n"
100 "\n"
101 "layout(location = 0) out vec4 uFragColor;\n"
102 "void main(){\n"
103 " uFragColor = vec4(0,1,0,1);\n"
104 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500105
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600106static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
107 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
108 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600109
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600110// ErrorMonitor Usage:
111//
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600112// Call SetDesiredFailureMsg with: a string to be compared against all
113// encountered log messages, or a validation error enum identifying
114// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
115// will match all log messages. logMsg will return true for skipCall
116// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117//
118// Call DesiredMsgFound to determine if the desired failure message
119// was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600120class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700121 public:
122 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600123 test_platform_thread_create_mutex(&m_mutex);
124 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200125 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700126 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600127 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600128 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129
Dustin Graves48458142016-04-29 16:11:55 -0600130 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
131
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600132 // ErrorMonitor will look for an error message containing the specified string
Karl Schultz6addd812016-02-02 17:17:23 -0700133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600134 // Also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600136 m_failure_message_strings.clear();
137 // If we are looking for a matching string, ignore any IDs
138 m_desired_message_ids.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600139 m_otherMsgs.clear();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600140 m_desired_message_strings.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700141 m_msgFound = VK_FALSE;
142 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600143 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600144 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600145
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600146 // ErrorMonitor will look for a message ID matching the specified one
147 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
148 // Also discard all collected messages to this point
149 test_platform_thread_lock_mutex(&m_mutex);
150 m_failure_message_strings.clear();
151 // If we are looking for IDs don't look for strings
152 m_desired_message_strings.clear();
153 m_otherMsgs.clear();
154 m_desired_message_ids.insert(msg_id);
155 m_msgFound = VK_FALSE;
156 m_msgFlags = msgFlags;
157 test_platform_thread_unlock_mutex(&m_mutex);
158 }
159
160 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600162 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600163 if (m_bailout != NULL) {
164 *m_bailout = true;
165 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600167 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600168
169 for (auto desired_msg : m_desired_message_strings) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600170 if (desired_msg.length() == 0) {
171 // An empty desired_msg string "" indicates a positive test - not expecting an error.
172 // Return true to avoid calling layers/driver with this error.
173 // And don't erase the "" string, so it remains if another error is found.
174 result = VK_TRUE;
175 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600176 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600177 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600178 m_msgFound = VK_TRUE;
179 result = VK_TRUE;
180 // We only want one match for each expected error so remove from set here
181 // Since we're about the break the loop it's ok to remove from set we're iterating over
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600182 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600183 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186 for (auto desired_id : m_desired_message_ids) {
187 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
188 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
189 // Return true to avoid calling layers/driver with this error.
190 result = VK_TRUE;
191 } else if (desired_id == message_code) {
192 // Double-check that the string matches the error enum
193 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
194 found_expected = true;
195 result = VK_TRUE;
196 m_msgFound = VK_TRUE;
197 m_desired_message_ids.erase(desired_id);
198 break;
199 } else {
200 // Treat this message as a regular unexpected error, but print a warning jic
201 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
202 errorString.c_str(), desired_id, validation_error_map[desired_id]);
203 }
204 }
205 }
206
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600207 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200208 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600209 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600210 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600211 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600212 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600213 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600214
Karl Schultz6addd812016-02-02 17:17:23 -0700215 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600216
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600217 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
218
Karl Schultz6addd812016-02-02 17:17:23 -0700219 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600220
Karl Schultz6addd812016-02-02 17:17:23 -0700221 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600222
Karl Schultz6addd812016-02-02 17:17:23 -0700223 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600224 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600225 if (otherMsgs.size()) {
226 cout << "Other error messages logged for this test were:" << endl;
227 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
228 cout << " " << *iter << endl;
229 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600230 }
231 }
232
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600233 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200234
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600235 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
236 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
237 m_msgFlags = message_flag_mask;
238 // Match ANY message matching specified type
239 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200240 }
241
242 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600243 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200244 if (!DesiredMsgFound()) {
245 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600246 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600247 FAIL() << "Did not receive expected error '" << desired_msg << "'";
248 }
Tony Barbour59b42282016-11-03 13:31:28 -0600249 for (auto desired_id : m_desired_message_ids) {
250 FAIL() << "Did not receive expected error '" << desired_id << "'";
251 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200252 }
253 }
254
255 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600256 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200257 if (DesiredMsgFound()) {
258 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600259 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600260 FAIL() << "Expected to succeed but got error: " << msg;
261 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262 }
263 }
264
Karl Schultz6addd812016-02-02 17:17:23 -0700265 private:
266 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600267 std::unordered_set<uint32_t>m_desired_message_ids;
268 std::unordered_set<string> m_desired_message_strings;
269 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700270 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600271 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700272 bool *m_bailout;
273 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600274};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500275
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600276static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
277 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
278 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600279 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
280 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600281 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600282 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600283 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600284}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500285
Karl Schultz6addd812016-02-02 17:17:23 -0700286class VkLayerTest : public VkRenderFramework {
287 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800288 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
289 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600290 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
291 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700292 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
294 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700295 }
Tony Barbour300a6082015-04-07 13:44:53 -0600296
Tony Barbourfe3351b2015-07-28 10:17:20 -0600297 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600298 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800299 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600300 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
301 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700302 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700304 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600305 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700306 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600307 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
308 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
309 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700310 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
311 }
312 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
313 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
314 }
315
316 protected:
317 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600318 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600319
320 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600321 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600322 std::vector<const char *> instance_extension_names;
323 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600324
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700325 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600326 /*
327 * Since CreateDbgMsgCallback is an instance level extension call
328 * any extension / layer that utilizes that feature also needs
329 * to be enabled at create instance time.
330 */
Karl Schultz6addd812016-02-02 17:17:23 -0700331 // Use Threading layer first to protect others from
332 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700333 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600334 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800335 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700336 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800337 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600338 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700339 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600340
Ian Elliott2c1daf52016-05-12 09:41:46 -0600341 if (m_enableWSI) {
342 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
343 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
344#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
345#if defined(VK_USE_PLATFORM_ANDROID_KHR)
346 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
347#endif // VK_USE_PLATFORM_ANDROID_KHR
348#if defined(VK_USE_PLATFORM_MIR_KHR)
349 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_MIR_KHR
351#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
352 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
353#endif // VK_USE_PLATFORM_WAYLAND_KHR
354#if defined(VK_USE_PLATFORM_WIN32_KHR)
355 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_WIN32_KHR
357#endif // NEED_TO_TEST_THIS_ON_PLATFORM
358#if defined(VK_USE_PLATFORM_XCB_KHR)
359 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
360#elif defined(VK_USE_PLATFORM_XLIB_KHR)
361 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
362#endif // VK_USE_PLATFORM_XLIB_KHR
363 }
364
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600365 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600366 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800367 this->app_info.pApplicationName = "layer_tests";
368 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600369 this->app_info.pEngineName = "unittest";
370 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600371 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600372
Tony Barbour15524c32015-04-29 17:34:29 -0600373 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600374 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600375 }
376
377 virtual void TearDown() {
378 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600379 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600380 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600381 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600382
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600383 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600384};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500385
Karl Schultz6addd812016-02-02 17:17:23 -0700386VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600387 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600388
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800389 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600390
391 /*
392 * For render test all drawing happens in a single render pass
393 * on a single command buffer.
394 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200395 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800396 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600397 }
398
399 return result;
400}
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600403 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600404
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200405 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800406 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200407 }
Tony Barbour300a6082015-04-07 13:44:53 -0600408
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600410
411 return result;
412}
413
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600414void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500415 // Create identity matrix
416 int i;
417 struct vktriangle_vs_uniform data;
418
419 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700420 glm::mat4 View = glm::mat4(1.0f);
421 glm::mat4 Model = glm::mat4(1.0f);
422 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700424 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425
426 memcpy(&data.mvp, &MVP[0][0], matrixSize);
427
Karl Schultz6addd812016-02-02 17:17:23 -0700428 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600429 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500430 };
431
Karl Schultz6addd812016-02-02 17:17:23 -0700432 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 data.position[i][0] = tri_data[i].posX;
434 data.position[i][1] = tri_data[i].posY;
435 data.position[i][2] = tri_data[i].posZ;
436 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700437 data.color[i][0] = tri_data[i].r;
438 data.color[i][1] = tri_data[i].g;
439 data.color[i][2] = tri_data[i].b;
440 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500441 }
442
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 ASSERT_NO_FATAL_FAILURE(InitViewport());
444
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200445 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
446 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Karl Schultz6addd812016-02-02 17:17:23 -0700448 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600449 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
451 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800452 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 pipelineobj.AddShader(&vs);
454 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 if (failMask & BsoFailLineWidth) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600457 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600458 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600459 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
460 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600461 }
462 if (failMask & BsoFailDepthBias) {
463 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600464 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600465 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600466 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600467 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600468 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600469 }
Karl Schultz6addd812016-02-02 17:17:23 -0700470 // Viewport and scissors must stay in synch or other errors will occur than
471 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 if (failMask & BsoFailViewport) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
474 }
475 if (failMask & BsoFailScissor) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
477 }
478 if (failMask & BsoFailBlend) {
479 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600480 VkPipelineColorBlendAttachmentState att_state = {};
481 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
482 att_state.blendEnable = VK_TRUE;
483 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600484 }
485 if (failMask & BsoFailDepthBounds) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
487 }
488 if (failMask & BsoFailStencilReadMask) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
490 }
491 if (failMask & BsoFailStencilWriteMask) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
493 }
494 if (failMask & BsoFailStencilReference) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
496 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500497
498 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600499 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600502 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
Tony Barbourfe3351b2015-07-28 10:17:20 -0600504 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500505
506 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600507 if (failMask & BsoFailIndexBuffer) {
508 // Use DrawIndexed w/o an index buffer bound
509 DrawIndexed(3, 1, 0, 0, 0);
510 } else {
511 Draw(3, 1, 0, 0);
512 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500513
Mark Muellerd4914412016-06-13 17:52:06 -0600514 if (failMask & BsoFailCmdClearAttachments) {
515 VkClearAttachment color_attachment = {};
516 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
517 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
518 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
519
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600520 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600521 }
522
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500523 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600524 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500525
Tony Barbourfe3351b2015-07-28 10:17:20 -0600526 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500527}
528
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600529void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
530 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500531 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500533 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600534 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500535 }
536
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800537 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700538 // Make sure depthWriteEnable is set so that Depth fail test will work
539 // correctly
540 // Make sure stencilTestEnable is set so that Stencil fail test will work
541 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600542 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800543 stencil.failOp = VK_STENCIL_OP_KEEP;
544 stencil.passOp = VK_STENCIL_OP_KEEP;
545 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
546 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600547
548 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
549 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600550 ds_ci.pNext = NULL;
551 ds_ci.depthTestEnable = VK_FALSE;
552 ds_ci.depthWriteEnable = VK_TRUE;
553 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
554 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600555 if (failMask & BsoFailDepthBounds) {
556 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600557 ds_ci.maxDepthBounds = 0.0f;
558 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600559 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600560 ds_ci.stencilTestEnable = VK_TRUE;
561 ds_ci.front = stencil;
562 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600563
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600564 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600565 pipelineobj.SetViewport(m_viewports);
566 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800567 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600568 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600569 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800570 commandBuffer->BindPipeline(pipelineobj);
571 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500572}
573
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600574class VkPositiveLayerTest : public VkLayerTest {
575 public:
576 protected:
577};
578
Ian Elliott2c1daf52016-05-12 09:41:46 -0600579class VkWsiEnabledLayerTest : public VkLayerTest {
580 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 protected:
582 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600583};
584
Mark Muellerdfe37552016-07-07 14:47:42 -0600585class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600586 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600587 enum eTestEnFlags {
588 eDoubleDelete,
589 eInvalidDeviceOffset,
590 eInvalidMemoryOffset,
591 eBindNullBuffer,
592 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600593 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600594 };
595
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600596 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600597
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
599 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600600 return true;
601 }
602 VkDeviceSize offset_limit = 0;
603 if (eInvalidMemoryOffset == aTestFlag) {
604 VkBuffer vulkanBuffer;
605 VkBufferCreateInfo buffer_create_info = {};
606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
607 buffer_create_info.size = 32;
608 buffer_create_info.usage = aBufferUsage;
609
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600610 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600611 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600614 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
615 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
617 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600618 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600620 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600622 }
623 if (eOffsetAlignment < offset_limit) {
624 return true;
625 }
626 return false;
627 }
628
629 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
631 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
633 if (eBindNullBuffer == aTestFlag) {
634 VulkanMemory = 0;
635 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
636 } else {
637 VkBufferCreateInfo buffer_create_info = {};
638 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
639 buffer_create_info.size = 32;
640 buffer_create_info.usage = aBufferUsage;
641
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600643
644 CreateCurrent = true;
645
646 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600647 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600648
649 VkMemoryAllocateInfo memory_allocate_info = {};
650 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
651 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
653 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600654 if (!pass) {
655 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
656 return;
657 }
658
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600659 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600660 AllocateCurrent = true;
661 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
663 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 BoundCurrent = true;
665
666 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
667 }
668 }
669
670 ~VkBufferTest() {
671 if (CreateCurrent) {
672 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
673 }
674 if (AllocateCurrent) {
675 if (InvalidDeleteEn) {
676 union {
677 VkDeviceMemory device_memory;
678 unsigned long long index_access;
679 } bad_index;
680
681 bad_index.device_memory = VulkanMemory;
682 bad_index.index_access++;
683
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600684 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600685 }
686 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
687 }
688 }
689
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600690 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600691
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600692 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600693
694 void TestDoubleDestroy() {
695 // Destroy the buffer but leave the flag set, which will cause
696 // the buffer to be destroyed again in the destructor.
697 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600701 bool AllocateCurrent;
702 bool BoundCurrent;
703 bool CreateCurrent;
704 bool InvalidDeleteEn;
705
706 VkBuffer VulkanBuffer;
707 VkDevice VulkanDevice;
708 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600709};
710
711class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600712 public:
713 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600714 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600716 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600717 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
718 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 BindIdGenerator++; // NB: This can wrap w/misuse
720
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600721 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
722 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
725 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
726 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
727 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
728 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600729
730 unsigned i = 0;
731 do {
732 VertexInputAttributeDescription[i].binding = BindId;
733 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
735 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600736 i++;
737 } while (AttributeCount < i);
738
739 i = 0;
740 do {
741 VertexInputBindingDescription[i].binding = BindId;
742 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600743 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600744 i++;
745 } while (BindingCount < i);
746 }
747
748 ~VkVerticesObj() {
749 if (VertexInputAttributeDescription) {
750 delete[] VertexInputAttributeDescription;
751 }
752 if (VertexInputBindingDescription) {
753 delete[] VertexInputBindingDescription;
754 }
755 }
756
757 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
759 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600760 return true;
761 }
762
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600763 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600764 VkDeviceSize *offsetList;
765 unsigned offsetCount;
766
767 if (aOffsetCount) {
768 offsetList = aOffsetList;
769 offsetCount = aOffsetCount;
770 } else {
771 offsetList = new VkDeviceSize[1]();
772 offsetCount = 1;
773 }
774
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600775 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600776 BoundCurrent = true;
777
778 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600779 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600780 }
781 }
782
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600783 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600784 static uint32_t BindIdGenerator;
785
786 bool BoundCurrent;
787 unsigned AttributeCount;
788 unsigned BindingCount;
789 uint32_t BindId;
790
791 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
792 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
793 VkVertexInputBindingDescription *VertexInputBindingDescription;
794 VkConstantBufferObj VulkanMemoryBuffer;
795};
796
797uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500798// ********************************************************************************************************************
799// ********************************************************************************************************************
800// ********************************************************************************************************************
801// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600802#if PARAMETER_VALIDATION_TESTS
803TEST_F(VkLayerTest, RequiredParameter) {
804 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
805 "pointer, array, and array count parameters");
806
807 ASSERT_NO_FATAL_FAILURE(InitState());
808
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600810 // Specify NULL for a pointer to a handle
811 // Expected to trigger an error with
812 // parameter_validation::validate_required_pointer
813 vkGetPhysicalDeviceFeatures(gpu(), NULL);
814 m_errorMonitor->VerifyFound();
815
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
817 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600818 // Specify NULL for pointer to array count
819 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600820 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600821 m_errorMonitor->VerifyFound();
822
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 // Specify 0 for a required array count
825 // Expected to trigger an error with parameter_validation::validate_array
826 VkViewport view_port = {};
827 m_commandBuffer->SetViewport(0, 0, &view_port);
828 m_errorMonitor->VerifyFound();
829
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for a required array
832 // Expected to trigger an error with parameter_validation::validate_array
833 m_commandBuffer->SetViewport(0, 1, NULL);
834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify VK_NULL_HANDLE for a required handle
838 // Expected to trigger an error with
839 // parameter_validation::validate_required_handle
840 vkUnmapMemory(device(), VK_NULL_HANDLE);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
844 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600845 // Specify VK_NULL_HANDLE for a required handle array entry
846 // Expected to trigger an error with
847 // parameter_validation::validate_required_handle_array
848 VkFence fence = VK_NULL_HANDLE;
849 vkResetFences(device(), 1, &fence);
850 m_errorMonitor->VerifyFound();
851
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600853 // Specify NULL for a required struct pointer
854 // Expected to trigger an error with
855 // parameter_validation::validate_struct_type
856 VkDeviceMemory memory = VK_NULL_HANDLE;
857 vkAllocateMemory(device(), NULL, NULL, &memory);
858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600861 // Specify 0 for a required VkFlags parameter
862 // Expected to trigger an error with parameter_validation::validate_flags
863 m_commandBuffer->SetStencilReference(0, 0);
864 m_errorMonitor->VerifyFound();
865
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600867 // Specify 0 for a required VkFlags array entry
868 // Expected to trigger an error with
869 // parameter_validation::validate_flags_array
870 VkSemaphore semaphore = VK_NULL_HANDLE;
871 VkPipelineStageFlags stageFlags = 0;
872 VkSubmitInfo submitInfo = {};
873 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
874 submitInfo.waitSemaphoreCount = 1;
875 submitInfo.pWaitSemaphores = &semaphore;
876 submitInfo.pWaitDstStageMask = &stageFlags;
877 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
878 m_errorMonitor->VerifyFound();
879}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600880
Dustin Gravesfce74c02016-05-10 11:42:58 -0600881TEST_F(VkLayerTest, ReservedParameter) {
882 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
883
884 ASSERT_NO_FATAL_FAILURE(InitState());
885
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600887 // Specify 0 for a reserved VkFlags parameter
888 // Expected to trigger an error with
889 // parameter_validation::validate_reserved_flags
890 VkEvent event_handle = VK_NULL_HANDLE;
891 VkEventCreateInfo event_info = {};
892 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
893 event_info.flags = 1;
894 vkCreateEvent(device(), &event_info, NULL, &event_handle);
895 m_errorMonitor->VerifyFound();
896}
897
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600898TEST_F(VkLayerTest, InvalidStructSType) {
899 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
900 "structure's sType field");
901
902 ASSERT_NO_FATAL_FAILURE(InitState());
903
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600905 // Zero struct memory, effectively setting sType to
906 // VK_STRUCTURE_TYPE_APPLICATION_INFO
907 // Expected to trigger an error with
908 // parameter_validation::validate_struct_type
909 VkMemoryAllocateInfo alloc_info = {};
910 VkDeviceMemory memory = VK_NULL_HANDLE;
911 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
912 m_errorMonitor->VerifyFound();
913
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915 // Zero struct memory, effectively setting sType to
916 // VK_STRUCTURE_TYPE_APPLICATION_INFO
917 // Expected to trigger an error with
918 // parameter_validation::validate_struct_type_array
919 VkSubmitInfo submit_info = {};
920 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
921 m_errorMonitor->VerifyFound();
922}
923
924TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600925 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600926
927 ASSERT_NO_FATAL_FAILURE(InitState());
928
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600930 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600931 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600932 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600933 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600934 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600935 // Zero-initialization will provide the correct sType
936 VkApplicationInfo app_info = {};
937 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
938 event_alloc_info.pNext = &app_info;
939 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
940 m_errorMonitor->VerifyFound();
941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
943 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
945 // a function that has allowed pNext structure types and specify
946 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600947 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600948 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600949 VkMemoryAllocateInfo memory_alloc_info = {};
950 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
951 memory_alloc_info.pNext = &app_info;
952 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600953 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600954}
Dustin Graves5d33d532016-05-09 16:21:12 -0600955
956TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600957 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600958
959 ASSERT_NO_FATAL_FAILURE(InitState());
960
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
962 "range of the core VkFormat "
963 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600964 // Specify an invalid VkFormat value
965 // Expected to trigger an error with
966 // parameter_validation::validate_ranged_enum
967 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600968 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600969 m_errorMonitor->VerifyFound();
970
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 // Specify an invalid VkFlags bitmask value
973 // Expected to trigger an error with parameter_validation::validate_flags
974 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600975 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
976 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600977 m_errorMonitor->VerifyFound();
978
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 // Specify an invalid VkFlags array entry
981 // Expected to trigger an error with
982 // parameter_validation::validate_flags_array
983 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600984 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600985 VkSubmitInfo submit_info = {};
986 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
987 submit_info.waitSemaphoreCount = 1;
988 submit_info.pWaitSemaphores = &semaphore;
989 submit_info.pWaitDstStageMask = &stage_flags;
990 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
991 m_errorMonitor->VerifyFound();
992
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 // Specify an invalid VkBool32 value
995 // Expected to trigger a warning with
996 // parameter_validation::validate_bool32
997 VkSampler sampler = VK_NULL_HANDLE;
998 VkSamplerCreateInfo sampler_info = {};
999 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1000 sampler_info.pNext = NULL;
1001 sampler_info.magFilter = VK_FILTER_NEAREST;
1002 sampler_info.minFilter = VK_FILTER_NEAREST;
1003 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1004 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1005 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1006 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1007 sampler_info.mipLodBias = 1.0;
1008 sampler_info.maxAnisotropy = 1;
1009 sampler_info.compareEnable = VK_FALSE;
1010 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1011 sampler_info.minLod = 1.0;
1012 sampler_info.maxLod = 1.0;
1013 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1014 sampler_info.unnormalizedCoordinates = VK_FALSE;
1015 // Not VK_TRUE or VK_FALSE
1016 sampler_info.anisotropyEnable = 3;
1017 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1018 m_errorMonitor->VerifyFound();
1019}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001020
1021TEST_F(VkLayerTest, FailedReturnValue) {
1022 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1023
1024 ASSERT_NO_FATAL_FAILURE(InitState());
1025
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001026 // Find an unsupported image format
1027 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1028 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1029 VkFormat format = static_cast<VkFormat>(f);
1030 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001031 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001032 unsupported = format;
1033 break;
1034 }
1035 }
1036
1037 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1039 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001040 // Specify an unsupported VkFormat value to generate a
1041 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1042 // Expected to trigger a warning from
1043 // parameter_validation::validate_result
1044 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001045 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1046 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1048 m_errorMonitor->VerifyFound();
1049 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001050}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001051
1052TEST_F(VkLayerTest, UpdateBufferAlignment) {
1053 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001054 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001055
1056 ASSERT_NO_FATAL_FAILURE(InitState());
1057
1058 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1059 vk_testing::Buffer buffer;
1060 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1061
1062 BeginCommandBuffer();
1063 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1066 m_errorMonitor->VerifyFound();
1067
1068 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1071 m_errorMonitor->VerifyFound();
1072
1073 // Introduce failure by using dataSize that is < 0
1074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001075 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1077 m_errorMonitor->VerifyFound();
1078
1079 // Introduce failure by using dataSize that is > 65536
1080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001081 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001082 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1083 m_errorMonitor->VerifyFound();
1084
1085 EndCommandBuffer();
1086}
1087
1088TEST_F(VkLayerTest, FillBufferAlignment) {
1089 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1090
1091 ASSERT_NO_FATAL_FAILURE(InitState());
1092
1093 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1094 vk_testing::Buffer buffer;
1095 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1096
1097 BeginCommandBuffer();
1098
1099 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1102 m_errorMonitor->VerifyFound();
1103
1104 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001106 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1107 m_errorMonitor->VerifyFound();
1108
1109 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001111 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1112 m_errorMonitor->VerifyFound();
1113
1114 EndCommandBuffer();
1115}
Dustin Graves40f35822016-06-23 11:12:53 -06001116
Cortd889ff92016-07-27 09:51:27 -07001117TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1118 VkResult err;
1119
1120 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001121 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001122
1123 ASSERT_NO_FATAL_FAILURE(InitState());
1124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1125
1126 std::vector<const char *> device_extension_names;
1127 auto features = m_device->phy().features();
1128 // Artificially disable support for non-solid fill modes
1129 features.fillModeNonSolid = false;
1130 // The sacrificial device object
1131 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1132
1133 VkRenderpassObj render_pass(&test_device);
1134
1135 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1136 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1137 pipeline_layout_ci.setLayoutCount = 0;
1138 pipeline_layout_ci.pSetLayouts = NULL;
1139
1140 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001141 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001142 ASSERT_VK_SUCCESS(err);
1143
1144 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1145 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1146 rs_ci.pNext = nullptr;
1147 rs_ci.lineWidth = 1.0f;
1148 rs_ci.rasterizerDiscardEnable = true;
1149
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001150 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1151 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001152
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001153 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1155 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001156 {
1157 VkPipelineObj pipe(&test_device);
1158 pipe.AddShader(&vs);
1159 pipe.AddShader(&fs);
1160 pipe.AddColorAttachment();
1161 // Introduce failure by setting unsupported polygon mode
1162 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1163 pipe.SetRasterization(&rs_ci);
1164 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1165 }
1166 m_errorMonitor->VerifyFound();
1167
1168 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1170 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001171 {
1172 VkPipelineObj pipe(&test_device);
1173 pipe.AddShader(&vs);
1174 pipe.AddShader(&fs);
1175 pipe.AddColorAttachment();
1176 // Introduce failure by setting unsupported polygon mode
1177 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1178 pipe.SetRasterization(&rs_ci);
1179 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1180 }
1181 m_errorMonitor->VerifyFound();
1182
Cortd889ff92016-07-27 09:51:27 -07001183 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1184}
1185
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001186#endif // PARAMETER_VALIDATION_TESTS
1187
Tobin Ehlis0788f522015-05-26 16:11:58 -06001188#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001189#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001190TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001191{
1192 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001193 VkFenceCreateInfo fenceInfo = {};
1194 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1195 fenceInfo.pNext = NULL;
1196 fenceInfo.flags = 0;
1197
Mike Weiblencce7ec72016-10-17 19:33:05 -06001198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001199
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001200 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001201
1202 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1203 vk_testing::Buffer buffer;
1204 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001205
Tony Barbourfe3351b2015-07-28 10:17:20 -06001206 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001207 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001208 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001209
1210 testFence.init(*m_device, fenceInfo);
1211
1212 // Bypass framework since it does the waits automatically
1213 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001214 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001215 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1216 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001217 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001218 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001219 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001220 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001221 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001222 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001223 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001224
1225 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001226 ASSERT_VK_SUCCESS( err );
1227
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001229 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001230
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001231 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232}
1233
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001235{
1236 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001237 VkFenceCreateInfo fenceInfo = {};
1238 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1239 fenceInfo.pNext = NULL;
1240 fenceInfo.flags = 0;
1241
Mike Weiblencce7ec72016-10-17 19:33:05 -06001242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001243
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001244 ASSERT_NO_FATAL_FAILURE(InitState());
1245 ASSERT_NO_FATAL_FAILURE(InitViewport());
1246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1247
Tony Barbourfe3351b2015-07-28 10:17:20 -06001248 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001249 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001250 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251
1252 testFence.init(*m_device, fenceInfo);
1253
1254 // Bypass framework since it does the waits automatically
1255 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001256 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001257 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1258 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001259 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001260 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001261 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001262 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001263 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001264 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001265 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001266
1267 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001268 ASSERT_VK_SUCCESS( err );
1269
Jon Ashburnf19916e2016-01-11 13:12:43 -07001270 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001271 VkCommandBufferBeginInfo info = {};
1272 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1273 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001274 info.renderPass = VK_NULL_HANDLE;
1275 info.subpass = 0;
1276 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001277 info.occlusionQueryEnable = VK_FALSE;
1278 info.queryFlags = 0;
1279 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001280
1281 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001282 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001283
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001284 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001285}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001286#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001287
Tobin Ehlisf11be982016-05-11 13:52:53 -06001288TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1289 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1290 "buffer and image to memory such that they will alias.");
1291 VkResult err;
1292 bool pass;
1293 ASSERT_NO_FATAL_FAILURE(InitState());
1294
Tobin Ehlis077ded32016-05-12 17:39:13 -06001295 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001296 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001297 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001298 VkDeviceMemory mem; // buffer will be bound first
1299 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001300 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001301
1302 VkBufferCreateInfo buf_info = {};
1303 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1304 buf_info.pNext = NULL;
1305 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1306 buf_info.size = 256;
1307 buf_info.queueFamilyIndexCount = 0;
1308 buf_info.pQueueFamilyIndices = NULL;
1309 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1310 buf_info.flags = 0;
1311 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1312 ASSERT_VK_SUCCESS(err);
1313
Tobin Ehlis077ded32016-05-12 17:39:13 -06001314 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001315
1316 VkImageCreateInfo image_create_info = {};
1317 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1318 image_create_info.pNext = NULL;
1319 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1320 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1321 image_create_info.extent.width = 64;
1322 image_create_info.extent.height = 64;
1323 image_create_info.extent.depth = 1;
1324 image_create_info.mipLevels = 1;
1325 image_create_info.arrayLayers = 1;
1326 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001327 // Image tiling must be optimal to trigger error when aliasing linear buffer
1328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001329 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1330 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1331 image_create_info.queueFamilyIndexCount = 0;
1332 image_create_info.pQueueFamilyIndices = NULL;
1333 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1334 image_create_info.flags = 0;
1335
Tobin Ehlisf11be982016-05-11 13:52:53 -06001336 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1337 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001338 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1339 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001340
Tobin Ehlis077ded32016-05-12 17:39:13 -06001341 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1342
1343 VkMemoryAllocateInfo alloc_info = {};
1344 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1345 alloc_info.pNext = NULL;
1346 alloc_info.memoryTypeIndex = 0;
1347 // Ensure memory is big enough for both bindings
1348 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001349 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1350 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001351 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001352 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001353 vkDestroyImage(m_device->device(), image, NULL);
1354 return;
1355 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001356 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1357 ASSERT_VK_SUCCESS(err);
1358 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1359 ASSERT_VK_SUCCESS(err);
1360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001362 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001363 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1364 m_errorMonitor->VerifyFound();
1365
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001366 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001367 // aliasing buffer2
1368 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1369 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001370 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1371 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001372 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001373 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001375 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001376 m_errorMonitor->VerifyFound();
1377
1378 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001379 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001380 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001381 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001382 vkFreeMemory(m_device->device(), mem, NULL);
1383 vkFreeMemory(m_device->device(), mem_img, NULL);
1384}
1385
Tobin Ehlis35372522016-05-12 08:32:31 -06001386TEST_F(VkLayerTest, InvalidMemoryMapping) {
1387 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1388 VkResult err;
1389 bool pass;
1390 ASSERT_NO_FATAL_FAILURE(InitState());
1391
1392 VkBuffer buffer;
1393 VkDeviceMemory mem;
1394 VkMemoryRequirements mem_reqs;
1395
1396 VkBufferCreateInfo buf_info = {};
1397 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1398 buf_info.pNext = NULL;
1399 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1400 buf_info.size = 256;
1401 buf_info.queueFamilyIndexCount = 0;
1402 buf_info.pQueueFamilyIndices = NULL;
1403 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1404 buf_info.flags = 0;
1405 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1406 ASSERT_VK_SUCCESS(err);
1407
1408 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1409 VkMemoryAllocateInfo alloc_info = {};
1410 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1411 alloc_info.pNext = NULL;
1412 alloc_info.memoryTypeIndex = 0;
1413
1414 // Ensure memory is big enough for both bindings
1415 static const VkDeviceSize allocation_size = 0x10000;
1416 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001417 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001418 if (!pass) {
1419 vkDestroyBuffer(m_device->device(), buffer, NULL);
1420 return;
1421 }
1422 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1423 ASSERT_VK_SUCCESS(err);
1424
1425 uint8_t *pData;
1426 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001428 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1429 m_errorMonitor->VerifyFound();
1430 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001431 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001432 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1434 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1435 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001436 m_errorMonitor->VerifyFound();
1437
1438 // Unmap the memory to avoid re-map error
1439 vkUnmapMemory(m_device->device(), mem);
1440 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1442 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1443 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001444 m_errorMonitor->VerifyFound();
1445 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1447 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001448 m_errorMonitor->VerifyFound();
1449 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001451 vkUnmapMemory(m_device->device(), mem);
1452 m_errorMonitor->VerifyFound();
1453 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001454 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001455 ASSERT_VK_SUCCESS(err);
1456 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001457 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001458 mmr.memory = mem;
1459 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001461 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1462 m_errorMonitor->VerifyFound();
1463 // Now flush range that oversteps mapped range
1464 vkUnmapMemory(m_device->device(), mem);
1465 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1466 ASSERT_VK_SUCCESS(err);
1467 mmr.offset = 16;
1468 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1470 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1471 m_errorMonitor->VerifyFound();
1472
1473 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1474 vkUnmapMemory(m_device->device(), mem);
1475 err = vkMapMemory(m_device->device(), mem, 128, 256, 0, (void **)&pData);
1476 ASSERT_VK_SUCCESS(err);
1477 mmr.offset = 64;
1478 mmr.size = VK_WHOLE_SIZE;
1479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001480 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1481 m_errorMonitor->VerifyFound();
1482
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001483 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1484 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001485 if (!pass) {
1486 vkFreeMemory(m_device->device(), mem, NULL);
1487 vkDestroyBuffer(m_device->device(), buffer, NULL);
1488 return;
1489 }
1490 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1491 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1492
1493 vkDestroyBuffer(m_device->device(), buffer, NULL);
1494 vkFreeMemory(m_device->device(), mem, NULL);
1495}
1496
Ian Elliott1c32c772016-04-28 14:47:13 -06001497TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1498 VkResult err;
1499 bool pass;
1500
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001501 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1502 // following declaration (which is temporarily being moved below):
1503 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001504 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001505 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001506 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001507 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001508 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001509 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001510
1511 ASSERT_NO_FATAL_FAILURE(InitState());
1512
Ian Elliott3f06ce52016-04-29 14:46:21 -06001513#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1514#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1515 // Use the functions from the VK_KHR_android_surface extension without
1516 // enabling that extension:
1517
1518 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001519 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1521 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001522 pass = (err != VK_SUCCESS);
1523 ASSERT_TRUE(pass);
1524 m_errorMonitor->VerifyFound();
1525#endif // VK_USE_PLATFORM_ANDROID_KHR
1526
Ian Elliott3f06ce52016-04-29 14:46:21 -06001527#if defined(VK_USE_PLATFORM_MIR_KHR)
1528 // Use the functions from the VK_KHR_mir_surface extension without enabling
1529 // that extension:
1530
1531 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001532 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001534 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1535 pass = (err != VK_SUCCESS);
1536 ASSERT_TRUE(pass);
1537 m_errorMonitor->VerifyFound();
1538
1539 // Tell whether an mir_connection supports presentation:
1540 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1542 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001543 m_errorMonitor->VerifyFound();
1544#endif // VK_USE_PLATFORM_MIR_KHR
1545
Ian Elliott3f06ce52016-04-29 14:46:21 -06001546#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1547 // Use the functions from the VK_KHR_wayland_surface extension without
1548 // enabling that extension:
1549
1550 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001551 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1553 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001554 pass = (err != VK_SUCCESS);
1555 ASSERT_TRUE(pass);
1556 m_errorMonitor->VerifyFound();
1557
1558 // Tell whether an wayland_display supports presentation:
1559 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1561 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001562 m_errorMonitor->VerifyFound();
1563#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001564#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001565
Ian Elliott3f06ce52016-04-29 14:46:21 -06001566#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001567 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1568 // TO NON-LINUX PLATFORMS:
1569 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001570 // Use the functions from the VK_KHR_win32_surface extension without
1571 // enabling that extension:
1572
1573 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001574 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1576 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001577 pass = (err != VK_SUCCESS);
1578 ASSERT_TRUE(pass);
1579 m_errorMonitor->VerifyFound();
1580
1581 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001583 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001584 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001585// Set this (for now, until all platforms are supported and tested):
1586#define NEED_TO_TEST_THIS_ON_PLATFORM
1587#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001588#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001589 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1590 // TO NON-LINUX PLATFORMS:
1591 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001592#endif
1593#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001594 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1595 // that extension:
1596
1597 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001598 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001600 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1601 pass = (err != VK_SUCCESS);
1602 ASSERT_TRUE(pass);
1603 m_errorMonitor->VerifyFound();
1604
1605 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001606 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001607 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1609 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001610 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001611// Set this (for now, until all platforms are supported and tested):
1612#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001613#endif // VK_USE_PLATFORM_XCB_KHR
1614
Ian Elliott12630812016-04-29 14:35:43 -06001615#if defined(VK_USE_PLATFORM_XLIB_KHR)
1616 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1617 // that extension:
1618
1619 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001620 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001622 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1623 pass = (err != VK_SUCCESS);
1624 ASSERT_TRUE(pass);
1625 m_errorMonitor->VerifyFound();
1626
1627 // Tell whether an Xlib VisualID supports presentation:
1628 Display *dpy = NULL;
1629 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001631 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1632 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001633// Set this (for now, until all platforms are supported and tested):
1634#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001635#endif // VK_USE_PLATFORM_XLIB_KHR
1636
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001637// Use the functions from the VK_KHR_surface extension without enabling
1638// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001639
Ian Elliott489eec02016-05-05 14:12:44 -06001640#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001641 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001643 vkDestroySurfaceKHR(instance(), surface, NULL);
1644 m_errorMonitor->VerifyFound();
1645
1646 // Check if surface supports presentation:
1647 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001649 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1650 pass = (err != VK_SUCCESS);
1651 ASSERT_TRUE(pass);
1652 m_errorMonitor->VerifyFound();
1653
1654 // Check surface capabilities:
1655 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1657 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001658 pass = (err != VK_SUCCESS);
1659 ASSERT_TRUE(pass);
1660 m_errorMonitor->VerifyFound();
1661
1662 // Check surface formats:
1663 uint32_t format_count = 0;
1664 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1666 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001667 pass = (err != VK_SUCCESS);
1668 ASSERT_TRUE(pass);
1669 m_errorMonitor->VerifyFound();
1670
1671 // Check surface present modes:
1672 uint32_t present_mode_count = 0;
1673 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1675 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001676 pass = (err != VK_SUCCESS);
1677 ASSERT_TRUE(pass);
1678 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001679#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001680
Ian Elliott1c32c772016-04-28 14:47:13 -06001681 // Use the functions from the VK_KHR_swapchain extension without enabling
1682 // that extension:
1683
1684 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001686 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1687 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001688 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001689 pass = (err != VK_SUCCESS);
1690 ASSERT_TRUE(pass);
1691 m_errorMonitor->VerifyFound();
1692
1693 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1695 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001696 pass = (err != VK_SUCCESS);
1697 ASSERT_TRUE(pass);
1698 m_errorMonitor->VerifyFound();
1699
Chris Forbeseb7d5502016-09-13 18:19:21 +12001700 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1701 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1702 VkFence fence;
1703 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1704
Ian Elliott1c32c772016-04-28 14:47:13 -06001705 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001707 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001708 pass = (err != VK_SUCCESS);
1709 ASSERT_TRUE(pass);
1710 m_errorMonitor->VerifyFound();
1711
Chris Forbeseb7d5502016-09-13 18:19:21 +12001712 vkDestroyFence(m_device->device(), fence, nullptr);
1713
Ian Elliott1c32c772016-04-28 14:47:13 -06001714 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001715 //
1716 // NOTE: Currently can't test this because a real swapchain is needed (as
1717 // opposed to the fake one we created) in order for the layer to lookup the
1718 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001719
1720 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001722 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1723 m_errorMonitor->VerifyFound();
1724}
1725
Karl Schultz6addd812016-02-02 17:17:23 -07001726TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1727 VkResult err;
1728 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001729
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1731 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001732
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001733 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001734
1735 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001736 VkImage image;
1737 VkDeviceMemory mem;
1738 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001739
Karl Schultz6addd812016-02-02 17:17:23 -07001740 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1741 const int32_t tex_width = 32;
1742 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001743
Tony Barboureb254902015-07-15 12:50:33 -06001744 VkImageCreateInfo image_create_info = {};
1745 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001746 image_create_info.pNext = NULL;
1747 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1748 image_create_info.format = tex_format;
1749 image_create_info.extent.width = tex_width;
1750 image_create_info.extent.height = tex_height;
1751 image_create_info.extent.depth = 1;
1752 image_create_info.mipLevels = 1;
1753 image_create_info.arrayLayers = 1;
1754 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1755 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1756 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1757 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001758 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001759
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001760 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001761 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001762 mem_alloc.pNext = NULL;
1763 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001764
Chia-I Wuf7458c52015-10-26 21:10:41 +08001765 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001766 ASSERT_VK_SUCCESS(err);
1767
Karl Schultz6addd812016-02-02 17:17:23 -07001768 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001769
Mark Lobodzinski23065352015-05-29 09:32:35 -05001770 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001771
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001772 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 -07001773 if (!pass) { // If we can't find any unmappable memory this test doesn't
1774 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001775 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001776 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001777 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001778
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001779 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001780 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001781 ASSERT_VK_SUCCESS(err);
1782
1783 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001784 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001785 ASSERT_VK_SUCCESS(err);
1786
1787 // Map memory as if to initialize the image
1788 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001789 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001790
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001791 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001792
Chia-I Wuf7458c52015-10-26 21:10:41 +08001793 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001794 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001795}
1796
Karl Schultz6addd812016-02-02 17:17:23 -07001797TEST_F(VkLayerTest, RebindMemory) {
1798 VkResult err;
1799 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001800
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001802
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001803 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001804
1805 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001806 VkImage image;
1807 VkDeviceMemory mem1;
1808 VkDeviceMemory mem2;
1809 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001810
Karl Schultz6addd812016-02-02 17:17:23 -07001811 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1812 const int32_t tex_width = 32;
1813 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001814
Tony Barboureb254902015-07-15 12:50:33 -06001815 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001816 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1817 image_create_info.pNext = NULL;
1818 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1819 image_create_info.format = tex_format;
1820 image_create_info.extent.width = tex_width;
1821 image_create_info.extent.height = tex_height;
1822 image_create_info.extent.depth = 1;
1823 image_create_info.mipLevels = 1;
1824 image_create_info.arrayLayers = 1;
1825 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1826 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1827 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1828 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001829
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001830 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001831 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1832 mem_alloc.pNext = NULL;
1833 mem_alloc.allocationSize = 0;
1834 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001835
Karl Schultz6addd812016-02-02 17:17:23 -07001836 // Introduce failure, do NOT set memProps to
1837 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001838 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001839 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001840 ASSERT_VK_SUCCESS(err);
1841
Karl Schultz6addd812016-02-02 17:17:23 -07001842 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001843
1844 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001845 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001846 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001847
1848 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001849 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001850 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001851 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001852 ASSERT_VK_SUCCESS(err);
1853
1854 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001855 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001856 ASSERT_VK_SUCCESS(err);
1857
Karl Schultz6addd812016-02-02 17:17:23 -07001858 // Introduce validation failure, try to bind a different memory object to
1859 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001860 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001861
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001862 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001863
Chia-I Wuf7458c52015-10-26 21:10:41 +08001864 vkDestroyImage(m_device->device(), image, NULL);
1865 vkFreeMemory(m_device->device(), mem1, NULL);
1866 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001867}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001868
Karl Schultz6addd812016-02-02 17:17:23 -07001869TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001870 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001871
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1873 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001874
1875 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001876 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1877 fenceInfo.pNext = NULL;
1878 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001879
Tony Barbour300a6082015-04-07 13:44:53 -06001880 ASSERT_NO_FATAL_FAILURE(InitState());
1881 ASSERT_NO_FATAL_FAILURE(InitViewport());
1882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1883
Tony Barbourfe3351b2015-07-28 10:17:20 -06001884 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001885 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001886 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001887
1888 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001889
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001890 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001891 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1892 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001893 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001894 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001895 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001896 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001897 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001898 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001899 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001900
1901 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001902 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001903
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001904 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001905}
Chris Forbes4e44c912016-06-16 10:20:00 +12001906
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001907TEST_F(VkLayerTest, InvalidUsageBits) {
1908 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1909 "Initialize buffer with wrong usage then perform copy expecting errors "
1910 "from both the image and the buffer (2 calls)");
1911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001912
1913 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001914 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001915 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001916 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 -06001917 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001918
Tony Barbourf92621a2016-05-02 14:28:12 -06001919 VkImageView dsv;
1920 VkImageViewCreateInfo dsvci = {};
1921 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1922 dsvci.image = image.handle();
1923 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1924 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1925 dsvci.subresourceRange.layerCount = 1;
1926 dsvci.subresourceRange.baseMipLevel = 0;
1927 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001928 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001929
Tony Barbourf92621a2016-05-02 14:28:12 -06001930 // Create a view with depth / stencil aspect for image with different usage
1931 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001932
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001933 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001934
1935 // Initialize buffer with TRANSFER_DST usage
1936 vk_testing::Buffer buffer;
1937 VkMemoryPropertyFlags reqs = 0;
1938 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1939 VkBufferImageCopy region = {};
1940 region.bufferRowLength = 128;
1941 region.bufferImageHeight = 128;
1942 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1943 region.imageSubresource.layerCount = 1;
1944 region.imageExtent.height = 16;
1945 region.imageExtent.width = 16;
1946 region.imageExtent.depth = 1;
1947
Tony Barbourf92621a2016-05-02 14:28:12 -06001948 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1949 // TRANSFER_DST
1950 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001951
Chris Forbesda581202016-10-06 18:25:26 +13001952 // two separate errors from this call:
1953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1955
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001956 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1957 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001958 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001959}
Tony Barbour75d79f02016-08-30 09:39:07 -06001960
Tony Barbour75d79f02016-08-30 09:39:07 -06001961
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001962#endif // MEM_TRACKER_TESTS
1963
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001964#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001965
1966TEST_F(VkLayerTest, LeakAnObject) {
1967 VkResult err;
1968
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001969 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001970
1971 // Note that we have to create a new device since destroying the
1972 // framework's device causes Teardown() to fail and just calling Teardown
1973 // will destroy the errorMonitor.
1974
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001976
1977 ASSERT_NO_FATAL_FAILURE(InitState());
1978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001979 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001980 std::vector<VkDeviceQueueCreateInfo> queue_info;
1981 queue_info.reserve(queue_props.size());
1982 std::vector<std::vector<float>> queue_priorities;
1983 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
1984 VkDeviceQueueCreateInfo qi = {};
1985 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
1986 qi.pNext = NULL;
1987 qi.queueFamilyIndex = i;
1988 qi.queueCount = queue_props[i].queueCount;
1989 queue_priorities.emplace_back(qi.queueCount, 0.0f);
1990 qi.pQueuePriorities = queue_priorities[i].data();
1991 queue_info.push_back(qi);
1992 }
1993
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001994 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001995
1996 // The sacrificial device object
1997 VkDevice testDevice;
1998 VkDeviceCreateInfo device_create_info = {};
1999 auto features = m_device->phy().features();
2000 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2001 device_create_info.pNext = NULL;
2002 device_create_info.queueCreateInfoCount = queue_info.size();
2003 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002004 device_create_info.enabledLayerCount = 0;
2005 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002006 device_create_info.pEnabledFeatures = &features;
2007 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2008 ASSERT_VK_SUCCESS(err);
2009
2010 VkFence fence;
2011 VkFenceCreateInfo fence_create_info = {};
2012 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2013 fence_create_info.pNext = NULL;
2014 fence_create_info.flags = 0;
2015 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2016 ASSERT_VK_SUCCESS(err);
2017
2018 // Induce failure by not calling vkDestroyFence
2019 vkDestroyDevice(testDevice, NULL);
2020 m_errorMonitor->VerifyFound();
2021}
2022
2023TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2024
2025 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2026 "attempt to delete them from another.");
2027
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002029
Cody Northropc31a84f2016-08-22 10:41:47 -06002030 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002031 VkCommandPool command_pool_one;
2032 VkCommandPool command_pool_two;
2033
2034 VkCommandPoolCreateInfo pool_create_info{};
2035 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2036 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2037 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2038
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002039 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002040
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002041 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002042
2043 VkCommandBuffer command_buffer[9];
2044 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002045 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002046 command_buffer_allocate_info.commandPool = command_pool_one;
2047 command_buffer_allocate_info.commandBufferCount = 9;
2048 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002049 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002050
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002051 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002052
2053 m_errorMonitor->VerifyFound();
2054
2055 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2056 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2057}
2058
2059TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2060 VkResult err;
2061
2062 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002063 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002064
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002066
2067 ASSERT_NO_FATAL_FAILURE(InitState());
2068 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2069
2070 VkDescriptorPoolSize ds_type_count = {};
2071 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2072 ds_type_count.descriptorCount = 1;
2073
2074 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2075 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2076 ds_pool_ci.pNext = NULL;
2077 ds_pool_ci.flags = 0;
2078 ds_pool_ci.maxSets = 1;
2079 ds_pool_ci.poolSizeCount = 1;
2080 ds_pool_ci.pPoolSizes = &ds_type_count;
2081
2082 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002083 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002084 ASSERT_VK_SUCCESS(err);
2085
2086 // Create a second descriptor pool
2087 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002088 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002089 ASSERT_VK_SUCCESS(err);
2090
2091 VkDescriptorSetLayoutBinding dsl_binding = {};
2092 dsl_binding.binding = 0;
2093 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2094 dsl_binding.descriptorCount = 1;
2095 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2096 dsl_binding.pImmutableSamplers = NULL;
2097
2098 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2099 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2100 ds_layout_ci.pNext = NULL;
2101 ds_layout_ci.bindingCount = 1;
2102 ds_layout_ci.pBindings = &dsl_binding;
2103
2104 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002105 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002106 ASSERT_VK_SUCCESS(err);
2107
2108 VkDescriptorSet descriptorSet;
2109 VkDescriptorSetAllocateInfo alloc_info = {};
2110 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2111 alloc_info.descriptorSetCount = 1;
2112 alloc_info.descriptorPool = ds_pool_one;
2113 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002114 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002115 ASSERT_VK_SUCCESS(err);
2116
2117 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2118
2119 m_errorMonitor->VerifyFound();
2120
2121 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2122 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2123 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2124}
2125
2126TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002129 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002130
2131 ASSERT_NO_FATAL_FAILURE(InitState());
2132
2133 // Pass bogus handle into GetImageMemoryRequirements
2134 VkMemoryRequirements mem_reqs;
2135 uint64_t fakeImageHandle = 0xCADECADE;
2136 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2137
2138 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2139
2140 m_errorMonitor->VerifyFound();
2141}
2142
Karl Schultz6addd812016-02-02 17:17:23 -07002143TEST_F(VkLayerTest, PipelineNotBound) {
2144 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002145
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002146 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002147
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002149
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002150 ASSERT_NO_FATAL_FAILURE(InitState());
2151 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002152
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002153 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002154 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2155 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002156
2157 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002158 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2159 ds_pool_ci.pNext = NULL;
2160 ds_pool_ci.maxSets = 1;
2161 ds_pool_ci.poolSizeCount = 1;
2162 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002163
2164 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002165 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002166 ASSERT_VK_SUCCESS(err);
2167
2168 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002169 dsl_binding.binding = 0;
2170 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2171 dsl_binding.descriptorCount = 1;
2172 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2173 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002174
2175 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002176 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2177 ds_layout_ci.pNext = NULL;
2178 ds_layout_ci.bindingCount = 1;
2179 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002180
2181 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002182 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002183 ASSERT_VK_SUCCESS(err);
2184
2185 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002186 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002187 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002188 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002189 alloc_info.descriptorPool = ds_pool;
2190 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002191 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002192 ASSERT_VK_SUCCESS(err);
2193
2194 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002195 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2196 pipeline_layout_ci.pNext = NULL;
2197 pipeline_layout_ci.setLayoutCount = 1;
2198 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002199
2200 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002201 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002202 ASSERT_VK_SUCCESS(err);
2203
Mark Youngad779052016-01-06 14:26:04 -07002204 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002205
2206 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002207 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002208
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002209 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002210
Chia-I Wuf7458c52015-10-26 21:10:41 +08002211 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2212 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2213 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002214}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002215
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002216TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2217 VkResult err;
2218
2219 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2220 "during bind[Buffer|Image]Memory time");
2221
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002222 ASSERT_NO_FATAL_FAILURE(InitState());
2223
2224 // Create an image, allocate memory, set a bad typeIndex and then try to
2225 // bind it
2226 VkImage image;
2227 VkDeviceMemory mem;
2228 VkMemoryRequirements mem_reqs;
2229 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2230 const int32_t tex_width = 32;
2231 const int32_t tex_height = 32;
2232
2233 VkImageCreateInfo image_create_info = {};
2234 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2235 image_create_info.pNext = NULL;
2236 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2237 image_create_info.format = tex_format;
2238 image_create_info.extent.width = tex_width;
2239 image_create_info.extent.height = tex_height;
2240 image_create_info.extent.depth = 1;
2241 image_create_info.mipLevels = 1;
2242 image_create_info.arrayLayers = 1;
2243 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2244 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2245 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2246 image_create_info.flags = 0;
2247
2248 VkMemoryAllocateInfo mem_alloc = {};
2249 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2250 mem_alloc.pNext = NULL;
2251 mem_alloc.allocationSize = 0;
2252 mem_alloc.memoryTypeIndex = 0;
2253
2254 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2255 ASSERT_VK_SUCCESS(err);
2256
2257 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2258 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002259
2260 // Introduce Failure, select invalid TypeIndex
2261 VkPhysicalDeviceMemoryProperties memory_info;
2262
2263 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2264 unsigned int i;
2265 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2266 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2267 mem_alloc.memoryTypeIndex = i;
2268 break;
2269 }
2270 }
2271 if (i >= memory_info.memoryTypeCount) {
2272 printf("No invalid memory type index could be found; skipped.\n");
2273 vkDestroyImage(m_device->device(), image, NULL);
2274 return;
2275 }
2276
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002277 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 -06002278
2279 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2280 ASSERT_VK_SUCCESS(err);
2281
2282 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2283 (void)err;
2284
2285 m_errorMonitor->VerifyFound();
2286
2287 vkDestroyImage(m_device->device(), image, NULL);
2288 vkFreeMemory(m_device->device(), mem, NULL);
2289}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002290
Karl Schultz6addd812016-02-02 17:17:23 -07002291TEST_F(VkLayerTest, BindInvalidMemory) {
2292 VkResult err;
2293 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002294
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002296
Tobin Ehlisec598302015-09-15 15:02:17 -06002297 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002298
2299 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002300 VkImage image;
2301 VkDeviceMemory mem;
2302 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002303
Karl Schultz6addd812016-02-02 17:17:23 -07002304 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2305 const int32_t tex_width = 32;
2306 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002307
2308 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002309 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2310 image_create_info.pNext = NULL;
2311 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2312 image_create_info.format = tex_format;
2313 image_create_info.extent.width = tex_width;
2314 image_create_info.extent.height = tex_height;
2315 image_create_info.extent.depth = 1;
2316 image_create_info.mipLevels = 1;
2317 image_create_info.arrayLayers = 1;
2318 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2319 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2320 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2321 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002322
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002323 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002324 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2325 mem_alloc.pNext = NULL;
2326 mem_alloc.allocationSize = 0;
2327 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002328
Chia-I Wuf7458c52015-10-26 21:10:41 +08002329 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002330 ASSERT_VK_SUCCESS(err);
2331
Karl Schultz6addd812016-02-02 17:17:23 -07002332 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002333
2334 mem_alloc.allocationSize = mem_reqs.size;
2335
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002336 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002337 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002338
2339 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002340 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002341 ASSERT_VK_SUCCESS(err);
2342
2343 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002344 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002345
2346 // Try to bind free memory that has been freed
2347 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2348 // This may very well return an error.
2349 (void)err;
2350
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002351 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002352
Chia-I Wuf7458c52015-10-26 21:10:41 +08002353 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002354}
2355
Karl Schultz6addd812016-02-02 17:17:23 -07002356TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2357 VkResult err;
2358 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002359
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002361
Tobin Ehlisec598302015-09-15 15:02:17 -06002362 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002363
Karl Schultz6addd812016-02-02 17:17:23 -07002364 // Create an image object, allocate memory, destroy the object and then try
2365 // to bind it
2366 VkImage image;
2367 VkDeviceMemory mem;
2368 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002369
Karl Schultz6addd812016-02-02 17:17:23 -07002370 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2371 const int32_t tex_width = 32;
2372 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002373
2374 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002375 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2376 image_create_info.pNext = NULL;
2377 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2378 image_create_info.format = tex_format;
2379 image_create_info.extent.width = tex_width;
2380 image_create_info.extent.height = tex_height;
2381 image_create_info.extent.depth = 1;
2382 image_create_info.mipLevels = 1;
2383 image_create_info.arrayLayers = 1;
2384 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2385 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2386 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2387 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002388
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002389 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002390 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2391 mem_alloc.pNext = NULL;
2392 mem_alloc.allocationSize = 0;
2393 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002394
Chia-I Wuf7458c52015-10-26 21:10:41 +08002395 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002396 ASSERT_VK_SUCCESS(err);
2397
Karl Schultz6addd812016-02-02 17:17:23 -07002398 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002399
2400 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002401 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002402 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002403
2404 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002405 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002406 ASSERT_VK_SUCCESS(err);
2407
2408 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002409 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002410 ASSERT_VK_SUCCESS(err);
2411
2412 // Now Try to bind memory to this destroyed object
2413 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2414 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002415 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002416
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002417 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002418
Chia-I Wuf7458c52015-10-26 21:10:41 +08002419 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002420}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002421
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002422#endif // OBJ_TRACKER_TESTS
2423
Tobin Ehlis0788f522015-05-26 16:11:58 -06002424#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002425
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002426TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2427 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2428
2429 ASSERT_NO_FATAL_FAILURE(InitState());
2430 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2431
2432 VkVertexInputBindingDescription input_binding;
2433 memset(&input_binding, 0, sizeof(input_binding));
2434
2435 VkVertexInputAttributeDescription input_attribs;
2436 memset(&input_attribs, 0, sizeof(input_attribs));
2437
2438 // Pick a really bad format for this purpose and make sure it should fail
2439 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2440 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2441 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2442 printf("Format unsuitable for test; skipped.\n");
2443 return;
2444 }
2445
2446 input_attribs.location = 0;
2447 char const *vsSource = "#version 450\n"
2448 "\n"
2449 "out gl_PerVertex {\n"
2450 " vec4 gl_Position;\n"
2451 "};\n"
2452 "void main(){\n"
2453 " gl_Position = vec4(1);\n"
2454 "}\n";
2455 char const *fsSource = "#version 450\n"
2456 "\n"
2457 "layout(location=0) out vec4 color;\n"
2458 "void main(){\n"
2459 " color = vec4(1);\n"
2460 "}\n";
2461
2462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2463 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2464 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2465
2466 VkPipelineObj pipe(m_device);
2467 pipe.AddColorAttachment();
2468 pipe.AddShader(&vs);
2469 pipe.AddShader(&fs);
2470
2471 pipe.AddVertexInputBindings(&input_binding, 1);
2472 pipe.AddVertexInputAttribs(&input_attribs, 1);
2473
2474 VkDescriptorSetObj descriptorSet(m_device);
2475 descriptorSet.AppendDummy();
2476 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2477
2478 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2479
2480 m_errorMonitor->VerifyFound();
2481}
2482
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002483TEST_F(VkLayerTest, ImageSampleCounts) {
2484
2485 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2486 "validation errors.");
2487 ASSERT_NO_FATAL_FAILURE(InitState());
2488
2489 VkMemoryPropertyFlags reqs = 0;
2490 VkImageCreateInfo image_create_info = {};
2491 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2492 image_create_info.pNext = NULL;
2493 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2494 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2495 image_create_info.extent.width = 256;
2496 image_create_info.extent.height = 256;
2497 image_create_info.extent.depth = 1;
2498 image_create_info.mipLevels = 1;
2499 image_create_info.arrayLayers = 1;
2500 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2501 image_create_info.flags = 0;
2502
2503 VkImageBlit blit_region = {};
2504 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2505 blit_region.srcSubresource.baseArrayLayer = 0;
2506 blit_region.srcSubresource.layerCount = 1;
2507 blit_region.srcSubresource.mipLevel = 0;
2508 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2509 blit_region.dstSubresource.baseArrayLayer = 0;
2510 blit_region.dstSubresource.layerCount = 1;
2511 blit_region.dstSubresource.mipLevel = 0;
2512
2513 // Create two images, the source with sampleCount = 2, and attempt to blit
2514 // between them
2515 {
2516 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002517 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002518 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002519 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002520 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002521 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002522 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002523 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002524 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2526 "of VK_SAMPLE_COUNT_2_BIT but "
2527 "must be VK_SAMPLE_COUNT_1_BIT");
2528 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2529 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002530 m_errorMonitor->VerifyFound();
2531 m_commandBuffer->EndCommandBuffer();
2532 }
2533
2534 // Create two images, the dest with sampleCount = 4, and attempt to blit
2535 // between them
2536 {
2537 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002538 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002539 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002540 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002541 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002542 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002543 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002544 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002545 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2547 "of VK_SAMPLE_COUNT_4_BIT but "
2548 "must be VK_SAMPLE_COUNT_1_BIT");
2549 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2550 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002551 m_errorMonitor->VerifyFound();
2552 m_commandBuffer->EndCommandBuffer();
2553 }
2554
2555 VkBufferImageCopy copy_region = {};
2556 copy_region.bufferRowLength = 128;
2557 copy_region.bufferImageHeight = 128;
2558 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2559 copy_region.imageSubresource.layerCount = 1;
2560 copy_region.imageExtent.height = 64;
2561 copy_region.imageExtent.width = 64;
2562 copy_region.imageExtent.depth = 1;
2563
2564 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2565 // buffer to image
2566 {
2567 vk_testing::Buffer src_buffer;
2568 VkMemoryPropertyFlags reqs = 0;
2569 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2570 image_create_info.samples = VK_SAMPLE_COUNT_8_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_8_BIT but "
2577 "must be VK_SAMPLE_COUNT_1_BIT");
2578 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2579 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002580 m_errorMonitor->VerifyFound();
2581 m_commandBuffer->EndCommandBuffer();
2582 }
2583
2584 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2585 // image to buffer
2586 {
2587 vk_testing::Buffer dst_buffer;
2588 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2589 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002590 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002591 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002592 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002593 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2595 "of VK_SAMPLE_COUNT_2_BIT but "
2596 "must be VK_SAMPLE_COUNT_1_BIT");
2597 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002598 dst_buffer.handle(), 1, &copy_region);
2599 m_errorMonitor->VerifyFound();
2600 m_commandBuffer->EndCommandBuffer();
2601 }
2602}
2603
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002604TEST_F(VkLayerTest, BlitImageFormats) {
2605
2606 // Image blit with mismatched formats
2607 const char * expected_message =
2608 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2609 " the other one must also have signed/unsigned integer format";
2610
2611 ASSERT_NO_FATAL_FAILURE(InitState());
2612
2613 VkImageObj src_image(m_device);
2614 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2615 VkImageObj dst_image(m_device);
2616 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2617 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002618 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 -06002619
2620 VkImageBlit blitRegion = {};
2621 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2622 blitRegion.srcSubresource.baseArrayLayer = 0;
2623 blitRegion.srcSubresource.layerCount = 1;
2624 blitRegion.srcSubresource.mipLevel = 0;
2625 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2626 blitRegion.dstSubresource.baseArrayLayer = 0;
2627 blitRegion.dstSubresource.layerCount = 1;
2628 blitRegion.dstSubresource.mipLevel = 0;
2629
2630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2631
2632 // Unsigned int vs not an int
2633 BeginCommandBuffer();
2634 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2635 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2636
2637 m_errorMonitor->VerifyFound();
2638
2639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2640
2641 // Unsigned int vs signed int
2642 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2643 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2644
2645 m_errorMonitor->VerifyFound();
2646
2647 EndCommandBuffer();
2648}
2649
2650
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002651TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2652 VkResult err;
2653 bool pass;
2654
2655 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2656 ASSERT_NO_FATAL_FAILURE(InitState());
2657
2658 // If w/d/h granularity is 1, test is not meaningful
2659 // TODO: When virtual device limits are available, create a set of limits for this test that
2660 // will always have a granularity of > 1 for w, h, and d
2661 auto index = m_device->graphics_queue_node_index_;
2662 auto queue_family_properties = m_device->phy().queue_properties();
2663
2664 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2665 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2666 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2667 return;
2668 }
2669
2670 // Create two images of different types and try to copy between them
2671 VkImage srcImage;
2672 VkImage dstImage;
2673 VkDeviceMemory srcMem;
2674 VkDeviceMemory destMem;
2675 VkMemoryRequirements memReqs;
2676
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002677 VkImageCreateInfo image_create_info = {};
2678 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2679 image_create_info.pNext = NULL;
2680 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2681 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2682 image_create_info.extent.width = 32;
2683 image_create_info.extent.height = 32;
2684 image_create_info.extent.depth = 1;
2685 image_create_info.mipLevels = 1;
2686 image_create_info.arrayLayers = 4;
2687 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2688 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2689 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2690 image_create_info.flags = 0;
2691
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002692 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002693 ASSERT_VK_SUCCESS(err);
2694
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002695 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002696 ASSERT_VK_SUCCESS(err);
2697
2698 // Allocate memory
2699 VkMemoryAllocateInfo memAlloc = {};
2700 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2701 memAlloc.pNext = NULL;
2702 memAlloc.allocationSize = 0;
2703 memAlloc.memoryTypeIndex = 0;
2704
2705 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2706 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002707 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002708 ASSERT_TRUE(pass);
2709 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2710 ASSERT_VK_SUCCESS(err);
2711
2712 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2713 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002714 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002715 ASSERT_VK_SUCCESS(err);
2716 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2717 ASSERT_VK_SUCCESS(err);
2718
2719 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2720 ASSERT_VK_SUCCESS(err);
2721 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2722 ASSERT_VK_SUCCESS(err);
2723
2724 BeginCommandBuffer();
2725 VkImageCopy copyRegion;
2726 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2727 copyRegion.srcSubresource.mipLevel = 0;
2728 copyRegion.srcSubresource.baseArrayLayer = 0;
2729 copyRegion.srcSubresource.layerCount = 1;
2730 copyRegion.srcOffset.x = 0;
2731 copyRegion.srcOffset.y = 0;
2732 copyRegion.srcOffset.z = 0;
2733 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2734 copyRegion.dstSubresource.mipLevel = 0;
2735 copyRegion.dstSubresource.baseArrayLayer = 0;
2736 copyRegion.dstSubresource.layerCount = 1;
2737 copyRegion.dstOffset.x = 0;
2738 copyRegion.dstOffset.y = 0;
2739 copyRegion.dstOffset.z = 0;
2740 copyRegion.extent.width = 1;
2741 copyRegion.extent.height = 1;
2742 copyRegion.extent.depth = 1;
2743
2744 // Introduce failure by setting srcOffset to a bad granularity value
2745 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2747 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002748 m_errorMonitor->VerifyFound();
2749
2750 // Introduce failure by setting extent to a bad granularity value
2751 copyRegion.srcOffset.y = 0;
2752 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2754 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002755 m_errorMonitor->VerifyFound();
2756
2757 // Now do some buffer/image copies
2758 vk_testing::Buffer buffer;
2759 VkMemoryPropertyFlags reqs = 0;
2760 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2761 VkBufferImageCopy region = {};
2762 region.bufferOffset = 0;
2763 region.bufferRowLength = 3;
2764 region.bufferImageHeight = 128;
2765 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2766 region.imageSubresource.layerCount = 1;
2767 region.imageExtent.height = 16;
2768 region.imageExtent.width = 16;
2769 region.imageExtent.depth = 1;
2770 region.imageOffset.x = 0;
2771 region.imageOffset.y = 0;
2772 region.imageOffset.z = 0;
2773
2774 // Introduce failure by setting bufferRowLength to a bad granularity value
2775 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2777 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2778 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002779 m_errorMonitor->VerifyFound();
2780 region.bufferRowLength = 128;
2781
2782 // Introduce failure by setting bufferOffset to a bad granularity value
2783 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2785 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2786 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002787 m_errorMonitor->VerifyFound();
2788 region.bufferOffset = 0;
2789
2790 // Introduce failure by setting bufferImageHeight to a bad granularity value
2791 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2793 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2794 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002795 m_errorMonitor->VerifyFound();
2796 region.bufferImageHeight = 128;
2797
2798 // Introduce failure by setting imageExtent to a bad granularity value
2799 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2801 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2802 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002803 m_errorMonitor->VerifyFound();
2804 region.imageExtent.width = 16;
2805
2806 // Introduce failure by setting imageOffset to a bad granularity value
2807 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2809 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2810 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002811 m_errorMonitor->VerifyFound();
2812
2813 EndCommandBuffer();
2814
2815 vkDestroyImage(m_device->device(), srcImage, NULL);
2816 vkDestroyImage(m_device->device(), dstImage, NULL);
2817 vkFreeMemory(m_device->device(), srcMem, NULL);
2818 vkFreeMemory(m_device->device(), destMem, NULL);
2819}
2820
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002821TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002822 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2823 "attempt to submit them on a queue created in a different "
2824 "queue family.");
2825
Cody Northropc31a84f2016-08-22 10:41:47 -06002826 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002827 // This test is meaningless unless we have multiple queue families
2828 auto queue_family_properties = m_device->phy().queue_properties();
2829 if (queue_family_properties.size() < 2) {
2830 return;
2831 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002833 // Get safe index of another queue family
2834 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2835 ASSERT_NO_FATAL_FAILURE(InitState());
2836 // Create a second queue using a different queue family
2837 VkQueue other_queue;
2838 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2839
2840 // Record an empty cmd buffer
2841 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2842 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2843 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2844 vkEndCommandBuffer(m_commandBuffer->handle());
2845
2846 // And submit on the wrong queue
2847 VkSubmitInfo submit_info = {};
2848 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2849 submit_info.commandBufferCount = 1;
2850 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002851 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002852
2853 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002854}
2855
Chris Forbesa58c4522016-09-28 15:19:39 +13002856TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2857 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2858 ASSERT_NO_FATAL_FAILURE(InitState());
2859
2860 // A renderpass with two subpasses, both writing the same attachment.
2861 VkAttachmentDescription attach[] = {
2862 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2863 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2864 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2865 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2866 },
2867 };
2868 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2869 VkSubpassDescription subpasses[] = {
2870 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2871 1, &ref, nullptr, nullptr, 0, nullptr },
2872 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2873 1, &ref, nullptr, nullptr, 0, nullptr },
2874 };
2875 VkSubpassDependency dep = {
2876 0, 1,
2877 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2878 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2879 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2880 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2881 VK_DEPENDENCY_BY_REGION_BIT
2882 };
2883 VkRenderPassCreateInfo rpci = {
2884 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2885 0, 1, attach, 2, subpasses, 1, &dep
2886 };
2887 VkRenderPass rp;
2888 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2889 ASSERT_VK_SUCCESS(err);
2890
2891 VkImageObj image(m_device);
2892 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2893 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2894 VK_IMAGE_TILING_OPTIMAL, 0);
2895 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2896
2897 VkFramebufferCreateInfo fbci = {
2898 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2899 0, rp, 1, &imageView, 32, 32, 1
2900 };
2901 VkFramebuffer fb;
2902 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2903 ASSERT_VK_SUCCESS(err);
2904
2905 char const *vsSource =
2906 "#version 450\n"
2907 "void main() { gl_Position = vec4(1); }\n";
2908 char const *fsSource =
2909 "#version 450\n"
2910 "layout(location=0) out vec4 color;\n"
2911 "void main() { color = vec4(1); }\n";
2912
2913 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2914 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2915 VkPipelineObj pipe(m_device);
2916 pipe.AddColorAttachment();
2917 pipe.AddShader(&vs);
2918 pipe.AddShader(&fs);
2919 VkViewport view_port = {};
2920 m_viewports.push_back(view_port);
2921 pipe.SetViewport(m_viewports);
2922 VkRect2D rect = {};
2923 m_scissors.push_back(rect);
2924 pipe.SetScissor(m_scissors);
2925
2926 VkPipelineLayoutCreateInfo plci = {
2927 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2928 0, 0, nullptr, 0, nullptr
2929 };
2930 VkPipelineLayout pl;
2931 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2932 ASSERT_VK_SUCCESS(err);
2933 pipe.CreateVKPipeline(pl, rp);
2934
2935 BeginCommandBuffer();
2936
2937 VkRenderPassBeginInfo rpbi = {
2938 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2939 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
2940 };
2941
2942 // subtest 1: bind in the wrong subpass
2943 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2944 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2946 "built for subpass 0 but used in subpass 1");
2947 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2948 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2949 m_errorMonitor->VerifyFound();
2950
2951 vkCmdEndRenderPass(m_commandBuffer->handle());
2952
2953 // subtest 2: bind in correct subpass, then transition to next subpass
2954 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2955 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2956 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2958 "built for subpass 0 but used in subpass 1");
2959 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2960 m_errorMonitor->VerifyFound();
2961
2962 vkCmdEndRenderPass(m_commandBuffer->handle());
2963
2964 EndCommandBuffer();
2965
2966 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
2967 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
2968 vkDestroyRenderPass(m_device->device(), rp, nullptr);
2969}
2970
Tony Barbour4e919972016-08-09 13:27:40 -06002971TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
2972 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
2973 "with extent outside of framebuffer");
2974 ASSERT_NO_FATAL_FAILURE(InitState());
2975 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2976
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
2978 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06002979
2980 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
2981 m_renderPassBeginInfo.renderArea.extent.width = 257;
2982 m_renderPassBeginInfo.renderArea.extent.height = 257;
2983 BeginCommandBuffer();
2984 m_errorMonitor->VerifyFound();
2985}
2986
2987TEST_F(VkLayerTest, DisabledIndependentBlend) {
2988 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
2989 "blend and then specifying different blend states for two "
2990 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06002991 VkPhysicalDeviceFeatures features = {};
2992 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06002993 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06002994
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2996 "Invalid Pipeline CreateInfo: If independent blend feature not "
2997 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06002998
Cody Northropc31a84f2016-08-22 10:41:47 -06002999 VkDescriptorSetObj descriptorSet(m_device);
3000 descriptorSet.AppendDummy();
3001 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003002
Cody Northropc31a84f2016-08-22 10:41:47 -06003003 VkPipelineObj pipeline(m_device);
3004 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003005 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003006 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003007
Cody Northropc31a84f2016-08-22 10:41:47 -06003008 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3009 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3010 att_state1.blendEnable = VK_TRUE;
3011 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3012 att_state2.blendEnable = VK_FALSE;
3013 pipeline.AddColorAttachment(0, &att_state1);
3014 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003015 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003016 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003017}
3018
3019TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3020 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3021 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003022 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3025 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003026
3027 // Create a renderPass with a single color attachment
3028 VkAttachmentReference attach = {};
3029 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3030 VkSubpassDescription subpass = {};
3031 VkRenderPassCreateInfo rpci = {};
3032 rpci.subpassCount = 1;
3033 rpci.pSubpasses = &subpass;
3034 rpci.attachmentCount = 1;
3035 VkAttachmentDescription attach_desc = {};
3036 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3037 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3038 rpci.pAttachments = &attach_desc;
3039 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3040 VkRenderPass rp;
3041 subpass.pDepthStencilAttachment = &attach;
3042 subpass.pColorAttachments = NULL;
3043 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3044 m_errorMonitor->VerifyFound();
3045}
3046
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003047TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3048 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3049 "attachment reference of VK_ATTACHMENT_UNUSED");
3050
3051 ASSERT_NO_FATAL_FAILURE(InitState());
3052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3053
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003055
3056 VkAttachmentReference color_attach = {};
3057 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3058 color_attach.attachment = 0;
3059 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3060 VkSubpassDescription subpass = {};
3061 subpass.colorAttachmentCount = 1;
3062 subpass.pColorAttachments = &color_attach;
3063 subpass.preserveAttachmentCount = 1;
3064 subpass.pPreserveAttachments = &preserve_attachment;
3065
3066 VkRenderPassCreateInfo rpci = {};
3067 rpci.subpassCount = 1;
3068 rpci.pSubpasses = &subpass;
3069 rpci.attachmentCount = 1;
3070 VkAttachmentDescription attach_desc = {};
3071 attach_desc.format = VK_FORMAT_UNDEFINED;
3072 rpci.pAttachments = &attach_desc;
3073 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3074 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003075 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003076
3077 m_errorMonitor->VerifyFound();
3078
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003079 if (result == VK_SUCCESS) {
3080 vkDestroyRenderPass(m_device->device(), rp, NULL);
3081 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003082}
3083
Chris Forbesc5389742016-06-29 11:49:23 +12003084TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003085 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3086 "when the source of a subpass multisample resolve "
3087 "does not have multiple samples.");
3088
Chris Forbesc5389742016-06-29 11:49:23 +12003089 ASSERT_NO_FATAL_FAILURE(InitState());
3090
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3092 "Subpass 0 requests multisample resolve from attachment 0 which has "
3093 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003094
3095 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003096 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3097 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3098 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3099 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3100 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3101 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003102 };
3103
3104 VkAttachmentReference color = {
3105 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3106 };
3107
3108 VkAttachmentReference resolve = {
3109 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3110 };
3111
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003112 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003113
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003114 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003115
3116 VkRenderPass rp;
3117 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3118
3119 m_errorMonitor->VerifyFound();
3120
3121 if (err == VK_SUCCESS)
3122 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3123}
3124
3125TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003126 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3127 "when a subpass multisample resolve operation is "
3128 "requested, and the destination of that resolve has "
3129 "multiple samples.");
3130
Chris Forbesc5389742016-06-29 11:49:23 +12003131 ASSERT_NO_FATAL_FAILURE(InitState());
3132
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3134 "Subpass 0 requests multisample resolve into attachment 1, which "
3135 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003136
3137 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003138 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3139 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3140 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3141 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3142 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3143 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003144 };
3145
3146 VkAttachmentReference color = {
3147 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3148 };
3149
3150 VkAttachmentReference resolve = {
3151 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3152 };
3153
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003154 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003155
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003156 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003157
3158 VkRenderPass rp;
3159 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3160
3161 m_errorMonitor->VerifyFound();
3162
3163 if (err == VK_SUCCESS)
3164 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3165}
3166
Chris Forbes3f128ef2016-06-29 14:58:53 +12003167TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003168 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3169 "when the color and depth attachments used by a subpass "
3170 "have inconsistent sample counts");
3171
Chris Forbes3f128ef2016-06-29 14:58:53 +12003172 ASSERT_NO_FATAL_FAILURE(InitState());
3173
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3175 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003176
3177 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003178 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3179 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3180 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3181 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3182 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3183 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003184 };
3185
3186 VkAttachmentReference color[] = {
3187 {
3188 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3189 },
3190 {
3191 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3192 },
3193 };
3194
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003195 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003196
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003197 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003198
3199 VkRenderPass rp;
3200 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3201
3202 m_errorMonitor->VerifyFound();
3203
3204 if (err == VK_SUCCESS)
3205 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3206}
3207
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003208TEST_F(VkLayerTest, FramebufferCreateErrors) {
3209 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003210 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003211 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003212 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3213 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3214 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3215 " 6. Framebuffer attachment where dimensions don't match\n"
3216 " 7. Framebuffer attachment w/o identity swizzle\n"
3217 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003218
3219 ASSERT_NO_FATAL_FAILURE(InitState());
3220 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3221
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3223 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3224 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003225
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003226 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003227 VkAttachmentReference attach = {};
3228 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3229 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003230 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003231 VkRenderPassCreateInfo rpci = {};
3232 rpci.subpassCount = 1;
3233 rpci.pSubpasses = &subpass;
3234 rpci.attachmentCount = 1;
3235 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003236 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003237 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003238 rpci.pAttachments = &attach_desc;
3239 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3240 VkRenderPass rp;
3241 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3242 ASSERT_VK_SUCCESS(err);
3243
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003244 VkImageView ivs[2];
3245 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3246 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003247 VkFramebufferCreateInfo fb_info = {};
3248 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3249 fb_info.pNext = NULL;
3250 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003251 // Set mis-matching attachmentCount
3252 fb_info.attachmentCount = 2;
3253 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003254 fb_info.width = 100;
3255 fb_info.height = 100;
3256 fb_info.layers = 1;
3257
3258 VkFramebuffer fb;
3259 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3260
3261 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003262 if (err == VK_SUCCESS) {
3263 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3264 }
3265 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003266
3267 // Create a renderPass with a depth-stencil attachment created with
3268 // IMAGE_USAGE_COLOR_ATTACHMENT
3269 // Add our color attachment to pDepthStencilAttachment
3270 subpass.pDepthStencilAttachment = &attach;
3271 subpass.pColorAttachments = NULL;
3272 VkRenderPass rp_ds;
3273 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3274 ASSERT_VK_SUCCESS(err);
3275 // Set correct attachment count, but attachment has COLOR usage bit set
3276 fb_info.attachmentCount = 1;
3277 fb_info.renderPass = rp_ds;
3278
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003280 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3281
3282 m_errorMonitor->VerifyFound();
3283 if (err == VK_SUCCESS) {
3284 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3285 }
3286 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003287
3288 // Create new renderpass with alternate attachment format from fb
3289 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3290 subpass.pDepthStencilAttachment = NULL;
3291 subpass.pColorAttachments = &attach;
3292 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3293 ASSERT_VK_SUCCESS(err);
3294
3295 // Cause error due to mis-matched formats between rp & fb
3296 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3297 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3299 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003300 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3301
3302 m_errorMonitor->VerifyFound();
3303 if (err == VK_SUCCESS) {
3304 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3305 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003306 vkDestroyRenderPass(m_device->device(), rp, NULL);
3307
3308 // Create new renderpass with alternate sample count from fb
3309 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3310 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3311 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3312 ASSERT_VK_SUCCESS(err);
3313
3314 // Cause error due to mis-matched sample count between rp & fb
3315 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3317 "that do not match the "
3318 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003319 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3320
3321 m_errorMonitor->VerifyFound();
3322 if (err == VK_SUCCESS) {
3323 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3324 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003325
3326 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003327
3328 // Create a custom imageView with non-1 mip levels
3329 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003330 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 -06003331 ASSERT_TRUE(image.initialized());
3332
3333 VkImageView view;
3334 VkImageViewCreateInfo ivci = {};
3335 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3336 ivci.image = image.handle();
3337 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3338 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3339 ivci.subresourceRange.layerCount = 1;
3340 ivci.subresourceRange.baseMipLevel = 0;
3341 // Set level count 2 (only 1 is allowed for FB attachment)
3342 ivci.subresourceRange.levelCount = 2;
3343 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3344 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3345 ASSERT_VK_SUCCESS(err);
3346 // Re-create renderpass to have matching sample count
3347 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3348 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3349 ASSERT_VK_SUCCESS(err);
3350
3351 fb_info.renderPass = rp;
3352 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003354 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3355
3356 m_errorMonitor->VerifyFound();
3357 if (err == VK_SUCCESS) {
3358 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3359 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003360 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003361 // Update view to original color buffer and grow FB dimensions too big
3362 fb_info.pAttachments = ivs;
3363 fb_info.height = 1024;
3364 fb_info.width = 1024;
3365 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3367 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003368 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3369
3370 m_errorMonitor->VerifyFound();
3371 if (err == VK_SUCCESS) {
3372 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3373 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003374 // Create view attachment with non-identity swizzle
3375 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3376 ivci.image = image.handle();
3377 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3378 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3379 ivci.subresourceRange.layerCount = 1;
3380 ivci.subresourceRange.baseMipLevel = 0;
3381 ivci.subresourceRange.levelCount = 1;
3382 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3383 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3384 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3385 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3386 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3387 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3388 ASSERT_VK_SUCCESS(err);
3389
3390 fb_info.pAttachments = &view;
3391 fb_info.height = 100;
3392 fb_info.width = 100;
3393 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3395 "framebuffer attachments must have "
3396 "been created with the identity "
3397 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003398 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3399
3400 m_errorMonitor->VerifyFound();
3401 if (err == VK_SUCCESS) {
3402 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3403 }
3404 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003405 // Request fb that exceeds max dimensions
3406 // reset attachment to color attachment
3407 fb_info.pAttachments = ivs;
3408 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3409 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3410 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3412 "dimensions exceed physical device "
3413 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003414 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3415
3416 m_errorMonitor->VerifyFound();
3417 if (err == VK_SUCCESS) {
3418 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3419 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003420
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003421 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003422}
3423
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003424TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003425 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3426 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003427
Cody Northropc31a84f2016-08-22 10:41:47 -06003428 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003429 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3431 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003432 m_errorMonitor->VerifyFound();
3433}
3434
3435TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003436 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3437 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003438
Cody Northropc31a84f2016-08-22 10:41:47 -06003439 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003440 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3442 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003443 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003444}
3445
3446TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003447 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3448 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003449
Cody Northropc31a84f2016-08-22 10:41:47 -06003450 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003451 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003452 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 -06003453 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003454 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003455}
3456
3457TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003458 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3459 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003460
Cody Northropc31a84f2016-08-22 10:41:47 -06003461 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003462 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003463 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 -06003464 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003465 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003466}
3467
Cortd713fe82016-07-27 09:51:27 -07003468TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003469 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3470 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003471
3472 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003473 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3475 "Dynamic blend constants state not set for this command buffer");
3476 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003477 m_errorMonitor->VerifyFound();
3478}
3479
3480TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003481 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3482 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003483
3484 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003485 if (!m_device->phy().features().depthBounds) {
3486 printf("Device does not support depthBounds test; skipped.\n");
3487 return;
3488 }
3489 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3491 "Dynamic depth bounds state not set for this command buffer");
3492 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003493 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003494}
3495
3496TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003497 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3498 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003499
3500 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003501 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3503 "Dynamic stencil read mask state not set for this command buffer");
3504 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003505 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003506}
3507
3508TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003509 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3510 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003511
3512 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003513 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3515 "Dynamic stencil write mask state not set for this command buffer");
3516 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003517 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003518}
3519
3520TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003521 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3522 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003523
3524 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003525 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3527 "Dynamic stencil reference state not set for this command buffer");
3528 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003529 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003530}
3531
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003532TEST_F(VkLayerTest, IndexBufferNotBound) {
3533 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003534
3535 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3537 "Index buffer object not bound to this command buffer when Indexed ");
3538 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003539 m_errorMonitor->VerifyFound();
3540}
3541
Karl Schultz6addd812016-02-02 17:17:23 -07003542TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3544 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3545 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003546
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003547 ASSERT_NO_FATAL_FAILURE(InitState());
3548 ASSERT_NO_FATAL_FAILURE(InitViewport());
3549 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3550
Karl Schultz6addd812016-02-02 17:17:23 -07003551 // We luck out b/c by default the framework creates CB w/ the
3552 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003553 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003554 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003555 EndCommandBuffer();
3556
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003557 // Bypass framework since it does the waits automatically
3558 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003559 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003560 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3561 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003562 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003563 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003564 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003565 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003566 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003567 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003568 submit_info.pSignalSemaphores = NULL;
3569
Chris Forbes40028e22016-06-13 09:59:34 +12003570 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003571 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003572 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003573
Karl Schultz6addd812016-02-02 17:17:23 -07003574 // Cause validation error by re-submitting cmd buffer that should only be
3575 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003576 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003577 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003578
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003579 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003580}
3581
Karl Schultz6addd812016-02-02 17:17:23 -07003582TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003583 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07003584 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003585
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
3587 "type "
3588 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003589
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003590 ASSERT_NO_FATAL_FAILURE(InitState());
3591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003592
Karl Schultz6addd812016-02-02 17:17:23 -07003593 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3594 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003595 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003596 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3597 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003598
3599 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003600 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3601 ds_pool_ci.pNext = NULL;
3602 ds_pool_ci.flags = 0;
3603 ds_pool_ci.maxSets = 1;
3604 ds_pool_ci.poolSizeCount = 1;
3605 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003606
3607 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003608 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003609 ASSERT_VK_SUCCESS(err);
3610
3611 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003612 dsl_binding.binding = 0;
3613 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3614 dsl_binding.descriptorCount = 1;
3615 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3616 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003617
3618 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003619 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3620 ds_layout_ci.pNext = NULL;
3621 ds_layout_ci.bindingCount = 1;
3622 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003623
3624 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003625 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003626 ASSERT_VK_SUCCESS(err);
3627
3628 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003629 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003630 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003631 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003632 alloc_info.descriptorPool = ds_pool;
3633 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003634 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003635
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003636 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003637
Chia-I Wuf7458c52015-10-26 21:10:41 +08003638 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3639 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003640}
3641
Karl Schultz6addd812016-02-02 17:17:23 -07003642TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3643 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003644
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3646 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3647 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003648
Tobin Ehlise735c692015-10-08 13:13:50 -06003649 ASSERT_NO_FATAL_FAILURE(InitState());
3650 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003651
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_UNIFORM_BUFFER;
3654 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -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.maxSets = 1;
3660 ds_pool_ci.poolSizeCount = 1;
3661 ds_pool_ci.flags = 0;
3662 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3663 // app can only call vkResetDescriptorPool on this pool.;
3664 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003665
3666 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003667 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003668 ASSERT_VK_SUCCESS(err);
3669
3670 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003671 dsl_binding.binding = 0;
3672 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3673 dsl_binding.descriptorCount = 1;
3674 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3675 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003676
3677 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003678 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3679 ds_layout_ci.pNext = NULL;
3680 ds_layout_ci.bindingCount = 1;
3681 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003682
3683 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003684 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003685 ASSERT_VK_SUCCESS(err);
3686
3687 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003688 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003689 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003690 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003691 alloc_info.descriptorPool = ds_pool;
3692 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003693 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003694 ASSERT_VK_SUCCESS(err);
3695
3696 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003697 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003698
Chia-I Wuf7458c52015-10-26 21:10:41 +08003699 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3700 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003701}
3702
Karl Schultz6addd812016-02-02 17:17:23 -07003703TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003704 // Attempt to clear Descriptor Pool with bad object.
3705 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003706
3707 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003709 uint64_t fake_pool_handle = 0xbaad6001;
3710 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3711 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003712 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003713}
3714
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003715TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003716 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3717 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003718 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003719 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003720
3721 uint64_t fake_set_handle = 0xbaad6001;
3722 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003723 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003725
3726 ASSERT_NO_FATAL_FAILURE(InitState());
3727
3728 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3729 layout_bindings[0].binding = 0;
3730 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3731 layout_bindings[0].descriptorCount = 1;
3732 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3733 layout_bindings[0].pImmutableSamplers = NULL;
3734
3735 VkDescriptorSetLayout descriptor_set_layout;
3736 VkDescriptorSetLayoutCreateInfo dslci = {};
3737 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3738 dslci.pNext = NULL;
3739 dslci.bindingCount = 1;
3740 dslci.pBindings = layout_bindings;
3741 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003742 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003743
3744 VkPipelineLayout pipeline_layout;
3745 VkPipelineLayoutCreateInfo plci = {};
3746 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3747 plci.pNext = NULL;
3748 plci.setLayoutCount = 1;
3749 plci.pSetLayouts = &descriptor_set_layout;
3750 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003751 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003752
3753 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003754 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3755 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003756 m_errorMonitor->VerifyFound();
3757 EndCommandBuffer();
3758 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3759 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003760}
3761
Karl Schultz6addd812016-02-02 17:17:23 -07003762TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003763 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3764 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003765 uint64_t fake_layout_handle = 0xbaad6001;
3766 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003768 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003769 VkPipelineLayout pipeline_layout;
3770 VkPipelineLayoutCreateInfo plci = {};
3771 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3772 plci.pNext = NULL;
3773 plci.setLayoutCount = 1;
3774 plci.pSetLayouts = &bad_layout;
3775 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3776
3777 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003778}
3779
Mark Muellerd4914412016-06-13 17:52:06 -06003780TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3781 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3782 "1) A uniform buffer update must have a valid buffer index."
3783 "2) When using an array of descriptors in a single WriteDescriptor,"
3784 " the descriptor types and stageflags must all be the same."
3785 "3) Immutable Sampler state must match across descriptors");
3786
3787 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003788 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3789 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3790 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3791 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3792 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003793
Mark Muellerd4914412016-06-13 17:52:06 -06003794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3795
3796 ASSERT_NO_FATAL_FAILURE(InitState());
3797 VkDescriptorPoolSize ds_type_count[4] = {};
3798 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3799 ds_type_count[0].descriptorCount = 1;
3800 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3801 ds_type_count[1].descriptorCount = 1;
3802 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3803 ds_type_count[2].descriptorCount = 1;
3804 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3805 ds_type_count[3].descriptorCount = 1;
3806
3807 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3808 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3809 ds_pool_ci.maxSets = 1;
3810 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3811 ds_pool_ci.pPoolSizes = ds_type_count;
3812
3813 VkDescriptorPool ds_pool;
3814 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3815 ASSERT_VK_SUCCESS(err);
3816
Mark Muellerb9896722016-06-16 09:54:29 -06003817 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003818 layout_binding[0].binding = 0;
3819 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3820 layout_binding[0].descriptorCount = 1;
3821 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3822 layout_binding[0].pImmutableSamplers = NULL;
3823
3824 layout_binding[1].binding = 1;
3825 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3826 layout_binding[1].descriptorCount = 1;
3827 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3828 layout_binding[1].pImmutableSamplers = NULL;
3829
3830 VkSamplerCreateInfo sampler_ci = {};
3831 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3832 sampler_ci.pNext = NULL;
3833 sampler_ci.magFilter = VK_FILTER_NEAREST;
3834 sampler_ci.minFilter = VK_FILTER_NEAREST;
3835 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3836 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3837 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3838 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3839 sampler_ci.mipLodBias = 1.0;
3840 sampler_ci.anisotropyEnable = VK_FALSE;
3841 sampler_ci.maxAnisotropy = 1;
3842 sampler_ci.compareEnable = VK_FALSE;
3843 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3844 sampler_ci.minLod = 1.0;
3845 sampler_ci.maxLod = 1.0;
3846 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3847 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3848 VkSampler sampler;
3849
3850 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3851 ASSERT_VK_SUCCESS(err);
3852
3853 layout_binding[2].binding = 2;
3854 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3855 layout_binding[2].descriptorCount = 1;
3856 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3857 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3858
Mark Muellerd4914412016-06-13 17:52:06 -06003859 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3860 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3861 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3862 ds_layout_ci.pBindings = layout_binding;
3863 VkDescriptorSetLayout ds_layout;
3864 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3865 ASSERT_VK_SUCCESS(err);
3866
3867 VkDescriptorSetAllocateInfo alloc_info = {};
3868 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3869 alloc_info.descriptorSetCount = 1;
3870 alloc_info.descriptorPool = ds_pool;
3871 alloc_info.pSetLayouts = &ds_layout;
3872 VkDescriptorSet descriptorSet;
3873 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3874 ASSERT_VK_SUCCESS(err);
3875
3876 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3877 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3878 pipeline_layout_ci.pNext = NULL;
3879 pipeline_layout_ci.setLayoutCount = 1;
3880 pipeline_layout_ci.pSetLayouts = &ds_layout;
3881
3882 VkPipelineLayout pipeline_layout;
3883 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3884 ASSERT_VK_SUCCESS(err);
3885
Mark Mueller5c838ce2016-06-16 09:54:29 -06003886 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003887 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3888 descriptor_write.dstSet = descriptorSet;
3889 descriptor_write.dstBinding = 0;
3890 descriptor_write.descriptorCount = 1;
3891 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3892
Mark Mueller5c838ce2016-06-16 09:54:29 -06003893 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003894 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3895 m_errorMonitor->VerifyFound();
3896
3897 // Create a buffer to update the descriptor with
3898 uint32_t qfi = 0;
3899 VkBufferCreateInfo buffCI = {};
3900 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3901 buffCI.size = 1024;
3902 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3903 buffCI.queueFamilyIndexCount = 1;
3904 buffCI.pQueueFamilyIndices = &qfi;
3905
3906 VkBuffer dyub;
3907 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3908 ASSERT_VK_SUCCESS(err);
3909 VkDescriptorBufferInfo buffInfo = {};
3910 buffInfo.buffer = dyub;
3911 buffInfo.offset = 0;
3912 buffInfo.range = 1024;
3913
3914 descriptor_write.pBufferInfo = &buffInfo;
3915 descriptor_write.descriptorCount = 2;
3916
Mark Mueller5c838ce2016-06-16 09:54:29 -06003917 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3919 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3920 m_errorMonitor->VerifyFound();
3921
Mark Mueller5c838ce2016-06-16 09:54:29 -06003922 // 3) The second descriptor has a null_ptr pImmutableSamplers and
3923 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06003924 descriptor_write.dstBinding = 1;
3925 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06003926
Mark Mueller5c838ce2016-06-16 09:54:29 -06003927 // Make pImageInfo index non-null to avoid complaints of it missing
3928 VkDescriptorImageInfo imageInfo = {};
3929 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3930 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06003931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
3932 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3933 m_errorMonitor->VerifyFound();
3934
Mark Muellerd4914412016-06-13 17:52:06 -06003935 vkDestroyBuffer(m_device->device(), dyub, NULL);
3936 vkDestroySampler(m_device->device(), sampler, NULL);
3937 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3938 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3939 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3940}
3941
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003942TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
3943 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
3944 "due to a buffer dependency being destroyed.");
3945 ASSERT_NO_FATAL_FAILURE(InitState());
3946
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003947 VkBuffer buffer;
3948 VkDeviceMemory mem;
3949 VkMemoryRequirements mem_reqs;
3950
3951 VkBufferCreateInfo buf_info = {};
3952 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12003953 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003954 buf_info.size = 256;
3955 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
3956 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
3957 ASSERT_VK_SUCCESS(err);
3958
3959 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
3960
3961 VkMemoryAllocateInfo alloc_info = {};
3962 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3963 alloc_info.allocationSize = 256;
3964 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003965 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 -06003966 if (!pass) {
3967 vkDestroyBuffer(m_device->device(), buffer, NULL);
3968 return;
3969 }
3970 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
3971 ASSERT_VK_SUCCESS(err);
3972
3973 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
3974 ASSERT_VK_SUCCESS(err);
3975
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003976 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12003977 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003978 m_commandBuffer->EndCommandBuffer();
3979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003981 // Destroy buffer dependency prior to submit to cause ERROR
3982 vkDestroyBuffer(m_device->device(), buffer, NULL);
3983
3984 VkSubmitInfo submit_info = {};
3985 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3986 submit_info.commandBufferCount = 1;
3987 submit_info.pCommandBuffers = &m_commandBuffer->handle();
3988 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3989
3990 m_errorMonitor->VerifyFound();
3991 vkFreeMemory(m_device->handle(), mem, NULL);
3992}
3993
Tobin Ehlisea413442016-09-28 10:23:59 -06003994TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
3995 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
3996
3997 ASSERT_NO_FATAL_FAILURE(InitState());
3998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3999
4000 VkDescriptorPoolSize ds_type_count;
4001 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4002 ds_type_count.descriptorCount = 1;
4003
4004 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4005 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4006 ds_pool_ci.maxSets = 1;
4007 ds_pool_ci.poolSizeCount = 1;
4008 ds_pool_ci.pPoolSizes = &ds_type_count;
4009
4010 VkDescriptorPool ds_pool;
4011 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4012 ASSERT_VK_SUCCESS(err);
4013
4014 VkDescriptorSetLayoutBinding layout_binding;
4015 layout_binding.binding = 0;
4016 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4017 layout_binding.descriptorCount = 1;
4018 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4019 layout_binding.pImmutableSamplers = NULL;
4020
4021 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4022 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4023 ds_layout_ci.bindingCount = 1;
4024 ds_layout_ci.pBindings = &layout_binding;
4025 VkDescriptorSetLayout ds_layout;
4026 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4027 ASSERT_VK_SUCCESS(err);
4028
4029 VkDescriptorSetAllocateInfo alloc_info = {};
4030 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4031 alloc_info.descriptorSetCount = 1;
4032 alloc_info.descriptorPool = ds_pool;
4033 alloc_info.pSetLayouts = &ds_layout;
4034 VkDescriptorSet descriptor_set;
4035 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4036 ASSERT_VK_SUCCESS(err);
4037
4038 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4039 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4040 pipeline_layout_ci.pNext = NULL;
4041 pipeline_layout_ci.setLayoutCount = 1;
4042 pipeline_layout_ci.pSetLayouts = &ds_layout;
4043
4044 VkPipelineLayout pipeline_layout;
4045 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4046 ASSERT_VK_SUCCESS(err);
4047
4048 VkBuffer buffer;
4049 uint32_t queue_family_index = 0;
4050 VkBufferCreateInfo buffer_create_info = {};
4051 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4052 buffer_create_info.size = 1024;
4053 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4054 buffer_create_info.queueFamilyIndexCount = 1;
4055 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4056
4057 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4058 ASSERT_VK_SUCCESS(err);
4059
4060 VkMemoryRequirements memory_reqs;
4061 VkDeviceMemory buffer_memory;
4062
4063 VkMemoryAllocateInfo memory_info = {};
4064 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4065 memory_info.allocationSize = 0;
4066 memory_info.memoryTypeIndex = 0;
4067
4068 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4069 memory_info.allocationSize = memory_reqs.size;
4070 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4071 ASSERT_TRUE(pass);
4072
4073 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4074 ASSERT_VK_SUCCESS(err);
4075 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4076 ASSERT_VK_SUCCESS(err);
4077
4078 VkBufferView view;
4079 VkBufferViewCreateInfo bvci = {};
4080 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4081 bvci.buffer = buffer;
4082 bvci.format = VK_FORMAT_R8_UNORM;
4083 bvci.range = VK_WHOLE_SIZE;
4084
4085 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4086 ASSERT_VK_SUCCESS(err);
4087
4088 VkWriteDescriptorSet descriptor_write = {};
4089 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4090 descriptor_write.dstSet = descriptor_set;
4091 descriptor_write.dstBinding = 0;
4092 descriptor_write.descriptorCount = 1;
4093 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4094 descriptor_write.pTexelBufferView = &view;
4095
4096 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4097
4098 char const *vsSource = "#version 450\n"
4099 "\n"
4100 "out gl_PerVertex { \n"
4101 " vec4 gl_Position;\n"
4102 "};\n"
4103 "void main(){\n"
4104 " gl_Position = vec4(1);\n"
4105 "}\n";
4106 char const *fsSource = "#version 450\n"
4107 "\n"
4108 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4109 "layout(location=0) out vec4 x;\n"
4110 "void main(){\n"
4111 " x = imageLoad(s, 0);\n"
4112 "}\n";
4113 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4114 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4115 VkPipelineObj pipe(m_device);
4116 pipe.AddShader(&vs);
4117 pipe.AddShader(&fs);
4118 pipe.AddColorAttachment();
4119 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4120
4121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4123
4124 BeginCommandBuffer();
4125 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4126 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4127 VkRect2D scissor = {{0, 0}, {16, 16}};
4128 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4129 // Bind pipeline to cmd buffer
4130 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4131 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4132 &descriptor_set, 0, nullptr);
4133 Draw(1, 0, 0, 0);
4134 EndCommandBuffer();
4135
4136 // Delete BufferView in order to invalidate cmd buffer
4137 vkDestroyBufferView(m_device->device(), view, NULL);
4138 // Now attempt submit of cmd buffer
4139 VkSubmitInfo submit_info = {};
4140 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4141 submit_info.commandBufferCount = 1;
4142 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4143 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4144 m_errorMonitor->VerifyFound();
4145
4146 // Clean-up
4147 vkDestroyBuffer(m_device->device(), buffer, NULL);
4148 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4149 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4150 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4151 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4152}
4153
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004154TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4155 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4156 "due to an image dependency being destroyed.");
4157 ASSERT_NO_FATAL_FAILURE(InitState());
4158
4159 VkImage image;
4160 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4161 VkImageCreateInfo image_create_info = {};
4162 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4163 image_create_info.pNext = NULL;
4164 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4165 image_create_info.format = tex_format;
4166 image_create_info.extent.width = 32;
4167 image_create_info.extent.height = 32;
4168 image_create_info.extent.depth = 1;
4169 image_create_info.mipLevels = 1;
4170 image_create_info.arrayLayers = 1;
4171 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4172 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004173 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004174 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004175 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004176 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004177 // Have to bind memory to image before recording cmd in cmd buffer using it
4178 VkMemoryRequirements mem_reqs;
4179 VkDeviceMemory image_mem;
4180 bool pass;
4181 VkMemoryAllocateInfo mem_alloc = {};
4182 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4183 mem_alloc.pNext = NULL;
4184 mem_alloc.memoryTypeIndex = 0;
4185 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4186 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004187 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004188 ASSERT_TRUE(pass);
4189 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4190 ASSERT_VK_SUCCESS(err);
4191 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4192 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004193
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004194 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004195 VkClearColorValue ccv;
4196 ccv.float32[0] = 1.0f;
4197 ccv.float32[1] = 1.0f;
4198 ccv.float32[2] = 1.0f;
4199 ccv.float32[3] = 1.0f;
4200 VkImageSubresourceRange isr = {};
4201 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004202 isr.baseArrayLayer = 0;
4203 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004204 isr.layerCount = 1;
4205 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004206 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004207 m_commandBuffer->EndCommandBuffer();
4208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004210 // Destroy image dependency prior to submit to cause ERROR
4211 vkDestroyImage(m_device->device(), image, NULL);
4212
4213 VkSubmitInfo submit_info = {};
4214 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4215 submit_info.commandBufferCount = 1;
4216 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4217 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4218
4219 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004220 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004221}
4222
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004223TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4224 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4225 "due to a framebuffer image dependency being destroyed.");
4226 VkFormatProperties format_properties;
4227 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004228 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4229 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004230 return;
4231 }
4232
4233 ASSERT_NO_FATAL_FAILURE(InitState());
4234 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4235
4236 VkImageCreateInfo image_ci = {};
4237 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4238 image_ci.pNext = NULL;
4239 image_ci.imageType = VK_IMAGE_TYPE_2D;
4240 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4241 image_ci.extent.width = 32;
4242 image_ci.extent.height = 32;
4243 image_ci.extent.depth = 1;
4244 image_ci.mipLevels = 1;
4245 image_ci.arrayLayers = 1;
4246 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4247 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004248 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004249 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4250 image_ci.flags = 0;
4251 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004252 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004253
4254 VkMemoryRequirements memory_reqs;
4255 VkDeviceMemory image_memory;
4256 bool pass;
4257 VkMemoryAllocateInfo memory_info = {};
4258 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4259 memory_info.pNext = NULL;
4260 memory_info.allocationSize = 0;
4261 memory_info.memoryTypeIndex = 0;
4262 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4263 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004264 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004265 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004266 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004267 ASSERT_VK_SUCCESS(err);
4268 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4269 ASSERT_VK_SUCCESS(err);
4270
4271 VkImageViewCreateInfo ivci = {
4272 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4273 nullptr,
4274 0,
4275 image,
4276 VK_IMAGE_VIEW_TYPE_2D,
4277 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004278 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004279 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4280 };
4281 VkImageView view;
4282 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4283 ASSERT_VK_SUCCESS(err);
4284
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004285 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004286 VkFramebuffer fb;
4287 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4288 ASSERT_VK_SUCCESS(err);
4289
4290 // Just use default renderpass with our framebuffer
4291 m_renderPassBeginInfo.framebuffer = fb;
4292 // Create Null cmd buffer for submit
4293 BeginCommandBuffer();
4294 EndCommandBuffer();
4295 // Destroy image attached to framebuffer to invalidate cmd buffer
4296 vkDestroyImage(m_device->device(), image, NULL);
4297 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004299 QueueCommandBuffer(false);
4300 m_errorMonitor->VerifyFound();
4301
4302 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4303 vkDestroyImageView(m_device->device(), view, nullptr);
4304 vkFreeMemory(m_device->device(), image_memory, nullptr);
4305}
4306
Tobin Ehlisb329f992016-10-12 13:20:29 -06004307TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4308 TEST_DESCRIPTION("Delete in-use framebuffer.");
4309 VkFormatProperties format_properties;
4310 VkResult err = VK_SUCCESS;
4311 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4312
4313 ASSERT_NO_FATAL_FAILURE(InitState());
4314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4315
4316 VkImageObj image(m_device);
4317 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4318 ASSERT_TRUE(image.initialized());
4319 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4320
4321 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4322 VkFramebuffer fb;
4323 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4324 ASSERT_VK_SUCCESS(err);
4325
4326 // Just use default renderpass with our framebuffer
4327 m_renderPassBeginInfo.framebuffer = fb;
4328 // Create Null cmd buffer for submit
4329 BeginCommandBuffer();
4330 EndCommandBuffer();
4331 // Submit cmd buffer to put it in-flight
4332 VkSubmitInfo submit_info = {};
4333 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4334 submit_info.commandBufferCount = 1;
4335 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4336 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4337 // Destroy framebuffer while in-flight
4338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4339 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4340 m_errorMonitor->VerifyFound();
4341 // Wait for queue to complete so we can safely destroy everything
4342 vkQueueWaitIdle(m_device->m_queue);
4343 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4344}
4345
Tobin Ehlis88becd72016-09-21 14:33:41 -06004346TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4347 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4348 VkFormatProperties format_properties;
4349 VkResult err = VK_SUCCESS;
4350 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004351
4352 ASSERT_NO_FATAL_FAILURE(InitState());
4353 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4354
4355 VkImageCreateInfo image_ci = {};
4356 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4357 image_ci.pNext = NULL;
4358 image_ci.imageType = VK_IMAGE_TYPE_2D;
4359 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4360 image_ci.extent.width = 256;
4361 image_ci.extent.height = 256;
4362 image_ci.extent.depth = 1;
4363 image_ci.mipLevels = 1;
4364 image_ci.arrayLayers = 1;
4365 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4366 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004367 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004368 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4369 image_ci.flags = 0;
4370 VkImage image;
4371 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4372
4373 VkMemoryRequirements memory_reqs;
4374 VkDeviceMemory image_memory;
4375 bool pass;
4376 VkMemoryAllocateInfo memory_info = {};
4377 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4378 memory_info.pNext = NULL;
4379 memory_info.allocationSize = 0;
4380 memory_info.memoryTypeIndex = 0;
4381 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4382 memory_info.allocationSize = memory_reqs.size;
4383 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4384 ASSERT_TRUE(pass);
4385 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4386 ASSERT_VK_SUCCESS(err);
4387 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4388 ASSERT_VK_SUCCESS(err);
4389
4390 VkImageViewCreateInfo ivci = {
4391 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4392 nullptr,
4393 0,
4394 image,
4395 VK_IMAGE_VIEW_TYPE_2D,
4396 VK_FORMAT_B8G8R8A8_UNORM,
4397 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4398 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4399 };
4400 VkImageView view;
4401 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4402 ASSERT_VK_SUCCESS(err);
4403
4404 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4405 VkFramebuffer fb;
4406 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4407 ASSERT_VK_SUCCESS(err);
4408
4409 // Just use default renderpass with our framebuffer
4410 m_renderPassBeginInfo.framebuffer = fb;
4411 // Create Null cmd buffer for submit
4412 BeginCommandBuffer();
4413 EndCommandBuffer();
4414 // Submit cmd buffer to put it (and attached imageView) in-flight
4415 VkSubmitInfo submit_info = {};
4416 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4417 submit_info.commandBufferCount = 1;
4418 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4419 // Submit cmd buffer to put framebuffer and children in-flight
4420 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4421 // Destroy image attached to framebuffer while in-flight
4422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4423 vkDestroyImage(m_device->device(), image, NULL);
4424 m_errorMonitor->VerifyFound();
4425 // Wait for queue to complete so we can safely destroy image and other objects
4426 vkQueueWaitIdle(m_device->m_queue);
4427 vkDestroyImage(m_device->device(), image, NULL);
4428 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4429 vkDestroyImageView(m_device->device(), view, nullptr);
4430 vkFreeMemory(m_device->device(), image_memory, nullptr);
4431}
4432
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004433TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4434 TEST_DESCRIPTION("Delete in-use renderPass.");
4435
4436 ASSERT_NO_FATAL_FAILURE(InitState());
4437 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4438
4439 // Create simple renderpass
4440 VkAttachmentReference attach = {};
4441 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4442 VkSubpassDescription subpass = {};
4443 subpass.pColorAttachments = &attach;
4444 VkRenderPassCreateInfo rpci = {};
4445 rpci.subpassCount = 1;
4446 rpci.pSubpasses = &subpass;
4447 rpci.attachmentCount = 1;
4448 VkAttachmentDescription attach_desc = {};
4449 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4450 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4451 rpci.pAttachments = &attach_desc;
4452 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4453 VkRenderPass rp;
4454 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4455 ASSERT_VK_SUCCESS(err);
4456
4457 // Create a pipeline that uses the given renderpass
4458 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4459 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4460
4461 VkPipelineLayout pipeline_layout;
4462 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4463 ASSERT_VK_SUCCESS(err);
4464
4465 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4466 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4467 vp_state_ci.viewportCount = 1;
4468 VkViewport vp = {}; // Just need dummy vp to point to
4469 vp_state_ci.pViewports = &vp;
4470 vp_state_ci.scissorCount = 1;
4471 VkRect2D scissors = {}; // Dummy scissors to point to
4472 vp_state_ci.pScissors = &scissors;
4473
4474 VkPipelineShaderStageCreateInfo shaderStages[2];
4475 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4476
4477 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4478 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4479 // but add it to be able to run on more devices
4480 shaderStages[0] = vs.GetStageCreateInfo();
4481 shaderStages[1] = fs.GetStageCreateInfo();
4482
4483 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4484 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4485
4486 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4487 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4488 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4489
4490 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4491 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4492 rs_ci.rasterizerDiscardEnable = true;
4493 rs_ci.lineWidth = 1.0f;
4494
4495 VkPipelineColorBlendAttachmentState att = {};
4496 att.blendEnable = VK_FALSE;
4497 att.colorWriteMask = 0xf;
4498
4499 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4500 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4501 cb_ci.attachmentCount = 1;
4502 cb_ci.pAttachments = &att;
4503
4504 VkGraphicsPipelineCreateInfo gp_ci = {};
4505 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4506 gp_ci.stageCount = 2;
4507 gp_ci.pStages = shaderStages;
4508 gp_ci.pVertexInputState = &vi_ci;
4509 gp_ci.pInputAssemblyState = &ia_ci;
4510 gp_ci.pViewportState = &vp_state_ci;
4511 gp_ci.pRasterizationState = &rs_ci;
4512 gp_ci.pColorBlendState = &cb_ci;
4513 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4514 gp_ci.layout = pipeline_layout;
4515 gp_ci.renderPass = rp;
4516
4517 VkPipelineCacheCreateInfo pc_ci = {};
4518 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4519
4520 VkPipeline pipeline;
4521 VkPipelineCache pipe_cache;
4522 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4523 ASSERT_VK_SUCCESS(err);
4524
4525 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4526 ASSERT_VK_SUCCESS(err);
4527 // Bind pipeline to cmd buffer, will also bind renderpass
4528 m_commandBuffer->BeginCommandBuffer();
4529 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4530 m_commandBuffer->EndCommandBuffer();
4531
4532 VkSubmitInfo submit_info = {};
4533 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4534 submit_info.commandBufferCount = 1;
4535 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4536 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4537
4538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4539 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4540 m_errorMonitor->VerifyFound();
4541
4542 // Wait for queue to complete so we can safely destroy everything
4543 vkQueueWaitIdle(m_device->m_queue);
4544 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4545 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4546 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4547 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4548}
4549
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004550TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004551 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004552 ASSERT_NO_FATAL_FAILURE(InitState());
4553
4554 VkImage image;
4555 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4556 VkImageCreateInfo image_create_info = {};
4557 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4558 image_create_info.pNext = NULL;
4559 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4560 image_create_info.format = tex_format;
4561 image_create_info.extent.width = 32;
4562 image_create_info.extent.height = 32;
4563 image_create_info.extent.depth = 1;
4564 image_create_info.mipLevels = 1;
4565 image_create_info.arrayLayers = 1;
4566 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4567 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004568 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004569 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004570 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004571 ASSERT_VK_SUCCESS(err);
4572 // Have to bind memory to image before recording cmd in cmd buffer using it
4573 VkMemoryRequirements mem_reqs;
4574 VkDeviceMemory image_mem;
4575 bool pass;
4576 VkMemoryAllocateInfo mem_alloc = {};
4577 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4578 mem_alloc.pNext = NULL;
4579 mem_alloc.memoryTypeIndex = 0;
4580 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4581 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004582 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004583 ASSERT_TRUE(pass);
4584 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4585 ASSERT_VK_SUCCESS(err);
4586
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004587 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004589 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004590
4591 m_commandBuffer->BeginCommandBuffer();
4592 VkClearColorValue ccv;
4593 ccv.float32[0] = 1.0f;
4594 ccv.float32[1] = 1.0f;
4595 ccv.float32[2] = 1.0f;
4596 ccv.float32[3] = 1.0f;
4597 VkImageSubresourceRange isr = {};
4598 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4599 isr.baseArrayLayer = 0;
4600 isr.baseMipLevel = 0;
4601 isr.layerCount = 1;
4602 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004603 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004604 m_commandBuffer->EndCommandBuffer();
4605
4606 m_errorMonitor->VerifyFound();
4607 vkDestroyImage(m_device->device(), image, NULL);
4608 vkFreeMemory(m_device->device(), image_mem, nullptr);
4609}
4610
4611TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004612 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004613 ASSERT_NO_FATAL_FAILURE(InitState());
4614
4615 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004616 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 -06004617 VK_IMAGE_TILING_OPTIMAL, 0);
4618 ASSERT_TRUE(image.initialized());
4619
4620 VkBuffer buffer;
4621 VkDeviceMemory mem;
4622 VkMemoryRequirements mem_reqs;
4623
4624 VkBufferCreateInfo buf_info = {};
4625 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004626 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004627 buf_info.size = 256;
4628 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4629 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4630 ASSERT_VK_SUCCESS(err);
4631
4632 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4633
4634 VkMemoryAllocateInfo alloc_info = {};
4635 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4636 alloc_info.allocationSize = 256;
4637 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004638 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 -06004639 if (!pass) {
4640 vkDestroyBuffer(m_device->device(), buffer, NULL);
4641 return;
4642 }
4643 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4644 ASSERT_VK_SUCCESS(err);
4645
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004646 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004648 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004649 VkBufferImageCopy region = {};
4650 region.bufferRowLength = 128;
4651 region.bufferImageHeight = 128;
4652 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4653
4654 region.imageSubresource.layerCount = 1;
4655 region.imageExtent.height = 4;
4656 region.imageExtent.width = 4;
4657 region.imageExtent.depth = 1;
4658 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004659 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4660 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004661 m_commandBuffer->EndCommandBuffer();
4662
4663 m_errorMonitor->VerifyFound();
4664
4665 vkDestroyBuffer(m_device->device(), buffer, NULL);
4666 vkFreeMemory(m_device->handle(), mem, NULL);
4667}
4668
Tobin Ehlis85940f52016-07-07 16:57:21 -06004669TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4670 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4671 "due to an event dependency being destroyed.");
4672 ASSERT_NO_FATAL_FAILURE(InitState());
4673
4674 VkEvent event;
4675 VkEventCreateInfo evci = {};
4676 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4677 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4678 ASSERT_VK_SUCCESS(result);
4679
4680 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004681 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004682 m_commandBuffer->EndCommandBuffer();
4683
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004685 // Destroy event dependency prior to submit to cause ERROR
4686 vkDestroyEvent(m_device->device(), event, NULL);
4687
4688 VkSubmitInfo submit_info = {};
4689 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4690 submit_info.commandBufferCount = 1;
4691 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4692 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4693
4694 m_errorMonitor->VerifyFound();
4695}
4696
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004697TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4698 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4699 "due to a query pool dependency being destroyed.");
4700 ASSERT_NO_FATAL_FAILURE(InitState());
4701
4702 VkQueryPool query_pool;
4703 VkQueryPoolCreateInfo qpci{};
4704 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4705 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4706 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004707 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004708 ASSERT_VK_SUCCESS(result);
4709
4710 m_commandBuffer->BeginCommandBuffer();
4711 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4712 m_commandBuffer->EndCommandBuffer();
4713
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004715 // Destroy query pool dependency prior to submit to cause ERROR
4716 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4717
4718 VkSubmitInfo submit_info = {};
4719 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4720 submit_info.commandBufferCount = 1;
4721 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4722 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4723
4724 m_errorMonitor->VerifyFound();
4725}
4726
Tobin Ehlis24130d92016-07-08 15:50:53 -06004727TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4728 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4729 "due to a pipeline dependency being destroyed.");
4730 ASSERT_NO_FATAL_FAILURE(InitState());
4731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4732
4733 VkResult err;
4734
4735 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4736 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4737
4738 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004739 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004740 ASSERT_VK_SUCCESS(err);
4741
4742 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4743 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4744 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004745 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004746 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004747 vp_state_ci.scissorCount = 1;
4748 VkRect2D scissors = {}; // Dummy scissors to point to
4749 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004750
4751 VkPipelineShaderStageCreateInfo shaderStages[2];
4752 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4753
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004754 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4755 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4756 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004757 shaderStages[0] = vs.GetStageCreateInfo();
4758 shaderStages[1] = fs.GetStageCreateInfo();
4759
4760 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4761 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4762
4763 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4764 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4765 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4766
4767 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4768 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004769 rs_ci.rasterizerDiscardEnable = true;
4770 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004771
4772 VkPipelineColorBlendAttachmentState att = {};
4773 att.blendEnable = VK_FALSE;
4774 att.colorWriteMask = 0xf;
4775
4776 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4777 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4778 cb_ci.attachmentCount = 1;
4779 cb_ci.pAttachments = &att;
4780
4781 VkGraphicsPipelineCreateInfo gp_ci = {};
4782 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4783 gp_ci.stageCount = 2;
4784 gp_ci.pStages = shaderStages;
4785 gp_ci.pVertexInputState = &vi_ci;
4786 gp_ci.pInputAssemblyState = &ia_ci;
4787 gp_ci.pViewportState = &vp_state_ci;
4788 gp_ci.pRasterizationState = &rs_ci;
4789 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004790 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4791 gp_ci.layout = pipeline_layout;
4792 gp_ci.renderPass = renderPass();
4793
4794 VkPipelineCacheCreateInfo pc_ci = {};
4795 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4796
4797 VkPipeline pipeline;
4798 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004799 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004800 ASSERT_VK_SUCCESS(err);
4801
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004802 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004803 ASSERT_VK_SUCCESS(err);
4804
4805 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004806 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004807 m_commandBuffer->EndCommandBuffer();
4808 // Now destroy pipeline in order to cause error when submitting
4809 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4810
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004812
4813 VkSubmitInfo submit_info = {};
4814 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4815 submit_info.commandBufferCount = 1;
4816 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4817 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4818
4819 m_errorMonitor->VerifyFound();
4820 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4821 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4822}
4823
Tobin Ehlis31289162016-08-17 14:57:58 -06004824TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4825 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4826 "due to a bound descriptor set with a buffer dependency "
4827 "being destroyed.");
4828 ASSERT_NO_FATAL_FAILURE(InitState());
4829 ASSERT_NO_FATAL_FAILURE(InitViewport());
4830 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4831
4832 VkDescriptorPoolSize ds_type_count = {};
4833 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4834 ds_type_count.descriptorCount = 1;
4835
4836 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4837 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4838 ds_pool_ci.pNext = NULL;
4839 ds_pool_ci.maxSets = 1;
4840 ds_pool_ci.poolSizeCount = 1;
4841 ds_pool_ci.pPoolSizes = &ds_type_count;
4842
4843 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004844 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004845 ASSERT_VK_SUCCESS(err);
4846
4847 VkDescriptorSetLayoutBinding dsl_binding = {};
4848 dsl_binding.binding = 0;
4849 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4850 dsl_binding.descriptorCount = 1;
4851 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4852 dsl_binding.pImmutableSamplers = NULL;
4853
4854 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4855 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4856 ds_layout_ci.pNext = NULL;
4857 ds_layout_ci.bindingCount = 1;
4858 ds_layout_ci.pBindings = &dsl_binding;
4859 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004860 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004861 ASSERT_VK_SUCCESS(err);
4862
4863 VkDescriptorSet descriptorSet;
4864 VkDescriptorSetAllocateInfo alloc_info = {};
4865 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4866 alloc_info.descriptorSetCount = 1;
4867 alloc_info.descriptorPool = ds_pool;
4868 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004869 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004870 ASSERT_VK_SUCCESS(err);
4871
4872 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4873 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4874 pipeline_layout_ci.pNext = NULL;
4875 pipeline_layout_ci.setLayoutCount = 1;
4876 pipeline_layout_ci.pSetLayouts = &ds_layout;
4877
4878 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004879 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004880 ASSERT_VK_SUCCESS(err);
4881
4882 // Create a buffer to update the descriptor with
4883 uint32_t qfi = 0;
4884 VkBufferCreateInfo buffCI = {};
4885 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4886 buffCI.size = 1024;
4887 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4888 buffCI.queueFamilyIndexCount = 1;
4889 buffCI.pQueueFamilyIndices = &qfi;
4890
4891 VkBuffer buffer;
4892 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4893 ASSERT_VK_SUCCESS(err);
4894 // Allocate memory and bind to buffer so we can make it to the appropriate
4895 // error
4896 VkMemoryAllocateInfo mem_alloc = {};
4897 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4898 mem_alloc.pNext = NULL;
4899 mem_alloc.allocationSize = 1024;
4900 mem_alloc.memoryTypeIndex = 0;
4901
4902 VkMemoryRequirements memReqs;
4903 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004904 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004905 if (!pass) {
4906 vkDestroyBuffer(m_device->device(), buffer, NULL);
4907 return;
4908 }
4909
4910 VkDeviceMemory mem;
4911 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4912 ASSERT_VK_SUCCESS(err);
4913 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4914 ASSERT_VK_SUCCESS(err);
4915 // Correctly update descriptor to avoid "NOT_UPDATED" error
4916 VkDescriptorBufferInfo buffInfo = {};
4917 buffInfo.buffer = buffer;
4918 buffInfo.offset = 0;
4919 buffInfo.range = 1024;
4920
4921 VkWriteDescriptorSet descriptor_write;
4922 memset(&descriptor_write, 0, sizeof(descriptor_write));
4923 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4924 descriptor_write.dstSet = descriptorSet;
4925 descriptor_write.dstBinding = 0;
4926 descriptor_write.descriptorCount = 1;
4927 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4928 descriptor_write.pBufferInfo = &buffInfo;
4929
4930 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4931
4932 // Create PSO to be used for draw-time errors below
4933 char const *vsSource = "#version 450\n"
4934 "\n"
4935 "out gl_PerVertex { \n"
4936 " vec4 gl_Position;\n"
4937 "};\n"
4938 "void main(){\n"
4939 " gl_Position = vec4(1);\n"
4940 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004941 char const *fsSource = "#version 450\n"
4942 "\n"
4943 "layout(location=0) out vec4 x;\n"
4944 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4945 "void main(){\n"
4946 " x = vec4(bar.y);\n"
4947 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06004948 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4949 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4950 VkPipelineObj pipe(m_device);
4951 pipe.AddShader(&vs);
4952 pipe.AddShader(&fs);
4953 pipe.AddColorAttachment();
4954 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4955
4956 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004957 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4958 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4959 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06004960 Draw(1, 0, 0, 0);
4961 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06004963 // Destroy buffer should invalidate the cmd buffer, causing error on submit
4964 vkDestroyBuffer(m_device->device(), buffer, NULL);
4965 // Attempt to submit cmd buffer
4966 VkSubmitInfo submit_info = {};
4967 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4968 submit_info.commandBufferCount = 1;
4969 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4970 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4971 m_errorMonitor->VerifyFound();
4972 // Cleanup
4973 vkFreeMemory(m_device->device(), mem, NULL);
4974
4975 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4976 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4977 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4978}
4979
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004980TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
4981 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4982 "due to a bound descriptor sets with a combined image "
4983 "sampler having their image, sampler, and descriptor set "
4984 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06004985 "submit associated cmd buffers. Attempt to destroy a "
4986 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004987 ASSERT_NO_FATAL_FAILURE(InitState());
4988 ASSERT_NO_FATAL_FAILURE(InitViewport());
4989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4990
4991 VkDescriptorPoolSize ds_type_count = {};
4992 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4993 ds_type_count.descriptorCount = 1;
4994
4995 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4996 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4997 ds_pool_ci.pNext = NULL;
4998 ds_pool_ci.maxSets = 1;
4999 ds_pool_ci.poolSizeCount = 1;
5000 ds_pool_ci.pPoolSizes = &ds_type_count;
5001
5002 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005003 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005004 ASSERT_VK_SUCCESS(err);
5005
5006 VkDescriptorSetLayoutBinding dsl_binding = {};
5007 dsl_binding.binding = 0;
5008 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5009 dsl_binding.descriptorCount = 1;
5010 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5011 dsl_binding.pImmutableSamplers = NULL;
5012
5013 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5014 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5015 ds_layout_ci.pNext = NULL;
5016 ds_layout_ci.bindingCount = 1;
5017 ds_layout_ci.pBindings = &dsl_binding;
5018 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005019 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005020 ASSERT_VK_SUCCESS(err);
5021
5022 VkDescriptorSet descriptorSet;
5023 VkDescriptorSetAllocateInfo alloc_info = {};
5024 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5025 alloc_info.descriptorSetCount = 1;
5026 alloc_info.descriptorPool = ds_pool;
5027 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005028 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005029 ASSERT_VK_SUCCESS(err);
5030
5031 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5032 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5033 pipeline_layout_ci.pNext = NULL;
5034 pipeline_layout_ci.setLayoutCount = 1;
5035 pipeline_layout_ci.pSetLayouts = &ds_layout;
5036
5037 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005038 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005039 ASSERT_VK_SUCCESS(err);
5040
5041 // Create images to update the descriptor with
5042 VkImage image;
5043 VkImage image2;
5044 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5045 const int32_t tex_width = 32;
5046 const int32_t tex_height = 32;
5047 VkImageCreateInfo image_create_info = {};
5048 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5049 image_create_info.pNext = NULL;
5050 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5051 image_create_info.format = tex_format;
5052 image_create_info.extent.width = tex_width;
5053 image_create_info.extent.height = tex_height;
5054 image_create_info.extent.depth = 1;
5055 image_create_info.mipLevels = 1;
5056 image_create_info.arrayLayers = 1;
5057 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5058 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5059 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5060 image_create_info.flags = 0;
5061 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5062 ASSERT_VK_SUCCESS(err);
5063 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5064 ASSERT_VK_SUCCESS(err);
5065
5066 VkMemoryRequirements memory_reqs;
5067 VkDeviceMemory image_memory;
5068 bool pass;
5069 VkMemoryAllocateInfo memory_info = {};
5070 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5071 memory_info.pNext = NULL;
5072 memory_info.allocationSize = 0;
5073 memory_info.memoryTypeIndex = 0;
5074 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5075 // Allocate enough memory for both images
5076 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005077 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005078 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005079 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005080 ASSERT_VK_SUCCESS(err);
5081 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5082 ASSERT_VK_SUCCESS(err);
5083 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005084 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005085 ASSERT_VK_SUCCESS(err);
5086
5087 VkImageViewCreateInfo image_view_create_info = {};
5088 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5089 image_view_create_info.image = image;
5090 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5091 image_view_create_info.format = tex_format;
5092 image_view_create_info.subresourceRange.layerCount = 1;
5093 image_view_create_info.subresourceRange.baseMipLevel = 0;
5094 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005095 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005096
5097 VkImageView view;
5098 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005099 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005100 ASSERT_VK_SUCCESS(err);
5101 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005102 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005103 ASSERT_VK_SUCCESS(err);
5104 // Create Samplers
5105 VkSamplerCreateInfo sampler_ci = {};
5106 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5107 sampler_ci.pNext = NULL;
5108 sampler_ci.magFilter = VK_FILTER_NEAREST;
5109 sampler_ci.minFilter = VK_FILTER_NEAREST;
5110 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5111 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5112 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5113 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5114 sampler_ci.mipLodBias = 1.0;
5115 sampler_ci.anisotropyEnable = VK_FALSE;
5116 sampler_ci.maxAnisotropy = 1;
5117 sampler_ci.compareEnable = VK_FALSE;
5118 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5119 sampler_ci.minLod = 1.0;
5120 sampler_ci.maxLod = 1.0;
5121 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5122 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5123 VkSampler sampler;
5124 VkSampler sampler2;
5125 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5126 ASSERT_VK_SUCCESS(err);
5127 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5128 ASSERT_VK_SUCCESS(err);
5129 // Update descriptor with image and sampler
5130 VkDescriptorImageInfo img_info = {};
5131 img_info.sampler = sampler;
5132 img_info.imageView = view;
5133 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5134
5135 VkWriteDescriptorSet descriptor_write;
5136 memset(&descriptor_write, 0, sizeof(descriptor_write));
5137 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5138 descriptor_write.dstSet = descriptorSet;
5139 descriptor_write.dstBinding = 0;
5140 descriptor_write.descriptorCount = 1;
5141 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5142 descriptor_write.pImageInfo = &img_info;
5143
5144 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5145
5146 // Create PSO to be used for draw-time errors below
5147 char const *vsSource = "#version 450\n"
5148 "\n"
5149 "out gl_PerVertex { \n"
5150 " vec4 gl_Position;\n"
5151 "};\n"
5152 "void main(){\n"
5153 " gl_Position = vec4(1);\n"
5154 "}\n";
5155 char const *fsSource = "#version 450\n"
5156 "\n"
5157 "layout(set=0, binding=0) uniform sampler2D s;\n"
5158 "layout(location=0) out vec4 x;\n"
5159 "void main(){\n"
5160 " x = texture(s, vec2(1));\n"
5161 "}\n";
5162 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5163 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5164 VkPipelineObj pipe(m_device);
5165 pipe.AddShader(&vs);
5166 pipe.AddShader(&fs);
5167 pipe.AddColorAttachment();
5168 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5169
5170 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005172 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005173 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5174 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5175 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005176 Draw(1, 0, 0, 0);
5177 EndCommandBuffer();
5178 // Destroy sampler invalidates the cmd buffer, causing error on submit
5179 vkDestroySampler(m_device->device(), sampler, NULL);
5180 // Attempt to submit cmd buffer
5181 VkSubmitInfo submit_info = {};
5182 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5183 submit_info.commandBufferCount = 1;
5184 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5185 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5186 m_errorMonitor->VerifyFound();
5187 // Now re-update descriptor with valid sampler and delete image
5188 img_info.sampler = sampler2;
5189 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005191 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005192 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5193 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5194 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005195 Draw(1, 0, 0, 0);
5196 EndCommandBuffer();
5197 // Destroy image invalidates the cmd buffer, causing error on submit
5198 vkDestroyImage(m_device->device(), image, NULL);
5199 // Attempt to submit cmd buffer
5200 submit_info = {};
5201 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5202 submit_info.commandBufferCount = 1;
5203 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5204 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5205 m_errorMonitor->VerifyFound();
5206 // Now update descriptor to be valid, but then free descriptor
5207 img_info.imageView = view2;
5208 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005210 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005211 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5212 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5213 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005214 Draw(1, 0, 0, 0);
5215 EndCommandBuffer();
5216 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005218 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005219 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005220 // Attempt to submit cmd buffer
5221 submit_info = {};
5222 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5223 submit_info.commandBufferCount = 1;
5224 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5225 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5226 m_errorMonitor->VerifyFound();
5227 // Cleanup
5228 vkFreeMemory(m_device->device(), image_memory, NULL);
5229 vkDestroySampler(m_device->device(), sampler2, NULL);
5230 vkDestroyImage(m_device->device(), image2, NULL);
5231 vkDestroyImageView(m_device->device(), view, NULL);
5232 vkDestroyImageView(m_device->device(), view2, NULL);
5233 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5234 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5235 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5236}
5237
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005238TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5239 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5240 ASSERT_NO_FATAL_FAILURE(InitState());
5241 ASSERT_NO_FATAL_FAILURE(InitViewport());
5242 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5243
5244 VkDescriptorPoolSize ds_type_count = {};
5245 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5246 ds_type_count.descriptorCount = 1;
5247
5248 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5249 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5250 ds_pool_ci.pNext = NULL;
5251 ds_pool_ci.maxSets = 1;
5252 ds_pool_ci.poolSizeCount = 1;
5253 ds_pool_ci.pPoolSizes = &ds_type_count;
5254
5255 VkDescriptorPool ds_pool;
5256 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5257 ASSERT_VK_SUCCESS(err);
5258
5259 VkDescriptorSetLayoutBinding dsl_binding = {};
5260 dsl_binding.binding = 0;
5261 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5262 dsl_binding.descriptorCount = 1;
5263 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5264 dsl_binding.pImmutableSamplers = NULL;
5265
5266 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5267 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5268 ds_layout_ci.pNext = NULL;
5269 ds_layout_ci.bindingCount = 1;
5270 ds_layout_ci.pBindings = &dsl_binding;
5271 VkDescriptorSetLayout ds_layout;
5272 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5273 ASSERT_VK_SUCCESS(err);
5274
5275 VkDescriptorSet descriptor_set;
5276 VkDescriptorSetAllocateInfo alloc_info = {};
5277 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5278 alloc_info.descriptorSetCount = 1;
5279 alloc_info.descriptorPool = ds_pool;
5280 alloc_info.pSetLayouts = &ds_layout;
5281 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5282 ASSERT_VK_SUCCESS(err);
5283
5284 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5285 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5286 pipeline_layout_ci.pNext = NULL;
5287 pipeline_layout_ci.setLayoutCount = 1;
5288 pipeline_layout_ci.pSetLayouts = &ds_layout;
5289
5290 VkPipelineLayout pipeline_layout;
5291 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5292 ASSERT_VK_SUCCESS(err);
5293
5294 // Create image to update the descriptor with
5295 VkImageObj image(m_device);
5296 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5297 ASSERT_TRUE(image.initialized());
5298
5299 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5300 // Create Sampler
5301 VkSamplerCreateInfo sampler_ci = {};
5302 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5303 sampler_ci.pNext = NULL;
5304 sampler_ci.magFilter = VK_FILTER_NEAREST;
5305 sampler_ci.minFilter = VK_FILTER_NEAREST;
5306 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5307 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5308 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5309 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5310 sampler_ci.mipLodBias = 1.0;
5311 sampler_ci.anisotropyEnable = VK_FALSE;
5312 sampler_ci.maxAnisotropy = 1;
5313 sampler_ci.compareEnable = VK_FALSE;
5314 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5315 sampler_ci.minLod = 1.0;
5316 sampler_ci.maxLod = 1.0;
5317 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5318 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5319 VkSampler sampler;
5320 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5321 ASSERT_VK_SUCCESS(err);
5322 // Update descriptor with image and sampler
5323 VkDescriptorImageInfo img_info = {};
5324 img_info.sampler = sampler;
5325 img_info.imageView = view;
5326 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5327
5328 VkWriteDescriptorSet descriptor_write;
5329 memset(&descriptor_write, 0, sizeof(descriptor_write));
5330 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5331 descriptor_write.dstSet = descriptor_set;
5332 descriptor_write.dstBinding = 0;
5333 descriptor_write.descriptorCount = 1;
5334 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5335 descriptor_write.pImageInfo = &img_info;
5336
5337 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5338
5339 // Create PSO to be used for draw-time errors below
5340 char const *vsSource = "#version 450\n"
5341 "\n"
5342 "out gl_PerVertex { \n"
5343 " vec4 gl_Position;\n"
5344 "};\n"
5345 "void main(){\n"
5346 " gl_Position = vec4(1);\n"
5347 "}\n";
5348 char const *fsSource = "#version 450\n"
5349 "\n"
5350 "layout(set=0, binding=0) uniform sampler2D s;\n"
5351 "layout(location=0) out vec4 x;\n"
5352 "void main(){\n"
5353 " x = texture(s, vec2(1));\n"
5354 "}\n";
5355 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5356 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5357 VkPipelineObj pipe(m_device);
5358 pipe.AddShader(&vs);
5359 pipe.AddShader(&fs);
5360 pipe.AddColorAttachment();
5361 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5362
5363 BeginCommandBuffer();
5364 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5365 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5366 &descriptor_set, 0, NULL);
5367 Draw(1, 0, 0, 0);
5368 EndCommandBuffer();
5369 // Submit cmd buffer to put pool in-flight
5370 VkSubmitInfo submit_info = {};
5371 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5372 submit_info.commandBufferCount = 1;
5373 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5374 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5375 // Destroy pool while in-flight, causing error
5376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5377 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5378 m_errorMonitor->VerifyFound();
5379 vkQueueWaitIdle(m_device->m_queue);
5380 // Cleanup
5381 vkDestroySampler(m_device->device(), sampler, NULL);
5382 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5383 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5384 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5385}
5386
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005387TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5388 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5389 ASSERT_NO_FATAL_FAILURE(InitState());
5390 ASSERT_NO_FATAL_FAILURE(InitViewport());
5391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5392
5393 VkDescriptorPoolSize ds_type_count = {};
5394 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5395 ds_type_count.descriptorCount = 1;
5396
5397 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5398 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5399 ds_pool_ci.pNext = NULL;
5400 ds_pool_ci.maxSets = 1;
5401 ds_pool_ci.poolSizeCount = 1;
5402 ds_pool_ci.pPoolSizes = &ds_type_count;
5403
5404 VkDescriptorPool ds_pool;
5405 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5406 ASSERT_VK_SUCCESS(err);
5407
5408 VkDescriptorSetLayoutBinding dsl_binding = {};
5409 dsl_binding.binding = 0;
5410 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5411 dsl_binding.descriptorCount = 1;
5412 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5413 dsl_binding.pImmutableSamplers = NULL;
5414
5415 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5416 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5417 ds_layout_ci.pNext = NULL;
5418 ds_layout_ci.bindingCount = 1;
5419 ds_layout_ci.pBindings = &dsl_binding;
5420 VkDescriptorSetLayout ds_layout;
5421 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5422 ASSERT_VK_SUCCESS(err);
5423
5424 VkDescriptorSet descriptorSet;
5425 VkDescriptorSetAllocateInfo alloc_info = {};
5426 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5427 alloc_info.descriptorSetCount = 1;
5428 alloc_info.descriptorPool = ds_pool;
5429 alloc_info.pSetLayouts = &ds_layout;
5430 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5431 ASSERT_VK_SUCCESS(err);
5432
5433 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5434 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5435 pipeline_layout_ci.pNext = NULL;
5436 pipeline_layout_ci.setLayoutCount = 1;
5437 pipeline_layout_ci.pSetLayouts = &ds_layout;
5438
5439 VkPipelineLayout pipeline_layout;
5440 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5441 ASSERT_VK_SUCCESS(err);
5442
5443 // Create images to update the descriptor with
5444 VkImage image;
5445 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5446 const int32_t tex_width = 32;
5447 const int32_t tex_height = 32;
5448 VkImageCreateInfo image_create_info = {};
5449 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5450 image_create_info.pNext = NULL;
5451 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5452 image_create_info.format = tex_format;
5453 image_create_info.extent.width = tex_width;
5454 image_create_info.extent.height = tex_height;
5455 image_create_info.extent.depth = 1;
5456 image_create_info.mipLevels = 1;
5457 image_create_info.arrayLayers = 1;
5458 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5459 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5460 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5461 image_create_info.flags = 0;
5462 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5463 ASSERT_VK_SUCCESS(err);
5464 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5465 VkMemoryRequirements memory_reqs;
5466 VkDeviceMemory image_memory;
5467 bool pass;
5468 VkMemoryAllocateInfo memory_info = {};
5469 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5470 memory_info.pNext = NULL;
5471 memory_info.allocationSize = 0;
5472 memory_info.memoryTypeIndex = 0;
5473 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5474 // Allocate enough memory for image
5475 memory_info.allocationSize = memory_reqs.size;
5476 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5477 ASSERT_TRUE(pass);
5478 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5479 ASSERT_VK_SUCCESS(err);
5480 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5481 ASSERT_VK_SUCCESS(err);
5482
5483 VkImageViewCreateInfo image_view_create_info = {};
5484 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5485 image_view_create_info.image = image;
5486 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5487 image_view_create_info.format = tex_format;
5488 image_view_create_info.subresourceRange.layerCount = 1;
5489 image_view_create_info.subresourceRange.baseMipLevel = 0;
5490 image_view_create_info.subresourceRange.levelCount = 1;
5491 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5492
5493 VkImageView view;
5494 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5495 ASSERT_VK_SUCCESS(err);
5496 // Create Samplers
5497 VkSamplerCreateInfo sampler_ci = {};
5498 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5499 sampler_ci.pNext = NULL;
5500 sampler_ci.magFilter = VK_FILTER_NEAREST;
5501 sampler_ci.minFilter = VK_FILTER_NEAREST;
5502 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5503 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5504 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5505 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5506 sampler_ci.mipLodBias = 1.0;
5507 sampler_ci.anisotropyEnable = VK_FALSE;
5508 sampler_ci.maxAnisotropy = 1;
5509 sampler_ci.compareEnable = VK_FALSE;
5510 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5511 sampler_ci.minLod = 1.0;
5512 sampler_ci.maxLod = 1.0;
5513 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5514 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5515 VkSampler sampler;
5516 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5517 ASSERT_VK_SUCCESS(err);
5518 // Update descriptor with image and sampler
5519 VkDescriptorImageInfo img_info = {};
5520 img_info.sampler = sampler;
5521 img_info.imageView = view;
5522 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5523
5524 VkWriteDescriptorSet descriptor_write;
5525 memset(&descriptor_write, 0, sizeof(descriptor_write));
5526 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5527 descriptor_write.dstSet = descriptorSet;
5528 descriptor_write.dstBinding = 0;
5529 descriptor_write.descriptorCount = 1;
5530 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5531 descriptor_write.pImageInfo = &img_info;
5532 // Break memory binding and attempt update
5533 vkFreeMemory(m_device->device(), image_memory, nullptr);
5534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005535 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5537 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5538 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5539 m_errorMonitor->VerifyFound();
5540 // Cleanup
5541 vkDestroyImage(m_device->device(), image, NULL);
5542 vkDestroySampler(m_device->device(), sampler, NULL);
5543 vkDestroyImageView(m_device->device(), view, NULL);
5544 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5545 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5546 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5547}
5548
Karl Schultz6addd812016-02-02 17:17:23 -07005549TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005550 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5551 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005552 // Create a valid cmd buffer
5553 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005554 uint64_t fake_pipeline_handle = 0xbaad6001;
5555 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005556 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005557 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5558
5559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005560 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005561 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005562 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005563
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005564 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005565 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 -06005566 Draw(1, 0, 0, 0);
5567 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005568
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005569 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005570 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 +12005571 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005572 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5573 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005574}
5575
Karl Schultz6addd812016-02-02 17:17:23 -07005576TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005577 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005578 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005579
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005581
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005582 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005583 ASSERT_NO_FATAL_FAILURE(InitViewport());
5584 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005585 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005586 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5587 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005588
5589 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005590 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5591 ds_pool_ci.pNext = NULL;
5592 ds_pool_ci.maxSets = 1;
5593 ds_pool_ci.poolSizeCount = 1;
5594 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005595
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005596 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005597 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005598 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005599
Tony Barboureb254902015-07-15 12:50:33 -06005600 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005601 dsl_binding.binding = 0;
5602 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5603 dsl_binding.descriptorCount = 1;
5604 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5605 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005606
Tony Barboureb254902015-07-15 12:50:33 -06005607 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005608 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5609 ds_layout_ci.pNext = NULL;
5610 ds_layout_ci.bindingCount = 1;
5611 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005612 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005613 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005614 ASSERT_VK_SUCCESS(err);
5615
5616 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005617 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005618 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005619 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005620 alloc_info.descriptorPool = ds_pool;
5621 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005622 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005623 ASSERT_VK_SUCCESS(err);
5624
Tony Barboureb254902015-07-15 12:50:33 -06005625 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005626 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5627 pipeline_layout_ci.pNext = NULL;
5628 pipeline_layout_ci.setLayoutCount = 1;
5629 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005630
5631 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005632 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005633 ASSERT_VK_SUCCESS(err);
5634
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005635 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005636 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005637 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005638 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005639
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005640 VkPipelineObj pipe(m_device);
5641 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005642 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005643 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005644 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005645
5646 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005647 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5648 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5649 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005650
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005651 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005652
Chia-I Wuf7458c52015-10-26 21:10:41 +08005653 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5654 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5655 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005656}
5657
Karl Schultz6addd812016-02-02 17:17:23 -07005658TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005659 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005660 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005661
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5663 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005664
5665 ASSERT_NO_FATAL_FAILURE(InitState());
5666 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005667 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5668 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005669
5670 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005671 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5672 ds_pool_ci.pNext = NULL;
5673 ds_pool_ci.maxSets = 1;
5674 ds_pool_ci.poolSizeCount = 1;
5675 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005676
5677 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005678 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005679 ASSERT_VK_SUCCESS(err);
5680
5681 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005682 dsl_binding.binding = 0;
5683 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5684 dsl_binding.descriptorCount = 1;
5685 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5686 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005687
5688 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005689 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5690 ds_layout_ci.pNext = NULL;
5691 ds_layout_ci.bindingCount = 1;
5692 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005693 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005694 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005695 ASSERT_VK_SUCCESS(err);
5696
5697 VkDescriptorSet descriptorSet;
5698 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005699 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005700 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005701 alloc_info.descriptorPool = ds_pool;
5702 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005703 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005704 ASSERT_VK_SUCCESS(err);
5705
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005706 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005707 VkWriteDescriptorSet descriptor_write;
5708 memset(&descriptor_write, 0, sizeof(descriptor_write));
5709 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5710 descriptor_write.dstSet = descriptorSet;
5711 descriptor_write.dstBinding = 0;
5712 descriptor_write.descriptorCount = 1;
5713 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5714 descriptor_write.pTexelBufferView = &view;
5715
5716 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5717
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005718 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005719
5720 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5721 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5722}
5723
Mark Youngd339ba32016-05-30 13:28:35 -06005724TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005725 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 -06005726
5727 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005729 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005730
5731 ASSERT_NO_FATAL_FAILURE(InitState());
5732
5733 // Create a buffer with no bound memory and then attempt to create
5734 // a buffer view.
5735 VkBufferCreateInfo buff_ci = {};
5736 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005737 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005738 buff_ci.size = 256;
5739 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5740 VkBuffer buffer;
5741 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5742 ASSERT_VK_SUCCESS(err);
5743
5744 VkBufferViewCreateInfo buff_view_ci = {};
5745 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5746 buff_view_ci.buffer = buffer;
5747 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5748 buff_view_ci.range = VK_WHOLE_SIZE;
5749 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005750 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005751
5752 m_errorMonitor->VerifyFound();
5753 vkDestroyBuffer(m_device->device(), buffer, NULL);
5754 // If last error is success, it still created the view, so delete it.
5755 if (err == VK_SUCCESS) {
5756 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5757 }
5758}
5759
Karl Schultz6addd812016-02-02 17:17:23 -07005760TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5761 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5762 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005763 // 1. No dynamicOffset supplied
5764 // 2. Too many dynamicOffsets supplied
5765 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005766 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5768 "0 dynamicOffsets are left in "
5769 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005770
5771 ASSERT_NO_FATAL_FAILURE(InitState());
5772 ASSERT_NO_FATAL_FAILURE(InitViewport());
5773 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5774
5775 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005776 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5777 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005778
5779 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005780 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5781 ds_pool_ci.pNext = NULL;
5782 ds_pool_ci.maxSets = 1;
5783 ds_pool_ci.poolSizeCount = 1;
5784 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005785
5786 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005787 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005788 ASSERT_VK_SUCCESS(err);
5789
5790 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005791 dsl_binding.binding = 0;
5792 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5793 dsl_binding.descriptorCount = 1;
5794 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5795 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005796
5797 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005798 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5799 ds_layout_ci.pNext = NULL;
5800 ds_layout_ci.bindingCount = 1;
5801 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005802 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005803 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005804 ASSERT_VK_SUCCESS(err);
5805
5806 VkDescriptorSet descriptorSet;
5807 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005808 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005809 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005810 alloc_info.descriptorPool = ds_pool;
5811 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005812 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005813 ASSERT_VK_SUCCESS(err);
5814
5815 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005816 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5817 pipeline_layout_ci.pNext = NULL;
5818 pipeline_layout_ci.setLayoutCount = 1;
5819 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005820
5821 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005822 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005823 ASSERT_VK_SUCCESS(err);
5824
5825 // Create a buffer to update the descriptor with
5826 uint32_t qfi = 0;
5827 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005828 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5829 buffCI.size = 1024;
5830 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5831 buffCI.queueFamilyIndexCount = 1;
5832 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005833
5834 VkBuffer dyub;
5835 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5836 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005837 // Allocate memory and bind to buffer so we can make it to the appropriate
5838 // error
5839 VkMemoryAllocateInfo mem_alloc = {};
5840 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5841 mem_alloc.pNext = NULL;
5842 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005843 mem_alloc.memoryTypeIndex = 0;
5844
5845 VkMemoryRequirements memReqs;
5846 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005847 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005848 if (!pass) {
5849 vkDestroyBuffer(m_device->device(), dyub, NULL);
5850 return;
5851 }
5852
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005853 VkDeviceMemory mem;
5854 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5855 ASSERT_VK_SUCCESS(err);
5856 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5857 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005858 // Correctly update descriptor to avoid "NOT_UPDATED" error
5859 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005860 buffInfo.buffer = dyub;
5861 buffInfo.offset = 0;
5862 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005863
5864 VkWriteDescriptorSet descriptor_write;
5865 memset(&descriptor_write, 0, sizeof(descriptor_write));
5866 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5867 descriptor_write.dstSet = descriptorSet;
5868 descriptor_write.dstBinding = 0;
5869 descriptor_write.descriptorCount = 1;
5870 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5871 descriptor_write.pBufferInfo = &buffInfo;
5872
5873 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5874
5875 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005876 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5877 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005878 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005879 uint32_t pDynOff[2] = {512, 756};
5880 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5882 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5883 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5884 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005885 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005886 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5888 "offset 0 and range 1024 that "
5889 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005890 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005891 char const *vsSource = "#version 450\n"
5892 "\n"
5893 "out gl_PerVertex { \n"
5894 " vec4 gl_Position;\n"
5895 "};\n"
5896 "void main(){\n"
5897 " gl_Position = vec4(1);\n"
5898 "}\n";
5899 char const *fsSource = "#version 450\n"
5900 "\n"
5901 "layout(location=0) out vec4 x;\n"
5902 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5903 "void main(){\n"
5904 " x = vec4(bar.y);\n"
5905 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005906 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5907 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5908 VkPipelineObj pipe(m_device);
5909 pipe.AddShader(&vs);
5910 pipe.AddShader(&fs);
5911 pipe.AddColorAttachment();
5912 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5913
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005914 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005915 // This update should succeed, but offset size of 512 will overstep buffer
5916 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005917 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5918 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005919 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005920 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005921
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005922 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005923 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005924
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005925 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005926 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005927 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5928}
5929
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005930TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
5931 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
5932 "that doesn't have memory bound");
5933 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005935 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5937 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005938
5939 ASSERT_NO_FATAL_FAILURE(InitState());
5940 ASSERT_NO_FATAL_FAILURE(InitViewport());
5941 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5942
5943 VkDescriptorPoolSize ds_type_count = {};
5944 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5945 ds_type_count.descriptorCount = 1;
5946
5947 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5948 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5949 ds_pool_ci.pNext = NULL;
5950 ds_pool_ci.maxSets = 1;
5951 ds_pool_ci.poolSizeCount = 1;
5952 ds_pool_ci.pPoolSizes = &ds_type_count;
5953
5954 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005955 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005956 ASSERT_VK_SUCCESS(err);
5957
5958 VkDescriptorSetLayoutBinding dsl_binding = {};
5959 dsl_binding.binding = 0;
5960 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5961 dsl_binding.descriptorCount = 1;
5962 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5963 dsl_binding.pImmutableSamplers = NULL;
5964
5965 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5966 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5967 ds_layout_ci.pNext = NULL;
5968 ds_layout_ci.bindingCount = 1;
5969 ds_layout_ci.pBindings = &dsl_binding;
5970 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005971 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005972 ASSERT_VK_SUCCESS(err);
5973
5974 VkDescriptorSet descriptorSet;
5975 VkDescriptorSetAllocateInfo alloc_info = {};
5976 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5977 alloc_info.descriptorSetCount = 1;
5978 alloc_info.descriptorPool = ds_pool;
5979 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005980 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005981 ASSERT_VK_SUCCESS(err);
5982
5983 // Create a buffer to update the descriptor with
5984 uint32_t qfi = 0;
5985 VkBufferCreateInfo buffCI = {};
5986 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5987 buffCI.size = 1024;
5988 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5989 buffCI.queueFamilyIndexCount = 1;
5990 buffCI.pQueueFamilyIndices = &qfi;
5991
5992 VkBuffer dyub;
5993 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5994 ASSERT_VK_SUCCESS(err);
5995
5996 // Attempt to update descriptor without binding memory to it
5997 VkDescriptorBufferInfo buffInfo = {};
5998 buffInfo.buffer = dyub;
5999 buffInfo.offset = 0;
6000 buffInfo.range = 1024;
6001
6002 VkWriteDescriptorSet descriptor_write;
6003 memset(&descriptor_write, 0, sizeof(descriptor_write));
6004 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6005 descriptor_write.dstSet = descriptorSet;
6006 descriptor_write.dstBinding = 0;
6007 descriptor_write.descriptorCount = 1;
6008 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6009 descriptor_write.pBufferInfo = &buffInfo;
6010
6011 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6012 m_errorMonitor->VerifyFound();
6013
6014 vkDestroyBuffer(m_device->device(), dyub, NULL);
6015 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6016 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6017}
6018
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006019TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006020 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006021 ASSERT_NO_FATAL_FAILURE(InitState());
6022 ASSERT_NO_FATAL_FAILURE(InitViewport());
6023 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6024
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006025 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006026 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006027 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6028 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6029 pipeline_layout_ci.pushConstantRangeCount = 1;
6030 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6031
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006032 //
6033 // Check for invalid push constant ranges in pipeline layouts.
6034 //
6035 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006036 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006037 char const *msg;
6038 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006039
Karl Schultzc81037d2016-05-12 08:11:23 -06006040 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6041 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6042 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6043 "vkCreatePipelineLayout() call has push constants index 0 with "
6044 "size 0."},
6045 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6046 "vkCreatePipelineLayout() call has push constants index 0 with "
6047 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006048 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006049 "vkCreatePipelineLayout() call has push constants index 0 with "
6050 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006051 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006052 "vkCreatePipelineLayout() call has push constants index 0 with "
6053 "size 0."},
6054 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6055 "vkCreatePipelineLayout() call has push constants index 0 with "
6056 "offset 1. Offset must"},
6057 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6058 "vkCreatePipelineLayout() call has push constants index 0 "
6059 "with offset "},
6060 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6061 "vkCreatePipelineLayout() call has push constants "
6062 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006063 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006064 "vkCreatePipelineLayout() call has push constants index 0 "
6065 "with offset "},
6066 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6067 "vkCreatePipelineLayout() call has push "
6068 "constants index 0 with offset "},
6069 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6070 "vkCreatePipelineLayout() call has push "
6071 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006072 }};
6073
6074 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006075 for (const auto &iter : range_tests) {
6076 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6078 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006079 m_errorMonitor->VerifyFound();
6080 if (VK_SUCCESS == err) {
6081 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6082 }
6083 }
6084
6085 // Check for invalid stage flag
6086 pc_range.offset = 0;
6087 pc_range.size = 16;
6088 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006089 m_errorMonitor->SetDesiredFailureMsg(
6090 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6091 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006092 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006093 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006094 if (VK_SUCCESS == err) {
6095 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6096 }
6097
6098 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006099 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006100 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006101 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006102 char const *msg;
6103 };
6104
Karl Schultzc81037d2016-05-12 08:11:23 -06006105 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006106 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6107 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6108 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6109 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6110 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006111 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006112 {
6113 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6114 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6115 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6116 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6117 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006118 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006119 },
6120 {
6121 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6122 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6123 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6124 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6125 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006126 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006127 },
6128 {
6129 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6130 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6131 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6132 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6133 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006134 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006135 },
6136 {
6137 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6138 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6139 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6140 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6141 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006142 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006143 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006144
Karl Schultzc81037d2016-05-12 08:11:23 -06006145 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006146 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006147 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6149 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006150 m_errorMonitor->VerifyFound();
6151 if (VK_SUCCESS == err) {
6152 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6153 }
6154 }
6155
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006156 //
6157 // CmdPushConstants tests
6158 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006159 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006160
6161 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006162 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6163 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006164 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6165 "vkCmdPushConstants() call has push constants with size 1. Size "
6166 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006167 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006168 "vkCmdPushConstants() call has push constants with size 1. Size "
6169 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006170 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006171 "vkCmdPushConstants() call has push constants with offset 1. "
6172 "Offset must be a multiple of 4."},
6173 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6174 "vkCmdPushConstants() call has push constants with offset 1. "
6175 "Offset must be a multiple of 4."},
6176 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6177 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6178 "0x1 not within flag-matching ranges in pipeline layout"},
6179 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6180 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6181 "0x1 not within flag-matching ranges in pipeline layout"},
6182 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6183 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6184 "0x1 not within flag-matching ranges in pipeline layout"},
6185 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6186 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6187 "0x1 not within flag-matching ranges in pipeline layout"},
6188 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6189 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6190 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006191 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006192 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6193 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006194 }};
6195
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006196 BeginCommandBuffer();
6197
6198 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006199 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006200 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006201 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006202 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006203 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006204 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006205 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006206 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6208 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006209 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006210 m_errorMonitor->VerifyFound();
6211 }
6212
6213 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006215 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006216 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006217 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006218
Karl Schultzc81037d2016-05-12 08:11:23 -06006219 // overlapping range tests with cmd
6220 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6221 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6222 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6223 "0x1 not within flag-matching ranges in pipeline layout"},
6224 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6225 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6226 "0x1 not within flag-matching ranges in pipeline layout"},
6227 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6228 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6229 "0x1 not within flag-matching ranges in pipeline layout"},
6230 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006231 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006232 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006233 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6234 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006235 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006236 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006237 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006238 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006239 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006240 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6242 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006243 iter.range.size, dummy_values);
6244 m_errorMonitor->VerifyFound();
6245 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006246 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6247
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006248 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006249}
6250
Karl Schultz6addd812016-02-02 17:17:23 -07006251TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006252 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006253 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006254
6255 ASSERT_NO_FATAL_FAILURE(InitState());
6256 ASSERT_NO_FATAL_FAILURE(InitViewport());
6257 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6258
Mike Stroyanb8a61002016-06-20 16:00:28 -06006259 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6260 VkImageTiling tiling;
6261 VkFormatProperties format_properties;
6262 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006263 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006264 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006265 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006266 tiling = VK_IMAGE_TILING_OPTIMAL;
6267 } else {
6268 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6269 "skipped.\n");
6270 return;
6271 }
6272
Tobin Ehlis559c6382015-11-05 09:52:49 -07006273 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6274 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006275 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6276 ds_type_count[0].descriptorCount = 10;
6277 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6278 ds_type_count[1].descriptorCount = 2;
6279 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6280 ds_type_count[2].descriptorCount = 2;
6281 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6282 ds_type_count[3].descriptorCount = 5;
6283 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6284 // type
6285 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6286 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6287 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006288
6289 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006290 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6291 ds_pool_ci.pNext = NULL;
6292 ds_pool_ci.maxSets = 5;
6293 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6294 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006295
6296 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006297 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006298 ASSERT_VK_SUCCESS(err);
6299
6300 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6301 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006302 dsl_binding[0].binding = 0;
6303 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6304 dsl_binding[0].descriptorCount = 5;
6305 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6306 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006307
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006308 // Create layout identical to set0 layout but w/ different stageFlags
6309 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006310 dsl_fs_stage_only.binding = 0;
6311 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6312 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006313 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6314 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006315 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006316 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006317 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6318 ds_layout_ci.pNext = NULL;
6319 ds_layout_ci.bindingCount = 1;
6320 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006321 static const uint32_t NUM_LAYOUTS = 4;
6322 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006323 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006324 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6325 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006326 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006327 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006328 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006329 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006330 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006331 dsl_binding[0].binding = 0;
6332 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006333 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006334 dsl_binding[1].binding = 1;
6335 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6336 dsl_binding[1].descriptorCount = 2;
6337 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6338 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006339 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006340 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006341 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006342 ASSERT_VK_SUCCESS(err);
6343 dsl_binding[0].binding = 0;
6344 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006345 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006346 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006347 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006348 ASSERT_VK_SUCCESS(err);
6349 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006350 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006351 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006352 ASSERT_VK_SUCCESS(err);
6353
6354 static const uint32_t NUM_SETS = 4;
6355 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6356 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006357 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006358 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006359 alloc_info.descriptorPool = ds_pool;
6360 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006361 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006362 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006363 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006364 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006365 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006366 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006367 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006368
6369 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006370 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6371 pipeline_layout_ci.pNext = NULL;
6372 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6373 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006374
6375 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006376 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006377 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006378 // Create pipelineLayout with only one setLayout
6379 pipeline_layout_ci.setLayoutCount = 1;
6380 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006381 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006382 ASSERT_VK_SUCCESS(err);
6383 // Create pipelineLayout with 2 descriptor setLayout at index 0
6384 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6385 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006386 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006387 ASSERT_VK_SUCCESS(err);
6388 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6389 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6390 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006391 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006392 ASSERT_VK_SUCCESS(err);
6393 // Create pipelineLayout with UB type, but stageFlags for FS only
6394 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6395 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006396 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006397 ASSERT_VK_SUCCESS(err);
6398 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6399 VkDescriptorSetLayout pl_bad_s0[2] = {};
6400 pl_bad_s0[0] = ds_layout_fs_only;
6401 pl_bad_s0[1] = ds_layout[1];
6402 pipeline_layout_ci.setLayoutCount = 2;
6403 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6404 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006405 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006406 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006407
6408 // Create a buffer to update the descriptor with
6409 uint32_t qfi = 0;
6410 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006411 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6412 buffCI.size = 1024;
6413 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6414 buffCI.queueFamilyIndexCount = 1;
6415 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006416
6417 VkBuffer dyub;
6418 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6419 ASSERT_VK_SUCCESS(err);
6420 // Correctly update descriptor to avoid "NOT_UPDATED" error
6421 static const uint32_t NUM_BUFFS = 5;
6422 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006423 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006424 buffInfo[i].buffer = dyub;
6425 buffInfo[i].offset = 0;
6426 buffInfo[i].range = 1024;
6427 }
Karl Schultz6addd812016-02-02 17:17:23 -07006428 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006429 const int32_t tex_width = 32;
6430 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006431 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006432 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6433 image_create_info.pNext = NULL;
6434 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6435 image_create_info.format = tex_format;
6436 image_create_info.extent.width = tex_width;
6437 image_create_info.extent.height = tex_height;
6438 image_create_info.extent.depth = 1;
6439 image_create_info.mipLevels = 1;
6440 image_create_info.arrayLayers = 1;
6441 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006442 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006443 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006444 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006445 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6446 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006447
Karl Schultz6addd812016-02-02 17:17:23 -07006448 VkMemoryRequirements memReqs;
6449 VkDeviceMemory imageMem;
6450 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006451 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006452 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6453 memAlloc.pNext = NULL;
6454 memAlloc.allocationSize = 0;
6455 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006456 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6457 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006458 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006459 ASSERT_TRUE(pass);
6460 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6461 ASSERT_VK_SUCCESS(err);
6462 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6463 ASSERT_VK_SUCCESS(err);
6464
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006465 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006466 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6467 image_view_create_info.image = image;
6468 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6469 image_view_create_info.format = tex_format;
6470 image_view_create_info.subresourceRange.layerCount = 1;
6471 image_view_create_info.subresourceRange.baseMipLevel = 0;
6472 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006473 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006474
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006475 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006476 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006477 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006478 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006479 imageInfo[0].imageView = view;
6480 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6481 imageInfo[1].imageView = view;
6482 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006483 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006484 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006485 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006486 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006487
6488 static const uint32_t NUM_SET_UPDATES = 3;
6489 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6490 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6491 descriptor_write[0].dstSet = descriptorSet[0];
6492 descriptor_write[0].dstBinding = 0;
6493 descriptor_write[0].descriptorCount = 5;
6494 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6495 descriptor_write[0].pBufferInfo = buffInfo;
6496 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6497 descriptor_write[1].dstSet = descriptorSet[1];
6498 descriptor_write[1].dstBinding = 0;
6499 descriptor_write[1].descriptorCount = 2;
6500 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6501 descriptor_write[1].pImageInfo = imageInfo;
6502 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6503 descriptor_write[2].dstSet = descriptorSet[1];
6504 descriptor_write[2].dstBinding = 1;
6505 descriptor_write[2].descriptorCount = 2;
6506 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006507 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006508
6509 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006510
Tobin Ehlis88452832015-12-03 09:40:56 -07006511 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006512 char const *vsSource = "#version 450\n"
6513 "\n"
6514 "out gl_PerVertex {\n"
6515 " vec4 gl_Position;\n"
6516 "};\n"
6517 "void main(){\n"
6518 " gl_Position = vec4(1);\n"
6519 "}\n";
6520 char const *fsSource = "#version 450\n"
6521 "\n"
6522 "layout(location=0) out vec4 x;\n"
6523 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6524 "void main(){\n"
6525 " x = vec4(bar.y);\n"
6526 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006527 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6528 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006529 VkPipelineObj pipe(m_device);
6530 pipe.AddShader(&vs);
6531 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006532 pipe.AddColorAttachment();
6533 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006534
6535 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006536
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006537 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006538 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6539 // of PSO
6540 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6541 // cmd_pipeline.c
6542 // due to the fact that cmd_alloc_dset_data() has not been called in
6543 // cmd_bind_graphics_pipeline()
6544 // TODO : Want to cause various binding incompatibility issues here to test
6545 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006546 // First cause various verify_layout_compatibility() fails
6547 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006548 // verify_set_layout_compatibility fail cases:
6549 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6551 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6552 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006553 m_errorMonitor->VerifyFound();
6554
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006555 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6557 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6558 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006559 m_errorMonitor->VerifyFound();
6560
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006561 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006562 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6563 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6565 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6566 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006567 m_errorMonitor->VerifyFound();
6568
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006569 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6570 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6572 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6573 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006574 m_errorMonitor->VerifyFound();
6575
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006576 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6577 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6579 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6580 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6581 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006582 m_errorMonitor->VerifyFound();
6583
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006584 // Cause INFO messages due to disturbing previously bound Sets
6585 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006586 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6587 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006588 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6590 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6591 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006592 m_errorMonitor->VerifyFound();
6593
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006594 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6595 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006596 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6598 "any subsequent sets were disturbed ");
6599 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6600 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006601 m_errorMonitor->VerifyFound();
6602
Tobin Ehlis10fad692016-07-07 12:00:36 -06006603 // Now that we're done actively using the pipelineLayout that gfx pipeline
6604 // was created with, we should be able to delete it. Do that now to verify
6605 // that validation obeys pipelineLayout lifetime
6606 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6607
Tobin Ehlis88452832015-12-03 09:40:56 -07006608 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006609 // 1. Error due to not binding required set (we actually use same code as
6610 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006611 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6612 &descriptorSet[0], 0, NULL);
6613 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6614 &descriptorSet[1], 0, NULL);
6615 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 -07006616 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006617 m_errorMonitor->VerifyFound();
6618
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006619 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006620 // 2. Error due to bound set not being compatible with PSO's
6621 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006622 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6623 &descriptorSet[0], 0, NULL);
6624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006625 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006626 m_errorMonitor->VerifyFound();
6627
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006628 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006629 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006630 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6631 }
6632 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006633 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006634 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6635 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006636 vkFreeMemory(m_device->device(), imageMem, NULL);
6637 vkDestroyImage(m_device->device(), image, NULL);
6638 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006639}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006640
Karl Schultz6addd812016-02-02 17:17:23 -07006641TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006642
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6644 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006645
6646 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006647 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006648 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006649 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006650
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006651 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006652}
6653
Karl Schultz6addd812016-02-02 17:17:23 -07006654TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6655 VkResult err;
6656 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006657
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006659
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006660 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006661
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006662 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006663 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006664 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006665 cmd.commandPool = m_commandPool;
6666 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006667 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006668
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006669 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006670 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006671
6672 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006673 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006674 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006675 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006676 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006677 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 -07006678 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006679
6680 // The error should be caught by validation of the BeginCommandBuffer call
6681 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6682
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006683 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006684 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006685}
6686
Karl Schultz6addd812016-02-02 17:17:23 -07006687TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006688 // Cause error due to Begin while recording CB
6689 // Then cause 2 errors for attempting to reset CB w/o having
6690 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6691 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006693
6694 ASSERT_NO_FATAL_FAILURE(InitState());
6695
6696 // Calls AllocateCommandBuffers
6697 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6698
Karl Schultz6addd812016-02-02 17:17:23 -07006699 // Force the failure by setting the Renderpass and Framebuffer fields with
6700 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006701 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006702 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006703 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6704 cmd_buf_info.pNext = NULL;
6705 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006706 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006707
6708 // Begin CB to transition to recording state
6709 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6710 // Can't re-begin. This should trigger error
6711 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006712 m_errorMonitor->VerifyFound();
6713
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006715 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6716 // Reset attempt will trigger error due to incorrect CommandPool state
6717 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006718 m_errorMonitor->VerifyFound();
6719
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006721 // Transition CB to RECORDED state
6722 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6723 // Now attempting to Begin will implicitly reset, which triggers error
6724 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006725 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006726}
6727
Karl Schultz6addd812016-02-02 17:17:23 -07006728TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006729 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006730 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006731
Mike Weiblencce7ec72016-10-17 19:33:05 -06006732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006733
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006734 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006735 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006736
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006737 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006738 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6739 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006740
6741 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006742 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6743 ds_pool_ci.pNext = NULL;
6744 ds_pool_ci.maxSets = 1;
6745 ds_pool_ci.poolSizeCount = 1;
6746 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006747
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006748 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006749 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006750 ASSERT_VK_SUCCESS(err);
6751
Tony Barboureb254902015-07-15 12:50:33 -06006752 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006753 dsl_binding.binding = 0;
6754 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6755 dsl_binding.descriptorCount = 1;
6756 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6757 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006758
Tony Barboureb254902015-07-15 12:50:33 -06006759 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006760 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6761 ds_layout_ci.pNext = NULL;
6762 ds_layout_ci.bindingCount = 1;
6763 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006764
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006765 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006766 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006767 ASSERT_VK_SUCCESS(err);
6768
6769 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006770 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006771 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006772 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006773 alloc_info.descriptorPool = ds_pool;
6774 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006775 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006776 ASSERT_VK_SUCCESS(err);
6777
Tony Barboureb254902015-07-15 12:50:33 -06006778 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006779 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6780 pipeline_layout_ci.setLayoutCount = 1;
6781 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006782
6783 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006784 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006785 ASSERT_VK_SUCCESS(err);
6786
Tobin Ehlise68360f2015-10-01 11:15:13 -06006787 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006788 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006789
6790 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006791 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6792 vp_state_ci.scissorCount = 1;
6793 vp_state_ci.pScissors = &sc;
6794 vp_state_ci.viewportCount = 1;
6795 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006796
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006797 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6798 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6799 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6800 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6801 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6802 rs_state_ci.depthClampEnable = VK_FALSE;
6803 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6804 rs_state_ci.depthBiasEnable = VK_FALSE;
6805
Tony Barboureb254902015-07-15 12:50:33 -06006806 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006807 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6808 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006809 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006810 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6811 gp_ci.layout = pipeline_layout;
6812 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006813
6814 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006815 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6816 pc_ci.initialDataSize = 0;
6817 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006818
6819 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006820 VkPipelineCache pipelineCache;
6821
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006822 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006823 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006824 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006825
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006826 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006827
Chia-I Wuf7458c52015-10-26 21:10:41 +08006828 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6829 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6830 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6831 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006832}
Tobin Ehlis912df022015-09-17 08:46:18 -06006833/*// TODO : This test should be good, but needs Tess support in compiler to run
6834TEST_F(VkLayerTest, InvalidPatchControlPoints)
6835{
6836 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006837 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006838
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006840 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6841primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006842
Tobin Ehlis912df022015-09-17 08:46:18 -06006843 ASSERT_NO_FATAL_FAILURE(InitState());
6844 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006845
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006846 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006847 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006848 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006849
6850 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6851 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6852 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006853 ds_pool_ci.poolSizeCount = 1;
6854 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006855
6856 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006857 err = vkCreateDescriptorPool(m_device->device(),
6858VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006859 ASSERT_VK_SUCCESS(err);
6860
6861 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006862 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006863 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006864 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006865 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6866 dsl_binding.pImmutableSamplers = NULL;
6867
6868 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006869 ds_layout_ci.sType =
6870VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006871 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006872 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006873 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006874
6875 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006876 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6877&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006878 ASSERT_VK_SUCCESS(err);
6879
6880 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006881 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6882VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006883 ASSERT_VK_SUCCESS(err);
6884
6885 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006886 pipeline_layout_ci.sType =
6887VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006888 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006889 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006890 pipeline_layout_ci.pSetLayouts = &ds_layout;
6891
6892 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006893 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6894&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006895 ASSERT_VK_SUCCESS(err);
6896
6897 VkPipelineShaderStageCreateInfo shaderStages[3];
6898 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6899
Karl Schultz6addd812016-02-02 17:17:23 -07006900 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6901this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006902 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006903 VkShaderObj
6904tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6905this);
6906 VkShaderObj
6907te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6908this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006909
Karl Schultz6addd812016-02-02 17:17:23 -07006910 shaderStages[0].sType =
6911VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006912 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006913 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006914 shaderStages[1].sType =
6915VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006916 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006917 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006918 shaderStages[2].sType =
6919VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006920 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006921 shaderStages[2].shader = te.handle();
6922
6923 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006924 iaCI.sType =
6925VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006926 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006927
6928 VkPipelineTessellationStateCreateInfo tsCI = {};
6929 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6930 tsCI.patchControlPoints = 0; // This will cause an error
6931
6932 VkGraphicsPipelineCreateInfo gp_ci = {};
6933 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6934 gp_ci.pNext = NULL;
6935 gp_ci.stageCount = 3;
6936 gp_ci.pStages = shaderStages;
6937 gp_ci.pVertexInputState = NULL;
6938 gp_ci.pInputAssemblyState = &iaCI;
6939 gp_ci.pTessellationState = &tsCI;
6940 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006941 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006942 gp_ci.pMultisampleState = NULL;
6943 gp_ci.pDepthStencilState = NULL;
6944 gp_ci.pColorBlendState = NULL;
6945 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6946 gp_ci.layout = pipeline_layout;
6947 gp_ci.renderPass = renderPass();
6948
6949 VkPipelineCacheCreateInfo pc_ci = {};
6950 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6951 pc_ci.pNext = NULL;
6952 pc_ci.initialSize = 0;
6953 pc_ci.initialData = 0;
6954 pc_ci.maxSize = 0;
6955
6956 VkPipeline pipeline;
6957 VkPipelineCache pipelineCache;
6958
Karl Schultz6addd812016-02-02 17:17:23 -07006959 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6960&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006961 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006962 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6963&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006964
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006965 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006966
Chia-I Wuf7458c52015-10-26 21:10:41 +08006967 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6968 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6969 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6970 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006971}
6972*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006973// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006974TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006975 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006976
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6978 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006979
Tobin Ehlise68360f2015-10-01 11:15:13 -06006980 ASSERT_NO_FATAL_FAILURE(InitState());
6981 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006982
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006983 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006984 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6985 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006986
6987 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006988 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6989 ds_pool_ci.maxSets = 1;
6990 ds_pool_ci.poolSizeCount = 1;
6991 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006992
6993 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006994 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006995 ASSERT_VK_SUCCESS(err);
6996
6997 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006998 dsl_binding.binding = 0;
6999 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7000 dsl_binding.descriptorCount = 1;
7001 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007002
7003 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007004 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7005 ds_layout_ci.bindingCount = 1;
7006 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007007
7008 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007009 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007010 ASSERT_VK_SUCCESS(err);
7011
7012 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007013 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007014 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007015 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007016 alloc_info.descriptorPool = ds_pool;
7017 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007018 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007019 ASSERT_VK_SUCCESS(err);
7020
7021 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007022 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7023 pipeline_layout_ci.setLayoutCount = 1;
7024 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007025
7026 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007027 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007028 ASSERT_VK_SUCCESS(err);
7029
7030 VkViewport vp = {}; // Just need dummy vp to point to
7031
7032 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007033 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7034 vp_state_ci.scissorCount = 0;
7035 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7036 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007037
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007038 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7039 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7040 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7041 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7042 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7043 rs_state_ci.depthClampEnable = VK_FALSE;
7044 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7045 rs_state_ci.depthBiasEnable = VK_FALSE;
7046
Cody Northropeb3a6c12015-10-05 14:44:45 -06007047 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007048 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007050 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7051 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7052 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007053 shaderStages[0] = vs.GetStageCreateInfo();
7054 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007055
7056 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007057 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7058 gp_ci.stageCount = 2;
7059 gp_ci.pStages = shaderStages;
7060 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007061 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007062 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7063 gp_ci.layout = pipeline_layout;
7064 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007065
7066 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007067 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007068
7069 VkPipeline pipeline;
7070 VkPipelineCache pipelineCache;
7071
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007072 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007073 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007074 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007075
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007076 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007077
Chia-I Wuf7458c52015-10-26 21:10:41 +08007078 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7079 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7080 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7081 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007082}
Karl Schultz6addd812016-02-02 17:17:23 -07007083// Don't set viewport state in PSO. This is an error b/c we always need this
7084// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007085// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007086TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007087 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007088 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007089
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007091
Tobin Ehlise68360f2015-10-01 11:15:13 -06007092 ASSERT_NO_FATAL_FAILURE(InitState());
7093 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007094
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007095 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007096 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7097 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007098
7099 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007100 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7101 ds_pool_ci.maxSets = 1;
7102 ds_pool_ci.poolSizeCount = 1;
7103 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007104
7105 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007106 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007107 ASSERT_VK_SUCCESS(err);
7108
7109 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007110 dsl_binding.binding = 0;
7111 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7112 dsl_binding.descriptorCount = 1;
7113 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007114
7115 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007116 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7117 ds_layout_ci.bindingCount = 1;
7118 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007119
7120 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007121 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007122 ASSERT_VK_SUCCESS(err);
7123
7124 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007125 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007126 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007127 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007128 alloc_info.descriptorPool = ds_pool;
7129 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007130 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007131 ASSERT_VK_SUCCESS(err);
7132
7133 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007134 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7135 pipeline_layout_ci.setLayoutCount = 1;
7136 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007137
7138 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007139 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007140 ASSERT_VK_SUCCESS(err);
7141
7142 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7143 // Set scissor as dynamic to avoid second error
7144 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007145 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7146 dyn_state_ci.dynamicStateCount = 1;
7147 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007148
Cody Northropeb3a6c12015-10-05 14:44:45 -06007149 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007150 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007151
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007152 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7153 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7154 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007155 shaderStages[0] = vs.GetStageCreateInfo();
7156 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007157
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007158 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7159 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7160 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7161 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7162 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7163 rs_state_ci.depthClampEnable = VK_FALSE;
7164 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7165 rs_state_ci.depthBiasEnable = VK_FALSE;
7166
Tobin Ehlise68360f2015-10-01 11:15:13 -06007167 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007168 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7169 gp_ci.stageCount = 2;
7170 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007171 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007172 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7173 // should cause validation error
7174 gp_ci.pDynamicState = &dyn_state_ci;
7175 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7176 gp_ci.layout = pipeline_layout;
7177 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007178
7179 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007180 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007181
7182 VkPipeline pipeline;
7183 VkPipelineCache pipelineCache;
7184
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007185 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007186 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007187 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007188
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007189 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007190
Chia-I Wuf7458c52015-10-26 21:10:41 +08007191 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7192 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7193 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7194 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007195}
7196// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007197// Then run second test where dynamic scissor count doesn't match PSO scissor
7198// count
7199TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7200 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007201
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7203 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007204
Tobin Ehlise68360f2015-10-01 11:15:13 -06007205 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007206
7207 if (!m_device->phy().features().multiViewport) {
7208 printf("Device does not support multiple viewports/scissors; skipped.\n");
7209 return;
7210 }
7211
Tobin Ehlise68360f2015-10-01 11:15:13 -06007212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007213
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007214 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007215 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7216 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007217
7218 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007219 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7220 ds_pool_ci.maxSets = 1;
7221 ds_pool_ci.poolSizeCount = 1;
7222 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007223
7224 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007225 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007226 ASSERT_VK_SUCCESS(err);
7227
7228 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007229 dsl_binding.binding = 0;
7230 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7231 dsl_binding.descriptorCount = 1;
7232 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007233
7234 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007235 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7236 ds_layout_ci.bindingCount = 1;
7237 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007238
7239 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007240 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007241 ASSERT_VK_SUCCESS(err);
7242
7243 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007244 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007245 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007246 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007247 alloc_info.descriptorPool = ds_pool;
7248 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007249 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007250 ASSERT_VK_SUCCESS(err);
7251
7252 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007253 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7254 pipeline_layout_ci.setLayoutCount = 1;
7255 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007256
7257 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007258 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007259 ASSERT_VK_SUCCESS(err);
7260
7261 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007262 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7263 vp_state_ci.viewportCount = 1;
7264 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7265 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007266 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007267
7268 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7269 // Set scissor as dynamic to avoid that error
7270 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007271 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7272 dyn_state_ci.dynamicStateCount = 1;
7273 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007274
Cody Northropeb3a6c12015-10-05 14:44:45 -06007275 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007276 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007277
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007278 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7279 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7280 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007281 shaderStages[0] = vs.GetStageCreateInfo();
7282 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007283
Cody Northropf6622dc2015-10-06 10:33:21 -06007284 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7285 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7286 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007287 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007288 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007289 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007290 vi_ci.pVertexAttributeDescriptions = nullptr;
7291
7292 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7293 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7294 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7295
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007296 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007297 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007298 rs_ci.pNext = nullptr;
7299
Mark Youngc89c6312016-03-31 16:03:20 -06007300 VkPipelineColorBlendAttachmentState att = {};
7301 att.blendEnable = VK_FALSE;
7302 att.colorWriteMask = 0xf;
7303
Cody Northropf6622dc2015-10-06 10:33:21 -06007304 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7305 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7306 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007307 cb_ci.attachmentCount = 1;
7308 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007309
Tobin Ehlise68360f2015-10-01 11:15:13 -06007310 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007311 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7312 gp_ci.stageCount = 2;
7313 gp_ci.pStages = shaderStages;
7314 gp_ci.pVertexInputState = &vi_ci;
7315 gp_ci.pInputAssemblyState = &ia_ci;
7316 gp_ci.pViewportState = &vp_state_ci;
7317 gp_ci.pRasterizationState = &rs_ci;
7318 gp_ci.pColorBlendState = &cb_ci;
7319 gp_ci.pDynamicState = &dyn_state_ci;
7320 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7321 gp_ci.layout = pipeline_layout;
7322 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007323
7324 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007325 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007326
7327 VkPipeline pipeline;
7328 VkPipelineCache pipelineCache;
7329
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007330 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007331 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007332 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007333
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007334 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007335
Tobin Ehlisd332f282015-10-02 11:00:56 -06007336 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007337 // First need to successfully create the PSO from above by setting
7338 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007339 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 -07007340
7341 VkViewport vp = {}; // Just need dummy vp to point to
7342 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007343 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007344 ASSERT_VK_SUCCESS(err);
7345 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007346 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007347 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007348 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007349 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007350 Draw(1, 0, 0, 0);
7351
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007352 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007353
7354 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7355 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7356 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7357 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007358 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007359}
7360// Create PSO w/o non-zero scissorCount but no scissor data
7361// Then run second test where dynamic viewportCount doesn't match PSO
7362// viewportCount
7363TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7364 VkResult err;
7365
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007366 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 -07007367
7368 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007369
7370 if (!m_device->phy().features().multiViewport) {
7371 printf("Device does not support multiple viewports/scissors; skipped.\n");
7372 return;
7373 }
7374
Karl Schultz6addd812016-02-02 17:17:23 -07007375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7376
7377 VkDescriptorPoolSize ds_type_count = {};
7378 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7379 ds_type_count.descriptorCount = 1;
7380
7381 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7382 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7383 ds_pool_ci.maxSets = 1;
7384 ds_pool_ci.poolSizeCount = 1;
7385 ds_pool_ci.pPoolSizes = &ds_type_count;
7386
7387 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007388 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007389 ASSERT_VK_SUCCESS(err);
7390
7391 VkDescriptorSetLayoutBinding dsl_binding = {};
7392 dsl_binding.binding = 0;
7393 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7394 dsl_binding.descriptorCount = 1;
7395 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7396
7397 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7398 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7399 ds_layout_ci.bindingCount = 1;
7400 ds_layout_ci.pBindings = &dsl_binding;
7401
7402 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007403 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007404 ASSERT_VK_SUCCESS(err);
7405
7406 VkDescriptorSet descriptorSet;
7407 VkDescriptorSetAllocateInfo alloc_info = {};
7408 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7409 alloc_info.descriptorSetCount = 1;
7410 alloc_info.descriptorPool = ds_pool;
7411 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007412 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007413 ASSERT_VK_SUCCESS(err);
7414
7415 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7416 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7417 pipeline_layout_ci.setLayoutCount = 1;
7418 pipeline_layout_ci.pSetLayouts = &ds_layout;
7419
7420 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007421 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007422 ASSERT_VK_SUCCESS(err);
7423
7424 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7425 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7426 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007427 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007428 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007429 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007430
7431 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7432 // Set scissor as dynamic to avoid that error
7433 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7434 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7435 dyn_state_ci.dynamicStateCount = 1;
7436 dyn_state_ci.pDynamicStates = &vp_state;
7437
7438 VkPipelineShaderStageCreateInfo shaderStages[2];
7439 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7440
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007441 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7442 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7443 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007444 shaderStages[0] = vs.GetStageCreateInfo();
7445 shaderStages[1] = fs.GetStageCreateInfo();
7446
7447 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7448 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7449 vi_ci.pNext = nullptr;
7450 vi_ci.vertexBindingDescriptionCount = 0;
7451 vi_ci.pVertexBindingDescriptions = nullptr;
7452 vi_ci.vertexAttributeDescriptionCount = 0;
7453 vi_ci.pVertexAttributeDescriptions = nullptr;
7454
7455 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7456 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7457 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7458
7459 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7460 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7461 rs_ci.pNext = nullptr;
7462
Mark Youngc89c6312016-03-31 16:03:20 -06007463 VkPipelineColorBlendAttachmentState att = {};
7464 att.blendEnable = VK_FALSE;
7465 att.colorWriteMask = 0xf;
7466
Karl Schultz6addd812016-02-02 17:17:23 -07007467 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7468 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7469 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007470 cb_ci.attachmentCount = 1;
7471 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007472
7473 VkGraphicsPipelineCreateInfo gp_ci = {};
7474 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7475 gp_ci.stageCount = 2;
7476 gp_ci.pStages = shaderStages;
7477 gp_ci.pVertexInputState = &vi_ci;
7478 gp_ci.pInputAssemblyState = &ia_ci;
7479 gp_ci.pViewportState = &vp_state_ci;
7480 gp_ci.pRasterizationState = &rs_ci;
7481 gp_ci.pColorBlendState = &cb_ci;
7482 gp_ci.pDynamicState = &dyn_state_ci;
7483 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7484 gp_ci.layout = pipeline_layout;
7485 gp_ci.renderPass = renderPass();
7486
7487 VkPipelineCacheCreateInfo pc_ci = {};
7488 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7489
7490 VkPipeline pipeline;
7491 VkPipelineCache pipelineCache;
7492
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007493 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007494 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007495 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007496
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007497 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007498
7499 // Now hit second fail case where we set scissor w/ different count than PSO
7500 // First need to successfully create the PSO from above by setting
7501 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007502 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 -06007503
Tobin Ehlisd332f282015-10-02 11:00:56 -06007504 VkRect2D sc = {}; // Just need dummy vp to point to
7505 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007506 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007507 ASSERT_VK_SUCCESS(err);
7508 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007509 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007510 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007511 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007512 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007513 Draw(1, 0, 0, 0);
7514
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007515 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007516
Chia-I Wuf7458c52015-10-26 21:10:41 +08007517 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7518 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7519 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7520 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007521 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007522}
7523
Mark Young7394fdd2016-03-31 14:56:43 -06007524TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7525 VkResult err;
7526
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007528
7529 ASSERT_NO_FATAL_FAILURE(InitState());
7530 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7531
7532 VkDescriptorPoolSize ds_type_count = {};
7533 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7534 ds_type_count.descriptorCount = 1;
7535
7536 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7537 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7538 ds_pool_ci.maxSets = 1;
7539 ds_pool_ci.poolSizeCount = 1;
7540 ds_pool_ci.pPoolSizes = &ds_type_count;
7541
7542 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007543 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007544 ASSERT_VK_SUCCESS(err);
7545
7546 VkDescriptorSetLayoutBinding dsl_binding = {};
7547 dsl_binding.binding = 0;
7548 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7549 dsl_binding.descriptorCount = 1;
7550 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7551
7552 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7553 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7554 ds_layout_ci.bindingCount = 1;
7555 ds_layout_ci.pBindings = &dsl_binding;
7556
7557 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007558 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007559 ASSERT_VK_SUCCESS(err);
7560
7561 VkDescriptorSet descriptorSet;
7562 VkDescriptorSetAllocateInfo alloc_info = {};
7563 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7564 alloc_info.descriptorSetCount = 1;
7565 alloc_info.descriptorPool = ds_pool;
7566 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007567 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007568 ASSERT_VK_SUCCESS(err);
7569
7570 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7571 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7572 pipeline_layout_ci.setLayoutCount = 1;
7573 pipeline_layout_ci.pSetLayouts = &ds_layout;
7574
7575 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007576 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007577 ASSERT_VK_SUCCESS(err);
7578
7579 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7580 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7581 vp_state_ci.scissorCount = 1;
7582 vp_state_ci.pScissors = NULL;
7583 vp_state_ci.viewportCount = 1;
7584 vp_state_ci.pViewports = NULL;
7585
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007586 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007587 // Set scissor as dynamic to avoid that error
7588 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7589 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7590 dyn_state_ci.dynamicStateCount = 2;
7591 dyn_state_ci.pDynamicStates = dynamic_states;
7592
7593 VkPipelineShaderStageCreateInfo shaderStages[2];
7594 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7595
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007596 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7597 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007598 this); // TODO - We shouldn't need a fragment shader
7599 // but add it to be able to run on more devices
7600 shaderStages[0] = vs.GetStageCreateInfo();
7601 shaderStages[1] = fs.GetStageCreateInfo();
7602
7603 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7604 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7605 vi_ci.pNext = nullptr;
7606 vi_ci.vertexBindingDescriptionCount = 0;
7607 vi_ci.pVertexBindingDescriptions = nullptr;
7608 vi_ci.vertexAttributeDescriptionCount = 0;
7609 vi_ci.pVertexAttributeDescriptions = nullptr;
7610
7611 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7612 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7613 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7614
7615 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7616 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7617 rs_ci.pNext = nullptr;
7618
Mark Young47107952016-05-02 15:59:55 -06007619 // Check too low (line width of -1.0f).
7620 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007621
7622 VkPipelineColorBlendAttachmentState att = {};
7623 att.blendEnable = VK_FALSE;
7624 att.colorWriteMask = 0xf;
7625
7626 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7627 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7628 cb_ci.pNext = nullptr;
7629 cb_ci.attachmentCount = 1;
7630 cb_ci.pAttachments = &att;
7631
7632 VkGraphicsPipelineCreateInfo gp_ci = {};
7633 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7634 gp_ci.stageCount = 2;
7635 gp_ci.pStages = shaderStages;
7636 gp_ci.pVertexInputState = &vi_ci;
7637 gp_ci.pInputAssemblyState = &ia_ci;
7638 gp_ci.pViewportState = &vp_state_ci;
7639 gp_ci.pRasterizationState = &rs_ci;
7640 gp_ci.pColorBlendState = &cb_ci;
7641 gp_ci.pDynamicState = &dyn_state_ci;
7642 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7643 gp_ci.layout = pipeline_layout;
7644 gp_ci.renderPass = renderPass();
7645
7646 VkPipelineCacheCreateInfo pc_ci = {};
7647 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7648
7649 VkPipeline pipeline;
7650 VkPipelineCache pipelineCache;
7651
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007652 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007653 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007654 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007655
7656 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007657 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007658
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007660
7661 // Check too high (line width of 65536.0f).
7662 rs_ci.lineWidth = 65536.0f;
7663
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007664 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007665 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007666 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007667
7668 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007669 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007670
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007672
7673 dyn_state_ci.dynamicStateCount = 3;
7674
7675 rs_ci.lineWidth = 1.0f;
7676
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007677 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007678 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007679 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007680 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007681 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007682
7683 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007684 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007685 m_errorMonitor->VerifyFound();
7686
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007688
7689 // Check too high with dynamic setting.
7690 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7691 m_errorMonitor->VerifyFound();
7692 EndCommandBuffer();
7693
7694 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7695 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7696 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7697 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007698 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007699}
7700
Karl Schultz6addd812016-02-02 17:17:23 -07007701TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007702 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7704 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007705
7706 ASSERT_NO_FATAL_FAILURE(InitState());
7707 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007708
Tony Barbourfe3351b2015-07-28 10:17:20 -06007709 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007710 // Don't care about RenderPass handle b/c error should be flagged before
7711 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007712 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007713
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007714 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007715}
7716
Karl Schultz6addd812016-02-02 17:17:23 -07007717TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007718 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7720 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007721
7722 ASSERT_NO_FATAL_FAILURE(InitState());
7723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007724
Tony Barbourfe3351b2015-07-28 10:17:20 -06007725 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007726 // Just create a dummy Renderpass that's non-NULL so we can get to the
7727 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007728 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007729
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007730 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007731}
7732
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007733TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7734 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7735 "the number of renderPass attachments that use loadOp"
7736 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7737
7738 ASSERT_NO_FATAL_FAILURE(InitState());
7739 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7740
7741 // Create a renderPass with a single attachment that uses loadOp CLEAR
7742 VkAttachmentReference attach = {};
7743 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7744 VkSubpassDescription subpass = {};
7745 subpass.inputAttachmentCount = 1;
7746 subpass.pInputAttachments = &attach;
7747 VkRenderPassCreateInfo rpci = {};
7748 rpci.subpassCount = 1;
7749 rpci.pSubpasses = &subpass;
7750 rpci.attachmentCount = 1;
7751 VkAttachmentDescription attach_desc = {};
7752 attach_desc.format = VK_FORMAT_UNDEFINED;
7753 // Set loadOp to CLEAR
7754 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7755 rpci.pAttachments = &attach_desc;
7756 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7757 VkRenderPass rp;
7758 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7759
7760 VkCommandBufferInheritanceInfo hinfo = {};
7761 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7762 hinfo.renderPass = VK_NULL_HANDLE;
7763 hinfo.subpass = 0;
7764 hinfo.framebuffer = VK_NULL_HANDLE;
7765 hinfo.occlusionQueryEnable = VK_FALSE;
7766 hinfo.queryFlags = 0;
7767 hinfo.pipelineStatistics = 0;
7768 VkCommandBufferBeginInfo info = {};
7769 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7770 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7771 info.pInheritanceInfo = &hinfo;
7772
7773 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7774 VkRenderPassBeginInfo rp_begin = {};
7775 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7776 rp_begin.pNext = NULL;
7777 rp_begin.renderPass = renderPass();
7778 rp_begin.framebuffer = framebuffer();
7779 rp_begin.clearValueCount = 0; // Should be 1
7780
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7782 "there must be at least 1 entries in "
7783 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007784
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007785 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007786
7787 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007788
7789 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007790}
7791
Cody Northrop3bb4d962016-05-09 16:15:57 -06007792TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7793
7794 TEST_DESCRIPTION("End a command buffer with an active render pass");
7795
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7797 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007798
7799 ASSERT_NO_FATAL_FAILURE(InitState());
7800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7801
7802 // The framework's BeginCommandBuffer calls CreateRenderPass
7803 BeginCommandBuffer();
7804
7805 // Call directly into vkEndCommandBuffer instead of the
7806 // the framework's EndCommandBuffer, which inserts a
7807 // vkEndRenderPass
7808 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7809
7810 m_errorMonitor->VerifyFound();
7811
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007812 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7813 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007814}
7815
Karl Schultz6addd812016-02-02 17:17:23 -07007816TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007817 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7819 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007820
7821 ASSERT_NO_FATAL_FAILURE(InitState());
7822 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007823
7824 // Renderpass is started here
7825 BeginCommandBuffer();
7826
7827 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007828 vk_testing::Buffer dstBuffer;
7829 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007830
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007831 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007832
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007833 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007834}
7835
Karl Schultz6addd812016-02-02 17:17:23 -07007836TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007837 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7839 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007840
7841 ASSERT_NO_FATAL_FAILURE(InitState());
7842 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007843
7844 // Renderpass is started here
7845 BeginCommandBuffer();
7846
7847 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007848 vk_testing::Buffer dstBuffer;
7849 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007850
Karl Schultz6addd812016-02-02 17:17:23 -07007851 VkDeviceSize dstOffset = 0;
7852 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007853 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007854
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007855 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007856
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007857 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007858}
7859
Karl Schultz6addd812016-02-02 17:17:23 -07007860TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007861 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7863 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007864
7865 ASSERT_NO_FATAL_FAILURE(InitState());
7866 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007867
7868 // Renderpass is started here
7869 BeginCommandBuffer();
7870
Michael Lentine0a369f62016-02-03 16:51:46 -06007871 VkClearColorValue clear_color;
7872 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007873 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7874 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7875 const int32_t tex_width = 32;
7876 const int32_t tex_height = 32;
7877 VkImageCreateInfo image_create_info = {};
7878 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7879 image_create_info.pNext = NULL;
7880 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7881 image_create_info.format = tex_format;
7882 image_create_info.extent.width = tex_width;
7883 image_create_info.extent.height = tex_height;
7884 image_create_info.extent.depth = 1;
7885 image_create_info.mipLevels = 1;
7886 image_create_info.arrayLayers = 1;
7887 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7888 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7889 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007890
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007891 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007892 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007893
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007894 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007895
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007896 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007897
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007898 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007899}
7900
Karl Schultz6addd812016-02-02 17:17:23 -07007901TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007902 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7904 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007905
7906 ASSERT_NO_FATAL_FAILURE(InitState());
7907 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007908
7909 // Renderpass is started here
7910 BeginCommandBuffer();
7911
7912 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007913 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007914 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7915 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7916 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7917 image_create_info.extent.width = 64;
7918 image_create_info.extent.height = 64;
7919 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7920 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007921
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007922 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007923 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007924
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007925 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007926
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007927 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7928 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007929
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007930 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007931}
7932
Karl Schultz6addd812016-02-02 17:17:23 -07007933TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007934 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007935 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007936
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
7938 "must be issued inside an active "
7939 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007940
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007941 ASSERT_NO_FATAL_FAILURE(InitState());
7942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007943
7944 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007945 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007946 ASSERT_VK_SUCCESS(err);
7947
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007948 VkClearAttachment color_attachment;
7949 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7950 color_attachment.clearValue.color.float32[0] = 0;
7951 color_attachment.clearValue.color.float32[1] = 0;
7952 color_attachment.clearValue.color.float32[2] = 0;
7953 color_attachment.clearValue.color.float32[3] = 0;
7954 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007955 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007956 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007957
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007958 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007959}
7960
Chris Forbes3b97e932016-09-07 11:29:24 +12007961TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
7962 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
7963 "called too many times in a renderpass instance");
7964
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
7966 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12007967
7968 ASSERT_NO_FATAL_FAILURE(InitState());
7969 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7970
7971 BeginCommandBuffer();
7972
7973 // error here.
7974 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
7975 m_errorMonitor->VerifyFound();
7976
7977 EndCommandBuffer();
7978}
7979
Chris Forbes6d624702016-09-07 13:57:05 +12007980TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
7981 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
7982 "called before the final subpass has been reached");
7983
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
7985 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12007986
7987 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007988 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
7989 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12007990
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007991 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12007992
7993 VkRenderPass rp;
7994 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
7995 ASSERT_VK_SUCCESS(err);
7996
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007997 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12007998
7999 VkFramebuffer fb;
8000 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8001 ASSERT_VK_SUCCESS(err);
8002
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008003 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008004
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008005 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 +12008006
8007 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8008
8009 // Error here.
8010 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8011 m_errorMonitor->VerifyFound();
8012
8013 // Clean up.
8014 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8015 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8016}
8017
Karl Schultz9e66a292016-04-21 15:57:51 -06008018TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8019 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8021 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008022
8023 ASSERT_NO_FATAL_FAILURE(InitState());
8024 BeginCommandBuffer();
8025
8026 VkBufferMemoryBarrier buf_barrier = {};
8027 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8028 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8029 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8030 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8031 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8032 buf_barrier.buffer = VK_NULL_HANDLE;
8033 buf_barrier.offset = 0;
8034 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008035 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8036 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008037
8038 m_errorMonitor->VerifyFound();
8039}
8040
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008041TEST_F(VkLayerTest, InvalidBarriers) {
8042 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8043
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008045
8046 ASSERT_NO_FATAL_FAILURE(InitState());
8047 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8048
8049 VkMemoryBarrier mem_barrier = {};
8050 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8051 mem_barrier.pNext = NULL;
8052 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8053 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8054 BeginCommandBuffer();
8055 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008056 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008057 &mem_barrier, 0, nullptr, 0, nullptr);
8058 m_errorMonitor->VerifyFound();
8059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008061 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008062 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 -06008063 ASSERT_TRUE(image.initialized());
8064 VkImageMemoryBarrier img_barrier = {};
8065 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8066 img_barrier.pNext = NULL;
8067 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8068 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8069 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8070 // New layout can't be UNDEFINED
8071 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8072 img_barrier.image = image.handle();
8073 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8074 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8075 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8076 img_barrier.subresourceRange.baseArrayLayer = 0;
8077 img_barrier.subresourceRange.baseMipLevel = 0;
8078 img_barrier.subresourceRange.layerCount = 1;
8079 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008080 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8081 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008082 m_errorMonitor->VerifyFound();
8083 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8084
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8086 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008087 // baseArrayLayer + layerCount must be <= image's arrayLayers
8088 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008089 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8090 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008091 m_errorMonitor->VerifyFound();
8092 img_barrier.subresourceRange.baseArrayLayer = 0;
8093
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008095 // baseMipLevel + levelCount must be <= image's mipLevels
8096 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008097 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8098 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008099 m_errorMonitor->VerifyFound();
8100 img_barrier.subresourceRange.baseMipLevel = 0;
8101
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008102 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 -06008103 vk_testing::Buffer buffer;
8104 buffer.init(*m_device, 256);
8105 VkBufferMemoryBarrier buf_barrier = {};
8106 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8107 buf_barrier.pNext = NULL;
8108 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8109 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8110 buf_barrier.buffer = buffer.handle();
8111 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8112 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8113 buf_barrier.offset = 0;
8114 buf_barrier.size = VK_WHOLE_SIZE;
8115 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008116 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8117 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008118 m_errorMonitor->VerifyFound();
8119 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8120
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008122 buf_barrier.offset = 257;
8123 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008124 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8125 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008126 m_errorMonitor->VerifyFound();
8127 buf_barrier.offset = 0;
8128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008130 buf_barrier.size = 257;
8131 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008132 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8133 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008134 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008135
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008136 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008137 m_errorMonitor->SetDesiredFailureMsg(
8138 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8139 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8140 m_errorMonitor->SetDesiredFailureMsg(
8141 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8142 "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 -06008143 VkDepthStencilObj ds_image(m_device);
8144 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8145 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008146 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8147 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008148 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008149 // Use of COLOR aspect on DS image is error
8150 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008151 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8152 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008153 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008154 // Now test depth-only
8155 VkFormatProperties format_props;
8156
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008157 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8158 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8160 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8162 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008163 VkDepthStencilObj d_image(m_device);
8164 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8165 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008166 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008167 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008168 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008169 // Use of COLOR aspect on depth image is error
8170 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008171 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8172 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008173 m_errorMonitor->VerifyFound();
8174 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008175 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8176 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008177 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8179 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008180 VkDepthStencilObj s_image(m_device);
8181 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8182 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008183 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008184 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008185 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008186 // Use of COLOR aspect on depth image is error
8187 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008188 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8189 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008190 m_errorMonitor->VerifyFound();
8191 }
8192 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8194 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8196 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008197 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008198 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 -06008199 ASSERT_TRUE(c_image.initialized());
8200 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8201 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8202 img_barrier.image = c_image.handle();
8203 // Set aspect to depth (non-color)
8204 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008205 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8206 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008207 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008208}
8209
Tony Barbour18ba25c2016-09-29 13:42:40 -06008210TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8211 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8212
8213 m_errorMonitor->SetDesiredFailureMsg(
8214 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8215 "must have required access bit");
8216 ASSERT_NO_FATAL_FAILURE(InitState());
8217 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008218 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 -06008219 ASSERT_TRUE(image.initialized());
8220
8221 VkImageMemoryBarrier barrier = {};
8222 VkImageSubresourceRange range;
8223 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8224 barrier.srcAccessMask = 0;
8225 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8226 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8227 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8228 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8229 barrier.image = image.handle();
8230 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8231 range.baseMipLevel = 0;
8232 range.levelCount = 1;
8233 range.baseArrayLayer = 0;
8234 range.layerCount = 1;
8235 barrier.subresourceRange = range;
8236 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8237 cmdbuf.BeginCommandBuffer();
8238 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8239 &barrier);
8240 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8241 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8242 barrier.srcAccessMask = 0;
8243 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8244 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8245 &barrier);
8246
8247 m_errorMonitor->VerifyFound();
8248}
8249
Karl Schultz6addd812016-02-02 17:17:23 -07008250TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008251 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008252 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008253
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008255
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008256 ASSERT_NO_FATAL_FAILURE(InitState());
8257 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008258 uint32_t qfi = 0;
8259 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008260 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8261 buffCI.size = 1024;
8262 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8263 buffCI.queueFamilyIndexCount = 1;
8264 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008265
8266 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008267 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008268 ASSERT_VK_SUCCESS(err);
8269
8270 BeginCommandBuffer();
8271 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008272 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8273 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008274 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008275 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008276
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008277 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008278
Chia-I Wuf7458c52015-10-26 21:10:41 +08008279 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008280}
8281
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008282TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8283 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8285 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8286 "of the indices specified when the device was created, via the "
8287 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008288
8289 ASSERT_NO_FATAL_FAILURE(InitState());
8290 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8291 VkBufferCreateInfo buffCI = {};
8292 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8293 buffCI.size = 1024;
8294 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8295 buffCI.queueFamilyIndexCount = 1;
8296 // Introduce failure by specifying invalid queue_family_index
8297 uint32_t qfi = 777;
8298 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008299 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008300
8301 VkBuffer ib;
8302 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8303
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008304 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008305 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008306}
8307
Karl Schultz6addd812016-02-02 17:17:23 -07008308TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008309TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008310 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008311
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008312 ASSERT_NO_FATAL_FAILURE(InitState());
8313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008314
Chris Forbesf29a84f2016-10-06 18:39:28 +13008315 // An empty primary command buffer
8316 VkCommandBufferObj cb(m_device, m_commandPool);
8317 cb.BeginCommandBuffer();
8318 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008319
Chris Forbesf29a84f2016-10-06 18:39:28 +13008320 m_commandBuffer->BeginCommandBuffer();
8321 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8322 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008323
Chris Forbesf29a84f2016-10-06 18:39:28 +13008324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8325 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008326 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008327}
8328
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008329TEST_F(VkLayerTest, DSUsageBitsErrors) {
8330 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8331 "that do not have correct usage bits sets.");
8332 VkResult err;
8333
8334 ASSERT_NO_FATAL_FAILURE(InitState());
8335 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8336 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8337 ds_type_count[i].type = VkDescriptorType(i);
8338 ds_type_count[i].descriptorCount = 1;
8339 }
8340 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8341 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8342 ds_pool_ci.pNext = NULL;
8343 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8344 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8345 ds_pool_ci.pPoolSizes = ds_type_count;
8346
8347 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008348 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008349 ASSERT_VK_SUCCESS(err);
8350
8351 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008352 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008353 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8354 dsl_binding[i].binding = 0;
8355 dsl_binding[i].descriptorType = VkDescriptorType(i);
8356 dsl_binding[i].descriptorCount = 1;
8357 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8358 dsl_binding[i].pImmutableSamplers = NULL;
8359 }
8360
8361 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8362 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8363 ds_layout_ci.pNext = NULL;
8364 ds_layout_ci.bindingCount = 1;
8365 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8366 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8367 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008368 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008369 ASSERT_VK_SUCCESS(err);
8370 }
8371 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8372 VkDescriptorSetAllocateInfo alloc_info = {};
8373 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8374 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8375 alloc_info.descriptorPool = ds_pool;
8376 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008377 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008378 ASSERT_VK_SUCCESS(err);
8379
8380 // Create a buffer & bufferView to be used for invalid updates
8381 VkBufferCreateInfo buff_ci = {};
8382 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8383 // This usage is not valid for any descriptor type
8384 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8385 buff_ci.size = 256;
8386 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8387 VkBuffer buffer;
8388 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8389 ASSERT_VK_SUCCESS(err);
8390
8391 VkBufferViewCreateInfo buff_view_ci = {};
8392 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8393 buff_view_ci.buffer = buffer;
8394 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8395 buff_view_ci.range = VK_WHOLE_SIZE;
8396 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008397 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008398 ASSERT_VK_SUCCESS(err);
8399
8400 // Create an image to be used for invalid updates
8401 VkImageCreateInfo image_ci = {};
8402 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8403 image_ci.imageType = VK_IMAGE_TYPE_2D;
8404 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8405 image_ci.extent.width = 64;
8406 image_ci.extent.height = 64;
8407 image_ci.extent.depth = 1;
8408 image_ci.mipLevels = 1;
8409 image_ci.arrayLayers = 1;
8410 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8411 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8412 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8413 // This usage is not valid for any descriptor type
8414 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8415 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8416 VkImage image;
8417 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8418 ASSERT_VK_SUCCESS(err);
8419 // Bind memory to image
8420 VkMemoryRequirements mem_reqs;
8421 VkDeviceMemory image_mem;
8422 bool pass;
8423 VkMemoryAllocateInfo mem_alloc = {};
8424 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8425 mem_alloc.pNext = NULL;
8426 mem_alloc.allocationSize = 0;
8427 mem_alloc.memoryTypeIndex = 0;
8428 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8429 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008430 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008431 ASSERT_TRUE(pass);
8432 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8433 ASSERT_VK_SUCCESS(err);
8434 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8435 ASSERT_VK_SUCCESS(err);
8436 // Now create view for image
8437 VkImageViewCreateInfo image_view_ci = {};
8438 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8439 image_view_ci.image = image;
8440 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8441 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8442 image_view_ci.subresourceRange.layerCount = 1;
8443 image_view_ci.subresourceRange.baseArrayLayer = 0;
8444 image_view_ci.subresourceRange.levelCount = 1;
8445 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8446 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008447 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008448 ASSERT_VK_SUCCESS(err);
8449
8450 VkDescriptorBufferInfo buff_info = {};
8451 buff_info.buffer = buffer;
8452 VkDescriptorImageInfo img_info = {};
8453 img_info.imageView = image_view;
8454 VkWriteDescriptorSet descriptor_write = {};
8455 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8456 descriptor_write.dstBinding = 0;
8457 descriptor_write.descriptorCount = 1;
8458 descriptor_write.pTexelBufferView = &buff_view;
8459 descriptor_write.pBufferInfo = &buff_info;
8460 descriptor_write.pImageInfo = &img_info;
8461
8462 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008463 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8464 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8465 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8466 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8467 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8468 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8469 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8470 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8471 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8472 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8473 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008474 // Start loop at 1 as SAMPLER desc type has no usage bit error
8475 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8476 descriptor_write.descriptorType = VkDescriptorType(i);
8477 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008479
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008480 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008481
8482 m_errorMonitor->VerifyFound();
8483 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8484 }
8485 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8486 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008487 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008488 vkDestroyImageView(m_device->device(), image_view, NULL);
8489 vkDestroyBuffer(m_device->device(), buffer, NULL);
8490 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008491 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008492 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8493}
8494
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008495TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008496 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8497 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8498 "1. offset value greater than buffer size\n"
8499 "2. range value of 0\n"
8500 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008501 VkResult err;
8502
8503 ASSERT_NO_FATAL_FAILURE(InitState());
8504 VkDescriptorPoolSize ds_type_count = {};
8505 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8506 ds_type_count.descriptorCount = 1;
8507
8508 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8509 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8510 ds_pool_ci.pNext = NULL;
8511 ds_pool_ci.maxSets = 1;
8512 ds_pool_ci.poolSizeCount = 1;
8513 ds_pool_ci.pPoolSizes = &ds_type_count;
8514
8515 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008516 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008517 ASSERT_VK_SUCCESS(err);
8518
8519 // Create layout with single uniform buffer descriptor
8520 VkDescriptorSetLayoutBinding dsl_binding = {};
8521 dsl_binding.binding = 0;
8522 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8523 dsl_binding.descriptorCount = 1;
8524 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8525 dsl_binding.pImmutableSamplers = NULL;
8526
8527 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8528 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8529 ds_layout_ci.pNext = NULL;
8530 ds_layout_ci.bindingCount = 1;
8531 ds_layout_ci.pBindings = &dsl_binding;
8532 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008533 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008534 ASSERT_VK_SUCCESS(err);
8535
8536 VkDescriptorSet descriptor_set = {};
8537 VkDescriptorSetAllocateInfo alloc_info = {};
8538 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8539 alloc_info.descriptorSetCount = 1;
8540 alloc_info.descriptorPool = ds_pool;
8541 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008542 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008543 ASSERT_VK_SUCCESS(err);
8544
8545 // Create a buffer to be used for invalid updates
8546 VkBufferCreateInfo buff_ci = {};
8547 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8548 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8549 buff_ci.size = 256;
8550 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8551 VkBuffer buffer;
8552 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8553 ASSERT_VK_SUCCESS(err);
8554 // Have to bind memory to buffer before descriptor update
8555 VkMemoryAllocateInfo mem_alloc = {};
8556 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8557 mem_alloc.pNext = NULL;
8558 mem_alloc.allocationSize = 256;
8559 mem_alloc.memoryTypeIndex = 0;
8560
8561 VkMemoryRequirements mem_reqs;
8562 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008563 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008564 if (!pass) {
8565 vkDestroyBuffer(m_device->device(), buffer, NULL);
8566 return;
8567 }
8568
8569 VkDeviceMemory mem;
8570 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8571 ASSERT_VK_SUCCESS(err);
8572 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8573 ASSERT_VK_SUCCESS(err);
8574
8575 VkDescriptorBufferInfo buff_info = {};
8576 buff_info.buffer = buffer;
8577 // First make offset 1 larger than buffer size
8578 buff_info.offset = 257;
8579 buff_info.range = VK_WHOLE_SIZE;
8580 VkWriteDescriptorSet descriptor_write = {};
8581 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8582 descriptor_write.dstBinding = 0;
8583 descriptor_write.descriptorCount = 1;
8584 descriptor_write.pTexelBufferView = nullptr;
8585 descriptor_write.pBufferInfo = &buff_info;
8586 descriptor_write.pImageInfo = nullptr;
8587
8588 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8589 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008591
8592 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8593
8594 m_errorMonitor->VerifyFound();
8595 // Now cause error due to range of 0
8596 buff_info.offset = 0;
8597 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8599 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008600
8601 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8602
8603 m_errorMonitor->VerifyFound();
8604 // Now cause error due to range exceeding buffer size - offset
8605 buff_info.offset = 128;
8606 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008607 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 -06008608
8609 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8610
8611 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008612 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008613 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8614 vkDestroyBuffer(m_device->device(), buffer, NULL);
8615 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8616 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8617}
8618
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008619TEST_F(VkLayerTest, DSAspectBitsErrors) {
8620 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8621 // are set, but could expand this test to hit more cases.
8622 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8623 "that do not have correct aspect bits sets.");
8624 VkResult err;
8625
8626 ASSERT_NO_FATAL_FAILURE(InitState());
8627 VkDescriptorPoolSize ds_type_count = {};
8628 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8629 ds_type_count.descriptorCount = 1;
8630
8631 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8632 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8633 ds_pool_ci.pNext = NULL;
8634 ds_pool_ci.maxSets = 5;
8635 ds_pool_ci.poolSizeCount = 1;
8636 ds_pool_ci.pPoolSizes = &ds_type_count;
8637
8638 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008639 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008640 ASSERT_VK_SUCCESS(err);
8641
8642 VkDescriptorSetLayoutBinding dsl_binding = {};
8643 dsl_binding.binding = 0;
8644 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8645 dsl_binding.descriptorCount = 1;
8646 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8647 dsl_binding.pImmutableSamplers = NULL;
8648
8649 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8650 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8651 ds_layout_ci.pNext = NULL;
8652 ds_layout_ci.bindingCount = 1;
8653 ds_layout_ci.pBindings = &dsl_binding;
8654 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008655 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008656 ASSERT_VK_SUCCESS(err);
8657
8658 VkDescriptorSet descriptor_set = {};
8659 VkDescriptorSetAllocateInfo alloc_info = {};
8660 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8661 alloc_info.descriptorSetCount = 1;
8662 alloc_info.descriptorPool = ds_pool;
8663 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008664 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008665 ASSERT_VK_SUCCESS(err);
8666
8667 // Create an image to be used for invalid updates
8668 VkImageCreateInfo image_ci = {};
8669 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8670 image_ci.imageType = VK_IMAGE_TYPE_2D;
8671 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8672 image_ci.extent.width = 64;
8673 image_ci.extent.height = 64;
8674 image_ci.extent.depth = 1;
8675 image_ci.mipLevels = 1;
8676 image_ci.arrayLayers = 1;
8677 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8678 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8679 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8680 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8681 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8682 VkImage image;
8683 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8684 ASSERT_VK_SUCCESS(err);
8685 // Bind memory to image
8686 VkMemoryRequirements mem_reqs;
8687 VkDeviceMemory image_mem;
8688 bool pass;
8689 VkMemoryAllocateInfo mem_alloc = {};
8690 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8691 mem_alloc.pNext = NULL;
8692 mem_alloc.allocationSize = 0;
8693 mem_alloc.memoryTypeIndex = 0;
8694 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8695 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008696 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008697 ASSERT_TRUE(pass);
8698 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8699 ASSERT_VK_SUCCESS(err);
8700 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8701 ASSERT_VK_SUCCESS(err);
8702 // Now create view for image
8703 VkImageViewCreateInfo image_view_ci = {};
8704 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8705 image_view_ci.image = image;
8706 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8707 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8708 image_view_ci.subresourceRange.layerCount = 1;
8709 image_view_ci.subresourceRange.baseArrayLayer = 0;
8710 image_view_ci.subresourceRange.levelCount = 1;
8711 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008712 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008713
8714 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008715 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008716 ASSERT_VK_SUCCESS(err);
8717
8718 VkDescriptorImageInfo img_info = {};
8719 img_info.imageView = image_view;
8720 VkWriteDescriptorSet descriptor_write = {};
8721 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8722 descriptor_write.dstBinding = 0;
8723 descriptor_write.descriptorCount = 1;
8724 descriptor_write.pTexelBufferView = NULL;
8725 descriptor_write.pBufferInfo = NULL;
8726 descriptor_write.pImageInfo = &img_info;
8727 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8728 descriptor_write.dstSet = descriptor_set;
8729 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8730 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008732
8733 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8734
8735 m_errorMonitor->VerifyFound();
8736 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8737 vkDestroyImage(m_device->device(), image, NULL);
8738 vkFreeMemory(m_device->device(), image_mem, NULL);
8739 vkDestroyImageView(m_device->device(), image_view, NULL);
8740 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8741 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8742}
8743
Karl Schultz6addd812016-02-02 17:17:23 -07008744TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008745 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008746 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008747
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8749 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8750 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008751
Tobin Ehlis3b780662015-05-28 12:11:26 -06008752 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008753 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008754 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008755 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8756 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008757
8758 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008759 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8760 ds_pool_ci.pNext = NULL;
8761 ds_pool_ci.maxSets = 1;
8762 ds_pool_ci.poolSizeCount = 1;
8763 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008764
Tobin Ehlis3b780662015-05-28 12:11:26 -06008765 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008766 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008767 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008768 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008769 dsl_binding.binding = 0;
8770 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8771 dsl_binding.descriptorCount = 1;
8772 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8773 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008774
Tony Barboureb254902015-07-15 12:50:33 -06008775 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008776 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8777 ds_layout_ci.pNext = NULL;
8778 ds_layout_ci.bindingCount = 1;
8779 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008780
Tobin Ehlis3b780662015-05-28 12:11:26 -06008781 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008782 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008783 ASSERT_VK_SUCCESS(err);
8784
8785 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008786 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008787 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008788 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008789 alloc_info.descriptorPool = ds_pool;
8790 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008791 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008792 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008793
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008794 VkSamplerCreateInfo sampler_ci = {};
8795 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8796 sampler_ci.pNext = NULL;
8797 sampler_ci.magFilter = VK_FILTER_NEAREST;
8798 sampler_ci.minFilter = VK_FILTER_NEAREST;
8799 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8800 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8801 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8802 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8803 sampler_ci.mipLodBias = 1.0;
8804 sampler_ci.anisotropyEnable = VK_FALSE;
8805 sampler_ci.maxAnisotropy = 1;
8806 sampler_ci.compareEnable = VK_FALSE;
8807 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8808 sampler_ci.minLod = 1.0;
8809 sampler_ci.maxLod = 1.0;
8810 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8811 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8812 VkSampler sampler;
8813 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8814 ASSERT_VK_SUCCESS(err);
8815
8816 VkDescriptorImageInfo info = {};
8817 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008818
8819 VkWriteDescriptorSet descriptor_write;
8820 memset(&descriptor_write, 0, sizeof(descriptor_write));
8821 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008822 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008823 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008824 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008825 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008826 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008827
8828 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8829
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008830 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008831
Chia-I Wuf7458c52015-10-26 21:10:41 +08008832 vkDestroySampler(m_device->device(), sampler, NULL);
8833 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8834 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008835}
8836
Karl Schultz6addd812016-02-02 17:17:23 -07008837TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008838 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008839 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008840
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8842 " binding #0 with 1 total descriptors but update of 1 descriptors "
8843 "starting at binding offset of 0 combined with update array element "
8844 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008845
Tobin Ehlis3b780662015-05-28 12:11:26 -06008846 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008847 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008848 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008849 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8850 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008851
8852 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008853 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8854 ds_pool_ci.pNext = NULL;
8855 ds_pool_ci.maxSets = 1;
8856 ds_pool_ci.poolSizeCount = 1;
8857 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008858
Tobin Ehlis3b780662015-05-28 12:11:26 -06008859 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008860 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008861 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008862
Tony Barboureb254902015-07-15 12:50:33 -06008863 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008864 dsl_binding.binding = 0;
8865 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8866 dsl_binding.descriptorCount = 1;
8867 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8868 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008869
8870 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008871 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8872 ds_layout_ci.pNext = NULL;
8873 ds_layout_ci.bindingCount = 1;
8874 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008875
Tobin Ehlis3b780662015-05-28 12:11:26 -06008876 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008877 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008878 ASSERT_VK_SUCCESS(err);
8879
8880 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008881 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008882 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008883 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008884 alloc_info.descriptorPool = ds_pool;
8885 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008886 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008887 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008888
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008889 // Correctly update descriptor to avoid "NOT_UPDATED" error
8890 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008891 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008892 buff_info.offset = 0;
8893 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008894
8895 VkWriteDescriptorSet descriptor_write;
8896 memset(&descriptor_write, 0, sizeof(descriptor_write));
8897 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008898 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008899 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008900 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008901 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8902 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008903
8904 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8905
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008906 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008907
Chia-I Wuf7458c52015-10-26 21:10:41 +08008908 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8909 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008910}
8911
Karl Schultz6addd812016-02-02 17:17:23 -07008912TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8913 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8914 // index 2
8915 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008916
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008918
Tobin Ehlis3b780662015-05-28 12:11:26 -06008919 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008920 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008921 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008922 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8923 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008924
8925 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008926 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8927 ds_pool_ci.pNext = NULL;
8928 ds_pool_ci.maxSets = 1;
8929 ds_pool_ci.poolSizeCount = 1;
8930 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008931
Tobin Ehlis3b780662015-05-28 12:11:26 -06008932 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008933 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008934 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008935
Tony Barboureb254902015-07-15 12:50:33 -06008936 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008937 dsl_binding.binding = 0;
8938 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8939 dsl_binding.descriptorCount = 1;
8940 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8941 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008942
8943 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008944 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8945 ds_layout_ci.pNext = NULL;
8946 ds_layout_ci.bindingCount = 1;
8947 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008948 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008949 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008950 ASSERT_VK_SUCCESS(err);
8951
8952 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008953 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008954 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008955 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008956 alloc_info.descriptorPool = ds_pool;
8957 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008958 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008959 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008960
Tony Barboureb254902015-07-15 12:50:33 -06008961 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008962 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8963 sampler_ci.pNext = NULL;
8964 sampler_ci.magFilter = VK_FILTER_NEAREST;
8965 sampler_ci.minFilter = VK_FILTER_NEAREST;
8966 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8967 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8968 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8969 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8970 sampler_ci.mipLodBias = 1.0;
8971 sampler_ci.anisotropyEnable = VK_FALSE;
8972 sampler_ci.maxAnisotropy = 1;
8973 sampler_ci.compareEnable = VK_FALSE;
8974 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8975 sampler_ci.minLod = 1.0;
8976 sampler_ci.maxLod = 1.0;
8977 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8978 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008979
Tobin Ehlis3b780662015-05-28 12:11:26 -06008980 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008981 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008982 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008983
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008984 VkDescriptorImageInfo info = {};
8985 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008986
8987 VkWriteDescriptorSet descriptor_write;
8988 memset(&descriptor_write, 0, sizeof(descriptor_write));
8989 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008990 descriptor_write.dstSet = descriptorSet;
8991 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008992 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008993 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008994 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008995 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008996
8997 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8998
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008999 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009000
Chia-I Wuf7458c52015-10-26 21:10:41 +08009001 vkDestroySampler(m_device->device(), sampler, NULL);
9002 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9003 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009004}
9005
Karl Schultz6addd812016-02-02 17:17:23 -07009006TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9007 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9008 // types
9009 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009011 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 -06009012
Tobin Ehlis3b780662015-05-28 12:11:26 -06009013 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009014
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009015 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009016 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9017 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009018
9019 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009020 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9021 ds_pool_ci.pNext = NULL;
9022 ds_pool_ci.maxSets = 1;
9023 ds_pool_ci.poolSizeCount = 1;
9024 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009025
Tobin Ehlis3b780662015-05-28 12:11:26 -06009026 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009027 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009028 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009029 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009030 dsl_binding.binding = 0;
9031 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9032 dsl_binding.descriptorCount = 1;
9033 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9034 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009035
Tony Barboureb254902015-07-15 12:50:33 -06009036 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009037 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9038 ds_layout_ci.pNext = NULL;
9039 ds_layout_ci.bindingCount = 1;
9040 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009041
Tobin Ehlis3b780662015-05-28 12:11:26 -06009042 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009043 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009044 ASSERT_VK_SUCCESS(err);
9045
9046 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009047 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009048 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009049 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009050 alloc_info.descriptorPool = ds_pool;
9051 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009052 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009053 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009054
Tony Barboureb254902015-07-15 12:50:33 -06009055 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009056 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9057 sampler_ci.pNext = NULL;
9058 sampler_ci.magFilter = VK_FILTER_NEAREST;
9059 sampler_ci.minFilter = VK_FILTER_NEAREST;
9060 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9061 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9062 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9063 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9064 sampler_ci.mipLodBias = 1.0;
9065 sampler_ci.anisotropyEnable = VK_FALSE;
9066 sampler_ci.maxAnisotropy = 1;
9067 sampler_ci.compareEnable = VK_FALSE;
9068 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9069 sampler_ci.minLod = 1.0;
9070 sampler_ci.maxLod = 1.0;
9071 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9072 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009073 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009074 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009075 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009076
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009077 VkDescriptorImageInfo info = {};
9078 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009079
9080 VkWriteDescriptorSet descriptor_write;
9081 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009082 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009083 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009084 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009085 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009086 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009087 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009088
9089 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9090
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009091 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009092
Chia-I Wuf7458c52015-10-26 21:10:41 +08009093 vkDestroySampler(m_device->device(), sampler, NULL);
9094 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9095 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009096}
9097
Karl Schultz6addd812016-02-02 17:17:23 -07009098TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009099 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009100 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009101
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9103 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009104
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009105 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009106 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9107 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009108 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009109 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9110 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009111
9112 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009113 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9114 ds_pool_ci.pNext = NULL;
9115 ds_pool_ci.maxSets = 1;
9116 ds_pool_ci.poolSizeCount = 1;
9117 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009118
9119 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009120 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009121 ASSERT_VK_SUCCESS(err);
9122
9123 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009124 dsl_binding.binding = 0;
9125 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9126 dsl_binding.descriptorCount = 1;
9127 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9128 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009129
9130 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009131 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9132 ds_layout_ci.pNext = NULL;
9133 ds_layout_ci.bindingCount = 1;
9134 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009135 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009136 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009137 ASSERT_VK_SUCCESS(err);
9138
9139 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009140 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009141 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009142 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009143 alloc_info.descriptorPool = ds_pool;
9144 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009145 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009146 ASSERT_VK_SUCCESS(err);
9147
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009148 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009149
9150 VkDescriptorImageInfo descriptor_info;
9151 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9152 descriptor_info.sampler = sampler;
9153
9154 VkWriteDescriptorSet descriptor_write;
9155 memset(&descriptor_write, 0, sizeof(descriptor_write));
9156 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009157 descriptor_write.dstSet = descriptorSet;
9158 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009159 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009160 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9161 descriptor_write.pImageInfo = &descriptor_info;
9162
9163 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9164
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009165 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009166
Chia-I Wuf7458c52015-10-26 21:10:41 +08009167 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9168 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009169}
9170
Karl Schultz6addd812016-02-02 17:17:23 -07009171TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9172 // Create a single combined Image/Sampler descriptor and send it an invalid
9173 // imageView
9174 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009175
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9177 "image sampler descriptor failed due "
9178 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009179
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009180 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009181 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009182 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9183 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009184
9185 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009186 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9187 ds_pool_ci.pNext = NULL;
9188 ds_pool_ci.maxSets = 1;
9189 ds_pool_ci.poolSizeCount = 1;
9190 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009191
9192 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009193 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009194 ASSERT_VK_SUCCESS(err);
9195
9196 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009197 dsl_binding.binding = 0;
9198 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9199 dsl_binding.descriptorCount = 1;
9200 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9201 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009202
9203 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009204 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9205 ds_layout_ci.pNext = NULL;
9206 ds_layout_ci.bindingCount = 1;
9207 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009208 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009209 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009210 ASSERT_VK_SUCCESS(err);
9211
9212 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009213 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009214 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009215 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009216 alloc_info.descriptorPool = ds_pool;
9217 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009218 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009219 ASSERT_VK_SUCCESS(err);
9220
9221 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009222 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9223 sampler_ci.pNext = NULL;
9224 sampler_ci.magFilter = VK_FILTER_NEAREST;
9225 sampler_ci.minFilter = VK_FILTER_NEAREST;
9226 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9227 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9228 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9229 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9230 sampler_ci.mipLodBias = 1.0;
9231 sampler_ci.anisotropyEnable = VK_FALSE;
9232 sampler_ci.maxAnisotropy = 1;
9233 sampler_ci.compareEnable = VK_FALSE;
9234 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9235 sampler_ci.minLod = 1.0;
9236 sampler_ci.maxLod = 1.0;
9237 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9238 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009239
9240 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009241 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009242 ASSERT_VK_SUCCESS(err);
9243
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009244 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009245
9246 VkDescriptorImageInfo descriptor_info;
9247 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9248 descriptor_info.sampler = sampler;
9249 descriptor_info.imageView = view;
9250
9251 VkWriteDescriptorSet descriptor_write;
9252 memset(&descriptor_write, 0, sizeof(descriptor_write));
9253 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009254 descriptor_write.dstSet = descriptorSet;
9255 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009256 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009257 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9258 descriptor_write.pImageInfo = &descriptor_info;
9259
9260 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9261
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009262 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009263
Chia-I Wuf7458c52015-10-26 21:10:41 +08009264 vkDestroySampler(m_device->device(), sampler, NULL);
9265 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9266 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009267}
9268
Karl Schultz6addd812016-02-02 17:17:23 -07009269TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9270 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9271 // into the other
9272 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009273
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9275 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9276 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009277
Tobin Ehlis04356f92015-10-27 16:35:27 -06009278 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009279 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009280 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009281 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9282 ds_type_count[0].descriptorCount = 1;
9283 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9284 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009285
9286 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009287 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9288 ds_pool_ci.pNext = NULL;
9289 ds_pool_ci.maxSets = 1;
9290 ds_pool_ci.poolSizeCount = 2;
9291 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009292
9293 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009294 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009295 ASSERT_VK_SUCCESS(err);
9296 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009297 dsl_binding[0].binding = 0;
9298 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9299 dsl_binding[0].descriptorCount = 1;
9300 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9301 dsl_binding[0].pImmutableSamplers = NULL;
9302 dsl_binding[1].binding = 1;
9303 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9304 dsl_binding[1].descriptorCount = 1;
9305 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9306 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009307
9308 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009309 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9310 ds_layout_ci.pNext = NULL;
9311 ds_layout_ci.bindingCount = 2;
9312 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009313
9314 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009315 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009316 ASSERT_VK_SUCCESS(err);
9317
9318 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009319 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009320 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009321 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009322 alloc_info.descriptorPool = ds_pool;
9323 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009324 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009325 ASSERT_VK_SUCCESS(err);
9326
9327 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009328 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9329 sampler_ci.pNext = NULL;
9330 sampler_ci.magFilter = VK_FILTER_NEAREST;
9331 sampler_ci.minFilter = VK_FILTER_NEAREST;
9332 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9333 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9334 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9335 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9336 sampler_ci.mipLodBias = 1.0;
9337 sampler_ci.anisotropyEnable = VK_FALSE;
9338 sampler_ci.maxAnisotropy = 1;
9339 sampler_ci.compareEnable = VK_FALSE;
9340 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9341 sampler_ci.minLod = 1.0;
9342 sampler_ci.maxLod = 1.0;
9343 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9344 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009345
9346 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009347 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009348 ASSERT_VK_SUCCESS(err);
9349
9350 VkDescriptorImageInfo info = {};
9351 info.sampler = sampler;
9352
9353 VkWriteDescriptorSet descriptor_write;
9354 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9355 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009356 descriptor_write.dstSet = descriptorSet;
9357 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009358 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009359 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9360 descriptor_write.pImageInfo = &info;
9361 // This write update should succeed
9362 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9363 // Now perform a copy update that fails due to type mismatch
9364 VkCopyDescriptorSet copy_ds_update;
9365 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9366 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9367 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009368 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009369 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009370 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009371 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009372 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9373
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009374 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009375 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009376 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 -06009377 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9378 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9379 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009380 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009381 copy_ds_update.dstSet = descriptorSet;
9382 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009383 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009384 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9385
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009386 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009387
Tobin Ehlis04356f92015-10-27 16:35:27 -06009388 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9390 "update array offset of 0 and update of "
9391 "5 descriptors oversteps total number "
9392 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009393
Tobin Ehlis04356f92015-10-27 16:35:27 -06009394 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9395 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9396 copy_ds_update.srcSet = descriptorSet;
9397 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009398 copy_ds_update.dstSet = descriptorSet;
9399 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009400 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009401 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9402
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009403 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009404
Chia-I Wuf7458c52015-10-26 21:10:41 +08009405 vkDestroySampler(m_device->device(), sampler, NULL);
9406 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9407 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009408}
9409
Karl Schultz6addd812016-02-02 17:17:23 -07009410TEST_F(VkLayerTest, NumSamplesMismatch) {
9411 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9412 // sampleCount
9413 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009414
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009416
Tobin Ehlis3b780662015-05-28 12:11:26 -06009417 ASSERT_NO_FATAL_FAILURE(InitState());
9418 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009419 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009420 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009421 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009422
9423 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009424 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9425 ds_pool_ci.pNext = NULL;
9426 ds_pool_ci.maxSets = 1;
9427 ds_pool_ci.poolSizeCount = 1;
9428 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009429
Tobin Ehlis3b780662015-05-28 12:11:26 -06009430 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009431 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009432 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009433
Tony Barboureb254902015-07-15 12:50:33 -06009434 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009435 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009436 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009437 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009438 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9439 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009440
Tony Barboureb254902015-07-15 12:50:33 -06009441 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9442 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9443 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009444 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009445 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009446
Tobin Ehlis3b780662015-05-28 12:11:26 -06009447 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009448 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009449 ASSERT_VK_SUCCESS(err);
9450
9451 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009452 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009453 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009454 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009455 alloc_info.descriptorPool = ds_pool;
9456 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009457 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009458 ASSERT_VK_SUCCESS(err);
9459
Tony Barboureb254902015-07-15 12:50:33 -06009460 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009461 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009462 pipe_ms_state_ci.pNext = NULL;
9463 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9464 pipe_ms_state_ci.sampleShadingEnable = 0;
9465 pipe_ms_state_ci.minSampleShading = 1.0;
9466 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009467
Tony Barboureb254902015-07-15 12:50:33 -06009468 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009469 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9470 pipeline_layout_ci.pNext = NULL;
9471 pipeline_layout_ci.setLayoutCount = 1;
9472 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009473
9474 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009475 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009476 ASSERT_VK_SUCCESS(err);
9477
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009478 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9479 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9480 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009481 VkPipelineObj pipe(m_device);
9482 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009483 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009484 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009485 pipe.SetMSAA(&pipe_ms_state_ci);
9486 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009487
Tony Barbourfe3351b2015-07-28 10:17:20 -06009488 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009489 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009490
Mark Young29927482016-05-04 14:38:51 -06009491 // Render triangle (the error should trigger on the attempt to draw).
9492 Draw(3, 1, 0, 0);
9493
9494 // Finalize recording of the command buffer
9495 EndCommandBuffer();
9496
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009497 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009498
Chia-I Wuf7458c52015-10-26 21:10:41 +08009499 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9500 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9501 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009502}
Mark Young29927482016-05-04 14:38:51 -06009503
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009504TEST_F(VkLayerTest, RenderPassIncompatible) {
9505 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9506 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009507 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009508 VkResult err;
9509
9510 ASSERT_NO_FATAL_FAILURE(InitState());
9511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9512
9513 VkDescriptorSetLayoutBinding dsl_binding = {};
9514 dsl_binding.binding = 0;
9515 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9516 dsl_binding.descriptorCount = 1;
9517 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9518 dsl_binding.pImmutableSamplers = NULL;
9519
9520 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9521 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9522 ds_layout_ci.pNext = NULL;
9523 ds_layout_ci.bindingCount = 1;
9524 ds_layout_ci.pBindings = &dsl_binding;
9525
9526 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009527 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009528 ASSERT_VK_SUCCESS(err);
9529
9530 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9531 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9532 pipeline_layout_ci.pNext = NULL;
9533 pipeline_layout_ci.setLayoutCount = 1;
9534 pipeline_layout_ci.pSetLayouts = &ds_layout;
9535
9536 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009537 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009538 ASSERT_VK_SUCCESS(err);
9539
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009540 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9541 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9542 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009543 // Create a renderpass that will be incompatible with default renderpass
9544 VkAttachmentReference attach = {};
9545 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9546 VkAttachmentReference color_att = {};
9547 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9548 VkSubpassDescription subpass = {};
9549 subpass.inputAttachmentCount = 1;
9550 subpass.pInputAttachments = &attach;
9551 subpass.colorAttachmentCount = 1;
9552 subpass.pColorAttachments = &color_att;
9553 VkRenderPassCreateInfo rpci = {};
9554 rpci.subpassCount = 1;
9555 rpci.pSubpasses = &subpass;
9556 rpci.attachmentCount = 1;
9557 VkAttachmentDescription attach_desc = {};
9558 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009559 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9560 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009561 rpci.pAttachments = &attach_desc;
9562 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9563 VkRenderPass rp;
9564 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9565 VkPipelineObj pipe(m_device);
9566 pipe.AddShader(&vs);
9567 pipe.AddShader(&fs);
9568 pipe.AddColorAttachment();
9569 VkViewport view_port = {};
9570 m_viewports.push_back(view_port);
9571 pipe.SetViewport(m_viewports);
9572 VkRect2D rect = {};
9573 m_scissors.push_back(rect);
9574 pipe.SetScissor(m_scissors);
9575 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9576
9577 VkCommandBufferInheritanceInfo cbii = {};
9578 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9579 cbii.renderPass = rp;
9580 cbii.subpass = 0;
9581 VkCommandBufferBeginInfo cbbi = {};
9582 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9583 cbbi.pInheritanceInfo = &cbii;
9584 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9585 VkRenderPassBeginInfo rpbi = {};
9586 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9587 rpbi.framebuffer = m_framebuffer;
9588 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009589 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9590 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009591
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009593 // Render triangle (the error should trigger on the attempt to draw).
9594 Draw(3, 1, 0, 0);
9595
9596 // Finalize recording of the command buffer
9597 EndCommandBuffer();
9598
9599 m_errorMonitor->VerifyFound();
9600
9601 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9602 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9603 vkDestroyRenderPass(m_device->device(), rp, NULL);
9604}
9605
Mark Youngc89c6312016-03-31 16:03:20 -06009606TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9607 // Create Pipeline where the number of blend attachments doesn't match the
9608 // number of color attachments. In this case, we don't add any color
9609 // blend attachments even though we have a color attachment.
9610 VkResult err;
9611
9612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009613 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009614
9615 ASSERT_NO_FATAL_FAILURE(InitState());
9616 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9617 VkDescriptorPoolSize ds_type_count = {};
9618 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9619 ds_type_count.descriptorCount = 1;
9620
9621 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9622 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9623 ds_pool_ci.pNext = NULL;
9624 ds_pool_ci.maxSets = 1;
9625 ds_pool_ci.poolSizeCount = 1;
9626 ds_pool_ci.pPoolSizes = &ds_type_count;
9627
9628 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009629 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009630 ASSERT_VK_SUCCESS(err);
9631
9632 VkDescriptorSetLayoutBinding dsl_binding = {};
9633 dsl_binding.binding = 0;
9634 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9635 dsl_binding.descriptorCount = 1;
9636 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9637 dsl_binding.pImmutableSamplers = NULL;
9638
9639 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9640 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9641 ds_layout_ci.pNext = NULL;
9642 ds_layout_ci.bindingCount = 1;
9643 ds_layout_ci.pBindings = &dsl_binding;
9644
9645 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009646 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009647 ASSERT_VK_SUCCESS(err);
9648
9649 VkDescriptorSet descriptorSet;
9650 VkDescriptorSetAllocateInfo alloc_info = {};
9651 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9652 alloc_info.descriptorSetCount = 1;
9653 alloc_info.descriptorPool = ds_pool;
9654 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009655 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009656 ASSERT_VK_SUCCESS(err);
9657
9658 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009659 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009660 pipe_ms_state_ci.pNext = NULL;
9661 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9662 pipe_ms_state_ci.sampleShadingEnable = 0;
9663 pipe_ms_state_ci.minSampleShading = 1.0;
9664 pipe_ms_state_ci.pSampleMask = NULL;
9665
9666 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9667 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9668 pipeline_layout_ci.pNext = NULL;
9669 pipeline_layout_ci.setLayoutCount = 1;
9670 pipeline_layout_ci.pSetLayouts = &ds_layout;
9671
9672 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009673 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009674 ASSERT_VK_SUCCESS(err);
9675
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009676 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9677 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9678 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009679 VkPipelineObj pipe(m_device);
9680 pipe.AddShader(&vs);
9681 pipe.AddShader(&fs);
9682 pipe.SetMSAA(&pipe_ms_state_ci);
9683 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9684
9685 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009686 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009687
Mark Young29927482016-05-04 14:38:51 -06009688 // Render triangle (the error should trigger on the attempt to draw).
9689 Draw(3, 1, 0, 0);
9690
9691 // Finalize recording of the command buffer
9692 EndCommandBuffer();
9693
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009694 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009695
9696 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9697 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9698 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9699}
Mark Young29927482016-05-04 14:38:51 -06009700
Mark Muellerd4914412016-06-13 17:52:06 -06009701TEST_F(VkLayerTest, MissingClearAttachment) {
9702 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9703 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009704 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009706 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009707
9708 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9709 m_errorMonitor->VerifyFound();
9710}
9711
Karl Schultz6addd812016-02-02 17:17:23 -07009712TEST_F(VkLayerTest, ClearCmdNoDraw) {
9713 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9714 // to issuing a Draw
9715 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009716
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009718 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009719
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009720 ASSERT_NO_FATAL_FAILURE(InitState());
9721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009722
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009723 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009724 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9725 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009726
9727 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009728 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9729 ds_pool_ci.pNext = NULL;
9730 ds_pool_ci.maxSets = 1;
9731 ds_pool_ci.poolSizeCount = 1;
9732 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009733
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009734 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009735 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009736 ASSERT_VK_SUCCESS(err);
9737
Tony Barboureb254902015-07-15 12:50:33 -06009738 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009739 dsl_binding.binding = 0;
9740 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9741 dsl_binding.descriptorCount = 1;
9742 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9743 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009744
Tony Barboureb254902015-07-15 12:50:33 -06009745 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009746 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9747 ds_layout_ci.pNext = NULL;
9748 ds_layout_ci.bindingCount = 1;
9749 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009750
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009751 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009752 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009753 ASSERT_VK_SUCCESS(err);
9754
9755 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009756 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009757 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009758 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009759 alloc_info.descriptorPool = ds_pool;
9760 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009761 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009762 ASSERT_VK_SUCCESS(err);
9763
Tony Barboureb254902015-07-15 12:50:33 -06009764 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009765 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009766 pipe_ms_state_ci.pNext = NULL;
9767 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9768 pipe_ms_state_ci.sampleShadingEnable = 0;
9769 pipe_ms_state_ci.minSampleShading = 1.0;
9770 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009771
Tony Barboureb254902015-07-15 12:50:33 -06009772 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009773 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9774 pipeline_layout_ci.pNext = NULL;
9775 pipeline_layout_ci.setLayoutCount = 1;
9776 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009777
9778 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009779 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009780 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009781
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009782 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009783 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009784 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009785 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009786
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009787 VkPipelineObj pipe(m_device);
9788 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009789 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009790 pipe.SetMSAA(&pipe_ms_state_ci);
9791 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009792
9793 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009794
Karl Schultz6addd812016-02-02 17:17:23 -07009795 // Main thing we care about for this test is that the VkImage obj we're
9796 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009797 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009798 VkClearAttachment color_attachment;
9799 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9800 color_attachment.clearValue.color.float32[0] = 1.0;
9801 color_attachment.clearValue.color.float32[1] = 1.0;
9802 color_attachment.clearValue.color.float32[2] = 1.0;
9803 color_attachment.clearValue.color.float32[3] = 1.0;
9804 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009805 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009806
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009807 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009808
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009809 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009810
Chia-I Wuf7458c52015-10-26 21:10:41 +08009811 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9812 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9813 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009814}
9815
Karl Schultz6addd812016-02-02 17:17:23 -07009816TEST_F(VkLayerTest, VtxBufferBadIndex) {
9817 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009818
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9820 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009821
Tobin Ehlis502480b2015-06-24 15:53:07 -06009822 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009823 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009824 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009825
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009826 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009827 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9828 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009829
9830 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009831 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9832 ds_pool_ci.pNext = NULL;
9833 ds_pool_ci.maxSets = 1;
9834 ds_pool_ci.poolSizeCount = 1;
9835 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009836
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009837 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009838 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009839 ASSERT_VK_SUCCESS(err);
9840
Tony Barboureb254902015-07-15 12:50:33 -06009841 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009842 dsl_binding.binding = 0;
9843 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9844 dsl_binding.descriptorCount = 1;
9845 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9846 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009847
Tony Barboureb254902015-07-15 12:50:33 -06009848 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009849 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9850 ds_layout_ci.pNext = NULL;
9851 ds_layout_ci.bindingCount = 1;
9852 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009853
Tobin Ehlis502480b2015-06-24 15:53:07 -06009854 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009855 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009856 ASSERT_VK_SUCCESS(err);
9857
9858 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009859 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009860 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009861 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009862 alloc_info.descriptorPool = ds_pool;
9863 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009864 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009865 ASSERT_VK_SUCCESS(err);
9866
Tony Barboureb254902015-07-15 12:50:33 -06009867 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009868 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009869 pipe_ms_state_ci.pNext = NULL;
9870 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9871 pipe_ms_state_ci.sampleShadingEnable = 0;
9872 pipe_ms_state_ci.minSampleShading = 1.0;
9873 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009874
Tony Barboureb254902015-07-15 12:50:33 -06009875 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009876 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9877 pipeline_layout_ci.pNext = NULL;
9878 pipeline_layout_ci.setLayoutCount = 1;
9879 pipeline_layout_ci.pSetLayouts = &ds_layout;
9880 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009881
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009882 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009883 ASSERT_VK_SUCCESS(err);
9884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009885 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9886 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9887 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009888 VkPipelineObj pipe(m_device);
9889 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009890 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009891 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009892 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009893 pipe.SetViewport(m_viewports);
9894 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009895 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009896
9897 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009898 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009899 // Don't care about actual data, just need to get to draw to flag error
9900 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009901 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009902 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009903 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009904
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009905 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009906
Chia-I Wuf7458c52015-10-26 21:10:41 +08009907 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9908 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9909 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009910}
Mark Muellerdfe37552016-07-07 14:47:42 -06009911
Mark Mueller2ee294f2016-08-04 12:59:48 -06009912TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
9913 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
9914 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -06009915 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -06009916
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009917 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
9918 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009919
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009920 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
9921 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009922
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009923 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009924
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -06009926 // The following test fails with recent NVidia drivers.
9927 // By the time core_validation is reached, the NVidia
9928 // driver has sanitized the invalid condition and core_validation
9929 // is not introduced to the failure condition. This is not the case
9930 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009931 // uint32_t count = static_cast<uint32_t>(~0);
9932 // VkPhysicalDevice physical_device;
9933 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
9934 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -06009935
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009937 float queue_priority = 0.0;
9938
9939 VkDeviceQueueCreateInfo queue_create_info = {};
9940 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
9941 queue_create_info.queueCount = 1;
9942 queue_create_info.pQueuePriorities = &queue_priority;
9943 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
9944
9945 VkPhysicalDeviceFeatures features = m_device->phy().features();
9946 VkDevice testDevice;
9947 VkDeviceCreateInfo device_create_info = {};
9948 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
9949 device_create_info.queueCreateInfoCount = 1;
9950 device_create_info.pQueueCreateInfos = &queue_create_info;
9951 device_create_info.pEnabledFeatures = &features;
9952 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9953 m_errorMonitor->VerifyFound();
9954
9955 queue_create_info.queueFamilyIndex = 1;
9956
9957 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
9958 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
9959 for (unsigned i = 0; i < feature_count; i++) {
9960 if (VK_FALSE == feature_array[i]) {
9961 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009963 device_create_info.pEnabledFeatures = &features;
9964 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9965 m_errorMonitor->VerifyFound();
9966 break;
9967 }
9968 }
9969}
9970
9971TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
9972 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
9973 "End a command buffer with a query still in progress.");
9974
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009975 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
9976 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
9977 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009979 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009980
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009982
9983 ASSERT_NO_FATAL_FAILURE(InitState());
9984
9985 VkEvent event;
9986 VkEventCreateInfo event_create_info{};
9987 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9988 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9989
Mark Mueller2ee294f2016-08-04 12:59:48 -06009990 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009991 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009992
9993 BeginCommandBuffer();
9994
9995 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009996 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 -06009997 ASSERT_TRUE(image.initialized());
9998 VkImageMemoryBarrier img_barrier = {};
9999 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10000 img_barrier.pNext = NULL;
10001 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10002 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10003 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10004 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10005 img_barrier.image = image.handle();
10006 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010007
10008 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10009 // that layer validation catches the case when it is not.
10010 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010011 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10012 img_barrier.subresourceRange.baseArrayLayer = 0;
10013 img_barrier.subresourceRange.baseMipLevel = 0;
10014 img_barrier.subresourceRange.layerCount = 1;
10015 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010016 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10017 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010018 m_errorMonitor->VerifyFound();
10019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010021
10022 VkQueryPool query_pool;
10023 VkQueryPoolCreateInfo query_pool_create_info = {};
10024 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10025 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10026 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010027 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010028
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010029 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010030 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10031
10032 vkEndCommandBuffer(m_commandBuffer->handle());
10033 m_errorMonitor->VerifyFound();
10034
10035 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10036 vkDestroyEvent(m_device->device(), event, nullptr);
10037}
10038
Mark Muellerdfe37552016-07-07 14:47:42 -060010039TEST_F(VkLayerTest, VertexBufferInvalid) {
10040 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10041 "delete a buffer twice, use an invalid offset for each "
10042 "buffer type, and attempt to bind a null buffer");
10043
10044 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10045 "using deleted buffer ";
10046 const char *double_destroy_message = "Cannot free buffer 0x";
10047 const char *invalid_offset_message = "vkBindBufferMemory(): "
10048 "memoryOffset is 0x";
10049 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10050 "storage memoryOffset "
10051 "is 0x";
10052 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10053 "texel memoryOffset "
10054 "is 0x";
10055 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10056 "uniform memoryOffset "
10057 "is 0x";
10058 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
10059 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -060010060 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010061
10062 ASSERT_NO_FATAL_FAILURE(InitState());
10063 ASSERT_NO_FATAL_FAILURE(InitViewport());
10064 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10065
10066 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010067 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010068 pipe_ms_state_ci.pNext = NULL;
10069 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10070 pipe_ms_state_ci.sampleShadingEnable = 0;
10071 pipe_ms_state_ci.minSampleShading = 1.0;
10072 pipe_ms_state_ci.pSampleMask = nullptr;
10073
10074 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10075 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10076 VkPipelineLayout pipeline_layout;
10077
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010078 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010079 ASSERT_VK_SUCCESS(err);
10080
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010081 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10082 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010083 VkPipelineObj pipe(m_device);
10084 pipe.AddShader(&vs);
10085 pipe.AddShader(&fs);
10086 pipe.AddColorAttachment();
10087 pipe.SetMSAA(&pipe_ms_state_ci);
10088 pipe.SetViewport(m_viewports);
10089 pipe.SetScissor(m_scissors);
10090 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10091
10092 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010093 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010094
10095 {
10096 // Create and bind a vertex buffer in a reduced scope, which will cause
10097 // it to be deleted upon leaving this scope
10098 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010099 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010100 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10101 draw_verticies.AddVertexInputToPipe(pipe);
10102 }
10103
10104 Draw(1, 0, 0, 0);
10105
10106 EndCommandBuffer();
10107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010109 QueueCommandBuffer(false);
10110 m_errorMonitor->VerifyFound();
10111
10112 {
10113 // Create and bind a vertex buffer in a reduced scope, and delete it
10114 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010115 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010117 buffer_test.TestDoubleDestroy();
10118 }
10119 m_errorMonitor->VerifyFound();
10120
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010121 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010122 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10124 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10125 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010126 m_errorMonitor->VerifyFound();
10127 }
10128
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010129 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10130 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010131 // Create and bind a memory buffer with an invalid offset again,
10132 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10134 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10135 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010136 m_errorMonitor->VerifyFound();
10137 }
10138
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010139 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010140 // Create and bind a memory buffer with an invalid offset again, but
10141 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10143 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10144 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010145 m_errorMonitor->VerifyFound();
10146 }
10147
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010148 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010149 // Create and bind a memory buffer with an invalid offset again, but
10150 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10152 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10153 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010154 m_errorMonitor->VerifyFound();
10155 }
10156
10157 {
10158 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10160 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10161 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010162 m_errorMonitor->VerifyFound();
10163 }
10164
10165 {
10166 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10168 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10169 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010170 }
10171 m_errorMonitor->VerifyFound();
10172
10173 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10174}
10175
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010176// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10177TEST_F(VkLayerTest, InvalidImageLayout) {
10178 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010179 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10180 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010181 // 3 in ValidateCmdBufImageLayouts
10182 // * -1 Attempt to submit cmd buf w/ deleted image
10183 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10184 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10186 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010187
10188 ASSERT_NO_FATAL_FAILURE(InitState());
10189 // Create src & dst images to use for copy operations
10190 VkImage src_image;
10191 VkImage dst_image;
10192
10193 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10194 const int32_t tex_width = 32;
10195 const int32_t tex_height = 32;
10196
10197 VkImageCreateInfo image_create_info = {};
10198 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10199 image_create_info.pNext = NULL;
10200 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10201 image_create_info.format = tex_format;
10202 image_create_info.extent.width = tex_width;
10203 image_create_info.extent.height = tex_height;
10204 image_create_info.extent.depth = 1;
10205 image_create_info.mipLevels = 1;
10206 image_create_info.arrayLayers = 4;
10207 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10208 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10209 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10210 image_create_info.flags = 0;
10211
10212 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10213 ASSERT_VK_SUCCESS(err);
10214 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10215 ASSERT_VK_SUCCESS(err);
10216
10217 BeginCommandBuffer();
10218 VkImageCopy copyRegion;
10219 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10220 copyRegion.srcSubresource.mipLevel = 0;
10221 copyRegion.srcSubresource.baseArrayLayer = 0;
10222 copyRegion.srcSubresource.layerCount = 1;
10223 copyRegion.srcOffset.x = 0;
10224 copyRegion.srcOffset.y = 0;
10225 copyRegion.srcOffset.z = 0;
10226 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10227 copyRegion.dstSubresource.mipLevel = 0;
10228 copyRegion.dstSubresource.baseArrayLayer = 0;
10229 copyRegion.dstSubresource.layerCount = 1;
10230 copyRegion.dstOffset.x = 0;
10231 copyRegion.dstOffset.y = 0;
10232 copyRegion.dstOffset.z = 0;
10233 copyRegion.extent.width = 1;
10234 copyRegion.extent.height = 1;
10235 copyRegion.extent.depth = 1;
10236 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10237 m_errorMonitor->VerifyFound();
10238 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10240 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10241 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010242 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10243 m_errorMonitor->VerifyFound();
10244 // Final src error is due to bad layout type
10245 m_errorMonitor->SetDesiredFailureMsg(
10246 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10247 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10248 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10249 m_errorMonitor->VerifyFound();
10250 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10252 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010253 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10254 m_errorMonitor->VerifyFound();
10255 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10257 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10258 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010259 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10260 m_errorMonitor->VerifyFound();
10261 m_errorMonitor->SetDesiredFailureMsg(
10262 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10263 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10264 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10265 m_errorMonitor->VerifyFound();
10266 // Now cause error due to bad image layout transition in PipelineBarrier
10267 VkImageMemoryBarrier image_barrier[1] = {};
10268 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10269 image_barrier[0].image = src_image;
10270 image_barrier[0].subresourceRange.layerCount = 2;
10271 image_barrier[0].subresourceRange.levelCount = 2;
10272 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10274 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10275 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10276 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10277 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010278 m_errorMonitor->VerifyFound();
10279
10280 // Finally some layout errors at RenderPass create time
10281 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10282 VkAttachmentReference attach = {};
10283 // perf warning for GENERAL layout w/ non-DS input attachment
10284 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10285 VkSubpassDescription subpass = {};
10286 subpass.inputAttachmentCount = 1;
10287 subpass.pInputAttachments = &attach;
10288 VkRenderPassCreateInfo rpci = {};
10289 rpci.subpassCount = 1;
10290 rpci.pSubpasses = &subpass;
10291 rpci.attachmentCount = 1;
10292 VkAttachmentDescription attach_desc = {};
10293 attach_desc.format = VK_FORMAT_UNDEFINED;
10294 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010295 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010296 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10298 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010299 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10300 m_errorMonitor->VerifyFound();
10301 // error w/ non-general layout
10302 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10303
10304 m_errorMonitor->SetDesiredFailureMsg(
10305 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10306 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10307 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10308 m_errorMonitor->VerifyFound();
10309 subpass.inputAttachmentCount = 0;
10310 subpass.colorAttachmentCount = 1;
10311 subpass.pColorAttachments = &attach;
10312 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10313 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10315 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010316 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10317 m_errorMonitor->VerifyFound();
10318 // error w/ non-color opt or GENERAL layout for color attachment
10319 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10320 m_errorMonitor->SetDesiredFailureMsg(
10321 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10322 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10323 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10324 m_errorMonitor->VerifyFound();
10325 subpass.colorAttachmentCount = 0;
10326 subpass.pDepthStencilAttachment = &attach;
10327 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10328 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10330 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010331 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10332 m_errorMonitor->VerifyFound();
10333 // error w/ non-ds opt or GENERAL layout for color attachment
10334 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10336 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10337 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010338 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10339 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010340 // For this error we need a valid renderpass so create default one
10341 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10342 attach.attachment = 0;
10343 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10344 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10345 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10346 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10347 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10348 // Can't do a CLEAR load on READ_ONLY initialLayout
10349 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10350 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10351 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10353 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10354 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010355 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10356 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010357
10358 vkDestroyImage(m_device->device(), src_image, NULL);
10359 vkDestroyImage(m_device->device(), dst_image, NULL);
10360}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010361
Tobin Ehlise0936662016-10-11 08:10:51 -060010362TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10363 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10364 VkResult err;
10365
10366 ASSERT_NO_FATAL_FAILURE(InitState());
10367
10368 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10369 VkImageTiling tiling;
10370 VkFormatProperties format_properties;
10371 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10372 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10373 tiling = VK_IMAGE_TILING_LINEAR;
10374 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10375 tiling = VK_IMAGE_TILING_OPTIMAL;
10376 } else {
10377 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10378 "skipped.\n");
10379 return;
10380 }
10381
10382 VkDescriptorPoolSize ds_type = {};
10383 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10384 ds_type.descriptorCount = 1;
10385
10386 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10387 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10388 ds_pool_ci.maxSets = 1;
10389 ds_pool_ci.poolSizeCount = 1;
10390 ds_pool_ci.pPoolSizes = &ds_type;
10391 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10392
10393 VkDescriptorPool ds_pool;
10394 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10395 ASSERT_VK_SUCCESS(err);
10396
10397 VkDescriptorSetLayoutBinding dsl_binding = {};
10398 dsl_binding.binding = 0;
10399 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10400 dsl_binding.descriptorCount = 1;
10401 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10402 dsl_binding.pImmutableSamplers = NULL;
10403
10404 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10405 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10406 ds_layout_ci.pNext = NULL;
10407 ds_layout_ci.bindingCount = 1;
10408 ds_layout_ci.pBindings = &dsl_binding;
10409
10410 VkDescriptorSetLayout ds_layout;
10411 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10412 ASSERT_VK_SUCCESS(err);
10413
10414 VkDescriptorSetAllocateInfo alloc_info = {};
10415 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10416 alloc_info.descriptorSetCount = 1;
10417 alloc_info.descriptorPool = ds_pool;
10418 alloc_info.pSetLayouts = &ds_layout;
10419 VkDescriptorSet descriptor_set;
10420 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10421 ASSERT_VK_SUCCESS(err);
10422
10423 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10424 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10425 pipeline_layout_ci.pNext = NULL;
10426 pipeline_layout_ci.setLayoutCount = 1;
10427 pipeline_layout_ci.pSetLayouts = &ds_layout;
10428 VkPipelineLayout pipeline_layout;
10429 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10430 ASSERT_VK_SUCCESS(err);
10431
10432 VkImageObj image(m_device);
10433 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10434 ASSERT_TRUE(image.initialized());
10435 VkImageView view = image.targetView(tex_format);
10436
10437 VkDescriptorImageInfo image_info = {};
10438 image_info.imageView = view;
10439 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10440
10441 VkWriteDescriptorSet descriptor_write = {};
10442 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10443 descriptor_write.dstSet = descriptor_set;
10444 descriptor_write.dstBinding = 0;
10445 descriptor_write.descriptorCount = 1;
10446 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10447 descriptor_write.pImageInfo = &image_info;
10448
10449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10450 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10451 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10452 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10453 m_errorMonitor->VerifyFound();
10454
10455 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10456 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10457 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10458 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10459}
10460
Mark Mueller93b938f2016-08-18 10:27:40 -060010461TEST_F(VkLayerTest, SimultaneousUse) {
10462 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10463 "in primary and secondary command buffers.");
10464
10465 ASSERT_NO_FATAL_FAILURE(InitState());
10466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10467
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010468 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010469 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10470 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010471
10472 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010473 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010474 command_buffer_allocate_info.commandPool = m_commandPool;
10475 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10476 command_buffer_allocate_info.commandBufferCount = 1;
10477
10478 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010479 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010480 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10481 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010482 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010483 command_buffer_inheritance_info.renderPass = m_renderPass;
10484 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10485 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010486 command_buffer_begin_info.flags =
10487 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010488 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10489
10490 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010491 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10492 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010493 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010494 vkEndCommandBuffer(secondary_command_buffer);
10495
Mark Mueller93b938f2016-08-18 10:27:40 -060010496 VkSubmitInfo submit_info = {};
10497 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10498 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010499 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010500 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010501
Mark Mueller4042b652016-09-05 22:52:21 -060010502 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010503 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10505 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010506 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010507 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10508 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010509
10510 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010511 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10512
Mark Mueller4042b652016-09-05 22:52:21 -060010513 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010514 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010515 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010516
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10518 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010519 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010520 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10521 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010522}
10523
Mark Mueller917f6bc2016-08-30 10:57:19 -060010524TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10525 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10526 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010527 "Delete objects that are inuse. Call VkQueueSubmit "
10528 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010529
10530 ASSERT_NO_FATAL_FAILURE(InitState());
10531 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10532
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010533 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10534 const char *cannot_delete_event_message = "Cannot delete event 0x";
10535 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10536 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010537
10538 BeginCommandBuffer();
10539
10540 VkEvent event;
10541 VkEventCreateInfo event_create_info = {};
10542 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10543 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010544 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010545
Mark Muellerc8d441e2016-08-23 17:36:00 -060010546 EndCommandBuffer();
10547 vkDestroyEvent(m_device->device(), event, nullptr);
10548
10549 VkSubmitInfo submit_info = {};
10550 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10551 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010552 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010554 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10555 m_errorMonitor->VerifyFound();
10556
10557 m_errorMonitor->SetDesiredFailureMsg(0, "");
10558 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10559
10560 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10561
Mark Mueller917f6bc2016-08-30 10:57:19 -060010562 VkSemaphoreCreateInfo semaphore_create_info = {};
10563 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10564 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010565 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010566 VkFenceCreateInfo fence_create_info = {};
10567 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10568 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010569 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010570
10571 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010572 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010573 descriptor_pool_type_count.descriptorCount = 1;
10574
10575 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10576 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10577 descriptor_pool_create_info.maxSets = 1;
10578 descriptor_pool_create_info.poolSizeCount = 1;
10579 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010580 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010581
10582 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010583 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010584
10585 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010586 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010587 descriptorset_layout_binding.descriptorCount = 1;
10588 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10589
10590 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010591 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010592 descriptorset_layout_create_info.bindingCount = 1;
10593 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10594
10595 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010596 ASSERT_VK_SUCCESS(
10597 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010598
10599 VkDescriptorSet descriptorset;
10600 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010601 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010602 descriptorset_allocate_info.descriptorSetCount = 1;
10603 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10604 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010605 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010606
Mark Mueller4042b652016-09-05 22:52:21 -060010607 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10608
10609 VkDescriptorBufferInfo buffer_info = {};
10610 buffer_info.buffer = buffer_test.GetBuffer();
10611 buffer_info.offset = 0;
10612 buffer_info.range = 1024;
10613
10614 VkWriteDescriptorSet write_descriptor_set = {};
10615 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10616 write_descriptor_set.dstSet = descriptorset;
10617 write_descriptor_set.descriptorCount = 1;
10618 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10619 write_descriptor_set.pBufferInfo = &buffer_info;
10620
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010621 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010623 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10624 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010625
10626 VkPipelineObj pipe(m_device);
10627 pipe.AddColorAttachment();
10628 pipe.AddShader(&vs);
10629 pipe.AddShader(&fs);
10630
10631 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010632 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010633 pipeline_layout_create_info.setLayoutCount = 1;
10634 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10635
10636 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010637 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010638
10639 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10640
Mark Muellerc8d441e2016-08-23 17:36:00 -060010641 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010642 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010643
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010644 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10645 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10646 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010647
Mark Muellerc8d441e2016-08-23 17:36:00 -060010648 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010649
Mark Mueller917f6bc2016-08-30 10:57:19 -060010650 submit_info.signalSemaphoreCount = 1;
10651 submit_info.pSignalSemaphores = &semaphore;
10652 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010653
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010655 vkDestroyEvent(m_device->device(), event, nullptr);
10656 m_errorMonitor->VerifyFound();
10657
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010659 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10660 m_errorMonitor->VerifyFound();
10661
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010663 vkDestroyFence(m_device->device(), fence, nullptr);
10664 m_errorMonitor->VerifyFound();
10665
Tobin Ehlis122207b2016-09-01 08:50:06 -070010666 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010667 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10668 vkDestroyFence(m_device->device(), fence, nullptr);
10669 vkDestroyEvent(m_device->device(), event, nullptr);
10670 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010671 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010672 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10673}
10674
Tobin Ehlis2adda372016-09-01 08:51:06 -070010675TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10676 TEST_DESCRIPTION("Delete in-use query pool.");
10677
10678 ASSERT_NO_FATAL_FAILURE(InitState());
10679 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10680
10681 VkQueryPool query_pool;
10682 VkQueryPoolCreateInfo query_pool_ci{};
10683 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10684 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10685 query_pool_ci.queryCount = 1;
10686 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10687 BeginCommandBuffer();
10688 // Reset query pool to create binding with cmd buffer
10689 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10690
10691 EndCommandBuffer();
10692
10693 VkSubmitInfo submit_info = {};
10694 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10695 submit_info.commandBufferCount = 1;
10696 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10697 // Submit cmd buffer and then destroy query pool while in-flight
10698 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10699
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010701 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10702 m_errorMonitor->VerifyFound();
10703
10704 vkQueueWaitIdle(m_device->m_queue);
10705 // Now that cmd buffer done we can safely destroy query_pool
10706 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10707}
10708
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010709TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10710 TEST_DESCRIPTION("Delete in-use pipeline.");
10711
10712 ASSERT_NO_FATAL_FAILURE(InitState());
10713 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10714
10715 // Empty pipeline layout used for binding PSO
10716 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10717 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10718 pipeline_layout_ci.setLayoutCount = 0;
10719 pipeline_layout_ci.pSetLayouts = NULL;
10720
10721 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010722 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010723 ASSERT_VK_SUCCESS(err);
10724
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010726 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010727 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10728 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010729 // Store pipeline handle so we can actually delete it before test finishes
10730 VkPipeline delete_this_pipeline;
10731 { // Scope pipeline so it will be auto-deleted
10732 VkPipelineObj pipe(m_device);
10733 pipe.AddShader(&vs);
10734 pipe.AddShader(&fs);
10735 pipe.AddColorAttachment();
10736 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10737 delete_this_pipeline = pipe.handle();
10738
10739 BeginCommandBuffer();
10740 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010741 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010742
10743 EndCommandBuffer();
10744
10745 VkSubmitInfo submit_info = {};
10746 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10747 submit_info.commandBufferCount = 1;
10748 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10749 // Submit cmd buffer and then pipeline destroyed while in-flight
10750 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10751 } // Pipeline deletion triggered here
10752 m_errorMonitor->VerifyFound();
10753 // Make sure queue finished and then actually delete pipeline
10754 vkQueueWaitIdle(m_device->m_queue);
10755 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10756 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10757}
10758
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010759TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10760 TEST_DESCRIPTION("Delete in-use imageView.");
10761
10762 ASSERT_NO_FATAL_FAILURE(InitState());
10763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10764
10765 VkDescriptorPoolSize ds_type_count;
10766 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10767 ds_type_count.descriptorCount = 1;
10768
10769 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10770 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10771 ds_pool_ci.maxSets = 1;
10772 ds_pool_ci.poolSizeCount = 1;
10773 ds_pool_ci.pPoolSizes = &ds_type_count;
10774
10775 VkDescriptorPool ds_pool;
10776 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10777 ASSERT_VK_SUCCESS(err);
10778
10779 VkSamplerCreateInfo sampler_ci = {};
10780 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10781 sampler_ci.pNext = NULL;
10782 sampler_ci.magFilter = VK_FILTER_NEAREST;
10783 sampler_ci.minFilter = VK_FILTER_NEAREST;
10784 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10785 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10786 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10787 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10788 sampler_ci.mipLodBias = 1.0;
10789 sampler_ci.anisotropyEnable = VK_FALSE;
10790 sampler_ci.maxAnisotropy = 1;
10791 sampler_ci.compareEnable = VK_FALSE;
10792 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10793 sampler_ci.minLod = 1.0;
10794 sampler_ci.maxLod = 1.0;
10795 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10796 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10797 VkSampler sampler;
10798
10799 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10800 ASSERT_VK_SUCCESS(err);
10801
10802 VkDescriptorSetLayoutBinding layout_binding;
10803 layout_binding.binding = 0;
10804 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10805 layout_binding.descriptorCount = 1;
10806 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10807 layout_binding.pImmutableSamplers = NULL;
10808
10809 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10810 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10811 ds_layout_ci.bindingCount = 1;
10812 ds_layout_ci.pBindings = &layout_binding;
10813 VkDescriptorSetLayout ds_layout;
10814 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10815 ASSERT_VK_SUCCESS(err);
10816
10817 VkDescriptorSetAllocateInfo alloc_info = {};
10818 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10819 alloc_info.descriptorSetCount = 1;
10820 alloc_info.descriptorPool = ds_pool;
10821 alloc_info.pSetLayouts = &ds_layout;
10822 VkDescriptorSet descriptor_set;
10823 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10824 ASSERT_VK_SUCCESS(err);
10825
10826 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10827 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10828 pipeline_layout_ci.pNext = NULL;
10829 pipeline_layout_ci.setLayoutCount = 1;
10830 pipeline_layout_ci.pSetLayouts = &ds_layout;
10831
10832 VkPipelineLayout pipeline_layout;
10833 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10834 ASSERT_VK_SUCCESS(err);
10835
10836 VkImageObj image(m_device);
10837 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
10838 ASSERT_TRUE(image.initialized());
10839
10840 VkImageView view;
10841 VkImageViewCreateInfo ivci = {};
10842 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10843 ivci.image = image.handle();
10844 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10845 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
10846 ivci.subresourceRange.layerCount = 1;
10847 ivci.subresourceRange.baseMipLevel = 0;
10848 ivci.subresourceRange.levelCount = 1;
10849 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10850
10851 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
10852 ASSERT_VK_SUCCESS(err);
10853
10854 VkDescriptorImageInfo image_info{};
10855 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10856 image_info.imageView = view;
10857 image_info.sampler = sampler;
10858
10859 VkWriteDescriptorSet descriptor_write = {};
10860 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10861 descriptor_write.dstSet = descriptor_set;
10862 descriptor_write.dstBinding = 0;
10863 descriptor_write.descriptorCount = 1;
10864 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10865 descriptor_write.pImageInfo = &image_info;
10866
10867 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10868
10869 // Create PSO to use the sampler
10870 char const *vsSource = "#version 450\n"
10871 "\n"
10872 "out gl_PerVertex { \n"
10873 " vec4 gl_Position;\n"
10874 "};\n"
10875 "void main(){\n"
10876 " gl_Position = vec4(1);\n"
10877 "}\n";
10878 char const *fsSource = "#version 450\n"
10879 "\n"
10880 "layout(set=0, binding=0) uniform sampler2D s;\n"
10881 "layout(location=0) out vec4 x;\n"
10882 "void main(){\n"
10883 " x = texture(s, vec2(1));\n"
10884 "}\n";
10885 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10886 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10887 VkPipelineObj pipe(m_device);
10888 pipe.AddShader(&vs);
10889 pipe.AddShader(&fs);
10890 pipe.AddColorAttachment();
10891 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10892
10893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
10894
10895 BeginCommandBuffer();
10896 // Bind pipeline to cmd buffer
10897 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10898 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10899 &descriptor_set, 0, nullptr);
10900 Draw(1, 0, 0, 0);
10901 EndCommandBuffer();
10902 // Submit cmd buffer then destroy sampler
10903 VkSubmitInfo submit_info = {};
10904 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10905 submit_info.commandBufferCount = 1;
10906 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10907 // Submit cmd buffer and then destroy imageView while in-flight
10908 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10909
10910 vkDestroyImageView(m_device->device(), view, nullptr);
10911 m_errorMonitor->VerifyFound();
10912 vkQueueWaitIdle(m_device->m_queue);
10913 // Now we can actually destroy imageView
10914 vkDestroyImageView(m_device->device(), view, NULL);
10915 vkDestroySampler(m_device->device(), sampler, nullptr);
10916 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10917 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10918 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10919}
10920
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060010921TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
10922 TEST_DESCRIPTION("Delete in-use bufferView.");
10923
10924 ASSERT_NO_FATAL_FAILURE(InitState());
10925 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10926
10927 VkDescriptorPoolSize ds_type_count;
10928 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10929 ds_type_count.descriptorCount = 1;
10930
10931 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10932 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10933 ds_pool_ci.maxSets = 1;
10934 ds_pool_ci.poolSizeCount = 1;
10935 ds_pool_ci.pPoolSizes = &ds_type_count;
10936
10937 VkDescriptorPool ds_pool;
10938 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10939 ASSERT_VK_SUCCESS(err);
10940
10941 VkDescriptorSetLayoutBinding layout_binding;
10942 layout_binding.binding = 0;
10943 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10944 layout_binding.descriptorCount = 1;
10945 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10946 layout_binding.pImmutableSamplers = NULL;
10947
10948 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10949 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10950 ds_layout_ci.bindingCount = 1;
10951 ds_layout_ci.pBindings = &layout_binding;
10952 VkDescriptorSetLayout ds_layout;
10953 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10954 ASSERT_VK_SUCCESS(err);
10955
10956 VkDescriptorSetAllocateInfo alloc_info = {};
10957 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10958 alloc_info.descriptorSetCount = 1;
10959 alloc_info.descriptorPool = ds_pool;
10960 alloc_info.pSetLayouts = &ds_layout;
10961 VkDescriptorSet descriptor_set;
10962 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10963 ASSERT_VK_SUCCESS(err);
10964
10965 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10966 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10967 pipeline_layout_ci.pNext = NULL;
10968 pipeline_layout_ci.setLayoutCount = 1;
10969 pipeline_layout_ci.pSetLayouts = &ds_layout;
10970
10971 VkPipelineLayout pipeline_layout;
10972 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10973 ASSERT_VK_SUCCESS(err);
10974
10975 VkBuffer buffer;
10976 uint32_t queue_family_index = 0;
10977 VkBufferCreateInfo buffer_create_info = {};
10978 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10979 buffer_create_info.size = 1024;
10980 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10981 buffer_create_info.queueFamilyIndexCount = 1;
10982 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
10983
10984 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
10985 ASSERT_VK_SUCCESS(err);
10986
10987 VkMemoryRequirements memory_reqs;
10988 VkDeviceMemory buffer_memory;
10989
10990 VkMemoryAllocateInfo memory_info = {};
10991 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10992 memory_info.allocationSize = 0;
10993 memory_info.memoryTypeIndex = 0;
10994
10995 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
10996 memory_info.allocationSize = memory_reqs.size;
10997 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
10998 ASSERT_TRUE(pass);
10999
11000 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11001 ASSERT_VK_SUCCESS(err);
11002 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11003 ASSERT_VK_SUCCESS(err);
11004
11005 VkBufferView view;
11006 VkBufferViewCreateInfo bvci = {};
11007 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11008 bvci.buffer = buffer;
11009 bvci.format = VK_FORMAT_R8_UNORM;
11010 bvci.range = VK_WHOLE_SIZE;
11011
11012 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11013 ASSERT_VK_SUCCESS(err);
11014
11015 VkWriteDescriptorSet descriptor_write = {};
11016 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11017 descriptor_write.dstSet = descriptor_set;
11018 descriptor_write.dstBinding = 0;
11019 descriptor_write.descriptorCount = 1;
11020 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11021 descriptor_write.pTexelBufferView = &view;
11022
11023 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11024
11025 char const *vsSource = "#version 450\n"
11026 "\n"
11027 "out gl_PerVertex { \n"
11028 " vec4 gl_Position;\n"
11029 "};\n"
11030 "void main(){\n"
11031 " gl_Position = vec4(1);\n"
11032 "}\n";
11033 char const *fsSource = "#version 450\n"
11034 "\n"
11035 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11036 "layout(location=0) out vec4 x;\n"
11037 "void main(){\n"
11038 " x = imageLoad(s, 0);\n"
11039 "}\n";
11040 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11041 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11042 VkPipelineObj pipe(m_device);
11043 pipe.AddShader(&vs);
11044 pipe.AddShader(&fs);
11045 pipe.AddColorAttachment();
11046 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11047
11048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11049
11050 BeginCommandBuffer();
11051 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11052 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11053 VkRect2D scissor = {{0, 0}, {16, 16}};
11054 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11055 // Bind pipeline to cmd buffer
11056 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11057 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11058 &descriptor_set, 0, nullptr);
11059 Draw(1, 0, 0, 0);
11060 EndCommandBuffer();
11061
11062 VkSubmitInfo submit_info = {};
11063 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11064 submit_info.commandBufferCount = 1;
11065 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11066 // Submit cmd buffer and then destroy bufferView while in-flight
11067 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11068
11069 vkDestroyBufferView(m_device->device(), view, nullptr);
11070 m_errorMonitor->VerifyFound();
11071 vkQueueWaitIdle(m_device->m_queue);
11072 // Now we can actually destroy bufferView
11073 vkDestroyBufferView(m_device->device(), view, NULL);
11074 vkDestroyBuffer(m_device->device(), buffer, NULL);
11075 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11076 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11077 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11078 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11079}
11080
Tobin Ehlis209532e2016-09-07 13:52:18 -060011081TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11082 TEST_DESCRIPTION("Delete in-use sampler.");
11083
11084 ASSERT_NO_FATAL_FAILURE(InitState());
11085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11086
11087 VkDescriptorPoolSize ds_type_count;
11088 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11089 ds_type_count.descriptorCount = 1;
11090
11091 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11092 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11093 ds_pool_ci.maxSets = 1;
11094 ds_pool_ci.poolSizeCount = 1;
11095 ds_pool_ci.pPoolSizes = &ds_type_count;
11096
11097 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011098 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011099 ASSERT_VK_SUCCESS(err);
11100
11101 VkSamplerCreateInfo sampler_ci = {};
11102 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11103 sampler_ci.pNext = NULL;
11104 sampler_ci.magFilter = VK_FILTER_NEAREST;
11105 sampler_ci.minFilter = VK_FILTER_NEAREST;
11106 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11107 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11108 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11109 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11110 sampler_ci.mipLodBias = 1.0;
11111 sampler_ci.anisotropyEnable = VK_FALSE;
11112 sampler_ci.maxAnisotropy = 1;
11113 sampler_ci.compareEnable = VK_FALSE;
11114 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11115 sampler_ci.minLod = 1.0;
11116 sampler_ci.maxLod = 1.0;
11117 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11118 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11119 VkSampler sampler;
11120
11121 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11122 ASSERT_VK_SUCCESS(err);
11123
11124 VkDescriptorSetLayoutBinding layout_binding;
11125 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011126 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011127 layout_binding.descriptorCount = 1;
11128 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11129 layout_binding.pImmutableSamplers = NULL;
11130
11131 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11132 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11133 ds_layout_ci.bindingCount = 1;
11134 ds_layout_ci.pBindings = &layout_binding;
11135 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011136 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011137 ASSERT_VK_SUCCESS(err);
11138
11139 VkDescriptorSetAllocateInfo alloc_info = {};
11140 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11141 alloc_info.descriptorSetCount = 1;
11142 alloc_info.descriptorPool = ds_pool;
11143 alloc_info.pSetLayouts = &ds_layout;
11144 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011145 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011146 ASSERT_VK_SUCCESS(err);
11147
11148 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11149 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11150 pipeline_layout_ci.pNext = NULL;
11151 pipeline_layout_ci.setLayoutCount = 1;
11152 pipeline_layout_ci.pSetLayouts = &ds_layout;
11153
11154 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011155 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011156 ASSERT_VK_SUCCESS(err);
11157
11158 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011159 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 -060011160 ASSERT_TRUE(image.initialized());
11161
11162 VkImageView view;
11163 VkImageViewCreateInfo ivci = {};
11164 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11165 ivci.image = image.handle();
11166 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11167 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11168 ivci.subresourceRange.layerCount = 1;
11169 ivci.subresourceRange.baseMipLevel = 0;
11170 ivci.subresourceRange.levelCount = 1;
11171 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11172
11173 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11174 ASSERT_VK_SUCCESS(err);
11175
11176 VkDescriptorImageInfo image_info{};
11177 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11178 image_info.imageView = view;
11179 image_info.sampler = sampler;
11180
11181 VkWriteDescriptorSet descriptor_write = {};
11182 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11183 descriptor_write.dstSet = descriptor_set;
11184 descriptor_write.dstBinding = 0;
11185 descriptor_write.descriptorCount = 1;
11186 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11187 descriptor_write.pImageInfo = &image_info;
11188
11189 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11190
11191 // Create PSO to use the sampler
11192 char const *vsSource = "#version 450\n"
11193 "\n"
11194 "out gl_PerVertex { \n"
11195 " vec4 gl_Position;\n"
11196 "};\n"
11197 "void main(){\n"
11198 " gl_Position = vec4(1);\n"
11199 "}\n";
11200 char const *fsSource = "#version 450\n"
11201 "\n"
11202 "layout(set=0, binding=0) uniform sampler2D s;\n"
11203 "layout(location=0) out vec4 x;\n"
11204 "void main(){\n"
11205 " x = texture(s, vec2(1));\n"
11206 "}\n";
11207 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11208 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11209 VkPipelineObj pipe(m_device);
11210 pipe.AddShader(&vs);
11211 pipe.AddShader(&fs);
11212 pipe.AddColorAttachment();
11213 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011216
11217 BeginCommandBuffer();
11218 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011219 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11220 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11221 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011222 Draw(1, 0, 0, 0);
11223 EndCommandBuffer();
11224 // Submit cmd buffer then destroy sampler
11225 VkSubmitInfo submit_info = {};
11226 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11227 submit_info.commandBufferCount = 1;
11228 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11229 // Submit cmd buffer and then destroy sampler while in-flight
11230 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11231
11232 vkDestroySampler(m_device->device(), sampler, nullptr);
11233 m_errorMonitor->VerifyFound();
11234 vkQueueWaitIdle(m_device->m_queue);
11235 // Now we can actually destroy sampler
11236 vkDestroySampler(m_device->device(), sampler, nullptr);
11237 vkDestroyImageView(m_device->device(), view, NULL);
11238 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11239 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11240 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11241}
11242
Mark Mueller1cd9f412016-08-25 13:23:52 -060011243TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011244 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011245 "signaled but not waited on by the queue. Wait on a "
11246 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011247
11248 ASSERT_NO_FATAL_FAILURE(InitState());
11249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11250
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011251 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11252 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11253 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011254
11255 BeginCommandBuffer();
11256 EndCommandBuffer();
11257
11258 VkSemaphoreCreateInfo semaphore_create_info = {};
11259 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11260 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011261 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011262 VkSubmitInfo submit_info = {};
11263 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11264 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011265 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011266 submit_info.signalSemaphoreCount = 1;
11267 submit_info.pSignalSemaphores = &semaphore;
11268 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11269 m_errorMonitor->SetDesiredFailureMsg(0, "");
11270 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11271 BeginCommandBuffer();
11272 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011274 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11275 m_errorMonitor->VerifyFound();
11276
Mark Mueller1cd9f412016-08-25 13:23:52 -060011277 VkFenceCreateInfo fence_create_info = {};
11278 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11279 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011280 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011281
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011283 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11284 m_errorMonitor->VerifyFound();
11285
Mark Mueller4042b652016-09-05 22:52:21 -060011286 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011287 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011288 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11289}
11290
Tobin Ehlis4af23302016-07-19 10:50:30 -060011291TEST_F(VkLayerTest, FramebufferIncompatible) {
11292 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11293 "that does not match the framebuffer for the active "
11294 "renderpass.");
11295 ASSERT_NO_FATAL_FAILURE(InitState());
11296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11297
11298 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011299 VkAttachmentDescription attachment = {0,
11300 VK_FORMAT_B8G8R8A8_UNORM,
11301 VK_SAMPLE_COUNT_1_BIT,
11302 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11303 VK_ATTACHMENT_STORE_OP_STORE,
11304 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11305 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11306 VK_IMAGE_LAYOUT_UNDEFINED,
11307 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011309 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011310
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011311 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011312
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011313 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011314
11315 VkRenderPass rp;
11316 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11317 ASSERT_VK_SUCCESS(err);
11318
11319 // A compatible framebuffer.
11320 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011321 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 -060011322 ASSERT_TRUE(image.initialized());
11323
11324 VkImageViewCreateInfo ivci = {
11325 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11326 nullptr,
11327 0,
11328 image.handle(),
11329 VK_IMAGE_VIEW_TYPE_2D,
11330 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011331 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11332 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011333 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11334 };
11335 VkImageView view;
11336 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11337 ASSERT_VK_SUCCESS(err);
11338
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011339 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011340 VkFramebuffer fb;
11341 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11342 ASSERT_VK_SUCCESS(err);
11343
11344 VkCommandBufferAllocateInfo cbai = {};
11345 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11346 cbai.commandPool = m_commandPool;
11347 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11348 cbai.commandBufferCount = 1;
11349
11350 VkCommandBuffer sec_cb;
11351 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11352 ASSERT_VK_SUCCESS(err);
11353 VkCommandBufferBeginInfo cbbi = {};
11354 VkCommandBufferInheritanceInfo cbii = {};
11355 cbii.renderPass = renderPass();
11356 cbii.framebuffer = fb;
11357 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11358 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011359 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 -060011360 cbbi.pInheritanceInfo = &cbii;
11361 vkBeginCommandBuffer(sec_cb, &cbbi);
11362 vkEndCommandBuffer(sec_cb);
11363
Chris Forbes3400bc52016-09-13 18:10:34 +120011364 VkCommandBufferBeginInfo cbbi2 = {
11365 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11366 0, nullptr
11367 };
11368 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11369 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011372 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011373 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11374 m_errorMonitor->VerifyFound();
11375 // Cleanup
11376 vkDestroyImageView(m_device->device(), view, NULL);
11377 vkDestroyRenderPass(m_device->device(), rp, NULL);
11378 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11379}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011380
11381TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11382 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11383 "invalid value. If logicOp is not available, attempt to "
11384 "use it and verify that we see the correct error.");
11385 ASSERT_NO_FATAL_FAILURE(InitState());
11386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11387
11388 auto features = m_device->phy().features();
11389 // Set the expected error depending on whether or not logicOp available
11390 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11392 "enabled, logicOpEnable must be "
11393 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011394 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011396 }
11397 // Create a pipeline using logicOp
11398 VkResult err;
11399
11400 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11401 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11402
11403 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011404 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011405 ASSERT_VK_SUCCESS(err);
11406
11407 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11408 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11409 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011410 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011411 vp_state_ci.pViewports = &vp;
11412 vp_state_ci.scissorCount = 1;
11413 VkRect2D scissors = {}; // Dummy scissors to point to
11414 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011415
11416 VkPipelineShaderStageCreateInfo shaderStages[2];
11417 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11418
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011419 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11420 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011421 shaderStages[0] = vs.GetStageCreateInfo();
11422 shaderStages[1] = fs.GetStageCreateInfo();
11423
11424 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11425 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11426
11427 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11428 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11429 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11430
11431 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11432 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011433 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011434
11435 VkPipelineColorBlendAttachmentState att = {};
11436 att.blendEnable = VK_FALSE;
11437 att.colorWriteMask = 0xf;
11438
11439 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11440 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11441 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11442 cb_ci.logicOpEnable = VK_TRUE;
11443 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11444 cb_ci.attachmentCount = 1;
11445 cb_ci.pAttachments = &att;
11446
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011447 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11448 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11449 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11450
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011451 VkGraphicsPipelineCreateInfo gp_ci = {};
11452 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11453 gp_ci.stageCount = 2;
11454 gp_ci.pStages = shaderStages;
11455 gp_ci.pVertexInputState = &vi_ci;
11456 gp_ci.pInputAssemblyState = &ia_ci;
11457 gp_ci.pViewportState = &vp_state_ci;
11458 gp_ci.pRasterizationState = &rs_ci;
11459 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011460 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011461 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11462 gp_ci.layout = pipeline_layout;
11463 gp_ci.renderPass = renderPass();
11464
11465 VkPipelineCacheCreateInfo pc_ci = {};
11466 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11467
11468 VkPipeline pipeline;
11469 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011470 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011471 ASSERT_VK_SUCCESS(err);
11472
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011473 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011474 m_errorMonitor->VerifyFound();
11475 if (VK_SUCCESS == err) {
11476 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11477 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011478 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11479 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11480}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011481#endif // DRAW_STATE_TESTS
11482
Tobin Ehlis0788f522015-05-26 16:11:58 -060011483#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011484#if GTEST_IS_THREADSAFE
11485struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011486 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011487 VkEvent event;
11488 bool bailout;
11489};
11490
Karl Schultz6addd812016-02-02 17:17:23 -070011491extern "C" void *AddToCommandBuffer(void *arg) {
11492 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011493
Mike Stroyana6d14942016-07-13 15:10:05 -060011494 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011495 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011496 if (data->bailout) {
11497 break;
11498 }
11499 }
11500 return NULL;
11501}
11502
Karl Schultz6addd812016-02-02 17:17:23 -070011503TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011504 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011505
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011507
Mike Stroyanaccf7692015-05-12 16:00:45 -060011508 ASSERT_NO_FATAL_FAILURE(InitState());
11509 ASSERT_NO_FATAL_FAILURE(InitViewport());
11510 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11511
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011512 // Calls AllocateCommandBuffers
11513 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011514
11515 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011516 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011517
11518 VkEventCreateInfo event_info;
11519 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011520 VkResult err;
11521
11522 memset(&event_info, 0, sizeof(event_info));
11523 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11524
Chia-I Wuf7458c52015-10-26 21:10:41 +080011525 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011526 ASSERT_VK_SUCCESS(err);
11527
Mike Stroyanaccf7692015-05-12 16:00:45 -060011528 err = vkResetEvent(device(), event);
11529 ASSERT_VK_SUCCESS(err);
11530
11531 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011532 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011533 data.event = event;
11534 data.bailout = false;
11535 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011536
11537 // First do some correct operations using multiple threads.
11538 // Add many entries to command buffer from another thread.
11539 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11540 // Make non-conflicting calls from this thread at the same time.
11541 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011542 uint32_t count;
11543 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011544 }
11545 test_platform_thread_join(thread, NULL);
11546
11547 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011548 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011549 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011550 // Add many entries to command buffer from this thread at the same time.
11551 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011552
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011553 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011554 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011555
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011556 m_errorMonitor->SetBailout(NULL);
11557
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011558 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011559
Chia-I Wuf7458c52015-10-26 21:10:41 +080011560 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011561}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011562#endif // GTEST_IS_THREADSAFE
11563#endif // THREADING_TESTS
11564
Chris Forbes9f7ff632015-05-25 11:13:08 +120011565#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011566TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011567 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11568 "with an impossible code size");
11569
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011571
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011572 ASSERT_NO_FATAL_FAILURE(InitState());
11573 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11574
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011575 VkShaderModule module;
11576 VkShaderModuleCreateInfo moduleCreateInfo;
11577 struct icd_spv_header spv;
11578
11579 spv.magic = ICD_SPV_MAGIC;
11580 spv.version = ICD_SPV_VERSION;
11581 spv.gen_magic = 0;
11582
11583 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11584 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011585 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011586 moduleCreateInfo.codeSize = 4;
11587 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011588 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011589
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011590 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011591}
11592
Karl Schultz6addd812016-02-02 17:17:23 -070011593TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011594 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11595 "with a bad magic number");
11596
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011598
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011599 ASSERT_NO_FATAL_FAILURE(InitState());
11600 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11601
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011602 VkShaderModule module;
11603 VkShaderModuleCreateInfo moduleCreateInfo;
11604 struct icd_spv_header spv;
11605
11606 spv.magic = ~ICD_SPV_MAGIC;
11607 spv.version = ICD_SPV_VERSION;
11608 spv.gen_magic = 0;
11609
11610 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11611 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011612 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011613 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11614 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011615 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011616
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011617 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011618}
11619
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011620#if 0
11621// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011622TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011624 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011625
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011626 ASSERT_NO_FATAL_FAILURE(InitState());
11627 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11628
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011629 VkShaderModule module;
11630 VkShaderModuleCreateInfo moduleCreateInfo;
11631 struct icd_spv_header spv;
11632
11633 spv.magic = ICD_SPV_MAGIC;
11634 spv.version = ~ICD_SPV_VERSION;
11635 spv.gen_magic = 0;
11636
11637 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11638 moduleCreateInfo.pNext = NULL;
11639
Karl Schultz6addd812016-02-02 17:17:23 -070011640 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011641 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11642 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011643 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011644
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011645 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011646}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011647#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011648
Karl Schultz6addd812016-02-02 17:17:23 -070011649TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011650 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11651 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011653
Chris Forbes9f7ff632015-05-25 11:13:08 +120011654 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011655 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011656
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011657 char const *vsSource = "#version 450\n"
11658 "\n"
11659 "layout(location=0) out float x;\n"
11660 "out gl_PerVertex {\n"
11661 " vec4 gl_Position;\n"
11662 "};\n"
11663 "void main(){\n"
11664 " gl_Position = vec4(1);\n"
11665 " x = 0;\n"
11666 "}\n";
11667 char const *fsSource = "#version 450\n"
11668 "\n"
11669 "layout(location=0) out vec4 color;\n"
11670 "void main(){\n"
11671 " color = vec4(1);\n"
11672 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011673
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011674 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11675 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011676
11677 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011678 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011679 pipe.AddShader(&vs);
11680 pipe.AddShader(&fs);
11681
Chris Forbes9f7ff632015-05-25 11:13:08 +120011682 VkDescriptorSetObj descriptorSet(m_device);
11683 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011684 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011685
Tony Barbour5781e8f2015-08-04 16:23:11 -060011686 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011687
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011688 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011689}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011690
Mark Mueller098c9cb2016-09-08 09:01:57 -060011691TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11692 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11693
11694 ASSERT_NO_FATAL_FAILURE(InitState());
11695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11696
11697 const char *bad_specialization_message =
11698 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11699
11700 char const *vsSource =
11701 "#version 450\n"
11702 "\n"
11703 "out gl_PerVertex {\n"
11704 " vec4 gl_Position;\n"
11705 "};\n"
11706 "void main(){\n"
11707 " gl_Position = vec4(1);\n"
11708 "}\n";
11709
11710 char const *fsSource =
11711 "#version 450\n"
11712 "\n"
11713 "layout (constant_id = 0) const float r = 0.0f;\n"
11714 "layout(location = 0) out vec4 uFragColor;\n"
11715 "void main(){\n"
11716 " uFragColor = vec4(r,1,0,1);\n"
11717 "}\n";
11718
11719 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11720 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11721
11722 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11723 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11724
11725 VkPipelineLayout pipeline_layout;
11726 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11727
11728 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11729 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11730 vp_state_create_info.viewportCount = 1;
11731 VkViewport viewport = {};
11732 vp_state_create_info.pViewports = &viewport;
11733 vp_state_create_info.scissorCount = 1;
11734 VkRect2D scissors = {};
11735 vp_state_create_info.pScissors = &scissors;
11736
11737 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11738
11739 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11740 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11741 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11742 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11743
11744 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11745 vs.GetStageCreateInfo(),
11746 fs.GetStageCreateInfo()
11747 };
11748
11749 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11750 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11751
11752 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11753 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11754 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11755
11756 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11757 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11758 rasterization_state_create_info.pNext = nullptr;
11759 rasterization_state_create_info.lineWidth = 1.0f;
11760 rasterization_state_create_info.rasterizerDiscardEnable = true;
11761
11762 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11763 color_blend_attachment_state.blendEnable = VK_FALSE;
11764 color_blend_attachment_state.colorWriteMask = 0xf;
11765
11766 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11767 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11768 color_blend_state_create_info.attachmentCount = 1;
11769 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11770
11771 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11772 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11773 graphicspipe_create_info.stageCount = 2;
11774 graphicspipe_create_info.pStages = shader_stage_create_info;
11775 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11776 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11777 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11778 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11779 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11780 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11781 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11782 graphicspipe_create_info.layout = pipeline_layout;
11783 graphicspipe_create_info.renderPass = renderPass();
11784
11785 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
11786 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11787
11788 VkPipelineCache pipelineCache;
11789 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
11790
11791 // This structure maps constant ids to data locations.
11792 const VkSpecializationMapEntry entry =
11793 // id, offset, size
11794 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
11795
11796 uint32_t data = 1;
11797
11798 // Set up the info describing spec map and data
11799 const VkSpecializationInfo specialization_info = {
11800 1,
11801 &entry,
11802 1 * sizeof(float),
11803 &data,
11804 };
11805 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
11806
11807 VkPipeline pipeline;
11808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
11809 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
11810 m_errorMonitor->VerifyFound();
11811
11812 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
11813 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11814}
11815
11816TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
11817 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11818
11819 ASSERT_NO_FATAL_FAILURE(InitState());
11820 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11821
11822 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
11823
11824 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
11825 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11826 descriptor_pool_type_count[0].descriptorCount = 1;
11827 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11828 descriptor_pool_type_count[1].descriptorCount = 1;
11829
11830 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11831 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11832 descriptor_pool_create_info.maxSets = 1;
11833 descriptor_pool_create_info.poolSizeCount = 2;
11834 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
11835 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11836
11837 VkDescriptorPool descriptorset_pool;
11838 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11839
11840 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11841 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11842 descriptorset_layout_binding.descriptorCount = 1;
11843 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11844
11845 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11846 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11847 descriptorset_layout_create_info.bindingCount = 1;
11848 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11849
11850 VkDescriptorSetLayout descriptorset_layout;
11851 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
11852
11853 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11854 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11855 descriptorset_allocate_info.descriptorSetCount = 1;
11856 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11857 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11858 VkDescriptorSet descriptorset;
11859 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11860
11861 // Challenge core_validation with a non uniform buffer type.
11862 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
11863
Mark Mueller098c9cb2016-09-08 09:01:57 -060011864 char const *vsSource =
11865 "#version 450\n"
11866 "\n"
11867 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11868 " mat4 mvp;\n"
11869 "} ubuf;\n"
11870 "out gl_PerVertex {\n"
11871 " vec4 gl_Position;\n"
11872 "};\n"
11873 "void main(){\n"
11874 " gl_Position = ubuf.mvp * vec4(1);\n"
11875 "}\n";
11876
11877 char const *fsSource =
11878 "#version 450\n"
11879 "\n"
11880 "layout(location = 0) out vec4 uFragColor;\n"
11881 "void main(){\n"
11882 " uFragColor = vec4(0,1,0,1);\n"
11883 "}\n";
11884
11885 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11886 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11887
11888 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11889 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11890 pipeline_layout_create_info.setLayoutCount = 1;
11891 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11892
11893 VkPipelineLayout pipeline_layout;
11894 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11895
11896 VkPipelineObj pipe(m_device);
11897 pipe.AddColorAttachment();
11898 pipe.AddShader(&vs);
11899 pipe.AddShader(&fs);
11900
11901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
11902 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11903 m_errorMonitor->VerifyFound();
11904
11905 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11906 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11907 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11908}
11909
11910TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
11911 TEST_DESCRIPTION(
11912 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
11913
11914 ASSERT_NO_FATAL_FAILURE(InitState());
11915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11916
11917 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
11918
11919 VkDescriptorPoolSize descriptor_pool_type_count = {};
11920 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11921 descriptor_pool_type_count.descriptorCount = 1;
11922
11923 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11924 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11925 descriptor_pool_create_info.maxSets = 1;
11926 descriptor_pool_create_info.poolSizeCount = 1;
11927 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
11928 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11929
11930 VkDescriptorPool descriptorset_pool;
11931 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11932
11933 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11934 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11935 descriptorset_layout_binding.descriptorCount = 1;
11936 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
11937 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11938
11939 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11940 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11941 descriptorset_layout_create_info.bindingCount = 1;
11942 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11943
11944 VkDescriptorSetLayout descriptorset_layout;
11945 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
11946 nullptr, &descriptorset_layout));
11947
11948 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11949 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11950 descriptorset_allocate_info.descriptorSetCount = 1;
11951 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11952 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11953 VkDescriptorSet descriptorset;
11954 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11955
11956 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11957
Mark Mueller098c9cb2016-09-08 09:01:57 -060011958 char const *vsSource =
11959 "#version 450\n"
11960 "\n"
11961 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11962 " mat4 mvp;\n"
11963 "} ubuf;\n"
11964 "out gl_PerVertex {\n"
11965 " vec4 gl_Position;\n"
11966 "};\n"
11967 "void main(){\n"
11968 " gl_Position = ubuf.mvp * vec4(1);\n"
11969 "}\n";
11970
11971 char const *fsSource =
11972 "#version 450\n"
11973 "\n"
11974 "layout(location = 0) out vec4 uFragColor;\n"
11975 "void main(){\n"
11976 " uFragColor = vec4(0,1,0,1);\n"
11977 "}\n";
11978
11979 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11980 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11981
11982 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11983 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11984 pipeline_layout_create_info.setLayoutCount = 1;
11985 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11986
11987 VkPipelineLayout pipeline_layout;
11988 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11989
11990 VkPipelineObj pipe(m_device);
11991 pipe.AddColorAttachment();
11992 pipe.AddShader(&vs);
11993 pipe.AddShader(&fs);
11994
11995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
11996 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11997 m_errorMonitor->VerifyFound();
11998
11999 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12000 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12001 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12002}
12003
12004TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12005 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12006 "accessible from the current shader stage.");
12007
12008 ASSERT_NO_FATAL_FAILURE(InitState());
12009 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12010
12011 const char *push_constant_not_accessible_message =
12012 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12013
12014 char const *vsSource =
12015 "#version 450\n"
12016 "\n"
12017 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12018 "out gl_PerVertex {\n"
12019 " vec4 gl_Position;\n"
12020 "};\n"
12021 "void main(){\n"
12022 " gl_Position = vec4(consts.x);\n"
12023 "}\n";
12024
12025 char const *fsSource =
12026 "#version 450\n"
12027 "\n"
12028 "layout(location = 0) out vec4 uFragColor;\n"
12029 "void main(){\n"
12030 " uFragColor = vec4(0,1,0,1);\n"
12031 "}\n";
12032
12033 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12034 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12035
12036 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12037 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12038
12039 // Set up a push constant range
12040 VkPushConstantRange push_constant_ranges = {};
12041 // Set to the wrong stage to challenge core_validation
12042 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12043 push_constant_ranges.size = 4;
12044
12045 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12046 pipeline_layout_create_info.pushConstantRangeCount = 1;
12047
12048 VkPipelineLayout pipeline_layout;
12049 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12050
12051 VkPipelineObj pipe(m_device);
12052 pipe.AddColorAttachment();
12053 pipe.AddShader(&vs);
12054 pipe.AddShader(&fs);
12055
12056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12057 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12058 m_errorMonitor->VerifyFound();
12059
12060 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12061}
12062
12063TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12064 TEST_DESCRIPTION(
12065 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12066
12067 ASSERT_NO_FATAL_FAILURE(InitState());
12068 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12069
12070 const char *feature_not_enabled_message =
12071 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12072
12073 // Some awkward steps are required to test with custom device features.
12074 std::vector<const char *> device_extension_names;
12075 auto features = m_device->phy().features();
12076 // Disable support for 64 bit floats
12077 features.shaderFloat64 = false;
12078 // The sacrificial device object
12079 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12080
12081 char const *vsSource = "#version 450\n"
12082 "\n"
12083 "out gl_PerVertex {\n"
12084 " vec4 gl_Position;\n"
12085 "};\n"
12086 "void main(){\n"
12087 " gl_Position = vec4(1);\n"
12088 "}\n";
12089 char const *fsSource = "#version 450\n"
12090 "\n"
12091 "layout(location=0) out vec4 color;\n"
12092 "void main(){\n"
12093 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12094 " color = vec4(green);\n"
12095 "}\n";
12096
12097 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12098 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12099
12100 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012101
12102 VkPipelineObj pipe(&test_device);
12103 pipe.AddColorAttachment();
12104 pipe.AddShader(&vs);
12105 pipe.AddShader(&fs);
12106
12107 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12108 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12109 VkPipelineLayout pipeline_layout;
12110 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12111
12112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12113 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12114 m_errorMonitor->VerifyFound();
12115
12116 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12117}
12118
12119TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12120 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12121
12122 ASSERT_NO_FATAL_FAILURE(InitState());
12123 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12124
12125 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12126
12127 char const *vsSource = "#version 450\n"
12128 "\n"
12129 "out gl_PerVertex {\n"
12130 " vec4 gl_Position;\n"
12131 "};\n"
12132 "layout(xfb_buffer = 1) out;"
12133 "void main(){\n"
12134 " gl_Position = vec4(1);\n"
12135 "}\n";
12136 char const *fsSource = "#version 450\n"
12137 "\n"
12138 "layout(location=0) out vec4 color;\n"
12139 "void main(){\n"
12140 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12141 " color = vec4(green);\n"
12142 "}\n";
12143
12144 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12145 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12146
12147 VkPipelineObj pipe(m_device);
12148 pipe.AddColorAttachment();
12149 pipe.AddShader(&vs);
12150 pipe.AddShader(&fs);
12151
12152 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12153 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12154 VkPipelineLayout pipeline_layout;
12155 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12156
12157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12158 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12159 m_errorMonitor->VerifyFound();
12160
12161 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12162}
12163
Karl Schultz6addd812016-02-02 17:17:23 -070012164TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012165 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12166 "which is not present in the outputs of the previous stage");
12167
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012169
Chris Forbes59cb88d2015-05-25 11:13:13 +120012170 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012171 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012173 char const *vsSource = "#version 450\n"
12174 "\n"
12175 "out gl_PerVertex {\n"
12176 " vec4 gl_Position;\n"
12177 "};\n"
12178 "void main(){\n"
12179 " gl_Position = vec4(1);\n"
12180 "}\n";
12181 char const *fsSource = "#version 450\n"
12182 "\n"
12183 "layout(location=0) in float x;\n"
12184 "layout(location=0) out vec4 color;\n"
12185 "void main(){\n"
12186 " color = vec4(x);\n"
12187 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012188
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012189 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12190 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012191
12192 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012193 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012194 pipe.AddShader(&vs);
12195 pipe.AddShader(&fs);
12196
Chris Forbes59cb88d2015-05-25 11:13:13 +120012197 VkDescriptorSetObj descriptorSet(m_device);
12198 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012199 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012200
Tony Barbour5781e8f2015-08-04 16:23:11 -060012201 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012202
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012203 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012204}
12205
Karl Schultz6addd812016-02-02 17:17:23 -070012206TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012207 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12208 "within an interace block, which is not present in the outputs "
12209 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012211
12212 ASSERT_NO_FATAL_FAILURE(InitState());
12213 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012215 char const *vsSource = "#version 450\n"
12216 "\n"
12217 "out gl_PerVertex {\n"
12218 " vec4 gl_Position;\n"
12219 "};\n"
12220 "void main(){\n"
12221 " gl_Position = vec4(1);\n"
12222 "}\n";
12223 char const *fsSource = "#version 450\n"
12224 "\n"
12225 "in block { layout(location=0) float x; } ins;\n"
12226 "layout(location=0) out vec4 color;\n"
12227 "void main(){\n"
12228 " color = vec4(ins.x);\n"
12229 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012230
12231 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12232 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12233
12234 VkPipelineObj pipe(m_device);
12235 pipe.AddColorAttachment();
12236 pipe.AddShader(&vs);
12237 pipe.AddShader(&fs);
12238
12239 VkDescriptorSetObj descriptorSet(m_device);
12240 descriptorSet.AppendDummy();
12241 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12242
12243 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12244
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012245 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012246}
12247
Karl Schultz6addd812016-02-02 17:17:23 -070012248TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012249 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012250 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12252 "output arr[2] of float32' vs 'ptr to "
12253 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012254
12255 ASSERT_NO_FATAL_FAILURE(InitState());
12256 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012258 char const *vsSource = "#version 450\n"
12259 "\n"
12260 "layout(location=0) out float x[2];\n"
12261 "out gl_PerVertex {\n"
12262 " vec4 gl_Position;\n"
12263 "};\n"
12264 "void main(){\n"
12265 " x[0] = 0; x[1] = 0;\n"
12266 " gl_Position = vec4(1);\n"
12267 "}\n";
12268 char const *fsSource = "#version 450\n"
12269 "\n"
12270 "layout(location=0) in float x[3];\n"
12271 "layout(location=0) out vec4 color;\n"
12272 "void main(){\n"
12273 " color = vec4(x[0] + x[1] + x[2]);\n"
12274 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012275
12276 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12277 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12278
12279 VkPipelineObj pipe(m_device);
12280 pipe.AddColorAttachment();
12281 pipe.AddShader(&vs);
12282 pipe.AddShader(&fs);
12283
12284 VkDescriptorSetObj descriptorSet(m_device);
12285 descriptorSet.AppendDummy();
12286 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12287
12288 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12289
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012290 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012291}
12292
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012293
Karl Schultz6addd812016-02-02 17:17:23 -070012294TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012295 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012296 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012298
Chris Forbesb56af562015-05-25 11:13:17 +120012299 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012300 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012301
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012302 char const *vsSource = "#version 450\n"
12303 "\n"
12304 "layout(location=0) out int x;\n"
12305 "out gl_PerVertex {\n"
12306 " vec4 gl_Position;\n"
12307 "};\n"
12308 "void main(){\n"
12309 " x = 0;\n"
12310 " gl_Position = vec4(1);\n"
12311 "}\n";
12312 char const *fsSource = "#version 450\n"
12313 "\n"
12314 "layout(location=0) in float x;\n" /* VS writes int */
12315 "layout(location=0) out vec4 color;\n"
12316 "void main(){\n"
12317 " color = vec4(x);\n"
12318 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012319
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012320 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12321 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012322
12323 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012324 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012325 pipe.AddShader(&vs);
12326 pipe.AddShader(&fs);
12327
Chris Forbesb56af562015-05-25 11:13:17 +120012328 VkDescriptorSetObj descriptorSet(m_device);
12329 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012330 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012331
Tony Barbour5781e8f2015-08-04 16:23:11 -060012332 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012333
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012334 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012335}
12336
Karl Schultz6addd812016-02-02 17:17:23 -070012337TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012338 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012339 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012340 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012342
12343 ASSERT_NO_FATAL_FAILURE(InitState());
12344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12345
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012346 char const *vsSource = "#version 450\n"
12347 "\n"
12348 "out block { layout(location=0) int x; } outs;\n"
12349 "out gl_PerVertex {\n"
12350 " vec4 gl_Position;\n"
12351 "};\n"
12352 "void main(){\n"
12353 " outs.x = 0;\n"
12354 " gl_Position = vec4(1);\n"
12355 "}\n";
12356 char const *fsSource = "#version 450\n"
12357 "\n"
12358 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12359 "layout(location=0) out vec4 color;\n"
12360 "void main(){\n"
12361 " color = vec4(ins.x);\n"
12362 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012363
12364 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12365 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12366
12367 VkPipelineObj pipe(m_device);
12368 pipe.AddColorAttachment();
12369 pipe.AddShader(&vs);
12370 pipe.AddShader(&fs);
12371
12372 VkDescriptorSetObj descriptorSet(m_device);
12373 descriptorSet.AppendDummy();
12374 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12375
12376 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12377
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012378 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012379}
12380
12381TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012382 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012383 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012384 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012385 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 +130012386
12387 ASSERT_NO_FATAL_FAILURE(InitState());
12388 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012390 char const *vsSource = "#version 450\n"
12391 "\n"
12392 "out block { layout(location=1) float x; } outs;\n"
12393 "out gl_PerVertex {\n"
12394 " vec4 gl_Position;\n"
12395 "};\n"
12396 "void main(){\n"
12397 " outs.x = 0;\n"
12398 " gl_Position = vec4(1);\n"
12399 "}\n";
12400 char const *fsSource = "#version 450\n"
12401 "\n"
12402 "in block { layout(location=0) float x; } ins;\n"
12403 "layout(location=0) out vec4 color;\n"
12404 "void main(){\n"
12405 " color = vec4(ins.x);\n"
12406 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012407
12408 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12409 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12410
12411 VkPipelineObj pipe(m_device);
12412 pipe.AddColorAttachment();
12413 pipe.AddShader(&vs);
12414 pipe.AddShader(&fs);
12415
12416 VkDescriptorSetObj descriptorSet(m_device);
12417 descriptorSet.AppendDummy();
12418 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12419
12420 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12421
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012422 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012423}
12424
12425TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012426 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012427 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012428 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012429 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 +130012430
12431 ASSERT_NO_FATAL_FAILURE(InitState());
12432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12433
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012434 char const *vsSource = "#version 450\n"
12435 "\n"
12436 "out block { layout(location=0, component=0) float x; } outs;\n"
12437 "out gl_PerVertex {\n"
12438 " vec4 gl_Position;\n"
12439 "};\n"
12440 "void main(){\n"
12441 " outs.x = 0;\n"
12442 " gl_Position = vec4(1);\n"
12443 "}\n";
12444 char const *fsSource = "#version 450\n"
12445 "\n"
12446 "in block { layout(location=0, component=1) float x; } ins;\n"
12447 "layout(location=0) out vec4 color;\n"
12448 "void main(){\n"
12449 " color = vec4(ins.x);\n"
12450 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012451
12452 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12453 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12454
12455 VkPipelineObj pipe(m_device);
12456 pipe.AddColorAttachment();
12457 pipe.AddShader(&vs);
12458 pipe.AddShader(&fs);
12459
12460 VkDescriptorSetObj descriptorSet(m_device);
12461 descriptorSet.AppendDummy();
12462 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12463
12464 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12465
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012466 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012467}
12468
Karl Schultz6addd812016-02-02 17:17:23 -070012469TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012470 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12471 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012473
Chris Forbesde136e02015-05-25 11:13:28 +120012474 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012476
12477 VkVertexInputBindingDescription input_binding;
12478 memset(&input_binding, 0, sizeof(input_binding));
12479
12480 VkVertexInputAttributeDescription input_attrib;
12481 memset(&input_attrib, 0, sizeof(input_attrib));
12482 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12483
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012484 char const *vsSource = "#version 450\n"
12485 "\n"
12486 "out gl_PerVertex {\n"
12487 " vec4 gl_Position;\n"
12488 "};\n"
12489 "void main(){\n"
12490 " gl_Position = vec4(1);\n"
12491 "}\n";
12492 char const *fsSource = "#version 450\n"
12493 "\n"
12494 "layout(location=0) out vec4 color;\n"
12495 "void main(){\n"
12496 " color = vec4(1);\n"
12497 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012498
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012499 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12500 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012501
12502 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012503 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012504 pipe.AddShader(&vs);
12505 pipe.AddShader(&fs);
12506
12507 pipe.AddVertexInputBindings(&input_binding, 1);
12508 pipe.AddVertexInputAttribs(&input_attrib, 1);
12509
Chris Forbesde136e02015-05-25 11:13:28 +120012510 VkDescriptorSetObj descriptorSet(m_device);
12511 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012512 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012513
Tony Barbour5781e8f2015-08-04 16:23:11 -060012514 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012515
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012516 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012517}
12518
Karl Schultz6addd812016-02-02 17:17:23 -070012519TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012520 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12521 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012523
12524 ASSERT_NO_FATAL_FAILURE(InitState());
12525 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12526
12527 VkVertexInputBindingDescription input_binding;
12528 memset(&input_binding, 0, sizeof(input_binding));
12529
12530 VkVertexInputAttributeDescription input_attrib;
12531 memset(&input_attrib, 0, sizeof(input_attrib));
12532 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12533
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012534 char const *vsSource = "#version 450\n"
12535 "\n"
12536 "layout(location=1) in float x;\n"
12537 "out gl_PerVertex {\n"
12538 " vec4 gl_Position;\n"
12539 "};\n"
12540 "void main(){\n"
12541 " gl_Position = vec4(x);\n"
12542 "}\n";
12543 char const *fsSource = "#version 450\n"
12544 "\n"
12545 "layout(location=0) out vec4 color;\n"
12546 "void main(){\n"
12547 " color = vec4(1);\n"
12548 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012549
12550 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12551 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12552
12553 VkPipelineObj pipe(m_device);
12554 pipe.AddColorAttachment();
12555 pipe.AddShader(&vs);
12556 pipe.AddShader(&fs);
12557
12558 pipe.AddVertexInputBindings(&input_binding, 1);
12559 pipe.AddVertexInputAttribs(&input_attrib, 1);
12560
12561 VkDescriptorSetObj descriptorSet(m_device);
12562 descriptorSet.AppendDummy();
12563 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12564
12565 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12566
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012567 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012568}
12569
Karl Schultz6addd812016-02-02 17:17:23 -070012570TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012571 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012572 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012573 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 -060012574
Chris Forbes62e8e502015-05-25 11:13:29 +120012575 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012576 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012577
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012578 char const *vsSource = "#version 450\n"
12579 "\n"
12580 "layout(location=0) in vec4 x;\n" /* not provided */
12581 "out gl_PerVertex {\n"
12582 " vec4 gl_Position;\n"
12583 "};\n"
12584 "void main(){\n"
12585 " gl_Position = x;\n"
12586 "}\n";
12587 char const *fsSource = "#version 450\n"
12588 "\n"
12589 "layout(location=0) out vec4 color;\n"
12590 "void main(){\n"
12591 " color = vec4(1);\n"
12592 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012593
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012594 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12595 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012596
12597 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012598 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012599 pipe.AddShader(&vs);
12600 pipe.AddShader(&fs);
12601
Chris Forbes62e8e502015-05-25 11:13:29 +120012602 VkDescriptorSetObj descriptorSet(m_device);
12603 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012604 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012605
Tony Barbour5781e8f2015-08-04 16:23:11 -060012606 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012607
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012608 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012609}
12610
Karl Schultz6addd812016-02-02 17:17:23 -070012611TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012612 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12613 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012614 "vertex shader input that consumes it");
12615 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 -060012616
Chris Forbesc97d98e2015-05-25 11:13:31 +120012617 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012618 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +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 "layout(location=0) in int x;\n" /* attrib provided float */
12630 "out gl_PerVertex {\n"
12631 " vec4 gl_Position;\n"
12632 "};\n"
12633 "void main(){\n"
12634 " gl_Position = vec4(x);\n"
12635 "}\n";
12636 char const *fsSource = "#version 450\n"
12637 "\n"
12638 "layout(location=0) out vec4 color;\n"
12639 "void main(){\n"
12640 " color = vec4(1);\n"
12641 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012642
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012643 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12644 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012645
12646 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012647 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012648 pipe.AddShader(&vs);
12649 pipe.AddShader(&fs);
12650
12651 pipe.AddVertexInputBindings(&input_binding, 1);
12652 pipe.AddVertexInputAttribs(&input_attrib, 1);
12653
Chris Forbesc97d98e2015-05-25 11:13:31 +120012654 VkDescriptorSetObj descriptorSet(m_device);
12655 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012656 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012657
Tony Barbour5781e8f2015-08-04 16:23:11 -060012658 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012659
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012660 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012661}
12662
Chris Forbesc68b43c2016-04-06 11:18:47 +120012663TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012664 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12665 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12667 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012668
12669 ASSERT_NO_FATAL_FAILURE(InitState());
12670 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12671
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012672 char const *vsSource = "#version 450\n"
12673 "\n"
12674 "out gl_PerVertex {\n"
12675 " vec4 gl_Position;\n"
12676 "};\n"
12677 "void main(){\n"
12678 " gl_Position = vec4(1);\n"
12679 "}\n";
12680 char const *fsSource = "#version 450\n"
12681 "\n"
12682 "layout(location=0) out vec4 color;\n"
12683 "void main(){\n"
12684 " color = vec4(1);\n"
12685 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012686
12687 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12688 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12689
12690 VkPipelineObj pipe(m_device);
12691 pipe.AddColorAttachment();
12692 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012693 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012694 pipe.AddShader(&fs);
12695
12696 VkDescriptorSetObj descriptorSet(m_device);
12697 descriptorSet.AppendDummy();
12698 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12699
12700 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12701
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012702 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012703}
12704
Chris Forbes82ff92a2016-09-09 10:50:24 +120012705TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12707 "No entrypoint found named `foo`");
12708
12709 ASSERT_NO_FATAL_FAILURE(InitState());
12710 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12711
12712 char const *vsSource = "#version 450\n"
12713 "out gl_PerVertex {\n"
12714 " vec4 gl_Position;\n"
12715 "};\n"
12716 "void main(){\n"
12717 " gl_Position = vec4(0);\n"
12718 "}\n";
12719 char const *fsSource = "#version 450\n"
12720 "\n"
12721 "layout(location=0) out vec4 color;\n"
12722 "void main(){\n"
12723 " color = vec4(1);\n"
12724 "}\n";
12725
12726 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12727 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12728
12729 VkPipelineObj pipe(m_device);
12730 pipe.AddColorAttachment();
12731 pipe.AddShader(&vs);
12732 pipe.AddShader(&fs);
12733
12734 VkDescriptorSetObj descriptorSet(m_device);
12735 descriptorSet.AppendDummy();
12736 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12737
12738 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12739
12740 m_errorMonitor->VerifyFound();
12741}
12742
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012743TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12744 m_errorMonitor->SetDesiredFailureMsg(
12745 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12746 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12747 "uses a depth/stencil attachment");
12748
12749 ASSERT_NO_FATAL_FAILURE(InitState());
12750 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12751
12752 char const *vsSource = "#version 450\n"
12753 "void main(){ gl_Position = vec4(0); }\n";
12754 char const *fsSource = "#version 450\n"
12755 "\n"
12756 "layout(location=0) out vec4 color;\n"
12757 "void main(){\n"
12758 " color = vec4(1);\n"
12759 "}\n";
12760
12761 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12762 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12763
12764 VkPipelineObj pipe(m_device);
12765 pipe.AddColorAttachment();
12766 pipe.AddShader(&vs);
12767 pipe.AddShader(&fs);
12768
12769 VkDescriptorSetObj descriptorSet(m_device);
12770 descriptorSet.AppendDummy();
12771 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12772
12773 VkAttachmentDescription attachments[] = {
12774 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12775 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12776 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12777 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12778 },
12779 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12780 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12781 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12782 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12783 },
12784 };
12785 VkAttachmentReference refs[] = {
12786 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
12787 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
12788 };
12789 VkSubpassDescription subpass = {
12790 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
12791 1, &refs[0], nullptr, &refs[1],
12792 0, nullptr
12793 };
12794 VkRenderPassCreateInfo rpci = {
12795 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
12796 0, 2, attachments, 1, &subpass, 0, nullptr
12797 };
12798 VkRenderPass rp;
12799 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12800 ASSERT_VK_SUCCESS(err);
12801
12802 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
12803
12804 m_errorMonitor->VerifyFound();
12805
12806 vkDestroyRenderPass(m_device->device(), rp, nullptr);
12807}
12808
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012809TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012810 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
12811 "the TCS without the patch decoration, but consumed in the TES "
12812 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
12814 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120012815
12816 ASSERT_NO_FATAL_FAILURE(InitState());
12817 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12818
Chris Forbesc1e852d2016-04-04 19:26:42 +120012819 if (!m_device->phy().features().tessellationShader) {
12820 printf("Device does not support tessellation shaders; skipped.\n");
12821 return;
12822 }
12823
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012824 char const *vsSource = "#version 450\n"
12825 "void main(){}\n";
12826 char const *tcsSource = "#version 450\n"
12827 "layout(location=0) out int x[];\n"
12828 "layout(vertices=3) out;\n"
12829 "void main(){\n"
12830 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
12831 " gl_TessLevelInner[0] = 1;\n"
12832 " x[gl_InvocationID] = gl_InvocationID;\n"
12833 "}\n";
12834 char const *tesSource = "#version 450\n"
12835 "layout(triangles, equal_spacing, cw) in;\n"
12836 "layout(location=0) patch in int x;\n"
12837 "out gl_PerVertex { vec4 gl_Position; };\n"
12838 "void main(){\n"
12839 " gl_Position.xyz = gl_TessCoord;\n"
12840 " gl_Position.w = x;\n"
12841 "}\n";
12842 char const *fsSource = "#version 450\n"
12843 "layout(location=0) out vec4 color;\n"
12844 "void main(){\n"
12845 " color = vec4(1);\n"
12846 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120012847
12848 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12849 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
12850 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
12851 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12852
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012853 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
12854 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012855
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012856 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012857
12858 VkPipelineObj pipe(m_device);
12859 pipe.SetInputAssembly(&iasci);
12860 pipe.SetTessellation(&tsci);
12861 pipe.AddColorAttachment();
12862 pipe.AddShader(&vs);
12863 pipe.AddShader(&tcs);
12864 pipe.AddShader(&tes);
12865 pipe.AddShader(&fs);
12866
12867 VkDescriptorSetObj descriptorSet(m_device);
12868 descriptorSet.AppendDummy();
12869 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12870
12871 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12872
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012873 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120012874}
12875
Karl Schultz6addd812016-02-02 17:17:23 -070012876TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012877 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
12878 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12880 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012881
Chris Forbes280ba2c2015-06-12 11:16:41 +120012882 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012883 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012884
12885 /* Two binding descriptions for binding 0 */
12886 VkVertexInputBindingDescription input_bindings[2];
12887 memset(input_bindings, 0, sizeof(input_bindings));
12888
12889 VkVertexInputAttributeDescription input_attrib;
12890 memset(&input_attrib, 0, sizeof(input_attrib));
12891 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12892
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012893 char const *vsSource = "#version 450\n"
12894 "\n"
12895 "layout(location=0) in float x;\n" /* attrib provided float */
12896 "out gl_PerVertex {\n"
12897 " vec4 gl_Position;\n"
12898 "};\n"
12899 "void main(){\n"
12900 " gl_Position = vec4(x);\n"
12901 "}\n";
12902 char const *fsSource = "#version 450\n"
12903 "\n"
12904 "layout(location=0) out vec4 color;\n"
12905 "void main(){\n"
12906 " color = vec4(1);\n"
12907 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120012908
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012909 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12910 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012911
12912 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012913 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012914 pipe.AddShader(&vs);
12915 pipe.AddShader(&fs);
12916
12917 pipe.AddVertexInputBindings(input_bindings, 2);
12918 pipe.AddVertexInputAttribs(&input_attrib, 1);
12919
Chris Forbes280ba2c2015-06-12 11:16:41 +120012920 VkDescriptorSetObj descriptorSet(m_device);
12921 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012922 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012923
Tony Barbour5781e8f2015-08-04 16:23:11 -060012924 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012925
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012926 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012927}
Chris Forbes8f68b562015-05-25 11:13:32 +120012928
Karl Schultz6addd812016-02-02 17:17:23 -070012929TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012930 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012931 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012933
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012934 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012936 char const *vsSource = "#version 450\n"
12937 "\n"
12938 "out gl_PerVertex {\n"
12939 " vec4 gl_Position;\n"
12940 "};\n"
12941 "void main(){\n"
12942 " gl_Position = vec4(1);\n"
12943 "}\n";
12944 char const *fsSource = "#version 450\n"
12945 "\n"
12946 "void main(){\n"
12947 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012948
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012949 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12950 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012951
12952 VkPipelineObj pipe(m_device);
12953 pipe.AddShader(&vs);
12954 pipe.AddShader(&fs);
12955
Chia-I Wu08accc62015-07-07 11:50:03 +080012956 /* set up CB 0, not written */
12957 pipe.AddColorAttachment();
12958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012959
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012960 VkDescriptorSetObj descriptorSet(m_device);
12961 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012962 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012963
Tony Barbour5781e8f2015-08-04 16:23:11 -060012964 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012965
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012966 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012967}
12968
Karl Schultz6addd812016-02-02 17:17:23 -070012969TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012970 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120012971 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012973 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012974
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012975 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012976
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012977 char const *vsSource = "#version 450\n"
12978 "\n"
12979 "out gl_PerVertex {\n"
12980 " vec4 gl_Position;\n"
12981 "};\n"
12982 "void main(){\n"
12983 " gl_Position = vec4(1);\n"
12984 "}\n";
12985 char const *fsSource = "#version 450\n"
12986 "\n"
12987 "layout(location=0) out vec4 x;\n"
12988 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
12989 "void main(){\n"
12990 " x = vec4(1);\n"
12991 " y = vec4(1);\n"
12992 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012993
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012994 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12995 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012996
12997 VkPipelineObj pipe(m_device);
12998 pipe.AddShader(&vs);
12999 pipe.AddShader(&fs);
13000
Chia-I Wu08accc62015-07-07 11:50:03 +080013001 /* set up CB 0, not written */
13002 pipe.AddColorAttachment();
13003 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013004 /* FS writes CB 1, but we don't configure it */
13005
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013006 VkDescriptorSetObj descriptorSet(m_device);
13007 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013008 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013009
Tony Barbour5781e8f2015-08-04 16:23:11 -060013010 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013011
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013012 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013013}
13014
Karl Schultz6addd812016-02-02 17:17:23 -070013015TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013016 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013017 "type of an fragment shader output variable, and the format of the corresponding attachment");
13018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013019
Chris Forbesa36d69e2015-05-25 11:13:44 +120013020 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013022 char const *vsSource = "#version 450\n"
13023 "\n"
13024 "out gl_PerVertex {\n"
13025 " vec4 gl_Position;\n"
13026 "};\n"
13027 "void main(){\n"
13028 " gl_Position = vec4(1);\n"
13029 "}\n";
13030 char const *fsSource = "#version 450\n"
13031 "\n"
13032 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13033 "void main(){\n"
13034 " x = ivec4(1);\n"
13035 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013036
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013037 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13038 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013039
13040 VkPipelineObj pipe(m_device);
13041 pipe.AddShader(&vs);
13042 pipe.AddShader(&fs);
13043
Chia-I Wu08accc62015-07-07 11:50:03 +080013044 /* set up CB 0; type is UNORM by default */
13045 pipe.AddColorAttachment();
13046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013047
Chris Forbesa36d69e2015-05-25 11:13:44 +120013048 VkDescriptorSetObj descriptorSet(m_device);
13049 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013050 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013051
Tony Barbour5781e8f2015-08-04 16:23:11 -060013052 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013053
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013054 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013055}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013056
Karl Schultz6addd812016-02-02 17:17:23 -070013057TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013058 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13059 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013061
Chris Forbes556c76c2015-08-14 12:04:59 +120013062 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013063
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013064 char const *vsSource = "#version 450\n"
13065 "\n"
13066 "out gl_PerVertex {\n"
13067 " vec4 gl_Position;\n"
13068 "};\n"
13069 "void main(){\n"
13070 " gl_Position = vec4(1);\n"
13071 "}\n";
13072 char const *fsSource = "#version 450\n"
13073 "\n"
13074 "layout(location=0) out vec4 x;\n"
13075 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13076 "void main(){\n"
13077 " x = vec4(bar.y);\n"
13078 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013079
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013080 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13081 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013082
Chris Forbes556c76c2015-08-14 12:04:59 +120013083 VkPipelineObj pipe(m_device);
13084 pipe.AddShader(&vs);
13085 pipe.AddShader(&fs);
13086
13087 /* set up CB 0; type is UNORM by default */
13088 pipe.AddColorAttachment();
13089 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13090
13091 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013092 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013093
13094 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13095
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013096 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013097}
13098
Chris Forbes5c59e902016-02-26 16:56:09 +130013099TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013100 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13101 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013103
13104 ASSERT_NO_FATAL_FAILURE(InitState());
13105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013106 char const *vsSource = "#version 450\n"
13107 "\n"
13108 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13109 "out gl_PerVertex {\n"
13110 " vec4 gl_Position;\n"
13111 "};\n"
13112 "void main(){\n"
13113 " gl_Position = vec4(consts.x);\n"
13114 "}\n";
13115 char const *fsSource = "#version 450\n"
13116 "\n"
13117 "layout(location=0) out vec4 x;\n"
13118 "void main(){\n"
13119 " x = vec4(1);\n"
13120 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013121
13122 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13123 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13124
13125 VkPipelineObj pipe(m_device);
13126 pipe.AddShader(&vs);
13127 pipe.AddShader(&fs);
13128
13129 /* set up CB 0; type is UNORM by default */
13130 pipe.AddColorAttachment();
13131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13132
13133 VkDescriptorSetObj descriptorSet(m_device);
13134 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13135
13136 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13137
13138 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013139 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013140}
13141
Chris Forbes3fb17902016-08-22 14:57:55 +120013142TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13143 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13144 "which is not included in the subpass description");
13145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13146 "consumes input attachment index 0 but not provided in subpass");
13147
13148 ASSERT_NO_FATAL_FAILURE(InitState());
13149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013150 char const *vsSource = "#version 450\n"
13151 "\n"
13152 "out gl_PerVertex {\n"
13153 " vec4 gl_Position;\n"
13154 "};\n"
13155 "void main(){\n"
13156 " gl_Position = vec4(1);\n"
13157 "}\n";
13158 char const *fsSource = "#version 450\n"
13159 "\n"
13160 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13161 "layout(location=0) out vec4 color;\n"
13162 "void main() {\n"
13163 " color = subpassLoad(x);\n"
13164 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013165
13166 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13167 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13168
13169 VkPipelineObj pipe(m_device);
13170 pipe.AddShader(&vs);
13171 pipe.AddShader(&fs);
13172 pipe.AddColorAttachment();
13173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013175 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13176 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013177 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013178 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013179 ASSERT_VK_SUCCESS(err);
13180
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013181 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013182 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013183 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013184 ASSERT_VK_SUCCESS(err);
13185
13186 // error here.
13187 pipe.CreateVKPipeline(pl, renderPass());
13188
13189 m_errorMonitor->VerifyFound();
13190
13191 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13192 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13193}
13194
Chris Forbes5a9a0472016-08-22 16:02:09 +120013195TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13196 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13197 "with a format having a different fundamental type");
13198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13199 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13200
13201 ASSERT_NO_FATAL_FAILURE(InitState());
13202
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013203 char const *vsSource = "#version 450\n"
13204 "\n"
13205 "out gl_PerVertex {\n"
13206 " vec4 gl_Position;\n"
13207 "};\n"
13208 "void main(){\n"
13209 " gl_Position = vec4(1);\n"
13210 "}\n";
13211 char const *fsSource = "#version 450\n"
13212 "\n"
13213 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13214 "layout(location=0) out vec4 color;\n"
13215 "void main() {\n"
13216 " color = subpassLoad(x);\n"
13217 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013218
13219 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13220 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13221
13222 VkPipelineObj pipe(m_device);
13223 pipe.AddShader(&vs);
13224 pipe.AddShader(&fs);
13225 pipe.AddColorAttachment();
13226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13227
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013228 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13229 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013230 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013231 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013232 ASSERT_VK_SUCCESS(err);
13233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013234 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013235 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013236 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013237 ASSERT_VK_SUCCESS(err);
13238
13239 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013240 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13241 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13242 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13243 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13244 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 +120013245 };
13246 VkAttachmentReference color = {
13247 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13248 };
13249 VkAttachmentReference input = {
13250 1, VK_IMAGE_LAYOUT_GENERAL,
13251 };
13252
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013253 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013255 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013256 VkRenderPass rp;
13257 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13258 ASSERT_VK_SUCCESS(err);
13259
13260 // error here.
13261 pipe.CreateVKPipeline(pl, rp);
13262
13263 m_errorMonitor->VerifyFound();
13264
13265 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13266 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13267 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13268}
13269
Chris Forbes541f7b02016-08-22 15:30:27 +120013270TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13271 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13272 "which is not included in the subpass description -- array case");
13273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13274 "consumes input attachment index 1 but not provided in subpass");
13275
13276 ASSERT_NO_FATAL_FAILURE(InitState());
13277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013278 char const *vsSource = "#version 450\n"
13279 "\n"
13280 "out gl_PerVertex {\n"
13281 " vec4 gl_Position;\n"
13282 "};\n"
13283 "void main(){\n"
13284 " gl_Position = vec4(1);\n"
13285 "}\n";
13286 char const *fsSource = "#version 450\n"
13287 "\n"
13288 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13289 "layout(location=0) out vec4 color;\n"
13290 "void main() {\n"
13291 " color = subpassLoad(xs[1]);\n"
13292 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013293
13294 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13295 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13296
13297 VkPipelineObj pipe(m_device);
13298 pipe.AddShader(&vs);
13299 pipe.AddShader(&fs);
13300 pipe.AddColorAttachment();
13301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13302
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013303 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13304 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013305 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013306 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013307 ASSERT_VK_SUCCESS(err);
13308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013309 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013310 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013311 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013312 ASSERT_VK_SUCCESS(err);
13313
13314 // error here.
13315 pipe.CreateVKPipeline(pl, renderPass());
13316
13317 m_errorMonitor->VerifyFound();
13318
13319 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13320 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13321}
13322
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013323TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013324 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13325 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013327
13328 ASSERT_NO_FATAL_FAILURE(InitState());
13329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013330 char const *csSource = "#version 450\n"
13331 "\n"
13332 "layout(local_size_x=1) in;\n"
13333 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13334 "void main(){\n"
13335 " x = vec4(1);\n"
13336 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013337
13338 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13339
13340 VkDescriptorSetObj descriptorSet(m_device);
13341 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13342
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013343 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13344 nullptr,
13345 0,
13346 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13347 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13348 descriptorSet.GetPipelineLayout(),
13349 VK_NULL_HANDLE,
13350 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013351
13352 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013353 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013354
13355 m_errorMonitor->VerifyFound();
13356
13357 if (err == VK_SUCCESS) {
13358 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13359 }
13360}
13361
Chris Forbes22a9b092016-07-19 14:34:05 +120013362TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013363 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13364 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13366 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013367
13368 ASSERT_NO_FATAL_FAILURE(InitState());
13369
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013370 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13371 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013372 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013373 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013374 ASSERT_VK_SUCCESS(err);
13375
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013376 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013377 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013378 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013379 ASSERT_VK_SUCCESS(err);
13380
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013381 char const *csSource = "#version 450\n"
13382 "\n"
13383 "layout(local_size_x=1) in;\n"
13384 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13385 "void main() {\n"
13386 " x.x = 1.0f;\n"
13387 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013388 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013390 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13391 nullptr,
13392 0,
13393 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13394 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13395 pl,
13396 VK_NULL_HANDLE,
13397 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013398
13399 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013400 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013401
13402 m_errorMonitor->VerifyFound();
13403
13404 if (err == VK_SUCCESS) {
13405 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13406 }
13407
13408 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13409 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13410}
13411
Chris Forbes50020592016-07-27 13:52:41 +120013412TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13413 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13414 "does not match the dimensionality declared in the shader");
13415
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013416 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 +120013417
13418 ASSERT_NO_FATAL_FAILURE(InitState());
13419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013421 char const *vsSource = "#version 450\n"
13422 "\n"
13423 "out gl_PerVertex { vec4 gl_Position; };\n"
13424 "void main() { gl_Position = vec4(0); }\n";
13425 char const *fsSource = "#version 450\n"
13426 "\n"
13427 "layout(set=0, binding=0) uniform sampler3D s;\n"
13428 "layout(location=0) out vec4 color;\n"
13429 "void main() {\n"
13430 " color = texture(s, vec3(0));\n"
13431 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013432 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13433 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13434
13435 VkPipelineObj pipe(m_device);
13436 pipe.AddShader(&vs);
13437 pipe.AddShader(&fs);
13438 pipe.AddColorAttachment();
13439
13440 VkTextureObj texture(m_device, nullptr);
13441 VkSamplerObj sampler(m_device);
13442
13443 VkDescriptorSetObj descriptorSet(m_device);
13444 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13445 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13446
13447 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13448 ASSERT_VK_SUCCESS(err);
13449
13450 BeginCommandBuffer();
13451
13452 m_commandBuffer->BindPipeline(pipe);
13453 m_commandBuffer->BindDescriptorSet(descriptorSet);
13454
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013455 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013456 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013457 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013458 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13459
13460 // error produced here.
13461 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13462
13463 m_errorMonitor->VerifyFound();
13464
13465 EndCommandBuffer();
13466}
13467
Chris Forbes5533bfc2016-07-27 14:12:34 +120013468TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13469 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13470 "are consumed via singlesample images types in the shader, or vice versa.");
13471
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013473
13474 ASSERT_NO_FATAL_FAILURE(InitState());
13475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13476
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013477 char const *vsSource = "#version 450\n"
13478 "\n"
13479 "out gl_PerVertex { vec4 gl_Position; };\n"
13480 "void main() { gl_Position = vec4(0); }\n";
13481 char const *fsSource = "#version 450\n"
13482 "\n"
13483 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13484 "layout(location=0) out vec4 color;\n"
13485 "void main() {\n"
13486 " color = texelFetch(s, ivec2(0), 0);\n"
13487 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013488 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13489 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13490
13491 VkPipelineObj pipe(m_device);
13492 pipe.AddShader(&vs);
13493 pipe.AddShader(&fs);
13494 pipe.AddColorAttachment();
13495
13496 VkTextureObj texture(m_device, nullptr);
13497 VkSamplerObj sampler(m_device);
13498
13499 VkDescriptorSetObj descriptorSet(m_device);
13500 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13501 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13502
13503 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13504 ASSERT_VK_SUCCESS(err);
13505
13506 BeginCommandBuffer();
13507
13508 m_commandBuffer->BindPipeline(pipe);
13509 m_commandBuffer->BindDescriptorSet(descriptorSet);
13510
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013511 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013512 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013513 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013514 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13515
13516 // error produced here.
13517 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13518
13519 m_errorMonitor->VerifyFound();
13520
13521 EndCommandBuffer();
13522}
13523
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013524#endif // SHADER_CHECKER_TESTS
13525
13526#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013527TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013529
13530 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013531
13532 // Create an image
13533 VkImage image;
13534
Karl Schultz6addd812016-02-02 17:17:23 -070013535 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13536 const int32_t tex_width = 32;
13537 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013538
13539 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013540 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13541 image_create_info.pNext = NULL;
13542 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13543 image_create_info.format = tex_format;
13544 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013545 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013546 image_create_info.extent.depth = 1;
13547 image_create_info.mipLevels = 1;
13548 image_create_info.arrayLayers = 1;
13549 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13550 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13551 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13552 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013553
13554 // Introduce error by sending down a bogus width extent
13555 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013556 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013557
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013558 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013559}
13560
Mark Youngc48c4c12016-04-11 14:26:49 -060013561TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13563 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013564
13565 ASSERT_NO_FATAL_FAILURE(InitState());
13566
13567 // Create an image
13568 VkImage image;
13569
13570 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13571 const int32_t tex_width = 32;
13572 const int32_t tex_height = 32;
13573
13574 VkImageCreateInfo image_create_info = {};
13575 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13576 image_create_info.pNext = NULL;
13577 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13578 image_create_info.format = tex_format;
13579 image_create_info.extent.width = tex_width;
13580 image_create_info.extent.height = tex_height;
13581 image_create_info.extent.depth = 1;
13582 image_create_info.mipLevels = 1;
13583 image_create_info.arrayLayers = 1;
13584 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13585 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13586 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13587 image_create_info.flags = 0;
13588
13589 // Introduce error by sending down a bogus width extent
13590 image_create_info.extent.width = 0;
13591 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13592
13593 m_errorMonitor->VerifyFound();
13594}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013595#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013596
Tobin Ehliscde08892015-09-22 10:11:37 -060013597#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070013598
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013599TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13600 TEST_DESCRIPTION("Create a render pass with an attachment description "
13601 "format set to VK_FORMAT_UNDEFINED");
13602
13603 ASSERT_NO_FATAL_FAILURE(InitState());
13604 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13605
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013607
13608 VkAttachmentReference color_attach = {};
13609 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13610 color_attach.attachment = 0;
13611 VkSubpassDescription subpass = {};
13612 subpass.colorAttachmentCount = 1;
13613 subpass.pColorAttachments = &color_attach;
13614
13615 VkRenderPassCreateInfo rpci = {};
13616 rpci.subpassCount = 1;
13617 rpci.pSubpasses = &subpass;
13618 rpci.attachmentCount = 1;
13619 VkAttachmentDescription attach_desc = {};
13620 attach_desc.format = VK_FORMAT_UNDEFINED;
13621 rpci.pAttachments = &attach_desc;
13622 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13623 VkRenderPass rp;
13624 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13625
13626 m_errorMonitor->VerifyFound();
13627
13628 if (result == VK_SUCCESS) {
13629 vkDestroyRenderPass(m_device->device(), rp, NULL);
13630 }
13631}
13632
Karl Schultz6addd812016-02-02 17:17:23 -070013633TEST_F(VkLayerTest, InvalidImageView) {
13634 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013635
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013637
Tobin Ehliscde08892015-09-22 10:11:37 -060013638 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013639
Mike Stroyana3082432015-09-25 13:39:21 -060013640 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013641 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013642
Karl Schultz6addd812016-02-02 17:17:23 -070013643 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13644 const int32_t tex_width = 32;
13645 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013646
13647 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013648 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13649 image_create_info.pNext = NULL;
13650 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13651 image_create_info.format = tex_format;
13652 image_create_info.extent.width = tex_width;
13653 image_create_info.extent.height = tex_height;
13654 image_create_info.extent.depth = 1;
13655 image_create_info.mipLevels = 1;
13656 image_create_info.arrayLayers = 1;
13657 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13658 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13659 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13660 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013661
Chia-I Wuf7458c52015-10-26 21:10:41 +080013662 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013663 ASSERT_VK_SUCCESS(err);
13664
13665 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013666 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13667 image_view_create_info.image = image;
13668 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13669 image_view_create_info.format = tex_format;
13670 image_view_create_info.subresourceRange.layerCount = 1;
13671 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13672 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013673 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013674
13675 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013676 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013677
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013678 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013679 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013680}
Mike Stroyana3082432015-09-25 13:39:21 -060013681
Mark Youngd339ba32016-05-30 13:28:35 -060013682TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13683 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013685 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013686
13687 ASSERT_NO_FATAL_FAILURE(InitState());
13688
13689 // Create an image and try to create a view with no memory backing the image
13690 VkImage image;
13691
13692 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13693 const int32_t tex_width = 32;
13694 const int32_t tex_height = 32;
13695
13696 VkImageCreateInfo image_create_info = {};
13697 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13698 image_create_info.pNext = NULL;
13699 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13700 image_create_info.format = tex_format;
13701 image_create_info.extent.width = tex_width;
13702 image_create_info.extent.height = tex_height;
13703 image_create_info.extent.depth = 1;
13704 image_create_info.mipLevels = 1;
13705 image_create_info.arrayLayers = 1;
13706 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13707 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13708 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13709 image_create_info.flags = 0;
13710
13711 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13712 ASSERT_VK_SUCCESS(err);
13713
13714 VkImageViewCreateInfo image_view_create_info = {};
13715 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13716 image_view_create_info.image = image;
13717 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13718 image_view_create_info.format = tex_format;
13719 image_view_create_info.subresourceRange.layerCount = 1;
13720 image_view_create_info.subresourceRange.baseMipLevel = 0;
13721 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013722 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013723
13724 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013725 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013726
13727 m_errorMonitor->VerifyFound();
13728 vkDestroyImage(m_device->device(), image, NULL);
13729 // If last error is success, it still created the view, so delete it.
13730 if (err == VK_SUCCESS) {
13731 vkDestroyImageView(m_device->device(), view, NULL);
13732 }
Mark Youngd339ba32016-05-30 13:28:35 -060013733}
13734
Karl Schultz6addd812016-02-02 17:17:23 -070013735TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013736 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013738 "formats must have ONLY the "
13739 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13741 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013742
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013743 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013744
Karl Schultz6addd812016-02-02 17:17:23 -070013745 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013746 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013747 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013748 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013749
13750 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013751 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013752 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013753 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13754 image_view_create_info.format = tex_format;
13755 image_view_create_info.subresourceRange.baseMipLevel = 0;
13756 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013757 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013758 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013759 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013760
13761 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013762 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013763
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013764 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013765}
13766
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013767TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013768 VkResult err;
13769 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013770
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13772 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013773
Mike Stroyana3082432015-09-25 13:39:21 -060013774 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013775
13776 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013777 VkImage srcImage;
13778 VkImage dstImage;
13779 VkDeviceMemory srcMem;
13780 VkDeviceMemory destMem;
13781 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013782
13783 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013784 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13785 image_create_info.pNext = NULL;
13786 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13787 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13788 image_create_info.extent.width = 32;
13789 image_create_info.extent.height = 32;
13790 image_create_info.extent.depth = 1;
13791 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013792 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070013793 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13794 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13795 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13796 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013797
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013798 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013799 ASSERT_VK_SUCCESS(err);
13800
Mark Lobodzinski867787a2016-10-14 11:49:55 -060013801 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013802 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013803 ASSERT_VK_SUCCESS(err);
13804
13805 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013806 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013807 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13808 memAlloc.pNext = NULL;
13809 memAlloc.allocationSize = 0;
13810 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013811
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060013812 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013813 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013814 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060013815 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013816 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013817 ASSERT_VK_SUCCESS(err);
13818
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013819 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013820 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013821 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013822 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013823 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013824 ASSERT_VK_SUCCESS(err);
13825
13826 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
13827 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013828 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013829 ASSERT_VK_SUCCESS(err);
13830
13831 BeginCommandBuffer();
13832 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013833 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060013834 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060013835 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013836 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060013837 copyRegion.srcOffset.x = 0;
13838 copyRegion.srcOffset.y = 0;
13839 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013840 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013841 copyRegion.dstSubresource.mipLevel = 0;
13842 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013843 // Introduce failure by forcing the dst layerCount to differ from src
13844 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013845 copyRegion.dstOffset.x = 0;
13846 copyRegion.dstOffset.y = 0;
13847 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013848 copyRegion.extent.width = 1;
13849 copyRegion.extent.height = 1;
13850 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013851 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060013852 EndCommandBuffer();
13853
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013854 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060013855
Chia-I Wuf7458c52015-10-26 21:10:41 +080013856 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013857 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080013858 vkFreeMemory(m_device->device(), srcMem, NULL);
13859 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060013860}
13861
Tony Barbourd6673642016-05-05 14:46:39 -060013862TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
13863
13864 TEST_DESCRIPTION("Creating images with unsuported formats ");
13865
13866 ASSERT_NO_FATAL_FAILURE(InitState());
13867 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13868 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013869 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 -060013870 VK_IMAGE_TILING_OPTIMAL, 0);
13871 ASSERT_TRUE(image.initialized());
13872
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013873 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
13874 VkImageCreateInfo image_create_info;
13875 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13876 image_create_info.pNext = NULL;
13877 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13878 image_create_info.format = VK_FORMAT_UNDEFINED;
13879 image_create_info.extent.width = 32;
13880 image_create_info.extent.height = 32;
13881 image_create_info.extent.depth = 1;
13882 image_create_info.mipLevels = 1;
13883 image_create_info.arrayLayers = 1;
13884 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13885 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13886 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13887 image_create_info.flags = 0;
13888
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13890 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013891
13892 VkImage localImage;
13893 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
13894 m_errorMonitor->VerifyFound();
13895
Tony Barbourd6673642016-05-05 14:46:39 -060013896 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013897 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060013898 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
13899 VkFormat format = static_cast<VkFormat>(f);
13900 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013901 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060013902 unsupported = format;
13903 break;
13904 }
13905 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013906
Tony Barbourd6673642016-05-05 14:46:39 -060013907 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060013908 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060013910
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013911 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060013912 m_errorMonitor->VerifyFound();
13913 }
13914}
13915
13916TEST_F(VkLayerTest, ImageLayerViewTests) {
13917 VkResult ret;
13918 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
13919
13920 ASSERT_NO_FATAL_FAILURE(InitState());
13921
13922 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013923 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 -060013924 VK_IMAGE_TILING_OPTIMAL, 0);
13925 ASSERT_TRUE(image.initialized());
13926
13927 VkImageView imgView;
13928 VkImageViewCreateInfo imgViewInfo = {};
13929 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13930 imgViewInfo.image = image.handle();
13931 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
13932 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13933 imgViewInfo.subresourceRange.layerCount = 1;
13934 imgViewInfo.subresourceRange.baseMipLevel = 0;
13935 imgViewInfo.subresourceRange.levelCount = 1;
13936 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13937
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060013939 // View can't have baseMipLevel >= image's mipLevels - Expect
13940 // VIEW_CREATE_ERROR
13941 imgViewInfo.subresourceRange.baseMipLevel = 1;
13942 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13943 m_errorMonitor->VerifyFound();
13944 imgViewInfo.subresourceRange.baseMipLevel = 0;
13945
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060013947 // View can't have baseArrayLayer >= image's arraySize - Expect
13948 // VIEW_CREATE_ERROR
13949 imgViewInfo.subresourceRange.baseArrayLayer = 1;
13950 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13951 m_errorMonitor->VerifyFound();
13952 imgViewInfo.subresourceRange.baseArrayLayer = 0;
13953
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13955 "pCreateInfo->subresourceRange."
13956 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060013957 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
13958 imgViewInfo.subresourceRange.levelCount = 0;
13959 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13960 m_errorMonitor->VerifyFound();
13961 imgViewInfo.subresourceRange.levelCount = 1;
13962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13964 "pCreateInfo->subresourceRange."
13965 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013966 m_errorMonitor->SetDesiredFailureMsg(
13967 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13968 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060013969 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
13970 imgViewInfo.subresourceRange.layerCount = 0;
13971 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13972 m_errorMonitor->VerifyFound();
13973 imgViewInfo.subresourceRange.layerCount = 1;
13974
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13977 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13978 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013979 // Can't use depth format for view into color image - Expect INVALID_FORMAT
13980 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
13981 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13982 m_errorMonitor->VerifyFound();
13983 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13986 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13987 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013988 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
13989 // VIEW_CREATE_ERROR
13990 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
13991 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13992 m_errorMonitor->VerifyFound();
13993 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13994
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
13996 "differing formats but they must be "
13997 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013998 // TODO: Update framework to easily passing mutable flag into ImageObj init
13999 // For now just allowing image for this one test to not have memory bound
14000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14001 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014002 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14003 // VIEW_CREATE_ERROR
14004 VkImageCreateInfo mutImgInfo = image.create_info();
14005 VkImage mutImage;
14006 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014007 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014008 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14009 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14010 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14011 ASSERT_VK_SUCCESS(ret);
14012 imgViewInfo.image = mutImage;
14013 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14014 m_errorMonitor->VerifyFound();
14015 imgViewInfo.image = image.handle();
14016 vkDestroyImage(m_device->handle(), mutImage, NULL);
14017}
14018
14019TEST_F(VkLayerTest, MiscImageLayerTests) {
14020
14021 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14022
14023 ASSERT_NO_FATAL_FAILURE(InitState());
14024
14025 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014026 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 -060014027 VK_IMAGE_TILING_OPTIMAL, 0);
14028 ASSERT_TRUE(image.initialized());
14029
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060014031 vk_testing::Buffer buffer;
14032 VkMemoryPropertyFlags reqs = 0;
14033 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14034 VkBufferImageCopy region = {};
14035 region.bufferRowLength = 128;
14036 region.bufferImageHeight = 128;
14037 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14038 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
14039 region.imageSubresource.layerCount = 0;
14040 region.imageExtent.height = 4;
14041 region.imageExtent.width = 4;
14042 region.imageExtent.depth = 1;
14043 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014044 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14045 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014046 m_errorMonitor->VerifyFound();
14047 region.imageSubresource.layerCount = 1;
14048
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014049 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14050 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14051 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
14053 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14054 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014055 m_errorMonitor->VerifyFound();
14056
14057 // BufferOffset must be a multiple of 4
14058 // Introduce failure by setting bufferOffset to a value not divisible by 4
14059 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
14061 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14062 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014063 m_errorMonitor->VerifyFound();
14064
14065 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14066 region.bufferOffset = 0;
14067 region.imageExtent.height = 128;
14068 region.imageExtent.width = 128;
14069 // Introduce failure by setting bufferRowLength > 0 but less than width
14070 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14072 "must be zero or greater-than-or-equal-to imageExtent.width");
14073 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14074 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014075 m_errorMonitor->VerifyFound();
14076
14077 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14078 region.bufferRowLength = 128;
14079 // Introduce failure by setting bufferRowHeight > 0 but less than height
14080 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14082 "must be zero or greater-than-or-equal-to imageExtent.height");
14083 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14084 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014085 m_errorMonitor->VerifyFound();
14086
14087 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
14089 "specify only COLOR or DEPTH or "
14090 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060014091 // Expect MISMATCHED_IMAGE_ASPECT
14092 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014093 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14094 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014095 m_errorMonitor->VerifyFound();
14096 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14099 "If the format of srcImage is a depth, stencil, depth stencil or "
14100 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014101 // Expect INVALID_FILTER
14102 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014103 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 -060014104 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014105 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 -060014106 VkImageBlit blitRegion = {};
14107 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14108 blitRegion.srcSubresource.baseArrayLayer = 0;
14109 blitRegion.srcSubresource.layerCount = 1;
14110 blitRegion.srcSubresource.mipLevel = 0;
14111 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14112 blitRegion.dstSubresource.baseArrayLayer = 0;
14113 blitRegion.dstSubresource.layerCount = 1;
14114 blitRegion.dstSubresource.mipLevel = 0;
14115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014116 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14117 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014118 m_errorMonitor->VerifyFound();
14119
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014120 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14122 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14123 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014124 m_errorMonitor->VerifyFound();
14125
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014127 VkImageMemoryBarrier img_barrier;
14128 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14129 img_barrier.pNext = NULL;
14130 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14131 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14132 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14133 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14134 img_barrier.image = image.handle();
14135 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14136 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14137 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14138 img_barrier.subresourceRange.baseArrayLayer = 0;
14139 img_barrier.subresourceRange.baseMipLevel = 0;
14140 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14141 img_barrier.subresourceRange.layerCount = 0;
14142 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014143 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14144 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014145 m_errorMonitor->VerifyFound();
14146 img_barrier.subresourceRange.layerCount = 1;
14147}
14148
14149TEST_F(VkLayerTest, ImageFormatLimits) {
14150
14151 TEST_DESCRIPTION("Exceed the limits of image format ");
14152
Cody Northropc31a84f2016-08-22 10:41:47 -060014153 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014155 VkImageCreateInfo image_create_info = {};
14156 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14157 image_create_info.pNext = NULL;
14158 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14159 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14160 image_create_info.extent.width = 32;
14161 image_create_info.extent.height = 32;
14162 image_create_info.extent.depth = 1;
14163 image_create_info.mipLevels = 1;
14164 image_create_info.arrayLayers = 1;
14165 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14166 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14167 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14168 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14169 image_create_info.flags = 0;
14170
14171 VkImage nullImg;
14172 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014173 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14174 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014175 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14176 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14177 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14178 m_errorMonitor->VerifyFound();
14179 image_create_info.extent.depth = 1;
14180
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014182 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14183 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14184 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14185 m_errorMonitor->VerifyFound();
14186 image_create_info.mipLevels = 1;
14187
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014189 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14190 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14191 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14192 m_errorMonitor->VerifyFound();
14193 image_create_info.arrayLayers = 1;
14194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014196 int samples = imgFmtProps.sampleCounts >> 1;
14197 image_create_info.samples = (VkSampleCountFlagBits)samples;
14198 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14199 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14200 m_errorMonitor->VerifyFound();
14201 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14202
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14204 "VK_IMAGE_LAYOUT_UNDEFINED or "
14205 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014206 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14207 // Expect INVALID_LAYOUT
14208 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14209 m_errorMonitor->VerifyFound();
14210 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14211}
14212
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014213TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14214
14215 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014217
14218 ASSERT_NO_FATAL_FAILURE(InitState());
14219
14220 VkImageObj src_image(m_device);
14221 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14222 VkImageObj dst_image(m_device);
14223 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14224
14225 BeginCommandBuffer();
14226 VkImageCopy copy_region;
14227 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14228 copy_region.srcSubresource.mipLevel = 0;
14229 copy_region.srcSubresource.baseArrayLayer = 0;
14230 copy_region.srcSubresource.layerCount = 0;
14231 copy_region.srcOffset.x = 0;
14232 copy_region.srcOffset.y = 0;
14233 copy_region.srcOffset.z = 0;
14234 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14235 copy_region.dstSubresource.mipLevel = 0;
14236 copy_region.dstSubresource.baseArrayLayer = 0;
14237 copy_region.dstSubresource.layerCount = 0;
14238 copy_region.dstOffset.x = 0;
14239 copy_region.dstOffset.y = 0;
14240 copy_region.dstOffset.z = 0;
14241 copy_region.extent.width = 64;
14242 copy_region.extent.height = 64;
14243 copy_region.extent.depth = 1;
14244 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14245 &copy_region);
14246 EndCommandBuffer();
14247
14248 m_errorMonitor->VerifyFound();
14249}
14250
14251TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14252
14253 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014255
14256 ASSERT_NO_FATAL_FAILURE(InitState());
14257
14258 VkImageObj src_image(m_device);
14259 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14260 VkImageObj dst_image(m_device);
14261 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14262
14263 BeginCommandBuffer();
14264 VkImageCopy copy_region;
14265 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14266 copy_region.srcSubresource.mipLevel = 0;
14267 copy_region.srcSubresource.baseArrayLayer = 0;
14268 copy_region.srcSubresource.layerCount = 0;
14269 copy_region.srcOffset.x = 0;
14270 copy_region.srcOffset.y = 0;
14271 copy_region.srcOffset.z = 0;
14272 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14273 copy_region.dstSubresource.mipLevel = 0;
14274 copy_region.dstSubresource.baseArrayLayer = 0;
14275 copy_region.dstSubresource.layerCount = 0;
14276 copy_region.dstOffset.x = 0;
14277 copy_region.dstOffset.y = 0;
14278 copy_region.dstOffset.z = 0;
14279 copy_region.extent.width = 64;
14280 copy_region.extent.height = 64;
14281 copy_region.extent.depth = 1;
14282 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14283 &copy_region);
14284 EndCommandBuffer();
14285
14286 m_errorMonitor->VerifyFound();
14287}
14288
Karl Schultz6addd812016-02-02 17:17:23 -070014289TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014290 VkResult err;
14291 bool pass;
14292
14293 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14295 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014296
14297 ASSERT_NO_FATAL_FAILURE(InitState());
14298
14299 // Create two images of different types and try to copy between them
14300 VkImage srcImage;
14301 VkImage dstImage;
14302 VkDeviceMemory srcMem;
14303 VkDeviceMemory destMem;
14304 VkMemoryRequirements memReqs;
14305
14306 VkImageCreateInfo image_create_info = {};
14307 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14308 image_create_info.pNext = NULL;
14309 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14310 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14311 image_create_info.extent.width = 32;
14312 image_create_info.extent.height = 32;
14313 image_create_info.extent.depth = 1;
14314 image_create_info.mipLevels = 1;
14315 image_create_info.arrayLayers = 1;
14316 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14317 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14318 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14319 image_create_info.flags = 0;
14320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014321 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014322 ASSERT_VK_SUCCESS(err);
14323
14324 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14325 // Introduce failure by creating second image with a different-sized format.
14326 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014328 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014329 ASSERT_VK_SUCCESS(err);
14330
14331 // Allocate memory
14332 VkMemoryAllocateInfo memAlloc = {};
14333 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14334 memAlloc.pNext = NULL;
14335 memAlloc.allocationSize = 0;
14336 memAlloc.memoryTypeIndex = 0;
14337
14338 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14339 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014340 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014341 ASSERT_TRUE(pass);
14342 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14343 ASSERT_VK_SUCCESS(err);
14344
14345 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14346 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014347 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014348 ASSERT_TRUE(pass);
14349 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14350 ASSERT_VK_SUCCESS(err);
14351
14352 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14353 ASSERT_VK_SUCCESS(err);
14354 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14355 ASSERT_VK_SUCCESS(err);
14356
14357 BeginCommandBuffer();
14358 VkImageCopy copyRegion;
14359 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14360 copyRegion.srcSubresource.mipLevel = 0;
14361 copyRegion.srcSubresource.baseArrayLayer = 0;
14362 copyRegion.srcSubresource.layerCount = 0;
14363 copyRegion.srcOffset.x = 0;
14364 copyRegion.srcOffset.y = 0;
14365 copyRegion.srcOffset.z = 0;
14366 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14367 copyRegion.dstSubresource.mipLevel = 0;
14368 copyRegion.dstSubresource.baseArrayLayer = 0;
14369 copyRegion.dstSubresource.layerCount = 0;
14370 copyRegion.dstOffset.x = 0;
14371 copyRegion.dstOffset.y = 0;
14372 copyRegion.dstOffset.z = 0;
14373 copyRegion.extent.width = 1;
14374 copyRegion.extent.height = 1;
14375 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014376 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014377 EndCommandBuffer();
14378
14379 m_errorMonitor->VerifyFound();
14380
14381 vkDestroyImage(m_device->device(), srcImage, NULL);
14382 vkDestroyImage(m_device->device(), dstImage, NULL);
14383 vkFreeMemory(m_device->device(), srcMem, NULL);
14384 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014385}
14386
Karl Schultz6addd812016-02-02 17:17:23 -070014387TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14388 VkResult err;
14389 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014390
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014391 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14393 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014394
Mike Stroyana3082432015-09-25 13:39:21 -060014395 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014396
14397 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014398 VkImage srcImage;
14399 VkImage dstImage;
14400 VkDeviceMemory srcMem;
14401 VkDeviceMemory destMem;
14402 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014403
14404 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014405 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14406 image_create_info.pNext = NULL;
14407 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14408 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14409 image_create_info.extent.width = 32;
14410 image_create_info.extent.height = 32;
14411 image_create_info.extent.depth = 1;
14412 image_create_info.mipLevels = 1;
14413 image_create_info.arrayLayers = 1;
14414 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14415 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14416 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14417 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014418
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014419 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014420 ASSERT_VK_SUCCESS(err);
14421
Karl Schultzbdb75952016-04-19 11:36:49 -060014422 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14423
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014424 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014425 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014426 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014427 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014428
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014429 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014430 ASSERT_VK_SUCCESS(err);
14431
14432 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014433 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014434 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14435 memAlloc.pNext = NULL;
14436 memAlloc.allocationSize = 0;
14437 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014438
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014439 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014440 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014441 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014442 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014443 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014444 ASSERT_VK_SUCCESS(err);
14445
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014446 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014447 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014448 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014449 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014450 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014451 ASSERT_VK_SUCCESS(err);
14452
14453 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14454 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014455 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014456 ASSERT_VK_SUCCESS(err);
14457
14458 BeginCommandBuffer();
14459 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014460 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014461 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014462 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014463 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014464 copyRegion.srcOffset.x = 0;
14465 copyRegion.srcOffset.y = 0;
14466 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014467 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014468 copyRegion.dstSubresource.mipLevel = 0;
14469 copyRegion.dstSubresource.baseArrayLayer = 0;
14470 copyRegion.dstSubresource.layerCount = 0;
14471 copyRegion.dstOffset.x = 0;
14472 copyRegion.dstOffset.y = 0;
14473 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014474 copyRegion.extent.width = 1;
14475 copyRegion.extent.height = 1;
14476 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014477 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014478 EndCommandBuffer();
14479
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014480 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014481
Chia-I Wuf7458c52015-10-26 21:10:41 +080014482 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014483 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014484 vkFreeMemory(m_device->device(), srcMem, NULL);
14485 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014486}
14487
Karl Schultz6addd812016-02-02 17:17:23 -070014488TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14489 VkResult err;
14490 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14493 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014494
Mike Stroyana3082432015-09-25 13:39:21 -060014495 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014496
14497 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014498 VkImage srcImage;
14499 VkImage dstImage;
14500 VkDeviceMemory srcMem;
14501 VkDeviceMemory destMem;
14502 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014503
14504 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014505 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14506 image_create_info.pNext = NULL;
14507 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14508 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14509 image_create_info.extent.width = 32;
14510 image_create_info.extent.height = 1;
14511 image_create_info.extent.depth = 1;
14512 image_create_info.mipLevels = 1;
14513 image_create_info.arrayLayers = 1;
14514 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14515 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14516 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14517 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014518
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014519 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014520 ASSERT_VK_SUCCESS(err);
14521
Karl Schultz6addd812016-02-02 17:17:23 -070014522 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014523
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014524 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014525 ASSERT_VK_SUCCESS(err);
14526
14527 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014528 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014529 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14530 memAlloc.pNext = NULL;
14531 memAlloc.allocationSize = 0;
14532 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014533
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014534 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014535 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014536 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014537 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014538 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014539 ASSERT_VK_SUCCESS(err);
14540
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014541 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014542 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014543 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014544 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014545 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014546 ASSERT_VK_SUCCESS(err);
14547
14548 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14549 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014550 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014551 ASSERT_VK_SUCCESS(err);
14552
14553 BeginCommandBuffer();
14554 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014555 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14556 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014557 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014558 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014559 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014560 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014561 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014562 resolveRegion.srcOffset.x = 0;
14563 resolveRegion.srcOffset.y = 0;
14564 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014565 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014566 resolveRegion.dstSubresource.mipLevel = 0;
14567 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014568 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014569 resolveRegion.dstOffset.x = 0;
14570 resolveRegion.dstOffset.y = 0;
14571 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014572 resolveRegion.extent.width = 1;
14573 resolveRegion.extent.height = 1;
14574 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014575 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014576 EndCommandBuffer();
14577
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014578 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014579
Chia-I Wuf7458c52015-10-26 21:10:41 +080014580 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014581 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014582 vkFreeMemory(m_device->device(), srcMem, NULL);
14583 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014584}
14585
Karl Schultz6addd812016-02-02 17:17:23 -070014586TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14587 VkResult err;
14588 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014589
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14591 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014592
Mike Stroyana3082432015-09-25 13:39:21 -060014593 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014594
Chris Forbesa7530692016-05-08 12:35:39 +120014595 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014596 VkImage srcImage;
14597 VkImage dstImage;
14598 VkDeviceMemory srcMem;
14599 VkDeviceMemory destMem;
14600 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014601
14602 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014603 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14604 image_create_info.pNext = NULL;
14605 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14606 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14607 image_create_info.extent.width = 32;
14608 image_create_info.extent.height = 1;
14609 image_create_info.extent.depth = 1;
14610 image_create_info.mipLevels = 1;
14611 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014612 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014613 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14614 // Note: Some implementations expect color attachment usage for any
14615 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014616 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014617 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014618
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014619 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014620 ASSERT_VK_SUCCESS(err);
14621
Karl Schultz6addd812016-02-02 17:17:23 -070014622 // Note: Some implementations expect color attachment usage for any
14623 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014624 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014625
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014626 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014627 ASSERT_VK_SUCCESS(err);
14628
14629 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014630 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014631 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14632 memAlloc.pNext = NULL;
14633 memAlloc.allocationSize = 0;
14634 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014635
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014636 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014637 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014638 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014639 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014640 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014641 ASSERT_VK_SUCCESS(err);
14642
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014643 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014644 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014645 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014646 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014647 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014648 ASSERT_VK_SUCCESS(err);
14649
14650 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14651 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014652 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014653 ASSERT_VK_SUCCESS(err);
14654
14655 BeginCommandBuffer();
14656 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014657 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14658 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014659 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014660 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014661 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014662 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014663 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014664 resolveRegion.srcOffset.x = 0;
14665 resolveRegion.srcOffset.y = 0;
14666 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014667 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014668 resolveRegion.dstSubresource.mipLevel = 0;
14669 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014670 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014671 resolveRegion.dstOffset.x = 0;
14672 resolveRegion.dstOffset.y = 0;
14673 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014674 resolveRegion.extent.width = 1;
14675 resolveRegion.extent.height = 1;
14676 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014677 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014678 EndCommandBuffer();
14679
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014680 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014681
Chia-I Wuf7458c52015-10-26 21:10:41 +080014682 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014683 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014684 vkFreeMemory(m_device->device(), srcMem, NULL);
14685 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014686}
14687
Karl Schultz6addd812016-02-02 17:17:23 -070014688TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14689 VkResult err;
14690 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014691
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14693 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014694
Mike Stroyana3082432015-09-25 13:39:21 -060014695 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014696
14697 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014698 VkImage srcImage;
14699 VkImage dstImage;
14700 VkDeviceMemory srcMem;
14701 VkDeviceMemory destMem;
14702 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014703
14704 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014705 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14706 image_create_info.pNext = NULL;
14707 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14708 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14709 image_create_info.extent.width = 32;
14710 image_create_info.extent.height = 1;
14711 image_create_info.extent.depth = 1;
14712 image_create_info.mipLevels = 1;
14713 image_create_info.arrayLayers = 1;
14714 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14715 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14716 // Note: Some implementations expect color attachment usage for any
14717 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014718 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014719 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014720
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014721 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014722 ASSERT_VK_SUCCESS(err);
14723
Karl Schultz6addd812016-02-02 17:17:23 -070014724 // Set format to something other than source image
14725 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14726 // Note: Some implementations expect color attachment usage for any
14727 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014728 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014729 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014730
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014731 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014732 ASSERT_VK_SUCCESS(err);
14733
14734 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014735 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014736 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14737 memAlloc.pNext = NULL;
14738 memAlloc.allocationSize = 0;
14739 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014740
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014741 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014742 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014743 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014744 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014745 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014746 ASSERT_VK_SUCCESS(err);
14747
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014748 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014749 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014750 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014751 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014752 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014753 ASSERT_VK_SUCCESS(err);
14754
14755 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14756 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014757 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014758 ASSERT_VK_SUCCESS(err);
14759
14760 BeginCommandBuffer();
14761 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014762 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14763 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014764 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014765 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014766 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014767 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014768 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014769 resolveRegion.srcOffset.x = 0;
14770 resolveRegion.srcOffset.y = 0;
14771 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014772 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014773 resolveRegion.dstSubresource.mipLevel = 0;
14774 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014775 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014776 resolveRegion.dstOffset.x = 0;
14777 resolveRegion.dstOffset.y = 0;
14778 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014779 resolveRegion.extent.width = 1;
14780 resolveRegion.extent.height = 1;
14781 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014782 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014783 EndCommandBuffer();
14784
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014785 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014786
Chia-I Wuf7458c52015-10-26 21:10:41 +080014787 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014788 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014789 vkFreeMemory(m_device->device(), srcMem, NULL);
14790 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014791}
14792
Karl Schultz6addd812016-02-02 17:17:23 -070014793TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
14794 VkResult err;
14795 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014796
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14798 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014799
Mike Stroyana3082432015-09-25 13:39:21 -060014800 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014801
14802 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014803 VkImage srcImage;
14804 VkImage dstImage;
14805 VkDeviceMemory srcMem;
14806 VkDeviceMemory destMem;
14807 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014808
14809 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014810 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14811 image_create_info.pNext = NULL;
14812 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14813 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14814 image_create_info.extent.width = 32;
14815 image_create_info.extent.height = 1;
14816 image_create_info.extent.depth = 1;
14817 image_create_info.mipLevels = 1;
14818 image_create_info.arrayLayers = 1;
14819 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14820 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14821 // Note: Some implementations expect color attachment usage for any
14822 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014823 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014824 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014825
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014826 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014827 ASSERT_VK_SUCCESS(err);
14828
Karl Schultz6addd812016-02-02 17:17:23 -070014829 image_create_info.imageType = VK_IMAGE_TYPE_1D;
14830 // Note: Some implementations expect color attachment usage for any
14831 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014832 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014833 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014834
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014835 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014836 ASSERT_VK_SUCCESS(err);
14837
14838 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014839 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014840 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14841 memAlloc.pNext = NULL;
14842 memAlloc.allocationSize = 0;
14843 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014844
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014845 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014846 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014847 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014848 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014849 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014850 ASSERT_VK_SUCCESS(err);
14851
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014852 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014853 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014854 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014855 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014856 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014857 ASSERT_VK_SUCCESS(err);
14858
14859 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14860 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014861 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014862 ASSERT_VK_SUCCESS(err);
14863
14864 BeginCommandBuffer();
14865 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014866 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14867 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014868 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014869 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014870 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014871 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014872 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014873 resolveRegion.srcOffset.x = 0;
14874 resolveRegion.srcOffset.y = 0;
14875 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014876 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014877 resolveRegion.dstSubresource.mipLevel = 0;
14878 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014879 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014880 resolveRegion.dstOffset.x = 0;
14881 resolveRegion.dstOffset.y = 0;
14882 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014883 resolveRegion.extent.width = 1;
14884 resolveRegion.extent.height = 1;
14885 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014886 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014887 EndCommandBuffer();
14888
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014889 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014890
Chia-I Wuf7458c52015-10-26 21:10:41 +080014891 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014892 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014893 vkFreeMemory(m_device->device(), srcMem, NULL);
14894 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014895}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014896
Karl Schultz6addd812016-02-02 17:17:23 -070014897TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014898 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070014899 // to using a DS format, then cause it to hit error due to COLOR_BIT not
14900 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014901 // The image format check comes 2nd in validation so we trigger it first,
14902 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070014903 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014904
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14906 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014907
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014908 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014909
Chia-I Wu1b99bb22015-10-27 19:25:11 +080014910 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014911 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14912 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014913
14914 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014915 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14916 ds_pool_ci.pNext = NULL;
14917 ds_pool_ci.maxSets = 1;
14918 ds_pool_ci.poolSizeCount = 1;
14919 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014920
14921 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014922 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014923 ASSERT_VK_SUCCESS(err);
14924
14925 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014926 dsl_binding.binding = 0;
14927 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14928 dsl_binding.descriptorCount = 1;
14929 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
14930 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014931
14932 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014933 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14934 ds_layout_ci.pNext = NULL;
14935 ds_layout_ci.bindingCount = 1;
14936 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014937 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014938 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014939 ASSERT_VK_SUCCESS(err);
14940
14941 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014942 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080014943 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070014944 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014945 alloc_info.descriptorPool = ds_pool;
14946 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014947 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014948 ASSERT_VK_SUCCESS(err);
14949
Karl Schultz6addd812016-02-02 17:17:23 -070014950 VkImage image_bad;
14951 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014952 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060014953 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014954 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070014955 const int32_t tex_width = 32;
14956 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014957
14958 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014959 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14960 image_create_info.pNext = NULL;
14961 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14962 image_create_info.format = tex_format_bad;
14963 image_create_info.extent.width = tex_width;
14964 image_create_info.extent.height = tex_height;
14965 image_create_info.extent.depth = 1;
14966 image_create_info.mipLevels = 1;
14967 image_create_info.arrayLayers = 1;
14968 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14969 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014970 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014971 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014972
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014973 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014974 ASSERT_VK_SUCCESS(err);
14975 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014976 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14977 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014978 ASSERT_VK_SUCCESS(err);
14979
14980 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014981 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14982 image_view_create_info.image = image_bad;
14983 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14984 image_view_create_info.format = tex_format_bad;
14985 image_view_create_info.subresourceRange.baseArrayLayer = 0;
14986 image_view_create_info.subresourceRange.baseMipLevel = 0;
14987 image_view_create_info.subresourceRange.layerCount = 1;
14988 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014989 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014990
14991 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014992 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014993
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014994 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014995
Chia-I Wuf7458c52015-10-26 21:10:41 +080014996 vkDestroyImage(m_device->device(), image_bad, NULL);
14997 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014998 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
14999 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015000}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015001
15002TEST_F(VkLayerTest, ClearImageErrors) {
15003 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15004 "ClearDepthStencilImage with a color image.");
15005
15006 ASSERT_NO_FATAL_FAILURE(InitState());
15007 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15008
15009 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15010 BeginCommandBuffer();
15011 m_commandBuffer->EndRenderPass();
15012
15013 // Color image
15014 VkClearColorValue clear_color;
15015 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15016 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15017 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15018 const int32_t img_width = 32;
15019 const int32_t img_height = 32;
15020 VkImageCreateInfo image_create_info = {};
15021 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15022 image_create_info.pNext = NULL;
15023 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15024 image_create_info.format = color_format;
15025 image_create_info.extent.width = img_width;
15026 image_create_info.extent.height = img_height;
15027 image_create_info.extent.depth = 1;
15028 image_create_info.mipLevels = 1;
15029 image_create_info.arrayLayers = 1;
15030 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15031 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15032 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15033
15034 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015035 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015036
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015037 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015038
15039 // Depth/Stencil image
15040 VkClearDepthStencilValue clear_value = {0};
15041 reqs = 0; // don't need HOST_VISIBLE DS image
15042 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15043 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15044 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15045 ds_image_create_info.extent.width = 64;
15046 ds_image_create_info.extent.height = 64;
15047 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15048 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15049
15050 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015051 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015052
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015053 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 -060015054
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015056
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015057 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015058 &color_range);
15059
15060 m_errorMonitor->VerifyFound();
15061
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15063 "image created without "
15064 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015066 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015067 &color_range);
15068
15069 m_errorMonitor->VerifyFound();
15070
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015071 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15073 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015074
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015075 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15076 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015077
15078 m_errorMonitor->VerifyFound();
15079}
Tobin Ehliscde08892015-09-22 10:11:37 -060015080#endif // IMAGE_TESTS
15081
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015082
15083// WSI Enabled Tests
15084//
15085TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15086
15087#if defined(VK_USE_PLATFORM_XCB_KHR)
15088 VkSurfaceKHR surface = VK_NULL_HANDLE;
15089
15090 VkResult err;
15091 bool pass;
15092 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15093 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15094 // uint32_t swapchain_image_count = 0;
15095 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15096 // uint32_t image_index = 0;
15097 // VkPresentInfoKHR present_info = {};
15098
15099 ASSERT_NO_FATAL_FAILURE(InitState());
15100
15101 // Use the create function from one of the VK_KHR_*_surface extension in
15102 // order to create a surface, testing all known errors in the process,
15103 // before successfully creating a surface:
15104 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15106 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15107 pass = (err != VK_SUCCESS);
15108 ASSERT_TRUE(pass);
15109 m_errorMonitor->VerifyFound();
15110
15111 // Next, try to create a surface with the wrong
15112 // VkXcbSurfaceCreateInfoKHR::sType:
15113 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15114 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15116 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15117 pass = (err != VK_SUCCESS);
15118 ASSERT_TRUE(pass);
15119 m_errorMonitor->VerifyFound();
15120
15121 // Create a native window, and then correctly create a surface:
15122 xcb_connection_t *connection;
15123 xcb_screen_t *screen;
15124 xcb_window_t xcb_window;
15125 xcb_intern_atom_reply_t *atom_wm_delete_window;
15126
15127 const xcb_setup_t *setup;
15128 xcb_screen_iterator_t iter;
15129 int scr;
15130 uint32_t value_mask, value_list[32];
15131 int width = 1;
15132 int height = 1;
15133
15134 connection = xcb_connect(NULL, &scr);
15135 ASSERT_TRUE(connection != NULL);
15136 setup = xcb_get_setup(connection);
15137 iter = xcb_setup_roots_iterator(setup);
15138 while (scr-- > 0)
15139 xcb_screen_next(&iter);
15140 screen = iter.data;
15141
15142 xcb_window = xcb_generate_id(connection);
15143
15144 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15145 value_list[0] = screen->black_pixel;
15146 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15147
15148 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15149 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15150
15151 /* Magic code that will send notification when window is destroyed */
15152 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15153 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15154
15155 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15156 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15157 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15158 free(reply);
15159
15160 xcb_map_window(connection, xcb_window);
15161
15162 // Force the x/y coordinates to 100,100 results are identical in consecutive
15163 // runs
15164 const uint32_t coords[] = { 100, 100 };
15165 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15166
15167 // Finally, try to correctly create a surface:
15168 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15169 xcb_create_info.pNext = NULL;
15170 xcb_create_info.flags = 0;
15171 xcb_create_info.connection = connection;
15172 xcb_create_info.window = xcb_window;
15173 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15174 pass = (err == VK_SUCCESS);
15175 ASSERT_TRUE(pass);
15176
15177 // Check if surface supports presentation:
15178
15179 // 1st, do so without having queried the queue families:
15180 VkBool32 supported = false;
15181 // TODO: Get the following error to come out:
15182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15183 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15184 "function");
15185 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15186 pass = (err != VK_SUCCESS);
15187 // ASSERT_TRUE(pass);
15188 // m_errorMonitor->VerifyFound();
15189
15190 // Next, query a queue family index that's too large:
15191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15192 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15193 pass = (err != VK_SUCCESS);
15194 ASSERT_TRUE(pass);
15195 m_errorMonitor->VerifyFound();
15196
15197 // Finally, do so correctly:
15198 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15199 // SUPPORTED
15200 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15201 pass = (err == VK_SUCCESS);
15202 ASSERT_TRUE(pass);
15203
15204 // Before proceeding, try to create a swapchain without having called
15205 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15206 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15207 swapchain_create_info.pNext = NULL;
15208 swapchain_create_info.flags = 0;
15209 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15210 swapchain_create_info.surface = surface;
15211 swapchain_create_info.imageArrayLayers = 1;
15212 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15213 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15215 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15216 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15217 pass = (err != VK_SUCCESS);
15218 ASSERT_TRUE(pass);
15219 m_errorMonitor->VerifyFound();
15220
15221 // Get the surface capabilities:
15222 VkSurfaceCapabilitiesKHR surface_capabilities;
15223
15224 // Do so correctly (only error logged by this entrypoint is if the
15225 // extension isn't enabled):
15226 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15227 pass = (err == VK_SUCCESS);
15228 ASSERT_TRUE(pass);
15229
15230 // Get the surface formats:
15231 uint32_t surface_format_count;
15232
15233 // First, try without a pointer to surface_format_count:
15234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15235 "specified as NULL");
15236 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15237 pass = (err == VK_SUCCESS);
15238 ASSERT_TRUE(pass);
15239 m_errorMonitor->VerifyFound();
15240
15241 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15242 // correctly done a 1st try (to get the count):
15243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15244 surface_format_count = 0;
15245 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15246 pass = (err == VK_SUCCESS);
15247 ASSERT_TRUE(pass);
15248 m_errorMonitor->VerifyFound();
15249
15250 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15251 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15252 pass = (err == VK_SUCCESS);
15253 ASSERT_TRUE(pass);
15254
15255 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15256 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15257
15258 // Next, do a 2nd try with surface_format_count being set too high:
15259 surface_format_count += 5;
15260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15261 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15262 pass = (err == VK_SUCCESS);
15263 ASSERT_TRUE(pass);
15264 m_errorMonitor->VerifyFound();
15265
15266 // Finally, do a correct 1st and 2nd try:
15267 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15268 pass = (err == VK_SUCCESS);
15269 ASSERT_TRUE(pass);
15270 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15271 pass = (err == VK_SUCCESS);
15272 ASSERT_TRUE(pass);
15273
15274 // Get the surface present modes:
15275 uint32_t surface_present_mode_count;
15276
15277 // First, try without a pointer to surface_format_count:
15278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15279 "specified as NULL");
15280
15281 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15282 pass = (err == VK_SUCCESS);
15283 ASSERT_TRUE(pass);
15284 m_errorMonitor->VerifyFound();
15285
15286 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15287 // correctly done a 1st try (to get the count):
15288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15289 surface_present_mode_count = 0;
15290 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15291 (VkPresentModeKHR *)&surface_present_mode_count);
15292 pass = (err == VK_SUCCESS);
15293 ASSERT_TRUE(pass);
15294 m_errorMonitor->VerifyFound();
15295
15296 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15297 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15298 pass = (err == VK_SUCCESS);
15299 ASSERT_TRUE(pass);
15300
15301 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15302 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15303
15304 // Next, do a 2nd try with surface_format_count being set too high:
15305 surface_present_mode_count += 5;
15306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15307 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15308 pass = (err == VK_SUCCESS);
15309 ASSERT_TRUE(pass);
15310 m_errorMonitor->VerifyFound();
15311
15312 // Finally, do a correct 1st and 2nd try:
15313 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15314 pass = (err == VK_SUCCESS);
15315 ASSERT_TRUE(pass);
15316 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15317 pass = (err == VK_SUCCESS);
15318 ASSERT_TRUE(pass);
15319
15320 // Create a swapchain:
15321
15322 // First, try without a pointer to swapchain_create_info:
15323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15324 "specified as NULL");
15325
15326 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15327 pass = (err != VK_SUCCESS);
15328 ASSERT_TRUE(pass);
15329 m_errorMonitor->VerifyFound();
15330
15331 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15332 // sType:
15333 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15335
15336 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15337 pass = (err != VK_SUCCESS);
15338 ASSERT_TRUE(pass);
15339 m_errorMonitor->VerifyFound();
15340
15341 // Next, call with a NULL swapchain pointer:
15342 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15343 swapchain_create_info.pNext = NULL;
15344 swapchain_create_info.flags = 0;
15345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15346 "specified as NULL");
15347
15348 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15349 pass = (err != VK_SUCCESS);
15350 ASSERT_TRUE(pass);
15351 m_errorMonitor->VerifyFound();
15352
15353 // TODO: Enhance swapchain layer so that
15354 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15355
15356 // Next, call with a queue family index that's too large:
15357 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15358 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15359 swapchain_create_info.queueFamilyIndexCount = 2;
15360 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15362 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15363 pass = (err != VK_SUCCESS);
15364 ASSERT_TRUE(pass);
15365 m_errorMonitor->VerifyFound();
15366
15367 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15368 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15369 swapchain_create_info.queueFamilyIndexCount = 1;
15370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15371 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15372 "pCreateInfo->pQueueFamilyIndices).");
15373 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15374 pass = (err != VK_SUCCESS);
15375 ASSERT_TRUE(pass);
15376 m_errorMonitor->VerifyFound();
15377
15378 // Next, call with an invalid imageSharingMode:
15379 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15380 swapchain_create_info.queueFamilyIndexCount = 1;
15381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15382 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15383 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15384 pass = (err != VK_SUCCESS);
15385 ASSERT_TRUE(pass);
15386 m_errorMonitor->VerifyFound();
15387 // Fix for the future:
15388 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15389 // SUPPORTED
15390 swapchain_create_info.queueFamilyIndexCount = 0;
15391 queueFamilyIndex[0] = 0;
15392 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15393
15394 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15395 // Get the images from a swapchain:
15396 // Acquire an image from a swapchain:
15397 // Present an image to a swapchain:
15398 // Destroy the swapchain:
15399
15400 // TODOs:
15401 //
15402 // - Try destroying the device without first destroying the swapchain
15403 //
15404 // - Try destroying the device without first destroying the surface
15405 //
15406 // - Try destroying the surface without first destroying the swapchain
15407
15408 // Destroy the surface:
15409 vkDestroySurfaceKHR(instance(), surface, NULL);
15410
15411 // Tear down the window:
15412 xcb_destroy_window(connection, xcb_window);
15413 xcb_disconnect(connection);
15414
15415#else // VK_USE_PLATFORM_XCB_KHR
15416 return;
15417#endif // VK_USE_PLATFORM_XCB_KHR
15418}
15419
15420//
15421// POSITIVE VALIDATION TESTS
15422//
15423// These tests do not expect to encounter ANY validation errors pass only if this is true
15424
Tobin Ehlise0006882016-11-03 10:14:28 -060015425TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15426 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15427 "by a transition in the primary.");
15428 VkResult err;
15429 m_errorMonitor->ExpectSuccess();
15430 ASSERT_NO_FATAL_FAILURE(InitState());
15431 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15432 // Allocate a secondary and primary cmd buffer
15433 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15434 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15435 command_buffer_allocate_info.commandPool = m_commandPool;
15436 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15437 command_buffer_allocate_info.commandBufferCount = 1;
15438
15439 VkCommandBuffer secondary_command_buffer;
15440 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15441 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15442 VkCommandBuffer primary_command_buffer;
15443 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15444 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15445 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15446 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15447 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15448 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15449 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15450
15451 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15452 ASSERT_VK_SUCCESS(err);
15453 VkImageObj image(m_device);
15454 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15455 ASSERT_TRUE(image.initialized());
15456 VkImageMemoryBarrier img_barrier = {};
15457 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15458 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15459 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15460 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15461 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15462 img_barrier.image = image.handle();
15463 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15464 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15465 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15466 img_barrier.subresourceRange.baseArrayLayer = 0;
15467 img_barrier.subresourceRange.baseMipLevel = 0;
15468 img_barrier.subresourceRange.layerCount = 1;
15469 img_barrier.subresourceRange.levelCount = 1;
15470 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15471 0, nullptr, 1, &img_barrier);
15472 err = vkEndCommandBuffer(secondary_command_buffer);
15473 ASSERT_VK_SUCCESS(err);
15474
15475 // Now update primary cmd buffer to execute secondary and transitions image
15476 command_buffer_begin_info.pInheritanceInfo = nullptr;
15477 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15478 ASSERT_VK_SUCCESS(err);
15479 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15480 VkImageMemoryBarrier img_barrier2 = {};
15481 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15482 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15483 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15484 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15485 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15486 img_barrier2.image = image.handle();
15487 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15488 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15489 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15490 img_barrier2.subresourceRange.baseArrayLayer = 0;
15491 img_barrier2.subresourceRange.baseMipLevel = 0;
15492 img_barrier2.subresourceRange.layerCount = 1;
15493 img_barrier2.subresourceRange.levelCount = 1;
15494 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15495 nullptr, 1, &img_barrier2);
15496 err = vkEndCommandBuffer(primary_command_buffer);
15497 ASSERT_VK_SUCCESS(err);
15498 VkSubmitInfo submit_info = {};
15499 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15500 submit_info.commandBufferCount = 1;
15501 submit_info.pCommandBuffers = &primary_command_buffer;
15502 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15503 ASSERT_VK_SUCCESS(err);
15504 m_errorMonitor->VerifyNotFound();
15505 err = vkDeviceWaitIdle(m_device->device());
15506 ASSERT_VK_SUCCESS(err);
15507 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15508 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15509}
15510
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015511// This is a positive test. No failures are expected.
15512TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15513 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15514 "is ignoring VkWriteDescriptorSet members that are not "
15515 "related to the descriptor type specified by "
15516 "VkWriteDescriptorSet::descriptorType. Correct "
15517 "validation behavior will result in the test running to "
15518 "completion without validation errors.");
15519
15520 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15521
15522 ASSERT_NO_FATAL_FAILURE(InitState());
15523
15524 // Image Case
15525 {
15526 m_errorMonitor->ExpectSuccess();
15527
15528 VkImage image;
15529 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15530 const int32_t tex_width = 32;
15531 const int32_t tex_height = 32;
15532 VkImageCreateInfo image_create_info = {};
15533 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15534 image_create_info.pNext = NULL;
15535 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15536 image_create_info.format = tex_format;
15537 image_create_info.extent.width = tex_width;
15538 image_create_info.extent.height = tex_height;
15539 image_create_info.extent.depth = 1;
15540 image_create_info.mipLevels = 1;
15541 image_create_info.arrayLayers = 1;
15542 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15543 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15544 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15545 image_create_info.flags = 0;
15546 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15547 ASSERT_VK_SUCCESS(err);
15548
15549 VkMemoryRequirements memory_reqs;
15550 VkDeviceMemory image_memory;
15551 bool pass;
15552 VkMemoryAllocateInfo memory_info = {};
15553 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15554 memory_info.pNext = NULL;
15555 memory_info.allocationSize = 0;
15556 memory_info.memoryTypeIndex = 0;
15557 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15558 memory_info.allocationSize = memory_reqs.size;
15559 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15560 ASSERT_TRUE(pass);
15561 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15562 ASSERT_VK_SUCCESS(err);
15563 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15564 ASSERT_VK_SUCCESS(err);
15565
15566 VkImageViewCreateInfo image_view_create_info = {};
15567 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15568 image_view_create_info.image = image;
15569 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15570 image_view_create_info.format = tex_format;
15571 image_view_create_info.subresourceRange.layerCount = 1;
15572 image_view_create_info.subresourceRange.baseMipLevel = 0;
15573 image_view_create_info.subresourceRange.levelCount = 1;
15574 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15575
15576 VkImageView view;
15577 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15578 ASSERT_VK_SUCCESS(err);
15579
15580 VkDescriptorPoolSize ds_type_count = {};
15581 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15582 ds_type_count.descriptorCount = 1;
15583
15584 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15585 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15586 ds_pool_ci.pNext = NULL;
15587 ds_pool_ci.maxSets = 1;
15588 ds_pool_ci.poolSizeCount = 1;
15589 ds_pool_ci.pPoolSizes = &ds_type_count;
15590
15591 VkDescriptorPool ds_pool;
15592 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15593 ASSERT_VK_SUCCESS(err);
15594
15595 VkDescriptorSetLayoutBinding dsl_binding = {};
15596 dsl_binding.binding = 0;
15597 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15598 dsl_binding.descriptorCount = 1;
15599 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15600 dsl_binding.pImmutableSamplers = NULL;
15601
15602 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15603 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15604 ds_layout_ci.pNext = NULL;
15605 ds_layout_ci.bindingCount = 1;
15606 ds_layout_ci.pBindings = &dsl_binding;
15607 VkDescriptorSetLayout ds_layout;
15608 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15609 ASSERT_VK_SUCCESS(err);
15610
15611 VkDescriptorSet descriptor_set;
15612 VkDescriptorSetAllocateInfo alloc_info = {};
15613 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15614 alloc_info.descriptorSetCount = 1;
15615 alloc_info.descriptorPool = ds_pool;
15616 alloc_info.pSetLayouts = &ds_layout;
15617 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15618 ASSERT_VK_SUCCESS(err);
15619
15620 VkDescriptorImageInfo image_info = {};
15621 image_info.imageView = view;
15622 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15623
15624 VkWriteDescriptorSet descriptor_write;
15625 memset(&descriptor_write, 0, sizeof(descriptor_write));
15626 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15627 descriptor_write.dstSet = descriptor_set;
15628 descriptor_write.dstBinding = 0;
15629 descriptor_write.descriptorCount = 1;
15630 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15631 descriptor_write.pImageInfo = &image_info;
15632
15633 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15634 // be
15635 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15636 // This will most likely produce a crash if the parameter_validation
15637 // layer
15638 // does not correctly ignore pBufferInfo.
15639 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15640 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15641
15642 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15643
15644 m_errorMonitor->VerifyNotFound();
15645
15646 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15647 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15648 vkDestroyImageView(m_device->device(), view, NULL);
15649 vkDestroyImage(m_device->device(), image, NULL);
15650 vkFreeMemory(m_device->device(), image_memory, NULL);
15651 }
15652
15653 // Buffer Case
15654 {
15655 m_errorMonitor->ExpectSuccess();
15656
15657 VkBuffer buffer;
15658 uint32_t queue_family_index = 0;
15659 VkBufferCreateInfo buffer_create_info = {};
15660 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15661 buffer_create_info.size = 1024;
15662 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15663 buffer_create_info.queueFamilyIndexCount = 1;
15664 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15665
15666 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15667 ASSERT_VK_SUCCESS(err);
15668
15669 VkMemoryRequirements memory_reqs;
15670 VkDeviceMemory buffer_memory;
15671 bool pass;
15672 VkMemoryAllocateInfo memory_info = {};
15673 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15674 memory_info.pNext = NULL;
15675 memory_info.allocationSize = 0;
15676 memory_info.memoryTypeIndex = 0;
15677
15678 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15679 memory_info.allocationSize = memory_reqs.size;
15680 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15681 ASSERT_TRUE(pass);
15682
15683 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15684 ASSERT_VK_SUCCESS(err);
15685 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15686 ASSERT_VK_SUCCESS(err);
15687
15688 VkDescriptorPoolSize ds_type_count = {};
15689 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15690 ds_type_count.descriptorCount = 1;
15691
15692 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15693 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15694 ds_pool_ci.pNext = NULL;
15695 ds_pool_ci.maxSets = 1;
15696 ds_pool_ci.poolSizeCount = 1;
15697 ds_pool_ci.pPoolSizes = &ds_type_count;
15698
15699 VkDescriptorPool ds_pool;
15700 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15701 ASSERT_VK_SUCCESS(err);
15702
15703 VkDescriptorSetLayoutBinding dsl_binding = {};
15704 dsl_binding.binding = 0;
15705 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15706 dsl_binding.descriptorCount = 1;
15707 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15708 dsl_binding.pImmutableSamplers = NULL;
15709
15710 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15711 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15712 ds_layout_ci.pNext = NULL;
15713 ds_layout_ci.bindingCount = 1;
15714 ds_layout_ci.pBindings = &dsl_binding;
15715 VkDescriptorSetLayout ds_layout;
15716 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15717 ASSERT_VK_SUCCESS(err);
15718
15719 VkDescriptorSet descriptor_set;
15720 VkDescriptorSetAllocateInfo alloc_info = {};
15721 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15722 alloc_info.descriptorSetCount = 1;
15723 alloc_info.descriptorPool = ds_pool;
15724 alloc_info.pSetLayouts = &ds_layout;
15725 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15726 ASSERT_VK_SUCCESS(err);
15727
15728 VkDescriptorBufferInfo buffer_info = {};
15729 buffer_info.buffer = buffer;
15730 buffer_info.offset = 0;
15731 buffer_info.range = 1024;
15732
15733 VkWriteDescriptorSet descriptor_write;
15734 memset(&descriptor_write, 0, sizeof(descriptor_write));
15735 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15736 descriptor_write.dstSet = descriptor_set;
15737 descriptor_write.dstBinding = 0;
15738 descriptor_write.descriptorCount = 1;
15739 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15740 descriptor_write.pBufferInfo = &buffer_info;
15741
15742 // Set pImageInfo and pTexelBufferView to invalid values, which should
15743 // be
15744 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15745 // This will most likely produce a crash if the parameter_validation
15746 // layer
15747 // does not correctly ignore pImageInfo.
15748 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15749 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15750
15751 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15752
15753 m_errorMonitor->VerifyNotFound();
15754
15755 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15756 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15757 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15758 vkDestroyBuffer(m_device->device(), buffer, NULL);
15759 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15760 }
15761
15762 // Texel Buffer Case
15763 {
15764 m_errorMonitor->ExpectSuccess();
15765
15766 VkBuffer buffer;
15767 uint32_t queue_family_index = 0;
15768 VkBufferCreateInfo buffer_create_info = {};
15769 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15770 buffer_create_info.size = 1024;
15771 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15772 buffer_create_info.queueFamilyIndexCount = 1;
15773 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15774
15775 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15776 ASSERT_VK_SUCCESS(err);
15777
15778 VkMemoryRequirements memory_reqs;
15779 VkDeviceMemory buffer_memory;
15780 bool pass;
15781 VkMemoryAllocateInfo memory_info = {};
15782 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15783 memory_info.pNext = NULL;
15784 memory_info.allocationSize = 0;
15785 memory_info.memoryTypeIndex = 0;
15786
15787 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15788 memory_info.allocationSize = memory_reqs.size;
15789 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15790 ASSERT_TRUE(pass);
15791
15792 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15793 ASSERT_VK_SUCCESS(err);
15794 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15795 ASSERT_VK_SUCCESS(err);
15796
15797 VkBufferViewCreateInfo buff_view_ci = {};
15798 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
15799 buff_view_ci.buffer = buffer;
15800 buff_view_ci.format = VK_FORMAT_R8_UNORM;
15801 buff_view_ci.range = VK_WHOLE_SIZE;
15802 VkBufferView buffer_view;
15803 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
15804
15805 VkDescriptorPoolSize ds_type_count = {};
15806 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15807 ds_type_count.descriptorCount = 1;
15808
15809 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15810 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15811 ds_pool_ci.pNext = NULL;
15812 ds_pool_ci.maxSets = 1;
15813 ds_pool_ci.poolSizeCount = 1;
15814 ds_pool_ci.pPoolSizes = &ds_type_count;
15815
15816 VkDescriptorPool ds_pool;
15817 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15818 ASSERT_VK_SUCCESS(err);
15819
15820 VkDescriptorSetLayoutBinding dsl_binding = {};
15821 dsl_binding.binding = 0;
15822 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15823 dsl_binding.descriptorCount = 1;
15824 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15825 dsl_binding.pImmutableSamplers = NULL;
15826
15827 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15828 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15829 ds_layout_ci.pNext = NULL;
15830 ds_layout_ci.bindingCount = 1;
15831 ds_layout_ci.pBindings = &dsl_binding;
15832 VkDescriptorSetLayout ds_layout;
15833 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15834 ASSERT_VK_SUCCESS(err);
15835
15836 VkDescriptorSet descriptor_set;
15837 VkDescriptorSetAllocateInfo alloc_info = {};
15838 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15839 alloc_info.descriptorSetCount = 1;
15840 alloc_info.descriptorPool = ds_pool;
15841 alloc_info.pSetLayouts = &ds_layout;
15842 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15843 ASSERT_VK_SUCCESS(err);
15844
15845 VkWriteDescriptorSet descriptor_write;
15846 memset(&descriptor_write, 0, sizeof(descriptor_write));
15847 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15848 descriptor_write.dstSet = descriptor_set;
15849 descriptor_write.dstBinding = 0;
15850 descriptor_write.descriptorCount = 1;
15851 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15852 descriptor_write.pTexelBufferView = &buffer_view;
15853
15854 // Set pImageInfo and pBufferInfo to invalid values, which should be
15855 // ignored for descriptorType ==
15856 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
15857 // This will most likely produce a crash if the parameter_validation
15858 // layer
15859 // does not correctly ignore pImageInfo and pBufferInfo.
15860 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15861 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15862
15863 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15864
15865 m_errorMonitor->VerifyNotFound();
15866
15867 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15868 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15869 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15870 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
15871 vkDestroyBuffer(m_device->device(), buffer, NULL);
15872 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15873 }
15874}
15875
Tobin Ehlisf7428442016-10-25 07:58:24 -060015876TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
15877 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
15878
15879 ASSERT_NO_FATAL_FAILURE(InitState());
15880 // Create layout where two binding #s are "1"
15881 static const uint32_t NUM_BINDINGS = 3;
15882 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15883 dsl_binding[0].binding = 1;
15884 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15885 dsl_binding[0].descriptorCount = 1;
15886 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15887 dsl_binding[0].pImmutableSamplers = NULL;
15888 dsl_binding[1].binding = 0;
15889 dsl_binding[1].descriptorCount = 1;
15890 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15891 dsl_binding[1].descriptorCount = 1;
15892 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15893 dsl_binding[1].pImmutableSamplers = NULL;
15894 dsl_binding[2].binding = 1; // Duplicate binding should cause error
15895 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15896 dsl_binding[2].descriptorCount = 1;
15897 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15898 dsl_binding[2].pImmutableSamplers = NULL;
15899
15900 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15901 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15902 ds_layout_ci.pNext = NULL;
15903 ds_layout_ci.bindingCount = NUM_BINDINGS;
15904 ds_layout_ci.pBindings = dsl_binding;
15905 VkDescriptorSetLayout ds_layout;
15906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
15907 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15908 m_errorMonitor->VerifyFound();
15909}
15910
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060015911TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015912 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
15913
15914 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015915
15916 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015917
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060015918 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
15919
15920 {
15921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
15922 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
15923 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15924 m_errorMonitor->VerifyFound();
15925 }
15926
15927 {
15928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
15929 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
15930 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15931 m_errorMonitor->VerifyFound();
15932 }
15933
15934 {
15935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
15936 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
15937 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15938 m_errorMonitor->VerifyFound();
15939 }
15940
15941 {
15942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
15943 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
15944 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15945 m_errorMonitor->VerifyFound();
15946 }
15947
15948 {
15949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
15950 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
15951 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15952 m_errorMonitor->VerifyFound();
15953 }
15954
15955 {
15956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
15957 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
15958 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15959 m_errorMonitor->VerifyFound();
15960 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015961
15962 {
15963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
15964 VkRect2D scissor = {{-1, 0}, {16, 16}};
15965 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15966 m_errorMonitor->VerifyFound();
15967 }
15968
15969 {
15970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
15971 VkRect2D scissor = {{0, -2}, {16, 16}};
15972 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15973 m_errorMonitor->VerifyFound();
15974 }
15975
15976 {
15977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
15978 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
15979 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15980 m_errorMonitor->VerifyFound();
15981 }
15982
15983 {
15984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
15985 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
15986 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15987 m_errorMonitor->VerifyFound();
15988 }
15989
15990 EndCommandBuffer();
15991}
15992
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015993// This is a positive test. No failures are expected.
15994TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
15995 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
15996 VkResult err;
15997
15998 ASSERT_NO_FATAL_FAILURE(InitState());
15999 m_errorMonitor->ExpectSuccess();
16000 VkDescriptorPoolSize ds_type_count = {};
16001 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16002 ds_type_count.descriptorCount = 2;
16003
16004 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16005 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16006 ds_pool_ci.pNext = NULL;
16007 ds_pool_ci.maxSets = 1;
16008 ds_pool_ci.poolSizeCount = 1;
16009 ds_pool_ci.pPoolSizes = &ds_type_count;
16010
16011 VkDescriptorPool ds_pool;
16012 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16013 ASSERT_VK_SUCCESS(err);
16014
16015 // Create layout with two uniform buffer descriptors w/ empty binding between them
16016 static const uint32_t NUM_BINDINGS = 3;
16017 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16018 dsl_binding[0].binding = 0;
16019 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16020 dsl_binding[0].descriptorCount = 1;
16021 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16022 dsl_binding[0].pImmutableSamplers = NULL;
16023 dsl_binding[1].binding = 1;
16024 dsl_binding[1].descriptorCount = 0; // empty binding
16025 dsl_binding[2].binding = 2;
16026 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16027 dsl_binding[2].descriptorCount = 1;
16028 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16029 dsl_binding[2].pImmutableSamplers = NULL;
16030
16031 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16032 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16033 ds_layout_ci.pNext = NULL;
16034 ds_layout_ci.bindingCount = NUM_BINDINGS;
16035 ds_layout_ci.pBindings = dsl_binding;
16036 VkDescriptorSetLayout ds_layout;
16037 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16038 ASSERT_VK_SUCCESS(err);
16039
16040 VkDescriptorSet descriptor_set = {};
16041 VkDescriptorSetAllocateInfo alloc_info = {};
16042 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16043 alloc_info.descriptorSetCount = 1;
16044 alloc_info.descriptorPool = ds_pool;
16045 alloc_info.pSetLayouts = &ds_layout;
16046 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16047 ASSERT_VK_SUCCESS(err);
16048
16049 // Create a buffer to be used for update
16050 VkBufferCreateInfo buff_ci = {};
16051 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16052 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16053 buff_ci.size = 256;
16054 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16055 VkBuffer buffer;
16056 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16057 ASSERT_VK_SUCCESS(err);
16058 // Have to bind memory to buffer before descriptor update
16059 VkMemoryAllocateInfo mem_alloc = {};
16060 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16061 mem_alloc.pNext = NULL;
16062 mem_alloc.allocationSize = 512; // one allocation for both buffers
16063 mem_alloc.memoryTypeIndex = 0;
16064
16065 VkMemoryRequirements mem_reqs;
16066 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16067 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16068 if (!pass) {
16069 vkDestroyBuffer(m_device->device(), buffer, NULL);
16070 return;
16071 }
16072
16073 VkDeviceMemory mem;
16074 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16075 ASSERT_VK_SUCCESS(err);
16076 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16077 ASSERT_VK_SUCCESS(err);
16078
16079 // Only update the descriptor at binding 2
16080 VkDescriptorBufferInfo buff_info = {};
16081 buff_info.buffer = buffer;
16082 buff_info.offset = 0;
16083 buff_info.range = VK_WHOLE_SIZE;
16084 VkWriteDescriptorSet descriptor_write = {};
16085 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16086 descriptor_write.dstBinding = 2;
16087 descriptor_write.descriptorCount = 1;
16088 descriptor_write.pTexelBufferView = nullptr;
16089 descriptor_write.pBufferInfo = &buff_info;
16090 descriptor_write.pImageInfo = nullptr;
16091 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16092 descriptor_write.dstSet = descriptor_set;
16093
16094 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16095
16096 m_errorMonitor->VerifyNotFound();
16097 // Cleanup
16098 vkFreeMemory(m_device->device(), mem, NULL);
16099 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16100 vkDestroyBuffer(m_device->device(), buffer, NULL);
16101 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16102}
16103
16104// This is a positive test. No failures are expected.
16105TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16106 VkResult err;
16107 bool pass;
16108
16109 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16110 "the buffer, create an image, and bind the same memory to "
16111 "it");
16112
16113 m_errorMonitor->ExpectSuccess();
16114
16115 ASSERT_NO_FATAL_FAILURE(InitState());
16116
16117 VkBuffer buffer;
16118 VkImage image;
16119 VkDeviceMemory mem;
16120 VkMemoryRequirements mem_reqs;
16121
16122 VkBufferCreateInfo buf_info = {};
16123 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16124 buf_info.pNext = NULL;
16125 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16126 buf_info.size = 256;
16127 buf_info.queueFamilyIndexCount = 0;
16128 buf_info.pQueueFamilyIndices = NULL;
16129 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16130 buf_info.flags = 0;
16131 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16132 ASSERT_VK_SUCCESS(err);
16133
16134 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16135
16136 VkMemoryAllocateInfo alloc_info = {};
16137 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16138 alloc_info.pNext = NULL;
16139 alloc_info.memoryTypeIndex = 0;
16140
16141 // Ensure memory is big enough for both bindings
16142 alloc_info.allocationSize = 0x10000;
16143
16144 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16145 if (!pass) {
16146 vkDestroyBuffer(m_device->device(), buffer, NULL);
16147 return;
16148 }
16149
16150 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16151 ASSERT_VK_SUCCESS(err);
16152
16153 uint8_t *pData;
16154 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16155 ASSERT_VK_SUCCESS(err);
16156
16157 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16158
16159 vkUnmapMemory(m_device->device(), mem);
16160
16161 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16162 ASSERT_VK_SUCCESS(err);
16163
16164 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16165 // memory. In fact, it was never used by the GPU.
16166 // Just be be sure, wait for idle.
16167 vkDestroyBuffer(m_device->device(), buffer, NULL);
16168 vkDeviceWaitIdle(m_device->device());
16169
16170 VkImageCreateInfo image_create_info = {};
16171 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16172 image_create_info.pNext = NULL;
16173 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16174 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16175 image_create_info.extent.width = 64;
16176 image_create_info.extent.height = 64;
16177 image_create_info.extent.depth = 1;
16178 image_create_info.mipLevels = 1;
16179 image_create_info.arrayLayers = 1;
16180 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16181 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16182 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16183 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16184 image_create_info.queueFamilyIndexCount = 0;
16185 image_create_info.pQueueFamilyIndices = NULL;
16186 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16187 image_create_info.flags = 0;
16188
16189 VkMemoryAllocateInfo mem_alloc = {};
16190 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16191 mem_alloc.pNext = NULL;
16192 mem_alloc.allocationSize = 0;
16193 mem_alloc.memoryTypeIndex = 0;
16194
16195 /* Create a mappable image. It will be the texture if linear images are ok
16196 * to be textures or it will be the staging image if they are not.
16197 */
16198 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16199 ASSERT_VK_SUCCESS(err);
16200
16201 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16202
16203 mem_alloc.allocationSize = mem_reqs.size;
16204
16205 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16206 if (!pass) {
16207 vkDestroyImage(m_device->device(), image, NULL);
16208 return;
16209 }
16210
16211 // VALIDATION FAILURE:
16212 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16213 ASSERT_VK_SUCCESS(err);
16214
16215 m_errorMonitor->VerifyNotFound();
16216
16217 vkFreeMemory(m_device->device(), mem, NULL);
16218 vkDestroyBuffer(m_device->device(), buffer, NULL);
16219 vkDestroyImage(m_device->device(), image, NULL);
16220}
16221
16222TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16223
16224 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16225 "mapping while using VK_WHOLE_SIZE does not cause access "
16226 "violations");
16227 VkResult err;
16228 uint8_t *pData;
16229 ASSERT_NO_FATAL_FAILURE(InitState());
16230
16231 VkDeviceMemory mem;
16232 VkMemoryRequirements mem_reqs;
16233 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
16234 VkMemoryAllocateInfo alloc_info = {};
16235 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16236 alloc_info.pNext = NULL;
16237 alloc_info.memoryTypeIndex = 0;
16238
16239 static const VkDeviceSize allocation_size = 0x1000;
16240 alloc_info.allocationSize = allocation_size;
16241
16242 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16243 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16244 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16245 if (!pass) {
16246 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16247 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16248 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16249 if (!pass) {
16250 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16251 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16252 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16253 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16254 if (!pass) {
16255 return;
16256 }
16257 }
16258 }
16259
16260 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16261 ASSERT_VK_SUCCESS(err);
16262
16263 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16264 // mapped range
16265 m_errorMonitor->ExpectSuccess();
16266 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16267 ASSERT_VK_SUCCESS(err);
16268 VkMappedMemoryRange mmr = {};
16269 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16270 mmr.memory = mem;
16271 mmr.offset = 0;
16272 mmr.size = VK_WHOLE_SIZE;
16273 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16274 ASSERT_VK_SUCCESS(err);
16275 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16276 ASSERT_VK_SUCCESS(err);
16277 m_errorMonitor->VerifyNotFound();
16278 vkUnmapMemory(m_device->device(), mem);
16279
16280 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16281 // mapped range
16282 m_errorMonitor->ExpectSuccess();
16283 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16284 ASSERT_VK_SUCCESS(err);
16285 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16286 mmr.memory = mem;
16287 mmr.offset = 13;
16288 mmr.size = VK_WHOLE_SIZE;
16289 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16290 ASSERT_VK_SUCCESS(err);
16291 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16292 ASSERT_VK_SUCCESS(err);
16293 m_errorMonitor->VerifyNotFound();
16294 vkUnmapMemory(m_device->device(), mem);
16295
16296 // Map with prime offset and size
16297 // Flush/Invalidate subrange of mapped area with prime offset and size
16298 m_errorMonitor->ExpectSuccess();
16299 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16300 ASSERT_VK_SUCCESS(err);
16301 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16302 mmr.memory = mem;
16303 mmr.offset = allocation_size - 107;
16304 mmr.size = 61;
16305 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16306 ASSERT_VK_SUCCESS(err);
16307 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16308 ASSERT_VK_SUCCESS(err);
16309 m_errorMonitor->VerifyNotFound();
16310 vkUnmapMemory(m_device->device(), mem);
16311
16312 // Map without offset and flush WHOLE_SIZE with two separate offsets
16313 m_errorMonitor->ExpectSuccess();
16314 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16315 ASSERT_VK_SUCCESS(err);
16316 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16317 mmr.memory = mem;
16318 mmr.offset = allocation_size - 100;
16319 mmr.size = VK_WHOLE_SIZE;
16320 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16321 ASSERT_VK_SUCCESS(err);
16322 mmr.offset = allocation_size - 200;
16323 mmr.size = VK_WHOLE_SIZE;
16324 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16325 ASSERT_VK_SUCCESS(err);
16326 m_errorMonitor->VerifyNotFound();
16327 vkUnmapMemory(m_device->device(), mem);
16328
16329 vkFreeMemory(m_device->device(), mem, NULL);
16330}
16331
16332// This is a positive test. We used to expect error in this case but spec now allows it
16333TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16334 m_errorMonitor->ExpectSuccess();
16335 vk_testing::Fence testFence;
16336 VkFenceCreateInfo fenceInfo = {};
16337 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16338 fenceInfo.pNext = NULL;
16339
16340 ASSERT_NO_FATAL_FAILURE(InitState());
16341 testFence.init(*m_device, fenceInfo);
16342 VkFence fences[1] = { testFence.handle() };
16343 VkResult result = vkResetFences(m_device->device(), 1, fences);
16344 ASSERT_VK_SUCCESS(result);
16345
16346 m_errorMonitor->VerifyNotFound();
16347}
16348
16349TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16350 m_errorMonitor->ExpectSuccess();
16351
16352 ASSERT_NO_FATAL_FAILURE(InitState());
16353 VkResult err;
16354
16355 // Record (empty!) command buffer that can be submitted multiple times
16356 // simultaneously.
16357 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16358 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16359 m_commandBuffer->BeginCommandBuffer(&cbbi);
16360 m_commandBuffer->EndCommandBuffer();
16361
16362 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16363 VkFence fence;
16364 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16365 ASSERT_VK_SUCCESS(err);
16366
16367 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16368 VkSemaphore s1, s2;
16369 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16370 ASSERT_VK_SUCCESS(err);
16371 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16372 ASSERT_VK_SUCCESS(err);
16373
16374 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16375 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16376 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16377 ASSERT_VK_SUCCESS(err);
16378
16379 // Submit CB again, signaling s2.
16380 si.pSignalSemaphores = &s2;
16381 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16382 ASSERT_VK_SUCCESS(err);
16383
16384 // Wait for fence.
16385 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16386 ASSERT_VK_SUCCESS(err);
16387
16388 // CB is still in flight from second submission, but semaphore s1 is no
16389 // longer in flight. delete it.
16390 vkDestroySemaphore(m_device->device(), s1, nullptr);
16391
16392 m_errorMonitor->VerifyNotFound();
16393
16394 // Force device idle and clean up remaining objects
16395 vkDeviceWaitIdle(m_device->device());
16396 vkDestroySemaphore(m_device->device(), s2, nullptr);
16397 vkDestroyFence(m_device->device(), fence, nullptr);
16398}
16399
16400TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16401 m_errorMonitor->ExpectSuccess();
16402
16403 ASSERT_NO_FATAL_FAILURE(InitState());
16404 VkResult err;
16405
16406 // A fence created signaled
16407 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16408 VkFence f1;
16409 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16410 ASSERT_VK_SUCCESS(err);
16411
16412 // A fence created not
16413 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16414 VkFence f2;
16415 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16416 ASSERT_VK_SUCCESS(err);
16417
16418 // Submit the unsignaled fence
16419 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16420 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16421
16422 // Wait on both fences, with signaled first.
16423 VkFence fences[] = { f1, f2 };
16424 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16425
16426 // Should have both retired!
16427 vkDestroyFence(m_device->device(), f1, nullptr);
16428 vkDestroyFence(m_device->device(), f2, nullptr);
16429
16430 m_errorMonitor->VerifyNotFound();
16431}
16432
16433TEST_F(VkPositiveLayerTest, ValidUsage) {
16434 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16435 "doesn't generate validation errors");
16436
16437 ASSERT_NO_FATAL_FAILURE(InitState());
16438
16439 m_errorMonitor->ExpectSuccess();
16440 // Verify that we can create a view with usage INPUT_ATTACHMENT
16441 VkImageObj image(m_device);
16442 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16443 ASSERT_TRUE(image.initialized());
16444 VkImageView imageView;
16445 VkImageViewCreateInfo ivci = {};
16446 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16447 ivci.image = image.handle();
16448 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16449 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16450 ivci.subresourceRange.layerCount = 1;
16451 ivci.subresourceRange.baseMipLevel = 0;
16452 ivci.subresourceRange.levelCount = 1;
16453 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16454
16455 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16456 m_errorMonitor->VerifyNotFound();
16457 vkDestroyImageView(m_device->device(), imageView, NULL);
16458}
16459
16460// This is a positive test. No failures are expected.
16461TEST_F(VkPositiveLayerTest, BindSparse) {
16462 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16463 "and then free the memory");
16464
16465 ASSERT_NO_FATAL_FAILURE(InitState());
16466
16467 auto index = m_device->graphics_queue_node_index_;
16468 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16469 return;
16470
16471 m_errorMonitor->ExpectSuccess();
16472
16473 VkImage image;
16474 VkImageCreateInfo image_create_info = {};
16475 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16476 image_create_info.pNext = NULL;
16477 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16478 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16479 image_create_info.extent.width = 64;
16480 image_create_info.extent.height = 64;
16481 image_create_info.extent.depth = 1;
16482 image_create_info.mipLevels = 1;
16483 image_create_info.arrayLayers = 1;
16484 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16485 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16486 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16487 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16488 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16489 ASSERT_VK_SUCCESS(err);
16490
16491 VkMemoryRequirements memory_reqs;
16492 VkDeviceMemory memory_one, memory_two;
16493 bool pass;
16494 VkMemoryAllocateInfo memory_info = {};
16495 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16496 memory_info.pNext = NULL;
16497 memory_info.allocationSize = 0;
16498 memory_info.memoryTypeIndex = 0;
16499 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16500 // Find an image big enough to allow sparse mapping of 2 memory regions
16501 // Increase the image size until it is at least twice the
16502 // size of the required alignment, to ensure we can bind both
16503 // allocated memory blocks to the image on aligned offsets.
16504 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16505 vkDestroyImage(m_device->device(), image, nullptr);
16506 image_create_info.extent.width *= 2;
16507 image_create_info.extent.height *= 2;
16508 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16509 ASSERT_VK_SUCCESS(err);
16510 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16511 }
16512 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16513 // at the end of the first
16514 memory_info.allocationSize = memory_reqs.alignment;
16515 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16516 ASSERT_TRUE(pass);
16517 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16518 ASSERT_VK_SUCCESS(err);
16519 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16520 ASSERT_VK_SUCCESS(err);
16521 VkSparseMemoryBind binds[2];
16522 binds[0].flags = 0;
16523 binds[0].memory = memory_one;
16524 binds[0].memoryOffset = 0;
16525 binds[0].resourceOffset = 0;
16526 binds[0].size = memory_info.allocationSize;
16527 binds[1].flags = 0;
16528 binds[1].memory = memory_two;
16529 binds[1].memoryOffset = 0;
16530 binds[1].resourceOffset = memory_info.allocationSize;
16531 binds[1].size = memory_info.allocationSize;
16532
16533 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16534 opaqueBindInfo.image = image;
16535 opaqueBindInfo.bindCount = 2;
16536 opaqueBindInfo.pBinds = binds;
16537
16538 VkFence fence = VK_NULL_HANDLE;
16539 VkBindSparseInfo bindSparseInfo = {};
16540 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16541 bindSparseInfo.imageOpaqueBindCount = 1;
16542 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16543
16544 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16545 vkQueueWaitIdle(m_device->m_queue);
16546 vkDestroyImage(m_device->device(), image, NULL);
16547 vkFreeMemory(m_device->device(), memory_one, NULL);
16548 vkFreeMemory(m_device->device(), memory_two, NULL);
16549 m_errorMonitor->VerifyNotFound();
16550}
16551
16552TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16553 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16554 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16555 "the command buffer has prior knowledge of that "
16556 "attachment's layout.");
16557
16558 m_errorMonitor->ExpectSuccess();
16559
16560 ASSERT_NO_FATAL_FAILURE(InitState());
16561
16562 // A renderpass with one color attachment.
16563 VkAttachmentDescription attachment = { 0,
16564 VK_FORMAT_R8G8B8A8_UNORM,
16565 VK_SAMPLE_COUNT_1_BIT,
16566 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16567 VK_ATTACHMENT_STORE_OP_STORE,
16568 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16569 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16570 VK_IMAGE_LAYOUT_UNDEFINED,
16571 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16572
16573 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16574
16575 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16576
16577 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16578
16579 VkRenderPass rp;
16580 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16581 ASSERT_VK_SUCCESS(err);
16582
16583 // A compatible framebuffer.
16584 VkImageObj image(m_device);
16585 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16586 ASSERT_TRUE(image.initialized());
16587
16588 VkImageViewCreateInfo ivci = {
16589 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16590 nullptr,
16591 0,
16592 image.handle(),
16593 VK_IMAGE_VIEW_TYPE_2D,
16594 VK_FORMAT_R8G8B8A8_UNORM,
16595 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16596 VK_COMPONENT_SWIZZLE_IDENTITY },
16597 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16598 };
16599 VkImageView view;
16600 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16601 ASSERT_VK_SUCCESS(err);
16602
16603 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16604 VkFramebuffer fb;
16605 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16606 ASSERT_VK_SUCCESS(err);
16607
16608 // Record a single command buffer which uses this renderpass twice. The
16609 // bug is triggered at the beginning of the second renderpass, when the
16610 // command buffer already has a layout recorded for the attachment.
16611 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16612 BeginCommandBuffer();
16613 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16614 vkCmdEndRenderPass(m_commandBuffer->handle());
16615 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16616
16617 m_errorMonitor->VerifyNotFound();
16618
16619 vkCmdEndRenderPass(m_commandBuffer->handle());
16620 EndCommandBuffer();
16621
16622 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16623 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16624 vkDestroyImageView(m_device->device(), view, nullptr);
16625}
16626
16627TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
16628 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
16629 "command buffer, bind them together, then destroy "
16630 "command pool and framebuffer and verify there are no "
16631 "errors.");
16632
16633 m_errorMonitor->ExpectSuccess();
16634
16635 ASSERT_NO_FATAL_FAILURE(InitState());
16636
16637 // A renderpass with one color attachment.
16638 VkAttachmentDescription attachment = { 0,
16639 VK_FORMAT_R8G8B8A8_UNORM,
16640 VK_SAMPLE_COUNT_1_BIT,
16641 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16642 VK_ATTACHMENT_STORE_OP_STORE,
16643 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16644 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16645 VK_IMAGE_LAYOUT_UNDEFINED,
16646 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16647
16648 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16649
16650 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16651
16652 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16653
16654 VkRenderPass rp;
16655 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16656 ASSERT_VK_SUCCESS(err);
16657
16658 // A compatible framebuffer.
16659 VkImageObj image(m_device);
16660 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16661 ASSERT_TRUE(image.initialized());
16662
16663 VkImageViewCreateInfo ivci = {
16664 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16665 nullptr,
16666 0,
16667 image.handle(),
16668 VK_IMAGE_VIEW_TYPE_2D,
16669 VK_FORMAT_R8G8B8A8_UNORM,
16670 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16671 VK_COMPONENT_SWIZZLE_IDENTITY },
16672 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16673 };
16674 VkImageView view;
16675 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16676 ASSERT_VK_SUCCESS(err);
16677
16678 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16679 VkFramebuffer fb;
16680 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16681 ASSERT_VK_SUCCESS(err);
16682
16683 // Explicitly create a command buffer to bind the FB to so that we can then
16684 // destroy the command pool in order to implicitly free command buffer
16685 VkCommandPool command_pool;
16686 VkCommandPoolCreateInfo pool_create_info{};
16687 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16688 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16689 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16690 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16691
16692 VkCommandBuffer command_buffer;
16693 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16694 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16695 command_buffer_allocate_info.commandPool = command_pool;
16696 command_buffer_allocate_info.commandBufferCount = 1;
16697 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16698 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16699
16700 // Begin our cmd buffer with renderpass using our framebuffer
16701 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16702 VkCommandBufferBeginInfo begin_info{};
16703 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16704 vkBeginCommandBuffer(command_buffer, &begin_info);
16705
16706 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16707 vkCmdEndRenderPass(command_buffer);
16708 vkEndCommandBuffer(command_buffer);
16709 vkDestroyImageView(m_device->device(), view, nullptr);
16710 // Destroy command pool to implicitly free command buffer
16711 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16712 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16713 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16714 m_errorMonitor->VerifyNotFound();
16715}
16716
16717TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
16718 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
16719 "transitions for the first subpass");
16720
16721 m_errorMonitor->ExpectSuccess();
16722
16723 ASSERT_NO_FATAL_FAILURE(InitState());
16724
16725 // A renderpass with one color attachment.
16726 VkAttachmentDescription attachment = { 0,
16727 VK_FORMAT_R8G8B8A8_UNORM,
16728 VK_SAMPLE_COUNT_1_BIT,
16729 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16730 VK_ATTACHMENT_STORE_OP_STORE,
16731 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16732 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16733 VK_IMAGE_LAYOUT_UNDEFINED,
16734 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16735
16736 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16737
16738 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16739
16740 VkSubpassDependency dep = { 0,
16741 0,
16742 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16743 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16744 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16745 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16746 VK_DEPENDENCY_BY_REGION_BIT };
16747
16748 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16749
16750 VkResult err;
16751 VkRenderPass rp;
16752 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16753 ASSERT_VK_SUCCESS(err);
16754
16755 // A compatible framebuffer.
16756 VkImageObj image(m_device);
16757 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16758 ASSERT_TRUE(image.initialized());
16759
16760 VkImageViewCreateInfo ivci = {
16761 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16762 nullptr,
16763 0,
16764 image.handle(),
16765 VK_IMAGE_VIEW_TYPE_2D,
16766 VK_FORMAT_R8G8B8A8_UNORM,
16767 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16768 VK_COMPONENT_SWIZZLE_IDENTITY },
16769 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16770 };
16771 VkImageView view;
16772 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16773 ASSERT_VK_SUCCESS(err);
16774
16775 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16776 VkFramebuffer fb;
16777 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16778 ASSERT_VK_SUCCESS(err);
16779
16780 // Record a single command buffer which issues a pipeline barrier w/
16781 // image memory barrier for the attachment. This detects the previously
16782 // missing tracking of the subpass layout by throwing a validation error
16783 // if it doesn't occur.
16784 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16785 BeginCommandBuffer();
16786 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16787
16788 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
16789 nullptr,
16790 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16791 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16792 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16793 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16794 VK_QUEUE_FAMILY_IGNORED,
16795 VK_QUEUE_FAMILY_IGNORED,
16796 image.handle(),
16797 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
16798 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16799 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16800 &imb);
16801
16802 vkCmdEndRenderPass(m_commandBuffer->handle());
16803 m_errorMonitor->VerifyNotFound();
16804 EndCommandBuffer();
16805
16806 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16807 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16808 vkDestroyImageView(m_device->device(), view, nullptr);
16809}
16810
16811TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
16812 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
16813 "is used as a depth/stencil framebuffer attachment, the "
16814 "aspectMask is ignored and both depth and stencil image "
16815 "subresources are used.");
16816
16817 VkFormatProperties format_properties;
16818 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
16819 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
16820 return;
16821 }
16822
16823 m_errorMonitor->ExpectSuccess();
16824
16825 ASSERT_NO_FATAL_FAILURE(InitState());
16826
16827 VkAttachmentDescription attachment = { 0,
16828 VK_FORMAT_D32_SFLOAT_S8_UINT,
16829 VK_SAMPLE_COUNT_1_BIT,
16830 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16831 VK_ATTACHMENT_STORE_OP_STORE,
16832 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16833 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16834 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
16835 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16836
16837 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16838
16839 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
16840
16841 VkSubpassDependency dep = { 0,
16842 0,
16843 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16844 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16845 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16846 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16847 VK_DEPENDENCY_BY_REGION_BIT};
16848
16849 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16850
16851 VkResult err;
16852 VkRenderPass rp;
16853 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16854 ASSERT_VK_SUCCESS(err);
16855
16856 VkImageObj image(m_device);
16857 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
16858 0x26, // usage
16859 VK_IMAGE_TILING_OPTIMAL, 0);
16860 ASSERT_TRUE(image.initialized());
16861 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
16862
16863 VkImageViewCreateInfo ivci = {
16864 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16865 nullptr,
16866 0,
16867 image.handle(),
16868 VK_IMAGE_VIEW_TYPE_2D,
16869 VK_FORMAT_D32_SFLOAT_S8_UINT,
16870 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
16871 { 0x2, 0, 1, 0, 1 },
16872 };
16873 VkImageView view;
16874 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16875 ASSERT_VK_SUCCESS(err);
16876
16877 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16878 VkFramebuffer fb;
16879 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16880 ASSERT_VK_SUCCESS(err);
16881
16882 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16883 BeginCommandBuffer();
16884 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16885
16886 VkImageMemoryBarrier imb = {};
16887 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16888 imb.pNext = nullptr;
16889 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16890 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16891 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16892 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16893 imb.srcQueueFamilyIndex = 0;
16894 imb.dstQueueFamilyIndex = 0;
16895 imb.image = image.handle();
16896 imb.subresourceRange.aspectMask = 0x6;
16897 imb.subresourceRange.baseMipLevel = 0;
16898 imb.subresourceRange.levelCount = 0x1;
16899 imb.subresourceRange.baseArrayLayer = 0;
16900 imb.subresourceRange.layerCount = 0x1;
16901
16902 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16903 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16904 &imb);
16905
16906 vkCmdEndRenderPass(m_commandBuffer->handle());
16907 EndCommandBuffer();
16908 QueueCommandBuffer(false);
16909 m_errorMonitor->VerifyNotFound();
16910
16911 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16912 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16913 vkDestroyImageView(m_device->device(), view, nullptr);
16914}
16915
16916TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
16917 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
16918 "errors, when an attachment reference is "
16919 "VK_ATTACHMENT_UNUSED");
16920
16921 m_errorMonitor->ExpectSuccess();
16922
16923 ASSERT_NO_FATAL_FAILURE(InitState());
16924
16925 // A renderpass with no attachments
16926 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16927
16928 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16929
16930 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
16931
16932 VkRenderPass rp;
16933 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16934 ASSERT_VK_SUCCESS(err);
16935
16936 // A compatible framebuffer.
16937 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
16938 VkFramebuffer fb;
16939 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16940 ASSERT_VK_SUCCESS(err);
16941
16942 // Record a command buffer which just begins and ends the renderpass. The
16943 // bug manifests in BeginRenderPass.
16944 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16945 BeginCommandBuffer();
16946 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16947 vkCmdEndRenderPass(m_commandBuffer->handle());
16948 m_errorMonitor->VerifyNotFound();
16949 EndCommandBuffer();
16950
16951 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16952 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16953}
16954
16955// This is a positive test. No errors are expected.
16956TEST_F(VkPositiveLayerTest, StencilLoadOp) {
16957 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
16958 "CLEAR. stencil[Load|Store]Op used to be ignored.");
16959 VkResult result = VK_SUCCESS;
16960 VkImageFormatProperties formatProps;
16961 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
16962 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
16963 &formatProps);
16964 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
16965 return;
16966 }
16967
16968 ASSERT_NO_FATAL_FAILURE(InitState());
16969 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
16970 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
16971 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
16972 VkAttachmentDescription att = {};
16973 VkAttachmentReference ref = {};
16974 att.format = depth_stencil_fmt;
16975 att.samples = VK_SAMPLE_COUNT_1_BIT;
16976 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
16977 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
16978 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
16979 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
16980 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16981 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16982
16983 VkClearValue clear;
16984 clear.depthStencil.depth = 1.0;
16985 clear.depthStencil.stencil = 0;
16986 ref.attachment = 0;
16987 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16988
16989 VkSubpassDescription subpass = {};
16990 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
16991 subpass.flags = 0;
16992 subpass.inputAttachmentCount = 0;
16993 subpass.pInputAttachments = NULL;
16994 subpass.colorAttachmentCount = 0;
16995 subpass.pColorAttachments = NULL;
16996 subpass.pResolveAttachments = NULL;
16997 subpass.pDepthStencilAttachment = &ref;
16998 subpass.preserveAttachmentCount = 0;
16999 subpass.pPreserveAttachments = NULL;
17000
17001 VkRenderPass rp;
17002 VkRenderPassCreateInfo rp_info = {};
17003 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17004 rp_info.attachmentCount = 1;
17005 rp_info.pAttachments = &att;
17006 rp_info.subpassCount = 1;
17007 rp_info.pSubpasses = &subpass;
17008 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17009 ASSERT_VK_SUCCESS(result);
17010
17011 VkImageView *depthView = m_depthStencil->BindInfo();
17012 VkFramebufferCreateInfo fb_info = {};
17013 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17014 fb_info.pNext = NULL;
17015 fb_info.renderPass = rp;
17016 fb_info.attachmentCount = 1;
17017 fb_info.pAttachments = depthView;
17018 fb_info.width = 100;
17019 fb_info.height = 100;
17020 fb_info.layers = 1;
17021 VkFramebuffer fb;
17022 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17023 ASSERT_VK_SUCCESS(result);
17024
17025 VkRenderPassBeginInfo rpbinfo = {};
17026 rpbinfo.clearValueCount = 1;
17027 rpbinfo.pClearValues = &clear;
17028 rpbinfo.pNext = NULL;
17029 rpbinfo.renderPass = rp;
17030 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17031 rpbinfo.renderArea.extent.width = 100;
17032 rpbinfo.renderArea.extent.height = 100;
17033 rpbinfo.renderArea.offset.x = 0;
17034 rpbinfo.renderArea.offset.y = 0;
17035 rpbinfo.framebuffer = fb;
17036
17037 VkFence fence = {};
17038 VkFenceCreateInfo fence_ci = {};
17039 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17040 fence_ci.pNext = nullptr;
17041 fence_ci.flags = 0;
17042 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17043 ASSERT_VK_SUCCESS(result);
17044
17045 m_commandBuffer->BeginCommandBuffer();
17046 m_commandBuffer->BeginRenderPass(rpbinfo);
17047 m_commandBuffer->EndRenderPass();
17048 m_commandBuffer->EndCommandBuffer();
17049 m_commandBuffer->QueueCommandBuffer(fence);
17050
17051 VkImageObj destImage(m_device);
17052 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17053 VK_IMAGE_TILING_OPTIMAL, 0);
17054 VkImageMemoryBarrier barrier = {};
17055 VkImageSubresourceRange range;
17056 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17057 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17058 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17059 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17060 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17061 barrier.image = m_depthStencil->handle();
17062 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17063 range.baseMipLevel = 0;
17064 range.levelCount = 1;
17065 range.baseArrayLayer = 0;
17066 range.layerCount = 1;
17067 barrier.subresourceRange = range;
17068 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17069 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17070 cmdbuf.BeginCommandBuffer();
17071 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17072 &barrier);
17073 barrier.srcAccessMask = 0;
17074 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17075 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17076 barrier.image = destImage.handle();
17077 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17078 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17079 &barrier);
17080 VkImageCopy cregion;
17081 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17082 cregion.srcSubresource.mipLevel = 0;
17083 cregion.srcSubresource.baseArrayLayer = 0;
17084 cregion.srcSubresource.layerCount = 1;
17085 cregion.srcOffset.x = 0;
17086 cregion.srcOffset.y = 0;
17087 cregion.srcOffset.z = 0;
17088 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17089 cregion.dstSubresource.mipLevel = 0;
17090 cregion.dstSubresource.baseArrayLayer = 0;
17091 cregion.dstSubresource.layerCount = 1;
17092 cregion.dstOffset.x = 0;
17093 cregion.dstOffset.y = 0;
17094 cregion.dstOffset.z = 0;
17095 cregion.extent.width = 100;
17096 cregion.extent.height = 100;
17097 cregion.extent.depth = 1;
17098 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17099 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17100 cmdbuf.EndCommandBuffer();
17101
17102 VkSubmitInfo submit_info;
17103 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17104 submit_info.pNext = NULL;
17105 submit_info.waitSemaphoreCount = 0;
17106 submit_info.pWaitSemaphores = NULL;
17107 submit_info.pWaitDstStageMask = NULL;
17108 submit_info.commandBufferCount = 1;
17109 submit_info.pCommandBuffers = &cmdbuf.handle();
17110 submit_info.signalSemaphoreCount = 0;
17111 submit_info.pSignalSemaphores = NULL;
17112
17113 m_errorMonitor->ExpectSuccess();
17114 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17115 m_errorMonitor->VerifyNotFound();
17116
17117 vkQueueWaitIdle(m_device->m_queue);
17118 vkDestroyFence(m_device->device(), fence, nullptr);
17119 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17120 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17121}
17122
17123// This is a positive test. No errors should be generated.
17124TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17125 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17126
17127 m_errorMonitor->ExpectSuccess();
17128 ASSERT_NO_FATAL_FAILURE(InitState());
17129
17130 VkEvent event;
17131 VkEventCreateInfo event_create_info{};
17132 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17133 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17134
17135 VkCommandPool command_pool;
17136 VkCommandPoolCreateInfo pool_create_info{};
17137 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17138 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17139 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17140 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17141
17142 VkCommandBuffer command_buffer;
17143 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17144 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17145 command_buffer_allocate_info.commandPool = command_pool;
17146 command_buffer_allocate_info.commandBufferCount = 1;
17147 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17148 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17149
17150 VkQueue queue = VK_NULL_HANDLE;
17151 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17152
17153 {
17154 VkCommandBufferBeginInfo begin_info{};
17155 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17156 vkBeginCommandBuffer(command_buffer, &begin_info);
17157
17158 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17159 nullptr, 0, nullptr);
17160 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17161 vkEndCommandBuffer(command_buffer);
17162 }
17163 {
17164 VkSubmitInfo submit_info{};
17165 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17166 submit_info.commandBufferCount = 1;
17167 submit_info.pCommandBuffers = &command_buffer;
17168 submit_info.signalSemaphoreCount = 0;
17169 submit_info.pSignalSemaphores = nullptr;
17170 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17171 }
17172 { vkSetEvent(m_device->device(), event); }
17173
17174 vkQueueWaitIdle(queue);
17175
17176 vkDestroyEvent(m_device->device(), event, nullptr);
17177 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17178 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17179
17180 m_errorMonitor->VerifyNotFound();
17181}
17182// This is a positive test. No errors should be generated.
17183TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17184 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17185
17186 ASSERT_NO_FATAL_FAILURE(InitState());
17187 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17188 return;
17189
17190 m_errorMonitor->ExpectSuccess();
17191
17192 VkQueryPool query_pool;
17193 VkQueryPoolCreateInfo query_pool_create_info{};
17194 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17195 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17196 query_pool_create_info.queryCount = 1;
17197 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17198
17199 VkCommandPool command_pool;
17200 VkCommandPoolCreateInfo pool_create_info{};
17201 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17202 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17203 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17204 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17205
17206 VkCommandBuffer command_buffer;
17207 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17208 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17209 command_buffer_allocate_info.commandPool = command_pool;
17210 command_buffer_allocate_info.commandBufferCount = 1;
17211 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17212 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17213
17214 VkCommandBuffer secondary_command_buffer;
17215 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17216 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17217
17218 VkQueue queue = VK_NULL_HANDLE;
17219 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17220
17221 uint32_t qfi = 0;
17222 VkBufferCreateInfo buff_create_info = {};
17223 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17224 buff_create_info.size = 1024;
17225 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17226 buff_create_info.queueFamilyIndexCount = 1;
17227 buff_create_info.pQueueFamilyIndices = &qfi;
17228
17229 VkResult err;
17230 VkBuffer buffer;
17231 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17232 ASSERT_VK_SUCCESS(err);
17233 VkMemoryAllocateInfo mem_alloc = {};
17234 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17235 mem_alloc.pNext = NULL;
17236 mem_alloc.allocationSize = 1024;
17237 mem_alloc.memoryTypeIndex = 0;
17238
17239 VkMemoryRequirements memReqs;
17240 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17241 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17242 if (!pass) {
17243 vkDestroyBuffer(m_device->device(), buffer, NULL);
17244 return;
17245 }
17246
17247 VkDeviceMemory mem;
17248 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17249 ASSERT_VK_SUCCESS(err);
17250 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17251 ASSERT_VK_SUCCESS(err);
17252
17253 VkCommandBufferInheritanceInfo hinfo = {};
17254 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17255 hinfo.renderPass = VK_NULL_HANDLE;
17256 hinfo.subpass = 0;
17257 hinfo.framebuffer = VK_NULL_HANDLE;
17258 hinfo.occlusionQueryEnable = VK_FALSE;
17259 hinfo.queryFlags = 0;
17260 hinfo.pipelineStatistics = 0;
17261
17262 {
17263 VkCommandBufferBeginInfo begin_info{};
17264 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17265 begin_info.pInheritanceInfo = &hinfo;
17266 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17267
17268 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17269 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17270
17271 vkEndCommandBuffer(secondary_command_buffer);
17272
17273 begin_info.pInheritanceInfo = nullptr;
17274 vkBeginCommandBuffer(command_buffer, &begin_info);
17275
17276 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17277 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17278
17279 vkEndCommandBuffer(command_buffer);
17280 }
17281 {
17282 VkSubmitInfo submit_info{};
17283 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17284 submit_info.commandBufferCount = 1;
17285 submit_info.pCommandBuffers = &command_buffer;
17286 submit_info.signalSemaphoreCount = 0;
17287 submit_info.pSignalSemaphores = nullptr;
17288 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17289 }
17290
17291 vkQueueWaitIdle(queue);
17292
17293 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17294 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17295 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17296 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17297 vkDestroyBuffer(m_device->device(), buffer, NULL);
17298 vkFreeMemory(m_device->device(), mem, NULL);
17299
17300 m_errorMonitor->VerifyNotFound();
17301}
17302
17303// This is a positive test. No errors should be generated.
17304TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17305 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17306
17307 ASSERT_NO_FATAL_FAILURE(InitState());
17308 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17309 return;
17310
17311 m_errorMonitor->ExpectSuccess();
17312
17313 VkQueryPool query_pool;
17314 VkQueryPoolCreateInfo query_pool_create_info{};
17315 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17316 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17317 query_pool_create_info.queryCount = 1;
17318 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17319
17320 VkCommandPool command_pool;
17321 VkCommandPoolCreateInfo pool_create_info{};
17322 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17323 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17324 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17325 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17326
17327 VkCommandBuffer command_buffer[2];
17328 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17329 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17330 command_buffer_allocate_info.commandPool = command_pool;
17331 command_buffer_allocate_info.commandBufferCount = 2;
17332 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17333 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17334
17335 VkQueue queue = VK_NULL_HANDLE;
17336 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17337
17338 uint32_t qfi = 0;
17339 VkBufferCreateInfo buff_create_info = {};
17340 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17341 buff_create_info.size = 1024;
17342 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17343 buff_create_info.queueFamilyIndexCount = 1;
17344 buff_create_info.pQueueFamilyIndices = &qfi;
17345
17346 VkResult err;
17347 VkBuffer buffer;
17348 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17349 ASSERT_VK_SUCCESS(err);
17350 VkMemoryAllocateInfo mem_alloc = {};
17351 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17352 mem_alloc.pNext = NULL;
17353 mem_alloc.allocationSize = 1024;
17354 mem_alloc.memoryTypeIndex = 0;
17355
17356 VkMemoryRequirements memReqs;
17357 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17358 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17359 if (!pass) {
17360 vkDestroyBuffer(m_device->device(), buffer, NULL);
17361 return;
17362 }
17363
17364 VkDeviceMemory mem;
17365 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17366 ASSERT_VK_SUCCESS(err);
17367 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17368 ASSERT_VK_SUCCESS(err);
17369
17370 {
17371 VkCommandBufferBeginInfo begin_info{};
17372 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17373 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17374
17375 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17376 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17377
17378 vkEndCommandBuffer(command_buffer[0]);
17379
17380 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17381
17382 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17383
17384 vkEndCommandBuffer(command_buffer[1]);
17385 }
17386 {
17387 VkSubmitInfo submit_info{};
17388 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17389 submit_info.commandBufferCount = 2;
17390 submit_info.pCommandBuffers = command_buffer;
17391 submit_info.signalSemaphoreCount = 0;
17392 submit_info.pSignalSemaphores = nullptr;
17393 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17394 }
17395
17396 vkQueueWaitIdle(queue);
17397
17398 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17399 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17400 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17401 vkDestroyBuffer(m_device->device(), buffer, NULL);
17402 vkFreeMemory(m_device->device(), mem, NULL);
17403
17404 m_errorMonitor->VerifyNotFound();
17405}
17406
Tony Barbourc46924f2016-11-04 11:49:52 -060017407TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017408 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17409
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017410 ASSERT_NO_FATAL_FAILURE(InitState());
17411 VkEvent event;
17412 VkEventCreateInfo event_create_info{};
17413 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17414 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17415
17416 VkCommandPool command_pool;
17417 VkCommandPoolCreateInfo pool_create_info{};
17418 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17419 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17420 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17421 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17422
17423 VkCommandBuffer command_buffer;
17424 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17425 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17426 command_buffer_allocate_info.commandPool = command_pool;
17427 command_buffer_allocate_info.commandBufferCount = 1;
17428 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17429 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17430
17431 VkQueue queue = VK_NULL_HANDLE;
17432 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17433
17434 {
17435 VkCommandBufferBeginInfo begin_info{};
17436 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17437 vkBeginCommandBuffer(command_buffer, &begin_info);
17438
17439 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017440 vkEndCommandBuffer(command_buffer);
17441 }
17442 {
17443 VkSubmitInfo submit_info{};
17444 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17445 submit_info.commandBufferCount = 1;
17446 submit_info.pCommandBuffers = &command_buffer;
17447 submit_info.signalSemaphoreCount = 0;
17448 submit_info.pSignalSemaphores = nullptr;
17449 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17450 }
17451 {
17452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17453 "command buffer.");
17454 vkSetEvent(m_device->device(), event);
17455 m_errorMonitor->VerifyFound();
17456 }
17457
17458 vkQueueWaitIdle(queue);
17459
17460 vkDestroyEvent(m_device->device(), event, nullptr);
17461 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17462 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17463}
17464
17465// This is a positive test. No errors should be generated.
17466TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17467 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17468 "run through a Submit & WaitForFences cycle 3 times. This "
17469 "previously revealed a bug so running this positive test "
17470 "to prevent a regression.");
17471 m_errorMonitor->ExpectSuccess();
17472
17473 ASSERT_NO_FATAL_FAILURE(InitState());
17474 VkQueue queue = VK_NULL_HANDLE;
17475 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17476
17477 static const uint32_t NUM_OBJECTS = 2;
17478 static const uint32_t NUM_FRAMES = 3;
17479 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17480 VkFence fences[NUM_OBJECTS] = {};
17481
17482 VkCommandPool cmd_pool;
17483 VkCommandPoolCreateInfo cmd_pool_ci = {};
17484 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17485 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17486 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17487 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17488 ASSERT_VK_SUCCESS(err);
17489
17490 VkCommandBufferAllocateInfo cmd_buf_info = {};
17491 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17492 cmd_buf_info.commandPool = cmd_pool;
17493 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17494 cmd_buf_info.commandBufferCount = 1;
17495
17496 VkFenceCreateInfo fence_ci = {};
17497 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17498 fence_ci.pNext = nullptr;
17499 fence_ci.flags = 0;
17500
17501 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17502 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17503 ASSERT_VK_SUCCESS(err);
17504 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17505 ASSERT_VK_SUCCESS(err);
17506 }
17507
17508 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17509 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17510 // Create empty cmd buffer
17511 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17512 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17513
17514 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17515 ASSERT_VK_SUCCESS(err);
17516 err = vkEndCommandBuffer(cmd_buffers[obj]);
17517 ASSERT_VK_SUCCESS(err);
17518
17519 VkSubmitInfo submit_info = {};
17520 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17521 submit_info.commandBufferCount = 1;
17522 submit_info.pCommandBuffers = &cmd_buffers[obj];
17523 // Submit cmd buffer and wait for fence
17524 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17525 ASSERT_VK_SUCCESS(err);
17526 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17527 ASSERT_VK_SUCCESS(err);
17528 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17529 ASSERT_VK_SUCCESS(err);
17530 }
17531 }
17532 m_errorMonitor->VerifyNotFound();
17533 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17534 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17535 vkDestroyFence(m_device->device(), fences[i], nullptr);
17536 }
17537}
17538// This is a positive test. No errors should be generated.
17539TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17540
17541 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17542 "submitted on separate queues followed by a QueueWaitIdle.");
17543
17544 ASSERT_NO_FATAL_FAILURE(InitState());
17545 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17546 return;
17547
17548 m_errorMonitor->ExpectSuccess();
17549
17550 VkSemaphore semaphore;
17551 VkSemaphoreCreateInfo semaphore_create_info{};
17552 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17553 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17554
17555 VkCommandPool command_pool;
17556 VkCommandPoolCreateInfo pool_create_info{};
17557 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17558 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17559 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17560 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17561
17562 VkCommandBuffer command_buffer[2];
17563 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17564 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17565 command_buffer_allocate_info.commandPool = command_pool;
17566 command_buffer_allocate_info.commandBufferCount = 2;
17567 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17568 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17569
17570 VkQueue queue = VK_NULL_HANDLE;
17571 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17572
17573 {
17574 VkCommandBufferBeginInfo begin_info{};
17575 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17576 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17577
17578 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17579 nullptr, 0, nullptr, 0, nullptr);
17580
17581 VkViewport viewport{};
17582 viewport.maxDepth = 1.0f;
17583 viewport.minDepth = 0.0f;
17584 viewport.width = 512;
17585 viewport.height = 512;
17586 viewport.x = 0;
17587 viewport.y = 0;
17588 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17589 vkEndCommandBuffer(command_buffer[0]);
17590 }
17591 {
17592 VkCommandBufferBeginInfo begin_info{};
17593 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17594 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17595
17596 VkViewport viewport{};
17597 viewport.maxDepth = 1.0f;
17598 viewport.minDepth = 0.0f;
17599 viewport.width = 512;
17600 viewport.height = 512;
17601 viewport.x = 0;
17602 viewport.y = 0;
17603 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17604 vkEndCommandBuffer(command_buffer[1]);
17605 }
17606 {
17607 VkSubmitInfo submit_info{};
17608 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17609 submit_info.commandBufferCount = 1;
17610 submit_info.pCommandBuffers = &command_buffer[0];
17611 submit_info.signalSemaphoreCount = 1;
17612 submit_info.pSignalSemaphores = &semaphore;
17613 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17614 }
17615 {
17616 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17617 VkSubmitInfo submit_info{};
17618 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17619 submit_info.commandBufferCount = 1;
17620 submit_info.pCommandBuffers = &command_buffer[1];
17621 submit_info.waitSemaphoreCount = 1;
17622 submit_info.pWaitSemaphores = &semaphore;
17623 submit_info.pWaitDstStageMask = flags;
17624 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17625 }
17626
17627 vkQueueWaitIdle(m_device->m_queue);
17628
17629 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17630 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17631 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17632
17633 m_errorMonitor->VerifyNotFound();
17634}
17635
17636// This is a positive test. No errors should be generated.
17637TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
17638
17639 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17640 "submitted on separate queues, the second having a fence"
17641 "followed by a QueueWaitIdle.");
17642
17643 ASSERT_NO_FATAL_FAILURE(InitState());
17644 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17645 return;
17646
17647 m_errorMonitor->ExpectSuccess();
17648
17649 VkFence fence;
17650 VkFenceCreateInfo fence_create_info{};
17651 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17652 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17653
17654 VkSemaphore semaphore;
17655 VkSemaphoreCreateInfo semaphore_create_info{};
17656 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17657 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17658
17659 VkCommandPool command_pool;
17660 VkCommandPoolCreateInfo pool_create_info{};
17661 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17662 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17663 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17664 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17665
17666 VkCommandBuffer command_buffer[2];
17667 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17668 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17669 command_buffer_allocate_info.commandPool = command_pool;
17670 command_buffer_allocate_info.commandBufferCount = 2;
17671 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17672 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17673
17674 VkQueue queue = VK_NULL_HANDLE;
17675 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17676
17677 {
17678 VkCommandBufferBeginInfo begin_info{};
17679 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17680 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17681
17682 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17683 nullptr, 0, nullptr, 0, nullptr);
17684
17685 VkViewport viewport{};
17686 viewport.maxDepth = 1.0f;
17687 viewport.minDepth = 0.0f;
17688 viewport.width = 512;
17689 viewport.height = 512;
17690 viewport.x = 0;
17691 viewport.y = 0;
17692 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17693 vkEndCommandBuffer(command_buffer[0]);
17694 }
17695 {
17696 VkCommandBufferBeginInfo begin_info{};
17697 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17698 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17699
17700 VkViewport viewport{};
17701 viewport.maxDepth = 1.0f;
17702 viewport.minDepth = 0.0f;
17703 viewport.width = 512;
17704 viewport.height = 512;
17705 viewport.x = 0;
17706 viewport.y = 0;
17707 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17708 vkEndCommandBuffer(command_buffer[1]);
17709 }
17710 {
17711 VkSubmitInfo submit_info{};
17712 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17713 submit_info.commandBufferCount = 1;
17714 submit_info.pCommandBuffers = &command_buffer[0];
17715 submit_info.signalSemaphoreCount = 1;
17716 submit_info.pSignalSemaphores = &semaphore;
17717 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17718 }
17719 {
17720 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17721 VkSubmitInfo submit_info{};
17722 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17723 submit_info.commandBufferCount = 1;
17724 submit_info.pCommandBuffers = &command_buffer[1];
17725 submit_info.waitSemaphoreCount = 1;
17726 submit_info.pWaitSemaphores = &semaphore;
17727 submit_info.pWaitDstStageMask = flags;
17728 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17729 }
17730
17731 vkQueueWaitIdle(m_device->m_queue);
17732
17733 vkDestroyFence(m_device->device(), fence, nullptr);
17734 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17735 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17736 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17737
17738 m_errorMonitor->VerifyNotFound();
17739}
17740
17741// This is a positive test. No errors should be generated.
17742TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
17743
17744 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17745 "submitted on separate queues, the second having a fence"
17746 "followed by two consecutive WaitForFences calls on the same fence.");
17747
17748 ASSERT_NO_FATAL_FAILURE(InitState());
17749 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17750 return;
17751
17752 m_errorMonitor->ExpectSuccess();
17753
17754 VkFence fence;
17755 VkFenceCreateInfo fence_create_info{};
17756 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17757 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17758
17759 VkSemaphore semaphore;
17760 VkSemaphoreCreateInfo semaphore_create_info{};
17761 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17762 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17763
17764 VkCommandPool command_pool;
17765 VkCommandPoolCreateInfo pool_create_info{};
17766 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17767 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17768 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17769 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17770
17771 VkCommandBuffer command_buffer[2];
17772 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17773 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17774 command_buffer_allocate_info.commandPool = command_pool;
17775 command_buffer_allocate_info.commandBufferCount = 2;
17776 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17777 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17778
17779 VkQueue queue = VK_NULL_HANDLE;
17780 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17781
17782 {
17783 VkCommandBufferBeginInfo begin_info{};
17784 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17785 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17786
17787 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17788 nullptr, 0, nullptr, 0, nullptr);
17789
17790 VkViewport viewport{};
17791 viewport.maxDepth = 1.0f;
17792 viewport.minDepth = 0.0f;
17793 viewport.width = 512;
17794 viewport.height = 512;
17795 viewport.x = 0;
17796 viewport.y = 0;
17797 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17798 vkEndCommandBuffer(command_buffer[0]);
17799 }
17800 {
17801 VkCommandBufferBeginInfo begin_info{};
17802 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17803 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17804
17805 VkViewport viewport{};
17806 viewport.maxDepth = 1.0f;
17807 viewport.minDepth = 0.0f;
17808 viewport.width = 512;
17809 viewport.height = 512;
17810 viewport.x = 0;
17811 viewport.y = 0;
17812 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17813 vkEndCommandBuffer(command_buffer[1]);
17814 }
17815 {
17816 VkSubmitInfo submit_info{};
17817 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17818 submit_info.commandBufferCount = 1;
17819 submit_info.pCommandBuffers = &command_buffer[0];
17820 submit_info.signalSemaphoreCount = 1;
17821 submit_info.pSignalSemaphores = &semaphore;
17822 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17823 }
17824 {
17825 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17826 VkSubmitInfo submit_info{};
17827 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17828 submit_info.commandBufferCount = 1;
17829 submit_info.pCommandBuffers = &command_buffer[1];
17830 submit_info.waitSemaphoreCount = 1;
17831 submit_info.pWaitSemaphores = &semaphore;
17832 submit_info.pWaitDstStageMask = flags;
17833 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17834 }
17835
17836 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17837 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17838
17839 vkDestroyFence(m_device->device(), fence, nullptr);
17840 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17841 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17842 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17843
17844 m_errorMonitor->VerifyNotFound();
17845}
17846
17847TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
17848
17849 ASSERT_NO_FATAL_FAILURE(InitState());
17850 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
17851 printf("Test requires two queues, skipping\n");
17852 return;
17853 }
17854
17855 VkResult err;
17856
17857 m_errorMonitor->ExpectSuccess();
17858
17859 VkQueue q0 = m_device->m_queue;
17860 VkQueue q1 = nullptr;
17861 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
17862 ASSERT_NE(q1, nullptr);
17863
17864 // An (empty) command buffer. We must have work in the first submission --
17865 // the layer treats unfenced work differently from fenced work.
17866 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
17867 VkCommandPool pool;
17868 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
17869 ASSERT_VK_SUCCESS(err);
17870 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
17871 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
17872 VkCommandBuffer cb;
17873 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
17874 ASSERT_VK_SUCCESS(err);
17875 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
17876 err = vkBeginCommandBuffer(cb, &cbbi);
17877 ASSERT_VK_SUCCESS(err);
17878 err = vkEndCommandBuffer(cb);
17879 ASSERT_VK_SUCCESS(err);
17880
17881 // A semaphore
17882 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17883 VkSemaphore s;
17884 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
17885 ASSERT_VK_SUCCESS(err);
17886
17887 // First submission, to q0
17888 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
17889
17890 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
17891 ASSERT_VK_SUCCESS(err);
17892
17893 // Second submission, to q1, waiting on s
17894 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
17895 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
17896
17897 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
17898 ASSERT_VK_SUCCESS(err);
17899
17900 // Wait for q0 idle
17901 err = vkQueueWaitIdle(q0);
17902 ASSERT_VK_SUCCESS(err);
17903
17904 // Command buffer should have been completed (it was on q0); reset the pool.
17905 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
17906
17907 m_errorMonitor->VerifyNotFound();
17908
17909 // Force device completely idle and clean up resources
17910 vkDeviceWaitIdle(m_device->device());
17911 vkDestroyCommandPool(m_device->device(), pool, nullptr);
17912 vkDestroySemaphore(m_device->device(), s, nullptr);
17913}
17914
17915// This is a positive test. No errors should be generated.
17916TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
17917
17918 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17919 "submitted on separate queues, the second having a fence, "
17920 "followed by a WaitForFences call.");
17921
17922 ASSERT_NO_FATAL_FAILURE(InitState());
17923 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17924 return;
17925
17926 m_errorMonitor->ExpectSuccess();
17927
17928 ASSERT_NO_FATAL_FAILURE(InitState());
17929 VkFence fence;
17930 VkFenceCreateInfo fence_create_info{};
17931 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17932 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17933
17934 VkSemaphore semaphore;
17935 VkSemaphoreCreateInfo semaphore_create_info{};
17936 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17937 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17938
17939 VkCommandPool command_pool;
17940 VkCommandPoolCreateInfo pool_create_info{};
17941 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17942 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17943 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17944 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17945
17946 VkCommandBuffer command_buffer[2];
17947 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17948 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17949 command_buffer_allocate_info.commandPool = command_pool;
17950 command_buffer_allocate_info.commandBufferCount = 2;
17951 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17952 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17953
17954 VkQueue queue = VK_NULL_HANDLE;
17955 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17956
17957 {
17958 VkCommandBufferBeginInfo begin_info{};
17959 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17960 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17961
17962 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17963 nullptr, 0, nullptr, 0, nullptr);
17964
17965 VkViewport viewport{};
17966 viewport.maxDepth = 1.0f;
17967 viewport.minDepth = 0.0f;
17968 viewport.width = 512;
17969 viewport.height = 512;
17970 viewport.x = 0;
17971 viewport.y = 0;
17972 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17973 vkEndCommandBuffer(command_buffer[0]);
17974 }
17975 {
17976 VkCommandBufferBeginInfo begin_info{};
17977 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17978 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17979
17980 VkViewport viewport{};
17981 viewport.maxDepth = 1.0f;
17982 viewport.minDepth = 0.0f;
17983 viewport.width = 512;
17984 viewport.height = 512;
17985 viewport.x = 0;
17986 viewport.y = 0;
17987 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17988 vkEndCommandBuffer(command_buffer[1]);
17989 }
17990 {
17991 VkSubmitInfo submit_info{};
17992 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17993 submit_info.commandBufferCount = 1;
17994 submit_info.pCommandBuffers = &command_buffer[0];
17995 submit_info.signalSemaphoreCount = 1;
17996 submit_info.pSignalSemaphores = &semaphore;
17997 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17998 }
17999 {
18000 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18001 VkSubmitInfo submit_info{};
18002 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18003 submit_info.commandBufferCount = 1;
18004 submit_info.pCommandBuffers = &command_buffer[1];
18005 submit_info.waitSemaphoreCount = 1;
18006 submit_info.pWaitSemaphores = &semaphore;
18007 submit_info.pWaitDstStageMask = flags;
18008 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18009 }
18010
18011 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18012
18013 vkDestroyFence(m_device->device(), fence, nullptr);
18014 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18015 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18016 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18017
18018 m_errorMonitor->VerifyNotFound();
18019}
18020
18021// This is a positive test. No errors should be generated.
18022TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18023
18024 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18025 "on the same queue, sharing a signal/wait semaphore, the "
18026 "second having a fence, "
18027 "followed by a WaitForFences call.");
18028
18029 m_errorMonitor->ExpectSuccess();
18030
18031 ASSERT_NO_FATAL_FAILURE(InitState());
18032 VkFence fence;
18033 VkFenceCreateInfo fence_create_info{};
18034 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18035 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18036
18037 VkSemaphore semaphore;
18038 VkSemaphoreCreateInfo semaphore_create_info{};
18039 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18040 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18041
18042 VkCommandPool command_pool;
18043 VkCommandPoolCreateInfo pool_create_info{};
18044 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18045 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18046 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18047 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18048
18049 VkCommandBuffer command_buffer[2];
18050 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18051 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18052 command_buffer_allocate_info.commandPool = command_pool;
18053 command_buffer_allocate_info.commandBufferCount = 2;
18054 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18055 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18056
18057 {
18058 VkCommandBufferBeginInfo begin_info{};
18059 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18060 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18061
18062 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18063 nullptr, 0, nullptr, 0, nullptr);
18064
18065 VkViewport viewport{};
18066 viewport.maxDepth = 1.0f;
18067 viewport.minDepth = 0.0f;
18068 viewport.width = 512;
18069 viewport.height = 512;
18070 viewport.x = 0;
18071 viewport.y = 0;
18072 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18073 vkEndCommandBuffer(command_buffer[0]);
18074 }
18075 {
18076 VkCommandBufferBeginInfo begin_info{};
18077 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18078 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18079
18080 VkViewport viewport{};
18081 viewport.maxDepth = 1.0f;
18082 viewport.minDepth = 0.0f;
18083 viewport.width = 512;
18084 viewport.height = 512;
18085 viewport.x = 0;
18086 viewport.y = 0;
18087 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18088 vkEndCommandBuffer(command_buffer[1]);
18089 }
18090 {
18091 VkSubmitInfo submit_info{};
18092 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18093 submit_info.commandBufferCount = 1;
18094 submit_info.pCommandBuffers = &command_buffer[0];
18095 submit_info.signalSemaphoreCount = 1;
18096 submit_info.pSignalSemaphores = &semaphore;
18097 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18098 }
18099 {
18100 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18101 VkSubmitInfo submit_info{};
18102 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18103 submit_info.commandBufferCount = 1;
18104 submit_info.pCommandBuffers = &command_buffer[1];
18105 submit_info.waitSemaphoreCount = 1;
18106 submit_info.pWaitSemaphores = &semaphore;
18107 submit_info.pWaitDstStageMask = flags;
18108 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18109 }
18110
18111 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18112
18113 vkDestroyFence(m_device->device(), fence, nullptr);
18114 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18115 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18116 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18117
18118 m_errorMonitor->VerifyNotFound();
18119}
18120
18121// This is a positive test. No errors should be generated.
18122TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18123
18124 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18125 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18126 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18127
18128 m_errorMonitor->ExpectSuccess();
18129
18130 ASSERT_NO_FATAL_FAILURE(InitState());
18131 VkFence fence;
18132 VkFenceCreateInfo fence_create_info{};
18133 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18134 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18135
18136 VkCommandPool command_pool;
18137 VkCommandPoolCreateInfo pool_create_info{};
18138 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18139 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18140 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18141 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18142
18143 VkCommandBuffer command_buffer[2];
18144 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18145 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18146 command_buffer_allocate_info.commandPool = command_pool;
18147 command_buffer_allocate_info.commandBufferCount = 2;
18148 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18149 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18150
18151 {
18152 VkCommandBufferBeginInfo begin_info{};
18153 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18154 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18155
18156 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18157 nullptr, 0, nullptr, 0, nullptr);
18158
18159 VkViewport viewport{};
18160 viewport.maxDepth = 1.0f;
18161 viewport.minDepth = 0.0f;
18162 viewport.width = 512;
18163 viewport.height = 512;
18164 viewport.x = 0;
18165 viewport.y = 0;
18166 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18167 vkEndCommandBuffer(command_buffer[0]);
18168 }
18169 {
18170 VkCommandBufferBeginInfo begin_info{};
18171 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18172 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18173
18174 VkViewport viewport{};
18175 viewport.maxDepth = 1.0f;
18176 viewport.minDepth = 0.0f;
18177 viewport.width = 512;
18178 viewport.height = 512;
18179 viewport.x = 0;
18180 viewport.y = 0;
18181 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18182 vkEndCommandBuffer(command_buffer[1]);
18183 }
18184 {
18185 VkSubmitInfo submit_info{};
18186 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18187 submit_info.commandBufferCount = 1;
18188 submit_info.pCommandBuffers = &command_buffer[0];
18189 submit_info.signalSemaphoreCount = 0;
18190 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18191 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18192 }
18193 {
18194 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18195 VkSubmitInfo submit_info{};
18196 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18197 submit_info.commandBufferCount = 1;
18198 submit_info.pCommandBuffers = &command_buffer[1];
18199 submit_info.waitSemaphoreCount = 0;
18200 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18201 submit_info.pWaitDstStageMask = flags;
18202 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18203 }
18204
18205 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18206
18207 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18208 ASSERT_VK_SUCCESS(err);
18209
18210 vkDestroyFence(m_device->device(), fence, nullptr);
18211 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18212 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18213
18214 m_errorMonitor->VerifyNotFound();
18215}
18216
18217// This is a positive test. No errors should be generated.
18218TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18219
18220 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18221 "on the same queue, the second having a fence, followed "
18222 "by a WaitForFences call.");
18223
18224 m_errorMonitor->ExpectSuccess();
18225
18226 ASSERT_NO_FATAL_FAILURE(InitState());
18227 VkFence fence;
18228 VkFenceCreateInfo fence_create_info{};
18229 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18230 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18231
18232 VkCommandPool command_pool;
18233 VkCommandPoolCreateInfo pool_create_info{};
18234 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18235 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18236 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18237 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18238
18239 VkCommandBuffer command_buffer[2];
18240 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18241 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18242 command_buffer_allocate_info.commandPool = command_pool;
18243 command_buffer_allocate_info.commandBufferCount = 2;
18244 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18245 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18246
18247 {
18248 VkCommandBufferBeginInfo begin_info{};
18249 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18250 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18251
18252 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18253 nullptr, 0, nullptr, 0, nullptr);
18254
18255 VkViewport viewport{};
18256 viewport.maxDepth = 1.0f;
18257 viewport.minDepth = 0.0f;
18258 viewport.width = 512;
18259 viewport.height = 512;
18260 viewport.x = 0;
18261 viewport.y = 0;
18262 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18263 vkEndCommandBuffer(command_buffer[0]);
18264 }
18265 {
18266 VkCommandBufferBeginInfo begin_info{};
18267 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18268 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18269
18270 VkViewport viewport{};
18271 viewport.maxDepth = 1.0f;
18272 viewport.minDepth = 0.0f;
18273 viewport.width = 512;
18274 viewport.height = 512;
18275 viewport.x = 0;
18276 viewport.y = 0;
18277 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18278 vkEndCommandBuffer(command_buffer[1]);
18279 }
18280 {
18281 VkSubmitInfo submit_info{};
18282 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18283 submit_info.commandBufferCount = 1;
18284 submit_info.pCommandBuffers = &command_buffer[0];
18285 submit_info.signalSemaphoreCount = 0;
18286 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18287 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18288 }
18289 {
18290 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18291 VkSubmitInfo submit_info{};
18292 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18293 submit_info.commandBufferCount = 1;
18294 submit_info.pCommandBuffers = &command_buffer[1];
18295 submit_info.waitSemaphoreCount = 0;
18296 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18297 submit_info.pWaitDstStageMask = flags;
18298 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18299 }
18300
18301 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18302
18303 vkDestroyFence(m_device->device(), fence, nullptr);
18304 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18305 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18306
18307 m_errorMonitor->VerifyNotFound();
18308}
18309
18310// This is a positive test. No errors should be generated.
18311TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18312
18313 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18314 "QueueSubmit call followed by a WaitForFences call.");
18315 ASSERT_NO_FATAL_FAILURE(InitState());
18316
18317 m_errorMonitor->ExpectSuccess();
18318
18319 VkFence fence;
18320 VkFenceCreateInfo fence_create_info{};
18321 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18322 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18323
18324 VkSemaphore semaphore;
18325 VkSemaphoreCreateInfo semaphore_create_info{};
18326 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18327 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18328
18329 VkCommandPool command_pool;
18330 VkCommandPoolCreateInfo pool_create_info{};
18331 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18332 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18333 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18334 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18335
18336 VkCommandBuffer command_buffer[2];
18337 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18338 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18339 command_buffer_allocate_info.commandPool = command_pool;
18340 command_buffer_allocate_info.commandBufferCount = 2;
18341 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18342 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18343
18344 {
18345 VkCommandBufferBeginInfo begin_info{};
18346 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18347 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18348
18349 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18350 nullptr, 0, nullptr, 0, nullptr);
18351
18352 VkViewport viewport{};
18353 viewport.maxDepth = 1.0f;
18354 viewport.minDepth = 0.0f;
18355 viewport.width = 512;
18356 viewport.height = 512;
18357 viewport.x = 0;
18358 viewport.y = 0;
18359 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18360 vkEndCommandBuffer(command_buffer[0]);
18361 }
18362 {
18363 VkCommandBufferBeginInfo begin_info{};
18364 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18365 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18366
18367 VkViewport viewport{};
18368 viewport.maxDepth = 1.0f;
18369 viewport.minDepth = 0.0f;
18370 viewport.width = 512;
18371 viewport.height = 512;
18372 viewport.x = 0;
18373 viewport.y = 0;
18374 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18375 vkEndCommandBuffer(command_buffer[1]);
18376 }
18377 {
18378 VkSubmitInfo submit_info[2];
18379 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18380
18381 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18382 submit_info[0].pNext = NULL;
18383 submit_info[0].commandBufferCount = 1;
18384 submit_info[0].pCommandBuffers = &command_buffer[0];
18385 submit_info[0].signalSemaphoreCount = 1;
18386 submit_info[0].pSignalSemaphores = &semaphore;
18387 submit_info[0].waitSemaphoreCount = 0;
18388 submit_info[0].pWaitSemaphores = NULL;
18389 submit_info[0].pWaitDstStageMask = 0;
18390
18391 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18392 submit_info[1].pNext = NULL;
18393 submit_info[1].commandBufferCount = 1;
18394 submit_info[1].pCommandBuffers = &command_buffer[1];
18395 submit_info[1].waitSemaphoreCount = 1;
18396 submit_info[1].pWaitSemaphores = &semaphore;
18397 submit_info[1].pWaitDstStageMask = flags;
18398 submit_info[1].signalSemaphoreCount = 0;
18399 submit_info[1].pSignalSemaphores = NULL;
18400 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18401 }
18402
18403 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18404
18405 vkDestroyFence(m_device->device(), fence, nullptr);
18406 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18407 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18408 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18409
18410 m_errorMonitor->VerifyNotFound();
18411}
18412
18413TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18414 m_errorMonitor->ExpectSuccess();
18415
18416 ASSERT_NO_FATAL_FAILURE(InitState());
18417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18418
18419 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18420 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18421
18422 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18423 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18424 m_errorMonitor->VerifyNotFound();
18425 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18426 m_errorMonitor->VerifyNotFound();
18427 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18428 m_errorMonitor->VerifyNotFound();
18429
18430 m_commandBuffer->EndCommandBuffer();
18431 m_errorMonitor->VerifyNotFound();
18432}
18433
18434TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18435 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18436 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18437 "has a valid layout, and a second subpass then uses a "
18438 "valid *READ_ONLY* layout.");
18439 m_errorMonitor->ExpectSuccess();
18440 ASSERT_NO_FATAL_FAILURE(InitState());
18441
18442 VkAttachmentReference attach[2] = {};
18443 attach[0].attachment = 0;
18444 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18445 attach[1].attachment = 0;
18446 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18447 VkSubpassDescription subpasses[2] = {};
18448 // First subpass clears DS attach on load
18449 subpasses[0].pDepthStencilAttachment = &attach[0];
18450 // 2nd subpass reads in DS as input attachment
18451 subpasses[1].inputAttachmentCount = 1;
18452 subpasses[1].pInputAttachments = &attach[1];
18453 VkAttachmentDescription attach_desc = {};
18454 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18455 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18456 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18457 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18458 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18459 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18460 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18461 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18462 VkRenderPassCreateInfo rpci = {};
18463 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18464 rpci.attachmentCount = 1;
18465 rpci.pAttachments = &attach_desc;
18466 rpci.subpassCount = 2;
18467 rpci.pSubpasses = subpasses;
18468
18469 // Now create RenderPass and verify no errors
18470 VkRenderPass rp;
18471 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18472 m_errorMonitor->VerifyNotFound();
18473
18474 vkDestroyRenderPass(m_device->device(), rp, NULL);
18475}
18476
18477TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18478 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18479 "as vertex attributes");
18480 m_errorMonitor->ExpectSuccess();
18481
18482 ASSERT_NO_FATAL_FAILURE(InitState());
18483 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18484
18485 VkVertexInputBindingDescription input_binding;
18486 memset(&input_binding, 0, sizeof(input_binding));
18487
18488 VkVertexInputAttributeDescription input_attribs[2];
18489 memset(input_attribs, 0, sizeof(input_attribs));
18490
18491 for (int i = 0; i < 2; i++) {
18492 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18493 input_attribs[i].location = i;
18494 }
18495
18496 char const *vsSource = "#version 450\n"
18497 "\n"
18498 "layout(location=0) in mat2x4 x;\n"
18499 "out gl_PerVertex {\n"
18500 " vec4 gl_Position;\n"
18501 "};\n"
18502 "void main(){\n"
18503 " gl_Position = x[0] + x[1];\n"
18504 "}\n";
18505 char const *fsSource = "#version 450\n"
18506 "\n"
18507 "layout(location=0) out vec4 color;\n"
18508 "void main(){\n"
18509 " color = vec4(1);\n"
18510 "}\n";
18511
18512 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18513 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18514
18515 VkPipelineObj pipe(m_device);
18516 pipe.AddColorAttachment();
18517 pipe.AddShader(&vs);
18518 pipe.AddShader(&fs);
18519
18520 pipe.AddVertexInputBindings(&input_binding, 1);
18521 pipe.AddVertexInputAttribs(input_attribs, 2);
18522
18523 VkDescriptorSetObj descriptorSet(m_device);
18524 descriptorSet.AppendDummy();
18525 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18526
18527 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18528
18529 /* expect success */
18530 m_errorMonitor->VerifyNotFound();
18531}
18532
18533TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18534 m_errorMonitor->ExpectSuccess();
18535
18536 ASSERT_NO_FATAL_FAILURE(InitState());
18537 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18538
18539 VkVertexInputBindingDescription input_binding;
18540 memset(&input_binding, 0, sizeof(input_binding));
18541
18542 VkVertexInputAttributeDescription input_attribs[2];
18543 memset(input_attribs, 0, sizeof(input_attribs));
18544
18545 for (int i = 0; i < 2; i++) {
18546 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18547 input_attribs[i].location = i;
18548 }
18549
18550 char const *vsSource = "#version 450\n"
18551 "\n"
18552 "layout(location=0) in vec4 x[2];\n"
18553 "out gl_PerVertex {\n"
18554 " vec4 gl_Position;\n"
18555 "};\n"
18556 "void main(){\n"
18557 " gl_Position = x[0] + x[1];\n"
18558 "}\n";
18559 char const *fsSource = "#version 450\n"
18560 "\n"
18561 "layout(location=0) out vec4 color;\n"
18562 "void main(){\n"
18563 " color = vec4(1);\n"
18564 "}\n";
18565
18566 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18567 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18568
18569 VkPipelineObj pipe(m_device);
18570 pipe.AddColorAttachment();
18571 pipe.AddShader(&vs);
18572 pipe.AddShader(&fs);
18573
18574 pipe.AddVertexInputBindings(&input_binding, 1);
18575 pipe.AddVertexInputAttribs(input_attribs, 2);
18576
18577 VkDescriptorSetObj descriptorSet(m_device);
18578 descriptorSet.AppendDummy();
18579 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18580
18581 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18582
18583 m_errorMonitor->VerifyNotFound();
18584}
18585
18586TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18587 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18588 "through multiple vertex shader inputs, each consuming a different "
18589 "subset of the components.");
18590 m_errorMonitor->ExpectSuccess();
18591
18592 ASSERT_NO_FATAL_FAILURE(InitState());
18593 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18594
18595 VkVertexInputBindingDescription input_binding;
18596 memset(&input_binding, 0, sizeof(input_binding));
18597
18598 VkVertexInputAttributeDescription input_attribs[3];
18599 memset(input_attribs, 0, sizeof(input_attribs));
18600
18601 for (int i = 0; i < 3; i++) {
18602 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18603 input_attribs[i].location = i;
18604 }
18605
18606 char const *vsSource = "#version 450\n"
18607 "\n"
18608 "layout(location=0) in vec4 x;\n"
18609 "layout(location=1) in vec3 y1;\n"
18610 "layout(location=1, component=3) in float y2;\n"
18611 "layout(location=2) in vec4 z;\n"
18612 "out gl_PerVertex {\n"
18613 " vec4 gl_Position;\n"
18614 "};\n"
18615 "void main(){\n"
18616 " gl_Position = x + vec4(y1, y2) + z;\n"
18617 "}\n";
18618 char const *fsSource = "#version 450\n"
18619 "\n"
18620 "layout(location=0) out vec4 color;\n"
18621 "void main(){\n"
18622 " color = vec4(1);\n"
18623 "}\n";
18624
18625 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18626 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18627
18628 VkPipelineObj pipe(m_device);
18629 pipe.AddColorAttachment();
18630 pipe.AddShader(&vs);
18631 pipe.AddShader(&fs);
18632
18633 pipe.AddVertexInputBindings(&input_binding, 1);
18634 pipe.AddVertexInputAttribs(input_attribs, 3);
18635
18636 VkDescriptorSetObj descriptorSet(m_device);
18637 descriptorSet.AppendDummy();
18638 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18639
18640 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18641
18642 m_errorMonitor->VerifyNotFound();
18643}
18644
18645TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
18646 m_errorMonitor->ExpectSuccess();
18647
18648 ASSERT_NO_FATAL_FAILURE(InitState());
18649 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18650
18651 char const *vsSource = "#version 450\n"
18652 "out gl_PerVertex {\n"
18653 " vec4 gl_Position;\n"
18654 "};\n"
18655 "void main(){\n"
18656 " gl_Position = vec4(0);\n"
18657 "}\n";
18658 char const *fsSource = "#version 450\n"
18659 "\n"
18660 "layout(location=0) out vec4 color;\n"
18661 "void main(){\n"
18662 " color = vec4(1);\n"
18663 "}\n";
18664
18665 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18666 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18667
18668 VkPipelineObj pipe(m_device);
18669 pipe.AddColorAttachment();
18670 pipe.AddShader(&vs);
18671 pipe.AddShader(&fs);
18672
18673 VkDescriptorSetObj descriptorSet(m_device);
18674 descriptorSet.AppendDummy();
18675 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18676
18677 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18678
18679 m_errorMonitor->VerifyNotFound();
18680}
18681
18682TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
18683 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
18684 "set out in 14.1.3: fundamental type must match, and producer side must "
18685 "have at least as many components");
18686 m_errorMonitor->ExpectSuccess();
18687
18688 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
18689
18690 ASSERT_NO_FATAL_FAILURE(InitState());
18691 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18692
18693 char const *vsSource = "#version 450\n"
18694 "out gl_PerVertex {\n"
18695 " vec4 gl_Position;\n"
18696 "};\n"
18697 "layout(location=0) out vec3 x;\n"
18698 "layout(location=1) out ivec3 y;\n"
18699 "layout(location=2) out vec3 z;\n"
18700 "void main(){\n"
18701 " gl_Position = vec4(0);\n"
18702 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
18703 "}\n";
18704 char const *fsSource = "#version 450\n"
18705 "\n"
18706 "layout(location=0) out vec4 color;\n"
18707 "layout(location=0) in float x;\n"
18708 "layout(location=1) flat in int y;\n"
18709 "layout(location=2) in vec2 z;\n"
18710 "void main(){\n"
18711 " color = vec4(1 + x + y + z.x);\n"
18712 "}\n";
18713
18714 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18715 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18716
18717 VkPipelineObj pipe(m_device);
18718 pipe.AddColorAttachment();
18719 pipe.AddShader(&vs);
18720 pipe.AddShader(&fs);
18721
18722 VkDescriptorSetObj descriptorSet(m_device);
18723 descriptorSet.AppendDummy();
18724 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18725
18726 VkResult err = VK_SUCCESS;
18727 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18728 ASSERT_VK_SUCCESS(err);
18729
18730 m_errorMonitor->VerifyNotFound();
18731}
18732
18733TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
18734 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
18735 "passed between the TCS and TES stages");
18736 m_errorMonitor->ExpectSuccess();
18737
18738 ASSERT_NO_FATAL_FAILURE(InitState());
18739 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18740
18741 if (!m_device->phy().features().tessellationShader) {
18742 printf("Device does not support tessellation shaders; skipped.\n");
18743 return;
18744 }
18745
18746 char const *vsSource = "#version 450\n"
18747 "void main(){}\n";
18748 char const *tcsSource = "#version 450\n"
18749 "layout(location=0) out int x[];\n"
18750 "layout(vertices=3) out;\n"
18751 "void main(){\n"
18752 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
18753 " gl_TessLevelInner[0] = 1;\n"
18754 " x[gl_InvocationID] = gl_InvocationID;\n"
18755 "}\n";
18756 char const *tesSource = "#version 450\n"
18757 "layout(triangles, equal_spacing, cw) in;\n"
18758 "layout(location=0) in int x[];\n"
18759 "out gl_PerVertex { vec4 gl_Position; };\n"
18760 "void main(){\n"
18761 " gl_Position.xyz = gl_TessCoord;\n"
18762 " gl_Position.w = x[0] + x[1] + x[2];\n"
18763 "}\n";
18764 char const *fsSource = "#version 450\n"
18765 "layout(location=0) out vec4 color;\n"
18766 "void main(){\n"
18767 " color = vec4(1);\n"
18768 "}\n";
18769
18770 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18771 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
18772 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
18773 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18774
18775 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
18776 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
18777
18778 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
18779
18780 VkPipelineObj pipe(m_device);
18781 pipe.SetInputAssembly(&iasci);
18782 pipe.SetTessellation(&tsci);
18783 pipe.AddColorAttachment();
18784 pipe.AddShader(&vs);
18785 pipe.AddShader(&tcs);
18786 pipe.AddShader(&tes);
18787 pipe.AddShader(&fs);
18788
18789 VkDescriptorSetObj descriptorSet(m_device);
18790 descriptorSet.AppendDummy();
18791 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18792
18793 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18794
18795 m_errorMonitor->VerifyNotFound();
18796}
18797
18798TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
18799 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
18800 "interface block passed into the geometry shader. This "
18801 "is interesting because the 'extra' array level is not "
18802 "present on the member type, but on the block instance.");
18803 m_errorMonitor->ExpectSuccess();
18804
18805 ASSERT_NO_FATAL_FAILURE(InitState());
18806 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18807
18808 if (!m_device->phy().features().geometryShader) {
18809 printf("Device does not support geometry shaders; skipped.\n");
18810 return;
18811 }
18812
18813 char const *vsSource = "#version 450\n"
18814 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
18815 "void main(){\n"
18816 " vs_out.x = vec4(1);\n"
18817 "}\n";
18818 char const *gsSource = "#version 450\n"
18819 "layout(triangles) in;\n"
18820 "layout(triangle_strip, max_vertices=3) out;\n"
18821 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
18822 "out gl_PerVertex { vec4 gl_Position; };\n"
18823 "void main() {\n"
18824 " gl_Position = gs_in[0].x;\n"
18825 " EmitVertex();\n"
18826 "}\n";
18827 char const *fsSource = "#version 450\n"
18828 "layout(location=0) out vec4 color;\n"
18829 "void main(){\n"
18830 " color = vec4(1);\n"
18831 "}\n";
18832
18833 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18834 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
18835 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18836
18837 VkPipelineObj pipe(m_device);
18838 pipe.AddColorAttachment();
18839 pipe.AddShader(&vs);
18840 pipe.AddShader(&gs);
18841 pipe.AddShader(&fs);
18842
18843 VkDescriptorSetObj descriptorSet(m_device);
18844 descriptorSet.AppendDummy();
18845 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18846
18847 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18848
18849 m_errorMonitor->VerifyNotFound();
18850}
18851
18852TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
18853 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
18854 "attributes. This is interesting because they consume multiple "
18855 "locations.");
18856 m_errorMonitor->ExpectSuccess();
18857
18858 ASSERT_NO_FATAL_FAILURE(InitState());
18859 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18860
18861 if (!m_device->phy().features().shaderFloat64) {
18862 printf("Device does not support 64bit vertex attributes; skipped.\n");
18863 return;
18864 }
18865
18866 VkVertexInputBindingDescription input_bindings[1];
18867 memset(input_bindings, 0, sizeof(input_bindings));
18868
18869 VkVertexInputAttributeDescription input_attribs[4];
18870 memset(input_attribs, 0, sizeof(input_attribs));
18871 input_attribs[0].location = 0;
18872 input_attribs[0].offset = 0;
18873 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18874 input_attribs[1].location = 2;
18875 input_attribs[1].offset = 32;
18876 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18877 input_attribs[2].location = 4;
18878 input_attribs[2].offset = 64;
18879 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18880 input_attribs[3].location = 6;
18881 input_attribs[3].offset = 96;
18882 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18883
18884 char const *vsSource = "#version 450\n"
18885 "\n"
18886 "layout(location=0) in dmat4 x;\n"
18887 "out gl_PerVertex {\n"
18888 " vec4 gl_Position;\n"
18889 "};\n"
18890 "void main(){\n"
18891 " gl_Position = vec4(x[0][0]);\n"
18892 "}\n";
18893 char const *fsSource = "#version 450\n"
18894 "\n"
18895 "layout(location=0) out vec4 color;\n"
18896 "void main(){\n"
18897 " color = vec4(1);\n"
18898 "}\n";
18899
18900 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18901 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18902
18903 VkPipelineObj pipe(m_device);
18904 pipe.AddColorAttachment();
18905 pipe.AddShader(&vs);
18906 pipe.AddShader(&fs);
18907
18908 pipe.AddVertexInputBindings(input_bindings, 1);
18909 pipe.AddVertexInputAttribs(input_attribs, 4);
18910
18911 VkDescriptorSetObj descriptorSet(m_device);
18912 descriptorSet.AppendDummy();
18913 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18914
18915 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18916
18917 m_errorMonitor->VerifyNotFound();
18918}
18919
18920TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
18921 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
18922 m_errorMonitor->ExpectSuccess();
18923
18924 ASSERT_NO_FATAL_FAILURE(InitState());
18925
18926 char const *vsSource = "#version 450\n"
18927 "\n"
18928 "out gl_PerVertex {\n"
18929 " vec4 gl_Position;\n"
18930 "};\n"
18931 "void main(){\n"
18932 " gl_Position = vec4(1);\n"
18933 "}\n";
18934 char const *fsSource = "#version 450\n"
18935 "\n"
18936 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
18937 "layout(location=0) out vec4 color;\n"
18938 "void main() {\n"
18939 " color = subpassLoad(x);\n"
18940 "}\n";
18941
18942 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18943 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18944
18945 VkPipelineObj pipe(m_device);
18946 pipe.AddShader(&vs);
18947 pipe.AddShader(&fs);
18948 pipe.AddColorAttachment();
18949 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18950
18951 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
18952 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
18953 VkDescriptorSetLayout dsl;
18954 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18955 ASSERT_VK_SUCCESS(err);
18956
18957 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18958 VkPipelineLayout pl;
18959 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18960 ASSERT_VK_SUCCESS(err);
18961
18962 VkAttachmentDescription descs[2] = {
18963 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18964 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18965 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
18966 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18967 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
18968 };
18969 VkAttachmentReference color = {
18970 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18971 };
18972 VkAttachmentReference input = {
18973 1, VK_IMAGE_LAYOUT_GENERAL,
18974 };
18975
18976 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
18977
18978 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
18979 VkRenderPass rp;
18980 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18981 ASSERT_VK_SUCCESS(err);
18982
18983 // should be OK. would go wrong here if it's going to...
18984 pipe.CreateVKPipeline(pl, rp);
18985
18986 m_errorMonitor->VerifyNotFound();
18987
18988 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18989 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18990 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18991}
18992
18993TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
18994 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
18995 "descriptor-backed resource which is not provided, but the shader does not "
18996 "statically use it. This is interesting because it requires compute pipelines "
18997 "to have a proper descriptor use walk, which they didn't for some time.");
18998 m_errorMonitor->ExpectSuccess();
18999
19000 ASSERT_NO_FATAL_FAILURE(InitState());
19001
19002 char const *csSource = "#version 450\n"
19003 "\n"
19004 "layout(local_size_x=1) in;\n"
19005 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19006 "void main(){\n"
19007 " // x is not used.\n"
19008 "}\n";
19009
19010 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19011
19012 VkDescriptorSetObj descriptorSet(m_device);
19013 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19014
19015 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19016 nullptr,
19017 0,
19018 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19019 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19020 descriptorSet.GetPipelineLayout(),
19021 VK_NULL_HANDLE,
19022 -1 };
19023
19024 VkPipeline pipe;
19025 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19026
19027 m_errorMonitor->VerifyNotFound();
19028
19029 if (err == VK_SUCCESS) {
19030 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19031 }
19032}
19033
19034TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19035 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19036 "sampler portion of a combined image + sampler");
19037 m_errorMonitor->ExpectSuccess();
19038
19039 ASSERT_NO_FATAL_FAILURE(InitState());
19040
19041 VkDescriptorSetLayoutBinding bindings[] = {
19042 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19043 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19044 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19045 };
19046 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19047 VkDescriptorSetLayout dsl;
19048 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19049 ASSERT_VK_SUCCESS(err);
19050
19051 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19052 VkPipelineLayout pl;
19053 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19054 ASSERT_VK_SUCCESS(err);
19055
19056 char const *csSource = "#version 450\n"
19057 "\n"
19058 "layout(local_size_x=1) in;\n"
19059 "layout(set=0, binding=0) uniform sampler s;\n"
19060 "layout(set=0, binding=1) uniform texture2D t;\n"
19061 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19062 "void main() {\n"
19063 " x = texture(sampler2D(t, s), vec2(0));\n"
19064 "}\n";
19065 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19066
19067 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19068 nullptr,
19069 0,
19070 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19071 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19072 pl,
19073 VK_NULL_HANDLE,
19074 -1 };
19075
19076 VkPipeline pipe;
19077 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19078
19079 m_errorMonitor->VerifyNotFound();
19080
19081 if (err == VK_SUCCESS) {
19082 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19083 }
19084
19085 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19086 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19087}
19088
19089TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19090 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19091 "image portion of a combined image + sampler");
19092 m_errorMonitor->ExpectSuccess();
19093
19094 ASSERT_NO_FATAL_FAILURE(InitState());
19095
19096 VkDescriptorSetLayoutBinding bindings[] = {
19097 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19098 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19099 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19100 };
19101 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19102 VkDescriptorSetLayout dsl;
19103 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19104 ASSERT_VK_SUCCESS(err);
19105
19106 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19107 VkPipelineLayout pl;
19108 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19109 ASSERT_VK_SUCCESS(err);
19110
19111 char const *csSource = "#version 450\n"
19112 "\n"
19113 "layout(local_size_x=1) in;\n"
19114 "layout(set=0, binding=0) uniform texture2D t;\n"
19115 "layout(set=0, binding=1) uniform sampler s;\n"
19116 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19117 "void main() {\n"
19118 " x = texture(sampler2D(t, s), vec2(0));\n"
19119 "}\n";
19120 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19121
19122 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19123 nullptr,
19124 0,
19125 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19126 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19127 pl,
19128 VK_NULL_HANDLE,
19129 -1 };
19130
19131 VkPipeline pipe;
19132 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19133
19134 m_errorMonitor->VerifyNotFound();
19135
19136 if (err == VK_SUCCESS) {
19137 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19138 }
19139
19140 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19141 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19142}
19143
19144TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19145 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19146 "both the sampler and the image of a combined image+sampler "
19147 "but via separate variables");
19148 m_errorMonitor->ExpectSuccess();
19149
19150 ASSERT_NO_FATAL_FAILURE(InitState());
19151
19152 VkDescriptorSetLayoutBinding bindings[] = {
19153 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19154 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19155 };
19156 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19157 VkDescriptorSetLayout dsl;
19158 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19159 ASSERT_VK_SUCCESS(err);
19160
19161 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19162 VkPipelineLayout pl;
19163 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19164 ASSERT_VK_SUCCESS(err);
19165
19166 char const *csSource = "#version 450\n"
19167 "\n"
19168 "layout(local_size_x=1) in;\n"
19169 "layout(set=0, binding=0) uniform texture2D t;\n"
19170 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19171 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19172 "void main() {\n"
19173 " x = texture(sampler2D(t, s), vec2(0));\n"
19174 "}\n";
19175 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19176
19177 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19178 nullptr,
19179 0,
19180 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19181 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19182 pl,
19183 VK_NULL_HANDLE,
19184 -1 };
19185
19186 VkPipeline pipe;
19187 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19188
19189 m_errorMonitor->VerifyNotFound();
19190
19191 if (err == VK_SUCCESS) {
19192 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19193 }
19194
19195 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19196 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19197}
19198
19199TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19200 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19201
19202 ASSERT_NO_FATAL_FAILURE(InitState());
19203
19204 // Positive test to check parameter_validation and unique_objects support
19205 // for NV_dedicated_allocation
19206 uint32_t extension_count = 0;
19207 bool supports_nv_dedicated_allocation = false;
19208 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19209 ASSERT_VK_SUCCESS(err);
19210
19211 if (extension_count > 0) {
19212 std::vector<VkExtensionProperties> available_extensions(extension_count);
19213
19214 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19215 ASSERT_VK_SUCCESS(err);
19216
19217 for (const auto &extension_props : available_extensions) {
19218 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19219 supports_nv_dedicated_allocation = true;
19220 }
19221 }
19222 }
19223
19224 if (supports_nv_dedicated_allocation) {
19225 m_errorMonitor->ExpectSuccess();
19226
19227 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19228 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19229 dedicated_buffer_create_info.pNext = nullptr;
19230 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19231
19232 uint32_t queue_family_index = 0;
19233 VkBufferCreateInfo buffer_create_info = {};
19234 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19235 buffer_create_info.pNext = &dedicated_buffer_create_info;
19236 buffer_create_info.size = 1024;
19237 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19238 buffer_create_info.queueFamilyIndexCount = 1;
19239 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19240
19241 VkBuffer buffer;
19242 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19243 ASSERT_VK_SUCCESS(err);
19244
19245 VkMemoryRequirements memory_reqs;
19246 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19247
19248 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19249 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19250 dedicated_memory_info.pNext = nullptr;
19251 dedicated_memory_info.buffer = buffer;
19252 dedicated_memory_info.image = VK_NULL_HANDLE;
19253
19254 VkMemoryAllocateInfo memory_info = {};
19255 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19256 memory_info.pNext = &dedicated_memory_info;
19257 memory_info.allocationSize = memory_reqs.size;
19258
19259 bool pass;
19260 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19261 ASSERT_TRUE(pass);
19262
19263 VkDeviceMemory buffer_memory;
19264 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19265 ASSERT_VK_SUCCESS(err);
19266
19267 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19268 ASSERT_VK_SUCCESS(err);
19269
19270 vkDestroyBuffer(m_device->device(), buffer, NULL);
19271 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19272
19273 m_errorMonitor->VerifyNotFound();
19274 }
19275}
19276
19277TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19278 VkResult err;
19279
19280 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19281
19282 ASSERT_NO_FATAL_FAILURE(InitState());
19283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19284
19285 std::vector<const char *> device_extension_names;
19286 auto features = m_device->phy().features();
19287 // Artificially disable support for non-solid fill modes
19288 features.fillModeNonSolid = false;
19289 // The sacrificial device object
19290 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19291
19292 VkRenderpassObj render_pass(&test_device);
19293
19294 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19295 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19296 pipeline_layout_ci.setLayoutCount = 0;
19297 pipeline_layout_ci.pSetLayouts = NULL;
19298
19299 VkPipelineLayout pipeline_layout;
19300 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19301 ASSERT_VK_SUCCESS(err);
19302
19303 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19304 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19305 rs_ci.pNext = nullptr;
19306 rs_ci.lineWidth = 1.0f;
19307 rs_ci.rasterizerDiscardEnable = true;
19308
19309 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19310 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19311
19312 // Set polygonMode=FILL. No error is expected
19313 m_errorMonitor->ExpectSuccess();
19314 {
19315 VkPipelineObj pipe(&test_device);
19316 pipe.AddShader(&vs);
19317 pipe.AddShader(&fs);
19318 pipe.AddColorAttachment();
19319 // Set polygonMode to a good value
19320 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19321 pipe.SetRasterization(&rs_ci);
19322 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19323 }
19324 m_errorMonitor->VerifyNotFound();
19325
19326 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19327}
19328
19329TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19330 VkResult err;
19331 ASSERT_NO_FATAL_FAILURE(InitState());
19332 ASSERT_NO_FATAL_FAILURE(InitViewport());
19333 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19334
19335 VkPipelineLayout pipeline_layout;
19336 VkPushConstantRange pc_range = {};
19337 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19338 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19339 pipeline_layout_ci.pushConstantRangeCount = 1;
19340 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19341
19342 //
19343 // Check for invalid push constant ranges in pipeline layouts.
19344 //
19345 struct PipelineLayoutTestCase {
19346 VkPushConstantRange const range;
19347 char const *msg;
19348 };
19349
19350 // Check for overlapping ranges
19351 const uint32_t ranges_per_test = 5;
19352 struct OverlappingRangeTestCase {
19353 VkPushConstantRange const ranges[ranges_per_test];
19354 char const *msg;
19355 };
19356
19357 // Run some positive tests to make sure overlap checking in the layer is OK
19358 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19359 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19360 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19361 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19362 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19363 "" },
19364 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19365 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19366 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19367 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19368 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19369 "" } } };
19370 for (const auto &iter : overlapping_range_tests_pos) {
19371 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19372 m_errorMonitor->ExpectSuccess();
19373 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19374 m_errorMonitor->VerifyNotFound();
19375 if (VK_SUCCESS == err) {
19376 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19377 }
19378 }
19379
19380 //
19381 // CmdPushConstants tests
19382 //
19383 const uint8_t dummy_values[100] = {};
19384
19385 BeginCommandBuffer();
19386
19387 // positive overlapping range tests with cmd
19388 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19389 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19390 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19391 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19392 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19393 } };
19394
19395 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19396 const VkPushConstantRange pc_range4[] = {
19397 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19398 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19399 };
19400
19401 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19402 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19403 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19404 ASSERT_VK_SUCCESS(err);
19405 for (const auto &iter : cmd_overlap_tests_pos) {
19406 m_errorMonitor->ExpectSuccess();
19407 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19408 iter.range.size, dummy_values);
19409 m_errorMonitor->VerifyNotFound();
19410 }
19411 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19412
19413 EndCommandBuffer();
19414}
19415
19416
19417
19418
19419
19420
19421
19422#if 0 // A few devices have issues with this test so disabling for now
19423TEST_F(VkPositiveLayerTest, LongFenceChain)
19424{
19425 m_errorMonitor->ExpectSuccess();
19426
19427 ASSERT_NO_FATAL_FAILURE(InitState());
19428 VkResult err;
19429
19430 std::vector<VkFence> fences;
19431
19432 const int chainLength = 32768;
19433
19434 for (int i = 0; i < chainLength; i++) {
19435 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19436 VkFence fence;
19437 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19438 ASSERT_VK_SUCCESS(err);
19439
19440 fences.push_back(fence);
19441
19442 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19443 0, nullptr, 0, nullptr };
19444 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19445 ASSERT_VK_SUCCESS(err);
19446
19447 }
19448
19449 // BOOM, stack overflow.
19450 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19451
19452 for (auto fence : fences)
19453 vkDestroyFence(m_device->device(), fence, nullptr);
19454
19455 m_errorMonitor->VerifyNotFound();
19456}
19457#endif
19458
19459
Cody Northrop1242dfd2016-07-13 17:24:59 -060019460#if defined(ANDROID) && defined(VALIDATION_APK)
19461static bool initialized = false;
19462static bool active = false;
19463
19464// Convert Intents to argv
19465// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019466std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019467 std::vector<std::string> args;
19468 JavaVM &vm = *app.activity->vm;
19469 JNIEnv *p_env;
19470 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19471 return args;
19472
19473 JNIEnv &env = *p_env;
19474 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019475 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019476 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019477 jmethodID get_string_extra_method =
19478 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019479 jvalue get_string_extra_args;
19480 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019481 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019482
19483 std::string args_str;
19484 if (extra_str) {
19485 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19486 args_str = extra_utf;
19487 env.ReleaseStringUTFChars(extra_str, extra_utf);
19488 env.DeleteLocalRef(extra_str);
19489 }
19490
19491 env.DeleteLocalRef(get_string_extra_args.l);
19492 env.DeleteLocalRef(intent);
19493 vm.DetachCurrentThread();
19494
19495 // split args_str
19496 std::stringstream ss(args_str);
19497 std::string arg;
19498 while (std::getline(ss, arg, ' ')) {
19499 if (!arg.empty())
19500 args.push_back(arg);
19501 }
19502
19503 return args;
19504}
19505
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019506static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019507
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019508static void processCommand(struct android_app *app, int32_t cmd) {
19509 switch (cmd) {
19510 case APP_CMD_INIT_WINDOW: {
19511 if (app->window) {
19512 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019513 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019514 break;
19515 }
19516 case APP_CMD_GAINED_FOCUS: {
19517 active = true;
19518 break;
19519 }
19520 case APP_CMD_LOST_FOCUS: {
19521 active = false;
19522 break;
19523 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019524 }
19525}
19526
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019527void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019528 app_dummy();
19529
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019530 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019531
19532 int vulkanSupport = InitVulkan();
19533 if (vulkanSupport == 0) {
19534 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19535 return;
19536 }
19537
19538 app->onAppCmd = processCommand;
19539 app->onInputEvent = processInput;
19540
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019541 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019542 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019543 struct android_poll_source *source;
19544 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019545 if (source) {
19546 source->process(app, source);
19547 }
19548
19549 if (app->destroyRequested != 0) {
19550 VkTestFramework::Finish();
19551 return;
19552 }
19553 }
19554
19555 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019556 // Use the following key to send arguments to gtest, i.e.
19557 // --es args "--gtest_filter=-VkLayerTest.foo"
19558 const char key[] = "args";
19559 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019560
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019561 std::string filter = "";
19562 if (args.size() > 0) {
19563 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19564 filter += args[0];
19565 } else {
19566 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19567 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019568
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019569 int argc = 2;
19570 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19571 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019572
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019573 // Route output to files until we can override the gtest output
19574 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19575 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019576
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019577 ::testing::InitGoogleTest(&argc, argv);
19578 VkTestFramework::InitArgs(&argc, argv);
19579 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019580
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019581 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019582
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019583 if (result != 0) {
19584 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19585 } else {
19586 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19587 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019588
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019589 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019590
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019591 fclose(stdout);
19592 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019593
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019594 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019595
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019596 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019597 }
19598 }
19599}
19600#endif
19601
Tony Barbour300a6082015-04-07 13:44:53 -060019602int main(int argc, char **argv) {
19603 int result;
19604
Cody Northrop8e54a402016-03-08 22:25:52 -070019605#ifdef ANDROID
19606 int vulkanSupport = InitVulkan();
19607 if (vulkanSupport == 0)
19608 return 1;
19609#endif
19610
Tony Barbour300a6082015-04-07 13:44:53 -060019611 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060019612 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060019613
19614 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
19615
19616 result = RUN_ALL_TESTS();
19617
Tony Barbour6918cd52015-04-09 12:58:51 -060019618 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060019619 return result;
19620}