blob: 3a9b0732ab9f6a17aa191e456f8baa4c11cd128f [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060037#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060038#include "vkrenderframework.h"
39#include <limits.h>
40#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060041
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042#define GLM_FORCE_RADIANS
43#include "glm/glm.hpp"
44#include <glm/gtc/matrix_transform.hpp>
45
Dustin Gravesffa90fa2016-05-06 11:20:38 -060046#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060047#define MEM_TRACKER_TESTS 1
48#define OBJ_TRACKER_TESTS 1
49#define DRAW_STATE_TESTS 1
50#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120051#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060052#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060053#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060054
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055//--------------------------------------------------------------------------------------
56// Mesh and VertexFormat Data
57//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070058struct Vertex {
59 float posX, posY, posZ, posW; // Position data
60 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061};
62
Karl Schultz6addd812016-02-02 17:17:23 -070063#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050064
65typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070066 BsoFailNone = 0x00000000,
67 BsoFailLineWidth = 0x00000001,
68 BsoFailDepthBias = 0x00000002,
69 BsoFailViewport = 0x00000004,
70 BsoFailScissor = 0x00000008,
71 BsoFailBlend = 0x00000010,
72 BsoFailDepthBounds = 0x00000020,
73 BsoFailStencilReadMask = 0x00000040,
74 BsoFailStencilWriteMask = 0x00000080,
75 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060076 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060077 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050085};
86
Mark Lobodzinskice751c62016-09-08 10:45:35 -060087static const char bindStateVertShaderText[] = "#version 450\n"
88 "vec2 vertices[3];\n"
89 "out gl_PerVertex {\n"
90 " vec4 gl_Position;\n"
91 "};\n"
92 "void main() {\n"
93 " vertices[0] = vec2(-1.0, -1.0);\n"
94 " vertices[1] = vec2( 1.0, -1.0);\n"
95 " vertices[2] = vec2( 0.0, 1.0);\n"
96 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
97 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060099static const char bindStateFragShaderText[] = "#version 450\n"
100 "\n"
101 "layout(location = 0) out vec4 uFragColor;\n"
102 "void main(){\n"
103 " uFragColor = vec4(0,1,0,1);\n"
104 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500105
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600106static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
107 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
108 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600109
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600110// ErrorMonitor Usage:
111//
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600112// Call SetDesiredFailureMsg with: a string to be compared against all
113// encountered log messages, or a validation error enum identifying
114// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
115// will match all log messages. logMsg will return true for skipCall
116// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117//
118// Call DesiredMsgFound to determine if the desired failure message
119// was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600120class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700121 public:
122 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600123 test_platform_thread_create_mutex(&m_mutex);
124 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200125 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700126 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600127 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600128 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129
Dustin Graves48458142016-04-29 16:11:55 -0600130 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
131
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600132 // ErrorMonitor will look for an error message containing the specified string
Karl Schultz6addd812016-02-02 17:17:23 -0700133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600134 // Also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600136 m_failure_message_strings.clear();
137 // If we are looking for a matching string, ignore any IDs
138 m_desired_message_ids.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600139 m_otherMsgs.clear();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600140 m_desired_message_strings.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700141 m_msgFound = VK_FALSE;
142 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600143 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600144 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600145
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600146 // ErrorMonitor will look for a message ID matching the specified one
147 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
148 // Also discard all collected messages to this point
149 test_platform_thread_lock_mutex(&m_mutex);
150 m_failure_message_strings.clear();
151 // If we are looking for IDs don't look for strings
152 m_desired_message_strings.clear();
153 m_otherMsgs.clear();
154 m_desired_message_ids.insert(msg_id);
155 m_msgFound = VK_FALSE;
156 m_msgFlags = msgFlags;
157 test_platform_thread_unlock_mutex(&m_mutex);
158 }
159
160 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600162 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600163 if (m_bailout != NULL) {
164 *m_bailout = true;
165 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600167 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600168
169 for (auto desired_msg : m_desired_message_strings) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600170 if (desired_msg.length() == 0) {
171 // An empty desired_msg string "" indicates a positive test - not expecting an error.
172 // Return true to avoid calling layers/driver with this error.
173 // And don't erase the "" string, so it remains if another error is found.
174 result = VK_TRUE;
175 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600176 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600177 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600178 m_msgFound = VK_TRUE;
179 result = VK_TRUE;
180 // We only want one match for each expected error so remove from set here
181 // Since we're about the break the loop it's ok to remove from set we're iterating over
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600182 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600183 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186 for (auto desired_id : m_desired_message_ids) {
187 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
188 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
189 // Return true to avoid calling layers/driver with this error.
190 result = VK_TRUE;
191 } else if (desired_id == message_code) {
192 // Double-check that the string matches the error enum
193 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
194 found_expected = true;
195 result = VK_TRUE;
196 m_msgFound = VK_TRUE;
197 m_desired_message_ids.erase(desired_id);
198 break;
199 } else {
200 // Treat this message as a regular unexpected error, but print a warning jic
201 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
202 errorString.c_str(), desired_id, validation_error_map[desired_id]);
203 }
204 }
205 }
206
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600207 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200208 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600209 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600210 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600211 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600212 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600213 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600214
Karl Schultz6addd812016-02-02 17:17:23 -0700215 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600216
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600217 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
218
Karl Schultz6addd812016-02-02 17:17:23 -0700219 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600220
Karl Schultz6addd812016-02-02 17:17:23 -0700221 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600222
Karl Schultz6addd812016-02-02 17:17:23 -0700223 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600224 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600225 if (otherMsgs.size()) {
226 cout << "Other error messages logged for this test were:" << endl;
227 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
228 cout << " " << *iter << endl;
229 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600230 }
231 }
232
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600233 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200234
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600235 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
236 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
237 m_msgFlags = message_flag_mask;
238 // Match ANY message matching specified type
239 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200240 }
241
242 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600243 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200244 if (!DesiredMsgFound()) {
245 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600246 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600247 FAIL() << "Did not receive expected error '" << desired_msg << "'";
248 }
Tony Barbour59b42282016-11-03 13:31:28 -0600249 for (auto desired_id : m_desired_message_ids) {
250 FAIL() << "Did not receive expected error '" << desired_id << "'";
251 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200252 }
253 }
254
255 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600256 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200257 if (DesiredMsgFound()) {
258 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600259 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600260 FAIL() << "Expected to succeed but got error: " << msg;
261 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262 }
263 }
264
Karl Schultz6addd812016-02-02 17:17:23 -0700265 private:
266 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600267 std::unordered_set<uint32_t>m_desired_message_ids;
268 std::unordered_set<string> m_desired_message_strings;
269 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700270 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600271 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700272 bool *m_bailout;
273 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600274};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500275
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600276static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
277 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
278 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600279 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
280 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600281 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600282 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600283 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600284}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500285
Karl Schultz6addd812016-02-02 17:17:23 -0700286class VkLayerTest : public VkRenderFramework {
287 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800288 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
289 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600290 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
291 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700292 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
294 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700295 }
Tony Barbour300a6082015-04-07 13:44:53 -0600296
Tony Barbourfe3351b2015-07-28 10:17:20 -0600297 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600298 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800299 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600300 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
301 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700302 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700304 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600305 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700306 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600307 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
308 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
309 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700310 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
311 }
312 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
313 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
314 }
315
316 protected:
317 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600318 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600319
320 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600321 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600322 std::vector<const char *> instance_extension_names;
323 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600324
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700325 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600326 /*
327 * Since CreateDbgMsgCallback is an instance level extension call
328 * any extension / layer that utilizes that feature also needs
329 * to be enabled at create instance time.
330 */
Karl Schultz6addd812016-02-02 17:17:23 -0700331 // Use Threading layer first to protect others from
332 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700333 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600334 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800335 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700336 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800337 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600338 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700339 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600340
Ian Elliott2c1daf52016-05-12 09:41:46 -0600341 if (m_enableWSI) {
342 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
343 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
344#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
345#if defined(VK_USE_PLATFORM_ANDROID_KHR)
346 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
347#endif // VK_USE_PLATFORM_ANDROID_KHR
348#if defined(VK_USE_PLATFORM_MIR_KHR)
349 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_MIR_KHR
351#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
352 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
353#endif // VK_USE_PLATFORM_WAYLAND_KHR
354#if defined(VK_USE_PLATFORM_WIN32_KHR)
355 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_WIN32_KHR
357#endif // NEED_TO_TEST_THIS_ON_PLATFORM
358#if defined(VK_USE_PLATFORM_XCB_KHR)
359 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
360#elif defined(VK_USE_PLATFORM_XLIB_KHR)
361 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
362#endif // VK_USE_PLATFORM_XLIB_KHR
363 }
364
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600365 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600366 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800367 this->app_info.pApplicationName = "layer_tests";
368 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600369 this->app_info.pEngineName = "unittest";
370 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600371 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600372
Tony Barbour15524c32015-04-29 17:34:29 -0600373 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600374 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600375 }
376
377 virtual void TearDown() {
378 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600379 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600380 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600381 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600382
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600383 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600384};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500385
Karl Schultz6addd812016-02-02 17:17:23 -0700386VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600387 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600388
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800389 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600390
391 /*
392 * For render test all drawing happens in a single render pass
393 * on a single command buffer.
394 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200395 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800396 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600397 }
398
399 return result;
400}
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600403 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600404
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200405 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800406 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200407 }
Tony Barbour300a6082015-04-07 13:44:53 -0600408
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600410
411 return result;
412}
413
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600414void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500415 // Create identity matrix
416 int i;
417 struct vktriangle_vs_uniform data;
418
419 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700420 glm::mat4 View = glm::mat4(1.0f);
421 glm::mat4 Model = glm::mat4(1.0f);
422 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700424 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425
426 memcpy(&data.mvp, &MVP[0][0], matrixSize);
427
Karl Schultz6addd812016-02-02 17:17:23 -0700428 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600429 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500430 };
431
Karl Schultz6addd812016-02-02 17:17:23 -0700432 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 data.position[i][0] = tri_data[i].posX;
434 data.position[i][1] = tri_data[i].posY;
435 data.position[i][2] = tri_data[i].posZ;
436 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700437 data.color[i][0] = tri_data[i].r;
438 data.color[i][1] = tri_data[i].g;
439 data.color[i][2] = tri_data[i].b;
440 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500441 }
442
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 ASSERT_NO_FATAL_FAILURE(InitViewport());
444
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200445 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
446 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Karl Schultz6addd812016-02-02 17:17:23 -0700448 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600449 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
451 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800452 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 pipelineobj.AddShader(&vs);
454 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 if (failMask & BsoFailLineWidth) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600457 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600458 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600459 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
460 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600461 }
462 if (failMask & BsoFailDepthBias) {
463 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600464 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600465 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600466 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600467 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600468 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600469 }
Karl Schultz6addd812016-02-02 17:17:23 -0700470 // Viewport and scissors must stay in synch or other errors will occur than
471 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 if (failMask & BsoFailViewport) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
474 }
475 if (failMask & BsoFailScissor) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
477 }
478 if (failMask & BsoFailBlend) {
479 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600480 VkPipelineColorBlendAttachmentState att_state = {};
481 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
482 att_state.blendEnable = VK_TRUE;
483 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600484 }
485 if (failMask & BsoFailDepthBounds) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
487 }
488 if (failMask & BsoFailStencilReadMask) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
490 }
491 if (failMask & BsoFailStencilWriteMask) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
493 }
494 if (failMask & BsoFailStencilReference) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
496 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500497
498 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600499 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600502 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
Tony Barbourfe3351b2015-07-28 10:17:20 -0600504 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500505
506 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600507 if (failMask & BsoFailIndexBuffer) {
508 // Use DrawIndexed w/o an index buffer bound
509 DrawIndexed(3, 1, 0, 0, 0);
510 } else {
511 Draw(3, 1, 0, 0);
512 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500513
Mark Muellerd4914412016-06-13 17:52:06 -0600514 if (failMask & BsoFailCmdClearAttachments) {
515 VkClearAttachment color_attachment = {};
516 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
517 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
518 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
519
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600520 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600521 }
522
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500523 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600524 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500525
Tony Barbourfe3351b2015-07-28 10:17:20 -0600526 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500527}
528
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600529void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
530 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500531 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500533 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600534 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500535 }
536
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800537 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700538 // Make sure depthWriteEnable is set so that Depth fail test will work
539 // correctly
540 // Make sure stencilTestEnable is set so that Stencil fail test will work
541 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600542 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800543 stencil.failOp = VK_STENCIL_OP_KEEP;
544 stencil.passOp = VK_STENCIL_OP_KEEP;
545 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
546 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600547
548 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
549 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600550 ds_ci.pNext = NULL;
551 ds_ci.depthTestEnable = VK_FALSE;
552 ds_ci.depthWriteEnable = VK_TRUE;
553 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
554 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600555 if (failMask & BsoFailDepthBounds) {
556 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600557 ds_ci.maxDepthBounds = 0.0f;
558 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600559 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600560 ds_ci.stencilTestEnable = VK_TRUE;
561 ds_ci.front = stencil;
562 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600563
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600564 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600565 pipelineobj.SetViewport(m_viewports);
566 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800567 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600568 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600569 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800570 commandBuffer->BindPipeline(pipelineobj);
571 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500572}
573
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600574class VkPositiveLayerTest : public VkLayerTest {
575 public:
576 protected:
577};
578
Ian Elliott2c1daf52016-05-12 09:41:46 -0600579class VkWsiEnabledLayerTest : public VkLayerTest {
580 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 protected:
582 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600583};
584
Mark Muellerdfe37552016-07-07 14:47:42 -0600585class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600586 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600587 enum eTestEnFlags {
588 eDoubleDelete,
589 eInvalidDeviceOffset,
590 eInvalidMemoryOffset,
591 eBindNullBuffer,
592 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600593 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600594 };
595
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600596 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600597
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
599 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600600 return true;
601 }
602 VkDeviceSize offset_limit = 0;
603 if (eInvalidMemoryOffset == aTestFlag) {
604 VkBuffer vulkanBuffer;
605 VkBufferCreateInfo buffer_create_info = {};
606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
607 buffer_create_info.size = 32;
608 buffer_create_info.usage = aBufferUsage;
609
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600610 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600611 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600614 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
615 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
617 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600618 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600620 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600622 }
623 if (eOffsetAlignment < offset_limit) {
624 return true;
625 }
626 return false;
627 }
628
629 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
631 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
633 if (eBindNullBuffer == aTestFlag) {
634 VulkanMemory = 0;
635 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
636 } else {
637 VkBufferCreateInfo buffer_create_info = {};
638 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
639 buffer_create_info.size = 32;
640 buffer_create_info.usage = aBufferUsage;
641
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600643
644 CreateCurrent = true;
645
646 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600647 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600648
649 VkMemoryAllocateInfo memory_allocate_info = {};
650 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
651 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
653 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600654 if (!pass) {
655 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
656 return;
657 }
658
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600659 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600660 AllocateCurrent = true;
661 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
663 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 BoundCurrent = true;
665
666 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
667 }
668 }
669
670 ~VkBufferTest() {
671 if (CreateCurrent) {
672 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
673 }
674 if (AllocateCurrent) {
675 if (InvalidDeleteEn) {
676 union {
677 VkDeviceMemory device_memory;
678 unsigned long long index_access;
679 } bad_index;
680
681 bad_index.device_memory = VulkanMemory;
682 bad_index.index_access++;
683
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600684 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600685 }
686 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
687 }
688 }
689
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600690 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600691
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600692 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600693
694 void TestDoubleDestroy() {
695 // Destroy the buffer but leave the flag set, which will cause
696 // the buffer to be destroyed again in the destructor.
697 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600701 bool AllocateCurrent;
702 bool BoundCurrent;
703 bool CreateCurrent;
704 bool InvalidDeleteEn;
705
706 VkBuffer VulkanBuffer;
707 VkDevice VulkanDevice;
708 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600709};
710
711class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600712 public:
713 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600714 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600716 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600717 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
718 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 BindIdGenerator++; // NB: This can wrap w/misuse
720
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600721 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
722 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
725 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
726 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
727 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
728 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600729
730 unsigned i = 0;
731 do {
732 VertexInputAttributeDescription[i].binding = BindId;
733 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
735 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600736 i++;
737 } while (AttributeCount < i);
738
739 i = 0;
740 do {
741 VertexInputBindingDescription[i].binding = BindId;
742 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600743 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600744 i++;
745 } while (BindingCount < i);
746 }
747
748 ~VkVerticesObj() {
749 if (VertexInputAttributeDescription) {
750 delete[] VertexInputAttributeDescription;
751 }
752 if (VertexInputBindingDescription) {
753 delete[] VertexInputBindingDescription;
754 }
755 }
756
757 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
759 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600760 return true;
761 }
762
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600763 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600764 VkDeviceSize *offsetList;
765 unsigned offsetCount;
766
767 if (aOffsetCount) {
768 offsetList = aOffsetList;
769 offsetCount = aOffsetCount;
770 } else {
771 offsetList = new VkDeviceSize[1]();
772 offsetCount = 1;
773 }
774
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600775 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600776 BoundCurrent = true;
777
778 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600779 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600780 }
781 }
782
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600783 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600784 static uint32_t BindIdGenerator;
785
786 bool BoundCurrent;
787 unsigned AttributeCount;
788 unsigned BindingCount;
789 uint32_t BindId;
790
791 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
792 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
793 VkVertexInputBindingDescription *VertexInputBindingDescription;
794 VkConstantBufferObj VulkanMemoryBuffer;
795};
796
797uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500798// ********************************************************************************************************************
799// ********************************************************************************************************************
800// ********************************************************************************************************************
801// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600802#if PARAMETER_VALIDATION_TESTS
803TEST_F(VkLayerTest, RequiredParameter) {
804 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
805 "pointer, array, and array count parameters");
806
807 ASSERT_NO_FATAL_FAILURE(InitState());
808
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600810 // Specify NULL for a pointer to a handle
811 // Expected to trigger an error with
812 // parameter_validation::validate_required_pointer
813 vkGetPhysicalDeviceFeatures(gpu(), NULL);
814 m_errorMonitor->VerifyFound();
815
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
817 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600818 // Specify NULL for pointer to array count
819 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600820 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600821 m_errorMonitor->VerifyFound();
822
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 // Specify 0 for a required array count
825 // Expected to trigger an error with parameter_validation::validate_array
826 VkViewport view_port = {};
827 m_commandBuffer->SetViewport(0, 0, &view_port);
828 m_errorMonitor->VerifyFound();
829
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for a required array
832 // Expected to trigger an error with parameter_validation::validate_array
833 m_commandBuffer->SetViewport(0, 1, NULL);
834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify VK_NULL_HANDLE for a required handle
838 // Expected to trigger an error with
839 // parameter_validation::validate_required_handle
840 vkUnmapMemory(device(), VK_NULL_HANDLE);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
844 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600845 // Specify VK_NULL_HANDLE for a required handle array entry
846 // Expected to trigger an error with
847 // parameter_validation::validate_required_handle_array
848 VkFence fence = VK_NULL_HANDLE;
849 vkResetFences(device(), 1, &fence);
850 m_errorMonitor->VerifyFound();
851
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600853 // Specify NULL for a required struct pointer
854 // Expected to trigger an error with
855 // parameter_validation::validate_struct_type
856 VkDeviceMemory memory = VK_NULL_HANDLE;
857 vkAllocateMemory(device(), NULL, NULL, &memory);
858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600861 // Specify 0 for a required VkFlags parameter
862 // Expected to trigger an error with parameter_validation::validate_flags
863 m_commandBuffer->SetStencilReference(0, 0);
864 m_errorMonitor->VerifyFound();
865
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600867 // Specify 0 for a required VkFlags array entry
868 // Expected to trigger an error with
869 // parameter_validation::validate_flags_array
870 VkSemaphore semaphore = VK_NULL_HANDLE;
871 VkPipelineStageFlags stageFlags = 0;
872 VkSubmitInfo submitInfo = {};
873 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
874 submitInfo.waitSemaphoreCount = 1;
875 submitInfo.pWaitSemaphores = &semaphore;
876 submitInfo.pWaitDstStageMask = &stageFlags;
877 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
878 m_errorMonitor->VerifyFound();
879}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600880
Dustin Gravesfce74c02016-05-10 11:42:58 -0600881TEST_F(VkLayerTest, ReservedParameter) {
882 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
883
884 ASSERT_NO_FATAL_FAILURE(InitState());
885
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600887 // Specify 0 for a reserved VkFlags parameter
888 // Expected to trigger an error with
889 // parameter_validation::validate_reserved_flags
890 VkEvent event_handle = VK_NULL_HANDLE;
891 VkEventCreateInfo event_info = {};
892 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
893 event_info.flags = 1;
894 vkCreateEvent(device(), &event_info, NULL, &event_handle);
895 m_errorMonitor->VerifyFound();
896}
897
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600898TEST_F(VkLayerTest, InvalidStructSType) {
899 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
900 "structure's sType field");
901
902 ASSERT_NO_FATAL_FAILURE(InitState());
903
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600905 // Zero struct memory, effectively setting sType to
906 // VK_STRUCTURE_TYPE_APPLICATION_INFO
907 // Expected to trigger an error with
908 // parameter_validation::validate_struct_type
909 VkMemoryAllocateInfo alloc_info = {};
910 VkDeviceMemory memory = VK_NULL_HANDLE;
911 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
912 m_errorMonitor->VerifyFound();
913
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915 // Zero struct memory, effectively setting sType to
916 // VK_STRUCTURE_TYPE_APPLICATION_INFO
917 // Expected to trigger an error with
918 // parameter_validation::validate_struct_type_array
919 VkSubmitInfo submit_info = {};
920 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
921 m_errorMonitor->VerifyFound();
922}
923
924TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600925 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600926
927 ASSERT_NO_FATAL_FAILURE(InitState());
928
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600930 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600931 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600932 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600933 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600934 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600935 // Zero-initialization will provide the correct sType
936 VkApplicationInfo app_info = {};
937 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
938 event_alloc_info.pNext = &app_info;
939 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
940 m_errorMonitor->VerifyFound();
941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
943 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
945 // a function that has allowed pNext structure types and specify
946 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600947 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600948 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600949 VkMemoryAllocateInfo memory_alloc_info = {};
950 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
951 memory_alloc_info.pNext = &app_info;
952 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600953 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600954}
Dustin Graves5d33d532016-05-09 16:21:12 -0600955
956TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600957 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600958
959 ASSERT_NO_FATAL_FAILURE(InitState());
960
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
962 "range of the core VkFormat "
963 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600964 // Specify an invalid VkFormat value
965 // Expected to trigger an error with
966 // parameter_validation::validate_ranged_enum
967 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600968 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600969 m_errorMonitor->VerifyFound();
970
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 // Specify an invalid VkFlags bitmask value
973 // Expected to trigger an error with parameter_validation::validate_flags
974 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600975 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
976 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600977 m_errorMonitor->VerifyFound();
978
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 // Specify an invalid VkFlags array entry
981 // Expected to trigger an error with
982 // parameter_validation::validate_flags_array
983 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600984 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600985 VkSubmitInfo submit_info = {};
986 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
987 submit_info.waitSemaphoreCount = 1;
988 submit_info.pWaitSemaphores = &semaphore;
989 submit_info.pWaitDstStageMask = &stage_flags;
990 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
991 m_errorMonitor->VerifyFound();
992
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 // Specify an invalid VkBool32 value
995 // Expected to trigger a warning with
996 // parameter_validation::validate_bool32
997 VkSampler sampler = VK_NULL_HANDLE;
998 VkSamplerCreateInfo sampler_info = {};
999 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1000 sampler_info.pNext = NULL;
1001 sampler_info.magFilter = VK_FILTER_NEAREST;
1002 sampler_info.minFilter = VK_FILTER_NEAREST;
1003 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1004 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1005 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1006 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1007 sampler_info.mipLodBias = 1.0;
1008 sampler_info.maxAnisotropy = 1;
1009 sampler_info.compareEnable = VK_FALSE;
1010 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1011 sampler_info.minLod = 1.0;
1012 sampler_info.maxLod = 1.0;
1013 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1014 sampler_info.unnormalizedCoordinates = VK_FALSE;
1015 // Not VK_TRUE or VK_FALSE
1016 sampler_info.anisotropyEnable = 3;
1017 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1018 m_errorMonitor->VerifyFound();
1019}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001020
1021TEST_F(VkLayerTest, FailedReturnValue) {
1022 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1023
1024 ASSERT_NO_FATAL_FAILURE(InitState());
1025
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001026 // Find an unsupported image format
1027 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1028 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1029 VkFormat format = static_cast<VkFormat>(f);
1030 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001031 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001032 unsupported = format;
1033 break;
1034 }
1035 }
1036
1037 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1039 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001040 // Specify an unsupported VkFormat value to generate a
1041 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1042 // Expected to trigger a warning from
1043 // parameter_validation::validate_result
1044 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001045 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1046 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1048 m_errorMonitor->VerifyFound();
1049 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001050}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001051
1052TEST_F(VkLayerTest, UpdateBufferAlignment) {
1053 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001054 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001055
1056 ASSERT_NO_FATAL_FAILURE(InitState());
1057
1058 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1059 vk_testing::Buffer buffer;
1060 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1061
1062 BeginCommandBuffer();
1063 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1066 m_errorMonitor->VerifyFound();
1067
1068 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1071 m_errorMonitor->VerifyFound();
1072
1073 // Introduce failure by using dataSize that is < 0
1074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001075 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1077 m_errorMonitor->VerifyFound();
1078
1079 // Introduce failure by using dataSize that is > 65536
1080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001081 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001082 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1083 m_errorMonitor->VerifyFound();
1084
1085 EndCommandBuffer();
1086}
1087
1088TEST_F(VkLayerTest, FillBufferAlignment) {
1089 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1090
1091 ASSERT_NO_FATAL_FAILURE(InitState());
1092
1093 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1094 vk_testing::Buffer buffer;
1095 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1096
1097 BeginCommandBuffer();
1098
1099 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1102 m_errorMonitor->VerifyFound();
1103
1104 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001106 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1107 m_errorMonitor->VerifyFound();
1108
1109 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001111 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1112 m_errorMonitor->VerifyFound();
1113
1114 EndCommandBuffer();
1115}
Dustin Graves40f35822016-06-23 11:12:53 -06001116
Cortd889ff92016-07-27 09:51:27 -07001117TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1118 VkResult err;
1119
1120 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001121 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001122
1123 ASSERT_NO_FATAL_FAILURE(InitState());
1124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1125
1126 std::vector<const char *> device_extension_names;
1127 auto features = m_device->phy().features();
1128 // Artificially disable support for non-solid fill modes
1129 features.fillModeNonSolid = false;
1130 // The sacrificial device object
1131 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1132
1133 VkRenderpassObj render_pass(&test_device);
1134
1135 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1136 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1137 pipeline_layout_ci.setLayoutCount = 0;
1138 pipeline_layout_ci.pSetLayouts = NULL;
1139
1140 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001141 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001142 ASSERT_VK_SUCCESS(err);
1143
1144 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1145 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1146 rs_ci.pNext = nullptr;
1147 rs_ci.lineWidth = 1.0f;
1148 rs_ci.rasterizerDiscardEnable = true;
1149
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001150 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1151 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001152
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001153 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1155 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001156 {
1157 VkPipelineObj pipe(&test_device);
1158 pipe.AddShader(&vs);
1159 pipe.AddShader(&fs);
1160 pipe.AddColorAttachment();
1161 // Introduce failure by setting unsupported polygon mode
1162 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1163 pipe.SetRasterization(&rs_ci);
1164 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1165 }
1166 m_errorMonitor->VerifyFound();
1167
1168 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1170 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001171 {
1172 VkPipelineObj pipe(&test_device);
1173 pipe.AddShader(&vs);
1174 pipe.AddShader(&fs);
1175 pipe.AddColorAttachment();
1176 // Introduce failure by setting unsupported polygon mode
1177 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1178 pipe.SetRasterization(&rs_ci);
1179 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1180 }
1181 m_errorMonitor->VerifyFound();
1182
Cortd889ff92016-07-27 09:51:27 -07001183 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1184}
1185
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001186#endif // PARAMETER_VALIDATION_TESTS
1187
Tobin Ehlis0788f522015-05-26 16:11:58 -06001188#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001189#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001190TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001191{
1192 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001193 VkFenceCreateInfo fenceInfo = {};
1194 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1195 fenceInfo.pNext = NULL;
1196 fenceInfo.flags = 0;
1197
Mike Weiblencce7ec72016-10-17 19:33:05 -06001198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001199
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001200 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001201
1202 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1203 vk_testing::Buffer buffer;
1204 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001205
Tony Barbourfe3351b2015-07-28 10:17:20 -06001206 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001207 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001208 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001209
1210 testFence.init(*m_device, fenceInfo);
1211
1212 // Bypass framework since it does the waits automatically
1213 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001214 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001215 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1216 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001217 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001218 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001219 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001220 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001221 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001222 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001223 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001224
1225 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001226 ASSERT_VK_SUCCESS( err );
1227
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001229 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001230
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001231 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232}
1233
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001235{
1236 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001237 VkFenceCreateInfo fenceInfo = {};
1238 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1239 fenceInfo.pNext = NULL;
1240 fenceInfo.flags = 0;
1241
Mike Weiblencce7ec72016-10-17 19:33:05 -06001242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001243
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001244 ASSERT_NO_FATAL_FAILURE(InitState());
1245 ASSERT_NO_FATAL_FAILURE(InitViewport());
1246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1247
Tony Barbourfe3351b2015-07-28 10:17:20 -06001248 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001249 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001250 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251
1252 testFence.init(*m_device, fenceInfo);
1253
1254 // Bypass framework since it does the waits automatically
1255 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001256 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001257 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1258 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001259 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001260 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001261 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001262 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001263 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001264 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001265 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001266
1267 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001268 ASSERT_VK_SUCCESS( err );
1269
Jon Ashburnf19916e2016-01-11 13:12:43 -07001270 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001271 VkCommandBufferBeginInfo info = {};
1272 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1273 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001274 info.renderPass = VK_NULL_HANDLE;
1275 info.subpass = 0;
1276 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001277 info.occlusionQueryEnable = VK_FALSE;
1278 info.queryFlags = 0;
1279 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001280
1281 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001282 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001283
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001284 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001285}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001286#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001287
Tobin Ehlisf11be982016-05-11 13:52:53 -06001288TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1289 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1290 "buffer and image to memory such that they will alias.");
1291 VkResult err;
1292 bool pass;
1293 ASSERT_NO_FATAL_FAILURE(InitState());
1294
Tobin Ehlis077ded32016-05-12 17:39:13 -06001295 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001296 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001297 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001298 VkDeviceMemory mem; // buffer will be bound first
1299 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001300 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001301
1302 VkBufferCreateInfo buf_info = {};
1303 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1304 buf_info.pNext = NULL;
1305 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1306 buf_info.size = 256;
1307 buf_info.queueFamilyIndexCount = 0;
1308 buf_info.pQueueFamilyIndices = NULL;
1309 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1310 buf_info.flags = 0;
1311 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1312 ASSERT_VK_SUCCESS(err);
1313
Tobin Ehlis077ded32016-05-12 17:39:13 -06001314 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001315
1316 VkImageCreateInfo image_create_info = {};
1317 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1318 image_create_info.pNext = NULL;
1319 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1320 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1321 image_create_info.extent.width = 64;
1322 image_create_info.extent.height = 64;
1323 image_create_info.extent.depth = 1;
1324 image_create_info.mipLevels = 1;
1325 image_create_info.arrayLayers = 1;
1326 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001327 // Image tiling must be optimal to trigger error when aliasing linear buffer
1328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001329 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1330 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1331 image_create_info.queueFamilyIndexCount = 0;
1332 image_create_info.pQueueFamilyIndices = NULL;
1333 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1334 image_create_info.flags = 0;
1335
Tobin Ehlisf11be982016-05-11 13:52:53 -06001336 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1337 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001338 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1339 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001340
Tobin Ehlis077ded32016-05-12 17:39:13 -06001341 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1342
1343 VkMemoryAllocateInfo alloc_info = {};
1344 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1345 alloc_info.pNext = NULL;
1346 alloc_info.memoryTypeIndex = 0;
1347 // Ensure memory is big enough for both bindings
1348 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001349 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1350 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001351 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001352 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001353 vkDestroyImage(m_device->device(), image, NULL);
1354 return;
1355 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001356 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1357 ASSERT_VK_SUCCESS(err);
1358 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1359 ASSERT_VK_SUCCESS(err);
1360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001362 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001363 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1364 m_errorMonitor->VerifyFound();
1365
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001366 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001367 // aliasing buffer2
1368 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1369 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001370 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1371 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001372 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001373 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001375 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001376 m_errorMonitor->VerifyFound();
1377
1378 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001379 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001380 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001381 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001382 vkFreeMemory(m_device->device(), mem, NULL);
1383 vkFreeMemory(m_device->device(), mem_img, NULL);
1384}
1385
Tobin Ehlis35372522016-05-12 08:32:31 -06001386TEST_F(VkLayerTest, InvalidMemoryMapping) {
1387 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1388 VkResult err;
1389 bool pass;
1390 ASSERT_NO_FATAL_FAILURE(InitState());
1391
1392 VkBuffer buffer;
1393 VkDeviceMemory mem;
1394 VkMemoryRequirements mem_reqs;
1395
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001396 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1397
Tobin Ehlis35372522016-05-12 08:32:31 -06001398 VkBufferCreateInfo buf_info = {};
1399 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1400 buf_info.pNext = NULL;
1401 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1402 buf_info.size = 256;
1403 buf_info.queueFamilyIndexCount = 0;
1404 buf_info.pQueueFamilyIndices = NULL;
1405 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1406 buf_info.flags = 0;
1407 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1408 ASSERT_VK_SUCCESS(err);
1409
1410 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1411 VkMemoryAllocateInfo alloc_info = {};
1412 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1413 alloc_info.pNext = NULL;
1414 alloc_info.memoryTypeIndex = 0;
1415
1416 // Ensure memory is big enough for both bindings
1417 static const VkDeviceSize allocation_size = 0x10000;
1418 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001419 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001420 if (!pass) {
1421 vkDestroyBuffer(m_device->device(), buffer, NULL);
1422 return;
1423 }
1424 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1425 ASSERT_VK_SUCCESS(err);
1426
1427 uint8_t *pData;
1428 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001430 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1431 m_errorMonitor->VerifyFound();
1432 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001433 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001434 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1436 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1437 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001438 m_errorMonitor->VerifyFound();
1439
1440 // Unmap the memory to avoid re-map error
1441 vkUnmapMemory(m_device->device(), mem);
1442 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1444 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1445 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001446 m_errorMonitor->VerifyFound();
1447 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1449 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001450 m_errorMonitor->VerifyFound();
1451 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001453 vkUnmapMemory(m_device->device(), mem);
1454 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001455
Tobin Ehlis35372522016-05-12 08:32:31 -06001456 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001457 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001458 ASSERT_VK_SUCCESS(err);
1459 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001460 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001461 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001462 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001464 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1465 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001466
Tobin Ehlis35372522016-05-12 08:32:31 -06001467 // Now flush range that oversteps mapped range
1468 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001469 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001470 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001471 mmr.offset = atom_size;
1472 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1474 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1475 m_errorMonitor->VerifyFound();
1476
1477 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1478 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001479 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001480 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001481 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001482 mmr.size = VK_WHOLE_SIZE;
1483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001484 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1485 m_errorMonitor->VerifyFound();
1486
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001487 // Some platforms have an atomsize of 1 which makes the test meaningless
1488 if (atom_size > 3) {
1489 // Now with an offset NOT a multiple of the device limit
1490 vkUnmapMemory(m_device->device(), mem);
1491 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1492 ASSERT_VK_SUCCESS(err);
1493 mmr.offset = 3; // Not a multiple of atom_size
1494 mmr.size = VK_WHOLE_SIZE;
1495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1496 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1497 m_errorMonitor->VerifyFound();
1498
1499 // Now with a size NOT a multiple of the device limit
1500 vkUnmapMemory(m_device->device(), mem);
1501 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1502 ASSERT_VK_SUCCESS(err);
1503 mmr.offset = atom_size;
1504 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1506 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1507 m_errorMonitor->VerifyFound();
1508 }
1509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001510 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1511 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001512 if (!pass) {
1513 vkFreeMemory(m_device->device(), mem, NULL);
1514 vkDestroyBuffer(m_device->device(), buffer, NULL);
1515 return;
1516 }
1517 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1518 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1519
1520 vkDestroyBuffer(m_device->device(), buffer, NULL);
1521 vkFreeMemory(m_device->device(), mem, NULL);
1522}
1523
Chris Forbes09368e42016-10-13 11:59:22 +13001524#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001525TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1526 VkResult err;
1527 bool pass;
1528
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001529 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1530 // following declaration (which is temporarily being moved below):
1531 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001532 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001533 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001534 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001535 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001536 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001537 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001538
1539 ASSERT_NO_FATAL_FAILURE(InitState());
1540
Ian Elliott3f06ce52016-04-29 14:46:21 -06001541#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1542#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1543 // Use the functions from the VK_KHR_android_surface extension without
1544 // enabling that extension:
1545
1546 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001547 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1549 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001550 pass = (err != VK_SUCCESS);
1551 ASSERT_TRUE(pass);
1552 m_errorMonitor->VerifyFound();
1553#endif // VK_USE_PLATFORM_ANDROID_KHR
1554
Ian Elliott3f06ce52016-04-29 14:46:21 -06001555#if defined(VK_USE_PLATFORM_MIR_KHR)
1556 // Use the functions from the VK_KHR_mir_surface extension without enabling
1557 // that extension:
1558
1559 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001560 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001562 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1563 pass = (err != VK_SUCCESS);
1564 ASSERT_TRUE(pass);
1565 m_errorMonitor->VerifyFound();
1566
1567 // Tell whether an mir_connection supports presentation:
1568 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1570 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001571 m_errorMonitor->VerifyFound();
1572#endif // VK_USE_PLATFORM_MIR_KHR
1573
Ian Elliott3f06ce52016-04-29 14:46:21 -06001574#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1575 // Use the functions from the VK_KHR_wayland_surface extension without
1576 // enabling that extension:
1577
1578 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001579 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1581 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001582 pass = (err != VK_SUCCESS);
1583 ASSERT_TRUE(pass);
1584 m_errorMonitor->VerifyFound();
1585
1586 // Tell whether an wayland_display supports presentation:
1587 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1589 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001590 m_errorMonitor->VerifyFound();
1591#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001592#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001593
Ian Elliott3f06ce52016-04-29 14:46:21 -06001594#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001595 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1596 // TO NON-LINUX PLATFORMS:
1597 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001598 // Use the functions from the VK_KHR_win32_surface extension without
1599 // enabling that extension:
1600
1601 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001602 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1604 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001605 pass = (err != VK_SUCCESS);
1606 ASSERT_TRUE(pass);
1607 m_errorMonitor->VerifyFound();
1608
1609 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001611 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001612 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001613// Set this (for now, until all platforms are supported and tested):
1614#define NEED_TO_TEST_THIS_ON_PLATFORM
1615#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001616#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001617 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1618 // TO NON-LINUX PLATFORMS:
1619 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001620#endif
1621#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001622 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1623 // that extension:
1624
1625 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001626 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001628 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1629 pass = (err != VK_SUCCESS);
1630 ASSERT_TRUE(pass);
1631 m_errorMonitor->VerifyFound();
1632
1633 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001634 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001635 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1637 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001638 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001639// Set this (for now, until all platforms are supported and tested):
1640#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001641#endif // VK_USE_PLATFORM_XCB_KHR
1642
Ian Elliott12630812016-04-29 14:35:43 -06001643#if defined(VK_USE_PLATFORM_XLIB_KHR)
1644 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1645 // that extension:
1646
1647 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001648 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001650 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1651 pass = (err != VK_SUCCESS);
1652 ASSERT_TRUE(pass);
1653 m_errorMonitor->VerifyFound();
1654
1655 // Tell whether an Xlib VisualID supports presentation:
1656 Display *dpy = NULL;
1657 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001659 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1660 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001661// Set this (for now, until all platforms are supported and tested):
1662#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001663#endif // VK_USE_PLATFORM_XLIB_KHR
1664
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001665// Use the functions from the VK_KHR_surface extension without enabling
1666// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001667
Ian Elliott489eec02016-05-05 14:12:44 -06001668#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001669 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001671 vkDestroySurfaceKHR(instance(), surface, NULL);
1672 m_errorMonitor->VerifyFound();
1673
1674 // Check if surface supports presentation:
1675 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001677 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1678 pass = (err != VK_SUCCESS);
1679 ASSERT_TRUE(pass);
1680 m_errorMonitor->VerifyFound();
1681
1682 // Check surface capabilities:
1683 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1685 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001686 pass = (err != VK_SUCCESS);
1687 ASSERT_TRUE(pass);
1688 m_errorMonitor->VerifyFound();
1689
1690 // Check surface formats:
1691 uint32_t format_count = 0;
1692 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1694 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001695 pass = (err != VK_SUCCESS);
1696 ASSERT_TRUE(pass);
1697 m_errorMonitor->VerifyFound();
1698
1699 // Check surface present modes:
1700 uint32_t present_mode_count = 0;
1701 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1703 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001704 pass = (err != VK_SUCCESS);
1705 ASSERT_TRUE(pass);
1706 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001707#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001708
Ian Elliott1c32c772016-04-28 14:47:13 -06001709 // Use the functions from the VK_KHR_swapchain extension without enabling
1710 // that extension:
1711
1712 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001714 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1715 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001716 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001717 pass = (err != VK_SUCCESS);
1718 ASSERT_TRUE(pass);
1719 m_errorMonitor->VerifyFound();
1720
1721 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1723 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001724 pass = (err != VK_SUCCESS);
1725 ASSERT_TRUE(pass);
1726 m_errorMonitor->VerifyFound();
1727
Chris Forbeseb7d5502016-09-13 18:19:21 +12001728 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1729 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1730 VkFence fence;
1731 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1732
Ian Elliott1c32c772016-04-28 14:47:13 -06001733 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001735 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001736 pass = (err != VK_SUCCESS);
1737 ASSERT_TRUE(pass);
1738 m_errorMonitor->VerifyFound();
1739
Chris Forbeseb7d5502016-09-13 18:19:21 +12001740 vkDestroyFence(m_device->device(), fence, nullptr);
1741
Ian Elliott1c32c772016-04-28 14:47:13 -06001742 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001743 //
1744 // NOTE: Currently can't test this because a real swapchain is needed (as
1745 // opposed to the fake one we created) in order for the layer to lookup the
1746 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001747
1748 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001750 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1751 m_errorMonitor->VerifyFound();
1752}
Chris Forbes09368e42016-10-13 11:59:22 +13001753#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001754
Karl Schultz6addd812016-02-02 17:17:23 -07001755TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1756 VkResult err;
1757 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001758
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1760 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001761
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001762 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001763
1764 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001765 VkImage image;
1766 VkDeviceMemory mem;
1767 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001768
Karl Schultz6addd812016-02-02 17:17:23 -07001769 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1770 const int32_t tex_width = 32;
1771 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001772
Tony Barboureb254902015-07-15 12:50:33 -06001773 VkImageCreateInfo image_create_info = {};
1774 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001775 image_create_info.pNext = NULL;
1776 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1777 image_create_info.format = tex_format;
1778 image_create_info.extent.width = tex_width;
1779 image_create_info.extent.height = tex_height;
1780 image_create_info.extent.depth = 1;
1781 image_create_info.mipLevels = 1;
1782 image_create_info.arrayLayers = 1;
1783 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1784 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1785 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1786 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001787 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001788
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001789 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001790 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001791 mem_alloc.pNext = NULL;
1792 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001793
Chia-I Wuf7458c52015-10-26 21:10:41 +08001794 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001795 ASSERT_VK_SUCCESS(err);
1796
Karl Schultz6addd812016-02-02 17:17:23 -07001797 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001798
Mark Lobodzinski23065352015-05-29 09:32:35 -05001799 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001800
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001801 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Karl Schultz6addd812016-02-02 17:17:23 -07001802 if (!pass) { // If we can't find any unmappable memory this test doesn't
1803 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001804 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001805 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001806 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001807
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001808 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001809 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001810 ASSERT_VK_SUCCESS(err);
1811
1812 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001813 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001814 ASSERT_VK_SUCCESS(err);
1815
1816 // Map memory as if to initialize the image
1817 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001818 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001819
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001820 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001821
Chia-I Wuf7458c52015-10-26 21:10:41 +08001822 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001823 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001824}
1825
Karl Schultz6addd812016-02-02 17:17:23 -07001826TEST_F(VkLayerTest, RebindMemory) {
1827 VkResult err;
1828 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001829
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001831
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001832 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001833
1834 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001835 VkImage image;
1836 VkDeviceMemory mem1;
1837 VkDeviceMemory mem2;
1838 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001839
Karl Schultz6addd812016-02-02 17:17:23 -07001840 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1841 const int32_t tex_width = 32;
1842 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001843
Tony Barboureb254902015-07-15 12:50:33 -06001844 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001845 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1846 image_create_info.pNext = NULL;
1847 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1848 image_create_info.format = tex_format;
1849 image_create_info.extent.width = tex_width;
1850 image_create_info.extent.height = tex_height;
1851 image_create_info.extent.depth = 1;
1852 image_create_info.mipLevels = 1;
1853 image_create_info.arrayLayers = 1;
1854 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1855 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1856 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1857 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001858
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001859 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001860 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1861 mem_alloc.pNext = NULL;
1862 mem_alloc.allocationSize = 0;
1863 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001864
Karl Schultz6addd812016-02-02 17:17:23 -07001865 // Introduce failure, do NOT set memProps to
1866 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001867 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001868 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001869 ASSERT_VK_SUCCESS(err);
1870
Karl Schultz6addd812016-02-02 17:17:23 -07001871 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001872
1873 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001874 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001875 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001876
1877 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001878 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001879 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001880 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001881 ASSERT_VK_SUCCESS(err);
1882
1883 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001884 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001885 ASSERT_VK_SUCCESS(err);
1886
Karl Schultz6addd812016-02-02 17:17:23 -07001887 // Introduce validation failure, try to bind a different memory object to
1888 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001889 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001890
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001891 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001892
Chia-I Wuf7458c52015-10-26 21:10:41 +08001893 vkDestroyImage(m_device->device(), image, NULL);
1894 vkFreeMemory(m_device->device(), mem1, NULL);
1895 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001896}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001897
Karl Schultz6addd812016-02-02 17:17:23 -07001898TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001899 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001900
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1902 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001903
1904 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001905 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1906 fenceInfo.pNext = NULL;
1907 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001908
Tony Barbour300a6082015-04-07 13:44:53 -06001909 ASSERT_NO_FATAL_FAILURE(InitState());
1910 ASSERT_NO_FATAL_FAILURE(InitViewport());
1911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1912
Tony Barbourfe3351b2015-07-28 10:17:20 -06001913 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001914 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001915 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001916
1917 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001918
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001919 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001920 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1921 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001922 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001923 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001924 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001925 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001926 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001927 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001928 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001929
1930 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001931 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001932
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001933 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001934}
Chris Forbes4e44c912016-06-16 10:20:00 +12001935
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001936TEST_F(VkLayerTest, InvalidUsageBits) {
1937 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1938 "Initialize buffer with wrong usage then perform copy expecting errors "
1939 "from both the image and the buffer (2 calls)");
1940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001941
1942 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001943 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001944 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001945 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001946 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001947
Tony Barbourf92621a2016-05-02 14:28:12 -06001948 VkImageView dsv;
1949 VkImageViewCreateInfo dsvci = {};
1950 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1951 dsvci.image = image.handle();
1952 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1953 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1954 dsvci.subresourceRange.layerCount = 1;
1955 dsvci.subresourceRange.baseMipLevel = 0;
1956 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001957 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001958
Tony Barbourf92621a2016-05-02 14:28:12 -06001959 // Create a view with depth / stencil aspect for image with different usage
1960 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001961
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001962 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001963
1964 // Initialize buffer with TRANSFER_DST usage
1965 vk_testing::Buffer buffer;
1966 VkMemoryPropertyFlags reqs = 0;
1967 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1968 VkBufferImageCopy region = {};
1969 region.bufferRowLength = 128;
1970 region.bufferImageHeight = 128;
1971 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1972 region.imageSubresource.layerCount = 1;
1973 region.imageExtent.height = 16;
1974 region.imageExtent.width = 16;
1975 region.imageExtent.depth = 1;
1976
Tony Barbourf92621a2016-05-02 14:28:12 -06001977 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1978 // TRANSFER_DST
1979 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001980
Chris Forbesda581202016-10-06 18:25:26 +13001981 // two separate errors from this call:
1982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1984
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001985 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1986 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001987 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001988}
Tony Barbour75d79f02016-08-30 09:39:07 -06001989
Tony Barbour75d79f02016-08-30 09:39:07 -06001990
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001991#endif // MEM_TRACKER_TESTS
1992
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001993#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001994
1995TEST_F(VkLayerTest, LeakAnObject) {
1996 VkResult err;
1997
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001998 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001999
2000 // Note that we have to create a new device since destroying the
2001 // framework's device causes Teardown() to fail and just calling Teardown
2002 // will destroy the errorMonitor.
2003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002005
2006 ASSERT_NO_FATAL_FAILURE(InitState());
2007
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002008 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002009 std::vector<VkDeviceQueueCreateInfo> queue_info;
2010 queue_info.reserve(queue_props.size());
2011 std::vector<std::vector<float>> queue_priorities;
2012 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2013 VkDeviceQueueCreateInfo qi = {};
2014 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2015 qi.pNext = NULL;
2016 qi.queueFamilyIndex = i;
2017 qi.queueCount = queue_props[i].queueCount;
2018 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2019 qi.pQueuePriorities = queue_priorities[i].data();
2020 queue_info.push_back(qi);
2021 }
2022
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002023 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002024
2025 // The sacrificial device object
2026 VkDevice testDevice;
2027 VkDeviceCreateInfo device_create_info = {};
2028 auto features = m_device->phy().features();
2029 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2030 device_create_info.pNext = NULL;
2031 device_create_info.queueCreateInfoCount = queue_info.size();
2032 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002033 device_create_info.enabledLayerCount = 0;
2034 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002035 device_create_info.pEnabledFeatures = &features;
2036 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2037 ASSERT_VK_SUCCESS(err);
2038
2039 VkFence fence;
2040 VkFenceCreateInfo fence_create_info = {};
2041 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2042 fence_create_info.pNext = NULL;
2043 fence_create_info.flags = 0;
2044 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2045 ASSERT_VK_SUCCESS(err);
2046
2047 // Induce failure by not calling vkDestroyFence
2048 vkDestroyDevice(testDevice, NULL);
2049 m_errorMonitor->VerifyFound();
2050}
2051
2052TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2053
2054 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2055 "attempt to delete them from another.");
2056
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002058
Cody Northropc31a84f2016-08-22 10:41:47 -06002059 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002060 VkCommandPool command_pool_one;
2061 VkCommandPool command_pool_two;
2062
2063 VkCommandPoolCreateInfo pool_create_info{};
2064 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2065 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2066 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2067
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002068 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002069
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002070 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002071
2072 VkCommandBuffer command_buffer[9];
2073 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002074 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002075 command_buffer_allocate_info.commandPool = command_pool_one;
2076 command_buffer_allocate_info.commandBufferCount = 9;
2077 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002078 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002079
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002080 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002081
2082 m_errorMonitor->VerifyFound();
2083
2084 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2085 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2086}
2087
2088TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2089 VkResult err;
2090
2091 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002092 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002093
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002095
2096 ASSERT_NO_FATAL_FAILURE(InitState());
2097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2098
2099 VkDescriptorPoolSize ds_type_count = {};
2100 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2101 ds_type_count.descriptorCount = 1;
2102
2103 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2104 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2105 ds_pool_ci.pNext = NULL;
2106 ds_pool_ci.flags = 0;
2107 ds_pool_ci.maxSets = 1;
2108 ds_pool_ci.poolSizeCount = 1;
2109 ds_pool_ci.pPoolSizes = &ds_type_count;
2110
2111 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002112 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002113 ASSERT_VK_SUCCESS(err);
2114
2115 // Create a second descriptor pool
2116 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002117 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002118 ASSERT_VK_SUCCESS(err);
2119
2120 VkDescriptorSetLayoutBinding dsl_binding = {};
2121 dsl_binding.binding = 0;
2122 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2123 dsl_binding.descriptorCount = 1;
2124 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2125 dsl_binding.pImmutableSamplers = NULL;
2126
2127 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2128 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2129 ds_layout_ci.pNext = NULL;
2130 ds_layout_ci.bindingCount = 1;
2131 ds_layout_ci.pBindings = &dsl_binding;
2132
2133 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002134 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002135 ASSERT_VK_SUCCESS(err);
2136
2137 VkDescriptorSet descriptorSet;
2138 VkDescriptorSetAllocateInfo alloc_info = {};
2139 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2140 alloc_info.descriptorSetCount = 1;
2141 alloc_info.descriptorPool = ds_pool_one;
2142 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002143 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002144 ASSERT_VK_SUCCESS(err);
2145
2146 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2147
2148 m_errorMonitor->VerifyFound();
2149
2150 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2151 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2152 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2153}
2154
2155TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002157
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002158 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002159
2160 ASSERT_NO_FATAL_FAILURE(InitState());
2161
2162 // Pass bogus handle into GetImageMemoryRequirements
2163 VkMemoryRequirements mem_reqs;
2164 uint64_t fakeImageHandle = 0xCADECADE;
2165 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2166
2167 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2168
2169 m_errorMonitor->VerifyFound();
2170}
2171
Karl Schultz6addd812016-02-02 17:17:23 -07002172TEST_F(VkLayerTest, PipelineNotBound) {
2173 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002174
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002175 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002176
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002178
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002179 ASSERT_NO_FATAL_FAILURE(InitState());
2180 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002181
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002182 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002183 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2184 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002185
2186 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002187 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2188 ds_pool_ci.pNext = NULL;
2189 ds_pool_ci.maxSets = 1;
2190 ds_pool_ci.poolSizeCount = 1;
2191 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002192
2193 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002194 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002195 ASSERT_VK_SUCCESS(err);
2196
2197 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002198 dsl_binding.binding = 0;
2199 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2200 dsl_binding.descriptorCount = 1;
2201 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2202 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002203
2204 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002205 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2206 ds_layout_ci.pNext = NULL;
2207 ds_layout_ci.bindingCount = 1;
2208 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002209
2210 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002211 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002212 ASSERT_VK_SUCCESS(err);
2213
2214 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002215 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002216 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002217 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002218 alloc_info.descriptorPool = ds_pool;
2219 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002220 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002221 ASSERT_VK_SUCCESS(err);
2222
2223 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002224 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2225 pipeline_layout_ci.pNext = NULL;
2226 pipeline_layout_ci.setLayoutCount = 1;
2227 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002228
2229 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002230 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002231 ASSERT_VK_SUCCESS(err);
2232
Mark Youngad779052016-01-06 14:26:04 -07002233 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002234
2235 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002236 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002237
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002238 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002239
Chia-I Wuf7458c52015-10-26 21:10:41 +08002240 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2241 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2242 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002243}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002244
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002245TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2246 VkResult err;
2247
2248 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2249 "during bind[Buffer|Image]Memory time");
2250
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002251 ASSERT_NO_FATAL_FAILURE(InitState());
2252
2253 // Create an image, allocate memory, set a bad typeIndex and then try to
2254 // bind it
2255 VkImage image;
2256 VkDeviceMemory mem;
2257 VkMemoryRequirements mem_reqs;
2258 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2259 const int32_t tex_width = 32;
2260 const int32_t tex_height = 32;
2261
2262 VkImageCreateInfo image_create_info = {};
2263 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2264 image_create_info.pNext = NULL;
2265 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2266 image_create_info.format = tex_format;
2267 image_create_info.extent.width = tex_width;
2268 image_create_info.extent.height = tex_height;
2269 image_create_info.extent.depth = 1;
2270 image_create_info.mipLevels = 1;
2271 image_create_info.arrayLayers = 1;
2272 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2273 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2274 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2275 image_create_info.flags = 0;
2276
2277 VkMemoryAllocateInfo mem_alloc = {};
2278 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2279 mem_alloc.pNext = NULL;
2280 mem_alloc.allocationSize = 0;
2281 mem_alloc.memoryTypeIndex = 0;
2282
2283 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2284 ASSERT_VK_SUCCESS(err);
2285
2286 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2287 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002288
2289 // Introduce Failure, select invalid TypeIndex
2290 VkPhysicalDeviceMemoryProperties memory_info;
2291
2292 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2293 unsigned int i;
2294 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2295 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2296 mem_alloc.memoryTypeIndex = i;
2297 break;
2298 }
2299 }
2300 if (i >= memory_info.memoryTypeCount) {
2301 printf("No invalid memory type index could be found; skipped.\n");
2302 vkDestroyImage(m_device->device(), image, NULL);
2303 return;
2304 }
2305
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002307
2308 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2309 ASSERT_VK_SUCCESS(err);
2310
2311 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2312 (void)err;
2313
2314 m_errorMonitor->VerifyFound();
2315
2316 vkDestroyImage(m_device->device(), image, NULL);
2317 vkFreeMemory(m_device->device(), mem, NULL);
2318}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002319
Karl Schultz6addd812016-02-02 17:17:23 -07002320TEST_F(VkLayerTest, BindInvalidMemory) {
2321 VkResult err;
2322 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002323
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002325
Tobin Ehlisec598302015-09-15 15:02:17 -06002326 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002327
2328 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002329 VkImage image;
2330 VkDeviceMemory mem;
2331 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002332
Karl Schultz6addd812016-02-02 17:17:23 -07002333 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2334 const int32_t tex_width = 32;
2335 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002336
2337 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002338 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2339 image_create_info.pNext = NULL;
2340 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2341 image_create_info.format = tex_format;
2342 image_create_info.extent.width = tex_width;
2343 image_create_info.extent.height = tex_height;
2344 image_create_info.extent.depth = 1;
2345 image_create_info.mipLevels = 1;
2346 image_create_info.arrayLayers = 1;
2347 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2348 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2349 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2350 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002351
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002352 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002353 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2354 mem_alloc.pNext = NULL;
2355 mem_alloc.allocationSize = 0;
2356 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002357
Chia-I Wuf7458c52015-10-26 21:10:41 +08002358 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002359 ASSERT_VK_SUCCESS(err);
2360
Karl Schultz6addd812016-02-02 17:17:23 -07002361 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002362
2363 mem_alloc.allocationSize = mem_reqs.size;
2364
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002365 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002366 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002367
2368 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002369 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002370 ASSERT_VK_SUCCESS(err);
2371
2372 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002373 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002374
2375 // Try to bind free memory that has been freed
2376 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2377 // This may very well return an error.
2378 (void)err;
2379
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002380 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002381
Chia-I Wuf7458c52015-10-26 21:10:41 +08002382 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002383}
2384
Karl Schultz6addd812016-02-02 17:17:23 -07002385TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2386 VkResult err;
2387 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002388
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002390
Tobin Ehlisec598302015-09-15 15:02:17 -06002391 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002392
Karl Schultz6addd812016-02-02 17:17:23 -07002393 // Create an image object, allocate memory, destroy the object and then try
2394 // to bind it
2395 VkImage image;
2396 VkDeviceMemory mem;
2397 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002398
Karl Schultz6addd812016-02-02 17:17:23 -07002399 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2400 const int32_t tex_width = 32;
2401 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002402
2403 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002404 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2405 image_create_info.pNext = NULL;
2406 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2407 image_create_info.format = tex_format;
2408 image_create_info.extent.width = tex_width;
2409 image_create_info.extent.height = tex_height;
2410 image_create_info.extent.depth = 1;
2411 image_create_info.mipLevels = 1;
2412 image_create_info.arrayLayers = 1;
2413 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2414 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2415 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2416 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002417
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002418 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002419 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2420 mem_alloc.pNext = NULL;
2421 mem_alloc.allocationSize = 0;
2422 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002423
Chia-I Wuf7458c52015-10-26 21:10:41 +08002424 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002425 ASSERT_VK_SUCCESS(err);
2426
Karl Schultz6addd812016-02-02 17:17:23 -07002427 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002428
2429 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002430 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002431 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002432
2433 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002434 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002435 ASSERT_VK_SUCCESS(err);
2436
2437 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002438 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002439 ASSERT_VK_SUCCESS(err);
2440
2441 // Now Try to bind memory to this destroyed object
2442 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2443 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002444 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002445
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002446 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002447
Chia-I Wuf7458c52015-10-26 21:10:41 +08002448 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002449}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002450
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002451#endif // OBJ_TRACKER_TESTS
2452
Tobin Ehlis0788f522015-05-26 16:11:58 -06002453#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002454
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002455TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2456 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2457
2458 ASSERT_NO_FATAL_FAILURE(InitState());
2459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2460
2461 VkVertexInputBindingDescription input_binding;
2462 memset(&input_binding, 0, sizeof(input_binding));
2463
2464 VkVertexInputAttributeDescription input_attribs;
2465 memset(&input_attribs, 0, sizeof(input_attribs));
2466
2467 // Pick a really bad format for this purpose and make sure it should fail
2468 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2469 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2470 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2471 printf("Format unsuitable for test; skipped.\n");
2472 return;
2473 }
2474
2475 input_attribs.location = 0;
2476 char const *vsSource = "#version 450\n"
2477 "\n"
2478 "out gl_PerVertex {\n"
2479 " vec4 gl_Position;\n"
2480 "};\n"
2481 "void main(){\n"
2482 " gl_Position = vec4(1);\n"
2483 "}\n";
2484 char const *fsSource = "#version 450\n"
2485 "\n"
2486 "layout(location=0) out vec4 color;\n"
2487 "void main(){\n"
2488 " color = vec4(1);\n"
2489 "}\n";
2490
2491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2492 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2493 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2494
2495 VkPipelineObj pipe(m_device);
2496 pipe.AddColorAttachment();
2497 pipe.AddShader(&vs);
2498 pipe.AddShader(&fs);
2499
2500 pipe.AddVertexInputBindings(&input_binding, 1);
2501 pipe.AddVertexInputAttribs(&input_attribs, 1);
2502
2503 VkDescriptorSetObj descriptorSet(m_device);
2504 descriptorSet.AppendDummy();
2505 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2506
2507 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2508
2509 m_errorMonitor->VerifyFound();
2510}
2511
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002512TEST_F(VkLayerTest, ImageSampleCounts) {
2513
2514 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2515 "validation errors.");
2516 ASSERT_NO_FATAL_FAILURE(InitState());
2517
2518 VkMemoryPropertyFlags reqs = 0;
2519 VkImageCreateInfo image_create_info = {};
2520 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2521 image_create_info.pNext = NULL;
2522 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2523 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2524 image_create_info.extent.width = 256;
2525 image_create_info.extent.height = 256;
2526 image_create_info.extent.depth = 1;
2527 image_create_info.mipLevels = 1;
2528 image_create_info.arrayLayers = 1;
2529 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2530 image_create_info.flags = 0;
2531
2532 VkImageBlit blit_region = {};
2533 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2534 blit_region.srcSubresource.baseArrayLayer = 0;
2535 blit_region.srcSubresource.layerCount = 1;
2536 blit_region.srcSubresource.mipLevel = 0;
2537 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2538 blit_region.dstSubresource.baseArrayLayer = 0;
2539 blit_region.dstSubresource.layerCount = 1;
2540 blit_region.dstSubresource.mipLevel = 0;
2541
2542 // Create two images, the source with sampleCount = 2, and attempt to blit
2543 // between them
2544 {
2545 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002546 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002547 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002548 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002549 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002550 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002551 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002552 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002553 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2555 "of VK_SAMPLE_COUNT_2_BIT but "
2556 "must be VK_SAMPLE_COUNT_1_BIT");
2557 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2558 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002559 m_errorMonitor->VerifyFound();
2560 m_commandBuffer->EndCommandBuffer();
2561 }
2562
2563 // Create two images, the dest with sampleCount = 4, and attempt to blit
2564 // between them
2565 {
2566 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002567 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002568 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002569 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002570 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002571 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002572 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002573 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002574 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2576 "of VK_SAMPLE_COUNT_4_BIT but "
2577 "must be VK_SAMPLE_COUNT_1_BIT");
2578 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2579 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002580 m_errorMonitor->VerifyFound();
2581 m_commandBuffer->EndCommandBuffer();
2582 }
2583
2584 VkBufferImageCopy copy_region = {};
2585 copy_region.bufferRowLength = 128;
2586 copy_region.bufferImageHeight = 128;
2587 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2588 copy_region.imageSubresource.layerCount = 1;
2589 copy_region.imageExtent.height = 64;
2590 copy_region.imageExtent.width = 64;
2591 copy_region.imageExtent.depth = 1;
2592
2593 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2594 // buffer to image
2595 {
2596 vk_testing::Buffer src_buffer;
2597 VkMemoryPropertyFlags reqs = 0;
2598 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2599 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002600 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002601 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002602 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002603 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2605 "of VK_SAMPLE_COUNT_8_BIT but "
2606 "must be VK_SAMPLE_COUNT_1_BIT");
2607 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2608 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002609 m_errorMonitor->VerifyFound();
2610 m_commandBuffer->EndCommandBuffer();
2611 }
2612
2613 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2614 // image to buffer
2615 {
2616 vk_testing::Buffer dst_buffer;
2617 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2618 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002619 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002620 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002621 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002622 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2624 "of VK_SAMPLE_COUNT_2_BIT but "
2625 "must be VK_SAMPLE_COUNT_1_BIT");
2626 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002627 dst_buffer.handle(), 1, &copy_region);
2628 m_errorMonitor->VerifyFound();
2629 m_commandBuffer->EndCommandBuffer();
2630 }
2631}
2632
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002633TEST_F(VkLayerTest, BlitImageFormats) {
2634
2635 // Image blit with mismatched formats
2636 const char * expected_message =
2637 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2638 " the other one must also have signed/unsigned integer format";
2639
2640 ASSERT_NO_FATAL_FAILURE(InitState());
2641
2642 VkImageObj src_image(m_device);
2643 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2644 VkImageObj dst_image(m_device);
2645 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2646 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002647 dst_image2.init(64, 64, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002648
2649 VkImageBlit blitRegion = {};
2650 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2651 blitRegion.srcSubresource.baseArrayLayer = 0;
2652 blitRegion.srcSubresource.layerCount = 1;
2653 blitRegion.srcSubresource.mipLevel = 0;
2654 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2655 blitRegion.dstSubresource.baseArrayLayer = 0;
2656 blitRegion.dstSubresource.layerCount = 1;
2657 blitRegion.dstSubresource.mipLevel = 0;
2658
2659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2660
2661 // Unsigned int vs not an int
2662 BeginCommandBuffer();
2663 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2664 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2665
2666 m_errorMonitor->VerifyFound();
2667
2668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2669
2670 // Unsigned int vs signed int
2671 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2672 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2673
2674 m_errorMonitor->VerifyFound();
2675
2676 EndCommandBuffer();
2677}
2678
2679
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002680TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2681 VkResult err;
2682 bool pass;
2683
2684 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2685 ASSERT_NO_FATAL_FAILURE(InitState());
2686
2687 // If w/d/h granularity is 1, test is not meaningful
2688 // TODO: When virtual device limits are available, create a set of limits for this test that
2689 // will always have a granularity of > 1 for w, h, and d
2690 auto index = m_device->graphics_queue_node_index_;
2691 auto queue_family_properties = m_device->phy().queue_properties();
2692
2693 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2694 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2695 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2696 return;
2697 }
2698
2699 // Create two images of different types and try to copy between them
2700 VkImage srcImage;
2701 VkImage dstImage;
2702 VkDeviceMemory srcMem;
2703 VkDeviceMemory destMem;
2704 VkMemoryRequirements memReqs;
2705
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002706 VkImageCreateInfo image_create_info = {};
2707 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2708 image_create_info.pNext = NULL;
2709 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2710 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2711 image_create_info.extent.width = 32;
2712 image_create_info.extent.height = 32;
2713 image_create_info.extent.depth = 1;
2714 image_create_info.mipLevels = 1;
2715 image_create_info.arrayLayers = 4;
2716 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2717 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2718 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2719 image_create_info.flags = 0;
2720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002721 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002722 ASSERT_VK_SUCCESS(err);
2723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002724 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002725 ASSERT_VK_SUCCESS(err);
2726
2727 // Allocate memory
2728 VkMemoryAllocateInfo memAlloc = {};
2729 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2730 memAlloc.pNext = NULL;
2731 memAlloc.allocationSize = 0;
2732 memAlloc.memoryTypeIndex = 0;
2733
2734 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2735 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002736 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002737 ASSERT_TRUE(pass);
2738 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2739 ASSERT_VK_SUCCESS(err);
2740
2741 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2742 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002743 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002744 ASSERT_VK_SUCCESS(err);
2745 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2746 ASSERT_VK_SUCCESS(err);
2747
2748 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2749 ASSERT_VK_SUCCESS(err);
2750 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2751 ASSERT_VK_SUCCESS(err);
2752
2753 BeginCommandBuffer();
2754 VkImageCopy copyRegion;
2755 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2756 copyRegion.srcSubresource.mipLevel = 0;
2757 copyRegion.srcSubresource.baseArrayLayer = 0;
2758 copyRegion.srcSubresource.layerCount = 1;
2759 copyRegion.srcOffset.x = 0;
2760 copyRegion.srcOffset.y = 0;
2761 copyRegion.srcOffset.z = 0;
2762 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2763 copyRegion.dstSubresource.mipLevel = 0;
2764 copyRegion.dstSubresource.baseArrayLayer = 0;
2765 copyRegion.dstSubresource.layerCount = 1;
2766 copyRegion.dstOffset.x = 0;
2767 copyRegion.dstOffset.y = 0;
2768 copyRegion.dstOffset.z = 0;
2769 copyRegion.extent.width = 1;
2770 copyRegion.extent.height = 1;
2771 copyRegion.extent.depth = 1;
2772
2773 // Introduce failure by setting srcOffset to a bad granularity value
2774 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2776 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002777 m_errorMonitor->VerifyFound();
2778
2779 // Introduce failure by setting extent to a bad granularity value
2780 copyRegion.srcOffset.y = 0;
2781 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2783 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002784 m_errorMonitor->VerifyFound();
2785
2786 // Now do some buffer/image copies
2787 vk_testing::Buffer buffer;
2788 VkMemoryPropertyFlags reqs = 0;
2789 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2790 VkBufferImageCopy region = {};
2791 region.bufferOffset = 0;
2792 region.bufferRowLength = 3;
2793 region.bufferImageHeight = 128;
2794 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2795 region.imageSubresource.layerCount = 1;
2796 region.imageExtent.height = 16;
2797 region.imageExtent.width = 16;
2798 region.imageExtent.depth = 1;
2799 region.imageOffset.x = 0;
2800 region.imageOffset.y = 0;
2801 region.imageOffset.z = 0;
2802
2803 // Introduce failure by setting bufferRowLength to a bad granularity value
2804 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2806 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2807 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002808 m_errorMonitor->VerifyFound();
2809 region.bufferRowLength = 128;
2810
2811 // Introduce failure by setting bufferOffset to a bad granularity value
2812 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2814 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2815 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002816 m_errorMonitor->VerifyFound();
2817 region.bufferOffset = 0;
2818
2819 // Introduce failure by setting bufferImageHeight to a bad granularity value
2820 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2822 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2823 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002824 m_errorMonitor->VerifyFound();
2825 region.bufferImageHeight = 128;
2826
2827 // Introduce failure by setting imageExtent to a bad granularity value
2828 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2830 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2831 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002832 m_errorMonitor->VerifyFound();
2833 region.imageExtent.width = 16;
2834
2835 // Introduce failure by setting imageOffset to a bad granularity value
2836 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2838 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2839 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002840 m_errorMonitor->VerifyFound();
2841
2842 EndCommandBuffer();
2843
2844 vkDestroyImage(m_device->device(), srcImage, NULL);
2845 vkDestroyImage(m_device->device(), dstImage, NULL);
2846 vkFreeMemory(m_device->device(), srcMem, NULL);
2847 vkFreeMemory(m_device->device(), destMem, NULL);
2848}
2849
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002850TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002851 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2852 "attempt to submit them on a queue created in a different "
2853 "queue family.");
2854
Cody Northropc31a84f2016-08-22 10:41:47 -06002855 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002856 // This test is meaningless unless we have multiple queue families
2857 auto queue_family_properties = m_device->phy().queue_properties();
2858 if (queue_family_properties.size() < 2) {
2859 return;
2860 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002862 // Get safe index of another queue family
2863 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2864 ASSERT_NO_FATAL_FAILURE(InitState());
2865 // Create a second queue using a different queue family
2866 VkQueue other_queue;
2867 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2868
2869 // Record an empty cmd buffer
2870 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2871 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2872 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2873 vkEndCommandBuffer(m_commandBuffer->handle());
2874
2875 // And submit on the wrong queue
2876 VkSubmitInfo submit_info = {};
2877 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2878 submit_info.commandBufferCount = 1;
2879 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002880 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002881
2882 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002883}
2884
Chris Forbes4c24a922016-11-16 08:59:10 +13002885TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2886 ASSERT_NO_FATAL_FAILURE(InitState());
2887
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002888 // There are no attachments, but refer to attachment 0.
2889 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002890 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002891 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2892 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002893 };
2894
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002895 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2896 nullptr,
2897 0,
2898 0,
2899 nullptr,
2900 1,
2901 subpasses,
2902 0,
2903 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002904 VkRenderPass rp;
2905
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002906 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002908 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002909 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2910 m_errorMonitor->VerifyFound();
2911}
2912
Chris Forbesa58c4522016-09-28 15:19:39 +13002913TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2914 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2915 ASSERT_NO_FATAL_FAILURE(InitState());
2916
2917 // A renderpass with two subpasses, both writing the same attachment.
2918 VkAttachmentDescription attach[] = {
2919 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2920 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2921 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2922 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2923 },
2924 };
2925 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2926 VkSubpassDescription subpasses[] = {
2927 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2928 1, &ref, nullptr, nullptr, 0, nullptr },
2929 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2930 1, &ref, nullptr, nullptr, 0, nullptr },
2931 };
2932 VkSubpassDependency dep = {
2933 0, 1,
2934 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2935 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2936 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2937 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2938 VK_DEPENDENCY_BY_REGION_BIT
2939 };
2940 VkRenderPassCreateInfo rpci = {
2941 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2942 0, 1, attach, 2, subpasses, 1, &dep
2943 };
2944 VkRenderPass rp;
2945 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2946 ASSERT_VK_SUCCESS(err);
2947
2948 VkImageObj image(m_device);
2949 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2950 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2951 VK_IMAGE_TILING_OPTIMAL, 0);
2952 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2953
2954 VkFramebufferCreateInfo fbci = {
2955 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2956 0, rp, 1, &imageView, 32, 32, 1
2957 };
2958 VkFramebuffer fb;
2959 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2960 ASSERT_VK_SUCCESS(err);
2961
2962 char const *vsSource =
2963 "#version 450\n"
2964 "void main() { gl_Position = vec4(1); }\n";
2965 char const *fsSource =
2966 "#version 450\n"
2967 "layout(location=0) out vec4 color;\n"
2968 "void main() { color = vec4(1); }\n";
2969
2970 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2971 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2972 VkPipelineObj pipe(m_device);
2973 pipe.AddColorAttachment();
2974 pipe.AddShader(&vs);
2975 pipe.AddShader(&fs);
2976 VkViewport view_port = {};
2977 m_viewports.push_back(view_port);
2978 pipe.SetViewport(m_viewports);
2979 VkRect2D rect = {};
2980 m_scissors.push_back(rect);
2981 pipe.SetScissor(m_scissors);
2982
2983 VkPipelineLayoutCreateInfo plci = {
2984 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2985 0, 0, nullptr, 0, nullptr
2986 };
2987 VkPipelineLayout pl;
2988 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2989 ASSERT_VK_SUCCESS(err);
2990 pipe.CreateVKPipeline(pl, rp);
2991
2992 BeginCommandBuffer();
2993
2994 VkRenderPassBeginInfo rpbi = {
2995 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2996 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
2997 };
2998
2999 // subtest 1: bind in the wrong subpass
3000 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3001 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3003 "built for subpass 0 but used in subpass 1");
3004 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3005 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3006 m_errorMonitor->VerifyFound();
3007
3008 vkCmdEndRenderPass(m_commandBuffer->handle());
3009
3010 // subtest 2: bind in correct subpass, then transition to next subpass
3011 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3012 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3013 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3015 "built for subpass 0 but used in subpass 1");
3016 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3017 m_errorMonitor->VerifyFound();
3018
3019 vkCmdEndRenderPass(m_commandBuffer->handle());
3020
3021 EndCommandBuffer();
3022
3023 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3024 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3025 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3026}
3027
Tony Barbour4e919972016-08-09 13:27:40 -06003028TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3029 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3030 "with extent outside of framebuffer");
3031 ASSERT_NO_FATAL_FAILURE(InitState());
3032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3035 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003036
3037 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3038 m_renderPassBeginInfo.renderArea.extent.width = 257;
3039 m_renderPassBeginInfo.renderArea.extent.height = 257;
3040 BeginCommandBuffer();
3041 m_errorMonitor->VerifyFound();
3042}
3043
3044TEST_F(VkLayerTest, DisabledIndependentBlend) {
3045 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3046 "blend and then specifying different blend states for two "
3047 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003048 VkPhysicalDeviceFeatures features = {};
3049 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003050 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003051
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3053 "Invalid Pipeline CreateInfo: If independent blend feature not "
3054 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003055
Cody Northropc31a84f2016-08-22 10:41:47 -06003056 VkDescriptorSetObj descriptorSet(m_device);
3057 descriptorSet.AppendDummy();
3058 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003059
Cody Northropc31a84f2016-08-22 10:41:47 -06003060 VkPipelineObj pipeline(m_device);
3061 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003062 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003063 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003064
Cody Northropc31a84f2016-08-22 10:41:47 -06003065 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3066 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3067 att_state1.blendEnable = VK_TRUE;
3068 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3069 att_state2.blendEnable = VK_FALSE;
3070 pipeline.AddColorAttachment(0, &att_state1);
3071 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003072 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003073 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003074}
3075
3076TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3077 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3078 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003079 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003080
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3082 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003083
3084 // Create a renderPass with a single color attachment
3085 VkAttachmentReference attach = {};
3086 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3087 VkSubpassDescription subpass = {};
3088 VkRenderPassCreateInfo rpci = {};
3089 rpci.subpassCount = 1;
3090 rpci.pSubpasses = &subpass;
3091 rpci.attachmentCount = 1;
3092 VkAttachmentDescription attach_desc = {};
3093 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3094 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3095 rpci.pAttachments = &attach_desc;
3096 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3097 VkRenderPass rp;
3098 subpass.pDepthStencilAttachment = &attach;
3099 subpass.pColorAttachments = NULL;
3100 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3101 m_errorMonitor->VerifyFound();
3102}
3103
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003104TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3105 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3106 "attachment reference of VK_ATTACHMENT_UNUSED");
3107
3108 ASSERT_NO_FATAL_FAILURE(InitState());
3109 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3110
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003112
3113 VkAttachmentReference color_attach = {};
3114 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3115 color_attach.attachment = 0;
3116 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3117 VkSubpassDescription subpass = {};
3118 subpass.colorAttachmentCount = 1;
3119 subpass.pColorAttachments = &color_attach;
3120 subpass.preserveAttachmentCount = 1;
3121 subpass.pPreserveAttachments = &preserve_attachment;
3122
3123 VkRenderPassCreateInfo rpci = {};
3124 rpci.subpassCount = 1;
3125 rpci.pSubpasses = &subpass;
3126 rpci.attachmentCount = 1;
3127 VkAttachmentDescription attach_desc = {};
3128 attach_desc.format = VK_FORMAT_UNDEFINED;
3129 rpci.pAttachments = &attach_desc;
3130 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3131 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003132 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003133
3134 m_errorMonitor->VerifyFound();
3135
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003136 if (result == VK_SUCCESS) {
3137 vkDestroyRenderPass(m_device->device(), rp, NULL);
3138 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003139}
3140
Chris Forbesc5389742016-06-29 11:49:23 +12003141TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003142 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3143 "when the source of a subpass multisample resolve "
3144 "does not have multiple samples.");
3145
Chris Forbesc5389742016-06-29 11:49:23 +12003146 ASSERT_NO_FATAL_FAILURE(InitState());
3147
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3149 "Subpass 0 requests multisample resolve from attachment 0 which has "
3150 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003151
3152 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003153 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3154 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3155 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3156 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3157 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3158 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003159 };
3160
3161 VkAttachmentReference color = {
3162 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3163 };
3164
3165 VkAttachmentReference resolve = {
3166 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3167 };
3168
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003169 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003170
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003171 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003172
3173 VkRenderPass rp;
3174 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3175
3176 m_errorMonitor->VerifyFound();
3177
3178 if (err == VK_SUCCESS)
3179 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3180}
3181
3182TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003183 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3184 "when a subpass multisample resolve operation is "
3185 "requested, and the destination of that resolve has "
3186 "multiple samples.");
3187
Chris Forbesc5389742016-06-29 11:49:23 +12003188 ASSERT_NO_FATAL_FAILURE(InitState());
3189
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3191 "Subpass 0 requests multisample resolve into attachment 1, which "
3192 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003193
3194 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003195 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3196 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3197 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3198 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3199 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3200 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003201 };
3202
3203 VkAttachmentReference color = {
3204 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3205 };
3206
3207 VkAttachmentReference resolve = {
3208 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3209 };
3210
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003211 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003212
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003213 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003214
3215 VkRenderPass rp;
3216 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3217
3218 m_errorMonitor->VerifyFound();
3219
3220 if (err == VK_SUCCESS)
3221 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3222}
3223
Chris Forbes3f128ef2016-06-29 14:58:53 +12003224TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003225 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3226 "when the color and depth attachments used by a subpass "
3227 "have inconsistent sample counts");
3228
Chris Forbes3f128ef2016-06-29 14:58:53 +12003229 ASSERT_NO_FATAL_FAILURE(InitState());
3230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3232 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003233
3234 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003235 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3236 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3237 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3238 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3239 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3240 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003241 };
3242
3243 VkAttachmentReference color[] = {
3244 {
3245 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3246 },
3247 {
3248 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3249 },
3250 };
3251
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003252 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003253
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003254 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003255
3256 VkRenderPass rp;
3257 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3258
3259 m_errorMonitor->VerifyFound();
3260
3261 if (err == VK_SUCCESS)
3262 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3263}
3264
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003265TEST_F(VkLayerTest, FramebufferCreateErrors) {
3266 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003267 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003268 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003269 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3270 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3271 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3272 " 6. Framebuffer attachment where dimensions don't match\n"
3273 " 7. Framebuffer attachment w/o identity swizzle\n"
3274 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003275
3276 ASSERT_NO_FATAL_FAILURE(InitState());
3277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3278
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3280 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3281 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003282
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003283 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003284 VkAttachmentReference attach = {};
3285 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3286 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003287 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003288 VkRenderPassCreateInfo rpci = {};
3289 rpci.subpassCount = 1;
3290 rpci.pSubpasses = &subpass;
3291 rpci.attachmentCount = 1;
3292 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003293 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003294 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003295 rpci.pAttachments = &attach_desc;
3296 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3297 VkRenderPass rp;
3298 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3299 ASSERT_VK_SUCCESS(err);
3300
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003301 VkImageView ivs[2];
3302 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3303 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003304 VkFramebufferCreateInfo fb_info = {};
3305 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3306 fb_info.pNext = NULL;
3307 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003308 // Set mis-matching attachmentCount
3309 fb_info.attachmentCount = 2;
3310 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003311 fb_info.width = 100;
3312 fb_info.height = 100;
3313 fb_info.layers = 1;
3314
3315 VkFramebuffer fb;
3316 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3317
3318 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003319 if (err == VK_SUCCESS) {
3320 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3321 }
3322 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003323
3324 // Create a renderPass with a depth-stencil attachment created with
3325 // IMAGE_USAGE_COLOR_ATTACHMENT
3326 // Add our color attachment to pDepthStencilAttachment
3327 subpass.pDepthStencilAttachment = &attach;
3328 subpass.pColorAttachments = NULL;
3329 VkRenderPass rp_ds;
3330 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3331 ASSERT_VK_SUCCESS(err);
3332 // Set correct attachment count, but attachment has COLOR usage bit set
3333 fb_info.attachmentCount = 1;
3334 fb_info.renderPass = rp_ds;
3335
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003337 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3338
3339 m_errorMonitor->VerifyFound();
3340 if (err == VK_SUCCESS) {
3341 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3342 }
3343 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003344
3345 // Create new renderpass with alternate attachment format from fb
3346 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3347 subpass.pDepthStencilAttachment = NULL;
3348 subpass.pColorAttachments = &attach;
3349 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3350 ASSERT_VK_SUCCESS(err);
3351
3352 // Cause error due to mis-matched formats between rp & fb
3353 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3354 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3356 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003357 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3358
3359 m_errorMonitor->VerifyFound();
3360 if (err == VK_SUCCESS) {
3361 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3362 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003363 vkDestroyRenderPass(m_device->device(), rp, NULL);
3364
3365 // Create new renderpass with alternate sample count from fb
3366 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3367 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3368 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3369 ASSERT_VK_SUCCESS(err);
3370
3371 // Cause error due to mis-matched sample count between rp & fb
3372 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3374 "that do not match the "
3375 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003376 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3377
3378 m_errorMonitor->VerifyFound();
3379 if (err == VK_SUCCESS) {
3380 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3381 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003382
3383 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003384
3385 // Create a custom imageView with non-1 mip levels
3386 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003387 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003388 ASSERT_TRUE(image.initialized());
3389
3390 VkImageView view;
3391 VkImageViewCreateInfo ivci = {};
3392 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3393 ivci.image = image.handle();
3394 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3395 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3396 ivci.subresourceRange.layerCount = 1;
3397 ivci.subresourceRange.baseMipLevel = 0;
3398 // Set level count 2 (only 1 is allowed for FB attachment)
3399 ivci.subresourceRange.levelCount = 2;
3400 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3401 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3402 ASSERT_VK_SUCCESS(err);
3403 // Re-create renderpass to have matching sample count
3404 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3405 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3406 ASSERT_VK_SUCCESS(err);
3407
3408 fb_info.renderPass = rp;
3409 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003411 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3412
3413 m_errorMonitor->VerifyFound();
3414 if (err == VK_SUCCESS) {
3415 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3416 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003417 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003418 // Update view to original color buffer and grow FB dimensions too big
3419 fb_info.pAttachments = ivs;
3420 fb_info.height = 1024;
3421 fb_info.width = 1024;
3422 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3424 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003425 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3426
3427 m_errorMonitor->VerifyFound();
3428 if (err == VK_SUCCESS) {
3429 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3430 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003431 // Create view attachment with non-identity swizzle
3432 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3433 ivci.image = image.handle();
3434 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3435 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3436 ivci.subresourceRange.layerCount = 1;
3437 ivci.subresourceRange.baseMipLevel = 0;
3438 ivci.subresourceRange.levelCount = 1;
3439 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3440 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3441 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3442 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3443 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3444 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3445 ASSERT_VK_SUCCESS(err);
3446
3447 fb_info.pAttachments = &view;
3448 fb_info.height = 100;
3449 fb_info.width = 100;
3450 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3452 "framebuffer attachments must have "
3453 "been created with the identity "
3454 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003455 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3456
3457 m_errorMonitor->VerifyFound();
3458 if (err == VK_SUCCESS) {
3459 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3460 }
3461 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003462 // Request fb that exceeds max dimensions
3463 // reset attachment to color attachment
3464 fb_info.pAttachments = ivs;
3465 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3466 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3467 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3469 "dimensions exceed physical device "
3470 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003471 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3472
3473 m_errorMonitor->VerifyFound();
3474 if (err == VK_SUCCESS) {
3475 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3476 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003477
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003478 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003479}
3480
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003481TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003482 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3483 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003484
Cody Northropc31a84f2016-08-22 10:41:47 -06003485 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003486 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3488 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003489 m_errorMonitor->VerifyFound();
3490}
3491
3492TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003493 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3494 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003495
Cody Northropc31a84f2016-08-22 10:41:47 -06003496 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003497 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3499 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003500 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003501}
3502
3503TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003504 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3505 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003506
Cody Northropc31a84f2016-08-22 10:41:47 -06003507 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003508 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003510 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003511 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003512}
3513
3514TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003515 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3516 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003517
Cody Northropc31a84f2016-08-22 10:41:47 -06003518 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003519 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003521 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003522 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003523}
3524
Cortd713fe82016-07-27 09:51:27 -07003525TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003526 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3527 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003528
3529 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003530 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3532 "Dynamic blend constants state not set for this command buffer");
3533 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003534 m_errorMonitor->VerifyFound();
3535}
3536
3537TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003538 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3539 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003540
3541 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003542 if (!m_device->phy().features().depthBounds) {
3543 printf("Device does not support depthBounds test; skipped.\n");
3544 return;
3545 }
3546 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3548 "Dynamic depth bounds state not set for this command buffer");
3549 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003550 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003551}
3552
3553TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003554 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3555 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003556
3557 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003558 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3560 "Dynamic stencil read mask state not set for this command buffer");
3561 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003562 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003563}
3564
3565TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003566 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3567 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003568
3569 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003570 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3572 "Dynamic stencil write mask state not set for this command buffer");
3573 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003574 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003575}
3576
3577TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003578 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3579 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003580
3581 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003582 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3584 "Dynamic stencil reference state not set for this command buffer");
3585 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003586 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003587}
3588
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003589TEST_F(VkLayerTest, IndexBufferNotBound) {
3590 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003591
3592 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3594 "Index buffer object not bound to this command buffer when Indexed ");
3595 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003596 m_errorMonitor->VerifyFound();
3597}
3598
Karl Schultz6addd812016-02-02 17:17:23 -07003599TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3601 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3602 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003603
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003604 ASSERT_NO_FATAL_FAILURE(InitState());
3605 ASSERT_NO_FATAL_FAILURE(InitViewport());
3606 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3607
Karl Schultz6addd812016-02-02 17:17:23 -07003608 // We luck out b/c by default the framework creates CB w/ the
3609 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003610 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003611 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003612 EndCommandBuffer();
3613
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003614 // Bypass framework since it does the waits automatically
3615 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003616 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003617 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3618 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003619 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003620 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003621 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003622 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003623 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003624 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003625 submit_info.pSignalSemaphores = NULL;
3626
Chris Forbes40028e22016-06-13 09:59:34 +12003627 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003628 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003629 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003630
Karl Schultz6addd812016-02-02 17:17:23 -07003631 // Cause validation error by re-submitting cmd buffer that should only be
3632 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003633 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003634 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003635
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003636 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003637}
3638
Karl Schultz6addd812016-02-02 17:17:23 -07003639TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003640 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07003641 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003642
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
3644 "type "
3645 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003646
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003647 ASSERT_NO_FATAL_FAILURE(InitState());
3648 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003649
Karl Schultz6addd812016-02-02 17:17:23 -07003650 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3651 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003652 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003653 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3654 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003655
3656 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003657 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3658 ds_pool_ci.pNext = NULL;
3659 ds_pool_ci.flags = 0;
3660 ds_pool_ci.maxSets = 1;
3661 ds_pool_ci.poolSizeCount = 1;
3662 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003663
3664 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003665 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003666 ASSERT_VK_SUCCESS(err);
3667
3668 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003669 dsl_binding.binding = 0;
3670 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3671 dsl_binding.descriptorCount = 1;
3672 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3673 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003674
3675 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003676 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3677 ds_layout_ci.pNext = NULL;
3678 ds_layout_ci.bindingCount = 1;
3679 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003680
3681 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003682 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003683 ASSERT_VK_SUCCESS(err);
3684
3685 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003686 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003687 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003688 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003689 alloc_info.descriptorPool = ds_pool;
3690 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003691 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003692
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003693 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003694
Chia-I Wuf7458c52015-10-26 21:10:41 +08003695 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3696 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003697}
3698
Karl Schultz6addd812016-02-02 17:17:23 -07003699TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3700 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003701
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3703 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3704 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003705
Tobin Ehlise735c692015-10-08 13:13:50 -06003706 ASSERT_NO_FATAL_FAILURE(InitState());
3707 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003708
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003709 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003710 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3711 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003712
3713 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003714 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3715 ds_pool_ci.pNext = NULL;
3716 ds_pool_ci.maxSets = 1;
3717 ds_pool_ci.poolSizeCount = 1;
3718 ds_pool_ci.flags = 0;
3719 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3720 // app can only call vkResetDescriptorPool on this pool.;
3721 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003722
3723 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003724 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003725 ASSERT_VK_SUCCESS(err);
3726
3727 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003728 dsl_binding.binding = 0;
3729 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3730 dsl_binding.descriptorCount = 1;
3731 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3732 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003733
3734 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003735 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3736 ds_layout_ci.pNext = NULL;
3737 ds_layout_ci.bindingCount = 1;
3738 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003739
3740 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003741 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003742 ASSERT_VK_SUCCESS(err);
3743
3744 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003745 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003746 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003747 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003748 alloc_info.descriptorPool = ds_pool;
3749 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003750 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003751 ASSERT_VK_SUCCESS(err);
3752
3753 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003754 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003755
Chia-I Wuf7458c52015-10-26 21:10:41 +08003756 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3757 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003758}
3759
Karl Schultz6addd812016-02-02 17:17:23 -07003760TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003761 // Attempt to clear Descriptor Pool with bad object.
3762 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003763
3764 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003766 uint64_t fake_pool_handle = 0xbaad6001;
3767 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3768 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003769 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003770}
3771
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003772TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003773 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3774 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003775 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003776 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003777
3778 uint64_t fake_set_handle = 0xbaad6001;
3779 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003780 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003782
3783 ASSERT_NO_FATAL_FAILURE(InitState());
3784
3785 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3786 layout_bindings[0].binding = 0;
3787 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3788 layout_bindings[0].descriptorCount = 1;
3789 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3790 layout_bindings[0].pImmutableSamplers = NULL;
3791
3792 VkDescriptorSetLayout descriptor_set_layout;
3793 VkDescriptorSetLayoutCreateInfo dslci = {};
3794 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3795 dslci.pNext = NULL;
3796 dslci.bindingCount = 1;
3797 dslci.pBindings = layout_bindings;
3798 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003799 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003800
3801 VkPipelineLayout pipeline_layout;
3802 VkPipelineLayoutCreateInfo plci = {};
3803 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3804 plci.pNext = NULL;
3805 plci.setLayoutCount = 1;
3806 plci.pSetLayouts = &descriptor_set_layout;
3807 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003808 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003809
3810 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003811 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3812 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003813 m_errorMonitor->VerifyFound();
3814 EndCommandBuffer();
3815 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3816 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003817}
3818
Karl Schultz6addd812016-02-02 17:17:23 -07003819TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003820 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3821 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003822 uint64_t fake_layout_handle = 0xbaad6001;
3823 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003825 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003826 VkPipelineLayout pipeline_layout;
3827 VkPipelineLayoutCreateInfo plci = {};
3828 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3829 plci.pNext = NULL;
3830 plci.setLayoutCount = 1;
3831 plci.pSetLayouts = &bad_layout;
3832 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3833
3834 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003835}
3836
Mark Muellerd4914412016-06-13 17:52:06 -06003837TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3838 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3839 "1) A uniform buffer update must have a valid buffer index."
3840 "2) When using an array of descriptors in a single WriteDescriptor,"
3841 " the descriptor types and stageflags must all be the same."
3842 "3) Immutable Sampler state must match across descriptors");
3843
3844 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003845 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3846 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3847 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3848 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3849 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003850
Mark Muellerd4914412016-06-13 17:52:06 -06003851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3852
3853 ASSERT_NO_FATAL_FAILURE(InitState());
3854 VkDescriptorPoolSize ds_type_count[4] = {};
3855 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3856 ds_type_count[0].descriptorCount = 1;
3857 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3858 ds_type_count[1].descriptorCount = 1;
3859 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3860 ds_type_count[2].descriptorCount = 1;
3861 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3862 ds_type_count[3].descriptorCount = 1;
3863
3864 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3865 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3866 ds_pool_ci.maxSets = 1;
3867 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3868 ds_pool_ci.pPoolSizes = ds_type_count;
3869
3870 VkDescriptorPool ds_pool;
3871 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3872 ASSERT_VK_SUCCESS(err);
3873
Mark Muellerb9896722016-06-16 09:54:29 -06003874 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003875 layout_binding[0].binding = 0;
3876 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3877 layout_binding[0].descriptorCount = 1;
3878 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3879 layout_binding[0].pImmutableSamplers = NULL;
3880
3881 layout_binding[1].binding = 1;
3882 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3883 layout_binding[1].descriptorCount = 1;
3884 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3885 layout_binding[1].pImmutableSamplers = NULL;
3886
3887 VkSamplerCreateInfo sampler_ci = {};
3888 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3889 sampler_ci.pNext = NULL;
3890 sampler_ci.magFilter = VK_FILTER_NEAREST;
3891 sampler_ci.minFilter = VK_FILTER_NEAREST;
3892 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3893 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3894 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3895 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3896 sampler_ci.mipLodBias = 1.0;
3897 sampler_ci.anisotropyEnable = VK_FALSE;
3898 sampler_ci.maxAnisotropy = 1;
3899 sampler_ci.compareEnable = VK_FALSE;
3900 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3901 sampler_ci.minLod = 1.0;
3902 sampler_ci.maxLod = 1.0;
3903 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3904 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3905 VkSampler sampler;
3906
3907 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3908 ASSERT_VK_SUCCESS(err);
3909
3910 layout_binding[2].binding = 2;
3911 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3912 layout_binding[2].descriptorCount = 1;
3913 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3914 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3915
Mark Muellerd4914412016-06-13 17:52:06 -06003916 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3917 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3918 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3919 ds_layout_ci.pBindings = layout_binding;
3920 VkDescriptorSetLayout ds_layout;
3921 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3922 ASSERT_VK_SUCCESS(err);
3923
3924 VkDescriptorSetAllocateInfo alloc_info = {};
3925 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3926 alloc_info.descriptorSetCount = 1;
3927 alloc_info.descriptorPool = ds_pool;
3928 alloc_info.pSetLayouts = &ds_layout;
3929 VkDescriptorSet descriptorSet;
3930 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3931 ASSERT_VK_SUCCESS(err);
3932
3933 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3934 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3935 pipeline_layout_ci.pNext = NULL;
3936 pipeline_layout_ci.setLayoutCount = 1;
3937 pipeline_layout_ci.pSetLayouts = &ds_layout;
3938
3939 VkPipelineLayout pipeline_layout;
3940 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3941 ASSERT_VK_SUCCESS(err);
3942
Mark Mueller5c838ce2016-06-16 09:54:29 -06003943 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003944 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3945 descriptor_write.dstSet = descriptorSet;
3946 descriptor_write.dstBinding = 0;
3947 descriptor_write.descriptorCount = 1;
3948 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3949
Mark Mueller5c838ce2016-06-16 09:54:29 -06003950 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003951 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3952 m_errorMonitor->VerifyFound();
3953
3954 // Create a buffer to update the descriptor with
3955 uint32_t qfi = 0;
3956 VkBufferCreateInfo buffCI = {};
3957 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3958 buffCI.size = 1024;
3959 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3960 buffCI.queueFamilyIndexCount = 1;
3961 buffCI.pQueueFamilyIndices = &qfi;
3962
3963 VkBuffer dyub;
3964 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3965 ASSERT_VK_SUCCESS(err);
3966 VkDescriptorBufferInfo buffInfo = {};
3967 buffInfo.buffer = dyub;
3968 buffInfo.offset = 0;
3969 buffInfo.range = 1024;
3970
3971 descriptor_write.pBufferInfo = &buffInfo;
3972 descriptor_write.descriptorCount = 2;
3973
Mark Mueller5c838ce2016-06-16 09:54:29 -06003974 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3976 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3977 m_errorMonitor->VerifyFound();
3978
Mark Mueller5c838ce2016-06-16 09:54:29 -06003979 // 3) The second descriptor has a null_ptr pImmutableSamplers and
3980 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06003981 descriptor_write.dstBinding = 1;
3982 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06003983
Mark Mueller5c838ce2016-06-16 09:54:29 -06003984 // Make pImageInfo index non-null to avoid complaints of it missing
3985 VkDescriptorImageInfo imageInfo = {};
3986 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3987 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06003988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
3989 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3990 m_errorMonitor->VerifyFound();
3991
Mark Muellerd4914412016-06-13 17:52:06 -06003992 vkDestroyBuffer(m_device->device(), dyub, NULL);
3993 vkDestroySampler(m_device->device(), sampler, NULL);
3994 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3995 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3996 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3997}
3998
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003999TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4000 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4001 "due to a buffer dependency being destroyed.");
4002 ASSERT_NO_FATAL_FAILURE(InitState());
4003
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004004 VkBuffer buffer;
4005 VkDeviceMemory mem;
4006 VkMemoryRequirements mem_reqs;
4007
4008 VkBufferCreateInfo buf_info = {};
4009 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004010 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004011 buf_info.size = 256;
4012 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4013 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4014 ASSERT_VK_SUCCESS(err);
4015
4016 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4017
4018 VkMemoryAllocateInfo alloc_info = {};
4019 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4020 alloc_info.allocationSize = 256;
4021 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004022 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004023 if (!pass) {
4024 vkDestroyBuffer(m_device->device(), buffer, NULL);
4025 return;
4026 }
4027 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4028 ASSERT_VK_SUCCESS(err);
4029
4030 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4031 ASSERT_VK_SUCCESS(err);
4032
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004033 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004034 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004035 m_commandBuffer->EndCommandBuffer();
4036
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004038 // Destroy buffer dependency prior to submit to cause ERROR
4039 vkDestroyBuffer(m_device->device(), buffer, NULL);
4040
4041 VkSubmitInfo submit_info = {};
4042 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4043 submit_info.commandBufferCount = 1;
4044 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4045 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4046
4047 m_errorMonitor->VerifyFound();
4048 vkFreeMemory(m_device->handle(), mem, NULL);
4049}
4050
Tobin Ehlisea413442016-09-28 10:23:59 -06004051TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4052 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4053
4054 ASSERT_NO_FATAL_FAILURE(InitState());
4055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4056
4057 VkDescriptorPoolSize ds_type_count;
4058 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4059 ds_type_count.descriptorCount = 1;
4060
4061 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4062 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4063 ds_pool_ci.maxSets = 1;
4064 ds_pool_ci.poolSizeCount = 1;
4065 ds_pool_ci.pPoolSizes = &ds_type_count;
4066
4067 VkDescriptorPool ds_pool;
4068 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4069 ASSERT_VK_SUCCESS(err);
4070
4071 VkDescriptorSetLayoutBinding layout_binding;
4072 layout_binding.binding = 0;
4073 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4074 layout_binding.descriptorCount = 1;
4075 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4076 layout_binding.pImmutableSamplers = NULL;
4077
4078 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4079 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4080 ds_layout_ci.bindingCount = 1;
4081 ds_layout_ci.pBindings = &layout_binding;
4082 VkDescriptorSetLayout ds_layout;
4083 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4084 ASSERT_VK_SUCCESS(err);
4085
4086 VkDescriptorSetAllocateInfo alloc_info = {};
4087 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4088 alloc_info.descriptorSetCount = 1;
4089 alloc_info.descriptorPool = ds_pool;
4090 alloc_info.pSetLayouts = &ds_layout;
4091 VkDescriptorSet descriptor_set;
4092 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4093 ASSERT_VK_SUCCESS(err);
4094
4095 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4096 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4097 pipeline_layout_ci.pNext = NULL;
4098 pipeline_layout_ci.setLayoutCount = 1;
4099 pipeline_layout_ci.pSetLayouts = &ds_layout;
4100
4101 VkPipelineLayout pipeline_layout;
4102 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4103 ASSERT_VK_SUCCESS(err);
4104
4105 VkBuffer buffer;
4106 uint32_t queue_family_index = 0;
4107 VkBufferCreateInfo buffer_create_info = {};
4108 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4109 buffer_create_info.size = 1024;
4110 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4111 buffer_create_info.queueFamilyIndexCount = 1;
4112 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4113
4114 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4115 ASSERT_VK_SUCCESS(err);
4116
4117 VkMemoryRequirements memory_reqs;
4118 VkDeviceMemory buffer_memory;
4119
4120 VkMemoryAllocateInfo memory_info = {};
4121 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4122 memory_info.allocationSize = 0;
4123 memory_info.memoryTypeIndex = 0;
4124
4125 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4126 memory_info.allocationSize = memory_reqs.size;
4127 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4128 ASSERT_TRUE(pass);
4129
4130 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4131 ASSERT_VK_SUCCESS(err);
4132 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4133 ASSERT_VK_SUCCESS(err);
4134
4135 VkBufferView view;
4136 VkBufferViewCreateInfo bvci = {};
4137 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4138 bvci.buffer = buffer;
4139 bvci.format = VK_FORMAT_R8_UNORM;
4140 bvci.range = VK_WHOLE_SIZE;
4141
4142 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4143 ASSERT_VK_SUCCESS(err);
4144
4145 VkWriteDescriptorSet descriptor_write = {};
4146 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4147 descriptor_write.dstSet = descriptor_set;
4148 descriptor_write.dstBinding = 0;
4149 descriptor_write.descriptorCount = 1;
4150 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4151 descriptor_write.pTexelBufferView = &view;
4152
4153 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4154
4155 char const *vsSource = "#version 450\n"
4156 "\n"
4157 "out gl_PerVertex { \n"
4158 " vec4 gl_Position;\n"
4159 "};\n"
4160 "void main(){\n"
4161 " gl_Position = vec4(1);\n"
4162 "}\n";
4163 char const *fsSource = "#version 450\n"
4164 "\n"
4165 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4166 "layout(location=0) out vec4 x;\n"
4167 "void main(){\n"
4168 " x = imageLoad(s, 0);\n"
4169 "}\n";
4170 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4171 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4172 VkPipelineObj pipe(m_device);
4173 pipe.AddShader(&vs);
4174 pipe.AddShader(&fs);
4175 pipe.AddColorAttachment();
4176 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4177
4178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4180
4181 BeginCommandBuffer();
4182 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4183 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4184 VkRect2D scissor = {{0, 0}, {16, 16}};
4185 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4186 // Bind pipeline to cmd buffer
4187 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4188 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4189 &descriptor_set, 0, nullptr);
4190 Draw(1, 0, 0, 0);
4191 EndCommandBuffer();
4192
4193 // Delete BufferView in order to invalidate cmd buffer
4194 vkDestroyBufferView(m_device->device(), view, NULL);
4195 // Now attempt submit of cmd buffer
4196 VkSubmitInfo submit_info = {};
4197 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4198 submit_info.commandBufferCount = 1;
4199 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4200 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4201 m_errorMonitor->VerifyFound();
4202
4203 // Clean-up
4204 vkDestroyBuffer(m_device->device(), buffer, NULL);
4205 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4206 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4207 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4208 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4209}
4210
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004211TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4212 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4213 "due to an image dependency being destroyed.");
4214 ASSERT_NO_FATAL_FAILURE(InitState());
4215
4216 VkImage image;
4217 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4218 VkImageCreateInfo image_create_info = {};
4219 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4220 image_create_info.pNext = NULL;
4221 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4222 image_create_info.format = tex_format;
4223 image_create_info.extent.width = 32;
4224 image_create_info.extent.height = 32;
4225 image_create_info.extent.depth = 1;
4226 image_create_info.mipLevels = 1;
4227 image_create_info.arrayLayers = 1;
4228 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4229 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004230 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004231 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004232 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004233 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004234 // Have to bind memory to image before recording cmd in cmd buffer using it
4235 VkMemoryRequirements mem_reqs;
4236 VkDeviceMemory image_mem;
4237 bool pass;
4238 VkMemoryAllocateInfo mem_alloc = {};
4239 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4240 mem_alloc.pNext = NULL;
4241 mem_alloc.memoryTypeIndex = 0;
4242 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4243 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004244 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004245 ASSERT_TRUE(pass);
4246 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4247 ASSERT_VK_SUCCESS(err);
4248 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4249 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004250
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004251 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004252 VkClearColorValue ccv;
4253 ccv.float32[0] = 1.0f;
4254 ccv.float32[1] = 1.0f;
4255 ccv.float32[2] = 1.0f;
4256 ccv.float32[3] = 1.0f;
4257 VkImageSubresourceRange isr = {};
4258 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004259 isr.baseArrayLayer = 0;
4260 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004261 isr.layerCount = 1;
4262 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004263 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004264 m_commandBuffer->EndCommandBuffer();
4265
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004267 // Destroy image dependency prior to submit to cause ERROR
4268 vkDestroyImage(m_device->device(), image, NULL);
4269
4270 VkSubmitInfo submit_info = {};
4271 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4272 submit_info.commandBufferCount = 1;
4273 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4274 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4275
4276 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004277 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004278}
4279
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004280TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4281 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4282 "due to a framebuffer image dependency being destroyed.");
4283 VkFormatProperties format_properties;
4284 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004285 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4286 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004287 return;
4288 }
4289
4290 ASSERT_NO_FATAL_FAILURE(InitState());
4291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4292
4293 VkImageCreateInfo image_ci = {};
4294 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4295 image_ci.pNext = NULL;
4296 image_ci.imageType = VK_IMAGE_TYPE_2D;
4297 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4298 image_ci.extent.width = 32;
4299 image_ci.extent.height = 32;
4300 image_ci.extent.depth = 1;
4301 image_ci.mipLevels = 1;
4302 image_ci.arrayLayers = 1;
4303 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4304 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004305 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004306 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4307 image_ci.flags = 0;
4308 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004309 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004310
4311 VkMemoryRequirements memory_reqs;
4312 VkDeviceMemory image_memory;
4313 bool pass;
4314 VkMemoryAllocateInfo memory_info = {};
4315 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4316 memory_info.pNext = NULL;
4317 memory_info.allocationSize = 0;
4318 memory_info.memoryTypeIndex = 0;
4319 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4320 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004321 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004322 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004323 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004324 ASSERT_VK_SUCCESS(err);
4325 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4326 ASSERT_VK_SUCCESS(err);
4327
4328 VkImageViewCreateInfo ivci = {
4329 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4330 nullptr,
4331 0,
4332 image,
4333 VK_IMAGE_VIEW_TYPE_2D,
4334 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004335 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004336 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4337 };
4338 VkImageView view;
4339 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4340 ASSERT_VK_SUCCESS(err);
4341
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004342 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004343 VkFramebuffer fb;
4344 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4345 ASSERT_VK_SUCCESS(err);
4346
4347 // Just use default renderpass with our framebuffer
4348 m_renderPassBeginInfo.framebuffer = fb;
4349 // Create Null cmd buffer for submit
4350 BeginCommandBuffer();
4351 EndCommandBuffer();
4352 // Destroy image attached to framebuffer to invalidate cmd buffer
4353 vkDestroyImage(m_device->device(), image, NULL);
4354 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004356 QueueCommandBuffer(false);
4357 m_errorMonitor->VerifyFound();
4358
4359 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4360 vkDestroyImageView(m_device->device(), view, nullptr);
4361 vkFreeMemory(m_device->device(), image_memory, nullptr);
4362}
4363
Tobin Ehlisb329f992016-10-12 13:20:29 -06004364TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4365 TEST_DESCRIPTION("Delete in-use framebuffer.");
4366 VkFormatProperties format_properties;
4367 VkResult err = VK_SUCCESS;
4368 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4369
4370 ASSERT_NO_FATAL_FAILURE(InitState());
4371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4372
4373 VkImageObj image(m_device);
4374 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4375 ASSERT_TRUE(image.initialized());
4376 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4377
4378 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4379 VkFramebuffer fb;
4380 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4381 ASSERT_VK_SUCCESS(err);
4382
4383 // Just use default renderpass with our framebuffer
4384 m_renderPassBeginInfo.framebuffer = fb;
4385 // Create Null cmd buffer for submit
4386 BeginCommandBuffer();
4387 EndCommandBuffer();
4388 // Submit cmd buffer to put it in-flight
4389 VkSubmitInfo submit_info = {};
4390 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4391 submit_info.commandBufferCount = 1;
4392 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4393 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4394 // Destroy framebuffer while in-flight
4395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4396 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4397 m_errorMonitor->VerifyFound();
4398 // Wait for queue to complete so we can safely destroy everything
4399 vkQueueWaitIdle(m_device->m_queue);
4400 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4401}
4402
Tobin Ehlis88becd72016-09-21 14:33:41 -06004403TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4404 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4405 VkFormatProperties format_properties;
4406 VkResult err = VK_SUCCESS;
4407 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004408
4409 ASSERT_NO_FATAL_FAILURE(InitState());
4410 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4411
4412 VkImageCreateInfo image_ci = {};
4413 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4414 image_ci.pNext = NULL;
4415 image_ci.imageType = VK_IMAGE_TYPE_2D;
4416 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4417 image_ci.extent.width = 256;
4418 image_ci.extent.height = 256;
4419 image_ci.extent.depth = 1;
4420 image_ci.mipLevels = 1;
4421 image_ci.arrayLayers = 1;
4422 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4423 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004424 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004425 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4426 image_ci.flags = 0;
4427 VkImage image;
4428 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4429
4430 VkMemoryRequirements memory_reqs;
4431 VkDeviceMemory image_memory;
4432 bool pass;
4433 VkMemoryAllocateInfo memory_info = {};
4434 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4435 memory_info.pNext = NULL;
4436 memory_info.allocationSize = 0;
4437 memory_info.memoryTypeIndex = 0;
4438 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4439 memory_info.allocationSize = memory_reqs.size;
4440 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4441 ASSERT_TRUE(pass);
4442 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4443 ASSERT_VK_SUCCESS(err);
4444 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4445 ASSERT_VK_SUCCESS(err);
4446
4447 VkImageViewCreateInfo ivci = {
4448 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4449 nullptr,
4450 0,
4451 image,
4452 VK_IMAGE_VIEW_TYPE_2D,
4453 VK_FORMAT_B8G8R8A8_UNORM,
4454 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4455 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4456 };
4457 VkImageView view;
4458 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4459 ASSERT_VK_SUCCESS(err);
4460
4461 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4462 VkFramebuffer fb;
4463 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4464 ASSERT_VK_SUCCESS(err);
4465
4466 // Just use default renderpass with our framebuffer
4467 m_renderPassBeginInfo.framebuffer = fb;
4468 // Create Null cmd buffer for submit
4469 BeginCommandBuffer();
4470 EndCommandBuffer();
4471 // Submit cmd buffer to put it (and attached imageView) in-flight
4472 VkSubmitInfo submit_info = {};
4473 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4474 submit_info.commandBufferCount = 1;
4475 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4476 // Submit cmd buffer to put framebuffer and children in-flight
4477 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4478 // Destroy image attached to framebuffer while in-flight
4479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4480 vkDestroyImage(m_device->device(), image, NULL);
4481 m_errorMonitor->VerifyFound();
4482 // Wait for queue to complete so we can safely destroy image and other objects
4483 vkQueueWaitIdle(m_device->m_queue);
4484 vkDestroyImage(m_device->device(), image, NULL);
4485 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4486 vkDestroyImageView(m_device->device(), view, nullptr);
4487 vkFreeMemory(m_device->device(), image_memory, nullptr);
4488}
4489
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004490TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4491 TEST_DESCRIPTION("Delete in-use renderPass.");
4492
4493 ASSERT_NO_FATAL_FAILURE(InitState());
4494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4495
4496 // Create simple renderpass
4497 VkAttachmentReference attach = {};
4498 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4499 VkSubpassDescription subpass = {};
4500 subpass.pColorAttachments = &attach;
4501 VkRenderPassCreateInfo rpci = {};
4502 rpci.subpassCount = 1;
4503 rpci.pSubpasses = &subpass;
4504 rpci.attachmentCount = 1;
4505 VkAttachmentDescription attach_desc = {};
4506 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4507 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4508 rpci.pAttachments = &attach_desc;
4509 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4510 VkRenderPass rp;
4511 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4512 ASSERT_VK_SUCCESS(err);
4513
4514 // Create a pipeline that uses the given renderpass
4515 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4516 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4517
4518 VkPipelineLayout pipeline_layout;
4519 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4520 ASSERT_VK_SUCCESS(err);
4521
4522 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4523 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4524 vp_state_ci.viewportCount = 1;
4525 VkViewport vp = {}; // Just need dummy vp to point to
4526 vp_state_ci.pViewports = &vp;
4527 vp_state_ci.scissorCount = 1;
4528 VkRect2D scissors = {}; // Dummy scissors to point to
4529 vp_state_ci.pScissors = &scissors;
4530
4531 VkPipelineShaderStageCreateInfo shaderStages[2];
4532 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4533
4534 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4535 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4536 // but add it to be able to run on more devices
4537 shaderStages[0] = vs.GetStageCreateInfo();
4538 shaderStages[1] = fs.GetStageCreateInfo();
4539
4540 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4541 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4542
4543 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4544 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4545 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4546
4547 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4548 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4549 rs_ci.rasterizerDiscardEnable = true;
4550 rs_ci.lineWidth = 1.0f;
4551
4552 VkPipelineColorBlendAttachmentState att = {};
4553 att.blendEnable = VK_FALSE;
4554 att.colorWriteMask = 0xf;
4555
4556 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4557 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4558 cb_ci.attachmentCount = 1;
4559 cb_ci.pAttachments = &att;
4560
4561 VkGraphicsPipelineCreateInfo gp_ci = {};
4562 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4563 gp_ci.stageCount = 2;
4564 gp_ci.pStages = shaderStages;
4565 gp_ci.pVertexInputState = &vi_ci;
4566 gp_ci.pInputAssemblyState = &ia_ci;
4567 gp_ci.pViewportState = &vp_state_ci;
4568 gp_ci.pRasterizationState = &rs_ci;
4569 gp_ci.pColorBlendState = &cb_ci;
4570 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4571 gp_ci.layout = pipeline_layout;
4572 gp_ci.renderPass = rp;
4573
4574 VkPipelineCacheCreateInfo pc_ci = {};
4575 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4576
4577 VkPipeline pipeline;
4578 VkPipelineCache pipe_cache;
4579 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4580 ASSERT_VK_SUCCESS(err);
4581
4582 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4583 ASSERT_VK_SUCCESS(err);
4584 // Bind pipeline to cmd buffer, will also bind renderpass
4585 m_commandBuffer->BeginCommandBuffer();
4586 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4587 m_commandBuffer->EndCommandBuffer();
4588
4589 VkSubmitInfo submit_info = {};
4590 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4591 submit_info.commandBufferCount = 1;
4592 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4593 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4594
4595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4596 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4597 m_errorMonitor->VerifyFound();
4598
4599 // Wait for queue to complete so we can safely destroy everything
4600 vkQueueWaitIdle(m_device->m_queue);
4601 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4602 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4603 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4604 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4605}
4606
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004607TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004608 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004609 ASSERT_NO_FATAL_FAILURE(InitState());
4610
4611 VkImage image;
4612 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4613 VkImageCreateInfo image_create_info = {};
4614 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4615 image_create_info.pNext = NULL;
4616 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4617 image_create_info.format = tex_format;
4618 image_create_info.extent.width = 32;
4619 image_create_info.extent.height = 32;
4620 image_create_info.extent.depth = 1;
4621 image_create_info.mipLevels = 1;
4622 image_create_info.arrayLayers = 1;
4623 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4624 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004625 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004626 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004627 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004628 ASSERT_VK_SUCCESS(err);
4629 // Have to bind memory to image before recording cmd in cmd buffer using it
4630 VkMemoryRequirements mem_reqs;
4631 VkDeviceMemory image_mem;
4632 bool pass;
4633 VkMemoryAllocateInfo mem_alloc = {};
4634 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4635 mem_alloc.pNext = NULL;
4636 mem_alloc.memoryTypeIndex = 0;
4637 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4638 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004639 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004640 ASSERT_TRUE(pass);
4641 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4642 ASSERT_VK_SUCCESS(err);
4643
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004644 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004646 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004647
4648 m_commandBuffer->BeginCommandBuffer();
4649 VkClearColorValue ccv;
4650 ccv.float32[0] = 1.0f;
4651 ccv.float32[1] = 1.0f;
4652 ccv.float32[2] = 1.0f;
4653 ccv.float32[3] = 1.0f;
4654 VkImageSubresourceRange isr = {};
4655 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4656 isr.baseArrayLayer = 0;
4657 isr.baseMipLevel = 0;
4658 isr.layerCount = 1;
4659 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004660 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004661 m_commandBuffer->EndCommandBuffer();
4662
4663 m_errorMonitor->VerifyFound();
4664 vkDestroyImage(m_device->device(), image, NULL);
4665 vkFreeMemory(m_device->device(), image_mem, nullptr);
4666}
4667
4668TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004669 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004670 ASSERT_NO_FATAL_FAILURE(InitState());
4671
4672 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004673 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004674 VK_IMAGE_TILING_OPTIMAL, 0);
4675 ASSERT_TRUE(image.initialized());
4676
4677 VkBuffer buffer;
4678 VkDeviceMemory mem;
4679 VkMemoryRequirements mem_reqs;
4680
4681 VkBufferCreateInfo buf_info = {};
4682 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004683 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004684 buf_info.size = 256;
4685 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4686 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4687 ASSERT_VK_SUCCESS(err);
4688
4689 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4690
4691 VkMemoryAllocateInfo alloc_info = {};
4692 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4693 alloc_info.allocationSize = 256;
4694 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004695 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004696 if (!pass) {
4697 vkDestroyBuffer(m_device->device(), buffer, NULL);
4698 return;
4699 }
4700 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4701 ASSERT_VK_SUCCESS(err);
4702
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004703 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004705 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004706 VkBufferImageCopy region = {};
4707 region.bufferRowLength = 128;
4708 region.bufferImageHeight = 128;
4709 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4710
4711 region.imageSubresource.layerCount = 1;
4712 region.imageExtent.height = 4;
4713 region.imageExtent.width = 4;
4714 region.imageExtent.depth = 1;
4715 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004716 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4717 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004718 m_commandBuffer->EndCommandBuffer();
4719
4720 m_errorMonitor->VerifyFound();
4721
4722 vkDestroyBuffer(m_device->device(), buffer, NULL);
4723 vkFreeMemory(m_device->handle(), mem, NULL);
4724}
4725
Tobin Ehlis85940f52016-07-07 16:57:21 -06004726TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4727 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4728 "due to an event dependency being destroyed.");
4729 ASSERT_NO_FATAL_FAILURE(InitState());
4730
4731 VkEvent event;
4732 VkEventCreateInfo evci = {};
4733 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4734 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4735 ASSERT_VK_SUCCESS(result);
4736
4737 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004738 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004739 m_commandBuffer->EndCommandBuffer();
4740
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004742 // Destroy event dependency prior to submit to cause ERROR
4743 vkDestroyEvent(m_device->device(), event, NULL);
4744
4745 VkSubmitInfo submit_info = {};
4746 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4747 submit_info.commandBufferCount = 1;
4748 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4749 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4750
4751 m_errorMonitor->VerifyFound();
4752}
4753
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004754TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4755 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4756 "due to a query pool dependency being destroyed.");
4757 ASSERT_NO_FATAL_FAILURE(InitState());
4758
4759 VkQueryPool query_pool;
4760 VkQueryPoolCreateInfo qpci{};
4761 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4762 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4763 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004764 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004765 ASSERT_VK_SUCCESS(result);
4766
4767 m_commandBuffer->BeginCommandBuffer();
4768 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4769 m_commandBuffer->EndCommandBuffer();
4770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004772 // Destroy query pool dependency prior to submit to cause ERROR
4773 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4774
4775 VkSubmitInfo submit_info = {};
4776 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4777 submit_info.commandBufferCount = 1;
4778 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4779 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4780
4781 m_errorMonitor->VerifyFound();
4782}
4783
Tobin Ehlis24130d92016-07-08 15:50:53 -06004784TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4785 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4786 "due to a pipeline dependency being destroyed.");
4787 ASSERT_NO_FATAL_FAILURE(InitState());
4788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4789
4790 VkResult err;
4791
4792 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4793 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4794
4795 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004796 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004797 ASSERT_VK_SUCCESS(err);
4798
4799 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4800 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4801 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004802 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004803 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004804 vp_state_ci.scissorCount = 1;
4805 VkRect2D scissors = {}; // Dummy scissors to point to
4806 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004807
4808 VkPipelineShaderStageCreateInfo shaderStages[2];
4809 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4810
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004811 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4812 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4813 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004814 shaderStages[0] = vs.GetStageCreateInfo();
4815 shaderStages[1] = fs.GetStageCreateInfo();
4816
4817 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4818 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4819
4820 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4821 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4822 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4823
4824 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4825 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004826 rs_ci.rasterizerDiscardEnable = true;
4827 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004828
4829 VkPipelineColorBlendAttachmentState att = {};
4830 att.blendEnable = VK_FALSE;
4831 att.colorWriteMask = 0xf;
4832
4833 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4834 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4835 cb_ci.attachmentCount = 1;
4836 cb_ci.pAttachments = &att;
4837
4838 VkGraphicsPipelineCreateInfo gp_ci = {};
4839 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4840 gp_ci.stageCount = 2;
4841 gp_ci.pStages = shaderStages;
4842 gp_ci.pVertexInputState = &vi_ci;
4843 gp_ci.pInputAssemblyState = &ia_ci;
4844 gp_ci.pViewportState = &vp_state_ci;
4845 gp_ci.pRasterizationState = &rs_ci;
4846 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004847 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4848 gp_ci.layout = pipeline_layout;
4849 gp_ci.renderPass = renderPass();
4850
4851 VkPipelineCacheCreateInfo pc_ci = {};
4852 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4853
4854 VkPipeline pipeline;
4855 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004856 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004857 ASSERT_VK_SUCCESS(err);
4858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004859 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004860 ASSERT_VK_SUCCESS(err);
4861
4862 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004863 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004864 m_commandBuffer->EndCommandBuffer();
4865 // Now destroy pipeline in order to cause error when submitting
4866 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4867
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004869
4870 VkSubmitInfo submit_info = {};
4871 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4872 submit_info.commandBufferCount = 1;
4873 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4874 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4875
4876 m_errorMonitor->VerifyFound();
4877 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4878 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4879}
4880
Tobin Ehlis31289162016-08-17 14:57:58 -06004881TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4882 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4883 "due to a bound descriptor set with a buffer dependency "
4884 "being destroyed.");
4885 ASSERT_NO_FATAL_FAILURE(InitState());
4886 ASSERT_NO_FATAL_FAILURE(InitViewport());
4887 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4888
4889 VkDescriptorPoolSize ds_type_count = {};
4890 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4891 ds_type_count.descriptorCount = 1;
4892
4893 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4894 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4895 ds_pool_ci.pNext = NULL;
4896 ds_pool_ci.maxSets = 1;
4897 ds_pool_ci.poolSizeCount = 1;
4898 ds_pool_ci.pPoolSizes = &ds_type_count;
4899
4900 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004901 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004902 ASSERT_VK_SUCCESS(err);
4903
4904 VkDescriptorSetLayoutBinding dsl_binding = {};
4905 dsl_binding.binding = 0;
4906 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4907 dsl_binding.descriptorCount = 1;
4908 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4909 dsl_binding.pImmutableSamplers = NULL;
4910
4911 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4912 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4913 ds_layout_ci.pNext = NULL;
4914 ds_layout_ci.bindingCount = 1;
4915 ds_layout_ci.pBindings = &dsl_binding;
4916 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004917 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004918 ASSERT_VK_SUCCESS(err);
4919
4920 VkDescriptorSet descriptorSet;
4921 VkDescriptorSetAllocateInfo alloc_info = {};
4922 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4923 alloc_info.descriptorSetCount = 1;
4924 alloc_info.descriptorPool = ds_pool;
4925 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004926 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004927 ASSERT_VK_SUCCESS(err);
4928
4929 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4930 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4931 pipeline_layout_ci.pNext = NULL;
4932 pipeline_layout_ci.setLayoutCount = 1;
4933 pipeline_layout_ci.pSetLayouts = &ds_layout;
4934
4935 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004936 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004937 ASSERT_VK_SUCCESS(err);
4938
4939 // Create a buffer to update the descriptor with
4940 uint32_t qfi = 0;
4941 VkBufferCreateInfo buffCI = {};
4942 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4943 buffCI.size = 1024;
4944 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4945 buffCI.queueFamilyIndexCount = 1;
4946 buffCI.pQueueFamilyIndices = &qfi;
4947
4948 VkBuffer buffer;
4949 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4950 ASSERT_VK_SUCCESS(err);
4951 // Allocate memory and bind to buffer so we can make it to the appropriate
4952 // error
4953 VkMemoryAllocateInfo mem_alloc = {};
4954 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4955 mem_alloc.pNext = NULL;
4956 mem_alloc.allocationSize = 1024;
4957 mem_alloc.memoryTypeIndex = 0;
4958
4959 VkMemoryRequirements memReqs;
4960 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004961 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004962 if (!pass) {
4963 vkDestroyBuffer(m_device->device(), buffer, NULL);
4964 return;
4965 }
4966
4967 VkDeviceMemory mem;
4968 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4969 ASSERT_VK_SUCCESS(err);
4970 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4971 ASSERT_VK_SUCCESS(err);
4972 // Correctly update descriptor to avoid "NOT_UPDATED" error
4973 VkDescriptorBufferInfo buffInfo = {};
4974 buffInfo.buffer = buffer;
4975 buffInfo.offset = 0;
4976 buffInfo.range = 1024;
4977
4978 VkWriteDescriptorSet descriptor_write;
4979 memset(&descriptor_write, 0, sizeof(descriptor_write));
4980 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4981 descriptor_write.dstSet = descriptorSet;
4982 descriptor_write.dstBinding = 0;
4983 descriptor_write.descriptorCount = 1;
4984 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4985 descriptor_write.pBufferInfo = &buffInfo;
4986
4987 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4988
4989 // Create PSO to be used for draw-time errors below
4990 char const *vsSource = "#version 450\n"
4991 "\n"
4992 "out gl_PerVertex { \n"
4993 " vec4 gl_Position;\n"
4994 "};\n"
4995 "void main(){\n"
4996 " gl_Position = vec4(1);\n"
4997 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004998 char const *fsSource = "#version 450\n"
4999 "\n"
5000 "layout(location=0) out vec4 x;\n"
5001 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5002 "void main(){\n"
5003 " x = vec4(bar.y);\n"
5004 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005005 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5006 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5007 VkPipelineObj pipe(m_device);
5008 pipe.AddShader(&vs);
5009 pipe.AddShader(&fs);
5010 pipe.AddColorAttachment();
5011 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5012
5013 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005014 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5015 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5016 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005017 Draw(1, 0, 0, 0);
5018 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005020 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5021 vkDestroyBuffer(m_device->device(), buffer, NULL);
5022 // Attempt to submit cmd buffer
5023 VkSubmitInfo submit_info = {};
5024 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5025 submit_info.commandBufferCount = 1;
5026 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5027 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5028 m_errorMonitor->VerifyFound();
5029 // Cleanup
5030 vkFreeMemory(m_device->device(), mem, NULL);
5031
5032 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5033 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5034 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5035}
5036
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005037TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5038 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5039 "due to a bound descriptor sets with a combined image "
5040 "sampler having their image, sampler, and descriptor set "
5041 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005042 "submit associated cmd buffers. Attempt to destroy a "
5043 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005044 ASSERT_NO_FATAL_FAILURE(InitState());
5045 ASSERT_NO_FATAL_FAILURE(InitViewport());
5046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5047
5048 VkDescriptorPoolSize ds_type_count = {};
5049 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5050 ds_type_count.descriptorCount = 1;
5051
5052 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5053 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5054 ds_pool_ci.pNext = NULL;
5055 ds_pool_ci.maxSets = 1;
5056 ds_pool_ci.poolSizeCount = 1;
5057 ds_pool_ci.pPoolSizes = &ds_type_count;
5058
5059 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005060 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005061 ASSERT_VK_SUCCESS(err);
5062
5063 VkDescriptorSetLayoutBinding dsl_binding = {};
5064 dsl_binding.binding = 0;
5065 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5066 dsl_binding.descriptorCount = 1;
5067 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5068 dsl_binding.pImmutableSamplers = NULL;
5069
5070 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5071 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5072 ds_layout_ci.pNext = NULL;
5073 ds_layout_ci.bindingCount = 1;
5074 ds_layout_ci.pBindings = &dsl_binding;
5075 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005076 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005077 ASSERT_VK_SUCCESS(err);
5078
5079 VkDescriptorSet descriptorSet;
5080 VkDescriptorSetAllocateInfo alloc_info = {};
5081 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5082 alloc_info.descriptorSetCount = 1;
5083 alloc_info.descriptorPool = ds_pool;
5084 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005085 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005086 ASSERT_VK_SUCCESS(err);
5087
5088 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5089 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5090 pipeline_layout_ci.pNext = NULL;
5091 pipeline_layout_ci.setLayoutCount = 1;
5092 pipeline_layout_ci.pSetLayouts = &ds_layout;
5093
5094 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005095 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005096 ASSERT_VK_SUCCESS(err);
5097
5098 // Create images to update the descriptor with
5099 VkImage image;
5100 VkImage image2;
5101 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5102 const int32_t tex_width = 32;
5103 const int32_t tex_height = 32;
5104 VkImageCreateInfo image_create_info = {};
5105 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5106 image_create_info.pNext = NULL;
5107 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5108 image_create_info.format = tex_format;
5109 image_create_info.extent.width = tex_width;
5110 image_create_info.extent.height = tex_height;
5111 image_create_info.extent.depth = 1;
5112 image_create_info.mipLevels = 1;
5113 image_create_info.arrayLayers = 1;
5114 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5115 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5116 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5117 image_create_info.flags = 0;
5118 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5119 ASSERT_VK_SUCCESS(err);
5120 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5121 ASSERT_VK_SUCCESS(err);
5122
5123 VkMemoryRequirements memory_reqs;
5124 VkDeviceMemory image_memory;
5125 bool pass;
5126 VkMemoryAllocateInfo memory_info = {};
5127 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5128 memory_info.pNext = NULL;
5129 memory_info.allocationSize = 0;
5130 memory_info.memoryTypeIndex = 0;
5131 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5132 // Allocate enough memory for both images
5133 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005134 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005135 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005136 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005137 ASSERT_VK_SUCCESS(err);
5138 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5139 ASSERT_VK_SUCCESS(err);
5140 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005141 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005142 ASSERT_VK_SUCCESS(err);
5143
5144 VkImageViewCreateInfo image_view_create_info = {};
5145 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5146 image_view_create_info.image = image;
5147 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5148 image_view_create_info.format = tex_format;
5149 image_view_create_info.subresourceRange.layerCount = 1;
5150 image_view_create_info.subresourceRange.baseMipLevel = 0;
5151 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005152 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005153
5154 VkImageView view;
5155 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005156 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005157 ASSERT_VK_SUCCESS(err);
5158 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005159 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005160 ASSERT_VK_SUCCESS(err);
5161 // Create Samplers
5162 VkSamplerCreateInfo sampler_ci = {};
5163 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5164 sampler_ci.pNext = NULL;
5165 sampler_ci.magFilter = VK_FILTER_NEAREST;
5166 sampler_ci.minFilter = VK_FILTER_NEAREST;
5167 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5168 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5169 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5170 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5171 sampler_ci.mipLodBias = 1.0;
5172 sampler_ci.anisotropyEnable = VK_FALSE;
5173 sampler_ci.maxAnisotropy = 1;
5174 sampler_ci.compareEnable = VK_FALSE;
5175 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5176 sampler_ci.minLod = 1.0;
5177 sampler_ci.maxLod = 1.0;
5178 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5179 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5180 VkSampler sampler;
5181 VkSampler sampler2;
5182 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5183 ASSERT_VK_SUCCESS(err);
5184 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5185 ASSERT_VK_SUCCESS(err);
5186 // Update descriptor with image and sampler
5187 VkDescriptorImageInfo img_info = {};
5188 img_info.sampler = sampler;
5189 img_info.imageView = view;
5190 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5191
5192 VkWriteDescriptorSet descriptor_write;
5193 memset(&descriptor_write, 0, sizeof(descriptor_write));
5194 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5195 descriptor_write.dstSet = descriptorSet;
5196 descriptor_write.dstBinding = 0;
5197 descriptor_write.descriptorCount = 1;
5198 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5199 descriptor_write.pImageInfo = &img_info;
5200
5201 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5202
5203 // Create PSO to be used for draw-time errors below
5204 char const *vsSource = "#version 450\n"
5205 "\n"
5206 "out gl_PerVertex { \n"
5207 " vec4 gl_Position;\n"
5208 "};\n"
5209 "void main(){\n"
5210 " gl_Position = vec4(1);\n"
5211 "}\n";
5212 char const *fsSource = "#version 450\n"
5213 "\n"
5214 "layout(set=0, binding=0) uniform sampler2D s;\n"
5215 "layout(location=0) out vec4 x;\n"
5216 "void main(){\n"
5217 " x = texture(s, vec2(1));\n"
5218 "}\n";
5219 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5220 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5221 VkPipelineObj pipe(m_device);
5222 pipe.AddShader(&vs);
5223 pipe.AddShader(&fs);
5224 pipe.AddColorAttachment();
5225 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5226
5227 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005229 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005230 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5231 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5232 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005233 Draw(1, 0, 0, 0);
5234 EndCommandBuffer();
5235 // Destroy sampler invalidates the cmd buffer, causing error on submit
5236 vkDestroySampler(m_device->device(), sampler, NULL);
5237 // Attempt to submit cmd buffer
5238 VkSubmitInfo submit_info = {};
5239 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5240 submit_info.commandBufferCount = 1;
5241 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5242 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5243 m_errorMonitor->VerifyFound();
5244 // Now re-update descriptor with valid sampler and delete image
5245 img_info.sampler = sampler2;
5246 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005248 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005249 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5250 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5251 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005252 Draw(1, 0, 0, 0);
5253 EndCommandBuffer();
5254 // Destroy image invalidates the cmd buffer, causing error on submit
5255 vkDestroyImage(m_device->device(), image, NULL);
5256 // Attempt to submit cmd buffer
5257 submit_info = {};
5258 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5259 submit_info.commandBufferCount = 1;
5260 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5261 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5262 m_errorMonitor->VerifyFound();
5263 // Now update descriptor to be valid, but then free descriptor
5264 img_info.imageView = view2;
5265 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005267 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005268 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5269 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5270 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005271 Draw(1, 0, 0, 0);
5272 EndCommandBuffer();
5273 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005275 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005276 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005277 // Attempt to submit cmd buffer
5278 submit_info = {};
5279 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5280 submit_info.commandBufferCount = 1;
5281 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5282 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5283 m_errorMonitor->VerifyFound();
5284 // Cleanup
5285 vkFreeMemory(m_device->device(), image_memory, NULL);
5286 vkDestroySampler(m_device->device(), sampler2, NULL);
5287 vkDestroyImage(m_device->device(), image2, NULL);
5288 vkDestroyImageView(m_device->device(), view, NULL);
5289 vkDestroyImageView(m_device->device(), view2, NULL);
5290 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5291 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5292 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5293}
5294
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005295TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5296 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5297 ASSERT_NO_FATAL_FAILURE(InitState());
5298 ASSERT_NO_FATAL_FAILURE(InitViewport());
5299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5300
5301 VkDescriptorPoolSize ds_type_count = {};
5302 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5303 ds_type_count.descriptorCount = 1;
5304
5305 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5306 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5307 ds_pool_ci.pNext = NULL;
5308 ds_pool_ci.maxSets = 1;
5309 ds_pool_ci.poolSizeCount = 1;
5310 ds_pool_ci.pPoolSizes = &ds_type_count;
5311
5312 VkDescriptorPool ds_pool;
5313 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5314 ASSERT_VK_SUCCESS(err);
5315
5316 VkDescriptorSetLayoutBinding dsl_binding = {};
5317 dsl_binding.binding = 0;
5318 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5319 dsl_binding.descriptorCount = 1;
5320 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5321 dsl_binding.pImmutableSamplers = NULL;
5322
5323 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5324 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5325 ds_layout_ci.pNext = NULL;
5326 ds_layout_ci.bindingCount = 1;
5327 ds_layout_ci.pBindings = &dsl_binding;
5328 VkDescriptorSetLayout ds_layout;
5329 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5330 ASSERT_VK_SUCCESS(err);
5331
5332 VkDescriptorSet descriptor_set;
5333 VkDescriptorSetAllocateInfo alloc_info = {};
5334 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5335 alloc_info.descriptorSetCount = 1;
5336 alloc_info.descriptorPool = ds_pool;
5337 alloc_info.pSetLayouts = &ds_layout;
5338 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5339 ASSERT_VK_SUCCESS(err);
5340
5341 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5342 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5343 pipeline_layout_ci.pNext = NULL;
5344 pipeline_layout_ci.setLayoutCount = 1;
5345 pipeline_layout_ci.pSetLayouts = &ds_layout;
5346
5347 VkPipelineLayout pipeline_layout;
5348 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5349 ASSERT_VK_SUCCESS(err);
5350
5351 // Create image to update the descriptor with
5352 VkImageObj image(m_device);
5353 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5354 ASSERT_TRUE(image.initialized());
5355
5356 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5357 // Create Sampler
5358 VkSamplerCreateInfo sampler_ci = {};
5359 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5360 sampler_ci.pNext = NULL;
5361 sampler_ci.magFilter = VK_FILTER_NEAREST;
5362 sampler_ci.minFilter = VK_FILTER_NEAREST;
5363 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5364 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5365 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5366 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5367 sampler_ci.mipLodBias = 1.0;
5368 sampler_ci.anisotropyEnable = VK_FALSE;
5369 sampler_ci.maxAnisotropy = 1;
5370 sampler_ci.compareEnable = VK_FALSE;
5371 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5372 sampler_ci.minLod = 1.0;
5373 sampler_ci.maxLod = 1.0;
5374 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5375 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5376 VkSampler sampler;
5377 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5378 ASSERT_VK_SUCCESS(err);
5379 // Update descriptor with image and sampler
5380 VkDescriptorImageInfo img_info = {};
5381 img_info.sampler = sampler;
5382 img_info.imageView = view;
5383 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5384
5385 VkWriteDescriptorSet descriptor_write;
5386 memset(&descriptor_write, 0, sizeof(descriptor_write));
5387 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5388 descriptor_write.dstSet = descriptor_set;
5389 descriptor_write.dstBinding = 0;
5390 descriptor_write.descriptorCount = 1;
5391 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5392 descriptor_write.pImageInfo = &img_info;
5393
5394 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5395
5396 // Create PSO to be used for draw-time errors below
5397 char const *vsSource = "#version 450\n"
5398 "\n"
5399 "out gl_PerVertex { \n"
5400 " vec4 gl_Position;\n"
5401 "};\n"
5402 "void main(){\n"
5403 " gl_Position = vec4(1);\n"
5404 "}\n";
5405 char const *fsSource = "#version 450\n"
5406 "\n"
5407 "layout(set=0, binding=0) uniform sampler2D s;\n"
5408 "layout(location=0) out vec4 x;\n"
5409 "void main(){\n"
5410 " x = texture(s, vec2(1));\n"
5411 "}\n";
5412 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5413 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5414 VkPipelineObj pipe(m_device);
5415 pipe.AddShader(&vs);
5416 pipe.AddShader(&fs);
5417 pipe.AddColorAttachment();
5418 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5419
5420 BeginCommandBuffer();
5421 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5422 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5423 &descriptor_set, 0, NULL);
5424 Draw(1, 0, 0, 0);
5425 EndCommandBuffer();
5426 // Submit cmd buffer to put pool in-flight
5427 VkSubmitInfo submit_info = {};
5428 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5429 submit_info.commandBufferCount = 1;
5430 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5431 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5432 // Destroy pool while in-flight, causing error
5433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5434 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5435 m_errorMonitor->VerifyFound();
5436 vkQueueWaitIdle(m_device->m_queue);
5437 // Cleanup
5438 vkDestroySampler(m_device->device(), sampler, NULL);
5439 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5440 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5441 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5442}
5443
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005444TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5445 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5446 ASSERT_NO_FATAL_FAILURE(InitState());
5447 ASSERT_NO_FATAL_FAILURE(InitViewport());
5448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5449
5450 VkDescriptorPoolSize ds_type_count = {};
5451 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5452 ds_type_count.descriptorCount = 1;
5453
5454 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5455 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5456 ds_pool_ci.pNext = NULL;
5457 ds_pool_ci.maxSets = 1;
5458 ds_pool_ci.poolSizeCount = 1;
5459 ds_pool_ci.pPoolSizes = &ds_type_count;
5460
5461 VkDescriptorPool ds_pool;
5462 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5463 ASSERT_VK_SUCCESS(err);
5464
5465 VkDescriptorSetLayoutBinding dsl_binding = {};
5466 dsl_binding.binding = 0;
5467 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5468 dsl_binding.descriptorCount = 1;
5469 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5470 dsl_binding.pImmutableSamplers = NULL;
5471
5472 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5473 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5474 ds_layout_ci.pNext = NULL;
5475 ds_layout_ci.bindingCount = 1;
5476 ds_layout_ci.pBindings = &dsl_binding;
5477 VkDescriptorSetLayout ds_layout;
5478 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5479 ASSERT_VK_SUCCESS(err);
5480
5481 VkDescriptorSet descriptorSet;
5482 VkDescriptorSetAllocateInfo alloc_info = {};
5483 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5484 alloc_info.descriptorSetCount = 1;
5485 alloc_info.descriptorPool = ds_pool;
5486 alloc_info.pSetLayouts = &ds_layout;
5487 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5488 ASSERT_VK_SUCCESS(err);
5489
5490 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5491 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5492 pipeline_layout_ci.pNext = NULL;
5493 pipeline_layout_ci.setLayoutCount = 1;
5494 pipeline_layout_ci.pSetLayouts = &ds_layout;
5495
5496 VkPipelineLayout pipeline_layout;
5497 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5498 ASSERT_VK_SUCCESS(err);
5499
5500 // Create images to update the descriptor with
5501 VkImage image;
5502 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5503 const int32_t tex_width = 32;
5504 const int32_t tex_height = 32;
5505 VkImageCreateInfo image_create_info = {};
5506 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5507 image_create_info.pNext = NULL;
5508 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5509 image_create_info.format = tex_format;
5510 image_create_info.extent.width = tex_width;
5511 image_create_info.extent.height = tex_height;
5512 image_create_info.extent.depth = 1;
5513 image_create_info.mipLevels = 1;
5514 image_create_info.arrayLayers = 1;
5515 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5516 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5517 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5518 image_create_info.flags = 0;
5519 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5520 ASSERT_VK_SUCCESS(err);
5521 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5522 VkMemoryRequirements memory_reqs;
5523 VkDeviceMemory image_memory;
5524 bool pass;
5525 VkMemoryAllocateInfo memory_info = {};
5526 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5527 memory_info.pNext = NULL;
5528 memory_info.allocationSize = 0;
5529 memory_info.memoryTypeIndex = 0;
5530 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5531 // Allocate enough memory for image
5532 memory_info.allocationSize = memory_reqs.size;
5533 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5534 ASSERT_TRUE(pass);
5535 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5536 ASSERT_VK_SUCCESS(err);
5537 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5538 ASSERT_VK_SUCCESS(err);
5539
5540 VkImageViewCreateInfo image_view_create_info = {};
5541 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5542 image_view_create_info.image = image;
5543 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5544 image_view_create_info.format = tex_format;
5545 image_view_create_info.subresourceRange.layerCount = 1;
5546 image_view_create_info.subresourceRange.baseMipLevel = 0;
5547 image_view_create_info.subresourceRange.levelCount = 1;
5548 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5549
5550 VkImageView view;
5551 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5552 ASSERT_VK_SUCCESS(err);
5553 // Create Samplers
5554 VkSamplerCreateInfo sampler_ci = {};
5555 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5556 sampler_ci.pNext = NULL;
5557 sampler_ci.magFilter = VK_FILTER_NEAREST;
5558 sampler_ci.minFilter = VK_FILTER_NEAREST;
5559 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5560 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5561 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5562 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5563 sampler_ci.mipLodBias = 1.0;
5564 sampler_ci.anisotropyEnable = VK_FALSE;
5565 sampler_ci.maxAnisotropy = 1;
5566 sampler_ci.compareEnable = VK_FALSE;
5567 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5568 sampler_ci.minLod = 1.0;
5569 sampler_ci.maxLod = 1.0;
5570 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5571 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5572 VkSampler sampler;
5573 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5574 ASSERT_VK_SUCCESS(err);
5575 // Update descriptor with image and sampler
5576 VkDescriptorImageInfo img_info = {};
5577 img_info.sampler = sampler;
5578 img_info.imageView = view;
5579 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5580
5581 VkWriteDescriptorSet descriptor_write;
5582 memset(&descriptor_write, 0, sizeof(descriptor_write));
5583 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5584 descriptor_write.dstSet = descriptorSet;
5585 descriptor_write.dstBinding = 0;
5586 descriptor_write.descriptorCount = 1;
5587 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5588 descriptor_write.pImageInfo = &img_info;
5589 // Break memory binding and attempt update
5590 vkFreeMemory(m_device->device(), image_memory, nullptr);
5591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005592 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5594 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5595 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5596 m_errorMonitor->VerifyFound();
5597 // Cleanup
5598 vkDestroyImage(m_device->device(), image, NULL);
5599 vkDestroySampler(m_device->device(), sampler, NULL);
5600 vkDestroyImageView(m_device->device(), view, NULL);
5601 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5602 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5603 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5604}
5605
Karl Schultz6addd812016-02-02 17:17:23 -07005606TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005607 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5608 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005609 // Create a valid cmd buffer
5610 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005611 uint64_t fake_pipeline_handle = 0xbaad6001;
5612 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005613 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5615
5616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005617 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005618 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005619 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005620
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005621 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005623 Draw(1, 0, 0, 0);
5624 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005625
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005626 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005628 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005629 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5630 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005631}
5632
Karl Schultz6addd812016-02-02 17:17:23 -07005633TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005634 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005635 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005636
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005638
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005639 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005640 ASSERT_NO_FATAL_FAILURE(InitViewport());
5641 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005642 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005643 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5644 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005645
5646 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005647 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5648 ds_pool_ci.pNext = NULL;
5649 ds_pool_ci.maxSets = 1;
5650 ds_pool_ci.poolSizeCount = 1;
5651 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005652
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005653 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005654 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005655 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005656
Tony Barboureb254902015-07-15 12:50:33 -06005657 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005658 dsl_binding.binding = 0;
5659 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5660 dsl_binding.descriptorCount = 1;
5661 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5662 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005663
Tony Barboureb254902015-07-15 12:50:33 -06005664 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005665 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5666 ds_layout_ci.pNext = NULL;
5667 ds_layout_ci.bindingCount = 1;
5668 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005669 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005670 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005671 ASSERT_VK_SUCCESS(err);
5672
5673 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005674 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005675 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005676 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005677 alloc_info.descriptorPool = ds_pool;
5678 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005679 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005680 ASSERT_VK_SUCCESS(err);
5681
Tony Barboureb254902015-07-15 12:50:33 -06005682 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005683 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5684 pipeline_layout_ci.pNext = NULL;
5685 pipeline_layout_ci.setLayoutCount = 1;
5686 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005687
5688 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005689 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005690 ASSERT_VK_SUCCESS(err);
5691
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005692 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005693 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005694 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005695 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005696
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005697 VkPipelineObj pipe(m_device);
5698 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005699 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005700 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005701 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005702
5703 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005704 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5705 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5706 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005707
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005708 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005709
Chia-I Wuf7458c52015-10-26 21:10:41 +08005710 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5711 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5712 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005713}
5714
Karl Schultz6addd812016-02-02 17:17:23 -07005715TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005716 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005717 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5720 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005721
5722 ASSERT_NO_FATAL_FAILURE(InitState());
5723 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005724 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5725 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005726
5727 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005728 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5729 ds_pool_ci.pNext = NULL;
5730 ds_pool_ci.maxSets = 1;
5731 ds_pool_ci.poolSizeCount = 1;
5732 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005733
5734 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005735 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005736 ASSERT_VK_SUCCESS(err);
5737
5738 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005739 dsl_binding.binding = 0;
5740 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5741 dsl_binding.descriptorCount = 1;
5742 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5743 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005744
5745 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005746 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5747 ds_layout_ci.pNext = NULL;
5748 ds_layout_ci.bindingCount = 1;
5749 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005750 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005751 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005752 ASSERT_VK_SUCCESS(err);
5753
5754 VkDescriptorSet descriptorSet;
5755 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005756 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005757 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005758 alloc_info.descriptorPool = ds_pool;
5759 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005760 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005761 ASSERT_VK_SUCCESS(err);
5762
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005763 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005764 VkWriteDescriptorSet descriptor_write;
5765 memset(&descriptor_write, 0, sizeof(descriptor_write));
5766 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5767 descriptor_write.dstSet = descriptorSet;
5768 descriptor_write.dstBinding = 0;
5769 descriptor_write.descriptorCount = 1;
5770 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5771 descriptor_write.pTexelBufferView = &view;
5772
5773 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5774
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005775 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005776
5777 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5778 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5779}
5780
Mark Youngd339ba32016-05-30 13:28:35 -06005781TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005782 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has no memory bound to it.");
Mark Youngd339ba32016-05-30 13:28:35 -06005783
5784 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005786 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005787
5788 ASSERT_NO_FATAL_FAILURE(InitState());
5789
5790 // Create a buffer with no bound memory and then attempt to create
5791 // a buffer view.
5792 VkBufferCreateInfo buff_ci = {};
5793 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005794 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005795 buff_ci.size = 256;
5796 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5797 VkBuffer buffer;
5798 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5799 ASSERT_VK_SUCCESS(err);
5800
5801 VkBufferViewCreateInfo buff_view_ci = {};
5802 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5803 buff_view_ci.buffer = buffer;
5804 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5805 buff_view_ci.range = VK_WHOLE_SIZE;
5806 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005807 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005808
5809 m_errorMonitor->VerifyFound();
5810 vkDestroyBuffer(m_device->device(), buffer, NULL);
5811 // If last error is success, it still created the view, so delete it.
5812 if (err == VK_SUCCESS) {
5813 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5814 }
5815}
5816
Karl Schultz6addd812016-02-02 17:17:23 -07005817TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5818 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5819 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005820 // 1. No dynamicOffset supplied
5821 // 2. Too many dynamicOffsets supplied
5822 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005823 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5825 "0 dynamicOffsets are left in "
5826 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005827
5828 ASSERT_NO_FATAL_FAILURE(InitState());
5829 ASSERT_NO_FATAL_FAILURE(InitViewport());
5830 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5831
5832 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005833 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5834 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005835
5836 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005837 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5838 ds_pool_ci.pNext = NULL;
5839 ds_pool_ci.maxSets = 1;
5840 ds_pool_ci.poolSizeCount = 1;
5841 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005842
5843 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005844 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005845 ASSERT_VK_SUCCESS(err);
5846
5847 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005848 dsl_binding.binding = 0;
5849 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5850 dsl_binding.descriptorCount = 1;
5851 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5852 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005853
5854 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005855 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5856 ds_layout_ci.pNext = NULL;
5857 ds_layout_ci.bindingCount = 1;
5858 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005859 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005860 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005861 ASSERT_VK_SUCCESS(err);
5862
5863 VkDescriptorSet descriptorSet;
5864 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005865 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005866 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005867 alloc_info.descriptorPool = ds_pool;
5868 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005869 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005870 ASSERT_VK_SUCCESS(err);
5871
5872 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005873 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5874 pipeline_layout_ci.pNext = NULL;
5875 pipeline_layout_ci.setLayoutCount = 1;
5876 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005877
5878 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005879 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005880 ASSERT_VK_SUCCESS(err);
5881
5882 // Create a buffer to update the descriptor with
5883 uint32_t qfi = 0;
5884 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005885 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5886 buffCI.size = 1024;
5887 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5888 buffCI.queueFamilyIndexCount = 1;
5889 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005890
5891 VkBuffer dyub;
5892 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5893 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005894 // Allocate memory and bind to buffer so we can make it to the appropriate
5895 // error
5896 VkMemoryAllocateInfo mem_alloc = {};
5897 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5898 mem_alloc.pNext = NULL;
5899 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005900 mem_alloc.memoryTypeIndex = 0;
5901
5902 VkMemoryRequirements memReqs;
5903 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005904 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005905 if (!pass) {
5906 vkDestroyBuffer(m_device->device(), dyub, NULL);
5907 return;
5908 }
5909
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005910 VkDeviceMemory mem;
5911 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5912 ASSERT_VK_SUCCESS(err);
5913 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5914 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005915 // Correctly update descriptor to avoid "NOT_UPDATED" error
5916 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005917 buffInfo.buffer = dyub;
5918 buffInfo.offset = 0;
5919 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005920
5921 VkWriteDescriptorSet descriptor_write;
5922 memset(&descriptor_write, 0, sizeof(descriptor_write));
5923 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5924 descriptor_write.dstSet = descriptorSet;
5925 descriptor_write.dstBinding = 0;
5926 descriptor_write.descriptorCount = 1;
5927 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5928 descriptor_write.pBufferInfo = &buffInfo;
5929
5930 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5931
5932 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005933 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5934 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005935 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005936 uint32_t pDynOff[2] = {512, 756};
5937 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5939 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5940 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5941 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005942 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005943 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5945 "offset 0 and range 1024 that "
5946 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005947 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005948 char const *vsSource = "#version 450\n"
5949 "\n"
5950 "out gl_PerVertex { \n"
5951 " vec4 gl_Position;\n"
5952 "};\n"
5953 "void main(){\n"
5954 " gl_Position = vec4(1);\n"
5955 "}\n";
5956 char const *fsSource = "#version 450\n"
5957 "\n"
5958 "layout(location=0) out vec4 x;\n"
5959 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5960 "void main(){\n"
5961 " x = vec4(bar.y);\n"
5962 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005963 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5964 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5965 VkPipelineObj pipe(m_device);
5966 pipe.AddShader(&vs);
5967 pipe.AddShader(&fs);
5968 pipe.AddColorAttachment();
5969 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5970
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005971 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005972 // This update should succeed, but offset size of 512 will overstep buffer
5973 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005974 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5975 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005976 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005977 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005978
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005979 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005980 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005981
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005982 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005983 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005984 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5985}
5986
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005987TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
5988 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
5989 "that doesn't have memory bound");
5990 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005992 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5994 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005995
5996 ASSERT_NO_FATAL_FAILURE(InitState());
5997 ASSERT_NO_FATAL_FAILURE(InitViewport());
5998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5999
6000 VkDescriptorPoolSize ds_type_count = {};
6001 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6002 ds_type_count.descriptorCount = 1;
6003
6004 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6005 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6006 ds_pool_ci.pNext = NULL;
6007 ds_pool_ci.maxSets = 1;
6008 ds_pool_ci.poolSizeCount = 1;
6009 ds_pool_ci.pPoolSizes = &ds_type_count;
6010
6011 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006012 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006013 ASSERT_VK_SUCCESS(err);
6014
6015 VkDescriptorSetLayoutBinding dsl_binding = {};
6016 dsl_binding.binding = 0;
6017 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6018 dsl_binding.descriptorCount = 1;
6019 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6020 dsl_binding.pImmutableSamplers = NULL;
6021
6022 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6023 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6024 ds_layout_ci.pNext = NULL;
6025 ds_layout_ci.bindingCount = 1;
6026 ds_layout_ci.pBindings = &dsl_binding;
6027 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006028 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006029 ASSERT_VK_SUCCESS(err);
6030
6031 VkDescriptorSet descriptorSet;
6032 VkDescriptorSetAllocateInfo alloc_info = {};
6033 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6034 alloc_info.descriptorSetCount = 1;
6035 alloc_info.descriptorPool = ds_pool;
6036 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006037 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006038 ASSERT_VK_SUCCESS(err);
6039
6040 // Create a buffer to update the descriptor with
6041 uint32_t qfi = 0;
6042 VkBufferCreateInfo buffCI = {};
6043 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6044 buffCI.size = 1024;
6045 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6046 buffCI.queueFamilyIndexCount = 1;
6047 buffCI.pQueueFamilyIndices = &qfi;
6048
6049 VkBuffer dyub;
6050 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6051 ASSERT_VK_SUCCESS(err);
6052
6053 // Attempt to update descriptor without binding memory to it
6054 VkDescriptorBufferInfo buffInfo = {};
6055 buffInfo.buffer = dyub;
6056 buffInfo.offset = 0;
6057 buffInfo.range = 1024;
6058
6059 VkWriteDescriptorSet descriptor_write;
6060 memset(&descriptor_write, 0, sizeof(descriptor_write));
6061 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6062 descriptor_write.dstSet = descriptorSet;
6063 descriptor_write.dstBinding = 0;
6064 descriptor_write.descriptorCount = 1;
6065 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6066 descriptor_write.pBufferInfo = &buffInfo;
6067
6068 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6069 m_errorMonitor->VerifyFound();
6070
6071 vkDestroyBuffer(m_device->device(), dyub, NULL);
6072 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6073 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6074}
6075
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006076TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006077 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006078 ASSERT_NO_FATAL_FAILURE(InitState());
6079 ASSERT_NO_FATAL_FAILURE(InitViewport());
6080 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6081
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006082 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006083 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006084 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6085 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6086 pipeline_layout_ci.pushConstantRangeCount = 1;
6087 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6088
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006089 //
6090 // Check for invalid push constant ranges in pipeline layouts.
6091 //
6092 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006093 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006094 char const *msg;
6095 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006096
Karl Schultzc81037d2016-05-12 08:11:23 -06006097 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6098 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6099 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6100 "vkCreatePipelineLayout() call has push constants index 0 with "
6101 "size 0."},
6102 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6103 "vkCreatePipelineLayout() call has push constants index 0 with "
6104 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006105 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006106 "vkCreatePipelineLayout() call has push constants index 0 with "
6107 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006108 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006109 "vkCreatePipelineLayout() call has push constants index 0 with "
6110 "size 0."},
6111 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6112 "vkCreatePipelineLayout() call has push constants index 0 with "
6113 "offset 1. Offset must"},
6114 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6115 "vkCreatePipelineLayout() call has push constants index 0 "
6116 "with offset "},
6117 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6118 "vkCreatePipelineLayout() call has push constants "
6119 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006120 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006121 "vkCreatePipelineLayout() call has push constants index 0 "
6122 "with offset "},
6123 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6124 "vkCreatePipelineLayout() call has push "
6125 "constants index 0 with offset "},
6126 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6127 "vkCreatePipelineLayout() call has push "
6128 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006129 }};
6130
6131 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006132 for (const auto &iter : range_tests) {
6133 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6135 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006136 m_errorMonitor->VerifyFound();
6137 if (VK_SUCCESS == err) {
6138 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6139 }
6140 }
6141
6142 // Check for invalid stage flag
6143 pc_range.offset = 0;
6144 pc_range.size = 16;
6145 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006146 m_errorMonitor->SetDesiredFailureMsg(
6147 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6148 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006149 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006150 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006151 if (VK_SUCCESS == err) {
6152 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6153 }
6154
6155 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006156 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006157 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006158 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006159 char const *msg;
6160 };
6161
Karl Schultzc81037d2016-05-12 08:11:23 -06006162 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006163 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6164 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6165 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6166 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6167 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006168 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006169 {
6170 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6171 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6172 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6173 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6174 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006175 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006176 },
6177 {
6178 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6179 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6180 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6181 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6182 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006183 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006184 },
6185 {
6186 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6187 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6188 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6189 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6190 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006191 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006192 },
6193 {
6194 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6195 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6196 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6197 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6198 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006199 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006200 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006201
Karl Schultzc81037d2016-05-12 08:11:23 -06006202 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006203 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006204 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6206 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006207 m_errorMonitor->VerifyFound();
6208 if (VK_SUCCESS == err) {
6209 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6210 }
6211 }
6212
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006213 //
6214 // CmdPushConstants tests
6215 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006216 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006217
6218 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006219 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6220 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006221 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6222 "vkCmdPushConstants() call has push constants with size 1. Size "
6223 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006224 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006225 "vkCmdPushConstants() call has push constants with size 1. Size "
6226 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006227 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006228 "vkCmdPushConstants() call has push constants with offset 1. "
6229 "Offset must be a multiple of 4."},
6230 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6231 "vkCmdPushConstants() call has push constants with offset 1. "
6232 "Offset must be a multiple of 4."},
6233 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6234 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6235 "0x1 not within flag-matching ranges in pipeline layout"},
6236 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6237 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6238 "0x1 not within flag-matching ranges in pipeline layout"},
6239 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6240 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6241 "0x1 not within flag-matching ranges in pipeline layout"},
6242 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6243 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6244 "0x1 not within flag-matching ranges in pipeline layout"},
6245 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6246 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6247 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006248 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006249 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6250 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006251 }};
6252
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006253 BeginCommandBuffer();
6254
6255 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006256 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006257 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006258 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006259 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006260 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006261 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006262 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006263 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6265 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006266 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006267 m_errorMonitor->VerifyFound();
6268 }
6269
6270 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006272 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006273 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006274 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006275
Karl Schultzc81037d2016-05-12 08:11:23 -06006276 // overlapping range tests with cmd
6277 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6278 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6279 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6280 "0x1 not within flag-matching ranges in pipeline layout"},
6281 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6282 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6283 "0x1 not within flag-matching ranges in pipeline layout"},
6284 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6285 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6286 "0x1 not within flag-matching ranges in pipeline layout"},
6287 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006288 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006289 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006290 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6291 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006292 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006293 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006294 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006295 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006296 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006297 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6299 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006300 iter.range.size, dummy_values);
6301 m_errorMonitor->VerifyFound();
6302 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006303 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6304
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006305 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006306}
6307
Karl Schultz6addd812016-02-02 17:17:23 -07006308TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006309 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006310 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006311
6312 ASSERT_NO_FATAL_FAILURE(InitState());
6313 ASSERT_NO_FATAL_FAILURE(InitViewport());
6314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6315
Mike Stroyanb8a61002016-06-20 16:00:28 -06006316 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6317 VkImageTiling tiling;
6318 VkFormatProperties format_properties;
6319 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006320 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006321 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006322 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006323 tiling = VK_IMAGE_TILING_OPTIMAL;
6324 } else {
6325 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6326 "skipped.\n");
6327 return;
6328 }
6329
Tobin Ehlis559c6382015-11-05 09:52:49 -07006330 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6331 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006332 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6333 ds_type_count[0].descriptorCount = 10;
6334 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6335 ds_type_count[1].descriptorCount = 2;
6336 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6337 ds_type_count[2].descriptorCount = 2;
6338 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6339 ds_type_count[3].descriptorCount = 5;
6340 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6341 // type
6342 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6343 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6344 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006345
6346 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006347 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6348 ds_pool_ci.pNext = NULL;
6349 ds_pool_ci.maxSets = 5;
6350 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6351 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006352
6353 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006354 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006355 ASSERT_VK_SUCCESS(err);
6356
6357 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6358 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006359 dsl_binding[0].binding = 0;
6360 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6361 dsl_binding[0].descriptorCount = 5;
6362 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6363 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006364
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006365 // Create layout identical to set0 layout but w/ different stageFlags
6366 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006367 dsl_fs_stage_only.binding = 0;
6368 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6369 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006370 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6371 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006372 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006373 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006374 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6375 ds_layout_ci.pNext = NULL;
6376 ds_layout_ci.bindingCount = 1;
6377 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006378 static const uint32_t NUM_LAYOUTS = 4;
6379 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006380 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006381 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6382 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006383 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006384 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006385 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006386 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006387 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006388 dsl_binding[0].binding = 0;
6389 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006390 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006391 dsl_binding[1].binding = 1;
6392 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6393 dsl_binding[1].descriptorCount = 2;
6394 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6395 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006396 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006397 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006398 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006399 ASSERT_VK_SUCCESS(err);
6400 dsl_binding[0].binding = 0;
6401 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006402 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006403 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006404 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006405 ASSERT_VK_SUCCESS(err);
6406 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006407 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006408 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006409 ASSERT_VK_SUCCESS(err);
6410
6411 static const uint32_t NUM_SETS = 4;
6412 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6413 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006414 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006415 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006416 alloc_info.descriptorPool = ds_pool;
6417 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006418 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006419 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006420 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006421 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006422 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006423 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006424 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006425
6426 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006427 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6428 pipeline_layout_ci.pNext = NULL;
6429 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6430 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006431
6432 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006433 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006434 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006435 // Create pipelineLayout with only one setLayout
6436 pipeline_layout_ci.setLayoutCount = 1;
6437 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006438 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006439 ASSERT_VK_SUCCESS(err);
6440 // Create pipelineLayout with 2 descriptor setLayout at index 0
6441 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6442 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006443 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006444 ASSERT_VK_SUCCESS(err);
6445 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6446 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6447 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006448 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006449 ASSERT_VK_SUCCESS(err);
6450 // Create pipelineLayout with UB type, but stageFlags for FS only
6451 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6452 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006453 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006454 ASSERT_VK_SUCCESS(err);
6455 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6456 VkDescriptorSetLayout pl_bad_s0[2] = {};
6457 pl_bad_s0[0] = ds_layout_fs_only;
6458 pl_bad_s0[1] = ds_layout[1];
6459 pipeline_layout_ci.setLayoutCount = 2;
6460 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6461 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006462 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006463 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006464
6465 // Create a buffer to update the descriptor with
6466 uint32_t qfi = 0;
6467 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006468 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6469 buffCI.size = 1024;
6470 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6471 buffCI.queueFamilyIndexCount = 1;
6472 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006473
6474 VkBuffer dyub;
6475 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6476 ASSERT_VK_SUCCESS(err);
6477 // Correctly update descriptor to avoid "NOT_UPDATED" error
6478 static const uint32_t NUM_BUFFS = 5;
6479 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006480 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006481 buffInfo[i].buffer = dyub;
6482 buffInfo[i].offset = 0;
6483 buffInfo[i].range = 1024;
6484 }
Karl Schultz6addd812016-02-02 17:17:23 -07006485 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006486 const int32_t tex_width = 32;
6487 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006488 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006489 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6490 image_create_info.pNext = NULL;
6491 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6492 image_create_info.format = tex_format;
6493 image_create_info.extent.width = tex_width;
6494 image_create_info.extent.height = tex_height;
6495 image_create_info.extent.depth = 1;
6496 image_create_info.mipLevels = 1;
6497 image_create_info.arrayLayers = 1;
6498 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006499 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006500 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006501 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006502 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6503 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006504
Karl Schultz6addd812016-02-02 17:17:23 -07006505 VkMemoryRequirements memReqs;
6506 VkDeviceMemory imageMem;
6507 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006508 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006509 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6510 memAlloc.pNext = NULL;
6511 memAlloc.allocationSize = 0;
6512 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006513 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6514 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006515 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006516 ASSERT_TRUE(pass);
6517 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6518 ASSERT_VK_SUCCESS(err);
6519 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6520 ASSERT_VK_SUCCESS(err);
6521
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006522 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006523 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6524 image_view_create_info.image = image;
6525 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6526 image_view_create_info.format = tex_format;
6527 image_view_create_info.subresourceRange.layerCount = 1;
6528 image_view_create_info.subresourceRange.baseMipLevel = 0;
6529 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006530 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006531
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006532 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006533 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006534 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006535 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006536 imageInfo[0].imageView = view;
6537 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6538 imageInfo[1].imageView = view;
6539 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006540 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006541 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006542 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006543 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006544
6545 static const uint32_t NUM_SET_UPDATES = 3;
6546 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6547 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6548 descriptor_write[0].dstSet = descriptorSet[0];
6549 descriptor_write[0].dstBinding = 0;
6550 descriptor_write[0].descriptorCount = 5;
6551 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6552 descriptor_write[0].pBufferInfo = buffInfo;
6553 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6554 descriptor_write[1].dstSet = descriptorSet[1];
6555 descriptor_write[1].dstBinding = 0;
6556 descriptor_write[1].descriptorCount = 2;
6557 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6558 descriptor_write[1].pImageInfo = imageInfo;
6559 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6560 descriptor_write[2].dstSet = descriptorSet[1];
6561 descriptor_write[2].dstBinding = 1;
6562 descriptor_write[2].descriptorCount = 2;
6563 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006564 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006565
6566 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006567
Tobin Ehlis88452832015-12-03 09:40:56 -07006568 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006569 char const *vsSource = "#version 450\n"
6570 "\n"
6571 "out gl_PerVertex {\n"
6572 " vec4 gl_Position;\n"
6573 "};\n"
6574 "void main(){\n"
6575 " gl_Position = vec4(1);\n"
6576 "}\n";
6577 char const *fsSource = "#version 450\n"
6578 "\n"
6579 "layout(location=0) out vec4 x;\n"
6580 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6581 "void main(){\n"
6582 " x = vec4(bar.y);\n"
6583 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006584 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6585 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006586 VkPipelineObj pipe(m_device);
6587 pipe.AddShader(&vs);
6588 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006589 pipe.AddColorAttachment();
6590 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006591
6592 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006593
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006594 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006595 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6596 // of PSO
6597 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6598 // cmd_pipeline.c
6599 // due to the fact that cmd_alloc_dset_data() has not been called in
6600 // cmd_bind_graphics_pipeline()
6601 // TODO : Want to cause various binding incompatibility issues here to test
6602 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006603 // First cause various verify_layout_compatibility() fails
6604 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006605 // verify_set_layout_compatibility fail cases:
6606 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6608 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6609 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006610 m_errorMonitor->VerifyFound();
6611
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006612 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6614 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6615 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006616 m_errorMonitor->VerifyFound();
6617
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006618 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006619 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6620 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6622 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6623 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006624 m_errorMonitor->VerifyFound();
6625
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006626 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6627 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6629 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6630 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006631 m_errorMonitor->VerifyFound();
6632
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006633 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6634 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6636 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6637 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6638 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006639 m_errorMonitor->VerifyFound();
6640
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006641 // Cause INFO messages due to disturbing previously bound Sets
6642 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006643 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6644 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006645 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6647 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6648 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006649 m_errorMonitor->VerifyFound();
6650
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006651 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6652 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006653 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6655 "any subsequent sets were disturbed ");
6656 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6657 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006658 m_errorMonitor->VerifyFound();
6659
Tobin Ehlis10fad692016-07-07 12:00:36 -06006660 // Now that we're done actively using the pipelineLayout that gfx pipeline
6661 // was created with, we should be able to delete it. Do that now to verify
6662 // that validation obeys pipelineLayout lifetime
6663 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6664
Tobin Ehlis88452832015-12-03 09:40:56 -07006665 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006666 // 1. Error due to not binding required set (we actually use same code as
6667 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006668 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6669 &descriptorSet[0], 0, NULL);
6670 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6671 &descriptorSet[1], 0, NULL);
6672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07006673 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006674 m_errorMonitor->VerifyFound();
6675
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006676 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006677 // 2. Error due to bound set not being compatible with PSO's
6678 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006679 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6680 &descriptorSet[0], 0, NULL);
6681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006682 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006683 m_errorMonitor->VerifyFound();
6684
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006685 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006686 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006687 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6688 }
6689 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006690 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006691 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6692 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006693 vkFreeMemory(m_device->device(), imageMem, NULL);
6694 vkDestroyImage(m_device->device(), image, NULL);
6695 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006696}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006697
Karl Schultz6addd812016-02-02 17:17:23 -07006698TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006699
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6701 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006702
6703 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006704 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006705 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006706 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006707
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006708 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006709}
6710
Karl Schultz6addd812016-02-02 17:17:23 -07006711TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6712 VkResult err;
6713 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006714
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006716
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006717 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006718
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006719 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006720 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006721 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006722 cmd.commandPool = m_commandPool;
6723 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006724 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006725
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006726 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006727 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006728
6729 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006730 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006731 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006732 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006733 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006734 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006735 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006736
6737 // The error should be caught by validation of the BeginCommandBuffer call
6738 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6739
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006740 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006741 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006742}
6743
Karl Schultz6addd812016-02-02 17:17:23 -07006744TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006745 // Cause error due to Begin while recording CB
6746 // Then cause 2 errors for attempting to reset CB w/o having
6747 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6748 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006750
6751 ASSERT_NO_FATAL_FAILURE(InitState());
6752
6753 // Calls AllocateCommandBuffers
6754 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6755
Karl Schultz6addd812016-02-02 17:17:23 -07006756 // Force the failure by setting the Renderpass and Framebuffer fields with
6757 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006758 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006759 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006760 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6761 cmd_buf_info.pNext = NULL;
6762 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006763 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006764
6765 // Begin CB to transition to recording state
6766 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6767 // Can't re-begin. This should trigger error
6768 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006769 m_errorMonitor->VerifyFound();
6770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006772 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6773 // Reset attempt will trigger error due to incorrect CommandPool state
6774 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006775 m_errorMonitor->VerifyFound();
6776
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006778 // Transition CB to RECORDED state
6779 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6780 // Now attempting to Begin will implicitly reset, which triggers error
6781 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006782 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006783}
6784
Karl Schultz6addd812016-02-02 17:17:23 -07006785TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006786 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006787 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006788
Mike Weiblencce7ec72016-10-17 19:33:05 -06006789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006790
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006791 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006793
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006794 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006795 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6796 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006797
6798 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006799 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6800 ds_pool_ci.pNext = NULL;
6801 ds_pool_ci.maxSets = 1;
6802 ds_pool_ci.poolSizeCount = 1;
6803 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006804
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006805 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006806 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006807 ASSERT_VK_SUCCESS(err);
6808
Tony Barboureb254902015-07-15 12:50:33 -06006809 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006810 dsl_binding.binding = 0;
6811 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6812 dsl_binding.descriptorCount = 1;
6813 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6814 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006815
Tony Barboureb254902015-07-15 12:50:33 -06006816 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006817 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6818 ds_layout_ci.pNext = NULL;
6819 ds_layout_ci.bindingCount = 1;
6820 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006821
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006822 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006823 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006824 ASSERT_VK_SUCCESS(err);
6825
6826 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006827 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006828 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006829 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006830 alloc_info.descriptorPool = ds_pool;
6831 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006832 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006833 ASSERT_VK_SUCCESS(err);
6834
Tony Barboureb254902015-07-15 12:50:33 -06006835 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006836 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6837 pipeline_layout_ci.setLayoutCount = 1;
6838 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006839
6840 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006841 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006842 ASSERT_VK_SUCCESS(err);
6843
Tobin Ehlise68360f2015-10-01 11:15:13 -06006844 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006845 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006846
6847 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006848 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6849 vp_state_ci.scissorCount = 1;
6850 vp_state_ci.pScissors = &sc;
6851 vp_state_ci.viewportCount = 1;
6852 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006853
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006854 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6855 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6856 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6857 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6858 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6859 rs_state_ci.depthClampEnable = VK_FALSE;
6860 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6861 rs_state_ci.depthBiasEnable = VK_FALSE;
6862
Tony Barboureb254902015-07-15 12:50:33 -06006863 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006864 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6865 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006866 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006867 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6868 gp_ci.layout = pipeline_layout;
6869 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006870
6871 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006872 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6873 pc_ci.initialDataSize = 0;
6874 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006875
6876 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006877 VkPipelineCache pipelineCache;
6878
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006879 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006880 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006881 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006882
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006883 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006884
Chia-I Wuf7458c52015-10-26 21:10:41 +08006885 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6886 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6887 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6888 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006889}
Tobin Ehlis912df022015-09-17 08:46:18 -06006890/*// TODO : This test should be good, but needs Tess support in compiler to run
6891TEST_F(VkLayerTest, InvalidPatchControlPoints)
6892{
6893 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006894 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006895
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006897 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6898primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006899
Tobin Ehlis912df022015-09-17 08:46:18 -06006900 ASSERT_NO_FATAL_FAILURE(InitState());
6901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006902
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006903 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006904 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006905 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006906
6907 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6908 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6909 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006910 ds_pool_ci.poolSizeCount = 1;
6911 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006912
6913 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006914 err = vkCreateDescriptorPool(m_device->device(),
6915VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006916 ASSERT_VK_SUCCESS(err);
6917
6918 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006919 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006920 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006921 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006922 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6923 dsl_binding.pImmutableSamplers = NULL;
6924
6925 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006926 ds_layout_ci.sType =
6927VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006928 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006929 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006930 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006931
6932 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006933 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6934&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006935 ASSERT_VK_SUCCESS(err);
6936
6937 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006938 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6939VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006940 ASSERT_VK_SUCCESS(err);
6941
6942 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006943 pipeline_layout_ci.sType =
6944VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006945 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006946 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006947 pipeline_layout_ci.pSetLayouts = &ds_layout;
6948
6949 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006950 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6951&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006952 ASSERT_VK_SUCCESS(err);
6953
6954 VkPipelineShaderStageCreateInfo shaderStages[3];
6955 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6956
Karl Schultz6addd812016-02-02 17:17:23 -07006957 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6958this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006959 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006960 VkShaderObj
6961tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6962this);
6963 VkShaderObj
6964te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6965this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006966
Karl Schultz6addd812016-02-02 17:17:23 -07006967 shaderStages[0].sType =
6968VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006969 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006970 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006971 shaderStages[1].sType =
6972VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006973 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006974 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006975 shaderStages[2].sType =
6976VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006977 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006978 shaderStages[2].shader = te.handle();
6979
6980 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006981 iaCI.sType =
6982VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006983 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006984
6985 VkPipelineTessellationStateCreateInfo tsCI = {};
6986 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6987 tsCI.patchControlPoints = 0; // This will cause an error
6988
6989 VkGraphicsPipelineCreateInfo gp_ci = {};
6990 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6991 gp_ci.pNext = NULL;
6992 gp_ci.stageCount = 3;
6993 gp_ci.pStages = shaderStages;
6994 gp_ci.pVertexInputState = NULL;
6995 gp_ci.pInputAssemblyState = &iaCI;
6996 gp_ci.pTessellationState = &tsCI;
6997 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006998 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006999 gp_ci.pMultisampleState = NULL;
7000 gp_ci.pDepthStencilState = NULL;
7001 gp_ci.pColorBlendState = NULL;
7002 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7003 gp_ci.layout = pipeline_layout;
7004 gp_ci.renderPass = renderPass();
7005
7006 VkPipelineCacheCreateInfo pc_ci = {};
7007 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7008 pc_ci.pNext = NULL;
7009 pc_ci.initialSize = 0;
7010 pc_ci.initialData = 0;
7011 pc_ci.maxSize = 0;
7012
7013 VkPipeline pipeline;
7014 VkPipelineCache pipelineCache;
7015
Karl Schultz6addd812016-02-02 17:17:23 -07007016 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7017&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007018 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007019 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7020&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007021
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007022 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007023
Chia-I Wuf7458c52015-10-26 21:10:41 +08007024 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7025 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7026 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7027 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007028}
7029*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06007030// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07007031TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007032 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7035 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007036
Tobin Ehlise68360f2015-10-01 11:15:13 -06007037 ASSERT_NO_FATAL_FAILURE(InitState());
7038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007039
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007040 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007041 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7042 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007043
7044 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007045 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7046 ds_pool_ci.maxSets = 1;
7047 ds_pool_ci.poolSizeCount = 1;
7048 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007049
7050 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007051 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007052 ASSERT_VK_SUCCESS(err);
7053
7054 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007055 dsl_binding.binding = 0;
7056 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7057 dsl_binding.descriptorCount = 1;
7058 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007059
7060 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007061 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7062 ds_layout_ci.bindingCount = 1;
7063 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007064
7065 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007066 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007067 ASSERT_VK_SUCCESS(err);
7068
7069 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007070 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007071 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007072 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007073 alloc_info.descriptorPool = ds_pool;
7074 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007075 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007076 ASSERT_VK_SUCCESS(err);
7077
7078 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007079 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7080 pipeline_layout_ci.setLayoutCount = 1;
7081 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007082
7083 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007084 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007085 ASSERT_VK_SUCCESS(err);
7086
7087 VkViewport vp = {}; // Just need dummy vp to point to
7088
7089 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007090 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7091 vp_state_ci.scissorCount = 0;
7092 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7093 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007094
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007095 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7096 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7097 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7098 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7099 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7100 rs_state_ci.depthClampEnable = VK_FALSE;
7101 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7102 rs_state_ci.depthBiasEnable = VK_FALSE;
7103
Cody Northropeb3a6c12015-10-05 14:44:45 -06007104 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007105 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007106
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007107 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7108 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7109 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007110 shaderStages[0] = vs.GetStageCreateInfo();
7111 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007112
7113 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007114 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7115 gp_ci.stageCount = 2;
7116 gp_ci.pStages = shaderStages;
7117 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007118 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007119 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7120 gp_ci.layout = pipeline_layout;
7121 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007122
7123 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007124 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007125
7126 VkPipeline pipeline;
7127 VkPipelineCache pipelineCache;
7128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007129 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007130 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007131 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007132
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007133 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007134
Chia-I Wuf7458c52015-10-26 21:10:41 +08007135 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7136 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7137 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7138 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007139}
Karl Schultz6addd812016-02-02 17:17:23 -07007140// Don't set viewport state in PSO. This is an error b/c we always need this
7141// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007142// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007143TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007144 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007145 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007146
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007148
Tobin Ehlise68360f2015-10-01 11:15:13 -06007149 ASSERT_NO_FATAL_FAILURE(InitState());
7150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007151
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007152 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007153 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7154 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007155
7156 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007157 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7158 ds_pool_ci.maxSets = 1;
7159 ds_pool_ci.poolSizeCount = 1;
7160 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007161
7162 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007163 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007164 ASSERT_VK_SUCCESS(err);
7165
7166 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007167 dsl_binding.binding = 0;
7168 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7169 dsl_binding.descriptorCount = 1;
7170 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007171
7172 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007173 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7174 ds_layout_ci.bindingCount = 1;
7175 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007176
7177 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007178 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007179 ASSERT_VK_SUCCESS(err);
7180
7181 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007182 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007183 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007184 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007185 alloc_info.descriptorPool = ds_pool;
7186 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007187 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007188 ASSERT_VK_SUCCESS(err);
7189
7190 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007191 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7192 pipeline_layout_ci.setLayoutCount = 1;
7193 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007194
7195 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007196 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007197 ASSERT_VK_SUCCESS(err);
7198
7199 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7200 // Set scissor as dynamic to avoid second error
7201 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007202 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7203 dyn_state_ci.dynamicStateCount = 1;
7204 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007205
Cody Northropeb3a6c12015-10-05 14:44:45 -06007206 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007207 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007209 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7210 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7211 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007212 shaderStages[0] = vs.GetStageCreateInfo();
7213 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007214
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007215 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7216 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7217 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7218 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7219 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7220 rs_state_ci.depthClampEnable = VK_FALSE;
7221 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7222 rs_state_ci.depthBiasEnable = VK_FALSE;
7223
Tobin Ehlise68360f2015-10-01 11:15:13 -06007224 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007225 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7226 gp_ci.stageCount = 2;
7227 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007228 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007229 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7230 // should cause validation error
7231 gp_ci.pDynamicState = &dyn_state_ci;
7232 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7233 gp_ci.layout = pipeline_layout;
7234 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007235
7236 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007237 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007238
7239 VkPipeline pipeline;
7240 VkPipelineCache pipelineCache;
7241
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007242 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007243 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007244 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007245
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007246 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007247
Chia-I Wuf7458c52015-10-26 21:10:41 +08007248 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7249 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7250 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7251 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007252}
7253// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007254// Then run second test where dynamic scissor count doesn't match PSO scissor
7255// count
7256TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7257 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007258
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7260 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007261
Tobin Ehlise68360f2015-10-01 11:15:13 -06007262 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007263
7264 if (!m_device->phy().features().multiViewport) {
7265 printf("Device does not support multiple viewports/scissors; skipped.\n");
7266 return;
7267 }
7268
Tobin Ehlise68360f2015-10-01 11:15:13 -06007269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007270
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007271 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007272 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7273 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007274
7275 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007276 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7277 ds_pool_ci.maxSets = 1;
7278 ds_pool_ci.poolSizeCount = 1;
7279 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007280
7281 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007282 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007283 ASSERT_VK_SUCCESS(err);
7284
7285 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007286 dsl_binding.binding = 0;
7287 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7288 dsl_binding.descriptorCount = 1;
7289 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007290
7291 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007292 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7293 ds_layout_ci.bindingCount = 1;
7294 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007295
7296 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007297 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007298 ASSERT_VK_SUCCESS(err);
7299
7300 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007301 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007302 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007303 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007304 alloc_info.descriptorPool = ds_pool;
7305 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007306 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007307 ASSERT_VK_SUCCESS(err);
7308
7309 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007310 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7311 pipeline_layout_ci.setLayoutCount = 1;
7312 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007313
7314 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007315 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007316 ASSERT_VK_SUCCESS(err);
7317
7318 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007319 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7320 vp_state_ci.viewportCount = 1;
7321 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7322 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007323 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007324
7325 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7326 // Set scissor as dynamic to avoid that error
7327 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007328 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7329 dyn_state_ci.dynamicStateCount = 1;
7330 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007331
Cody Northropeb3a6c12015-10-05 14:44:45 -06007332 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007333 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007334
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007335 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7336 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7337 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007338 shaderStages[0] = vs.GetStageCreateInfo();
7339 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007340
Cody Northropf6622dc2015-10-06 10:33:21 -06007341 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7342 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7343 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007344 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007345 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007346 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007347 vi_ci.pVertexAttributeDescriptions = nullptr;
7348
7349 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7350 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7351 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7352
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007353 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007354 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007355 rs_ci.pNext = nullptr;
7356
Mark Youngc89c6312016-03-31 16:03:20 -06007357 VkPipelineColorBlendAttachmentState att = {};
7358 att.blendEnable = VK_FALSE;
7359 att.colorWriteMask = 0xf;
7360
Cody Northropf6622dc2015-10-06 10:33:21 -06007361 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7362 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7363 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007364 cb_ci.attachmentCount = 1;
7365 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007366
Tobin Ehlise68360f2015-10-01 11:15:13 -06007367 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007368 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7369 gp_ci.stageCount = 2;
7370 gp_ci.pStages = shaderStages;
7371 gp_ci.pVertexInputState = &vi_ci;
7372 gp_ci.pInputAssemblyState = &ia_ci;
7373 gp_ci.pViewportState = &vp_state_ci;
7374 gp_ci.pRasterizationState = &rs_ci;
7375 gp_ci.pColorBlendState = &cb_ci;
7376 gp_ci.pDynamicState = &dyn_state_ci;
7377 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7378 gp_ci.layout = pipeline_layout;
7379 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007380
7381 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007382 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007383
7384 VkPipeline pipeline;
7385 VkPipelineCache pipelineCache;
7386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007387 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007388 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007389 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007390
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007391 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007392
Tobin Ehlisd332f282015-10-02 11:00:56 -06007393 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007394 // First need to successfully create the PSO from above by setting
7395 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by pipeline state object, ");
Karl Schultz6addd812016-02-02 17:17:23 -07007397
7398 VkViewport vp = {}; // Just need dummy vp to point to
7399 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007400 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007401 ASSERT_VK_SUCCESS(err);
7402 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007403 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007404 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007405 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007406 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007407 Draw(1, 0, 0, 0);
7408
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007409 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007410
7411 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7412 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7413 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7414 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007415 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007416}
7417// Create PSO w/o non-zero scissorCount but no scissor data
7418// Then run second test where dynamic viewportCount doesn't match PSO
7419// viewportCount
7420TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7421 VkResult err;
7422
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
Karl Schultz6addd812016-02-02 17:17:23 -07007424
7425 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007426
7427 if (!m_device->phy().features().multiViewport) {
7428 printf("Device does not support multiple viewports/scissors; skipped.\n");
7429 return;
7430 }
7431
Karl Schultz6addd812016-02-02 17:17:23 -07007432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7433
7434 VkDescriptorPoolSize ds_type_count = {};
7435 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7436 ds_type_count.descriptorCount = 1;
7437
7438 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7439 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7440 ds_pool_ci.maxSets = 1;
7441 ds_pool_ci.poolSizeCount = 1;
7442 ds_pool_ci.pPoolSizes = &ds_type_count;
7443
7444 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007445 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007446 ASSERT_VK_SUCCESS(err);
7447
7448 VkDescriptorSetLayoutBinding dsl_binding = {};
7449 dsl_binding.binding = 0;
7450 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7451 dsl_binding.descriptorCount = 1;
7452 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7453
7454 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7455 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7456 ds_layout_ci.bindingCount = 1;
7457 ds_layout_ci.pBindings = &dsl_binding;
7458
7459 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007460 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007461 ASSERT_VK_SUCCESS(err);
7462
7463 VkDescriptorSet descriptorSet;
7464 VkDescriptorSetAllocateInfo alloc_info = {};
7465 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7466 alloc_info.descriptorSetCount = 1;
7467 alloc_info.descriptorPool = ds_pool;
7468 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007469 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007470 ASSERT_VK_SUCCESS(err);
7471
7472 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7473 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7474 pipeline_layout_ci.setLayoutCount = 1;
7475 pipeline_layout_ci.pSetLayouts = &ds_layout;
7476
7477 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007478 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007479 ASSERT_VK_SUCCESS(err);
7480
7481 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7482 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7483 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007484 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007485 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007486 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007487
7488 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7489 // Set scissor as dynamic to avoid that error
7490 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7491 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7492 dyn_state_ci.dynamicStateCount = 1;
7493 dyn_state_ci.pDynamicStates = &vp_state;
7494
7495 VkPipelineShaderStageCreateInfo shaderStages[2];
7496 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7497
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007498 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7499 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7500 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007501 shaderStages[0] = vs.GetStageCreateInfo();
7502 shaderStages[1] = fs.GetStageCreateInfo();
7503
7504 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7505 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7506 vi_ci.pNext = nullptr;
7507 vi_ci.vertexBindingDescriptionCount = 0;
7508 vi_ci.pVertexBindingDescriptions = nullptr;
7509 vi_ci.vertexAttributeDescriptionCount = 0;
7510 vi_ci.pVertexAttributeDescriptions = nullptr;
7511
7512 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7513 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7514 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7515
7516 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7517 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7518 rs_ci.pNext = nullptr;
7519
Mark Youngc89c6312016-03-31 16:03:20 -06007520 VkPipelineColorBlendAttachmentState att = {};
7521 att.blendEnable = VK_FALSE;
7522 att.colorWriteMask = 0xf;
7523
Karl Schultz6addd812016-02-02 17:17:23 -07007524 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7525 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7526 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007527 cb_ci.attachmentCount = 1;
7528 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007529
7530 VkGraphicsPipelineCreateInfo gp_ci = {};
7531 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7532 gp_ci.stageCount = 2;
7533 gp_ci.pStages = shaderStages;
7534 gp_ci.pVertexInputState = &vi_ci;
7535 gp_ci.pInputAssemblyState = &ia_ci;
7536 gp_ci.pViewportState = &vp_state_ci;
7537 gp_ci.pRasterizationState = &rs_ci;
7538 gp_ci.pColorBlendState = &cb_ci;
7539 gp_ci.pDynamicState = &dyn_state_ci;
7540 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7541 gp_ci.layout = pipeline_layout;
7542 gp_ci.renderPass = renderPass();
7543
7544 VkPipelineCacheCreateInfo pc_ci = {};
7545 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7546
7547 VkPipeline pipeline;
7548 VkPipelineCache pipelineCache;
7549
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007550 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007551 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007552 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007553
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007554 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007555
7556 // Now hit second fail case where we set scissor w/ different count than PSO
7557 // First need to successfully create the PSO from above by setting
7558 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007560
Tobin Ehlisd332f282015-10-02 11:00:56 -06007561 VkRect2D sc = {}; // Just need dummy vp to point to
7562 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007563 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007564 ASSERT_VK_SUCCESS(err);
7565 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007566 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007567 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007568 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007569 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007570 Draw(1, 0, 0, 0);
7571
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007572 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007573
Chia-I Wuf7458c52015-10-26 21:10:41 +08007574 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7575 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7576 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7577 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007578 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007579}
7580
Mark Young7394fdd2016-03-31 14:56:43 -06007581TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7582 VkResult err;
7583
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007585
7586 ASSERT_NO_FATAL_FAILURE(InitState());
7587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7588
7589 VkDescriptorPoolSize ds_type_count = {};
7590 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7591 ds_type_count.descriptorCount = 1;
7592
7593 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7594 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7595 ds_pool_ci.maxSets = 1;
7596 ds_pool_ci.poolSizeCount = 1;
7597 ds_pool_ci.pPoolSizes = &ds_type_count;
7598
7599 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007600 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007601 ASSERT_VK_SUCCESS(err);
7602
7603 VkDescriptorSetLayoutBinding dsl_binding = {};
7604 dsl_binding.binding = 0;
7605 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7606 dsl_binding.descriptorCount = 1;
7607 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7608
7609 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7610 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7611 ds_layout_ci.bindingCount = 1;
7612 ds_layout_ci.pBindings = &dsl_binding;
7613
7614 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007615 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007616 ASSERT_VK_SUCCESS(err);
7617
7618 VkDescriptorSet descriptorSet;
7619 VkDescriptorSetAllocateInfo alloc_info = {};
7620 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7621 alloc_info.descriptorSetCount = 1;
7622 alloc_info.descriptorPool = ds_pool;
7623 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007624 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007625 ASSERT_VK_SUCCESS(err);
7626
7627 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7628 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7629 pipeline_layout_ci.setLayoutCount = 1;
7630 pipeline_layout_ci.pSetLayouts = &ds_layout;
7631
7632 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007633 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007634 ASSERT_VK_SUCCESS(err);
7635
7636 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7637 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7638 vp_state_ci.scissorCount = 1;
7639 vp_state_ci.pScissors = NULL;
7640 vp_state_ci.viewportCount = 1;
7641 vp_state_ci.pViewports = NULL;
7642
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007643 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007644 // Set scissor as dynamic to avoid that error
7645 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7646 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7647 dyn_state_ci.dynamicStateCount = 2;
7648 dyn_state_ci.pDynamicStates = dynamic_states;
7649
7650 VkPipelineShaderStageCreateInfo shaderStages[2];
7651 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7652
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007653 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7654 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007655 this); // TODO - We shouldn't need a fragment shader
7656 // but add it to be able to run on more devices
7657 shaderStages[0] = vs.GetStageCreateInfo();
7658 shaderStages[1] = fs.GetStageCreateInfo();
7659
7660 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7661 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7662 vi_ci.pNext = nullptr;
7663 vi_ci.vertexBindingDescriptionCount = 0;
7664 vi_ci.pVertexBindingDescriptions = nullptr;
7665 vi_ci.vertexAttributeDescriptionCount = 0;
7666 vi_ci.pVertexAttributeDescriptions = nullptr;
7667
7668 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7669 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7670 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7671
7672 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7673 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7674 rs_ci.pNext = nullptr;
7675
Mark Young47107952016-05-02 15:59:55 -06007676 // Check too low (line width of -1.0f).
7677 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007678
7679 VkPipelineColorBlendAttachmentState att = {};
7680 att.blendEnable = VK_FALSE;
7681 att.colorWriteMask = 0xf;
7682
7683 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7684 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7685 cb_ci.pNext = nullptr;
7686 cb_ci.attachmentCount = 1;
7687 cb_ci.pAttachments = &att;
7688
7689 VkGraphicsPipelineCreateInfo gp_ci = {};
7690 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7691 gp_ci.stageCount = 2;
7692 gp_ci.pStages = shaderStages;
7693 gp_ci.pVertexInputState = &vi_ci;
7694 gp_ci.pInputAssemblyState = &ia_ci;
7695 gp_ci.pViewportState = &vp_state_ci;
7696 gp_ci.pRasterizationState = &rs_ci;
7697 gp_ci.pColorBlendState = &cb_ci;
7698 gp_ci.pDynamicState = &dyn_state_ci;
7699 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7700 gp_ci.layout = pipeline_layout;
7701 gp_ci.renderPass = renderPass();
7702
7703 VkPipelineCacheCreateInfo pc_ci = {};
7704 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7705
7706 VkPipeline pipeline;
7707 VkPipelineCache pipelineCache;
7708
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007709 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007710 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007711 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007712
7713 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007714 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007715
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007717
7718 // Check too high (line width of 65536.0f).
7719 rs_ci.lineWidth = 65536.0f;
7720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007721 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007722 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007723 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007724
7725 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007726 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007729
7730 dyn_state_ci.dynamicStateCount = 3;
7731
7732 rs_ci.lineWidth = 1.0f;
7733
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007734 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007735 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007736 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007737 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007738 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007739
7740 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007741 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007742 m_errorMonitor->VerifyFound();
7743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007745
7746 // Check too high with dynamic setting.
7747 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7748 m_errorMonitor->VerifyFound();
7749 EndCommandBuffer();
7750
7751 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7752 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7753 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7754 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007755 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007756}
7757
Karl Schultz6addd812016-02-02 17:17:23 -07007758TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007759 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7761 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007762
7763 ASSERT_NO_FATAL_FAILURE(InitState());
7764 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007765
Tony Barbourfe3351b2015-07-28 10:17:20 -06007766 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007767 // Don't care about RenderPass handle b/c error should be flagged before
7768 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007769 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007770
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007771 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007772}
7773
Karl Schultz6addd812016-02-02 17:17:23 -07007774TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007775 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7777 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007778
7779 ASSERT_NO_FATAL_FAILURE(InitState());
7780 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007781
Tony Barbourfe3351b2015-07-28 10:17:20 -06007782 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007783 // Just create a dummy Renderpass that's non-NULL so we can get to the
7784 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007785 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007786
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007787 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007788}
7789
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007790TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7791 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7792 "the number of renderPass attachments that use loadOp"
7793 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7794
7795 ASSERT_NO_FATAL_FAILURE(InitState());
7796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7797
7798 // Create a renderPass with a single attachment that uses loadOp CLEAR
7799 VkAttachmentReference attach = {};
7800 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7801 VkSubpassDescription subpass = {};
7802 subpass.inputAttachmentCount = 1;
7803 subpass.pInputAttachments = &attach;
7804 VkRenderPassCreateInfo rpci = {};
7805 rpci.subpassCount = 1;
7806 rpci.pSubpasses = &subpass;
7807 rpci.attachmentCount = 1;
7808 VkAttachmentDescription attach_desc = {};
7809 attach_desc.format = VK_FORMAT_UNDEFINED;
7810 // Set loadOp to CLEAR
7811 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7812 rpci.pAttachments = &attach_desc;
7813 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7814 VkRenderPass rp;
7815 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7816
7817 VkCommandBufferInheritanceInfo hinfo = {};
7818 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7819 hinfo.renderPass = VK_NULL_HANDLE;
7820 hinfo.subpass = 0;
7821 hinfo.framebuffer = VK_NULL_HANDLE;
7822 hinfo.occlusionQueryEnable = VK_FALSE;
7823 hinfo.queryFlags = 0;
7824 hinfo.pipelineStatistics = 0;
7825 VkCommandBufferBeginInfo info = {};
7826 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7827 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7828 info.pInheritanceInfo = &hinfo;
7829
7830 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7831 VkRenderPassBeginInfo rp_begin = {};
7832 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7833 rp_begin.pNext = NULL;
7834 rp_begin.renderPass = renderPass();
7835 rp_begin.framebuffer = framebuffer();
7836 rp_begin.clearValueCount = 0; // Should be 1
7837
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7839 "there must be at least 1 entries in "
7840 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007841
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007842 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007843
7844 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007845
7846 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007847}
7848
Cody Northrop3bb4d962016-05-09 16:15:57 -06007849TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7850
7851 TEST_DESCRIPTION("End a command buffer with an active render pass");
7852
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7854 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007855
7856 ASSERT_NO_FATAL_FAILURE(InitState());
7857 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7858
7859 // The framework's BeginCommandBuffer calls CreateRenderPass
7860 BeginCommandBuffer();
7861
7862 // Call directly into vkEndCommandBuffer instead of the
7863 // the framework's EndCommandBuffer, which inserts a
7864 // vkEndRenderPass
7865 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7866
7867 m_errorMonitor->VerifyFound();
7868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007869 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7870 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007871}
7872
Karl Schultz6addd812016-02-02 17:17:23 -07007873TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007874 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7876 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007877
7878 ASSERT_NO_FATAL_FAILURE(InitState());
7879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007880
7881 // Renderpass is started here
7882 BeginCommandBuffer();
7883
7884 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007885 vk_testing::Buffer dstBuffer;
7886 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007887
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007888 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007889
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007890 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007891}
7892
Karl Schultz6addd812016-02-02 17:17:23 -07007893TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007894 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7896 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007897
7898 ASSERT_NO_FATAL_FAILURE(InitState());
7899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007900
7901 // Renderpass is started here
7902 BeginCommandBuffer();
7903
7904 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007905 vk_testing::Buffer dstBuffer;
7906 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007907
Karl Schultz6addd812016-02-02 17:17:23 -07007908 VkDeviceSize dstOffset = 0;
7909 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007910 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007912 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007913
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007914 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007915}
7916
Karl Schultz6addd812016-02-02 17:17:23 -07007917TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007918 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7920 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007921
7922 ASSERT_NO_FATAL_FAILURE(InitState());
7923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007924
7925 // Renderpass is started here
7926 BeginCommandBuffer();
7927
Michael Lentine0a369f62016-02-03 16:51:46 -06007928 VkClearColorValue clear_color;
7929 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007930 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7931 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7932 const int32_t tex_width = 32;
7933 const int32_t tex_height = 32;
7934 VkImageCreateInfo image_create_info = {};
7935 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7936 image_create_info.pNext = NULL;
7937 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7938 image_create_info.format = tex_format;
7939 image_create_info.extent.width = tex_width;
7940 image_create_info.extent.height = tex_height;
7941 image_create_info.extent.depth = 1;
7942 image_create_info.mipLevels = 1;
7943 image_create_info.arrayLayers = 1;
7944 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7945 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7946 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007947
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007948 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007949 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007950
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007951 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007952
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007953 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007954
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007955 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007956}
7957
Karl Schultz6addd812016-02-02 17:17:23 -07007958TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007959 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7961 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007962
7963 ASSERT_NO_FATAL_FAILURE(InitState());
7964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007965
7966 // Renderpass is started here
7967 BeginCommandBuffer();
7968
7969 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007970 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007971 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7972 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7973 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7974 image_create_info.extent.width = 64;
7975 image_create_info.extent.height = 64;
7976 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7977 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007978
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007979 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007980 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007981
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007982 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007983
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007984 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7985 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007986
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007987 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007988}
7989
Karl Schultz6addd812016-02-02 17:17:23 -07007990TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007991 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007992 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007993
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
7995 "must be issued inside an active "
7996 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007997
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007998 ASSERT_NO_FATAL_FAILURE(InitState());
7999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008000
8001 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008002 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008003 ASSERT_VK_SUCCESS(err);
8004
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008005 VkClearAttachment color_attachment;
8006 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8007 color_attachment.clearValue.color.float32[0] = 0;
8008 color_attachment.clearValue.color.float32[1] = 0;
8009 color_attachment.clearValue.color.float32[2] = 0;
8010 color_attachment.clearValue.color.float32[3] = 0;
8011 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008012 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008013 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008014
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008015 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008016}
8017
Chris Forbes3b97e932016-09-07 11:29:24 +12008018TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8019 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8020 "called too many times in a renderpass instance");
8021
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8023 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008024
8025 ASSERT_NO_FATAL_FAILURE(InitState());
8026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8027
8028 BeginCommandBuffer();
8029
8030 // error here.
8031 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8032 m_errorMonitor->VerifyFound();
8033
8034 EndCommandBuffer();
8035}
8036
Chris Forbes6d624702016-09-07 13:57:05 +12008037TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8038 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8039 "called before the final subpass has been reached");
8040
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8042 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008043
8044 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008045 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8046 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008047
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008048 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008049
8050 VkRenderPass rp;
8051 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8052 ASSERT_VK_SUCCESS(err);
8053
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008054 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008055
8056 VkFramebuffer fb;
8057 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8058 ASSERT_VK_SUCCESS(err);
8059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008060 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008061
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008062 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {16, 16}}, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008063
8064 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8065
8066 // Error here.
8067 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8068 m_errorMonitor->VerifyFound();
8069
8070 // Clean up.
8071 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8072 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8073}
8074
Karl Schultz9e66a292016-04-21 15:57:51 -06008075TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8076 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8078 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008079
8080 ASSERT_NO_FATAL_FAILURE(InitState());
8081 BeginCommandBuffer();
8082
8083 VkBufferMemoryBarrier buf_barrier = {};
8084 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8085 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8086 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8087 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8088 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8089 buf_barrier.buffer = VK_NULL_HANDLE;
8090 buf_barrier.offset = 0;
8091 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008092 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8093 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008094
8095 m_errorMonitor->VerifyFound();
8096}
8097
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008098TEST_F(VkLayerTest, InvalidBarriers) {
8099 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8100
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008102
8103 ASSERT_NO_FATAL_FAILURE(InitState());
8104 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8105
8106 VkMemoryBarrier mem_barrier = {};
8107 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8108 mem_barrier.pNext = NULL;
8109 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8110 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8111 BeginCommandBuffer();
8112 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008113 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008114 &mem_barrier, 0, nullptr, 0, nullptr);
8115 m_errorMonitor->VerifyFound();
8116
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008118 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008119 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008120 ASSERT_TRUE(image.initialized());
8121 VkImageMemoryBarrier img_barrier = {};
8122 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8123 img_barrier.pNext = NULL;
8124 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8125 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8126 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8127 // New layout can't be UNDEFINED
8128 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8129 img_barrier.image = image.handle();
8130 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8131 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8132 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8133 img_barrier.subresourceRange.baseArrayLayer = 0;
8134 img_barrier.subresourceRange.baseMipLevel = 0;
8135 img_barrier.subresourceRange.layerCount = 1;
8136 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008137 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8138 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008139 m_errorMonitor->VerifyFound();
8140 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8141
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8143 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008144 // baseArrayLayer + layerCount must be <= image's arrayLayers
8145 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008146 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8147 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008148 m_errorMonitor->VerifyFound();
8149 img_barrier.subresourceRange.baseArrayLayer = 0;
8150
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008152 // baseMipLevel + levelCount must be <= image's mipLevels
8153 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008154 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8155 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008156 m_errorMonitor->VerifyFound();
8157 img_barrier.subresourceRange.baseMipLevel = 0;
8158
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Buffer Barriers cannot be used during a render pass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008160 vk_testing::Buffer buffer;
8161 buffer.init(*m_device, 256);
8162 VkBufferMemoryBarrier buf_barrier = {};
8163 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8164 buf_barrier.pNext = NULL;
8165 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8166 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8167 buf_barrier.buffer = buffer.handle();
8168 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8169 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8170 buf_barrier.offset = 0;
8171 buf_barrier.size = VK_WHOLE_SIZE;
8172 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008173 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8174 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008175 m_errorMonitor->VerifyFound();
8176 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8177
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008179 buf_barrier.offset = 257;
8180 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008181 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8182 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008183 m_errorMonitor->VerifyFound();
8184 buf_barrier.offset = 0;
8185
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008187 buf_barrier.size = 257;
8188 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008189 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8190 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008191 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008192
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008193 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008194 m_errorMonitor->SetDesiredFailureMsg(
8195 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8196 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8197 m_errorMonitor->SetDesiredFailureMsg(
8198 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8199 "Depth/stencil image formats must have at least one of VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008200 VkDepthStencilObj ds_image(m_device);
8201 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8202 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008203 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8204 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008205 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008206 // Use of COLOR aspect on DS image is error
8207 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008208 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8209 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008210 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008211 // Now test depth-only
8212 VkFormatProperties format_props;
8213
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008214 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8215 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8217 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8219 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008220 VkDepthStencilObj d_image(m_device);
8221 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8222 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008223 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008224 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008225 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008226 // Use of COLOR aspect on depth image is error
8227 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008228 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8229 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008230 m_errorMonitor->VerifyFound();
8231 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008232 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8233 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008234 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8236 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008237 VkDepthStencilObj s_image(m_device);
8238 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8239 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008240 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008241 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008242 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008243 // Use of COLOR aspect on depth image is error
8244 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008245 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8246 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008247 m_errorMonitor->VerifyFound();
8248 }
8249 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8251 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8253 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008254 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008255 c_image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008256 ASSERT_TRUE(c_image.initialized());
8257 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8258 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8259 img_barrier.image = c_image.handle();
8260 // Set aspect to depth (non-color)
8261 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008262 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8263 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008264 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008265}
8266
Tony Barbour18ba25c2016-09-29 13:42:40 -06008267TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8268 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8269
8270 m_errorMonitor->SetDesiredFailureMsg(
8271 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8272 "must have required access bit");
8273 ASSERT_NO_FATAL_FAILURE(InitState());
8274 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008275 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06008276 ASSERT_TRUE(image.initialized());
8277
8278 VkImageMemoryBarrier barrier = {};
8279 VkImageSubresourceRange range;
8280 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8281 barrier.srcAccessMask = 0;
8282 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8283 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8284 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8285 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8286 barrier.image = image.handle();
8287 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8288 range.baseMipLevel = 0;
8289 range.levelCount = 1;
8290 range.baseArrayLayer = 0;
8291 range.layerCount = 1;
8292 barrier.subresourceRange = range;
8293 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8294 cmdbuf.BeginCommandBuffer();
8295 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8296 &barrier);
8297 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8298 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8299 barrier.srcAccessMask = 0;
8300 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8301 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8302 &barrier);
8303
8304 m_errorMonitor->VerifyFound();
8305}
8306
Karl Schultz6addd812016-02-02 17:17:23 -07008307TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008308 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008309 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008310
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008312
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008313 ASSERT_NO_FATAL_FAILURE(InitState());
8314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008315 uint32_t qfi = 0;
8316 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008317 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8318 buffCI.size = 1024;
8319 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8320 buffCI.queueFamilyIndexCount = 1;
8321 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008322
8323 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008324 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008325 ASSERT_VK_SUCCESS(err);
8326
8327 BeginCommandBuffer();
8328 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008329 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8330 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008331 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008332 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008333
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008334 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008335
Chia-I Wuf7458c52015-10-26 21:10:41 +08008336 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008337}
8338
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008339TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8340 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8342 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8343 "of the indices specified when the device was created, via the "
8344 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008345
8346 ASSERT_NO_FATAL_FAILURE(InitState());
8347 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8348 VkBufferCreateInfo buffCI = {};
8349 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8350 buffCI.size = 1024;
8351 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8352 buffCI.queueFamilyIndexCount = 1;
8353 // Introduce failure by specifying invalid queue_family_index
8354 uint32_t qfi = 777;
8355 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008356 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008357
8358 VkBuffer ib;
8359 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8360
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008361 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008362 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008363}
8364
Karl Schultz6addd812016-02-02 17:17:23 -07008365TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008366TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008367 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008368
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008369 ASSERT_NO_FATAL_FAILURE(InitState());
8370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008371
Chris Forbesf29a84f2016-10-06 18:39:28 +13008372 // An empty primary command buffer
8373 VkCommandBufferObj cb(m_device, m_commandPool);
8374 cb.BeginCommandBuffer();
8375 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008376
Chris Forbesf29a84f2016-10-06 18:39:28 +13008377 m_commandBuffer->BeginCommandBuffer();
8378 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8379 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008380
Chris Forbesf29a84f2016-10-06 18:39:28 +13008381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8382 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008383 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008384}
8385
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008386TEST_F(VkLayerTest, DSUsageBitsErrors) {
8387 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8388 "that do not have correct usage bits sets.");
8389 VkResult err;
8390
8391 ASSERT_NO_FATAL_FAILURE(InitState());
8392 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8393 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8394 ds_type_count[i].type = VkDescriptorType(i);
8395 ds_type_count[i].descriptorCount = 1;
8396 }
8397 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8398 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8399 ds_pool_ci.pNext = NULL;
8400 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8401 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8402 ds_pool_ci.pPoolSizes = ds_type_count;
8403
8404 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008405 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008406 ASSERT_VK_SUCCESS(err);
8407
8408 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008409 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008410 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8411 dsl_binding[i].binding = 0;
8412 dsl_binding[i].descriptorType = VkDescriptorType(i);
8413 dsl_binding[i].descriptorCount = 1;
8414 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8415 dsl_binding[i].pImmutableSamplers = NULL;
8416 }
8417
8418 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8419 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8420 ds_layout_ci.pNext = NULL;
8421 ds_layout_ci.bindingCount = 1;
8422 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8423 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8424 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008425 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008426 ASSERT_VK_SUCCESS(err);
8427 }
8428 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8429 VkDescriptorSetAllocateInfo alloc_info = {};
8430 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8431 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8432 alloc_info.descriptorPool = ds_pool;
8433 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008434 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008435 ASSERT_VK_SUCCESS(err);
8436
8437 // Create a buffer & bufferView to be used for invalid updates
8438 VkBufferCreateInfo buff_ci = {};
8439 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8440 // This usage is not valid for any descriptor type
8441 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8442 buff_ci.size = 256;
8443 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8444 VkBuffer buffer;
8445 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8446 ASSERT_VK_SUCCESS(err);
8447
8448 VkBufferViewCreateInfo buff_view_ci = {};
8449 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8450 buff_view_ci.buffer = buffer;
8451 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8452 buff_view_ci.range = VK_WHOLE_SIZE;
8453 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008454 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008455 ASSERT_VK_SUCCESS(err);
8456
8457 // Create an image to be used for invalid updates
8458 VkImageCreateInfo image_ci = {};
8459 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8460 image_ci.imageType = VK_IMAGE_TYPE_2D;
8461 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8462 image_ci.extent.width = 64;
8463 image_ci.extent.height = 64;
8464 image_ci.extent.depth = 1;
8465 image_ci.mipLevels = 1;
8466 image_ci.arrayLayers = 1;
8467 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8468 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8469 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8470 // This usage is not valid for any descriptor type
8471 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8472 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8473 VkImage image;
8474 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8475 ASSERT_VK_SUCCESS(err);
8476 // Bind memory to image
8477 VkMemoryRequirements mem_reqs;
8478 VkDeviceMemory image_mem;
8479 bool pass;
8480 VkMemoryAllocateInfo mem_alloc = {};
8481 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8482 mem_alloc.pNext = NULL;
8483 mem_alloc.allocationSize = 0;
8484 mem_alloc.memoryTypeIndex = 0;
8485 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8486 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008487 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008488 ASSERT_TRUE(pass);
8489 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8490 ASSERT_VK_SUCCESS(err);
8491 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8492 ASSERT_VK_SUCCESS(err);
8493 // Now create view for image
8494 VkImageViewCreateInfo image_view_ci = {};
8495 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8496 image_view_ci.image = image;
8497 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8498 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8499 image_view_ci.subresourceRange.layerCount = 1;
8500 image_view_ci.subresourceRange.baseArrayLayer = 0;
8501 image_view_ci.subresourceRange.levelCount = 1;
8502 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8503 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008504 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008505 ASSERT_VK_SUCCESS(err);
8506
8507 VkDescriptorBufferInfo buff_info = {};
8508 buff_info.buffer = buffer;
8509 VkDescriptorImageInfo img_info = {};
8510 img_info.imageView = image_view;
8511 VkWriteDescriptorSet descriptor_write = {};
8512 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8513 descriptor_write.dstBinding = 0;
8514 descriptor_write.descriptorCount = 1;
8515 descriptor_write.pTexelBufferView = &buff_view;
8516 descriptor_write.pBufferInfo = &buff_info;
8517 descriptor_write.pImageInfo = &img_info;
8518
8519 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008520 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8521 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8522 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8523 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8524 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8525 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8526 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8527 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8528 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8529 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8530 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008531 // Start loop at 1 as SAMPLER desc type has no usage bit error
8532 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8533 descriptor_write.descriptorType = VkDescriptorType(i);
8534 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008536
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008537 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008538
8539 m_errorMonitor->VerifyFound();
8540 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8541 }
8542 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8543 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008544 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008545 vkDestroyImageView(m_device->device(), image_view, NULL);
8546 vkDestroyBuffer(m_device->device(), buffer, NULL);
8547 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008548 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008549 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8550}
8551
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008552TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008553 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8554 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8555 "1. offset value greater than buffer size\n"
8556 "2. range value of 0\n"
8557 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008558 VkResult err;
8559
8560 ASSERT_NO_FATAL_FAILURE(InitState());
8561 VkDescriptorPoolSize ds_type_count = {};
8562 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8563 ds_type_count.descriptorCount = 1;
8564
8565 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8566 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8567 ds_pool_ci.pNext = NULL;
8568 ds_pool_ci.maxSets = 1;
8569 ds_pool_ci.poolSizeCount = 1;
8570 ds_pool_ci.pPoolSizes = &ds_type_count;
8571
8572 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008573 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008574 ASSERT_VK_SUCCESS(err);
8575
8576 // Create layout with single uniform buffer descriptor
8577 VkDescriptorSetLayoutBinding dsl_binding = {};
8578 dsl_binding.binding = 0;
8579 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8580 dsl_binding.descriptorCount = 1;
8581 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8582 dsl_binding.pImmutableSamplers = NULL;
8583
8584 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8585 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8586 ds_layout_ci.pNext = NULL;
8587 ds_layout_ci.bindingCount = 1;
8588 ds_layout_ci.pBindings = &dsl_binding;
8589 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008590 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008591 ASSERT_VK_SUCCESS(err);
8592
8593 VkDescriptorSet descriptor_set = {};
8594 VkDescriptorSetAllocateInfo alloc_info = {};
8595 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8596 alloc_info.descriptorSetCount = 1;
8597 alloc_info.descriptorPool = ds_pool;
8598 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008599 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008600 ASSERT_VK_SUCCESS(err);
8601
8602 // Create a buffer to be used for invalid updates
8603 VkBufferCreateInfo buff_ci = {};
8604 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8605 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8606 buff_ci.size = 256;
8607 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8608 VkBuffer buffer;
8609 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8610 ASSERT_VK_SUCCESS(err);
8611 // Have to bind memory to buffer before descriptor update
8612 VkMemoryAllocateInfo mem_alloc = {};
8613 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8614 mem_alloc.pNext = NULL;
8615 mem_alloc.allocationSize = 256;
8616 mem_alloc.memoryTypeIndex = 0;
8617
8618 VkMemoryRequirements mem_reqs;
8619 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008620 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008621 if (!pass) {
8622 vkDestroyBuffer(m_device->device(), buffer, NULL);
8623 return;
8624 }
8625
8626 VkDeviceMemory mem;
8627 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8628 ASSERT_VK_SUCCESS(err);
8629 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8630 ASSERT_VK_SUCCESS(err);
8631
8632 VkDescriptorBufferInfo buff_info = {};
8633 buff_info.buffer = buffer;
8634 // First make offset 1 larger than buffer size
8635 buff_info.offset = 257;
8636 buff_info.range = VK_WHOLE_SIZE;
8637 VkWriteDescriptorSet descriptor_write = {};
8638 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8639 descriptor_write.dstBinding = 0;
8640 descriptor_write.descriptorCount = 1;
8641 descriptor_write.pTexelBufferView = nullptr;
8642 descriptor_write.pBufferInfo = &buff_info;
8643 descriptor_write.pImageInfo = nullptr;
8644
8645 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8646 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008648
8649 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8650
8651 m_errorMonitor->VerifyFound();
8652 // Now cause error due to range of 0
8653 buff_info.offset = 0;
8654 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8656 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008657
8658 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8659
8660 m_errorMonitor->VerifyFound();
8661 // Now cause error due to range exceeding buffer size - offset
8662 buff_info.offset = 128;
8663 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " range is 200 which is greater than buffer size ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008665
8666 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8667
8668 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008669 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008670 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8671 vkDestroyBuffer(m_device->device(), buffer, NULL);
8672 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8673 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8674}
8675
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008676TEST_F(VkLayerTest, DSAspectBitsErrors) {
8677 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8678 // are set, but could expand this test to hit more cases.
8679 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8680 "that do not have correct aspect bits sets.");
8681 VkResult err;
8682
8683 ASSERT_NO_FATAL_FAILURE(InitState());
8684 VkDescriptorPoolSize ds_type_count = {};
8685 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8686 ds_type_count.descriptorCount = 1;
8687
8688 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8689 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8690 ds_pool_ci.pNext = NULL;
8691 ds_pool_ci.maxSets = 5;
8692 ds_pool_ci.poolSizeCount = 1;
8693 ds_pool_ci.pPoolSizes = &ds_type_count;
8694
8695 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008696 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008697 ASSERT_VK_SUCCESS(err);
8698
8699 VkDescriptorSetLayoutBinding dsl_binding = {};
8700 dsl_binding.binding = 0;
8701 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8702 dsl_binding.descriptorCount = 1;
8703 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8704 dsl_binding.pImmutableSamplers = NULL;
8705
8706 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8707 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8708 ds_layout_ci.pNext = NULL;
8709 ds_layout_ci.bindingCount = 1;
8710 ds_layout_ci.pBindings = &dsl_binding;
8711 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008712 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008713 ASSERT_VK_SUCCESS(err);
8714
8715 VkDescriptorSet descriptor_set = {};
8716 VkDescriptorSetAllocateInfo alloc_info = {};
8717 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8718 alloc_info.descriptorSetCount = 1;
8719 alloc_info.descriptorPool = ds_pool;
8720 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008721 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008722 ASSERT_VK_SUCCESS(err);
8723
8724 // Create an image to be used for invalid updates
8725 VkImageCreateInfo image_ci = {};
8726 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8727 image_ci.imageType = VK_IMAGE_TYPE_2D;
8728 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8729 image_ci.extent.width = 64;
8730 image_ci.extent.height = 64;
8731 image_ci.extent.depth = 1;
8732 image_ci.mipLevels = 1;
8733 image_ci.arrayLayers = 1;
8734 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8735 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8736 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8737 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8738 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8739 VkImage image;
8740 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8741 ASSERT_VK_SUCCESS(err);
8742 // Bind memory to image
8743 VkMemoryRequirements mem_reqs;
8744 VkDeviceMemory image_mem;
8745 bool pass;
8746 VkMemoryAllocateInfo mem_alloc = {};
8747 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8748 mem_alloc.pNext = NULL;
8749 mem_alloc.allocationSize = 0;
8750 mem_alloc.memoryTypeIndex = 0;
8751 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8752 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008753 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008754 ASSERT_TRUE(pass);
8755 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8756 ASSERT_VK_SUCCESS(err);
8757 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8758 ASSERT_VK_SUCCESS(err);
8759 // Now create view for image
8760 VkImageViewCreateInfo image_view_ci = {};
8761 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8762 image_view_ci.image = image;
8763 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8764 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8765 image_view_ci.subresourceRange.layerCount = 1;
8766 image_view_ci.subresourceRange.baseArrayLayer = 0;
8767 image_view_ci.subresourceRange.levelCount = 1;
8768 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008769 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008770
8771 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008772 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008773 ASSERT_VK_SUCCESS(err);
8774
8775 VkDescriptorImageInfo img_info = {};
8776 img_info.imageView = image_view;
8777 VkWriteDescriptorSet descriptor_write = {};
8778 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8779 descriptor_write.dstBinding = 0;
8780 descriptor_write.descriptorCount = 1;
8781 descriptor_write.pTexelBufferView = NULL;
8782 descriptor_write.pBufferInfo = NULL;
8783 descriptor_write.pImageInfo = &img_info;
8784 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8785 descriptor_write.dstSet = descriptor_set;
8786 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8787 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008789
8790 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8791
8792 m_errorMonitor->VerifyFound();
8793 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8794 vkDestroyImage(m_device->device(), image, NULL);
8795 vkFreeMemory(m_device->device(), image_mem, NULL);
8796 vkDestroyImageView(m_device->device(), image_view, NULL);
8797 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8798 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8799}
8800
Karl Schultz6addd812016-02-02 17:17:23 -07008801TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008802 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008803 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008804
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8806 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8807 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008808
Tobin Ehlis3b780662015-05-28 12:11:26 -06008809 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008810 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008811 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008812 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8813 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008814
8815 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008816 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8817 ds_pool_ci.pNext = NULL;
8818 ds_pool_ci.maxSets = 1;
8819 ds_pool_ci.poolSizeCount = 1;
8820 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008821
Tobin Ehlis3b780662015-05-28 12:11:26 -06008822 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008823 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008824 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008825 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008826 dsl_binding.binding = 0;
8827 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8828 dsl_binding.descriptorCount = 1;
8829 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8830 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008831
Tony Barboureb254902015-07-15 12:50:33 -06008832 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008833 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8834 ds_layout_ci.pNext = NULL;
8835 ds_layout_ci.bindingCount = 1;
8836 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008837
Tobin Ehlis3b780662015-05-28 12:11:26 -06008838 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008839 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008840 ASSERT_VK_SUCCESS(err);
8841
8842 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008843 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008844 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008845 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008846 alloc_info.descriptorPool = ds_pool;
8847 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008848 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008849 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008850
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008851 VkSamplerCreateInfo sampler_ci = {};
8852 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8853 sampler_ci.pNext = NULL;
8854 sampler_ci.magFilter = VK_FILTER_NEAREST;
8855 sampler_ci.minFilter = VK_FILTER_NEAREST;
8856 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8857 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8858 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8859 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8860 sampler_ci.mipLodBias = 1.0;
8861 sampler_ci.anisotropyEnable = VK_FALSE;
8862 sampler_ci.maxAnisotropy = 1;
8863 sampler_ci.compareEnable = VK_FALSE;
8864 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8865 sampler_ci.minLod = 1.0;
8866 sampler_ci.maxLod = 1.0;
8867 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8868 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8869 VkSampler sampler;
8870 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8871 ASSERT_VK_SUCCESS(err);
8872
8873 VkDescriptorImageInfo info = {};
8874 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008875
8876 VkWriteDescriptorSet descriptor_write;
8877 memset(&descriptor_write, 0, sizeof(descriptor_write));
8878 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008879 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008880 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008881 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008882 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008883 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008884
8885 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8886
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008887 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008888
Chia-I Wuf7458c52015-10-26 21:10:41 +08008889 vkDestroySampler(m_device->device(), sampler, NULL);
8890 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8891 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008892}
8893
Karl Schultz6addd812016-02-02 17:17:23 -07008894TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008895 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008896 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008897
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8899 " binding #0 with 1 total descriptors but update of 1 descriptors "
8900 "starting at binding offset of 0 combined with update array element "
8901 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008902
Tobin Ehlis3b780662015-05-28 12:11:26 -06008903 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008904 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008905 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008906 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8907 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008908
8909 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008910 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8911 ds_pool_ci.pNext = NULL;
8912 ds_pool_ci.maxSets = 1;
8913 ds_pool_ci.poolSizeCount = 1;
8914 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008915
Tobin Ehlis3b780662015-05-28 12:11:26 -06008916 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008917 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008918 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008919
Tony Barboureb254902015-07-15 12:50:33 -06008920 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008921 dsl_binding.binding = 0;
8922 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8923 dsl_binding.descriptorCount = 1;
8924 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8925 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008926
8927 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008928 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8929 ds_layout_ci.pNext = NULL;
8930 ds_layout_ci.bindingCount = 1;
8931 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008932
Tobin Ehlis3b780662015-05-28 12:11:26 -06008933 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008934 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008935 ASSERT_VK_SUCCESS(err);
8936
8937 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008938 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008939 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008940 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008941 alloc_info.descriptorPool = ds_pool;
8942 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008943 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008944 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008945
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008946 // Correctly update descriptor to avoid "NOT_UPDATED" error
8947 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008948 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008949 buff_info.offset = 0;
8950 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008951
8952 VkWriteDescriptorSet descriptor_write;
8953 memset(&descriptor_write, 0, sizeof(descriptor_write));
8954 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008955 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008956 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008957 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008958 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8959 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008960
8961 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8962
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008963 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008964
Chia-I Wuf7458c52015-10-26 21:10:41 +08008965 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8966 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008967}
8968
Karl Schultz6addd812016-02-02 17:17:23 -07008969TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07008970 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07008971 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008972
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07008973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008974
Tobin Ehlis3b780662015-05-28 12:11:26 -06008975 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008976 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008977 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008978 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8979 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008980
8981 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008982 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8983 ds_pool_ci.pNext = NULL;
8984 ds_pool_ci.maxSets = 1;
8985 ds_pool_ci.poolSizeCount = 1;
8986 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008987
Tobin Ehlis3b780662015-05-28 12:11:26 -06008988 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008989 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008990 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008991
Tony Barboureb254902015-07-15 12:50:33 -06008992 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008993 dsl_binding.binding = 0;
8994 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8995 dsl_binding.descriptorCount = 1;
8996 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8997 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008998
8999 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009000 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9001 ds_layout_ci.pNext = NULL;
9002 ds_layout_ci.bindingCount = 1;
9003 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009004 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009005 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009006 ASSERT_VK_SUCCESS(err);
9007
9008 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009009 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009010 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009011 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009012 alloc_info.descriptorPool = ds_pool;
9013 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009014 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009015 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009016
Tony Barboureb254902015-07-15 12:50:33 -06009017 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009018 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9019 sampler_ci.pNext = NULL;
9020 sampler_ci.magFilter = VK_FILTER_NEAREST;
9021 sampler_ci.minFilter = VK_FILTER_NEAREST;
9022 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9023 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9024 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9025 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9026 sampler_ci.mipLodBias = 1.0;
9027 sampler_ci.anisotropyEnable = VK_FALSE;
9028 sampler_ci.maxAnisotropy = 1;
9029 sampler_ci.compareEnable = VK_FALSE;
9030 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9031 sampler_ci.minLod = 1.0;
9032 sampler_ci.maxLod = 1.0;
9033 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9034 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009035
Tobin Ehlis3b780662015-05-28 12:11:26 -06009036 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009037 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009038 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009039
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009040 VkDescriptorImageInfo info = {};
9041 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009042
9043 VkWriteDescriptorSet descriptor_write;
9044 memset(&descriptor_write, 0, sizeof(descriptor_write));
9045 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009046 descriptor_write.dstSet = descriptorSet;
9047 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009048 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009049 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009050 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009051 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009052
9053 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9054
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009055 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009056
Chia-I Wuf7458c52015-10-26 21:10:41 +08009057 vkDestroySampler(m_device->device(), sampler, NULL);
9058 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9059 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009060}
9061
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009062TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9063 // Create layout w/ empty binding and attempt to update it
9064 VkResult err;
9065
9066 ASSERT_NO_FATAL_FAILURE(InitState());
9067
9068 VkDescriptorPoolSize ds_type_count = {};
9069 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9070 ds_type_count.descriptorCount = 1;
9071
9072 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9073 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9074 ds_pool_ci.pNext = NULL;
9075 ds_pool_ci.maxSets = 1;
9076 ds_pool_ci.poolSizeCount = 1;
9077 ds_pool_ci.pPoolSizes = &ds_type_count;
9078
9079 VkDescriptorPool ds_pool;
9080 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9081 ASSERT_VK_SUCCESS(err);
9082
9083 VkDescriptorSetLayoutBinding dsl_binding = {};
9084 dsl_binding.binding = 0;
9085 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9086 dsl_binding.descriptorCount = 0;
9087 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9088 dsl_binding.pImmutableSamplers = NULL;
9089
9090 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9091 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9092 ds_layout_ci.pNext = NULL;
9093 ds_layout_ci.bindingCount = 1;
9094 ds_layout_ci.pBindings = &dsl_binding;
9095 VkDescriptorSetLayout ds_layout;
9096 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9097 ASSERT_VK_SUCCESS(err);
9098
9099 VkDescriptorSet descriptor_set;
9100 VkDescriptorSetAllocateInfo alloc_info = {};
9101 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9102 alloc_info.descriptorSetCount = 1;
9103 alloc_info.descriptorPool = ds_pool;
9104 alloc_info.pSetLayouts = &ds_layout;
9105 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9106 ASSERT_VK_SUCCESS(err);
9107
9108 VkSamplerCreateInfo sampler_ci = {};
9109 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9110 sampler_ci.magFilter = VK_FILTER_NEAREST;
9111 sampler_ci.minFilter = VK_FILTER_NEAREST;
9112 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9113 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9114 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9115 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9116 sampler_ci.mipLodBias = 1.0;
9117 sampler_ci.maxAnisotropy = 1;
9118 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9119 sampler_ci.minLod = 1.0;
9120 sampler_ci.maxLod = 1.0;
9121 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9122
9123 VkSampler sampler;
9124 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9125 ASSERT_VK_SUCCESS(err);
9126
9127 VkDescriptorImageInfo info = {};
9128 info.sampler = sampler;
9129
9130 VkWriteDescriptorSet descriptor_write;
9131 memset(&descriptor_write, 0, sizeof(descriptor_write));
9132 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9133 descriptor_write.dstSet = descriptor_set;
9134 descriptor_write.dstBinding = 0;
9135 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9136 // This is the wrong type, but empty binding error will be flagged first
9137 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9138 descriptor_write.pImageInfo = &info;
9139
9140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9141 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9142 m_errorMonitor->VerifyFound();
9143
9144 vkDestroySampler(m_device->device(), sampler, NULL);
9145 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9146 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9147}
9148
Karl Schultz6addd812016-02-02 17:17:23 -07009149TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9150 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9151 // types
9152 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009153
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009155
Tobin Ehlis3b780662015-05-28 12:11:26 -06009156 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009157
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009158 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009159 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9160 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009161
9162 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009163 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9164 ds_pool_ci.pNext = NULL;
9165 ds_pool_ci.maxSets = 1;
9166 ds_pool_ci.poolSizeCount = 1;
9167 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009168
Tobin Ehlis3b780662015-05-28 12:11:26 -06009169 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009170 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009171 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009172 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009173 dsl_binding.binding = 0;
9174 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9175 dsl_binding.descriptorCount = 1;
9176 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9177 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009178
Tony Barboureb254902015-07-15 12:50:33 -06009179 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009180 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9181 ds_layout_ci.pNext = NULL;
9182 ds_layout_ci.bindingCount = 1;
9183 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009184
Tobin Ehlis3b780662015-05-28 12:11:26 -06009185 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009186 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009187 ASSERT_VK_SUCCESS(err);
9188
9189 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009190 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009191 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009192 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009193 alloc_info.descriptorPool = ds_pool;
9194 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009195 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009196 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009197
Tony Barboureb254902015-07-15 12:50:33 -06009198 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009199 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9200 sampler_ci.pNext = NULL;
9201 sampler_ci.magFilter = VK_FILTER_NEAREST;
9202 sampler_ci.minFilter = VK_FILTER_NEAREST;
9203 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9204 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9205 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9206 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9207 sampler_ci.mipLodBias = 1.0;
9208 sampler_ci.anisotropyEnable = VK_FALSE;
9209 sampler_ci.maxAnisotropy = 1;
9210 sampler_ci.compareEnable = VK_FALSE;
9211 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9212 sampler_ci.minLod = 1.0;
9213 sampler_ci.maxLod = 1.0;
9214 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9215 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009216 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009217 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009218 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009219
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009220 VkDescriptorImageInfo info = {};
9221 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009222
9223 VkWriteDescriptorSet descriptor_write;
9224 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009225 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009226 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009227 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009228 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009229 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009230 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009231
9232 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9233
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009234 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009235
Chia-I Wuf7458c52015-10-26 21:10:41 +08009236 vkDestroySampler(m_device->device(), sampler, NULL);
9237 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9238 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009239}
9240
Karl Schultz6addd812016-02-02 17:17:23 -07009241TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009242 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009243 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009244
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9246 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009247
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009248 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009249 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9250 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009251 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009252 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9253 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009254
9255 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009256 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9257 ds_pool_ci.pNext = NULL;
9258 ds_pool_ci.maxSets = 1;
9259 ds_pool_ci.poolSizeCount = 1;
9260 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009261
9262 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009263 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009264 ASSERT_VK_SUCCESS(err);
9265
9266 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009267 dsl_binding.binding = 0;
9268 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9269 dsl_binding.descriptorCount = 1;
9270 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9271 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009272
9273 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009274 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9275 ds_layout_ci.pNext = NULL;
9276 ds_layout_ci.bindingCount = 1;
9277 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009278 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009279 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009280 ASSERT_VK_SUCCESS(err);
9281
9282 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009283 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009284 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009285 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009286 alloc_info.descriptorPool = ds_pool;
9287 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009288 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009289 ASSERT_VK_SUCCESS(err);
9290
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009291 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009292
9293 VkDescriptorImageInfo descriptor_info;
9294 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9295 descriptor_info.sampler = sampler;
9296
9297 VkWriteDescriptorSet descriptor_write;
9298 memset(&descriptor_write, 0, sizeof(descriptor_write));
9299 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009300 descriptor_write.dstSet = descriptorSet;
9301 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009302 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009303 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9304 descriptor_write.pImageInfo = &descriptor_info;
9305
9306 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9307
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009308 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009309
Chia-I Wuf7458c52015-10-26 21:10:41 +08009310 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9311 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009312}
9313
Karl Schultz6addd812016-02-02 17:17:23 -07009314TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9315 // Create a single combined Image/Sampler descriptor and send it an invalid
9316 // imageView
9317 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009318
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9320 "image sampler descriptor failed due "
9321 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009322
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009323 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009324 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009325 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9326 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009327
9328 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009329 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9330 ds_pool_ci.pNext = NULL;
9331 ds_pool_ci.maxSets = 1;
9332 ds_pool_ci.poolSizeCount = 1;
9333 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009334
9335 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009336 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009337 ASSERT_VK_SUCCESS(err);
9338
9339 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009340 dsl_binding.binding = 0;
9341 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9342 dsl_binding.descriptorCount = 1;
9343 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9344 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009345
9346 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009347 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9348 ds_layout_ci.pNext = NULL;
9349 ds_layout_ci.bindingCount = 1;
9350 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009351 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009352 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009353 ASSERT_VK_SUCCESS(err);
9354
9355 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009356 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009357 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009358 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009359 alloc_info.descriptorPool = ds_pool;
9360 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009361 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009362 ASSERT_VK_SUCCESS(err);
9363
9364 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009365 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9366 sampler_ci.pNext = NULL;
9367 sampler_ci.magFilter = VK_FILTER_NEAREST;
9368 sampler_ci.minFilter = VK_FILTER_NEAREST;
9369 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9370 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9371 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9372 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9373 sampler_ci.mipLodBias = 1.0;
9374 sampler_ci.anisotropyEnable = VK_FALSE;
9375 sampler_ci.maxAnisotropy = 1;
9376 sampler_ci.compareEnable = VK_FALSE;
9377 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9378 sampler_ci.minLod = 1.0;
9379 sampler_ci.maxLod = 1.0;
9380 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9381 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009382
9383 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009384 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009385 ASSERT_VK_SUCCESS(err);
9386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009387 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009388
9389 VkDescriptorImageInfo descriptor_info;
9390 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9391 descriptor_info.sampler = sampler;
9392 descriptor_info.imageView = view;
9393
9394 VkWriteDescriptorSet descriptor_write;
9395 memset(&descriptor_write, 0, sizeof(descriptor_write));
9396 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009397 descriptor_write.dstSet = descriptorSet;
9398 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009399 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009400 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9401 descriptor_write.pImageInfo = &descriptor_info;
9402
9403 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9404
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009405 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009406
Chia-I Wuf7458c52015-10-26 21:10:41 +08009407 vkDestroySampler(m_device->device(), sampler, NULL);
9408 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9409 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009410}
9411
Karl Schultz6addd812016-02-02 17:17:23 -07009412TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9413 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9414 // into the other
9415 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009416
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9418 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9419 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009420
Tobin Ehlis04356f92015-10-27 16:35:27 -06009421 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009422 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009423 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009424 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9425 ds_type_count[0].descriptorCount = 1;
9426 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9427 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009428
9429 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009430 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9431 ds_pool_ci.pNext = NULL;
9432 ds_pool_ci.maxSets = 1;
9433 ds_pool_ci.poolSizeCount = 2;
9434 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009435
9436 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009437 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009438 ASSERT_VK_SUCCESS(err);
9439 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009440 dsl_binding[0].binding = 0;
9441 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9442 dsl_binding[0].descriptorCount = 1;
9443 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9444 dsl_binding[0].pImmutableSamplers = NULL;
9445 dsl_binding[1].binding = 1;
9446 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9447 dsl_binding[1].descriptorCount = 1;
9448 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9449 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009450
9451 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009452 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9453 ds_layout_ci.pNext = NULL;
9454 ds_layout_ci.bindingCount = 2;
9455 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009456
9457 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009458 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009459 ASSERT_VK_SUCCESS(err);
9460
9461 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009462 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009463 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009464 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009465 alloc_info.descriptorPool = ds_pool;
9466 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009468 ASSERT_VK_SUCCESS(err);
9469
9470 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009471 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9472 sampler_ci.pNext = NULL;
9473 sampler_ci.magFilter = VK_FILTER_NEAREST;
9474 sampler_ci.minFilter = VK_FILTER_NEAREST;
9475 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9476 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9477 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9478 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9479 sampler_ci.mipLodBias = 1.0;
9480 sampler_ci.anisotropyEnable = VK_FALSE;
9481 sampler_ci.maxAnisotropy = 1;
9482 sampler_ci.compareEnable = VK_FALSE;
9483 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9484 sampler_ci.minLod = 1.0;
9485 sampler_ci.maxLod = 1.0;
9486 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9487 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009488
9489 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009490 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009491 ASSERT_VK_SUCCESS(err);
9492
9493 VkDescriptorImageInfo info = {};
9494 info.sampler = sampler;
9495
9496 VkWriteDescriptorSet descriptor_write;
9497 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9498 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009499 descriptor_write.dstSet = descriptorSet;
9500 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009501 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009502 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9503 descriptor_write.pImageInfo = &info;
9504 // This write update should succeed
9505 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9506 // Now perform a copy update that fails due to type mismatch
9507 VkCopyDescriptorSet copy_ds_update;
9508 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9509 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9510 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009511 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009512 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009513 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009514 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009515 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9516
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009517 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009518 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06009520 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9521 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9522 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009523 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009524 copy_ds_update.dstSet = descriptorSet;
9525 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009526 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009527 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9528
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009529 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009530
Tobin Ehlis04356f92015-10-27 16:35:27 -06009531 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9533 "update array offset of 0 and update of "
9534 "5 descriptors oversteps total number "
9535 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009536
Tobin Ehlis04356f92015-10-27 16:35:27 -06009537 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9538 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9539 copy_ds_update.srcSet = descriptorSet;
9540 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009541 copy_ds_update.dstSet = descriptorSet;
9542 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009543 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009544 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9545
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009546 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009547
Chia-I Wuf7458c52015-10-26 21:10:41 +08009548 vkDestroySampler(m_device->device(), sampler, NULL);
9549 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9550 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009551}
9552
Karl Schultz6addd812016-02-02 17:17:23 -07009553TEST_F(VkLayerTest, NumSamplesMismatch) {
9554 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9555 // sampleCount
9556 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009557
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009559
Tobin Ehlis3b780662015-05-28 12:11:26 -06009560 ASSERT_NO_FATAL_FAILURE(InitState());
9561 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009562 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009563 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009564 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009565
9566 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009567 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9568 ds_pool_ci.pNext = NULL;
9569 ds_pool_ci.maxSets = 1;
9570 ds_pool_ci.poolSizeCount = 1;
9571 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009572
Tobin Ehlis3b780662015-05-28 12:11:26 -06009573 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009574 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009575 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009576
Tony Barboureb254902015-07-15 12:50:33 -06009577 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009578 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009579 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009580 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009581 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9582 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009583
Tony Barboureb254902015-07-15 12:50:33 -06009584 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9585 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9586 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009587 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009588 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009589
Tobin Ehlis3b780662015-05-28 12:11:26 -06009590 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009591 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009592 ASSERT_VK_SUCCESS(err);
9593
9594 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009595 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009596 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009597 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009598 alloc_info.descriptorPool = ds_pool;
9599 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009600 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009601 ASSERT_VK_SUCCESS(err);
9602
Tony Barboureb254902015-07-15 12:50:33 -06009603 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009604 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009605 pipe_ms_state_ci.pNext = NULL;
9606 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9607 pipe_ms_state_ci.sampleShadingEnable = 0;
9608 pipe_ms_state_ci.minSampleShading = 1.0;
9609 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009610
Tony Barboureb254902015-07-15 12:50:33 -06009611 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009612 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9613 pipeline_layout_ci.pNext = NULL;
9614 pipeline_layout_ci.setLayoutCount = 1;
9615 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009616
9617 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009618 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009619 ASSERT_VK_SUCCESS(err);
9620
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009621 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9622 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9623 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009624 VkPipelineObj pipe(m_device);
9625 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009626 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009627 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009628 pipe.SetMSAA(&pipe_ms_state_ci);
9629 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009630
Tony Barbourfe3351b2015-07-28 10:17:20 -06009631 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009632 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009633
Mark Young29927482016-05-04 14:38:51 -06009634 // Render triangle (the error should trigger on the attempt to draw).
9635 Draw(3, 1, 0, 0);
9636
9637 // Finalize recording of the command buffer
9638 EndCommandBuffer();
9639
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009640 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009641
Chia-I Wuf7458c52015-10-26 21:10:41 +08009642 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9643 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9644 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009645}
Mark Young29927482016-05-04 14:38:51 -06009646
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009647TEST_F(VkLayerTest, RenderPassIncompatible) {
9648 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9649 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009650 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009651 VkResult err;
9652
9653 ASSERT_NO_FATAL_FAILURE(InitState());
9654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9655
9656 VkDescriptorSetLayoutBinding dsl_binding = {};
9657 dsl_binding.binding = 0;
9658 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9659 dsl_binding.descriptorCount = 1;
9660 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9661 dsl_binding.pImmutableSamplers = NULL;
9662
9663 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9664 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9665 ds_layout_ci.pNext = NULL;
9666 ds_layout_ci.bindingCount = 1;
9667 ds_layout_ci.pBindings = &dsl_binding;
9668
9669 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009670 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009671 ASSERT_VK_SUCCESS(err);
9672
9673 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9674 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9675 pipeline_layout_ci.pNext = NULL;
9676 pipeline_layout_ci.setLayoutCount = 1;
9677 pipeline_layout_ci.pSetLayouts = &ds_layout;
9678
9679 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009680 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009681 ASSERT_VK_SUCCESS(err);
9682
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009683 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9684 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9685 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009686 // Create a renderpass that will be incompatible with default renderpass
9687 VkAttachmentReference attach = {};
9688 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9689 VkAttachmentReference color_att = {};
9690 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9691 VkSubpassDescription subpass = {};
9692 subpass.inputAttachmentCount = 1;
9693 subpass.pInputAttachments = &attach;
9694 subpass.colorAttachmentCount = 1;
9695 subpass.pColorAttachments = &color_att;
9696 VkRenderPassCreateInfo rpci = {};
9697 rpci.subpassCount = 1;
9698 rpci.pSubpasses = &subpass;
9699 rpci.attachmentCount = 1;
9700 VkAttachmentDescription attach_desc = {};
9701 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009702 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9703 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009704 rpci.pAttachments = &attach_desc;
9705 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9706 VkRenderPass rp;
9707 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9708 VkPipelineObj pipe(m_device);
9709 pipe.AddShader(&vs);
9710 pipe.AddShader(&fs);
9711 pipe.AddColorAttachment();
9712 VkViewport view_port = {};
9713 m_viewports.push_back(view_port);
9714 pipe.SetViewport(m_viewports);
9715 VkRect2D rect = {};
9716 m_scissors.push_back(rect);
9717 pipe.SetScissor(m_scissors);
9718 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9719
9720 VkCommandBufferInheritanceInfo cbii = {};
9721 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9722 cbii.renderPass = rp;
9723 cbii.subpass = 0;
9724 VkCommandBufferBeginInfo cbbi = {};
9725 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9726 cbbi.pInheritanceInfo = &cbii;
9727 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9728 VkRenderPassBeginInfo rpbi = {};
9729 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9730 rpbi.framebuffer = m_framebuffer;
9731 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009732 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9733 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009734
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009736 // Render triangle (the error should trigger on the attempt to draw).
9737 Draw(3, 1, 0, 0);
9738
9739 // Finalize recording of the command buffer
9740 EndCommandBuffer();
9741
9742 m_errorMonitor->VerifyFound();
9743
9744 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9745 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9746 vkDestroyRenderPass(m_device->device(), rp, NULL);
9747}
9748
Mark Youngc89c6312016-03-31 16:03:20 -06009749TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9750 // Create Pipeline where the number of blend attachments doesn't match the
9751 // number of color attachments. In this case, we don't add any color
9752 // blend attachments even though we have a color attachment.
9753 VkResult err;
9754
9755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009756 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009757
9758 ASSERT_NO_FATAL_FAILURE(InitState());
9759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9760 VkDescriptorPoolSize ds_type_count = {};
9761 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9762 ds_type_count.descriptorCount = 1;
9763
9764 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9765 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9766 ds_pool_ci.pNext = NULL;
9767 ds_pool_ci.maxSets = 1;
9768 ds_pool_ci.poolSizeCount = 1;
9769 ds_pool_ci.pPoolSizes = &ds_type_count;
9770
9771 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009772 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009773 ASSERT_VK_SUCCESS(err);
9774
9775 VkDescriptorSetLayoutBinding dsl_binding = {};
9776 dsl_binding.binding = 0;
9777 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9778 dsl_binding.descriptorCount = 1;
9779 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9780 dsl_binding.pImmutableSamplers = NULL;
9781
9782 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9783 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9784 ds_layout_ci.pNext = NULL;
9785 ds_layout_ci.bindingCount = 1;
9786 ds_layout_ci.pBindings = &dsl_binding;
9787
9788 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009789 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009790 ASSERT_VK_SUCCESS(err);
9791
9792 VkDescriptorSet descriptorSet;
9793 VkDescriptorSetAllocateInfo alloc_info = {};
9794 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9795 alloc_info.descriptorSetCount = 1;
9796 alloc_info.descriptorPool = ds_pool;
9797 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009798 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009799 ASSERT_VK_SUCCESS(err);
9800
9801 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009802 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009803 pipe_ms_state_ci.pNext = NULL;
9804 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9805 pipe_ms_state_ci.sampleShadingEnable = 0;
9806 pipe_ms_state_ci.minSampleShading = 1.0;
9807 pipe_ms_state_ci.pSampleMask = NULL;
9808
9809 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9810 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9811 pipeline_layout_ci.pNext = NULL;
9812 pipeline_layout_ci.setLayoutCount = 1;
9813 pipeline_layout_ci.pSetLayouts = &ds_layout;
9814
9815 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009816 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009817 ASSERT_VK_SUCCESS(err);
9818
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009819 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9820 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9821 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009822 VkPipelineObj pipe(m_device);
9823 pipe.AddShader(&vs);
9824 pipe.AddShader(&fs);
9825 pipe.SetMSAA(&pipe_ms_state_ci);
9826 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9827
9828 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009829 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009830
Mark Young29927482016-05-04 14:38:51 -06009831 // Render triangle (the error should trigger on the attempt to draw).
9832 Draw(3, 1, 0, 0);
9833
9834 // Finalize recording of the command buffer
9835 EndCommandBuffer();
9836
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009837 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009838
9839 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9840 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9841 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9842}
Mark Young29927482016-05-04 14:38:51 -06009843
Mark Muellerd4914412016-06-13 17:52:06 -06009844TEST_F(VkLayerTest, MissingClearAttachment) {
9845 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9846 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009847 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009849 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009850
9851 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9852 m_errorMonitor->VerifyFound();
9853}
9854
Karl Schultz6addd812016-02-02 17:17:23 -07009855TEST_F(VkLayerTest, ClearCmdNoDraw) {
9856 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9857 // to issuing a Draw
9858 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009859
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009861 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009862
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009863 ASSERT_NO_FATAL_FAILURE(InitState());
9864 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009865
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009866 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009867 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9868 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009869
9870 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009871 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9872 ds_pool_ci.pNext = NULL;
9873 ds_pool_ci.maxSets = 1;
9874 ds_pool_ci.poolSizeCount = 1;
9875 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009876
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009877 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009878 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009879 ASSERT_VK_SUCCESS(err);
9880
Tony Barboureb254902015-07-15 12:50:33 -06009881 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009882 dsl_binding.binding = 0;
9883 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9884 dsl_binding.descriptorCount = 1;
9885 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9886 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009887
Tony Barboureb254902015-07-15 12:50:33 -06009888 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009889 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9890 ds_layout_ci.pNext = NULL;
9891 ds_layout_ci.bindingCount = 1;
9892 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009893
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009894 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009895 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009896 ASSERT_VK_SUCCESS(err);
9897
9898 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009899 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009900 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009901 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009902 alloc_info.descriptorPool = ds_pool;
9903 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009904 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009905 ASSERT_VK_SUCCESS(err);
9906
Tony Barboureb254902015-07-15 12:50:33 -06009907 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009908 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009909 pipe_ms_state_ci.pNext = NULL;
9910 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9911 pipe_ms_state_ci.sampleShadingEnable = 0;
9912 pipe_ms_state_ci.minSampleShading = 1.0;
9913 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009914
Tony Barboureb254902015-07-15 12:50:33 -06009915 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009916 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9917 pipeline_layout_ci.pNext = NULL;
9918 pipeline_layout_ci.setLayoutCount = 1;
9919 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009920
9921 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009922 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009923 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009924
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009925 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009926 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009927 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009928 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009929
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009930 VkPipelineObj pipe(m_device);
9931 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009932 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009933 pipe.SetMSAA(&pipe_ms_state_ci);
9934 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009935
9936 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009937
Karl Schultz6addd812016-02-02 17:17:23 -07009938 // Main thing we care about for this test is that the VkImage obj we're
9939 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009940 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009941 VkClearAttachment color_attachment;
9942 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9943 color_attachment.clearValue.color.float32[0] = 1.0;
9944 color_attachment.clearValue.color.float32[1] = 1.0;
9945 color_attachment.clearValue.color.float32[2] = 1.0;
9946 color_attachment.clearValue.color.float32[3] = 1.0;
9947 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009948 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009949
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009950 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009951
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009952 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009953
Chia-I Wuf7458c52015-10-26 21:10:41 +08009954 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9955 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9956 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009957}
9958
Karl Schultz6addd812016-02-02 17:17:23 -07009959TEST_F(VkLayerTest, VtxBufferBadIndex) {
9960 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009961
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9963 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009964
Tobin Ehlis502480b2015-06-24 15:53:07 -06009965 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009966 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009967 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009968
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009969 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009970 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9971 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009972
9973 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009974 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9975 ds_pool_ci.pNext = NULL;
9976 ds_pool_ci.maxSets = 1;
9977 ds_pool_ci.poolSizeCount = 1;
9978 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009979
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009980 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009981 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009982 ASSERT_VK_SUCCESS(err);
9983
Tony Barboureb254902015-07-15 12:50:33 -06009984 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009985 dsl_binding.binding = 0;
9986 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9987 dsl_binding.descriptorCount = 1;
9988 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9989 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009990
Tony Barboureb254902015-07-15 12:50:33 -06009991 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009992 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9993 ds_layout_ci.pNext = NULL;
9994 ds_layout_ci.bindingCount = 1;
9995 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009996
Tobin Ehlis502480b2015-06-24 15:53:07 -06009997 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009998 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009999 ASSERT_VK_SUCCESS(err);
10000
10001 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010002 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010003 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010004 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010005 alloc_info.descriptorPool = ds_pool;
10006 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010007 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010008 ASSERT_VK_SUCCESS(err);
10009
Tony Barboureb254902015-07-15 12:50:33 -060010010 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010011 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010012 pipe_ms_state_ci.pNext = NULL;
10013 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10014 pipe_ms_state_ci.sampleShadingEnable = 0;
10015 pipe_ms_state_ci.minSampleShading = 1.0;
10016 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010017
Tony Barboureb254902015-07-15 12:50:33 -060010018 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010019 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10020 pipeline_layout_ci.pNext = NULL;
10021 pipeline_layout_ci.setLayoutCount = 1;
10022 pipeline_layout_ci.pSetLayouts = &ds_layout;
10023 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010024
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010025 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010026 ASSERT_VK_SUCCESS(err);
10027
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010028 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10029 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10030 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010031 VkPipelineObj pipe(m_device);
10032 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010033 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010034 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010035 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010036 pipe.SetViewport(m_viewports);
10037 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010038 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010039
10040 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010041 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010042 // Don't care about actual data, just need to get to draw to flag error
10043 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010044 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010045 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010046 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010047
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010048 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010049
Chia-I Wuf7458c52015-10-26 21:10:41 +080010050 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10051 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10052 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010053}
Mark Muellerdfe37552016-07-07 14:47:42 -060010054
Mark Mueller2ee294f2016-08-04 12:59:48 -060010055TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10056 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10057 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010058 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010060 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10061 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010062
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010063 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10064 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010066 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010067
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010069 // The following test fails with recent NVidia drivers.
10070 // By the time core_validation is reached, the NVidia
10071 // driver has sanitized the invalid condition and core_validation
10072 // is not introduced to the failure condition. This is not the case
10073 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010074 // uint32_t count = static_cast<uint32_t>(~0);
10075 // VkPhysicalDevice physical_device;
10076 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10077 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010078
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010080 float queue_priority = 0.0;
10081
10082 VkDeviceQueueCreateInfo queue_create_info = {};
10083 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10084 queue_create_info.queueCount = 1;
10085 queue_create_info.pQueuePriorities = &queue_priority;
10086 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10087
10088 VkPhysicalDeviceFeatures features = m_device->phy().features();
10089 VkDevice testDevice;
10090 VkDeviceCreateInfo device_create_info = {};
10091 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10092 device_create_info.queueCreateInfoCount = 1;
10093 device_create_info.pQueueCreateInfos = &queue_create_info;
10094 device_create_info.pEnabledFeatures = &features;
10095 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10096 m_errorMonitor->VerifyFound();
10097
10098 queue_create_info.queueFamilyIndex = 1;
10099
10100 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10101 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10102 for (unsigned i = 0; i < feature_count; i++) {
10103 if (VK_FALSE == feature_array[i]) {
10104 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010106 device_create_info.pEnabledFeatures = &features;
10107 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10108 m_errorMonitor->VerifyFound();
10109 break;
10110 }
10111 }
10112}
10113
Tobin Ehlis16edf082016-11-21 12:33:49 -070010114TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10115 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10116
10117 ASSERT_NO_FATAL_FAILURE(InitState());
10118
10119 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10120 std::vector<VkDeviceQueueCreateInfo> queue_info;
10121 queue_info.reserve(queue_props.size());
10122 std::vector<std::vector<float>> queue_priorities;
10123 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10124 VkDeviceQueueCreateInfo qi{};
10125 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10126 qi.queueFamilyIndex = i;
10127 qi.queueCount = queue_props[i].queueCount;
10128 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10129 qi.pQueuePriorities = queue_priorities[i].data();
10130 queue_info.push_back(qi);
10131 }
10132
10133 std::vector<const char *> device_extension_names;
10134
10135 VkDevice local_device;
10136 VkDeviceCreateInfo device_create_info = {};
10137 auto features = m_device->phy().features();
10138 // Intentionally disable pipeline stats
10139 features.pipelineStatisticsQuery = VK_FALSE;
10140 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10141 device_create_info.pNext = NULL;
10142 device_create_info.queueCreateInfoCount = queue_info.size();
10143 device_create_info.pQueueCreateInfos = queue_info.data();
10144 device_create_info.enabledLayerCount = 0;
10145 device_create_info.ppEnabledLayerNames = NULL;
10146 device_create_info.pEnabledFeatures = &features;
10147 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10148 ASSERT_VK_SUCCESS(err);
10149
10150 VkQueryPoolCreateInfo qpci{};
10151 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10152 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10153 qpci.queryCount = 1;
10154 VkQueryPool query_pool;
10155
10156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10157 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10158 m_errorMonitor->VerifyFound();
10159
10160 vkDestroyDevice(local_device, nullptr);
10161}
10162
Mark Mueller2ee294f2016-08-04 12:59:48 -060010163TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10164 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10165 "End a command buffer with a query still in progress.");
10166
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010167 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10168 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10169 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010170
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010171 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010174
10175 ASSERT_NO_FATAL_FAILURE(InitState());
10176
10177 VkEvent event;
10178 VkEventCreateInfo event_create_info{};
10179 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10180 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10181
Mark Mueller2ee294f2016-08-04 12:59:48 -060010182 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010183 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010184
10185 BeginCommandBuffer();
10186
10187 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010188 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010189 ASSERT_TRUE(image.initialized());
10190 VkImageMemoryBarrier img_barrier = {};
10191 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10192 img_barrier.pNext = NULL;
10193 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10194 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10195 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10196 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10197 img_barrier.image = image.handle();
10198 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010199
10200 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10201 // that layer validation catches the case when it is not.
10202 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010203 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10204 img_barrier.subresourceRange.baseArrayLayer = 0;
10205 img_barrier.subresourceRange.baseMipLevel = 0;
10206 img_barrier.subresourceRange.layerCount = 1;
10207 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010208 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10209 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010210 m_errorMonitor->VerifyFound();
10211
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010213
10214 VkQueryPool query_pool;
10215 VkQueryPoolCreateInfo query_pool_create_info = {};
10216 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10217 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10218 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010219 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010220
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010221 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010222 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10223
10224 vkEndCommandBuffer(m_commandBuffer->handle());
10225 m_errorMonitor->VerifyFound();
10226
10227 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10228 vkDestroyEvent(m_device->device(), event, nullptr);
10229}
10230
Mark Muellerdfe37552016-07-07 14:47:42 -060010231TEST_F(VkLayerTest, VertexBufferInvalid) {
10232 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10233 "delete a buffer twice, use an invalid offset for each "
10234 "buffer type, and attempt to bind a null buffer");
10235
10236 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10237 "using deleted buffer ";
10238 const char *double_destroy_message = "Cannot free buffer 0x";
10239 const char *invalid_offset_message = "vkBindBufferMemory(): "
10240 "memoryOffset is 0x";
10241 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10242 "storage memoryOffset "
10243 "is 0x";
10244 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10245 "texel memoryOffset "
10246 "is 0x";
10247 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10248 "uniform memoryOffset "
10249 "is 0x";
10250 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
10251 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -060010252 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010253
10254 ASSERT_NO_FATAL_FAILURE(InitState());
10255 ASSERT_NO_FATAL_FAILURE(InitViewport());
10256 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10257
10258 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010259 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010260 pipe_ms_state_ci.pNext = NULL;
10261 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10262 pipe_ms_state_ci.sampleShadingEnable = 0;
10263 pipe_ms_state_ci.minSampleShading = 1.0;
10264 pipe_ms_state_ci.pSampleMask = nullptr;
10265
10266 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10267 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10268 VkPipelineLayout pipeline_layout;
10269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010270 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010271 ASSERT_VK_SUCCESS(err);
10272
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010273 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10274 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010275 VkPipelineObj pipe(m_device);
10276 pipe.AddShader(&vs);
10277 pipe.AddShader(&fs);
10278 pipe.AddColorAttachment();
10279 pipe.SetMSAA(&pipe_ms_state_ci);
10280 pipe.SetViewport(m_viewports);
10281 pipe.SetScissor(m_scissors);
10282 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10283
10284 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010285 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010286
10287 {
10288 // Create and bind a vertex buffer in a reduced scope, which will cause
10289 // it to be deleted upon leaving this scope
10290 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010291 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010292 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10293 draw_verticies.AddVertexInputToPipe(pipe);
10294 }
10295
10296 Draw(1, 0, 0, 0);
10297
10298 EndCommandBuffer();
10299
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010301 QueueCommandBuffer(false);
10302 m_errorMonitor->VerifyFound();
10303
10304 {
10305 // Create and bind a vertex buffer in a reduced scope, and delete it
10306 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010307 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010309 buffer_test.TestDoubleDestroy();
10310 }
10311 m_errorMonitor->VerifyFound();
10312
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010313 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010314 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10316 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10317 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010318 m_errorMonitor->VerifyFound();
10319 }
10320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010321 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10322 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010323 // Create and bind a memory buffer with an invalid offset again,
10324 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10326 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10327 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010328 m_errorMonitor->VerifyFound();
10329 }
10330
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010331 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010332 // Create and bind a memory buffer with an invalid offset again, but
10333 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10335 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10336 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010337 m_errorMonitor->VerifyFound();
10338 }
10339
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010340 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010341 // Create and bind a memory buffer with an invalid offset again, but
10342 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10344 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10345 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010346 m_errorMonitor->VerifyFound();
10347 }
10348
10349 {
10350 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10352 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10353 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010354 m_errorMonitor->VerifyFound();
10355 }
10356
10357 {
10358 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10360 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10361 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010362 }
10363 m_errorMonitor->VerifyFound();
10364
10365 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10366}
10367
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010368// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10369TEST_F(VkLayerTest, InvalidImageLayout) {
10370 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010371 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10372 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010373 // 3 in ValidateCmdBufImageLayouts
10374 // * -1 Attempt to submit cmd buf w/ deleted image
10375 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10376 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10378 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010379
10380 ASSERT_NO_FATAL_FAILURE(InitState());
10381 // Create src & dst images to use for copy operations
10382 VkImage src_image;
10383 VkImage dst_image;
10384
10385 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10386 const int32_t tex_width = 32;
10387 const int32_t tex_height = 32;
10388
10389 VkImageCreateInfo image_create_info = {};
10390 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10391 image_create_info.pNext = NULL;
10392 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10393 image_create_info.format = tex_format;
10394 image_create_info.extent.width = tex_width;
10395 image_create_info.extent.height = tex_height;
10396 image_create_info.extent.depth = 1;
10397 image_create_info.mipLevels = 1;
10398 image_create_info.arrayLayers = 4;
10399 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10400 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10401 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10402 image_create_info.flags = 0;
10403
10404 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10405 ASSERT_VK_SUCCESS(err);
10406 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10407 ASSERT_VK_SUCCESS(err);
10408
10409 BeginCommandBuffer();
10410 VkImageCopy copyRegion;
10411 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10412 copyRegion.srcSubresource.mipLevel = 0;
10413 copyRegion.srcSubresource.baseArrayLayer = 0;
10414 copyRegion.srcSubresource.layerCount = 1;
10415 copyRegion.srcOffset.x = 0;
10416 copyRegion.srcOffset.y = 0;
10417 copyRegion.srcOffset.z = 0;
10418 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10419 copyRegion.dstSubresource.mipLevel = 0;
10420 copyRegion.dstSubresource.baseArrayLayer = 0;
10421 copyRegion.dstSubresource.layerCount = 1;
10422 copyRegion.dstOffset.x = 0;
10423 copyRegion.dstOffset.y = 0;
10424 copyRegion.dstOffset.z = 0;
10425 copyRegion.extent.width = 1;
10426 copyRegion.extent.height = 1;
10427 copyRegion.extent.depth = 1;
10428 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10429 m_errorMonitor->VerifyFound();
10430 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10432 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10433 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010434 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10435 m_errorMonitor->VerifyFound();
10436 // Final src error is due to bad layout type
10437 m_errorMonitor->SetDesiredFailureMsg(
10438 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10439 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10440 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10441 m_errorMonitor->VerifyFound();
10442 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10444 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010445 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10446 m_errorMonitor->VerifyFound();
10447 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10449 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10450 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010451 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10452 m_errorMonitor->VerifyFound();
10453 m_errorMonitor->SetDesiredFailureMsg(
10454 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10455 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10456 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10457 m_errorMonitor->VerifyFound();
10458 // Now cause error due to bad image layout transition in PipelineBarrier
10459 VkImageMemoryBarrier image_barrier[1] = {};
10460 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10461 image_barrier[0].image = src_image;
10462 image_barrier[0].subresourceRange.layerCount = 2;
10463 image_barrier[0].subresourceRange.levelCount = 2;
10464 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10466 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10467 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10468 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10469 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010470 m_errorMonitor->VerifyFound();
10471
10472 // Finally some layout errors at RenderPass create time
10473 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10474 VkAttachmentReference attach = {};
10475 // perf warning for GENERAL layout w/ non-DS input attachment
10476 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10477 VkSubpassDescription subpass = {};
10478 subpass.inputAttachmentCount = 1;
10479 subpass.pInputAttachments = &attach;
10480 VkRenderPassCreateInfo rpci = {};
10481 rpci.subpassCount = 1;
10482 rpci.pSubpasses = &subpass;
10483 rpci.attachmentCount = 1;
10484 VkAttachmentDescription attach_desc = {};
10485 attach_desc.format = VK_FORMAT_UNDEFINED;
10486 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010487 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010488 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10490 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010491 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10492 m_errorMonitor->VerifyFound();
10493 // error w/ non-general layout
10494 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10495
10496 m_errorMonitor->SetDesiredFailureMsg(
10497 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10498 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10499 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10500 m_errorMonitor->VerifyFound();
10501 subpass.inputAttachmentCount = 0;
10502 subpass.colorAttachmentCount = 1;
10503 subpass.pColorAttachments = &attach;
10504 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10505 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10507 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010508 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10509 m_errorMonitor->VerifyFound();
10510 // error w/ non-color opt or GENERAL layout for color attachment
10511 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10512 m_errorMonitor->SetDesiredFailureMsg(
10513 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10514 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10515 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10516 m_errorMonitor->VerifyFound();
10517 subpass.colorAttachmentCount = 0;
10518 subpass.pDepthStencilAttachment = &attach;
10519 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10520 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10522 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010523 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10524 m_errorMonitor->VerifyFound();
10525 // error w/ non-ds opt or GENERAL layout for color attachment
10526 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10528 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10529 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010530 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10531 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010532 // For this error we need a valid renderpass so create default one
10533 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10534 attach.attachment = 0;
10535 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10536 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10537 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10538 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10539 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10540 // Can't do a CLEAR load on READ_ONLY initialLayout
10541 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10542 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10543 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10545 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10546 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010547 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10548 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010549
10550 vkDestroyImage(m_device->device(), src_image, NULL);
10551 vkDestroyImage(m_device->device(), dst_image, NULL);
10552}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010553
Tobin Ehlise0936662016-10-11 08:10:51 -060010554TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10555 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10556 VkResult err;
10557
10558 ASSERT_NO_FATAL_FAILURE(InitState());
10559
10560 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10561 VkImageTiling tiling;
10562 VkFormatProperties format_properties;
10563 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10564 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10565 tiling = VK_IMAGE_TILING_LINEAR;
10566 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10567 tiling = VK_IMAGE_TILING_OPTIMAL;
10568 } else {
10569 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10570 "skipped.\n");
10571 return;
10572 }
10573
10574 VkDescriptorPoolSize ds_type = {};
10575 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10576 ds_type.descriptorCount = 1;
10577
10578 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10579 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10580 ds_pool_ci.maxSets = 1;
10581 ds_pool_ci.poolSizeCount = 1;
10582 ds_pool_ci.pPoolSizes = &ds_type;
10583 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10584
10585 VkDescriptorPool ds_pool;
10586 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10587 ASSERT_VK_SUCCESS(err);
10588
10589 VkDescriptorSetLayoutBinding dsl_binding = {};
10590 dsl_binding.binding = 0;
10591 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10592 dsl_binding.descriptorCount = 1;
10593 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10594 dsl_binding.pImmutableSamplers = NULL;
10595
10596 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10597 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10598 ds_layout_ci.pNext = NULL;
10599 ds_layout_ci.bindingCount = 1;
10600 ds_layout_ci.pBindings = &dsl_binding;
10601
10602 VkDescriptorSetLayout ds_layout;
10603 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10604 ASSERT_VK_SUCCESS(err);
10605
10606 VkDescriptorSetAllocateInfo alloc_info = {};
10607 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10608 alloc_info.descriptorSetCount = 1;
10609 alloc_info.descriptorPool = ds_pool;
10610 alloc_info.pSetLayouts = &ds_layout;
10611 VkDescriptorSet descriptor_set;
10612 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10613 ASSERT_VK_SUCCESS(err);
10614
10615 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10616 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10617 pipeline_layout_ci.pNext = NULL;
10618 pipeline_layout_ci.setLayoutCount = 1;
10619 pipeline_layout_ci.pSetLayouts = &ds_layout;
10620 VkPipelineLayout pipeline_layout;
10621 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10622 ASSERT_VK_SUCCESS(err);
10623
10624 VkImageObj image(m_device);
10625 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10626 ASSERT_TRUE(image.initialized());
10627 VkImageView view = image.targetView(tex_format);
10628
10629 VkDescriptorImageInfo image_info = {};
10630 image_info.imageView = view;
10631 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10632
10633 VkWriteDescriptorSet descriptor_write = {};
10634 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10635 descriptor_write.dstSet = descriptor_set;
10636 descriptor_write.dstBinding = 0;
10637 descriptor_write.descriptorCount = 1;
10638 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10639 descriptor_write.pImageInfo = &image_info;
10640
10641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10642 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10643 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10644 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10645 m_errorMonitor->VerifyFound();
10646
10647 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10648 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10649 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10650 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10651}
10652
Mark Mueller93b938f2016-08-18 10:27:40 -060010653TEST_F(VkLayerTest, SimultaneousUse) {
10654 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10655 "in primary and secondary command buffers.");
10656
10657 ASSERT_NO_FATAL_FAILURE(InitState());
10658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10659
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010660 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010661 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10662 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010663
10664 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010665 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010666 command_buffer_allocate_info.commandPool = m_commandPool;
10667 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10668 command_buffer_allocate_info.commandBufferCount = 1;
10669
10670 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010671 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010672 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10673 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010674 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010675 command_buffer_inheritance_info.renderPass = m_renderPass;
10676 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10677 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010678 command_buffer_begin_info.flags =
10679 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010680 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10681
10682 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010683 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10684 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010685 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010686 vkEndCommandBuffer(secondary_command_buffer);
10687
Mark Mueller93b938f2016-08-18 10:27:40 -060010688 VkSubmitInfo submit_info = {};
10689 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10690 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010691 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010692 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010693
Mark Mueller4042b652016-09-05 22:52:21 -060010694 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010695 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10697 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010698 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010699 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10700 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010701
10702 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010703 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10704
Mark Mueller4042b652016-09-05 22:52:21 -060010705 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010706 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010707 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010708
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10710 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010711 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010712 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10713 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010714}
10715
Mark Mueller917f6bc2016-08-30 10:57:19 -060010716TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10717 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10718 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010719 "Delete objects that are inuse. Call VkQueueSubmit "
10720 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010721
10722 ASSERT_NO_FATAL_FAILURE(InitState());
10723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10724
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010725 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10726 const char *cannot_delete_event_message = "Cannot delete event 0x";
10727 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10728 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010729
10730 BeginCommandBuffer();
10731
10732 VkEvent event;
10733 VkEventCreateInfo event_create_info = {};
10734 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10735 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010736 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010737
Mark Muellerc8d441e2016-08-23 17:36:00 -060010738 EndCommandBuffer();
10739 vkDestroyEvent(m_device->device(), event, nullptr);
10740
10741 VkSubmitInfo submit_info = {};
10742 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10743 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010744 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010746 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10747 m_errorMonitor->VerifyFound();
10748
10749 m_errorMonitor->SetDesiredFailureMsg(0, "");
10750 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10751
10752 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10753
Mark Mueller917f6bc2016-08-30 10:57:19 -060010754 VkSemaphoreCreateInfo semaphore_create_info = {};
10755 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10756 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010757 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010758 VkFenceCreateInfo fence_create_info = {};
10759 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10760 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010761 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010762
10763 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010764 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010765 descriptor_pool_type_count.descriptorCount = 1;
10766
10767 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10768 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10769 descriptor_pool_create_info.maxSets = 1;
10770 descriptor_pool_create_info.poolSizeCount = 1;
10771 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010772 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010773
10774 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010775 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010776
10777 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010778 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010779 descriptorset_layout_binding.descriptorCount = 1;
10780 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10781
10782 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010783 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010784 descriptorset_layout_create_info.bindingCount = 1;
10785 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10786
10787 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010788 ASSERT_VK_SUCCESS(
10789 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010790
10791 VkDescriptorSet descriptorset;
10792 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010793 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010794 descriptorset_allocate_info.descriptorSetCount = 1;
10795 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10796 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010797 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010798
Mark Mueller4042b652016-09-05 22:52:21 -060010799 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10800
10801 VkDescriptorBufferInfo buffer_info = {};
10802 buffer_info.buffer = buffer_test.GetBuffer();
10803 buffer_info.offset = 0;
10804 buffer_info.range = 1024;
10805
10806 VkWriteDescriptorSet write_descriptor_set = {};
10807 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10808 write_descriptor_set.dstSet = descriptorset;
10809 write_descriptor_set.descriptorCount = 1;
10810 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10811 write_descriptor_set.pBufferInfo = &buffer_info;
10812
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010813 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010814
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010815 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10816 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010817
10818 VkPipelineObj pipe(m_device);
10819 pipe.AddColorAttachment();
10820 pipe.AddShader(&vs);
10821 pipe.AddShader(&fs);
10822
10823 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010824 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010825 pipeline_layout_create_info.setLayoutCount = 1;
10826 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10827
10828 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010829 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010830
10831 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10832
Mark Muellerc8d441e2016-08-23 17:36:00 -060010833 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010834 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010835
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010836 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10837 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10838 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010839
Mark Muellerc8d441e2016-08-23 17:36:00 -060010840 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010841
Mark Mueller917f6bc2016-08-30 10:57:19 -060010842 submit_info.signalSemaphoreCount = 1;
10843 submit_info.pSignalSemaphores = &semaphore;
10844 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010845
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010847 vkDestroyEvent(m_device->device(), event, nullptr);
10848 m_errorMonitor->VerifyFound();
10849
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010851 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10852 m_errorMonitor->VerifyFound();
10853
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010855 vkDestroyFence(m_device->device(), fence, nullptr);
10856 m_errorMonitor->VerifyFound();
10857
Tobin Ehlis122207b2016-09-01 08:50:06 -070010858 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010859 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10860 vkDestroyFence(m_device->device(), fence, nullptr);
10861 vkDestroyEvent(m_device->device(), event, nullptr);
10862 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010863 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010864 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10865}
10866
Tobin Ehlis2adda372016-09-01 08:51:06 -070010867TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10868 TEST_DESCRIPTION("Delete in-use query pool.");
10869
10870 ASSERT_NO_FATAL_FAILURE(InitState());
10871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10872
10873 VkQueryPool query_pool;
10874 VkQueryPoolCreateInfo query_pool_ci{};
10875 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10876 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10877 query_pool_ci.queryCount = 1;
10878 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10879 BeginCommandBuffer();
10880 // Reset query pool to create binding with cmd buffer
10881 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10882
10883 EndCommandBuffer();
10884
10885 VkSubmitInfo submit_info = {};
10886 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10887 submit_info.commandBufferCount = 1;
10888 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10889 // Submit cmd buffer and then destroy query pool while in-flight
10890 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10891
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010893 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10894 m_errorMonitor->VerifyFound();
10895
10896 vkQueueWaitIdle(m_device->m_queue);
10897 // Now that cmd buffer done we can safely destroy query_pool
10898 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10899}
10900
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010901TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10902 TEST_DESCRIPTION("Delete in-use pipeline.");
10903
10904 ASSERT_NO_FATAL_FAILURE(InitState());
10905 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10906
10907 // Empty pipeline layout used for binding PSO
10908 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10909 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10910 pipeline_layout_ci.setLayoutCount = 0;
10911 pipeline_layout_ci.pSetLayouts = NULL;
10912
10913 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010914 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010915 ASSERT_VK_SUCCESS(err);
10916
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010918 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010919 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10920 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010921 // Store pipeline handle so we can actually delete it before test finishes
10922 VkPipeline delete_this_pipeline;
10923 { // Scope pipeline so it will be auto-deleted
10924 VkPipelineObj pipe(m_device);
10925 pipe.AddShader(&vs);
10926 pipe.AddShader(&fs);
10927 pipe.AddColorAttachment();
10928 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10929 delete_this_pipeline = pipe.handle();
10930
10931 BeginCommandBuffer();
10932 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010933 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010934
10935 EndCommandBuffer();
10936
10937 VkSubmitInfo submit_info = {};
10938 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10939 submit_info.commandBufferCount = 1;
10940 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10941 // Submit cmd buffer and then pipeline destroyed while in-flight
10942 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10943 } // Pipeline deletion triggered here
10944 m_errorMonitor->VerifyFound();
10945 // Make sure queue finished and then actually delete pipeline
10946 vkQueueWaitIdle(m_device->m_queue);
10947 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10948 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10949}
10950
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010951TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10952 TEST_DESCRIPTION("Delete in-use imageView.");
10953
10954 ASSERT_NO_FATAL_FAILURE(InitState());
10955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10956
10957 VkDescriptorPoolSize ds_type_count;
10958 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10959 ds_type_count.descriptorCount = 1;
10960
10961 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10962 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10963 ds_pool_ci.maxSets = 1;
10964 ds_pool_ci.poolSizeCount = 1;
10965 ds_pool_ci.pPoolSizes = &ds_type_count;
10966
10967 VkDescriptorPool ds_pool;
10968 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10969 ASSERT_VK_SUCCESS(err);
10970
10971 VkSamplerCreateInfo sampler_ci = {};
10972 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10973 sampler_ci.pNext = NULL;
10974 sampler_ci.magFilter = VK_FILTER_NEAREST;
10975 sampler_ci.minFilter = VK_FILTER_NEAREST;
10976 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10977 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10978 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10979 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10980 sampler_ci.mipLodBias = 1.0;
10981 sampler_ci.anisotropyEnable = VK_FALSE;
10982 sampler_ci.maxAnisotropy = 1;
10983 sampler_ci.compareEnable = VK_FALSE;
10984 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10985 sampler_ci.minLod = 1.0;
10986 sampler_ci.maxLod = 1.0;
10987 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10988 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10989 VkSampler sampler;
10990
10991 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10992 ASSERT_VK_SUCCESS(err);
10993
10994 VkDescriptorSetLayoutBinding layout_binding;
10995 layout_binding.binding = 0;
10996 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10997 layout_binding.descriptorCount = 1;
10998 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10999 layout_binding.pImmutableSamplers = NULL;
11000
11001 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11002 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11003 ds_layout_ci.bindingCount = 1;
11004 ds_layout_ci.pBindings = &layout_binding;
11005 VkDescriptorSetLayout ds_layout;
11006 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11007 ASSERT_VK_SUCCESS(err);
11008
11009 VkDescriptorSetAllocateInfo alloc_info = {};
11010 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11011 alloc_info.descriptorSetCount = 1;
11012 alloc_info.descriptorPool = ds_pool;
11013 alloc_info.pSetLayouts = &ds_layout;
11014 VkDescriptorSet descriptor_set;
11015 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11016 ASSERT_VK_SUCCESS(err);
11017
11018 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11019 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11020 pipeline_layout_ci.pNext = NULL;
11021 pipeline_layout_ci.setLayoutCount = 1;
11022 pipeline_layout_ci.pSetLayouts = &ds_layout;
11023
11024 VkPipelineLayout pipeline_layout;
11025 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11026 ASSERT_VK_SUCCESS(err);
11027
11028 VkImageObj image(m_device);
11029 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11030 ASSERT_TRUE(image.initialized());
11031
11032 VkImageView view;
11033 VkImageViewCreateInfo ivci = {};
11034 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11035 ivci.image = image.handle();
11036 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11037 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11038 ivci.subresourceRange.layerCount = 1;
11039 ivci.subresourceRange.baseMipLevel = 0;
11040 ivci.subresourceRange.levelCount = 1;
11041 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11042
11043 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11044 ASSERT_VK_SUCCESS(err);
11045
11046 VkDescriptorImageInfo image_info{};
11047 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11048 image_info.imageView = view;
11049 image_info.sampler = sampler;
11050
11051 VkWriteDescriptorSet descriptor_write = {};
11052 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11053 descriptor_write.dstSet = descriptor_set;
11054 descriptor_write.dstBinding = 0;
11055 descriptor_write.descriptorCount = 1;
11056 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11057 descriptor_write.pImageInfo = &image_info;
11058
11059 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11060
11061 // Create PSO to use the sampler
11062 char const *vsSource = "#version 450\n"
11063 "\n"
11064 "out gl_PerVertex { \n"
11065 " vec4 gl_Position;\n"
11066 "};\n"
11067 "void main(){\n"
11068 " gl_Position = vec4(1);\n"
11069 "}\n";
11070 char const *fsSource = "#version 450\n"
11071 "\n"
11072 "layout(set=0, binding=0) uniform sampler2D s;\n"
11073 "layout(location=0) out vec4 x;\n"
11074 "void main(){\n"
11075 " x = texture(s, vec2(1));\n"
11076 "}\n";
11077 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11078 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11079 VkPipelineObj pipe(m_device);
11080 pipe.AddShader(&vs);
11081 pipe.AddShader(&fs);
11082 pipe.AddColorAttachment();
11083 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11084
11085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
11086
11087 BeginCommandBuffer();
11088 // Bind pipeline to cmd buffer
11089 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11090 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11091 &descriptor_set, 0, nullptr);
11092 Draw(1, 0, 0, 0);
11093 EndCommandBuffer();
11094 // Submit cmd buffer then destroy sampler
11095 VkSubmitInfo submit_info = {};
11096 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11097 submit_info.commandBufferCount = 1;
11098 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11099 // Submit cmd buffer and then destroy imageView while in-flight
11100 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11101
11102 vkDestroyImageView(m_device->device(), view, nullptr);
11103 m_errorMonitor->VerifyFound();
11104 vkQueueWaitIdle(m_device->m_queue);
11105 // Now we can actually destroy imageView
11106 vkDestroyImageView(m_device->device(), view, NULL);
11107 vkDestroySampler(m_device->device(), sampler, nullptr);
11108 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11109 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11110 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11111}
11112
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011113TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11114 TEST_DESCRIPTION("Delete in-use bufferView.");
11115
11116 ASSERT_NO_FATAL_FAILURE(InitState());
11117 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11118
11119 VkDescriptorPoolSize ds_type_count;
11120 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11121 ds_type_count.descriptorCount = 1;
11122
11123 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11124 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11125 ds_pool_ci.maxSets = 1;
11126 ds_pool_ci.poolSizeCount = 1;
11127 ds_pool_ci.pPoolSizes = &ds_type_count;
11128
11129 VkDescriptorPool ds_pool;
11130 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11131 ASSERT_VK_SUCCESS(err);
11132
11133 VkDescriptorSetLayoutBinding layout_binding;
11134 layout_binding.binding = 0;
11135 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11136 layout_binding.descriptorCount = 1;
11137 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11138 layout_binding.pImmutableSamplers = NULL;
11139
11140 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11141 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11142 ds_layout_ci.bindingCount = 1;
11143 ds_layout_ci.pBindings = &layout_binding;
11144 VkDescriptorSetLayout ds_layout;
11145 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11146 ASSERT_VK_SUCCESS(err);
11147
11148 VkDescriptorSetAllocateInfo alloc_info = {};
11149 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11150 alloc_info.descriptorSetCount = 1;
11151 alloc_info.descriptorPool = ds_pool;
11152 alloc_info.pSetLayouts = &ds_layout;
11153 VkDescriptorSet descriptor_set;
11154 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11155 ASSERT_VK_SUCCESS(err);
11156
11157 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11158 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11159 pipeline_layout_ci.pNext = NULL;
11160 pipeline_layout_ci.setLayoutCount = 1;
11161 pipeline_layout_ci.pSetLayouts = &ds_layout;
11162
11163 VkPipelineLayout pipeline_layout;
11164 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11165 ASSERT_VK_SUCCESS(err);
11166
11167 VkBuffer buffer;
11168 uint32_t queue_family_index = 0;
11169 VkBufferCreateInfo buffer_create_info = {};
11170 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11171 buffer_create_info.size = 1024;
11172 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11173 buffer_create_info.queueFamilyIndexCount = 1;
11174 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11175
11176 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11177 ASSERT_VK_SUCCESS(err);
11178
11179 VkMemoryRequirements memory_reqs;
11180 VkDeviceMemory buffer_memory;
11181
11182 VkMemoryAllocateInfo memory_info = {};
11183 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11184 memory_info.allocationSize = 0;
11185 memory_info.memoryTypeIndex = 0;
11186
11187 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11188 memory_info.allocationSize = memory_reqs.size;
11189 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11190 ASSERT_TRUE(pass);
11191
11192 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11193 ASSERT_VK_SUCCESS(err);
11194 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11195 ASSERT_VK_SUCCESS(err);
11196
11197 VkBufferView view;
11198 VkBufferViewCreateInfo bvci = {};
11199 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11200 bvci.buffer = buffer;
11201 bvci.format = VK_FORMAT_R8_UNORM;
11202 bvci.range = VK_WHOLE_SIZE;
11203
11204 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11205 ASSERT_VK_SUCCESS(err);
11206
11207 VkWriteDescriptorSet descriptor_write = {};
11208 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11209 descriptor_write.dstSet = descriptor_set;
11210 descriptor_write.dstBinding = 0;
11211 descriptor_write.descriptorCount = 1;
11212 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11213 descriptor_write.pTexelBufferView = &view;
11214
11215 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11216
11217 char const *vsSource = "#version 450\n"
11218 "\n"
11219 "out gl_PerVertex { \n"
11220 " vec4 gl_Position;\n"
11221 "};\n"
11222 "void main(){\n"
11223 " gl_Position = vec4(1);\n"
11224 "}\n";
11225 char const *fsSource = "#version 450\n"
11226 "\n"
11227 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11228 "layout(location=0) out vec4 x;\n"
11229 "void main(){\n"
11230 " x = imageLoad(s, 0);\n"
11231 "}\n";
11232 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11233 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11234 VkPipelineObj pipe(m_device);
11235 pipe.AddShader(&vs);
11236 pipe.AddShader(&fs);
11237 pipe.AddColorAttachment();
11238 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11239
11240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11241
11242 BeginCommandBuffer();
11243 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11244 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11245 VkRect2D scissor = {{0, 0}, {16, 16}};
11246 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11247 // Bind pipeline to cmd buffer
11248 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11249 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11250 &descriptor_set, 0, nullptr);
11251 Draw(1, 0, 0, 0);
11252 EndCommandBuffer();
11253
11254 VkSubmitInfo submit_info = {};
11255 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11256 submit_info.commandBufferCount = 1;
11257 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11258 // Submit cmd buffer and then destroy bufferView while in-flight
11259 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11260
11261 vkDestroyBufferView(m_device->device(), view, nullptr);
11262 m_errorMonitor->VerifyFound();
11263 vkQueueWaitIdle(m_device->m_queue);
11264 // Now we can actually destroy bufferView
11265 vkDestroyBufferView(m_device->device(), view, NULL);
11266 vkDestroyBuffer(m_device->device(), buffer, NULL);
11267 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11268 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11269 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11270 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11271}
11272
Tobin Ehlis209532e2016-09-07 13:52:18 -060011273TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11274 TEST_DESCRIPTION("Delete in-use sampler.");
11275
11276 ASSERT_NO_FATAL_FAILURE(InitState());
11277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11278
11279 VkDescriptorPoolSize ds_type_count;
11280 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11281 ds_type_count.descriptorCount = 1;
11282
11283 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11284 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11285 ds_pool_ci.maxSets = 1;
11286 ds_pool_ci.poolSizeCount = 1;
11287 ds_pool_ci.pPoolSizes = &ds_type_count;
11288
11289 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011290 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011291 ASSERT_VK_SUCCESS(err);
11292
11293 VkSamplerCreateInfo sampler_ci = {};
11294 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11295 sampler_ci.pNext = NULL;
11296 sampler_ci.magFilter = VK_FILTER_NEAREST;
11297 sampler_ci.minFilter = VK_FILTER_NEAREST;
11298 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11299 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11300 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11301 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11302 sampler_ci.mipLodBias = 1.0;
11303 sampler_ci.anisotropyEnable = VK_FALSE;
11304 sampler_ci.maxAnisotropy = 1;
11305 sampler_ci.compareEnable = VK_FALSE;
11306 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11307 sampler_ci.minLod = 1.0;
11308 sampler_ci.maxLod = 1.0;
11309 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11310 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11311 VkSampler sampler;
11312
11313 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11314 ASSERT_VK_SUCCESS(err);
11315
11316 VkDescriptorSetLayoutBinding layout_binding;
11317 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011318 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011319 layout_binding.descriptorCount = 1;
11320 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11321 layout_binding.pImmutableSamplers = NULL;
11322
11323 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11324 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11325 ds_layout_ci.bindingCount = 1;
11326 ds_layout_ci.pBindings = &layout_binding;
11327 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011328 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011329 ASSERT_VK_SUCCESS(err);
11330
11331 VkDescriptorSetAllocateInfo alloc_info = {};
11332 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11333 alloc_info.descriptorSetCount = 1;
11334 alloc_info.descriptorPool = ds_pool;
11335 alloc_info.pSetLayouts = &ds_layout;
11336 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011337 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011338 ASSERT_VK_SUCCESS(err);
11339
11340 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11341 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11342 pipeline_layout_ci.pNext = NULL;
11343 pipeline_layout_ci.setLayoutCount = 1;
11344 pipeline_layout_ci.pSetLayouts = &ds_layout;
11345
11346 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011347 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011348 ASSERT_VK_SUCCESS(err);
11349
11350 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011351 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011352 ASSERT_TRUE(image.initialized());
11353
11354 VkImageView view;
11355 VkImageViewCreateInfo ivci = {};
11356 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11357 ivci.image = image.handle();
11358 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11359 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11360 ivci.subresourceRange.layerCount = 1;
11361 ivci.subresourceRange.baseMipLevel = 0;
11362 ivci.subresourceRange.levelCount = 1;
11363 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11364
11365 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11366 ASSERT_VK_SUCCESS(err);
11367
11368 VkDescriptorImageInfo image_info{};
11369 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11370 image_info.imageView = view;
11371 image_info.sampler = sampler;
11372
11373 VkWriteDescriptorSet descriptor_write = {};
11374 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11375 descriptor_write.dstSet = descriptor_set;
11376 descriptor_write.dstBinding = 0;
11377 descriptor_write.descriptorCount = 1;
11378 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11379 descriptor_write.pImageInfo = &image_info;
11380
11381 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11382
11383 // Create PSO to use the sampler
11384 char const *vsSource = "#version 450\n"
11385 "\n"
11386 "out gl_PerVertex { \n"
11387 " vec4 gl_Position;\n"
11388 "};\n"
11389 "void main(){\n"
11390 " gl_Position = vec4(1);\n"
11391 "}\n";
11392 char const *fsSource = "#version 450\n"
11393 "\n"
11394 "layout(set=0, binding=0) uniform sampler2D s;\n"
11395 "layout(location=0) out vec4 x;\n"
11396 "void main(){\n"
11397 " x = texture(s, vec2(1));\n"
11398 "}\n";
11399 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11400 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11401 VkPipelineObj pipe(m_device);
11402 pipe.AddShader(&vs);
11403 pipe.AddShader(&fs);
11404 pipe.AddColorAttachment();
11405 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11406
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011408
11409 BeginCommandBuffer();
11410 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011411 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11412 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11413 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011414 Draw(1, 0, 0, 0);
11415 EndCommandBuffer();
11416 // Submit cmd buffer then destroy sampler
11417 VkSubmitInfo submit_info = {};
11418 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11419 submit_info.commandBufferCount = 1;
11420 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11421 // Submit cmd buffer and then destroy sampler while in-flight
11422 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11423
11424 vkDestroySampler(m_device->device(), sampler, nullptr);
11425 m_errorMonitor->VerifyFound();
11426 vkQueueWaitIdle(m_device->m_queue);
11427 // Now we can actually destroy sampler
11428 vkDestroySampler(m_device->device(), sampler, nullptr);
11429 vkDestroyImageView(m_device->device(), view, NULL);
11430 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11431 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11432 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11433}
11434
Mark Mueller1cd9f412016-08-25 13:23:52 -060011435TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011436 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011437 "signaled but not waited on by the queue. Wait on a "
11438 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011439
11440 ASSERT_NO_FATAL_FAILURE(InitState());
11441 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011443 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11444 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11445 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011446
11447 BeginCommandBuffer();
11448 EndCommandBuffer();
11449
11450 VkSemaphoreCreateInfo semaphore_create_info = {};
11451 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11452 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011453 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011454 VkSubmitInfo submit_info = {};
11455 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11456 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011457 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011458 submit_info.signalSemaphoreCount = 1;
11459 submit_info.pSignalSemaphores = &semaphore;
11460 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11461 m_errorMonitor->SetDesiredFailureMsg(0, "");
11462 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11463 BeginCommandBuffer();
11464 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011466 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11467 m_errorMonitor->VerifyFound();
11468
Mark Mueller1cd9f412016-08-25 13:23:52 -060011469 VkFenceCreateInfo fence_create_info = {};
11470 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11471 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011472 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011473
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011475 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11476 m_errorMonitor->VerifyFound();
11477
Mark Mueller4042b652016-09-05 22:52:21 -060011478 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011479 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011480 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11481}
11482
Tobin Ehlis4af23302016-07-19 10:50:30 -060011483TEST_F(VkLayerTest, FramebufferIncompatible) {
11484 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11485 "that does not match the framebuffer for the active "
11486 "renderpass.");
11487 ASSERT_NO_FATAL_FAILURE(InitState());
11488 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11489
11490 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011491 VkAttachmentDescription attachment = {0,
11492 VK_FORMAT_B8G8R8A8_UNORM,
11493 VK_SAMPLE_COUNT_1_BIT,
11494 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11495 VK_ATTACHMENT_STORE_OP_STORE,
11496 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11497 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11498 VK_IMAGE_LAYOUT_UNDEFINED,
11499 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011500
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011501 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011502
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011503 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011504
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011505 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011506
11507 VkRenderPass rp;
11508 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11509 ASSERT_VK_SUCCESS(err);
11510
11511 // A compatible framebuffer.
11512 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011513 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011514 ASSERT_TRUE(image.initialized());
11515
11516 VkImageViewCreateInfo ivci = {
11517 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11518 nullptr,
11519 0,
11520 image.handle(),
11521 VK_IMAGE_VIEW_TYPE_2D,
11522 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011523 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11524 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011525 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11526 };
11527 VkImageView view;
11528 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11529 ASSERT_VK_SUCCESS(err);
11530
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011531 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011532 VkFramebuffer fb;
11533 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11534 ASSERT_VK_SUCCESS(err);
11535
11536 VkCommandBufferAllocateInfo cbai = {};
11537 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11538 cbai.commandPool = m_commandPool;
11539 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11540 cbai.commandBufferCount = 1;
11541
11542 VkCommandBuffer sec_cb;
11543 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11544 ASSERT_VK_SUCCESS(err);
11545 VkCommandBufferBeginInfo cbbi = {};
11546 VkCommandBufferInheritanceInfo cbii = {};
11547 cbii.renderPass = renderPass();
11548 cbii.framebuffer = fb;
11549 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11550 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011551 cbbi.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Tobin Ehlis4af23302016-07-19 10:50:30 -060011552 cbbi.pInheritanceInfo = &cbii;
11553 vkBeginCommandBuffer(sec_cb, &cbbi);
11554 vkEndCommandBuffer(sec_cb);
11555
Chris Forbes3400bc52016-09-13 18:10:34 +120011556 VkCommandBufferBeginInfo cbbi2 = {
11557 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11558 0, nullptr
11559 };
11560 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11561 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011562
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011564 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011565 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11566 m_errorMonitor->VerifyFound();
11567 // Cleanup
11568 vkDestroyImageView(m_device->device(), view, NULL);
11569 vkDestroyRenderPass(m_device->device(), rp, NULL);
11570 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11571}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011572
11573TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11574 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11575 "invalid value. If logicOp is not available, attempt to "
11576 "use it and verify that we see the correct error.");
11577 ASSERT_NO_FATAL_FAILURE(InitState());
11578 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11579
11580 auto features = m_device->phy().features();
11581 // Set the expected error depending on whether or not logicOp available
11582 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11584 "enabled, logicOpEnable must be "
11585 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011586 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011588 }
11589 // Create a pipeline using logicOp
11590 VkResult err;
11591
11592 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11593 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11594
11595 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011596 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011597 ASSERT_VK_SUCCESS(err);
11598
11599 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11600 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11601 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011602 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011603 vp_state_ci.pViewports = &vp;
11604 vp_state_ci.scissorCount = 1;
11605 VkRect2D scissors = {}; // Dummy scissors to point to
11606 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011607
11608 VkPipelineShaderStageCreateInfo shaderStages[2];
11609 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11610
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011611 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11612 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011613 shaderStages[0] = vs.GetStageCreateInfo();
11614 shaderStages[1] = fs.GetStageCreateInfo();
11615
11616 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11617 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11618
11619 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11620 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11621 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11622
11623 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11624 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011625 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011626
11627 VkPipelineColorBlendAttachmentState att = {};
11628 att.blendEnable = VK_FALSE;
11629 att.colorWriteMask = 0xf;
11630
11631 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11632 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11633 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11634 cb_ci.logicOpEnable = VK_TRUE;
11635 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11636 cb_ci.attachmentCount = 1;
11637 cb_ci.pAttachments = &att;
11638
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011639 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11640 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11641 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11642
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011643 VkGraphicsPipelineCreateInfo gp_ci = {};
11644 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11645 gp_ci.stageCount = 2;
11646 gp_ci.pStages = shaderStages;
11647 gp_ci.pVertexInputState = &vi_ci;
11648 gp_ci.pInputAssemblyState = &ia_ci;
11649 gp_ci.pViewportState = &vp_state_ci;
11650 gp_ci.pRasterizationState = &rs_ci;
11651 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011652 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011653 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11654 gp_ci.layout = pipeline_layout;
11655 gp_ci.renderPass = renderPass();
11656
11657 VkPipelineCacheCreateInfo pc_ci = {};
11658 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11659
11660 VkPipeline pipeline;
11661 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011662 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011663 ASSERT_VK_SUCCESS(err);
11664
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011665 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011666 m_errorMonitor->VerifyFound();
11667 if (VK_SUCCESS == err) {
11668 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11669 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011670 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11671 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11672}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011673#endif // DRAW_STATE_TESTS
11674
Tobin Ehlis0788f522015-05-26 16:11:58 -060011675#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011676#if GTEST_IS_THREADSAFE
11677struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011678 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011679 VkEvent event;
11680 bool bailout;
11681};
11682
Karl Schultz6addd812016-02-02 17:17:23 -070011683extern "C" void *AddToCommandBuffer(void *arg) {
11684 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011685
Mike Stroyana6d14942016-07-13 15:10:05 -060011686 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011687 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011688 if (data->bailout) {
11689 break;
11690 }
11691 }
11692 return NULL;
11693}
11694
Karl Schultz6addd812016-02-02 17:17:23 -070011695TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011696 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011697
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011699
Mike Stroyanaccf7692015-05-12 16:00:45 -060011700 ASSERT_NO_FATAL_FAILURE(InitState());
11701 ASSERT_NO_FATAL_FAILURE(InitViewport());
11702 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11703
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011704 // Calls AllocateCommandBuffers
11705 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011706
11707 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011708 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011709
11710 VkEventCreateInfo event_info;
11711 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011712 VkResult err;
11713
11714 memset(&event_info, 0, sizeof(event_info));
11715 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11716
Chia-I Wuf7458c52015-10-26 21:10:41 +080011717 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011718 ASSERT_VK_SUCCESS(err);
11719
Mike Stroyanaccf7692015-05-12 16:00:45 -060011720 err = vkResetEvent(device(), event);
11721 ASSERT_VK_SUCCESS(err);
11722
11723 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011724 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011725 data.event = event;
11726 data.bailout = false;
11727 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011728
11729 // First do some correct operations using multiple threads.
11730 // Add many entries to command buffer from another thread.
11731 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11732 // Make non-conflicting calls from this thread at the same time.
11733 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011734 uint32_t count;
11735 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011736 }
11737 test_platform_thread_join(thread, NULL);
11738
11739 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011740 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011741 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011742 // Add many entries to command buffer from this thread at the same time.
11743 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011744
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011745 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011746 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011747
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011748 m_errorMonitor->SetBailout(NULL);
11749
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011750 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011751
Chia-I Wuf7458c52015-10-26 21:10:41 +080011752 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011753}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011754#endif // GTEST_IS_THREADSAFE
11755#endif // THREADING_TESTS
11756
Chris Forbes9f7ff632015-05-25 11:13:08 +120011757#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011758TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011759 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11760 "with an impossible code size");
11761
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011763
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011764 ASSERT_NO_FATAL_FAILURE(InitState());
11765 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11766
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011767 VkShaderModule module;
11768 VkShaderModuleCreateInfo moduleCreateInfo;
11769 struct icd_spv_header spv;
11770
11771 spv.magic = ICD_SPV_MAGIC;
11772 spv.version = ICD_SPV_VERSION;
11773 spv.gen_magic = 0;
11774
11775 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11776 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011777 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011778 moduleCreateInfo.codeSize = 4;
11779 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011780 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011781
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011782 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011783}
11784
Karl Schultz6addd812016-02-02 17:17:23 -070011785TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011786 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11787 "with a bad magic number");
11788
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011790
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011791 ASSERT_NO_FATAL_FAILURE(InitState());
11792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11793
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011794 VkShaderModule module;
11795 VkShaderModuleCreateInfo moduleCreateInfo;
11796 struct icd_spv_header spv;
11797
11798 spv.magic = ~ICD_SPV_MAGIC;
11799 spv.version = ICD_SPV_VERSION;
11800 spv.gen_magic = 0;
11801
11802 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11803 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011804 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011805 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11806 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011807 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011808
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011809 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011810}
11811
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011812#if 0
11813// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011814TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011816 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011817
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011818 ASSERT_NO_FATAL_FAILURE(InitState());
11819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11820
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011821 VkShaderModule module;
11822 VkShaderModuleCreateInfo moduleCreateInfo;
11823 struct icd_spv_header spv;
11824
11825 spv.magic = ICD_SPV_MAGIC;
11826 spv.version = ~ICD_SPV_VERSION;
11827 spv.gen_magic = 0;
11828
11829 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11830 moduleCreateInfo.pNext = NULL;
11831
Karl Schultz6addd812016-02-02 17:17:23 -070011832 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011833 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11834 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011835 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011836
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011837 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011838}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011839#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011840
Karl Schultz6addd812016-02-02 17:17:23 -070011841TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011842 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11843 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011845
Chris Forbes9f7ff632015-05-25 11:13:08 +120011846 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011848
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011849 char const *vsSource = "#version 450\n"
11850 "\n"
11851 "layout(location=0) out float x;\n"
11852 "out gl_PerVertex {\n"
11853 " vec4 gl_Position;\n"
11854 "};\n"
11855 "void main(){\n"
11856 " gl_Position = vec4(1);\n"
11857 " x = 0;\n"
11858 "}\n";
11859 char const *fsSource = "#version 450\n"
11860 "\n"
11861 "layout(location=0) out vec4 color;\n"
11862 "void main(){\n"
11863 " color = vec4(1);\n"
11864 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011865
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011866 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11867 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011868
11869 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011870 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011871 pipe.AddShader(&vs);
11872 pipe.AddShader(&fs);
11873
Chris Forbes9f7ff632015-05-25 11:13:08 +120011874 VkDescriptorSetObj descriptorSet(m_device);
11875 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011876 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011877
Tony Barbour5781e8f2015-08-04 16:23:11 -060011878 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011879
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011880 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011881}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011882
Mark Mueller098c9cb2016-09-08 09:01:57 -060011883TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11884 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11885
11886 ASSERT_NO_FATAL_FAILURE(InitState());
11887 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11888
11889 const char *bad_specialization_message =
11890 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11891
11892 char const *vsSource =
11893 "#version 450\n"
11894 "\n"
11895 "out gl_PerVertex {\n"
11896 " vec4 gl_Position;\n"
11897 "};\n"
11898 "void main(){\n"
11899 " gl_Position = vec4(1);\n"
11900 "}\n";
11901
11902 char const *fsSource =
11903 "#version 450\n"
11904 "\n"
11905 "layout (constant_id = 0) const float r = 0.0f;\n"
11906 "layout(location = 0) out vec4 uFragColor;\n"
11907 "void main(){\n"
11908 " uFragColor = vec4(r,1,0,1);\n"
11909 "}\n";
11910
11911 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11912 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11913
11914 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11915 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11916
11917 VkPipelineLayout pipeline_layout;
11918 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11919
11920 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11921 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11922 vp_state_create_info.viewportCount = 1;
11923 VkViewport viewport = {};
11924 vp_state_create_info.pViewports = &viewport;
11925 vp_state_create_info.scissorCount = 1;
11926 VkRect2D scissors = {};
11927 vp_state_create_info.pScissors = &scissors;
11928
11929 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11930
11931 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11932 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11933 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11934 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11935
11936 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11937 vs.GetStageCreateInfo(),
11938 fs.GetStageCreateInfo()
11939 };
11940
11941 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11942 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11943
11944 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11945 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11946 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11947
11948 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11949 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11950 rasterization_state_create_info.pNext = nullptr;
11951 rasterization_state_create_info.lineWidth = 1.0f;
11952 rasterization_state_create_info.rasterizerDiscardEnable = true;
11953
11954 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11955 color_blend_attachment_state.blendEnable = VK_FALSE;
11956 color_blend_attachment_state.colorWriteMask = 0xf;
11957
11958 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11959 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11960 color_blend_state_create_info.attachmentCount = 1;
11961 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11962
11963 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11964 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11965 graphicspipe_create_info.stageCount = 2;
11966 graphicspipe_create_info.pStages = shader_stage_create_info;
11967 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11968 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11969 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11970 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11971 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11972 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11973 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11974 graphicspipe_create_info.layout = pipeline_layout;
11975 graphicspipe_create_info.renderPass = renderPass();
11976
11977 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
11978 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11979
11980 VkPipelineCache pipelineCache;
11981 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
11982
11983 // This structure maps constant ids to data locations.
11984 const VkSpecializationMapEntry entry =
11985 // id, offset, size
11986 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
11987
11988 uint32_t data = 1;
11989
11990 // Set up the info describing spec map and data
11991 const VkSpecializationInfo specialization_info = {
11992 1,
11993 &entry,
11994 1 * sizeof(float),
11995 &data,
11996 };
11997 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
11998
11999 VkPipeline pipeline;
12000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12001 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12002 m_errorMonitor->VerifyFound();
12003
12004 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12005 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12006}
12007
12008TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12009 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12010
12011 ASSERT_NO_FATAL_FAILURE(InitState());
12012 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12013
12014 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12015
12016 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12017 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12018 descriptor_pool_type_count[0].descriptorCount = 1;
12019 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12020 descriptor_pool_type_count[1].descriptorCount = 1;
12021
12022 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12023 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12024 descriptor_pool_create_info.maxSets = 1;
12025 descriptor_pool_create_info.poolSizeCount = 2;
12026 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12027 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12028
12029 VkDescriptorPool descriptorset_pool;
12030 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12031
12032 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12033 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12034 descriptorset_layout_binding.descriptorCount = 1;
12035 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12036
12037 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12038 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12039 descriptorset_layout_create_info.bindingCount = 1;
12040 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12041
12042 VkDescriptorSetLayout descriptorset_layout;
12043 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12044
12045 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12046 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12047 descriptorset_allocate_info.descriptorSetCount = 1;
12048 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12049 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12050 VkDescriptorSet descriptorset;
12051 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12052
12053 // Challenge core_validation with a non uniform buffer type.
12054 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12055
Mark Mueller098c9cb2016-09-08 09:01:57 -060012056 char const *vsSource =
12057 "#version 450\n"
12058 "\n"
12059 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12060 " mat4 mvp;\n"
12061 "} ubuf;\n"
12062 "out gl_PerVertex {\n"
12063 " vec4 gl_Position;\n"
12064 "};\n"
12065 "void main(){\n"
12066 " gl_Position = ubuf.mvp * vec4(1);\n"
12067 "}\n";
12068
12069 char const *fsSource =
12070 "#version 450\n"
12071 "\n"
12072 "layout(location = 0) out vec4 uFragColor;\n"
12073 "void main(){\n"
12074 " uFragColor = vec4(0,1,0,1);\n"
12075 "}\n";
12076
12077 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12078 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12079
12080 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12081 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12082 pipeline_layout_create_info.setLayoutCount = 1;
12083 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12084
12085 VkPipelineLayout pipeline_layout;
12086 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12087
12088 VkPipelineObj pipe(m_device);
12089 pipe.AddColorAttachment();
12090 pipe.AddShader(&vs);
12091 pipe.AddShader(&fs);
12092
12093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12094 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12095 m_errorMonitor->VerifyFound();
12096
12097 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12098 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12099 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12100}
12101
12102TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12103 TEST_DESCRIPTION(
12104 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12105
12106 ASSERT_NO_FATAL_FAILURE(InitState());
12107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12108
12109 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12110
12111 VkDescriptorPoolSize descriptor_pool_type_count = {};
12112 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12113 descriptor_pool_type_count.descriptorCount = 1;
12114
12115 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12116 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12117 descriptor_pool_create_info.maxSets = 1;
12118 descriptor_pool_create_info.poolSizeCount = 1;
12119 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12120 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12121
12122 VkDescriptorPool descriptorset_pool;
12123 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12124
12125 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12126 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12127 descriptorset_layout_binding.descriptorCount = 1;
12128 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12129 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12130
12131 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12132 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12133 descriptorset_layout_create_info.bindingCount = 1;
12134 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12135
12136 VkDescriptorSetLayout descriptorset_layout;
12137 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12138 nullptr, &descriptorset_layout));
12139
12140 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12141 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12142 descriptorset_allocate_info.descriptorSetCount = 1;
12143 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12144 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12145 VkDescriptorSet descriptorset;
12146 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12147
12148 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12149
Mark Mueller098c9cb2016-09-08 09:01:57 -060012150 char const *vsSource =
12151 "#version 450\n"
12152 "\n"
12153 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12154 " mat4 mvp;\n"
12155 "} ubuf;\n"
12156 "out gl_PerVertex {\n"
12157 " vec4 gl_Position;\n"
12158 "};\n"
12159 "void main(){\n"
12160 " gl_Position = ubuf.mvp * vec4(1);\n"
12161 "}\n";
12162
12163 char const *fsSource =
12164 "#version 450\n"
12165 "\n"
12166 "layout(location = 0) out vec4 uFragColor;\n"
12167 "void main(){\n"
12168 " uFragColor = vec4(0,1,0,1);\n"
12169 "}\n";
12170
12171 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12172 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12173
12174 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12175 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12176 pipeline_layout_create_info.setLayoutCount = 1;
12177 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12178
12179 VkPipelineLayout pipeline_layout;
12180 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12181
12182 VkPipelineObj pipe(m_device);
12183 pipe.AddColorAttachment();
12184 pipe.AddShader(&vs);
12185 pipe.AddShader(&fs);
12186
12187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12188 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12189 m_errorMonitor->VerifyFound();
12190
12191 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12192 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12193 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12194}
12195
12196TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12197 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12198 "accessible from the current shader stage.");
12199
12200 ASSERT_NO_FATAL_FAILURE(InitState());
12201 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12202
12203 const char *push_constant_not_accessible_message =
12204 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12205
12206 char const *vsSource =
12207 "#version 450\n"
12208 "\n"
12209 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12210 "out gl_PerVertex {\n"
12211 " vec4 gl_Position;\n"
12212 "};\n"
12213 "void main(){\n"
12214 " gl_Position = vec4(consts.x);\n"
12215 "}\n";
12216
12217 char const *fsSource =
12218 "#version 450\n"
12219 "\n"
12220 "layout(location = 0) out vec4 uFragColor;\n"
12221 "void main(){\n"
12222 " uFragColor = vec4(0,1,0,1);\n"
12223 "}\n";
12224
12225 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12226 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12227
12228 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12229 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12230
12231 // Set up a push constant range
12232 VkPushConstantRange push_constant_ranges = {};
12233 // Set to the wrong stage to challenge core_validation
12234 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12235 push_constant_ranges.size = 4;
12236
12237 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12238 pipeline_layout_create_info.pushConstantRangeCount = 1;
12239
12240 VkPipelineLayout pipeline_layout;
12241 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12242
12243 VkPipelineObj pipe(m_device);
12244 pipe.AddColorAttachment();
12245 pipe.AddShader(&vs);
12246 pipe.AddShader(&fs);
12247
12248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12249 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12250 m_errorMonitor->VerifyFound();
12251
12252 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12253}
12254
12255TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12256 TEST_DESCRIPTION(
12257 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12258
12259 ASSERT_NO_FATAL_FAILURE(InitState());
12260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12261
12262 const char *feature_not_enabled_message =
12263 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12264
12265 // Some awkward steps are required to test with custom device features.
12266 std::vector<const char *> device_extension_names;
12267 auto features = m_device->phy().features();
12268 // Disable support for 64 bit floats
12269 features.shaderFloat64 = false;
12270 // The sacrificial device object
12271 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12272
12273 char const *vsSource = "#version 450\n"
12274 "\n"
12275 "out gl_PerVertex {\n"
12276 " vec4 gl_Position;\n"
12277 "};\n"
12278 "void main(){\n"
12279 " gl_Position = vec4(1);\n"
12280 "}\n";
12281 char const *fsSource = "#version 450\n"
12282 "\n"
12283 "layout(location=0) out vec4 color;\n"
12284 "void main(){\n"
12285 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12286 " color = vec4(green);\n"
12287 "}\n";
12288
12289 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12290 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12291
12292 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012293
12294 VkPipelineObj pipe(&test_device);
12295 pipe.AddColorAttachment();
12296 pipe.AddShader(&vs);
12297 pipe.AddShader(&fs);
12298
12299 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12300 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12301 VkPipelineLayout pipeline_layout;
12302 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12303
12304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12305 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12306 m_errorMonitor->VerifyFound();
12307
12308 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12309}
12310
12311TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12312 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12313
12314 ASSERT_NO_FATAL_FAILURE(InitState());
12315 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12316
12317 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12318
12319 char const *vsSource = "#version 450\n"
12320 "\n"
12321 "out gl_PerVertex {\n"
12322 " vec4 gl_Position;\n"
12323 "};\n"
12324 "layout(xfb_buffer = 1) out;"
12325 "void main(){\n"
12326 " gl_Position = vec4(1);\n"
12327 "}\n";
12328 char const *fsSource = "#version 450\n"
12329 "\n"
12330 "layout(location=0) out vec4 color;\n"
12331 "void main(){\n"
12332 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12333 " color = vec4(green);\n"
12334 "}\n";
12335
12336 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12337 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12338
12339 VkPipelineObj pipe(m_device);
12340 pipe.AddColorAttachment();
12341 pipe.AddShader(&vs);
12342 pipe.AddShader(&fs);
12343
12344 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12345 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12346 VkPipelineLayout pipeline_layout;
12347 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12348
12349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12350 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12351 m_errorMonitor->VerifyFound();
12352
12353 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12354}
12355
Karl Schultz6addd812016-02-02 17:17:23 -070012356TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012357 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12358 "which is not present in the outputs of the previous stage");
12359
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012361
Chris Forbes59cb88d2015-05-25 11:13:13 +120012362 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012363 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012364
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012365 char const *vsSource = "#version 450\n"
12366 "\n"
12367 "out gl_PerVertex {\n"
12368 " vec4 gl_Position;\n"
12369 "};\n"
12370 "void main(){\n"
12371 " gl_Position = vec4(1);\n"
12372 "}\n";
12373 char const *fsSource = "#version 450\n"
12374 "\n"
12375 "layout(location=0) in float x;\n"
12376 "layout(location=0) out vec4 color;\n"
12377 "void main(){\n"
12378 " color = vec4(x);\n"
12379 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012380
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012381 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12382 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012383
12384 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012385 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012386 pipe.AddShader(&vs);
12387 pipe.AddShader(&fs);
12388
Chris Forbes59cb88d2015-05-25 11:13:13 +120012389 VkDescriptorSetObj descriptorSet(m_device);
12390 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012391 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012392
Tony Barbour5781e8f2015-08-04 16:23:11 -060012393 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012394
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012395 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012396}
12397
Karl Schultz6addd812016-02-02 17:17:23 -070012398TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012399 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12400 "within an interace block, which is not present in the outputs "
12401 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012403
12404 ASSERT_NO_FATAL_FAILURE(InitState());
12405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12406
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012407 char const *vsSource = "#version 450\n"
12408 "\n"
12409 "out gl_PerVertex {\n"
12410 " vec4 gl_Position;\n"
12411 "};\n"
12412 "void main(){\n"
12413 " gl_Position = vec4(1);\n"
12414 "}\n";
12415 char const *fsSource = "#version 450\n"
12416 "\n"
12417 "in block { layout(location=0) float x; } ins;\n"
12418 "layout(location=0) out vec4 color;\n"
12419 "void main(){\n"
12420 " color = vec4(ins.x);\n"
12421 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012422
12423 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12424 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12425
12426 VkPipelineObj pipe(m_device);
12427 pipe.AddColorAttachment();
12428 pipe.AddShader(&vs);
12429 pipe.AddShader(&fs);
12430
12431 VkDescriptorSetObj descriptorSet(m_device);
12432 descriptorSet.AppendDummy();
12433 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12434
12435 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12436
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012437 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012438}
12439
Karl Schultz6addd812016-02-02 17:17:23 -070012440TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012441 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012442 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12444 "output arr[2] of float32' vs 'ptr to "
12445 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012446
12447 ASSERT_NO_FATAL_FAILURE(InitState());
12448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012450 char const *vsSource = "#version 450\n"
12451 "\n"
12452 "layout(location=0) out float x[2];\n"
12453 "out gl_PerVertex {\n"
12454 " vec4 gl_Position;\n"
12455 "};\n"
12456 "void main(){\n"
12457 " x[0] = 0; x[1] = 0;\n"
12458 " gl_Position = vec4(1);\n"
12459 "}\n";
12460 char const *fsSource = "#version 450\n"
12461 "\n"
12462 "layout(location=0) in float x[3];\n"
12463 "layout(location=0) out vec4 color;\n"
12464 "void main(){\n"
12465 " color = vec4(x[0] + x[1] + x[2]);\n"
12466 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012467
12468 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12469 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12470
12471 VkPipelineObj pipe(m_device);
12472 pipe.AddColorAttachment();
12473 pipe.AddShader(&vs);
12474 pipe.AddShader(&fs);
12475
12476 VkDescriptorSetObj descriptorSet(m_device);
12477 descriptorSet.AppendDummy();
12478 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12479
12480 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12481
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012482 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012483}
12484
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012485
Karl Schultz6addd812016-02-02 17:17:23 -070012486TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012487 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012488 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012490
Chris Forbesb56af562015-05-25 11:13:17 +120012491 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012492 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012493
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012494 char const *vsSource = "#version 450\n"
12495 "\n"
12496 "layout(location=0) out int x;\n"
12497 "out gl_PerVertex {\n"
12498 " vec4 gl_Position;\n"
12499 "};\n"
12500 "void main(){\n"
12501 " x = 0;\n"
12502 " gl_Position = vec4(1);\n"
12503 "}\n";
12504 char const *fsSource = "#version 450\n"
12505 "\n"
12506 "layout(location=0) in float x;\n" /* VS writes int */
12507 "layout(location=0) out vec4 color;\n"
12508 "void main(){\n"
12509 " color = vec4(x);\n"
12510 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012511
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012512 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12513 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012514
12515 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012516 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012517 pipe.AddShader(&vs);
12518 pipe.AddShader(&fs);
12519
Chris Forbesb56af562015-05-25 11:13:17 +120012520 VkDescriptorSetObj descriptorSet(m_device);
12521 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012522 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012523
Tony Barbour5781e8f2015-08-04 16:23:11 -060012524 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012525
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012526 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012527}
12528
Karl Schultz6addd812016-02-02 17:17:23 -070012529TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012530 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012531 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012532 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012534
12535 ASSERT_NO_FATAL_FAILURE(InitState());
12536 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12537
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012538 char const *vsSource = "#version 450\n"
12539 "\n"
12540 "out block { layout(location=0) int x; } outs;\n"
12541 "out gl_PerVertex {\n"
12542 " vec4 gl_Position;\n"
12543 "};\n"
12544 "void main(){\n"
12545 " outs.x = 0;\n"
12546 " gl_Position = vec4(1);\n"
12547 "}\n";
12548 char const *fsSource = "#version 450\n"
12549 "\n"
12550 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12551 "layout(location=0) out vec4 color;\n"
12552 "void main(){\n"
12553 " color = vec4(ins.x);\n"
12554 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012555
12556 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12557 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12558
12559 VkPipelineObj pipe(m_device);
12560 pipe.AddColorAttachment();
12561 pipe.AddShader(&vs);
12562 pipe.AddShader(&fs);
12563
12564 VkDescriptorSetObj descriptorSet(m_device);
12565 descriptorSet.AppendDummy();
12566 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12567
12568 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12569
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012570 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012571}
12572
12573TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012574 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012575 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012576 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0.0 which is not written by vertex shader");
Chris Forbese9928822016-02-17 14:44:52 +130012578
12579 ASSERT_NO_FATAL_FAILURE(InitState());
12580 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12581
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012582 char const *vsSource = "#version 450\n"
12583 "\n"
12584 "out block { layout(location=1) float x; } outs;\n"
12585 "out gl_PerVertex {\n"
12586 " vec4 gl_Position;\n"
12587 "};\n"
12588 "void main(){\n"
12589 " outs.x = 0;\n"
12590 " gl_Position = vec4(1);\n"
12591 "}\n";
12592 char const *fsSource = "#version 450\n"
12593 "\n"
12594 "in block { layout(location=0) float x; } ins;\n"
12595 "layout(location=0) out vec4 color;\n"
12596 "void main(){\n"
12597 " color = vec4(ins.x);\n"
12598 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012599
12600 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12601 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12602
12603 VkPipelineObj pipe(m_device);
12604 pipe.AddColorAttachment();
12605 pipe.AddShader(&vs);
12606 pipe.AddShader(&fs);
12607
12608 VkDescriptorSetObj descriptorSet(m_device);
12609 descriptorSet.AppendDummy();
12610 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12611
12612 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12613
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012614 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012615}
12616
12617TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012618 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012619 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012620 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0.1 which is not written by vertex shader");
Chris Forbese9928822016-02-17 14:44:52 +130012622
12623 ASSERT_NO_FATAL_FAILURE(InitState());
12624 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12625
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012626 char const *vsSource = "#version 450\n"
12627 "\n"
12628 "out block { layout(location=0, component=0) float x; } outs;\n"
12629 "out gl_PerVertex {\n"
12630 " vec4 gl_Position;\n"
12631 "};\n"
12632 "void main(){\n"
12633 " outs.x = 0;\n"
12634 " gl_Position = vec4(1);\n"
12635 "}\n";
12636 char const *fsSource = "#version 450\n"
12637 "\n"
12638 "in block { layout(location=0, component=1) float x; } ins;\n"
12639 "layout(location=0) out vec4 color;\n"
12640 "void main(){\n"
12641 " color = vec4(ins.x);\n"
12642 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012643
12644 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12645 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12646
12647 VkPipelineObj pipe(m_device);
12648 pipe.AddColorAttachment();
12649 pipe.AddShader(&vs);
12650 pipe.AddShader(&fs);
12651
12652 VkDescriptorSetObj descriptorSet(m_device);
12653 descriptorSet.AppendDummy();
12654 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12655
12656 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12657
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012658 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012659}
12660
Karl Schultz6addd812016-02-02 17:17:23 -070012661TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012662 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12663 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012665
Chris Forbesde136e02015-05-25 11:13:28 +120012666 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012667 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012668
12669 VkVertexInputBindingDescription input_binding;
12670 memset(&input_binding, 0, sizeof(input_binding));
12671
12672 VkVertexInputAttributeDescription input_attrib;
12673 memset(&input_attrib, 0, sizeof(input_attrib));
12674 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12675
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012676 char const *vsSource = "#version 450\n"
12677 "\n"
12678 "out gl_PerVertex {\n"
12679 " vec4 gl_Position;\n"
12680 "};\n"
12681 "void main(){\n"
12682 " gl_Position = vec4(1);\n"
12683 "}\n";
12684 char const *fsSource = "#version 450\n"
12685 "\n"
12686 "layout(location=0) out vec4 color;\n"
12687 "void main(){\n"
12688 " color = vec4(1);\n"
12689 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012690
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012691 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12692 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012693
12694 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012695 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012696 pipe.AddShader(&vs);
12697 pipe.AddShader(&fs);
12698
12699 pipe.AddVertexInputBindings(&input_binding, 1);
12700 pipe.AddVertexInputAttribs(&input_attrib, 1);
12701
Chris Forbesde136e02015-05-25 11:13:28 +120012702 VkDescriptorSetObj descriptorSet(m_device);
12703 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012704 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012705
Tony Barbour5781e8f2015-08-04 16:23:11 -060012706 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012707
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012708 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012709}
12710
Karl Schultz6addd812016-02-02 17:17:23 -070012711TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012712 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12713 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012715
12716 ASSERT_NO_FATAL_FAILURE(InitState());
12717 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12718
12719 VkVertexInputBindingDescription input_binding;
12720 memset(&input_binding, 0, sizeof(input_binding));
12721
12722 VkVertexInputAttributeDescription input_attrib;
12723 memset(&input_attrib, 0, sizeof(input_attrib));
12724 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12725
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012726 char const *vsSource = "#version 450\n"
12727 "\n"
12728 "layout(location=1) in float x;\n"
12729 "out gl_PerVertex {\n"
12730 " vec4 gl_Position;\n"
12731 "};\n"
12732 "void main(){\n"
12733 " gl_Position = vec4(x);\n"
12734 "}\n";
12735 char const *fsSource = "#version 450\n"
12736 "\n"
12737 "layout(location=0) out vec4 color;\n"
12738 "void main(){\n"
12739 " color = vec4(1);\n"
12740 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012741
12742 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12743 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12744
12745 VkPipelineObj pipe(m_device);
12746 pipe.AddColorAttachment();
12747 pipe.AddShader(&vs);
12748 pipe.AddShader(&fs);
12749
12750 pipe.AddVertexInputBindings(&input_binding, 1);
12751 pipe.AddVertexInputAttribs(&input_attrib, 1);
12752
12753 VkDescriptorSetObj descriptorSet(m_device);
12754 descriptorSet.AppendDummy();
12755 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12756
12757 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12758
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012759 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012760}
12761
Karl Schultz6addd812016-02-02 17:17:23 -070012762TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012763 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012764 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012766
Chris Forbes62e8e502015-05-25 11:13:29 +120012767 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012769
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012770 char const *vsSource = "#version 450\n"
12771 "\n"
12772 "layout(location=0) in vec4 x;\n" /* not provided */
12773 "out gl_PerVertex {\n"
12774 " vec4 gl_Position;\n"
12775 "};\n"
12776 "void main(){\n"
12777 " gl_Position = x;\n"
12778 "}\n";
12779 char const *fsSource = "#version 450\n"
12780 "\n"
12781 "layout(location=0) out vec4 color;\n"
12782 "void main(){\n"
12783 " color = vec4(1);\n"
12784 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012785
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012786 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12787 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012788
12789 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012790 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012791 pipe.AddShader(&vs);
12792 pipe.AddShader(&fs);
12793
Chris Forbes62e8e502015-05-25 11:13:29 +120012794 VkDescriptorSetObj descriptorSet(m_device);
12795 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012796 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012797
Tony Barbour5781e8f2015-08-04 16:23:11 -060012798 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012799
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012800 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012801}
12802
Karl Schultz6addd812016-02-02 17:17:23 -070012803TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012804 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12805 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012806 "vertex shader input that consumes it");
12807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match vertex shader input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012808
Chris Forbesc97d98e2015-05-25 11:13:31 +120012809 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012811
12812 VkVertexInputBindingDescription input_binding;
12813 memset(&input_binding, 0, sizeof(input_binding));
12814
12815 VkVertexInputAttributeDescription input_attrib;
12816 memset(&input_attrib, 0, sizeof(input_attrib));
12817 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12818
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012819 char const *vsSource = "#version 450\n"
12820 "\n"
12821 "layout(location=0) in int x;\n" /* attrib provided float */
12822 "out gl_PerVertex {\n"
12823 " vec4 gl_Position;\n"
12824 "};\n"
12825 "void main(){\n"
12826 " gl_Position = vec4(x);\n"
12827 "}\n";
12828 char const *fsSource = "#version 450\n"
12829 "\n"
12830 "layout(location=0) out vec4 color;\n"
12831 "void main(){\n"
12832 " color = vec4(1);\n"
12833 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012834
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012835 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12836 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012837
12838 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012839 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012840 pipe.AddShader(&vs);
12841 pipe.AddShader(&fs);
12842
12843 pipe.AddVertexInputBindings(&input_binding, 1);
12844 pipe.AddVertexInputAttribs(&input_attrib, 1);
12845
Chris Forbesc97d98e2015-05-25 11:13:31 +120012846 VkDescriptorSetObj descriptorSet(m_device);
12847 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012848 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012849
Tony Barbour5781e8f2015-08-04 16:23:11 -060012850 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012851
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012852 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012853}
12854
Chris Forbesc68b43c2016-04-06 11:18:47 +120012855TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012856 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12857 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12859 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012860
12861 ASSERT_NO_FATAL_FAILURE(InitState());
12862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12863
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012864 char const *vsSource = "#version 450\n"
12865 "\n"
12866 "out gl_PerVertex {\n"
12867 " vec4 gl_Position;\n"
12868 "};\n"
12869 "void main(){\n"
12870 " gl_Position = vec4(1);\n"
12871 "}\n";
12872 char const *fsSource = "#version 450\n"
12873 "\n"
12874 "layout(location=0) out vec4 color;\n"
12875 "void main(){\n"
12876 " color = vec4(1);\n"
12877 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012878
12879 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12880 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12881
12882 VkPipelineObj pipe(m_device);
12883 pipe.AddColorAttachment();
12884 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012885 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012886 pipe.AddShader(&fs);
12887
12888 VkDescriptorSetObj descriptorSet(m_device);
12889 descriptorSet.AppendDummy();
12890 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12891
12892 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12893
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012894 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012895}
12896
Chris Forbes82ff92a2016-09-09 10:50:24 +120012897TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12899 "No entrypoint found named `foo`");
12900
12901 ASSERT_NO_FATAL_FAILURE(InitState());
12902 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12903
12904 char const *vsSource = "#version 450\n"
12905 "out gl_PerVertex {\n"
12906 " vec4 gl_Position;\n"
12907 "};\n"
12908 "void main(){\n"
12909 " gl_Position = vec4(0);\n"
12910 "}\n";
12911 char const *fsSource = "#version 450\n"
12912 "\n"
12913 "layout(location=0) out vec4 color;\n"
12914 "void main(){\n"
12915 " color = vec4(1);\n"
12916 "}\n";
12917
12918 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12919 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12920
12921 VkPipelineObj pipe(m_device);
12922 pipe.AddColorAttachment();
12923 pipe.AddShader(&vs);
12924 pipe.AddShader(&fs);
12925
12926 VkDescriptorSetObj descriptorSet(m_device);
12927 descriptorSet.AppendDummy();
12928 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12929
12930 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12931
12932 m_errorMonitor->VerifyFound();
12933}
12934
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012935TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12936 m_errorMonitor->SetDesiredFailureMsg(
12937 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12938 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12939 "uses a depth/stencil attachment");
12940
12941 ASSERT_NO_FATAL_FAILURE(InitState());
12942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12943
12944 char const *vsSource = "#version 450\n"
12945 "void main(){ gl_Position = vec4(0); }\n";
12946 char const *fsSource = "#version 450\n"
12947 "\n"
12948 "layout(location=0) out vec4 color;\n"
12949 "void main(){\n"
12950 " color = vec4(1);\n"
12951 "}\n";
12952
12953 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12954 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12955
12956 VkPipelineObj pipe(m_device);
12957 pipe.AddColorAttachment();
12958 pipe.AddShader(&vs);
12959 pipe.AddShader(&fs);
12960
12961 VkDescriptorSetObj descriptorSet(m_device);
12962 descriptorSet.AppendDummy();
12963 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12964
12965 VkAttachmentDescription attachments[] = {
12966 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12967 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12968 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12969 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12970 },
12971 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12972 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12973 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12974 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12975 },
12976 };
12977 VkAttachmentReference refs[] = {
12978 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
12979 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
12980 };
12981 VkSubpassDescription subpass = {
12982 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
12983 1, &refs[0], nullptr, &refs[1],
12984 0, nullptr
12985 };
12986 VkRenderPassCreateInfo rpci = {
12987 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
12988 0, 2, attachments, 1, &subpass, 0, nullptr
12989 };
12990 VkRenderPass rp;
12991 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12992 ASSERT_VK_SUCCESS(err);
12993
12994 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
12995
12996 m_errorMonitor->VerifyFound();
12997
12998 vkDestroyRenderPass(m_device->device(), rp, nullptr);
12999}
13000
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013001TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013002 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13003 "the TCS without the patch decoration, but consumed in the TES "
13004 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13006 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013007
13008 ASSERT_NO_FATAL_FAILURE(InitState());
13009 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13010
Chris Forbesc1e852d2016-04-04 19:26:42 +120013011 if (!m_device->phy().features().tessellationShader) {
13012 printf("Device does not support tessellation shaders; skipped.\n");
13013 return;
13014 }
13015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013016 char const *vsSource = "#version 450\n"
13017 "void main(){}\n";
13018 char const *tcsSource = "#version 450\n"
13019 "layout(location=0) out int x[];\n"
13020 "layout(vertices=3) out;\n"
13021 "void main(){\n"
13022 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13023 " gl_TessLevelInner[0] = 1;\n"
13024 " x[gl_InvocationID] = gl_InvocationID;\n"
13025 "}\n";
13026 char const *tesSource = "#version 450\n"
13027 "layout(triangles, equal_spacing, cw) in;\n"
13028 "layout(location=0) patch in int x;\n"
13029 "out gl_PerVertex { vec4 gl_Position; };\n"
13030 "void main(){\n"
13031 " gl_Position.xyz = gl_TessCoord;\n"
13032 " gl_Position.w = x;\n"
13033 "}\n";
13034 char const *fsSource = "#version 450\n"
13035 "layout(location=0) out vec4 color;\n"
13036 "void main(){\n"
13037 " color = vec4(1);\n"
13038 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013039
13040 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13041 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13042 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13043 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13044
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013045 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13046 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013047
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013048 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013049
13050 VkPipelineObj pipe(m_device);
13051 pipe.SetInputAssembly(&iasci);
13052 pipe.SetTessellation(&tsci);
13053 pipe.AddColorAttachment();
13054 pipe.AddShader(&vs);
13055 pipe.AddShader(&tcs);
13056 pipe.AddShader(&tes);
13057 pipe.AddShader(&fs);
13058
13059 VkDescriptorSetObj descriptorSet(m_device);
13060 descriptorSet.AppendDummy();
13061 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13062
13063 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13064
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013065 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013066}
13067
Karl Schultz6addd812016-02-02 17:17:23 -070013068TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013069 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13070 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13072 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013073
Chris Forbes280ba2c2015-06-12 11:16:41 +120013074 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013075 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013076
13077 /* Two binding descriptions for binding 0 */
13078 VkVertexInputBindingDescription input_bindings[2];
13079 memset(input_bindings, 0, sizeof(input_bindings));
13080
13081 VkVertexInputAttributeDescription input_attrib;
13082 memset(&input_attrib, 0, sizeof(input_attrib));
13083 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13084
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013085 char const *vsSource = "#version 450\n"
13086 "\n"
13087 "layout(location=0) in float x;\n" /* attrib provided float */
13088 "out gl_PerVertex {\n"
13089 " vec4 gl_Position;\n"
13090 "};\n"
13091 "void main(){\n"
13092 " gl_Position = vec4(x);\n"
13093 "}\n";
13094 char const *fsSource = "#version 450\n"
13095 "\n"
13096 "layout(location=0) out vec4 color;\n"
13097 "void main(){\n"
13098 " color = vec4(1);\n"
13099 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013100
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013101 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13102 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013103
13104 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013105 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013106 pipe.AddShader(&vs);
13107 pipe.AddShader(&fs);
13108
13109 pipe.AddVertexInputBindings(input_bindings, 2);
13110 pipe.AddVertexInputAttribs(&input_attrib, 1);
13111
Chris Forbes280ba2c2015-06-12 11:16:41 +120013112 VkDescriptorSetObj descriptorSet(m_device);
13113 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013114 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013115
Tony Barbour5781e8f2015-08-04 16:23:11 -060013116 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013117
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013118 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013119}
Chris Forbes8f68b562015-05-25 11:13:32 +120013120
Karl Schultz6addd812016-02-02 17:17:23 -070013121TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013122 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013123 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013125
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013126 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013128 char const *vsSource = "#version 450\n"
13129 "\n"
13130 "out gl_PerVertex {\n"
13131 " vec4 gl_Position;\n"
13132 "};\n"
13133 "void main(){\n"
13134 " gl_Position = vec4(1);\n"
13135 "}\n";
13136 char const *fsSource = "#version 450\n"
13137 "\n"
13138 "void main(){\n"
13139 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013140
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013141 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13142 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013143
13144 VkPipelineObj pipe(m_device);
13145 pipe.AddShader(&vs);
13146 pipe.AddShader(&fs);
13147
Chia-I Wu08accc62015-07-07 11:50:03 +080013148 /* set up CB 0, not written */
13149 pipe.AddColorAttachment();
13150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013151
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013152 VkDescriptorSetObj descriptorSet(m_device);
13153 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013154 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013155
Tony Barbour5781e8f2015-08-04 16:23:11 -060013156 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013157
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013158 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013159}
13160
Karl Schultz6addd812016-02-02 17:17:23 -070013161TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013162 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013163 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013165 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013166
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013167 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013168
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013169 char const *vsSource = "#version 450\n"
13170 "\n"
13171 "out gl_PerVertex {\n"
13172 " vec4 gl_Position;\n"
13173 "};\n"
13174 "void main(){\n"
13175 " gl_Position = vec4(1);\n"
13176 "}\n";
13177 char const *fsSource = "#version 450\n"
13178 "\n"
13179 "layout(location=0) out vec4 x;\n"
13180 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13181 "void main(){\n"
13182 " x = vec4(1);\n"
13183 " y = vec4(1);\n"
13184 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013185
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013186 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13187 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013188
13189 VkPipelineObj pipe(m_device);
13190 pipe.AddShader(&vs);
13191 pipe.AddShader(&fs);
13192
Chia-I Wu08accc62015-07-07 11:50:03 +080013193 /* set up CB 0, not written */
13194 pipe.AddColorAttachment();
13195 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013196 /* FS writes CB 1, but we don't configure it */
13197
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013198 VkDescriptorSetObj descriptorSet(m_device);
13199 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013200 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013201
Tony Barbour5781e8f2015-08-04 16:23:11 -060013202 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013203
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013204 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013205}
13206
Karl Schultz6addd812016-02-02 17:17:23 -070013207TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013208 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013209 "type of an fragment shader output variable, and the format of the corresponding attachment");
13210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013211
Chris Forbesa36d69e2015-05-25 11:13:44 +120013212 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013214 char const *vsSource = "#version 450\n"
13215 "\n"
13216 "out gl_PerVertex {\n"
13217 " vec4 gl_Position;\n"
13218 "};\n"
13219 "void main(){\n"
13220 " gl_Position = vec4(1);\n"
13221 "}\n";
13222 char const *fsSource = "#version 450\n"
13223 "\n"
13224 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13225 "void main(){\n"
13226 " x = ivec4(1);\n"
13227 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013228
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013229 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13230 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013231
13232 VkPipelineObj pipe(m_device);
13233 pipe.AddShader(&vs);
13234 pipe.AddShader(&fs);
13235
Chia-I Wu08accc62015-07-07 11:50:03 +080013236 /* set up CB 0; type is UNORM by default */
13237 pipe.AddColorAttachment();
13238 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013239
Chris Forbesa36d69e2015-05-25 11:13:44 +120013240 VkDescriptorSetObj descriptorSet(m_device);
13241 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013242 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013243
Tony Barbour5781e8f2015-08-04 16:23:11 -060013244 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013245
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013246 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013247}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013248
Karl Schultz6addd812016-02-02 17:17:23 -070013249TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013250 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13251 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013253
Chris Forbes556c76c2015-08-14 12:04:59 +120013254 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013255
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013256 char const *vsSource = "#version 450\n"
13257 "\n"
13258 "out gl_PerVertex {\n"
13259 " vec4 gl_Position;\n"
13260 "};\n"
13261 "void main(){\n"
13262 " gl_Position = vec4(1);\n"
13263 "}\n";
13264 char const *fsSource = "#version 450\n"
13265 "\n"
13266 "layout(location=0) out vec4 x;\n"
13267 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13268 "void main(){\n"
13269 " x = vec4(bar.y);\n"
13270 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013271
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013272 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13273 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013274
Chris Forbes556c76c2015-08-14 12:04:59 +120013275 VkPipelineObj pipe(m_device);
13276 pipe.AddShader(&vs);
13277 pipe.AddShader(&fs);
13278
13279 /* set up CB 0; type is UNORM by default */
13280 pipe.AddColorAttachment();
13281 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13282
13283 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013284 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013285
13286 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13287
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013288 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013289}
13290
Chris Forbes5c59e902016-02-26 16:56:09 +130013291TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013292 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13293 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013295
13296 ASSERT_NO_FATAL_FAILURE(InitState());
13297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013298 char const *vsSource = "#version 450\n"
13299 "\n"
13300 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13301 "out gl_PerVertex {\n"
13302 " vec4 gl_Position;\n"
13303 "};\n"
13304 "void main(){\n"
13305 " gl_Position = vec4(consts.x);\n"
13306 "}\n";
13307 char const *fsSource = "#version 450\n"
13308 "\n"
13309 "layout(location=0) out vec4 x;\n"
13310 "void main(){\n"
13311 " x = vec4(1);\n"
13312 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013313
13314 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13315 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13316
13317 VkPipelineObj pipe(m_device);
13318 pipe.AddShader(&vs);
13319 pipe.AddShader(&fs);
13320
13321 /* set up CB 0; type is UNORM by default */
13322 pipe.AddColorAttachment();
13323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13324
13325 VkDescriptorSetObj descriptorSet(m_device);
13326 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13327
13328 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13329
13330 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013331 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013332}
13333
Chris Forbes3fb17902016-08-22 14:57:55 +120013334TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13335 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13336 "which is not included in the subpass description");
13337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13338 "consumes input attachment index 0 but not provided in subpass");
13339
13340 ASSERT_NO_FATAL_FAILURE(InitState());
13341
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013342 char const *vsSource = "#version 450\n"
13343 "\n"
13344 "out gl_PerVertex {\n"
13345 " vec4 gl_Position;\n"
13346 "};\n"
13347 "void main(){\n"
13348 " gl_Position = vec4(1);\n"
13349 "}\n";
13350 char const *fsSource = "#version 450\n"
13351 "\n"
13352 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13353 "layout(location=0) out vec4 color;\n"
13354 "void main() {\n"
13355 " color = subpassLoad(x);\n"
13356 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013357
13358 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13359 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13360
13361 VkPipelineObj pipe(m_device);
13362 pipe.AddShader(&vs);
13363 pipe.AddShader(&fs);
13364 pipe.AddColorAttachment();
13365 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13366
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013367 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13368 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013369 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013370 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013371 ASSERT_VK_SUCCESS(err);
13372
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013373 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013374 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013375 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013376 ASSERT_VK_SUCCESS(err);
13377
13378 // error here.
13379 pipe.CreateVKPipeline(pl, renderPass());
13380
13381 m_errorMonitor->VerifyFound();
13382
13383 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13384 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13385}
13386
Chris Forbes5a9a0472016-08-22 16:02:09 +120013387TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13388 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13389 "with a format having a different fundamental type");
13390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13391 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13392
13393 ASSERT_NO_FATAL_FAILURE(InitState());
13394
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013395 char const *vsSource = "#version 450\n"
13396 "\n"
13397 "out gl_PerVertex {\n"
13398 " vec4 gl_Position;\n"
13399 "};\n"
13400 "void main(){\n"
13401 " gl_Position = vec4(1);\n"
13402 "}\n";
13403 char const *fsSource = "#version 450\n"
13404 "\n"
13405 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13406 "layout(location=0) out vec4 color;\n"
13407 "void main() {\n"
13408 " color = subpassLoad(x);\n"
13409 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013410
13411 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13412 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13413
13414 VkPipelineObj pipe(m_device);
13415 pipe.AddShader(&vs);
13416 pipe.AddShader(&fs);
13417 pipe.AddColorAttachment();
13418 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13419
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013420 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13421 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013422 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013423 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013424 ASSERT_VK_SUCCESS(err);
13425
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013426 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013427 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013428 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013429 ASSERT_VK_SUCCESS(err);
13430
13431 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013432 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13433 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13434 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13435 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13436 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL},
Chris Forbes5a9a0472016-08-22 16:02:09 +120013437 };
13438 VkAttachmentReference color = {
13439 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13440 };
13441 VkAttachmentReference input = {
13442 1, VK_IMAGE_LAYOUT_GENERAL,
13443 };
13444
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013445 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013447 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013448 VkRenderPass rp;
13449 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13450 ASSERT_VK_SUCCESS(err);
13451
13452 // error here.
13453 pipe.CreateVKPipeline(pl, rp);
13454
13455 m_errorMonitor->VerifyFound();
13456
13457 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13458 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13459 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13460}
13461
Chris Forbes541f7b02016-08-22 15:30:27 +120013462TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13463 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13464 "which is not included in the subpass description -- array case");
13465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13466 "consumes input attachment index 1 but not provided in subpass");
13467
13468 ASSERT_NO_FATAL_FAILURE(InitState());
13469
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013470 char const *vsSource = "#version 450\n"
13471 "\n"
13472 "out gl_PerVertex {\n"
13473 " vec4 gl_Position;\n"
13474 "};\n"
13475 "void main(){\n"
13476 " gl_Position = vec4(1);\n"
13477 "}\n";
13478 char const *fsSource = "#version 450\n"
13479 "\n"
13480 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13481 "layout(location=0) out vec4 color;\n"
13482 "void main() {\n"
13483 " color = subpassLoad(xs[1]);\n"
13484 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013485
13486 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13487 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13488
13489 VkPipelineObj pipe(m_device);
13490 pipe.AddShader(&vs);
13491 pipe.AddShader(&fs);
13492 pipe.AddColorAttachment();
13493 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13494
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013495 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13496 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013497 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013498 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013499 ASSERT_VK_SUCCESS(err);
13500
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013501 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013502 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013503 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013504 ASSERT_VK_SUCCESS(err);
13505
13506 // error here.
13507 pipe.CreateVKPipeline(pl, renderPass());
13508
13509 m_errorMonitor->VerifyFound();
13510
13511 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13512 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13513}
13514
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013515TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013516 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13517 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013519
13520 ASSERT_NO_FATAL_FAILURE(InitState());
13521
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013522 char const *csSource = "#version 450\n"
13523 "\n"
13524 "layout(local_size_x=1) in;\n"
13525 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13526 "void main(){\n"
13527 " x = vec4(1);\n"
13528 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013529
13530 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13531
13532 VkDescriptorSetObj descriptorSet(m_device);
13533 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13534
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013535 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13536 nullptr,
13537 0,
13538 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13539 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13540 descriptorSet.GetPipelineLayout(),
13541 VK_NULL_HANDLE,
13542 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013543
13544 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013545 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013546
13547 m_errorMonitor->VerifyFound();
13548
13549 if (err == VK_SUCCESS) {
13550 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13551 }
13552}
13553
Chris Forbes22a9b092016-07-19 14:34:05 +120013554TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013555 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13556 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13558 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013559
13560 ASSERT_NO_FATAL_FAILURE(InitState());
13561
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013562 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13563 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013564 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013565 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013566 ASSERT_VK_SUCCESS(err);
13567
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013568 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013569 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013570 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013571 ASSERT_VK_SUCCESS(err);
13572
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013573 char const *csSource = "#version 450\n"
13574 "\n"
13575 "layout(local_size_x=1) in;\n"
13576 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13577 "void main() {\n"
13578 " x.x = 1.0f;\n"
13579 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013580 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13581
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013582 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13583 nullptr,
13584 0,
13585 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13586 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13587 pl,
13588 VK_NULL_HANDLE,
13589 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013590
13591 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013592 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013593
13594 m_errorMonitor->VerifyFound();
13595
13596 if (err == VK_SUCCESS) {
13597 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13598 }
13599
13600 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13601 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13602}
13603
Chris Forbes50020592016-07-27 13:52:41 +120013604TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13605 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13606 "does not match the dimensionality declared in the shader");
13607
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires an image view of type VK_IMAGE_VIEW_TYPE_3D");
Chris Forbes50020592016-07-27 13:52:41 +120013609
13610 ASSERT_NO_FATAL_FAILURE(InitState());
13611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13612
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013613 char const *vsSource = "#version 450\n"
13614 "\n"
13615 "out gl_PerVertex { vec4 gl_Position; };\n"
13616 "void main() { gl_Position = vec4(0); }\n";
13617 char const *fsSource = "#version 450\n"
13618 "\n"
13619 "layout(set=0, binding=0) uniform sampler3D s;\n"
13620 "layout(location=0) out vec4 color;\n"
13621 "void main() {\n"
13622 " color = texture(s, vec3(0));\n"
13623 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013624 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13625 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13626
13627 VkPipelineObj pipe(m_device);
13628 pipe.AddShader(&vs);
13629 pipe.AddShader(&fs);
13630 pipe.AddColorAttachment();
13631
13632 VkTextureObj texture(m_device, nullptr);
13633 VkSamplerObj sampler(m_device);
13634
13635 VkDescriptorSetObj descriptorSet(m_device);
13636 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13637 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13638
13639 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13640 ASSERT_VK_SUCCESS(err);
13641
13642 BeginCommandBuffer();
13643
13644 m_commandBuffer->BindPipeline(pipe);
13645 m_commandBuffer->BindDescriptorSet(descriptorSet);
13646
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013647 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013648 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013649 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013650 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13651
13652 // error produced here.
13653 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13654
13655 m_errorMonitor->VerifyFound();
13656
13657 EndCommandBuffer();
13658}
13659
Chris Forbes5533bfc2016-07-27 14:12:34 +120013660TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13661 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13662 "are consumed via singlesample images types in the shader, or vice versa.");
13663
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013665
13666 ASSERT_NO_FATAL_FAILURE(InitState());
13667 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13668
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013669 char const *vsSource = "#version 450\n"
13670 "\n"
13671 "out gl_PerVertex { vec4 gl_Position; };\n"
13672 "void main() { gl_Position = vec4(0); }\n";
13673 char const *fsSource = "#version 450\n"
13674 "\n"
13675 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13676 "layout(location=0) out vec4 color;\n"
13677 "void main() {\n"
13678 " color = texelFetch(s, ivec2(0), 0);\n"
13679 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013680 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13681 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13682
13683 VkPipelineObj pipe(m_device);
13684 pipe.AddShader(&vs);
13685 pipe.AddShader(&fs);
13686 pipe.AddColorAttachment();
13687
13688 VkTextureObj texture(m_device, nullptr);
13689 VkSamplerObj sampler(m_device);
13690
13691 VkDescriptorSetObj descriptorSet(m_device);
13692 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13693 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13694
13695 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13696 ASSERT_VK_SUCCESS(err);
13697
13698 BeginCommandBuffer();
13699
13700 m_commandBuffer->BindPipeline(pipe);
13701 m_commandBuffer->BindDescriptorSet(descriptorSet);
13702
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013703 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013704 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013705 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013706 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13707
13708 // error produced here.
13709 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13710
13711 m_errorMonitor->VerifyFound();
13712
13713 EndCommandBuffer();
13714}
13715
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013716#endif // SHADER_CHECKER_TESTS
13717
13718#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013719TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013721
13722 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013723
13724 // Create an image
13725 VkImage image;
13726
Karl Schultz6addd812016-02-02 17:17:23 -070013727 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13728 const int32_t tex_width = 32;
13729 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013730
13731 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013732 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13733 image_create_info.pNext = NULL;
13734 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13735 image_create_info.format = tex_format;
13736 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013737 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013738 image_create_info.extent.depth = 1;
13739 image_create_info.mipLevels = 1;
13740 image_create_info.arrayLayers = 1;
13741 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13742 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13743 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13744 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013745
13746 // Introduce error by sending down a bogus width extent
13747 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013748 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013749
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013750 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013751}
13752
Mark Youngc48c4c12016-04-11 14:26:49 -060013753TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13755 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013756
13757 ASSERT_NO_FATAL_FAILURE(InitState());
13758
13759 // Create an image
13760 VkImage image;
13761
13762 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13763 const int32_t tex_width = 32;
13764 const int32_t tex_height = 32;
13765
13766 VkImageCreateInfo image_create_info = {};
13767 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13768 image_create_info.pNext = NULL;
13769 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13770 image_create_info.format = tex_format;
13771 image_create_info.extent.width = tex_width;
13772 image_create_info.extent.height = tex_height;
13773 image_create_info.extent.depth = 1;
13774 image_create_info.mipLevels = 1;
13775 image_create_info.arrayLayers = 1;
13776 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13777 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13778 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13779 image_create_info.flags = 0;
13780
13781 // Introduce error by sending down a bogus width extent
13782 image_create_info.extent.width = 0;
13783 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13784
13785 m_errorMonitor->VerifyFound();
13786}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013787#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013788
Tobin Ehliscde08892015-09-22 10:11:37 -060013789#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070013790
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013791TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13792 TEST_DESCRIPTION("Create a render pass with an attachment description "
13793 "format set to VK_FORMAT_UNDEFINED");
13794
13795 ASSERT_NO_FATAL_FAILURE(InitState());
13796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13797
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013799
13800 VkAttachmentReference color_attach = {};
13801 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13802 color_attach.attachment = 0;
13803 VkSubpassDescription subpass = {};
13804 subpass.colorAttachmentCount = 1;
13805 subpass.pColorAttachments = &color_attach;
13806
13807 VkRenderPassCreateInfo rpci = {};
13808 rpci.subpassCount = 1;
13809 rpci.pSubpasses = &subpass;
13810 rpci.attachmentCount = 1;
13811 VkAttachmentDescription attach_desc = {};
13812 attach_desc.format = VK_FORMAT_UNDEFINED;
13813 rpci.pAttachments = &attach_desc;
13814 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13815 VkRenderPass rp;
13816 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13817
13818 m_errorMonitor->VerifyFound();
13819
13820 if (result == VK_SUCCESS) {
13821 vkDestroyRenderPass(m_device->device(), rp, NULL);
13822 }
13823}
13824
Karl Schultz6addd812016-02-02 17:17:23 -070013825TEST_F(VkLayerTest, InvalidImageView) {
13826 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013827
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013829
Tobin Ehliscde08892015-09-22 10:11:37 -060013830 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013831
Mike Stroyana3082432015-09-25 13:39:21 -060013832 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013833 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013834
Karl Schultz6addd812016-02-02 17:17:23 -070013835 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13836 const int32_t tex_width = 32;
13837 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013838
13839 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013840 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13841 image_create_info.pNext = NULL;
13842 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13843 image_create_info.format = tex_format;
13844 image_create_info.extent.width = tex_width;
13845 image_create_info.extent.height = tex_height;
13846 image_create_info.extent.depth = 1;
13847 image_create_info.mipLevels = 1;
13848 image_create_info.arrayLayers = 1;
13849 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13850 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13851 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13852 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013853
Chia-I Wuf7458c52015-10-26 21:10:41 +080013854 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013855 ASSERT_VK_SUCCESS(err);
13856
13857 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013858 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13859 image_view_create_info.image = image;
13860 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13861 image_view_create_info.format = tex_format;
13862 image_view_create_info.subresourceRange.layerCount = 1;
13863 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13864 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013865 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013866
13867 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013868 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013869
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013870 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013871 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013872}
Mike Stroyana3082432015-09-25 13:39:21 -060013873
Mark Youngd339ba32016-05-30 13:28:35 -060013874TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13875 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013877 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013878
13879 ASSERT_NO_FATAL_FAILURE(InitState());
13880
13881 // Create an image and try to create a view with no memory backing the image
13882 VkImage image;
13883
13884 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13885 const int32_t tex_width = 32;
13886 const int32_t tex_height = 32;
13887
13888 VkImageCreateInfo image_create_info = {};
13889 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13890 image_create_info.pNext = NULL;
13891 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13892 image_create_info.format = tex_format;
13893 image_create_info.extent.width = tex_width;
13894 image_create_info.extent.height = tex_height;
13895 image_create_info.extent.depth = 1;
13896 image_create_info.mipLevels = 1;
13897 image_create_info.arrayLayers = 1;
13898 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13899 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13900 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13901 image_create_info.flags = 0;
13902
13903 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13904 ASSERT_VK_SUCCESS(err);
13905
13906 VkImageViewCreateInfo image_view_create_info = {};
13907 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13908 image_view_create_info.image = image;
13909 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13910 image_view_create_info.format = tex_format;
13911 image_view_create_info.subresourceRange.layerCount = 1;
13912 image_view_create_info.subresourceRange.baseMipLevel = 0;
13913 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013914 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013915
13916 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013917 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013918
13919 m_errorMonitor->VerifyFound();
13920 vkDestroyImage(m_device->device(), image, NULL);
13921 // If last error is success, it still created the view, so delete it.
13922 if (err == VK_SUCCESS) {
13923 vkDestroyImageView(m_device->device(), view, NULL);
13924 }
Mark Youngd339ba32016-05-30 13:28:35 -060013925}
13926
Karl Schultz6addd812016-02-02 17:17:23 -070013927TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013928 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013930 "formats must have ONLY the "
13931 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13933 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013934
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013935 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013936
Karl Schultz6addd812016-02-02 17:17:23 -070013937 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013938 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013939 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013940 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013941
13942 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013943 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013944 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013945 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13946 image_view_create_info.format = tex_format;
13947 image_view_create_info.subresourceRange.baseMipLevel = 0;
13948 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013949 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013950 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013951 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013952
13953 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013954 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013955
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013956 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013957}
13958
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013959TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013960 VkResult err;
13961 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13964 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013965
Mike Stroyana3082432015-09-25 13:39:21 -060013966 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013967
13968 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013969 VkImage srcImage;
13970 VkImage dstImage;
13971 VkDeviceMemory srcMem;
13972 VkDeviceMemory destMem;
13973 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013974
13975 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013976 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13977 image_create_info.pNext = NULL;
13978 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13979 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13980 image_create_info.extent.width = 32;
13981 image_create_info.extent.height = 32;
13982 image_create_info.extent.depth = 1;
13983 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013984 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070013985 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13986 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13987 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13988 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013989
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013990 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013991 ASSERT_VK_SUCCESS(err);
13992
Mark Lobodzinski867787a2016-10-14 11:49:55 -060013993 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013994 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013995 ASSERT_VK_SUCCESS(err);
13996
13997 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013998 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013999 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14000 memAlloc.pNext = NULL;
14001 memAlloc.allocationSize = 0;
14002 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014003
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014004 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014005 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014006 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014007 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014008 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014009 ASSERT_VK_SUCCESS(err);
14010
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014011 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014012 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014013 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014014 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014015 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014016 ASSERT_VK_SUCCESS(err);
14017
14018 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14019 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014020 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014021 ASSERT_VK_SUCCESS(err);
14022
14023 BeginCommandBuffer();
14024 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014025 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014026 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014027 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014028 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014029 copyRegion.srcOffset.x = 0;
14030 copyRegion.srcOffset.y = 0;
14031 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014032 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014033 copyRegion.dstSubresource.mipLevel = 0;
14034 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014035 // Introduce failure by forcing the dst layerCount to differ from src
14036 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014037 copyRegion.dstOffset.x = 0;
14038 copyRegion.dstOffset.y = 0;
14039 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014040 copyRegion.extent.width = 1;
14041 copyRegion.extent.height = 1;
14042 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014043 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014044 EndCommandBuffer();
14045
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014046 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014047
Chia-I Wuf7458c52015-10-26 21:10:41 +080014048 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014049 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014050 vkFreeMemory(m_device->device(), srcMem, NULL);
14051 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014052}
14053
Tony Barbourd6673642016-05-05 14:46:39 -060014054TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14055
14056 TEST_DESCRIPTION("Creating images with unsuported formats ");
14057
14058 ASSERT_NO_FATAL_FAILURE(InitState());
14059 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14060 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014061 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Tony Barbourd6673642016-05-05 14:46:39 -060014062 VK_IMAGE_TILING_OPTIMAL, 0);
14063 ASSERT_TRUE(image.initialized());
14064
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014065 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
14066 VkImageCreateInfo image_create_info;
14067 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14068 image_create_info.pNext = NULL;
14069 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14070 image_create_info.format = VK_FORMAT_UNDEFINED;
14071 image_create_info.extent.width = 32;
14072 image_create_info.extent.height = 32;
14073 image_create_info.extent.depth = 1;
14074 image_create_info.mipLevels = 1;
14075 image_create_info.arrayLayers = 1;
14076 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14077 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14078 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14079 image_create_info.flags = 0;
14080
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14082 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014083
14084 VkImage localImage;
14085 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14086 m_errorMonitor->VerifyFound();
14087
Tony Barbourd6673642016-05-05 14:46:39 -060014088 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014089 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014090 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14091 VkFormat format = static_cast<VkFormat>(f);
14092 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014093 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014094 unsupported = format;
14095 break;
14096 }
14097 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014098
Tony Barbourd6673642016-05-05 14:46:39 -060014099 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014100 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014102
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014103 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014104 m_errorMonitor->VerifyFound();
14105 }
14106}
14107
14108TEST_F(VkLayerTest, ImageLayerViewTests) {
14109 VkResult ret;
14110 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14111
14112 ASSERT_NO_FATAL_FAILURE(InitState());
14113
14114 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014115 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Tony Barbourd6673642016-05-05 14:46:39 -060014116 VK_IMAGE_TILING_OPTIMAL, 0);
14117 ASSERT_TRUE(image.initialized());
14118
14119 VkImageView imgView;
14120 VkImageViewCreateInfo imgViewInfo = {};
14121 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14122 imgViewInfo.image = image.handle();
14123 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14124 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14125 imgViewInfo.subresourceRange.layerCount = 1;
14126 imgViewInfo.subresourceRange.baseMipLevel = 0;
14127 imgViewInfo.subresourceRange.levelCount = 1;
14128 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14129
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060014131 // View can't have baseMipLevel >= image's mipLevels - Expect
14132 // VIEW_CREATE_ERROR
14133 imgViewInfo.subresourceRange.baseMipLevel = 1;
14134 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14135 m_errorMonitor->VerifyFound();
14136 imgViewInfo.subresourceRange.baseMipLevel = 0;
14137
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014139 // View can't have baseArrayLayer >= image's arraySize - Expect
14140 // VIEW_CREATE_ERROR
14141 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14142 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14143 m_errorMonitor->VerifyFound();
14144 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14145
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14147 "pCreateInfo->subresourceRange."
14148 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014149 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14150 imgViewInfo.subresourceRange.levelCount = 0;
14151 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14152 m_errorMonitor->VerifyFound();
14153 imgViewInfo.subresourceRange.levelCount = 1;
14154
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14156 "pCreateInfo->subresourceRange."
14157 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014158 m_errorMonitor->SetDesiredFailureMsg(
14159 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14160 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014161 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14162 imgViewInfo.subresourceRange.layerCount = 0;
14163 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14164 m_errorMonitor->VerifyFound();
14165 imgViewInfo.subresourceRange.layerCount = 1;
14166
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14169 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14170 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014171 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14172 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14173 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14174 m_errorMonitor->VerifyFound();
14175 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14178 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14179 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014180 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14181 // VIEW_CREATE_ERROR
14182 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14183 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14184 m_errorMonitor->VerifyFound();
14185 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14186
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14188 "differing formats but they must be "
14189 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014190 // TODO: Update framework to easily passing mutable flag into ImageObj init
14191 // For now just allowing image for this one test to not have memory bound
14192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14193 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014194 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14195 // VIEW_CREATE_ERROR
14196 VkImageCreateInfo mutImgInfo = image.create_info();
14197 VkImage mutImage;
14198 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014199 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014200 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14201 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14202 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14203 ASSERT_VK_SUCCESS(ret);
14204 imgViewInfo.image = mutImage;
14205 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14206 m_errorMonitor->VerifyFound();
14207 imgViewInfo.image = image.handle();
14208 vkDestroyImage(m_device->handle(), mutImage, NULL);
14209}
14210
14211TEST_F(VkLayerTest, MiscImageLayerTests) {
14212
14213 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14214
14215 ASSERT_NO_FATAL_FAILURE(InitState());
14216
14217 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014218 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Tony Barbourd6673642016-05-05 14:46:39 -060014219 VK_IMAGE_TILING_OPTIMAL, 0);
14220 ASSERT_TRUE(image.initialized());
14221
Tony Barbourd6673642016-05-05 14:46:39 -060014222 vk_testing::Buffer buffer;
14223 VkMemoryPropertyFlags reqs = 0;
14224 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14225 VkBufferImageCopy region = {};
14226 region.bufferRowLength = 128;
14227 region.bufferImageHeight = 128;
14228 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14229 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014230 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014231 region.imageExtent.height = 4;
14232 region.imageExtent.width = 4;
14233 region.imageExtent.depth = 1;
14234 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014235
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014236 // Image must have offset.z of 0 and extent.depth of 1
14237 // Introduce failure by setting imageExtent.depth to 0
14238 region.imageExtent.depth = 0;
14239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14240 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14241 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14242 m_errorMonitor->VerifyFound();
14243
14244 region.imageExtent.depth = 1;
14245
14246 // Image must have offset.z of 0 and extent.depth of 1
14247 // Introduce failure by setting imageOffset.z to 4
14248 region.imageOffset.z = 4;
14249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14250 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14251 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14252 m_errorMonitor->VerifyFound();
14253
14254 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014255 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14256 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14257 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014259 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14260 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014261 m_errorMonitor->VerifyFound();
14262
14263 // BufferOffset must be a multiple of 4
14264 // Introduce failure by setting bufferOffset to a value not divisible by 4
14265 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014267 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14268 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014269 m_errorMonitor->VerifyFound();
14270
14271 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14272 region.bufferOffset = 0;
14273 region.imageExtent.height = 128;
14274 region.imageExtent.width = 128;
14275 // Introduce failure by setting bufferRowLength > 0 but less than width
14276 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014278 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14279 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014280 m_errorMonitor->VerifyFound();
14281
14282 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14283 region.bufferRowLength = 128;
14284 // Introduce failure by setting bufferRowHeight > 0 but less than height
14285 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014287 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14288 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014289 m_errorMonitor->VerifyFound();
14290
14291 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14293 "If the format of srcImage is a depth, stencil, depth stencil or "
14294 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014295 // Expect INVALID_FILTER
14296 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014297 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 -060014298 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014299 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 -060014300 VkImageBlit blitRegion = {};
14301 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14302 blitRegion.srcSubresource.baseArrayLayer = 0;
14303 blitRegion.srcSubresource.layerCount = 1;
14304 blitRegion.srcSubresource.mipLevel = 0;
14305 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14306 blitRegion.dstSubresource.baseArrayLayer = 0;
14307 blitRegion.dstSubresource.layerCount = 1;
14308 blitRegion.dstSubresource.mipLevel = 0;
14309
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014310 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14311 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014312 m_errorMonitor->VerifyFound();
14313
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014314 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14316 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14317 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014318 m_errorMonitor->VerifyFound();
14319
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014321 VkImageMemoryBarrier img_barrier;
14322 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14323 img_barrier.pNext = NULL;
14324 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14325 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14326 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14327 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14328 img_barrier.image = image.handle();
14329 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14330 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14331 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14332 img_barrier.subresourceRange.baseArrayLayer = 0;
14333 img_barrier.subresourceRange.baseMipLevel = 0;
14334 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14335 img_barrier.subresourceRange.layerCount = 0;
14336 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014337 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14338 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014339 m_errorMonitor->VerifyFound();
14340 img_barrier.subresourceRange.layerCount = 1;
14341}
14342
14343TEST_F(VkLayerTest, ImageFormatLimits) {
14344
14345 TEST_DESCRIPTION("Exceed the limits of image format ");
14346
Cody Northropc31a84f2016-08-22 10:41:47 -060014347 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014349 VkImageCreateInfo image_create_info = {};
14350 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14351 image_create_info.pNext = NULL;
14352 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14353 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14354 image_create_info.extent.width = 32;
14355 image_create_info.extent.height = 32;
14356 image_create_info.extent.depth = 1;
14357 image_create_info.mipLevels = 1;
14358 image_create_info.arrayLayers = 1;
14359 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14360 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14361 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14362 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14363 image_create_info.flags = 0;
14364
14365 VkImage nullImg;
14366 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014367 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14368 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014369 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14370 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14371 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14372 m_errorMonitor->VerifyFound();
14373 image_create_info.extent.depth = 1;
14374
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014376 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14377 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14378 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14379 m_errorMonitor->VerifyFound();
14380 image_create_info.mipLevels = 1;
14381
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014383 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14384 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14385 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14386 m_errorMonitor->VerifyFound();
14387 image_create_info.arrayLayers = 1;
14388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014390 int samples = imgFmtProps.sampleCounts >> 1;
14391 image_create_info.samples = (VkSampleCountFlagBits)samples;
14392 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14393 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14394 m_errorMonitor->VerifyFound();
14395 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14396
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14398 "VK_IMAGE_LAYOUT_UNDEFINED or "
14399 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014400 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14401 // Expect INVALID_LAYOUT
14402 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14403 m_errorMonitor->VerifyFound();
14404 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14405}
14406
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014407TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14408
14409 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014411
14412 ASSERT_NO_FATAL_FAILURE(InitState());
14413
14414 VkImageObj src_image(m_device);
14415 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14416 VkImageObj dst_image(m_device);
14417 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14418
14419 BeginCommandBuffer();
14420 VkImageCopy copy_region;
14421 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14422 copy_region.srcSubresource.mipLevel = 0;
14423 copy_region.srcSubresource.baseArrayLayer = 0;
14424 copy_region.srcSubresource.layerCount = 0;
14425 copy_region.srcOffset.x = 0;
14426 copy_region.srcOffset.y = 0;
14427 copy_region.srcOffset.z = 0;
14428 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14429 copy_region.dstSubresource.mipLevel = 0;
14430 copy_region.dstSubresource.baseArrayLayer = 0;
14431 copy_region.dstSubresource.layerCount = 0;
14432 copy_region.dstOffset.x = 0;
14433 copy_region.dstOffset.y = 0;
14434 copy_region.dstOffset.z = 0;
14435 copy_region.extent.width = 64;
14436 copy_region.extent.height = 64;
14437 copy_region.extent.depth = 1;
14438 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14439 &copy_region);
14440 EndCommandBuffer();
14441
14442 m_errorMonitor->VerifyFound();
14443}
14444
14445TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14446
14447 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014449
14450 ASSERT_NO_FATAL_FAILURE(InitState());
14451
14452 VkImageObj src_image(m_device);
14453 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14454 VkImageObj dst_image(m_device);
14455 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14456
14457 BeginCommandBuffer();
14458 VkImageCopy copy_region;
14459 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14460 copy_region.srcSubresource.mipLevel = 0;
14461 copy_region.srcSubresource.baseArrayLayer = 0;
14462 copy_region.srcSubresource.layerCount = 0;
14463 copy_region.srcOffset.x = 0;
14464 copy_region.srcOffset.y = 0;
14465 copy_region.srcOffset.z = 0;
14466 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14467 copy_region.dstSubresource.mipLevel = 0;
14468 copy_region.dstSubresource.baseArrayLayer = 0;
14469 copy_region.dstSubresource.layerCount = 0;
14470 copy_region.dstOffset.x = 0;
14471 copy_region.dstOffset.y = 0;
14472 copy_region.dstOffset.z = 0;
14473 copy_region.extent.width = 64;
14474 copy_region.extent.height = 64;
14475 copy_region.extent.depth = 1;
14476 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14477 &copy_region);
14478 EndCommandBuffer();
14479
14480 m_errorMonitor->VerifyFound();
14481}
14482
Karl Schultz6addd812016-02-02 17:17:23 -070014483TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014484 VkResult err;
14485 bool pass;
14486
14487 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14489 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014490
14491 ASSERT_NO_FATAL_FAILURE(InitState());
14492
14493 // Create two images of different types and try to copy between them
14494 VkImage srcImage;
14495 VkImage dstImage;
14496 VkDeviceMemory srcMem;
14497 VkDeviceMemory destMem;
14498 VkMemoryRequirements memReqs;
14499
14500 VkImageCreateInfo image_create_info = {};
14501 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14502 image_create_info.pNext = NULL;
14503 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14504 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14505 image_create_info.extent.width = 32;
14506 image_create_info.extent.height = 32;
14507 image_create_info.extent.depth = 1;
14508 image_create_info.mipLevels = 1;
14509 image_create_info.arrayLayers = 1;
14510 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14511 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14512 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14513 image_create_info.flags = 0;
14514
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014515 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014516 ASSERT_VK_SUCCESS(err);
14517
14518 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14519 // Introduce failure by creating second image with a different-sized format.
14520 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14521
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014522 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014523 ASSERT_VK_SUCCESS(err);
14524
14525 // Allocate memory
14526 VkMemoryAllocateInfo memAlloc = {};
14527 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14528 memAlloc.pNext = NULL;
14529 memAlloc.allocationSize = 0;
14530 memAlloc.memoryTypeIndex = 0;
14531
14532 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14533 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014534 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014535 ASSERT_TRUE(pass);
14536 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14537 ASSERT_VK_SUCCESS(err);
14538
14539 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14540 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014541 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014542 ASSERT_TRUE(pass);
14543 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14544 ASSERT_VK_SUCCESS(err);
14545
14546 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14547 ASSERT_VK_SUCCESS(err);
14548 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14549 ASSERT_VK_SUCCESS(err);
14550
14551 BeginCommandBuffer();
14552 VkImageCopy copyRegion;
14553 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14554 copyRegion.srcSubresource.mipLevel = 0;
14555 copyRegion.srcSubresource.baseArrayLayer = 0;
14556 copyRegion.srcSubresource.layerCount = 0;
14557 copyRegion.srcOffset.x = 0;
14558 copyRegion.srcOffset.y = 0;
14559 copyRegion.srcOffset.z = 0;
14560 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14561 copyRegion.dstSubresource.mipLevel = 0;
14562 copyRegion.dstSubresource.baseArrayLayer = 0;
14563 copyRegion.dstSubresource.layerCount = 0;
14564 copyRegion.dstOffset.x = 0;
14565 copyRegion.dstOffset.y = 0;
14566 copyRegion.dstOffset.z = 0;
14567 copyRegion.extent.width = 1;
14568 copyRegion.extent.height = 1;
14569 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014570 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014571 EndCommandBuffer();
14572
14573 m_errorMonitor->VerifyFound();
14574
14575 vkDestroyImage(m_device->device(), srcImage, NULL);
14576 vkDestroyImage(m_device->device(), dstImage, NULL);
14577 vkFreeMemory(m_device->device(), srcMem, NULL);
14578 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014579}
14580
Karl Schultz6addd812016-02-02 17:17:23 -070014581TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14582 VkResult err;
14583 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014584
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014585 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14587 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014588
Mike Stroyana3082432015-09-25 13:39:21 -060014589 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014590
14591 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014592 VkImage srcImage;
14593 VkImage dstImage;
14594 VkDeviceMemory srcMem;
14595 VkDeviceMemory destMem;
14596 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014597
14598 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014599 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14600 image_create_info.pNext = NULL;
14601 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14602 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14603 image_create_info.extent.width = 32;
14604 image_create_info.extent.height = 32;
14605 image_create_info.extent.depth = 1;
14606 image_create_info.mipLevels = 1;
14607 image_create_info.arrayLayers = 1;
14608 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14609 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14610 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14611 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014612
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014613 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014614 ASSERT_VK_SUCCESS(err);
14615
Karl Schultzbdb75952016-04-19 11:36:49 -060014616 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14617
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014618 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014619 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014620 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014621 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014623 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014624 ASSERT_VK_SUCCESS(err);
14625
14626 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014627 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014628 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14629 memAlloc.pNext = NULL;
14630 memAlloc.allocationSize = 0;
14631 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014632
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014633 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014634 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014635 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014636 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014637 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014638 ASSERT_VK_SUCCESS(err);
14639
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014640 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014641 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014642 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014643 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014644 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014645 ASSERT_VK_SUCCESS(err);
14646
14647 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14648 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014649 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014650 ASSERT_VK_SUCCESS(err);
14651
14652 BeginCommandBuffer();
14653 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014654 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014655 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014656 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014657 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014658 copyRegion.srcOffset.x = 0;
14659 copyRegion.srcOffset.y = 0;
14660 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014661 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014662 copyRegion.dstSubresource.mipLevel = 0;
14663 copyRegion.dstSubresource.baseArrayLayer = 0;
14664 copyRegion.dstSubresource.layerCount = 0;
14665 copyRegion.dstOffset.x = 0;
14666 copyRegion.dstOffset.y = 0;
14667 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014668 copyRegion.extent.width = 1;
14669 copyRegion.extent.height = 1;
14670 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014671 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014672 EndCommandBuffer();
14673
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014674 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014675
Chia-I Wuf7458c52015-10-26 21:10:41 +080014676 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014677 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014678 vkFreeMemory(m_device->device(), srcMem, NULL);
14679 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014680}
14681
Karl Schultz6addd812016-02-02 17:17:23 -070014682TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14683 VkResult err;
14684 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014685
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14687 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014688
Mike Stroyana3082432015-09-25 13:39:21 -060014689 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014690
14691 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014692 VkImage srcImage;
14693 VkImage dstImage;
14694 VkDeviceMemory srcMem;
14695 VkDeviceMemory destMem;
14696 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014697
14698 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014699 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14700 image_create_info.pNext = NULL;
14701 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14702 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14703 image_create_info.extent.width = 32;
14704 image_create_info.extent.height = 1;
14705 image_create_info.extent.depth = 1;
14706 image_create_info.mipLevels = 1;
14707 image_create_info.arrayLayers = 1;
14708 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14709 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14710 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14711 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014712
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014713 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014714 ASSERT_VK_SUCCESS(err);
14715
Karl Schultz6addd812016-02-02 17:17:23 -070014716 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014717
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014718 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014719 ASSERT_VK_SUCCESS(err);
14720
14721 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014722 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014723 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14724 memAlloc.pNext = NULL;
14725 memAlloc.allocationSize = 0;
14726 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014727
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014728 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014729 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014730 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014731 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014732 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014733 ASSERT_VK_SUCCESS(err);
14734
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014735 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014736 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014737 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014738 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014739 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014740 ASSERT_VK_SUCCESS(err);
14741
14742 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14743 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014744 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014745 ASSERT_VK_SUCCESS(err);
14746
14747 BeginCommandBuffer();
14748 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014749 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14750 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014751 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014752 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014753 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014754 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014755 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014756 resolveRegion.srcOffset.x = 0;
14757 resolveRegion.srcOffset.y = 0;
14758 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014759 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014760 resolveRegion.dstSubresource.mipLevel = 0;
14761 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014762 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014763 resolveRegion.dstOffset.x = 0;
14764 resolveRegion.dstOffset.y = 0;
14765 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014766 resolveRegion.extent.width = 1;
14767 resolveRegion.extent.height = 1;
14768 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014769 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014770 EndCommandBuffer();
14771
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014772 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014773
Chia-I Wuf7458c52015-10-26 21:10:41 +080014774 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014775 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014776 vkFreeMemory(m_device->device(), srcMem, NULL);
14777 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014778}
14779
Karl Schultz6addd812016-02-02 17:17:23 -070014780TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14781 VkResult err;
14782 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014783
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14785 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014786
Mike Stroyana3082432015-09-25 13:39:21 -060014787 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014788
Chris Forbesa7530692016-05-08 12:35:39 +120014789 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014790 VkImage srcImage;
14791 VkImage dstImage;
14792 VkDeviceMemory srcMem;
14793 VkDeviceMemory destMem;
14794 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014795
14796 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014797 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14798 image_create_info.pNext = NULL;
14799 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14800 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14801 image_create_info.extent.width = 32;
14802 image_create_info.extent.height = 1;
14803 image_create_info.extent.depth = 1;
14804 image_create_info.mipLevels = 1;
14805 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014806 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014807 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14808 // Note: Some implementations expect color attachment usage for any
14809 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014810 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014811 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014812
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014813 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014814 ASSERT_VK_SUCCESS(err);
14815
Karl Schultz6addd812016-02-02 17:17:23 -070014816 // Note: Some implementations expect color attachment usage for any
14817 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014818 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014819
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014820 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014821 ASSERT_VK_SUCCESS(err);
14822
14823 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014824 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014825 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14826 memAlloc.pNext = NULL;
14827 memAlloc.allocationSize = 0;
14828 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014829
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014830 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014831 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014832 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014833 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014834 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014835 ASSERT_VK_SUCCESS(err);
14836
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014837 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014838 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014839 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014840 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014841 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014842 ASSERT_VK_SUCCESS(err);
14843
14844 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14845 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014846 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014847 ASSERT_VK_SUCCESS(err);
14848
14849 BeginCommandBuffer();
14850 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014851 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14852 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014853 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014854 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014855 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014856 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014857 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014858 resolveRegion.srcOffset.x = 0;
14859 resolveRegion.srcOffset.y = 0;
14860 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014861 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014862 resolveRegion.dstSubresource.mipLevel = 0;
14863 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014864 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014865 resolveRegion.dstOffset.x = 0;
14866 resolveRegion.dstOffset.y = 0;
14867 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014868 resolveRegion.extent.width = 1;
14869 resolveRegion.extent.height = 1;
14870 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014871 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014872 EndCommandBuffer();
14873
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014874 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014875
Chia-I Wuf7458c52015-10-26 21:10:41 +080014876 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014877 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014878 vkFreeMemory(m_device->device(), srcMem, NULL);
14879 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014880}
14881
Karl Schultz6addd812016-02-02 17:17:23 -070014882TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14883 VkResult err;
14884 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014885
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14887 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014888
Mike Stroyana3082432015-09-25 13:39:21 -060014889 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014890
14891 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014892 VkImage srcImage;
14893 VkImage dstImage;
14894 VkDeviceMemory srcMem;
14895 VkDeviceMemory destMem;
14896 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014897
14898 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014899 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14900 image_create_info.pNext = NULL;
14901 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14902 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14903 image_create_info.extent.width = 32;
14904 image_create_info.extent.height = 1;
14905 image_create_info.extent.depth = 1;
14906 image_create_info.mipLevels = 1;
14907 image_create_info.arrayLayers = 1;
14908 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14909 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14910 // Note: Some implementations expect color attachment usage for any
14911 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014912 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014913 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014914
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014915 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014916 ASSERT_VK_SUCCESS(err);
14917
Karl Schultz6addd812016-02-02 17:17:23 -070014918 // Set format to something other than source image
14919 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14920 // Note: Some implementations expect color attachment usage for any
14921 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014922 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014923 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014924
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014925 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014926 ASSERT_VK_SUCCESS(err);
14927
14928 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014929 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014930 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14931 memAlloc.pNext = NULL;
14932 memAlloc.allocationSize = 0;
14933 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014934
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014935 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014936 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014937 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014938 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014939 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014940 ASSERT_VK_SUCCESS(err);
14941
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014942 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014943 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014944 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014945 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014946 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014947 ASSERT_VK_SUCCESS(err);
14948
14949 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14950 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014951 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014952 ASSERT_VK_SUCCESS(err);
14953
14954 BeginCommandBuffer();
14955 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014956 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14957 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014958 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014959 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014960 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014961 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014962 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014963 resolveRegion.srcOffset.x = 0;
14964 resolveRegion.srcOffset.y = 0;
14965 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014966 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014967 resolveRegion.dstSubresource.mipLevel = 0;
14968 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014969 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014970 resolveRegion.dstOffset.x = 0;
14971 resolveRegion.dstOffset.y = 0;
14972 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014973 resolveRegion.extent.width = 1;
14974 resolveRegion.extent.height = 1;
14975 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014976 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014977 EndCommandBuffer();
14978
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014979 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014980
Chia-I Wuf7458c52015-10-26 21:10:41 +080014981 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014982 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014983 vkFreeMemory(m_device->device(), srcMem, NULL);
14984 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014985}
14986
Karl Schultz6addd812016-02-02 17:17:23 -070014987TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
14988 VkResult err;
14989 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14992 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014993
Mike Stroyana3082432015-09-25 13:39:21 -060014994 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014995
14996 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014997 VkImage srcImage;
14998 VkImage dstImage;
14999 VkDeviceMemory srcMem;
15000 VkDeviceMemory destMem;
15001 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015002
15003 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015004 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15005 image_create_info.pNext = NULL;
15006 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15007 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15008 image_create_info.extent.width = 32;
15009 image_create_info.extent.height = 1;
15010 image_create_info.extent.depth = 1;
15011 image_create_info.mipLevels = 1;
15012 image_create_info.arrayLayers = 1;
15013 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15014 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15015 // Note: Some implementations expect color attachment usage for any
15016 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015017 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015018 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015020 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015021 ASSERT_VK_SUCCESS(err);
15022
Karl Schultz6addd812016-02-02 17:17:23 -070015023 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15024 // Note: Some implementations expect color attachment usage for any
15025 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015026 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015027 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015028
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015029 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015030 ASSERT_VK_SUCCESS(err);
15031
15032 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015033 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015034 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15035 memAlloc.pNext = NULL;
15036 memAlloc.allocationSize = 0;
15037 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015038
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015039 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015040 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015041 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015042 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015043 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015044 ASSERT_VK_SUCCESS(err);
15045
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015046 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015047 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015048 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015049 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015050 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015051 ASSERT_VK_SUCCESS(err);
15052
15053 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15054 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015055 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015056 ASSERT_VK_SUCCESS(err);
15057
15058 BeginCommandBuffer();
15059 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015060 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15061 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015062 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015063 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015064 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015065 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015066 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015067 resolveRegion.srcOffset.x = 0;
15068 resolveRegion.srcOffset.y = 0;
15069 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015070 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015071 resolveRegion.dstSubresource.mipLevel = 0;
15072 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015073 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015074 resolveRegion.dstOffset.x = 0;
15075 resolveRegion.dstOffset.y = 0;
15076 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015077 resolveRegion.extent.width = 1;
15078 resolveRegion.extent.height = 1;
15079 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015080 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015081 EndCommandBuffer();
15082
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015083 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015084
Chia-I Wuf7458c52015-10-26 21:10:41 +080015085 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015086 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015087 vkFreeMemory(m_device->device(), srcMem, NULL);
15088 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015089}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015090
Karl Schultz6addd812016-02-02 17:17:23 -070015091TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015092 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015093 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15094 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015095 // The image format check comes 2nd in validation so we trigger it first,
15096 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015097 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15100 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015101
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015102 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015103
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015104 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015105 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15106 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015107
15108 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015109 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15110 ds_pool_ci.pNext = NULL;
15111 ds_pool_ci.maxSets = 1;
15112 ds_pool_ci.poolSizeCount = 1;
15113 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015114
15115 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015116 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015117 ASSERT_VK_SUCCESS(err);
15118
15119 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015120 dsl_binding.binding = 0;
15121 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15122 dsl_binding.descriptorCount = 1;
15123 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15124 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015125
15126 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015127 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15128 ds_layout_ci.pNext = NULL;
15129 ds_layout_ci.bindingCount = 1;
15130 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015131 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015132 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015133 ASSERT_VK_SUCCESS(err);
15134
15135 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015136 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015137 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015138 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015139 alloc_info.descriptorPool = ds_pool;
15140 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015141 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015142 ASSERT_VK_SUCCESS(err);
15143
Karl Schultz6addd812016-02-02 17:17:23 -070015144 VkImage image_bad;
15145 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015146 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015147 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015148 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015149 const int32_t tex_width = 32;
15150 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015151
15152 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015153 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15154 image_create_info.pNext = NULL;
15155 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15156 image_create_info.format = tex_format_bad;
15157 image_create_info.extent.width = tex_width;
15158 image_create_info.extent.height = tex_height;
15159 image_create_info.extent.depth = 1;
15160 image_create_info.mipLevels = 1;
15161 image_create_info.arrayLayers = 1;
15162 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15163 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015164 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015165 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015166
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015167 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015168 ASSERT_VK_SUCCESS(err);
15169 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015170 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15171 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015172 ASSERT_VK_SUCCESS(err);
15173
15174 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015175 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15176 image_view_create_info.image = image_bad;
15177 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15178 image_view_create_info.format = tex_format_bad;
15179 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15180 image_view_create_info.subresourceRange.baseMipLevel = 0;
15181 image_view_create_info.subresourceRange.layerCount = 1;
15182 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015183 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015184
15185 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015186 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015187
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015188 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015189
Chia-I Wuf7458c52015-10-26 21:10:41 +080015190 vkDestroyImage(m_device->device(), image_bad, NULL);
15191 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015192 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15193 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015194}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015195
15196TEST_F(VkLayerTest, ClearImageErrors) {
15197 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15198 "ClearDepthStencilImage with a color image.");
15199
15200 ASSERT_NO_FATAL_FAILURE(InitState());
15201 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15202
15203 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15204 BeginCommandBuffer();
15205 m_commandBuffer->EndRenderPass();
15206
15207 // Color image
15208 VkClearColorValue clear_color;
15209 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15210 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15211 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15212 const int32_t img_width = 32;
15213 const int32_t img_height = 32;
15214 VkImageCreateInfo image_create_info = {};
15215 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15216 image_create_info.pNext = NULL;
15217 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15218 image_create_info.format = color_format;
15219 image_create_info.extent.width = img_width;
15220 image_create_info.extent.height = img_height;
15221 image_create_info.extent.depth = 1;
15222 image_create_info.mipLevels = 1;
15223 image_create_info.arrayLayers = 1;
15224 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15225 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15226 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15227
15228 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015229 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015230
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015231 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015232
15233 // Depth/Stencil image
15234 VkClearDepthStencilValue clear_value = {0};
15235 reqs = 0; // don't need HOST_VISIBLE DS image
15236 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15237 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15238 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15239 ds_image_create_info.extent.width = 64;
15240 ds_image_create_info.extent.height = 64;
15241 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15242 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15243
15244 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015245 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015246
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015247 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 -060015248
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015250
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015251 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015252 &color_range);
15253
15254 m_errorMonitor->VerifyFound();
15255
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15257 "image created without "
15258 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015260 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015261 &color_range);
15262
15263 m_errorMonitor->VerifyFound();
15264
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015265 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15267 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015269 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15270 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015271
15272 m_errorMonitor->VerifyFound();
15273}
Tobin Ehliscde08892015-09-22 10:11:37 -060015274#endif // IMAGE_TESTS
15275
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015276
15277// WSI Enabled Tests
15278//
Chris Forbes09368e42016-10-13 11:59:22 +130015279#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015280TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15281
15282#if defined(VK_USE_PLATFORM_XCB_KHR)
15283 VkSurfaceKHR surface = VK_NULL_HANDLE;
15284
15285 VkResult err;
15286 bool pass;
15287 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15288 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15289 // uint32_t swapchain_image_count = 0;
15290 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15291 // uint32_t image_index = 0;
15292 // VkPresentInfoKHR present_info = {};
15293
15294 ASSERT_NO_FATAL_FAILURE(InitState());
15295
15296 // Use the create function from one of the VK_KHR_*_surface extension in
15297 // order to create a surface, testing all known errors in the process,
15298 // before successfully creating a surface:
15299 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15301 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15302 pass = (err != VK_SUCCESS);
15303 ASSERT_TRUE(pass);
15304 m_errorMonitor->VerifyFound();
15305
15306 // Next, try to create a surface with the wrong
15307 // VkXcbSurfaceCreateInfoKHR::sType:
15308 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15309 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15311 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15312 pass = (err != VK_SUCCESS);
15313 ASSERT_TRUE(pass);
15314 m_errorMonitor->VerifyFound();
15315
15316 // Create a native window, and then correctly create a surface:
15317 xcb_connection_t *connection;
15318 xcb_screen_t *screen;
15319 xcb_window_t xcb_window;
15320 xcb_intern_atom_reply_t *atom_wm_delete_window;
15321
15322 const xcb_setup_t *setup;
15323 xcb_screen_iterator_t iter;
15324 int scr;
15325 uint32_t value_mask, value_list[32];
15326 int width = 1;
15327 int height = 1;
15328
15329 connection = xcb_connect(NULL, &scr);
15330 ASSERT_TRUE(connection != NULL);
15331 setup = xcb_get_setup(connection);
15332 iter = xcb_setup_roots_iterator(setup);
15333 while (scr-- > 0)
15334 xcb_screen_next(&iter);
15335 screen = iter.data;
15336
15337 xcb_window = xcb_generate_id(connection);
15338
15339 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15340 value_list[0] = screen->black_pixel;
15341 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15342
15343 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15344 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15345
15346 /* Magic code that will send notification when window is destroyed */
15347 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15348 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15349
15350 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15351 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15352 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15353 free(reply);
15354
15355 xcb_map_window(connection, xcb_window);
15356
15357 // Force the x/y coordinates to 100,100 results are identical in consecutive
15358 // runs
15359 const uint32_t coords[] = { 100, 100 };
15360 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15361
15362 // Finally, try to correctly create a surface:
15363 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15364 xcb_create_info.pNext = NULL;
15365 xcb_create_info.flags = 0;
15366 xcb_create_info.connection = connection;
15367 xcb_create_info.window = xcb_window;
15368 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15369 pass = (err == VK_SUCCESS);
15370 ASSERT_TRUE(pass);
15371
15372 // Check if surface supports presentation:
15373
15374 // 1st, do so without having queried the queue families:
15375 VkBool32 supported = false;
15376 // TODO: Get the following error to come out:
15377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15378 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15379 "function");
15380 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15381 pass = (err != VK_SUCCESS);
15382 // ASSERT_TRUE(pass);
15383 // m_errorMonitor->VerifyFound();
15384
15385 // Next, query a queue family index that's too large:
15386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15387 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15388 pass = (err != VK_SUCCESS);
15389 ASSERT_TRUE(pass);
15390 m_errorMonitor->VerifyFound();
15391
15392 // Finally, do so correctly:
15393 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15394 // SUPPORTED
15395 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15396 pass = (err == VK_SUCCESS);
15397 ASSERT_TRUE(pass);
15398
15399 // Before proceeding, try to create a swapchain without having called
15400 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15401 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15402 swapchain_create_info.pNext = NULL;
15403 swapchain_create_info.flags = 0;
15404 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15405 swapchain_create_info.surface = surface;
15406 swapchain_create_info.imageArrayLayers = 1;
15407 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15408 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15410 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15411 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15412 pass = (err != VK_SUCCESS);
15413 ASSERT_TRUE(pass);
15414 m_errorMonitor->VerifyFound();
15415
15416 // Get the surface capabilities:
15417 VkSurfaceCapabilitiesKHR surface_capabilities;
15418
15419 // Do so correctly (only error logged by this entrypoint is if the
15420 // extension isn't enabled):
15421 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15422 pass = (err == VK_SUCCESS);
15423 ASSERT_TRUE(pass);
15424
15425 // Get the surface formats:
15426 uint32_t surface_format_count;
15427
15428 // First, try without a pointer to surface_format_count:
15429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15430 "specified as NULL");
15431 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15432 pass = (err == VK_SUCCESS);
15433 ASSERT_TRUE(pass);
15434 m_errorMonitor->VerifyFound();
15435
15436 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15437 // correctly done a 1st try (to get the count):
15438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15439 surface_format_count = 0;
15440 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15441 pass = (err == VK_SUCCESS);
15442 ASSERT_TRUE(pass);
15443 m_errorMonitor->VerifyFound();
15444
15445 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15446 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15447 pass = (err == VK_SUCCESS);
15448 ASSERT_TRUE(pass);
15449
15450 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15451 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15452
15453 // Next, do a 2nd try with surface_format_count being set too high:
15454 surface_format_count += 5;
15455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15456 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15457 pass = (err == VK_SUCCESS);
15458 ASSERT_TRUE(pass);
15459 m_errorMonitor->VerifyFound();
15460
15461 // Finally, do a correct 1st and 2nd try:
15462 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15463 pass = (err == VK_SUCCESS);
15464 ASSERT_TRUE(pass);
15465 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15466 pass = (err == VK_SUCCESS);
15467 ASSERT_TRUE(pass);
15468
15469 // Get the surface present modes:
15470 uint32_t surface_present_mode_count;
15471
15472 // First, try without a pointer to surface_format_count:
15473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15474 "specified as NULL");
15475
15476 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15477 pass = (err == VK_SUCCESS);
15478 ASSERT_TRUE(pass);
15479 m_errorMonitor->VerifyFound();
15480
15481 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15482 // correctly done a 1st try (to get the count):
15483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15484 surface_present_mode_count = 0;
15485 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15486 (VkPresentModeKHR *)&surface_present_mode_count);
15487 pass = (err == VK_SUCCESS);
15488 ASSERT_TRUE(pass);
15489 m_errorMonitor->VerifyFound();
15490
15491 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15492 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15493 pass = (err == VK_SUCCESS);
15494 ASSERT_TRUE(pass);
15495
15496 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15497 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15498
15499 // Next, do a 2nd try with surface_format_count being set too high:
15500 surface_present_mode_count += 5;
15501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15502 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15503 pass = (err == VK_SUCCESS);
15504 ASSERT_TRUE(pass);
15505 m_errorMonitor->VerifyFound();
15506
15507 // Finally, do a correct 1st and 2nd try:
15508 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15509 pass = (err == VK_SUCCESS);
15510 ASSERT_TRUE(pass);
15511 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15512 pass = (err == VK_SUCCESS);
15513 ASSERT_TRUE(pass);
15514
15515 // Create a swapchain:
15516
15517 // First, try without a pointer to swapchain_create_info:
15518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15519 "specified as NULL");
15520
15521 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15522 pass = (err != VK_SUCCESS);
15523 ASSERT_TRUE(pass);
15524 m_errorMonitor->VerifyFound();
15525
15526 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15527 // sType:
15528 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15530
15531 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15532 pass = (err != VK_SUCCESS);
15533 ASSERT_TRUE(pass);
15534 m_errorMonitor->VerifyFound();
15535
15536 // Next, call with a NULL swapchain pointer:
15537 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15538 swapchain_create_info.pNext = NULL;
15539 swapchain_create_info.flags = 0;
15540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15541 "specified as NULL");
15542
15543 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15544 pass = (err != VK_SUCCESS);
15545 ASSERT_TRUE(pass);
15546 m_errorMonitor->VerifyFound();
15547
15548 // TODO: Enhance swapchain layer so that
15549 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15550
15551 // Next, call with a queue family index that's too large:
15552 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15553 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15554 swapchain_create_info.queueFamilyIndexCount = 2;
15555 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15557 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15558 pass = (err != VK_SUCCESS);
15559 ASSERT_TRUE(pass);
15560 m_errorMonitor->VerifyFound();
15561
15562 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15563 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15564 swapchain_create_info.queueFamilyIndexCount = 1;
15565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15566 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15567 "pCreateInfo->pQueueFamilyIndices).");
15568 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15569 pass = (err != VK_SUCCESS);
15570 ASSERT_TRUE(pass);
15571 m_errorMonitor->VerifyFound();
15572
15573 // Next, call with an invalid imageSharingMode:
15574 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15575 swapchain_create_info.queueFamilyIndexCount = 1;
15576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15577 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15578 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15579 pass = (err != VK_SUCCESS);
15580 ASSERT_TRUE(pass);
15581 m_errorMonitor->VerifyFound();
15582 // Fix for the future:
15583 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15584 // SUPPORTED
15585 swapchain_create_info.queueFamilyIndexCount = 0;
15586 queueFamilyIndex[0] = 0;
15587 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15588
15589 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15590 // Get the images from a swapchain:
15591 // Acquire an image from a swapchain:
15592 // Present an image to a swapchain:
15593 // Destroy the swapchain:
15594
15595 // TODOs:
15596 //
15597 // - Try destroying the device without first destroying the swapchain
15598 //
15599 // - Try destroying the device without first destroying the surface
15600 //
15601 // - Try destroying the surface without first destroying the swapchain
15602
15603 // Destroy the surface:
15604 vkDestroySurfaceKHR(instance(), surface, NULL);
15605
15606 // Tear down the window:
15607 xcb_destroy_window(connection, xcb_window);
15608 xcb_disconnect(connection);
15609
15610#else // VK_USE_PLATFORM_XCB_KHR
15611 return;
15612#endif // VK_USE_PLATFORM_XCB_KHR
15613}
Chris Forbes09368e42016-10-13 11:59:22 +130015614#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015615
15616//
15617// POSITIVE VALIDATION TESTS
15618//
15619// These tests do not expect to encounter ANY validation errors pass only if this is true
15620
Tobin Ehlise0006882016-11-03 10:14:28 -060015621TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15622 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15623 "by a transition in the primary.");
15624 VkResult err;
15625 m_errorMonitor->ExpectSuccess();
15626 ASSERT_NO_FATAL_FAILURE(InitState());
15627 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15628 // Allocate a secondary and primary cmd buffer
15629 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15630 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15631 command_buffer_allocate_info.commandPool = m_commandPool;
15632 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15633 command_buffer_allocate_info.commandBufferCount = 1;
15634
15635 VkCommandBuffer secondary_command_buffer;
15636 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15637 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15638 VkCommandBuffer primary_command_buffer;
15639 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15640 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15641 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15642 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15643 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15644 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15645 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15646
15647 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15648 ASSERT_VK_SUCCESS(err);
15649 VkImageObj image(m_device);
15650 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15651 ASSERT_TRUE(image.initialized());
15652 VkImageMemoryBarrier img_barrier = {};
15653 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15654 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15655 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15656 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15657 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15658 img_barrier.image = image.handle();
15659 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15660 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15661 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15662 img_barrier.subresourceRange.baseArrayLayer = 0;
15663 img_barrier.subresourceRange.baseMipLevel = 0;
15664 img_barrier.subresourceRange.layerCount = 1;
15665 img_barrier.subresourceRange.levelCount = 1;
15666 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15667 0, nullptr, 1, &img_barrier);
15668 err = vkEndCommandBuffer(secondary_command_buffer);
15669 ASSERT_VK_SUCCESS(err);
15670
15671 // Now update primary cmd buffer to execute secondary and transitions image
15672 command_buffer_begin_info.pInheritanceInfo = nullptr;
15673 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15674 ASSERT_VK_SUCCESS(err);
15675 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15676 VkImageMemoryBarrier img_barrier2 = {};
15677 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15678 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15679 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15680 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15681 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15682 img_barrier2.image = image.handle();
15683 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15684 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15685 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15686 img_barrier2.subresourceRange.baseArrayLayer = 0;
15687 img_barrier2.subresourceRange.baseMipLevel = 0;
15688 img_barrier2.subresourceRange.layerCount = 1;
15689 img_barrier2.subresourceRange.levelCount = 1;
15690 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15691 nullptr, 1, &img_barrier2);
15692 err = vkEndCommandBuffer(primary_command_buffer);
15693 ASSERT_VK_SUCCESS(err);
15694 VkSubmitInfo submit_info = {};
15695 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15696 submit_info.commandBufferCount = 1;
15697 submit_info.pCommandBuffers = &primary_command_buffer;
15698 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15699 ASSERT_VK_SUCCESS(err);
15700 m_errorMonitor->VerifyNotFound();
15701 err = vkDeviceWaitIdle(m_device->device());
15702 ASSERT_VK_SUCCESS(err);
15703 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15704 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15705}
15706
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015707// This is a positive test. No failures are expected.
15708TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15709 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15710 "is ignoring VkWriteDescriptorSet members that are not "
15711 "related to the descriptor type specified by "
15712 "VkWriteDescriptorSet::descriptorType. Correct "
15713 "validation behavior will result in the test running to "
15714 "completion without validation errors.");
15715
15716 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15717
15718 ASSERT_NO_FATAL_FAILURE(InitState());
15719
15720 // Image Case
15721 {
15722 m_errorMonitor->ExpectSuccess();
15723
15724 VkImage image;
15725 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15726 const int32_t tex_width = 32;
15727 const int32_t tex_height = 32;
15728 VkImageCreateInfo image_create_info = {};
15729 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15730 image_create_info.pNext = NULL;
15731 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15732 image_create_info.format = tex_format;
15733 image_create_info.extent.width = tex_width;
15734 image_create_info.extent.height = tex_height;
15735 image_create_info.extent.depth = 1;
15736 image_create_info.mipLevels = 1;
15737 image_create_info.arrayLayers = 1;
15738 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15739 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15740 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15741 image_create_info.flags = 0;
15742 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15743 ASSERT_VK_SUCCESS(err);
15744
15745 VkMemoryRequirements memory_reqs;
15746 VkDeviceMemory image_memory;
15747 bool pass;
15748 VkMemoryAllocateInfo memory_info = {};
15749 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15750 memory_info.pNext = NULL;
15751 memory_info.allocationSize = 0;
15752 memory_info.memoryTypeIndex = 0;
15753 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15754 memory_info.allocationSize = memory_reqs.size;
15755 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15756 ASSERT_TRUE(pass);
15757 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15758 ASSERT_VK_SUCCESS(err);
15759 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15760 ASSERT_VK_SUCCESS(err);
15761
15762 VkImageViewCreateInfo image_view_create_info = {};
15763 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15764 image_view_create_info.image = image;
15765 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15766 image_view_create_info.format = tex_format;
15767 image_view_create_info.subresourceRange.layerCount = 1;
15768 image_view_create_info.subresourceRange.baseMipLevel = 0;
15769 image_view_create_info.subresourceRange.levelCount = 1;
15770 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15771
15772 VkImageView view;
15773 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15774 ASSERT_VK_SUCCESS(err);
15775
15776 VkDescriptorPoolSize ds_type_count = {};
15777 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15778 ds_type_count.descriptorCount = 1;
15779
15780 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15781 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15782 ds_pool_ci.pNext = NULL;
15783 ds_pool_ci.maxSets = 1;
15784 ds_pool_ci.poolSizeCount = 1;
15785 ds_pool_ci.pPoolSizes = &ds_type_count;
15786
15787 VkDescriptorPool ds_pool;
15788 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15789 ASSERT_VK_SUCCESS(err);
15790
15791 VkDescriptorSetLayoutBinding dsl_binding = {};
15792 dsl_binding.binding = 0;
15793 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15794 dsl_binding.descriptorCount = 1;
15795 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15796 dsl_binding.pImmutableSamplers = NULL;
15797
15798 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15799 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15800 ds_layout_ci.pNext = NULL;
15801 ds_layout_ci.bindingCount = 1;
15802 ds_layout_ci.pBindings = &dsl_binding;
15803 VkDescriptorSetLayout ds_layout;
15804 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15805 ASSERT_VK_SUCCESS(err);
15806
15807 VkDescriptorSet descriptor_set;
15808 VkDescriptorSetAllocateInfo alloc_info = {};
15809 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15810 alloc_info.descriptorSetCount = 1;
15811 alloc_info.descriptorPool = ds_pool;
15812 alloc_info.pSetLayouts = &ds_layout;
15813 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15814 ASSERT_VK_SUCCESS(err);
15815
15816 VkDescriptorImageInfo image_info = {};
15817 image_info.imageView = view;
15818 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15819
15820 VkWriteDescriptorSet descriptor_write;
15821 memset(&descriptor_write, 0, sizeof(descriptor_write));
15822 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15823 descriptor_write.dstSet = descriptor_set;
15824 descriptor_write.dstBinding = 0;
15825 descriptor_write.descriptorCount = 1;
15826 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15827 descriptor_write.pImageInfo = &image_info;
15828
15829 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15830 // be
15831 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15832 // This will most likely produce a crash if the parameter_validation
15833 // layer
15834 // does not correctly ignore pBufferInfo.
15835 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15836 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15837
15838 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15839
15840 m_errorMonitor->VerifyNotFound();
15841
15842 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15843 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15844 vkDestroyImageView(m_device->device(), view, NULL);
15845 vkDestroyImage(m_device->device(), image, NULL);
15846 vkFreeMemory(m_device->device(), image_memory, NULL);
15847 }
15848
15849 // Buffer Case
15850 {
15851 m_errorMonitor->ExpectSuccess();
15852
15853 VkBuffer buffer;
15854 uint32_t queue_family_index = 0;
15855 VkBufferCreateInfo buffer_create_info = {};
15856 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15857 buffer_create_info.size = 1024;
15858 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15859 buffer_create_info.queueFamilyIndexCount = 1;
15860 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15861
15862 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15863 ASSERT_VK_SUCCESS(err);
15864
15865 VkMemoryRequirements memory_reqs;
15866 VkDeviceMemory buffer_memory;
15867 bool pass;
15868 VkMemoryAllocateInfo memory_info = {};
15869 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15870 memory_info.pNext = NULL;
15871 memory_info.allocationSize = 0;
15872 memory_info.memoryTypeIndex = 0;
15873
15874 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15875 memory_info.allocationSize = memory_reqs.size;
15876 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15877 ASSERT_TRUE(pass);
15878
15879 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15880 ASSERT_VK_SUCCESS(err);
15881 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15882 ASSERT_VK_SUCCESS(err);
15883
15884 VkDescriptorPoolSize ds_type_count = {};
15885 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15886 ds_type_count.descriptorCount = 1;
15887
15888 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15889 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15890 ds_pool_ci.pNext = NULL;
15891 ds_pool_ci.maxSets = 1;
15892 ds_pool_ci.poolSizeCount = 1;
15893 ds_pool_ci.pPoolSizes = &ds_type_count;
15894
15895 VkDescriptorPool ds_pool;
15896 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15897 ASSERT_VK_SUCCESS(err);
15898
15899 VkDescriptorSetLayoutBinding dsl_binding = {};
15900 dsl_binding.binding = 0;
15901 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15902 dsl_binding.descriptorCount = 1;
15903 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15904 dsl_binding.pImmutableSamplers = NULL;
15905
15906 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15907 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15908 ds_layout_ci.pNext = NULL;
15909 ds_layout_ci.bindingCount = 1;
15910 ds_layout_ci.pBindings = &dsl_binding;
15911 VkDescriptorSetLayout ds_layout;
15912 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15913 ASSERT_VK_SUCCESS(err);
15914
15915 VkDescriptorSet descriptor_set;
15916 VkDescriptorSetAllocateInfo alloc_info = {};
15917 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15918 alloc_info.descriptorSetCount = 1;
15919 alloc_info.descriptorPool = ds_pool;
15920 alloc_info.pSetLayouts = &ds_layout;
15921 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15922 ASSERT_VK_SUCCESS(err);
15923
15924 VkDescriptorBufferInfo buffer_info = {};
15925 buffer_info.buffer = buffer;
15926 buffer_info.offset = 0;
15927 buffer_info.range = 1024;
15928
15929 VkWriteDescriptorSet descriptor_write;
15930 memset(&descriptor_write, 0, sizeof(descriptor_write));
15931 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15932 descriptor_write.dstSet = descriptor_set;
15933 descriptor_write.dstBinding = 0;
15934 descriptor_write.descriptorCount = 1;
15935 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15936 descriptor_write.pBufferInfo = &buffer_info;
15937
15938 // Set pImageInfo and pTexelBufferView to invalid values, which should
15939 // be
15940 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15941 // This will most likely produce a crash if the parameter_validation
15942 // layer
15943 // does not correctly ignore pImageInfo.
15944 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15945 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15946
15947 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15948
15949 m_errorMonitor->VerifyNotFound();
15950
15951 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15952 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15953 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15954 vkDestroyBuffer(m_device->device(), buffer, NULL);
15955 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15956 }
15957
15958 // Texel Buffer Case
15959 {
15960 m_errorMonitor->ExpectSuccess();
15961
15962 VkBuffer buffer;
15963 uint32_t queue_family_index = 0;
15964 VkBufferCreateInfo buffer_create_info = {};
15965 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15966 buffer_create_info.size = 1024;
15967 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15968 buffer_create_info.queueFamilyIndexCount = 1;
15969 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15970
15971 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15972 ASSERT_VK_SUCCESS(err);
15973
15974 VkMemoryRequirements memory_reqs;
15975 VkDeviceMemory buffer_memory;
15976 bool pass;
15977 VkMemoryAllocateInfo memory_info = {};
15978 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15979 memory_info.pNext = NULL;
15980 memory_info.allocationSize = 0;
15981 memory_info.memoryTypeIndex = 0;
15982
15983 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15984 memory_info.allocationSize = memory_reqs.size;
15985 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15986 ASSERT_TRUE(pass);
15987
15988 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15989 ASSERT_VK_SUCCESS(err);
15990 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15991 ASSERT_VK_SUCCESS(err);
15992
15993 VkBufferViewCreateInfo buff_view_ci = {};
15994 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
15995 buff_view_ci.buffer = buffer;
15996 buff_view_ci.format = VK_FORMAT_R8_UNORM;
15997 buff_view_ci.range = VK_WHOLE_SIZE;
15998 VkBufferView buffer_view;
15999 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16000
16001 VkDescriptorPoolSize ds_type_count = {};
16002 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16003 ds_type_count.descriptorCount = 1;
16004
16005 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16006 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16007 ds_pool_ci.pNext = NULL;
16008 ds_pool_ci.maxSets = 1;
16009 ds_pool_ci.poolSizeCount = 1;
16010 ds_pool_ci.pPoolSizes = &ds_type_count;
16011
16012 VkDescriptorPool ds_pool;
16013 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16014 ASSERT_VK_SUCCESS(err);
16015
16016 VkDescriptorSetLayoutBinding dsl_binding = {};
16017 dsl_binding.binding = 0;
16018 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16019 dsl_binding.descriptorCount = 1;
16020 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16021 dsl_binding.pImmutableSamplers = NULL;
16022
16023 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16024 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16025 ds_layout_ci.pNext = NULL;
16026 ds_layout_ci.bindingCount = 1;
16027 ds_layout_ci.pBindings = &dsl_binding;
16028 VkDescriptorSetLayout ds_layout;
16029 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16030 ASSERT_VK_SUCCESS(err);
16031
16032 VkDescriptorSet descriptor_set;
16033 VkDescriptorSetAllocateInfo alloc_info = {};
16034 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16035 alloc_info.descriptorSetCount = 1;
16036 alloc_info.descriptorPool = ds_pool;
16037 alloc_info.pSetLayouts = &ds_layout;
16038 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16039 ASSERT_VK_SUCCESS(err);
16040
16041 VkWriteDescriptorSet descriptor_write;
16042 memset(&descriptor_write, 0, sizeof(descriptor_write));
16043 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16044 descriptor_write.dstSet = descriptor_set;
16045 descriptor_write.dstBinding = 0;
16046 descriptor_write.descriptorCount = 1;
16047 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16048 descriptor_write.pTexelBufferView = &buffer_view;
16049
16050 // Set pImageInfo and pBufferInfo to invalid values, which should be
16051 // ignored for descriptorType ==
16052 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16053 // This will most likely produce a crash if the parameter_validation
16054 // layer
16055 // does not correctly ignore pImageInfo and pBufferInfo.
16056 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16057 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16058
16059 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16060
16061 m_errorMonitor->VerifyNotFound();
16062
16063 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
16064 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16065 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16066 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16067 vkDestroyBuffer(m_device->device(), buffer, NULL);
16068 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16069 }
16070}
16071
Tobin Ehlisf7428442016-10-25 07:58:24 -060016072TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16073 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16074
16075 ASSERT_NO_FATAL_FAILURE(InitState());
16076 // Create layout where two binding #s are "1"
16077 static const uint32_t NUM_BINDINGS = 3;
16078 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16079 dsl_binding[0].binding = 1;
16080 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16081 dsl_binding[0].descriptorCount = 1;
16082 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16083 dsl_binding[0].pImmutableSamplers = NULL;
16084 dsl_binding[1].binding = 0;
16085 dsl_binding[1].descriptorCount = 1;
16086 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16087 dsl_binding[1].descriptorCount = 1;
16088 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16089 dsl_binding[1].pImmutableSamplers = NULL;
16090 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16091 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16092 dsl_binding[2].descriptorCount = 1;
16093 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16094 dsl_binding[2].pImmutableSamplers = NULL;
16095
16096 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16097 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16098 ds_layout_ci.pNext = NULL;
16099 ds_layout_ci.bindingCount = NUM_BINDINGS;
16100 ds_layout_ci.pBindings = dsl_binding;
16101 VkDescriptorSetLayout ds_layout;
16102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16103 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16104 m_errorMonitor->VerifyFound();
16105}
16106
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016107TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016108 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16109
16110 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016111
16112 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016113
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016114 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16115
16116 {
16117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16118 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16119 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16120 m_errorMonitor->VerifyFound();
16121 }
16122
16123 {
16124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16125 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16126 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16127 m_errorMonitor->VerifyFound();
16128 }
16129
16130 {
16131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16132 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16133 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16134 m_errorMonitor->VerifyFound();
16135 }
16136
16137 {
16138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16139 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16140 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16141 m_errorMonitor->VerifyFound();
16142 }
16143
16144 {
16145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16146 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16147 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16148 m_errorMonitor->VerifyFound();
16149 }
16150
16151 {
16152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16153 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16154 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16155 m_errorMonitor->VerifyFound();
16156 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016157
16158 {
16159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16160 VkRect2D scissor = {{-1, 0}, {16, 16}};
16161 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16162 m_errorMonitor->VerifyFound();
16163 }
16164
16165 {
16166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16167 VkRect2D scissor = {{0, -2}, {16, 16}};
16168 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16169 m_errorMonitor->VerifyFound();
16170 }
16171
16172 {
16173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16174 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16175 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16176 m_errorMonitor->VerifyFound();
16177 }
16178
16179 {
16180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16181 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16182 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16183 m_errorMonitor->VerifyFound();
16184 }
16185
16186 EndCommandBuffer();
16187}
16188
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016189// This is a positive test. No failures are expected.
16190TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16191 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16192 VkResult err;
16193
16194 ASSERT_NO_FATAL_FAILURE(InitState());
16195 m_errorMonitor->ExpectSuccess();
16196 VkDescriptorPoolSize ds_type_count = {};
16197 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16198 ds_type_count.descriptorCount = 2;
16199
16200 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16201 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16202 ds_pool_ci.pNext = NULL;
16203 ds_pool_ci.maxSets = 1;
16204 ds_pool_ci.poolSizeCount = 1;
16205 ds_pool_ci.pPoolSizes = &ds_type_count;
16206
16207 VkDescriptorPool ds_pool;
16208 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16209 ASSERT_VK_SUCCESS(err);
16210
16211 // Create layout with two uniform buffer descriptors w/ empty binding between them
16212 static const uint32_t NUM_BINDINGS = 3;
16213 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16214 dsl_binding[0].binding = 0;
16215 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16216 dsl_binding[0].descriptorCount = 1;
16217 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16218 dsl_binding[0].pImmutableSamplers = NULL;
16219 dsl_binding[1].binding = 1;
16220 dsl_binding[1].descriptorCount = 0; // empty binding
16221 dsl_binding[2].binding = 2;
16222 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16223 dsl_binding[2].descriptorCount = 1;
16224 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16225 dsl_binding[2].pImmutableSamplers = NULL;
16226
16227 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16228 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16229 ds_layout_ci.pNext = NULL;
16230 ds_layout_ci.bindingCount = NUM_BINDINGS;
16231 ds_layout_ci.pBindings = dsl_binding;
16232 VkDescriptorSetLayout ds_layout;
16233 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16234 ASSERT_VK_SUCCESS(err);
16235
16236 VkDescriptorSet descriptor_set = {};
16237 VkDescriptorSetAllocateInfo alloc_info = {};
16238 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16239 alloc_info.descriptorSetCount = 1;
16240 alloc_info.descriptorPool = ds_pool;
16241 alloc_info.pSetLayouts = &ds_layout;
16242 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16243 ASSERT_VK_SUCCESS(err);
16244
16245 // Create a buffer to be used for update
16246 VkBufferCreateInfo buff_ci = {};
16247 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16248 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16249 buff_ci.size = 256;
16250 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16251 VkBuffer buffer;
16252 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16253 ASSERT_VK_SUCCESS(err);
16254 // Have to bind memory to buffer before descriptor update
16255 VkMemoryAllocateInfo mem_alloc = {};
16256 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16257 mem_alloc.pNext = NULL;
16258 mem_alloc.allocationSize = 512; // one allocation for both buffers
16259 mem_alloc.memoryTypeIndex = 0;
16260
16261 VkMemoryRequirements mem_reqs;
16262 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16263 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16264 if (!pass) {
16265 vkDestroyBuffer(m_device->device(), buffer, NULL);
16266 return;
16267 }
16268
16269 VkDeviceMemory mem;
16270 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16271 ASSERT_VK_SUCCESS(err);
16272 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16273 ASSERT_VK_SUCCESS(err);
16274
16275 // Only update the descriptor at binding 2
16276 VkDescriptorBufferInfo buff_info = {};
16277 buff_info.buffer = buffer;
16278 buff_info.offset = 0;
16279 buff_info.range = VK_WHOLE_SIZE;
16280 VkWriteDescriptorSet descriptor_write = {};
16281 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16282 descriptor_write.dstBinding = 2;
16283 descriptor_write.descriptorCount = 1;
16284 descriptor_write.pTexelBufferView = nullptr;
16285 descriptor_write.pBufferInfo = &buff_info;
16286 descriptor_write.pImageInfo = nullptr;
16287 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16288 descriptor_write.dstSet = descriptor_set;
16289
16290 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16291
16292 m_errorMonitor->VerifyNotFound();
16293 // Cleanup
16294 vkFreeMemory(m_device->device(), mem, NULL);
16295 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16296 vkDestroyBuffer(m_device->device(), buffer, NULL);
16297 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16298}
16299
16300// This is a positive test. No failures are expected.
16301TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16302 VkResult err;
16303 bool pass;
16304
16305 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16306 "the buffer, create an image, and bind the same memory to "
16307 "it");
16308
16309 m_errorMonitor->ExpectSuccess();
16310
16311 ASSERT_NO_FATAL_FAILURE(InitState());
16312
16313 VkBuffer buffer;
16314 VkImage image;
16315 VkDeviceMemory mem;
16316 VkMemoryRequirements mem_reqs;
16317
16318 VkBufferCreateInfo buf_info = {};
16319 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16320 buf_info.pNext = NULL;
16321 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16322 buf_info.size = 256;
16323 buf_info.queueFamilyIndexCount = 0;
16324 buf_info.pQueueFamilyIndices = NULL;
16325 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16326 buf_info.flags = 0;
16327 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16328 ASSERT_VK_SUCCESS(err);
16329
16330 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16331
16332 VkMemoryAllocateInfo alloc_info = {};
16333 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16334 alloc_info.pNext = NULL;
16335 alloc_info.memoryTypeIndex = 0;
16336
16337 // Ensure memory is big enough for both bindings
16338 alloc_info.allocationSize = 0x10000;
16339
16340 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16341 if (!pass) {
16342 vkDestroyBuffer(m_device->device(), buffer, NULL);
16343 return;
16344 }
16345
16346 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16347 ASSERT_VK_SUCCESS(err);
16348
16349 uint8_t *pData;
16350 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16351 ASSERT_VK_SUCCESS(err);
16352
16353 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16354
16355 vkUnmapMemory(m_device->device(), mem);
16356
16357 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16358 ASSERT_VK_SUCCESS(err);
16359
16360 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16361 // memory. In fact, it was never used by the GPU.
16362 // Just be be sure, wait for idle.
16363 vkDestroyBuffer(m_device->device(), buffer, NULL);
16364 vkDeviceWaitIdle(m_device->device());
16365
16366 VkImageCreateInfo image_create_info = {};
16367 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16368 image_create_info.pNext = NULL;
16369 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16370 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16371 image_create_info.extent.width = 64;
16372 image_create_info.extent.height = 64;
16373 image_create_info.extent.depth = 1;
16374 image_create_info.mipLevels = 1;
16375 image_create_info.arrayLayers = 1;
16376 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16377 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16378 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16379 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16380 image_create_info.queueFamilyIndexCount = 0;
16381 image_create_info.pQueueFamilyIndices = NULL;
16382 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16383 image_create_info.flags = 0;
16384
16385 VkMemoryAllocateInfo mem_alloc = {};
16386 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16387 mem_alloc.pNext = NULL;
16388 mem_alloc.allocationSize = 0;
16389 mem_alloc.memoryTypeIndex = 0;
16390
16391 /* Create a mappable image. It will be the texture if linear images are ok
16392 * to be textures or it will be the staging image if they are not.
16393 */
16394 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16395 ASSERT_VK_SUCCESS(err);
16396
16397 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16398
16399 mem_alloc.allocationSize = mem_reqs.size;
16400
16401 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16402 if (!pass) {
16403 vkDestroyImage(m_device->device(), image, NULL);
16404 return;
16405 }
16406
16407 // VALIDATION FAILURE:
16408 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16409 ASSERT_VK_SUCCESS(err);
16410
16411 m_errorMonitor->VerifyNotFound();
16412
16413 vkFreeMemory(m_device->device(), mem, NULL);
16414 vkDestroyBuffer(m_device->device(), buffer, NULL);
16415 vkDestroyImage(m_device->device(), image, NULL);
16416}
16417
Tobin Ehlis953e8392016-11-17 10:54:13 -070016418TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16419 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16420 // We previously had a bug where dynamic offset of inactive bindings was still being used
16421 VkResult err;
16422 m_errorMonitor->ExpectSuccess();
16423
16424 ASSERT_NO_FATAL_FAILURE(InitState());
16425 ASSERT_NO_FATAL_FAILURE(InitViewport());
16426 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16427
16428 VkDescriptorPoolSize ds_type_count = {};
16429 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16430 ds_type_count.descriptorCount = 3;
16431
16432 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16433 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16434 ds_pool_ci.pNext = NULL;
16435 ds_pool_ci.maxSets = 1;
16436 ds_pool_ci.poolSizeCount = 1;
16437 ds_pool_ci.pPoolSizes = &ds_type_count;
16438
16439 VkDescriptorPool ds_pool;
16440 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16441 ASSERT_VK_SUCCESS(err);
16442
16443 const uint32_t BINDING_COUNT = 3;
16444 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
16445 dsl_binding[0].binding = 0;
16446 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16447 dsl_binding[0].descriptorCount = 1;
16448 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16449 dsl_binding[0].pImmutableSamplers = NULL;
16450 dsl_binding[1].binding = 1;
16451 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16452 dsl_binding[1].descriptorCount = 1;
16453 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16454 dsl_binding[1].pImmutableSamplers = NULL;
16455 dsl_binding[2].binding = 2;
16456 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16457 dsl_binding[2].descriptorCount = 1;
16458 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16459 dsl_binding[2].pImmutableSamplers = NULL;
16460
16461 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16462 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16463 ds_layout_ci.pNext = NULL;
16464 ds_layout_ci.bindingCount = BINDING_COUNT;
16465 ds_layout_ci.pBindings = dsl_binding;
16466 VkDescriptorSetLayout ds_layout;
16467 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16468 ASSERT_VK_SUCCESS(err);
16469
16470 VkDescriptorSet descriptor_set;
16471 VkDescriptorSetAllocateInfo alloc_info = {};
16472 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16473 alloc_info.descriptorSetCount = 1;
16474 alloc_info.descriptorPool = ds_pool;
16475 alloc_info.pSetLayouts = &ds_layout;
16476 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16477 ASSERT_VK_SUCCESS(err);
16478
16479 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16480 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16481 pipeline_layout_ci.pNext = NULL;
16482 pipeline_layout_ci.setLayoutCount = 1;
16483 pipeline_layout_ci.pSetLayouts = &ds_layout;
16484
16485 VkPipelineLayout pipeline_layout;
16486 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16487 ASSERT_VK_SUCCESS(err);
16488
16489 // Create two buffers to update the descriptors with
16490 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16491 uint32_t qfi = 0;
16492 VkBufferCreateInfo buffCI = {};
16493 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16494 buffCI.size = 2048;
16495 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16496 buffCI.queueFamilyIndexCount = 1;
16497 buffCI.pQueueFamilyIndices = &qfi;
16498
16499 VkBuffer dyub1;
16500 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16501 ASSERT_VK_SUCCESS(err);
16502 // buffer2
16503 buffCI.size = 1024;
16504 VkBuffer dyub2;
16505 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16506 ASSERT_VK_SUCCESS(err);
16507 // Allocate memory and bind to buffers
16508 VkMemoryAllocateInfo mem_alloc[2] = {};
16509 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16510 mem_alloc[0].pNext = NULL;
16511 mem_alloc[0].memoryTypeIndex = 0;
16512 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16513 mem_alloc[1].pNext = NULL;
16514 mem_alloc[1].memoryTypeIndex = 0;
16515
16516 VkMemoryRequirements mem_reqs1;
16517 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16518 VkMemoryRequirements mem_reqs2;
16519 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16520 mem_alloc[0].allocationSize = mem_reqs1.size;
16521 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16522 mem_alloc[1].allocationSize = mem_reqs2.size;
16523 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16524 if (!pass) {
16525 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16526 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16527 return;
16528 }
16529
16530 VkDeviceMemory mem1;
16531 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16532 ASSERT_VK_SUCCESS(err);
16533 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
16534 ASSERT_VK_SUCCESS(err);
16535 VkDeviceMemory mem2;
16536 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
16537 ASSERT_VK_SUCCESS(err);
16538 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
16539 ASSERT_VK_SUCCESS(err);
16540 // Update descriptors
16541 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
16542 buff_info[0].buffer = dyub1;
16543 buff_info[0].offset = 0;
16544 buff_info[0].range = 256;
16545 buff_info[1].buffer = dyub1;
16546 buff_info[1].offset = 256;
16547 buff_info[1].range = 512;
16548 buff_info[2].buffer = dyub2;
16549 buff_info[2].offset = 0;
16550 buff_info[2].range = 512;
16551
16552 VkWriteDescriptorSet descriptor_write;
16553 memset(&descriptor_write, 0, sizeof(descriptor_write));
16554 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16555 descriptor_write.dstSet = descriptor_set;
16556 descriptor_write.dstBinding = 0;
16557 descriptor_write.descriptorCount = BINDING_COUNT;
16558 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16559 descriptor_write.pBufferInfo = buff_info;
16560
16561 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16562
16563 BeginCommandBuffer();
16564
16565 // Create PSO to be used for draw-time errors below
16566 char const *vsSource = "#version 450\n"
16567 "\n"
16568 "out gl_PerVertex { \n"
16569 " vec4 gl_Position;\n"
16570 "};\n"
16571 "void main(){\n"
16572 " gl_Position = vec4(1);\n"
16573 "}\n";
16574 char const *fsSource = "#version 450\n"
16575 "\n"
16576 "layout(location=0) out vec4 x;\n"
16577 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
16578 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
16579 "void main(){\n"
16580 " x = vec4(bar1.y) + vec4(bar2.y);\n"
16581 "}\n";
16582 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16583 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16584 VkPipelineObj pipe(m_device);
16585 pipe.SetViewport(m_viewports);
16586 pipe.SetScissor(m_scissors);
16587 pipe.AddShader(&vs);
16588 pipe.AddShader(&fs);
16589 pipe.AddColorAttachment();
16590 pipe.CreateVKPipeline(pipeline_layout, renderPass());
16591
16592 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
16593 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
16594 // we used to have a bug in this case.
16595 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
16596 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
16597 &descriptor_set, BINDING_COUNT, dyn_off);
16598 Draw(1, 0, 0, 0);
16599 m_errorMonitor->VerifyNotFound();
16600
16601 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16602 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16603 vkFreeMemory(m_device->device(), mem1, NULL);
16604 vkFreeMemory(m_device->device(), mem2, NULL);
16605
16606 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
16607 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16608 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16609}
16610
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016611TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16612
16613 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16614 "mapping while using VK_WHOLE_SIZE does not cause access "
16615 "violations");
16616 VkResult err;
16617 uint8_t *pData;
16618 ASSERT_NO_FATAL_FAILURE(InitState());
16619
16620 VkDeviceMemory mem;
16621 VkMemoryRequirements mem_reqs;
16622 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
16623 VkMemoryAllocateInfo alloc_info = {};
16624 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16625 alloc_info.pNext = NULL;
16626 alloc_info.memoryTypeIndex = 0;
16627
16628 static const VkDeviceSize allocation_size = 0x1000;
16629 alloc_info.allocationSize = allocation_size;
16630
16631 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16632 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16633 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16634 if (!pass) {
16635 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16636 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16637 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16638 if (!pass) {
16639 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16640 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16641 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16642 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16643 if (!pass) {
16644 return;
16645 }
16646 }
16647 }
16648
16649 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16650 ASSERT_VK_SUCCESS(err);
16651
16652 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16653 // mapped range
16654 m_errorMonitor->ExpectSuccess();
16655 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16656 ASSERT_VK_SUCCESS(err);
16657 VkMappedMemoryRange mmr = {};
16658 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16659 mmr.memory = mem;
16660 mmr.offset = 0;
16661 mmr.size = VK_WHOLE_SIZE;
16662 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16663 ASSERT_VK_SUCCESS(err);
16664 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16665 ASSERT_VK_SUCCESS(err);
16666 m_errorMonitor->VerifyNotFound();
16667 vkUnmapMemory(m_device->device(), mem);
16668
16669 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16670 // mapped range
16671 m_errorMonitor->ExpectSuccess();
16672 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16673 ASSERT_VK_SUCCESS(err);
16674 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16675 mmr.memory = mem;
16676 mmr.offset = 13;
16677 mmr.size = VK_WHOLE_SIZE;
16678 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16679 ASSERT_VK_SUCCESS(err);
16680 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16681 ASSERT_VK_SUCCESS(err);
16682 m_errorMonitor->VerifyNotFound();
16683 vkUnmapMemory(m_device->device(), mem);
16684
16685 // Map with prime offset and size
16686 // Flush/Invalidate subrange of mapped area with prime offset and size
16687 m_errorMonitor->ExpectSuccess();
16688 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16689 ASSERT_VK_SUCCESS(err);
16690 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16691 mmr.memory = mem;
16692 mmr.offset = allocation_size - 107;
16693 mmr.size = 61;
16694 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16695 ASSERT_VK_SUCCESS(err);
16696 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16697 ASSERT_VK_SUCCESS(err);
16698 m_errorMonitor->VerifyNotFound();
16699 vkUnmapMemory(m_device->device(), mem);
16700
16701 // Map without offset and flush WHOLE_SIZE with two separate offsets
16702 m_errorMonitor->ExpectSuccess();
16703 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16704 ASSERT_VK_SUCCESS(err);
16705 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16706 mmr.memory = mem;
16707 mmr.offset = allocation_size - 100;
16708 mmr.size = VK_WHOLE_SIZE;
16709 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16710 ASSERT_VK_SUCCESS(err);
16711 mmr.offset = allocation_size - 200;
16712 mmr.size = VK_WHOLE_SIZE;
16713 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16714 ASSERT_VK_SUCCESS(err);
16715 m_errorMonitor->VerifyNotFound();
16716 vkUnmapMemory(m_device->device(), mem);
16717
16718 vkFreeMemory(m_device->device(), mem, NULL);
16719}
16720
16721// This is a positive test. We used to expect error in this case but spec now allows it
16722TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16723 m_errorMonitor->ExpectSuccess();
16724 vk_testing::Fence testFence;
16725 VkFenceCreateInfo fenceInfo = {};
16726 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16727 fenceInfo.pNext = NULL;
16728
16729 ASSERT_NO_FATAL_FAILURE(InitState());
16730 testFence.init(*m_device, fenceInfo);
16731 VkFence fences[1] = { testFence.handle() };
16732 VkResult result = vkResetFences(m_device->device(), 1, fences);
16733 ASSERT_VK_SUCCESS(result);
16734
16735 m_errorMonitor->VerifyNotFound();
16736}
16737
16738TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16739 m_errorMonitor->ExpectSuccess();
16740
16741 ASSERT_NO_FATAL_FAILURE(InitState());
16742 VkResult err;
16743
16744 // Record (empty!) command buffer that can be submitted multiple times
16745 // simultaneously.
16746 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16747 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16748 m_commandBuffer->BeginCommandBuffer(&cbbi);
16749 m_commandBuffer->EndCommandBuffer();
16750
16751 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16752 VkFence fence;
16753 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16754 ASSERT_VK_SUCCESS(err);
16755
16756 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16757 VkSemaphore s1, s2;
16758 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16759 ASSERT_VK_SUCCESS(err);
16760 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16761 ASSERT_VK_SUCCESS(err);
16762
16763 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16764 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16765 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16766 ASSERT_VK_SUCCESS(err);
16767
16768 // Submit CB again, signaling s2.
16769 si.pSignalSemaphores = &s2;
16770 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16771 ASSERT_VK_SUCCESS(err);
16772
16773 // Wait for fence.
16774 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16775 ASSERT_VK_SUCCESS(err);
16776
16777 // CB is still in flight from second submission, but semaphore s1 is no
16778 // longer in flight. delete it.
16779 vkDestroySemaphore(m_device->device(), s1, nullptr);
16780
16781 m_errorMonitor->VerifyNotFound();
16782
16783 // Force device idle and clean up remaining objects
16784 vkDeviceWaitIdle(m_device->device());
16785 vkDestroySemaphore(m_device->device(), s2, nullptr);
16786 vkDestroyFence(m_device->device(), fence, nullptr);
16787}
16788
16789TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16790 m_errorMonitor->ExpectSuccess();
16791
16792 ASSERT_NO_FATAL_FAILURE(InitState());
16793 VkResult err;
16794
16795 // A fence created signaled
16796 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16797 VkFence f1;
16798 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16799 ASSERT_VK_SUCCESS(err);
16800
16801 // A fence created not
16802 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16803 VkFence f2;
16804 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16805 ASSERT_VK_SUCCESS(err);
16806
16807 // Submit the unsignaled fence
16808 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16809 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16810
16811 // Wait on both fences, with signaled first.
16812 VkFence fences[] = { f1, f2 };
16813 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16814
16815 // Should have both retired!
16816 vkDestroyFence(m_device->device(), f1, nullptr);
16817 vkDestroyFence(m_device->device(), f2, nullptr);
16818
16819 m_errorMonitor->VerifyNotFound();
16820}
16821
16822TEST_F(VkPositiveLayerTest, ValidUsage) {
16823 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16824 "doesn't generate validation errors");
16825
16826 ASSERT_NO_FATAL_FAILURE(InitState());
16827
16828 m_errorMonitor->ExpectSuccess();
16829 // Verify that we can create a view with usage INPUT_ATTACHMENT
16830 VkImageObj image(m_device);
16831 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16832 ASSERT_TRUE(image.initialized());
16833 VkImageView imageView;
16834 VkImageViewCreateInfo ivci = {};
16835 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16836 ivci.image = image.handle();
16837 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16838 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16839 ivci.subresourceRange.layerCount = 1;
16840 ivci.subresourceRange.baseMipLevel = 0;
16841 ivci.subresourceRange.levelCount = 1;
16842 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16843
16844 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16845 m_errorMonitor->VerifyNotFound();
16846 vkDestroyImageView(m_device->device(), imageView, NULL);
16847}
16848
16849// This is a positive test. No failures are expected.
16850TEST_F(VkPositiveLayerTest, BindSparse) {
16851 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16852 "and then free the memory");
16853
16854 ASSERT_NO_FATAL_FAILURE(InitState());
16855
16856 auto index = m_device->graphics_queue_node_index_;
16857 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16858 return;
16859
16860 m_errorMonitor->ExpectSuccess();
16861
16862 VkImage image;
16863 VkImageCreateInfo image_create_info = {};
16864 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16865 image_create_info.pNext = NULL;
16866 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16867 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16868 image_create_info.extent.width = 64;
16869 image_create_info.extent.height = 64;
16870 image_create_info.extent.depth = 1;
16871 image_create_info.mipLevels = 1;
16872 image_create_info.arrayLayers = 1;
16873 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16874 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16875 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16876 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16877 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16878 ASSERT_VK_SUCCESS(err);
16879
16880 VkMemoryRequirements memory_reqs;
16881 VkDeviceMemory memory_one, memory_two;
16882 bool pass;
16883 VkMemoryAllocateInfo memory_info = {};
16884 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16885 memory_info.pNext = NULL;
16886 memory_info.allocationSize = 0;
16887 memory_info.memoryTypeIndex = 0;
16888 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16889 // Find an image big enough to allow sparse mapping of 2 memory regions
16890 // Increase the image size until it is at least twice the
16891 // size of the required alignment, to ensure we can bind both
16892 // allocated memory blocks to the image on aligned offsets.
16893 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16894 vkDestroyImage(m_device->device(), image, nullptr);
16895 image_create_info.extent.width *= 2;
16896 image_create_info.extent.height *= 2;
16897 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16898 ASSERT_VK_SUCCESS(err);
16899 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16900 }
16901 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16902 // at the end of the first
16903 memory_info.allocationSize = memory_reqs.alignment;
16904 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16905 ASSERT_TRUE(pass);
16906 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16907 ASSERT_VK_SUCCESS(err);
16908 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16909 ASSERT_VK_SUCCESS(err);
16910 VkSparseMemoryBind binds[2];
16911 binds[0].flags = 0;
16912 binds[0].memory = memory_one;
16913 binds[0].memoryOffset = 0;
16914 binds[0].resourceOffset = 0;
16915 binds[0].size = memory_info.allocationSize;
16916 binds[1].flags = 0;
16917 binds[1].memory = memory_two;
16918 binds[1].memoryOffset = 0;
16919 binds[1].resourceOffset = memory_info.allocationSize;
16920 binds[1].size = memory_info.allocationSize;
16921
16922 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16923 opaqueBindInfo.image = image;
16924 opaqueBindInfo.bindCount = 2;
16925 opaqueBindInfo.pBinds = binds;
16926
16927 VkFence fence = VK_NULL_HANDLE;
16928 VkBindSparseInfo bindSparseInfo = {};
16929 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16930 bindSparseInfo.imageOpaqueBindCount = 1;
16931 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16932
16933 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16934 vkQueueWaitIdle(m_device->m_queue);
16935 vkDestroyImage(m_device->device(), image, NULL);
16936 vkFreeMemory(m_device->device(), memory_one, NULL);
16937 vkFreeMemory(m_device->device(), memory_two, NULL);
16938 m_errorMonitor->VerifyNotFound();
16939}
16940
16941TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16942 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16943 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16944 "the command buffer has prior knowledge of that "
16945 "attachment's layout.");
16946
16947 m_errorMonitor->ExpectSuccess();
16948
16949 ASSERT_NO_FATAL_FAILURE(InitState());
16950
16951 // A renderpass with one color attachment.
16952 VkAttachmentDescription attachment = { 0,
16953 VK_FORMAT_R8G8B8A8_UNORM,
16954 VK_SAMPLE_COUNT_1_BIT,
16955 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16956 VK_ATTACHMENT_STORE_OP_STORE,
16957 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16958 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16959 VK_IMAGE_LAYOUT_UNDEFINED,
16960 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16961
16962 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16963
16964 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16965
16966 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16967
16968 VkRenderPass rp;
16969 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16970 ASSERT_VK_SUCCESS(err);
16971
16972 // A compatible framebuffer.
16973 VkImageObj image(m_device);
16974 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16975 ASSERT_TRUE(image.initialized());
16976
16977 VkImageViewCreateInfo ivci = {
16978 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16979 nullptr,
16980 0,
16981 image.handle(),
16982 VK_IMAGE_VIEW_TYPE_2D,
16983 VK_FORMAT_R8G8B8A8_UNORM,
16984 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16985 VK_COMPONENT_SWIZZLE_IDENTITY },
16986 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16987 };
16988 VkImageView view;
16989 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16990 ASSERT_VK_SUCCESS(err);
16991
16992 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16993 VkFramebuffer fb;
16994 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16995 ASSERT_VK_SUCCESS(err);
16996
16997 // Record a single command buffer which uses this renderpass twice. The
16998 // bug is triggered at the beginning of the second renderpass, when the
16999 // command buffer already has a layout recorded for the attachment.
17000 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17001 BeginCommandBuffer();
17002 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17003 vkCmdEndRenderPass(m_commandBuffer->handle());
17004 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17005
17006 m_errorMonitor->VerifyNotFound();
17007
17008 vkCmdEndRenderPass(m_commandBuffer->handle());
17009 EndCommandBuffer();
17010
17011 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17012 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17013 vkDestroyImageView(m_device->device(), view, nullptr);
17014}
17015
17016TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17017 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17018 "command buffer, bind them together, then destroy "
17019 "command pool and framebuffer and verify there are no "
17020 "errors.");
17021
17022 m_errorMonitor->ExpectSuccess();
17023
17024 ASSERT_NO_FATAL_FAILURE(InitState());
17025
17026 // A renderpass with one color attachment.
17027 VkAttachmentDescription attachment = { 0,
17028 VK_FORMAT_R8G8B8A8_UNORM,
17029 VK_SAMPLE_COUNT_1_BIT,
17030 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17031 VK_ATTACHMENT_STORE_OP_STORE,
17032 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17033 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17034 VK_IMAGE_LAYOUT_UNDEFINED,
17035 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17036
17037 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17038
17039 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17040
17041 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17042
17043 VkRenderPass rp;
17044 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17045 ASSERT_VK_SUCCESS(err);
17046
17047 // A compatible framebuffer.
17048 VkImageObj image(m_device);
17049 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17050 ASSERT_TRUE(image.initialized());
17051
17052 VkImageViewCreateInfo ivci = {
17053 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17054 nullptr,
17055 0,
17056 image.handle(),
17057 VK_IMAGE_VIEW_TYPE_2D,
17058 VK_FORMAT_R8G8B8A8_UNORM,
17059 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17060 VK_COMPONENT_SWIZZLE_IDENTITY },
17061 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17062 };
17063 VkImageView view;
17064 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17065 ASSERT_VK_SUCCESS(err);
17066
17067 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17068 VkFramebuffer fb;
17069 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17070 ASSERT_VK_SUCCESS(err);
17071
17072 // Explicitly create a command buffer to bind the FB to so that we can then
17073 // destroy the command pool in order to implicitly free command buffer
17074 VkCommandPool command_pool;
17075 VkCommandPoolCreateInfo pool_create_info{};
17076 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17077 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17078 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17079 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17080
17081 VkCommandBuffer command_buffer;
17082 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17083 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17084 command_buffer_allocate_info.commandPool = command_pool;
17085 command_buffer_allocate_info.commandBufferCount = 1;
17086 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17087 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17088
17089 // Begin our cmd buffer with renderpass using our framebuffer
17090 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17091 VkCommandBufferBeginInfo begin_info{};
17092 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17093 vkBeginCommandBuffer(command_buffer, &begin_info);
17094
17095 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17096 vkCmdEndRenderPass(command_buffer);
17097 vkEndCommandBuffer(command_buffer);
17098 vkDestroyImageView(m_device->device(), view, nullptr);
17099 // Destroy command pool to implicitly free command buffer
17100 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17101 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17102 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17103 m_errorMonitor->VerifyNotFound();
17104}
17105
17106TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17107 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17108 "transitions for the first subpass");
17109
17110 m_errorMonitor->ExpectSuccess();
17111
17112 ASSERT_NO_FATAL_FAILURE(InitState());
17113
17114 // A renderpass with one color attachment.
17115 VkAttachmentDescription attachment = { 0,
17116 VK_FORMAT_R8G8B8A8_UNORM,
17117 VK_SAMPLE_COUNT_1_BIT,
17118 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17119 VK_ATTACHMENT_STORE_OP_STORE,
17120 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17121 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17122 VK_IMAGE_LAYOUT_UNDEFINED,
17123 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17124
17125 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17126
17127 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17128
17129 VkSubpassDependency dep = { 0,
17130 0,
17131 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17132 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17133 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17134 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17135 VK_DEPENDENCY_BY_REGION_BIT };
17136
17137 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17138
17139 VkResult err;
17140 VkRenderPass rp;
17141 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17142 ASSERT_VK_SUCCESS(err);
17143
17144 // A compatible framebuffer.
17145 VkImageObj image(m_device);
17146 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17147 ASSERT_TRUE(image.initialized());
17148
17149 VkImageViewCreateInfo ivci = {
17150 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17151 nullptr,
17152 0,
17153 image.handle(),
17154 VK_IMAGE_VIEW_TYPE_2D,
17155 VK_FORMAT_R8G8B8A8_UNORM,
17156 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17157 VK_COMPONENT_SWIZZLE_IDENTITY },
17158 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17159 };
17160 VkImageView view;
17161 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17162 ASSERT_VK_SUCCESS(err);
17163
17164 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17165 VkFramebuffer fb;
17166 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17167 ASSERT_VK_SUCCESS(err);
17168
17169 // Record a single command buffer which issues a pipeline barrier w/
17170 // image memory barrier for the attachment. This detects the previously
17171 // missing tracking of the subpass layout by throwing a validation error
17172 // if it doesn't occur.
17173 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17174 BeginCommandBuffer();
17175 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17176
17177 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17178 nullptr,
17179 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17180 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17181 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17182 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17183 VK_QUEUE_FAMILY_IGNORED,
17184 VK_QUEUE_FAMILY_IGNORED,
17185 image.handle(),
17186 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17187 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17188 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17189 &imb);
17190
17191 vkCmdEndRenderPass(m_commandBuffer->handle());
17192 m_errorMonitor->VerifyNotFound();
17193 EndCommandBuffer();
17194
17195 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17196 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17197 vkDestroyImageView(m_device->device(), view, nullptr);
17198}
17199
17200TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17201 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17202 "is used as a depth/stencil framebuffer attachment, the "
17203 "aspectMask is ignored and both depth and stencil image "
17204 "subresources are used.");
17205
17206 VkFormatProperties format_properties;
17207 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17208 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17209 return;
17210 }
17211
17212 m_errorMonitor->ExpectSuccess();
17213
17214 ASSERT_NO_FATAL_FAILURE(InitState());
17215
17216 VkAttachmentDescription attachment = { 0,
17217 VK_FORMAT_D32_SFLOAT_S8_UINT,
17218 VK_SAMPLE_COUNT_1_BIT,
17219 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17220 VK_ATTACHMENT_STORE_OP_STORE,
17221 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17222 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17223 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17224 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17225
17226 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17227
17228 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17229
17230 VkSubpassDependency dep = { 0,
17231 0,
17232 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17233 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17234 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17235 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17236 VK_DEPENDENCY_BY_REGION_BIT};
17237
17238 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17239
17240 VkResult err;
17241 VkRenderPass rp;
17242 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17243 ASSERT_VK_SUCCESS(err);
17244
17245 VkImageObj image(m_device);
17246 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17247 0x26, // usage
17248 VK_IMAGE_TILING_OPTIMAL, 0);
17249 ASSERT_TRUE(image.initialized());
17250 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17251
17252 VkImageViewCreateInfo ivci = {
17253 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17254 nullptr,
17255 0,
17256 image.handle(),
17257 VK_IMAGE_VIEW_TYPE_2D,
17258 VK_FORMAT_D32_SFLOAT_S8_UINT,
17259 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17260 { 0x2, 0, 1, 0, 1 },
17261 };
17262 VkImageView view;
17263 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17264 ASSERT_VK_SUCCESS(err);
17265
17266 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17267 VkFramebuffer fb;
17268 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17269 ASSERT_VK_SUCCESS(err);
17270
17271 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17272 BeginCommandBuffer();
17273 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17274
17275 VkImageMemoryBarrier imb = {};
17276 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17277 imb.pNext = nullptr;
17278 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17279 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17280 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17281 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17282 imb.srcQueueFamilyIndex = 0;
17283 imb.dstQueueFamilyIndex = 0;
17284 imb.image = image.handle();
17285 imb.subresourceRange.aspectMask = 0x6;
17286 imb.subresourceRange.baseMipLevel = 0;
17287 imb.subresourceRange.levelCount = 0x1;
17288 imb.subresourceRange.baseArrayLayer = 0;
17289 imb.subresourceRange.layerCount = 0x1;
17290
17291 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17292 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17293 &imb);
17294
17295 vkCmdEndRenderPass(m_commandBuffer->handle());
17296 EndCommandBuffer();
17297 QueueCommandBuffer(false);
17298 m_errorMonitor->VerifyNotFound();
17299
17300 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17301 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17302 vkDestroyImageView(m_device->device(), view, nullptr);
17303}
17304
17305TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17306 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17307 "errors, when an attachment reference is "
17308 "VK_ATTACHMENT_UNUSED");
17309
17310 m_errorMonitor->ExpectSuccess();
17311
17312 ASSERT_NO_FATAL_FAILURE(InitState());
17313
17314 // A renderpass with no attachments
17315 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17316
17317 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17318
17319 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17320
17321 VkRenderPass rp;
17322 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17323 ASSERT_VK_SUCCESS(err);
17324
17325 // A compatible framebuffer.
17326 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17327 VkFramebuffer fb;
17328 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17329 ASSERT_VK_SUCCESS(err);
17330
17331 // Record a command buffer which just begins and ends the renderpass. The
17332 // bug manifests in BeginRenderPass.
17333 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17334 BeginCommandBuffer();
17335 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17336 vkCmdEndRenderPass(m_commandBuffer->handle());
17337 m_errorMonitor->VerifyNotFound();
17338 EndCommandBuffer();
17339
17340 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17341 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17342}
17343
17344// This is a positive test. No errors are expected.
17345TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17346 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17347 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17348 VkResult result = VK_SUCCESS;
17349 VkImageFormatProperties formatProps;
17350 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17351 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17352 &formatProps);
17353 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17354 return;
17355 }
17356
17357 ASSERT_NO_FATAL_FAILURE(InitState());
17358 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17359 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17360 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17361 VkAttachmentDescription att = {};
17362 VkAttachmentReference ref = {};
17363 att.format = depth_stencil_fmt;
17364 att.samples = VK_SAMPLE_COUNT_1_BIT;
17365 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17366 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17367 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17368 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17369 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17370 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17371
17372 VkClearValue clear;
17373 clear.depthStencil.depth = 1.0;
17374 clear.depthStencil.stencil = 0;
17375 ref.attachment = 0;
17376 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17377
17378 VkSubpassDescription subpass = {};
17379 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17380 subpass.flags = 0;
17381 subpass.inputAttachmentCount = 0;
17382 subpass.pInputAttachments = NULL;
17383 subpass.colorAttachmentCount = 0;
17384 subpass.pColorAttachments = NULL;
17385 subpass.pResolveAttachments = NULL;
17386 subpass.pDepthStencilAttachment = &ref;
17387 subpass.preserveAttachmentCount = 0;
17388 subpass.pPreserveAttachments = NULL;
17389
17390 VkRenderPass rp;
17391 VkRenderPassCreateInfo rp_info = {};
17392 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17393 rp_info.attachmentCount = 1;
17394 rp_info.pAttachments = &att;
17395 rp_info.subpassCount = 1;
17396 rp_info.pSubpasses = &subpass;
17397 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17398 ASSERT_VK_SUCCESS(result);
17399
17400 VkImageView *depthView = m_depthStencil->BindInfo();
17401 VkFramebufferCreateInfo fb_info = {};
17402 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17403 fb_info.pNext = NULL;
17404 fb_info.renderPass = rp;
17405 fb_info.attachmentCount = 1;
17406 fb_info.pAttachments = depthView;
17407 fb_info.width = 100;
17408 fb_info.height = 100;
17409 fb_info.layers = 1;
17410 VkFramebuffer fb;
17411 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17412 ASSERT_VK_SUCCESS(result);
17413
17414 VkRenderPassBeginInfo rpbinfo = {};
17415 rpbinfo.clearValueCount = 1;
17416 rpbinfo.pClearValues = &clear;
17417 rpbinfo.pNext = NULL;
17418 rpbinfo.renderPass = rp;
17419 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17420 rpbinfo.renderArea.extent.width = 100;
17421 rpbinfo.renderArea.extent.height = 100;
17422 rpbinfo.renderArea.offset.x = 0;
17423 rpbinfo.renderArea.offset.y = 0;
17424 rpbinfo.framebuffer = fb;
17425
17426 VkFence fence = {};
17427 VkFenceCreateInfo fence_ci = {};
17428 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17429 fence_ci.pNext = nullptr;
17430 fence_ci.flags = 0;
17431 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17432 ASSERT_VK_SUCCESS(result);
17433
17434 m_commandBuffer->BeginCommandBuffer();
17435 m_commandBuffer->BeginRenderPass(rpbinfo);
17436 m_commandBuffer->EndRenderPass();
17437 m_commandBuffer->EndCommandBuffer();
17438 m_commandBuffer->QueueCommandBuffer(fence);
17439
17440 VkImageObj destImage(m_device);
17441 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17442 VK_IMAGE_TILING_OPTIMAL, 0);
17443 VkImageMemoryBarrier barrier = {};
17444 VkImageSubresourceRange range;
17445 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17446 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17447 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17448 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17449 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17450 barrier.image = m_depthStencil->handle();
17451 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17452 range.baseMipLevel = 0;
17453 range.levelCount = 1;
17454 range.baseArrayLayer = 0;
17455 range.layerCount = 1;
17456 barrier.subresourceRange = range;
17457 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17458 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17459 cmdbuf.BeginCommandBuffer();
17460 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17461 &barrier);
17462 barrier.srcAccessMask = 0;
17463 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17464 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17465 barrier.image = destImage.handle();
17466 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17467 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17468 &barrier);
17469 VkImageCopy cregion;
17470 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17471 cregion.srcSubresource.mipLevel = 0;
17472 cregion.srcSubresource.baseArrayLayer = 0;
17473 cregion.srcSubresource.layerCount = 1;
17474 cregion.srcOffset.x = 0;
17475 cregion.srcOffset.y = 0;
17476 cregion.srcOffset.z = 0;
17477 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17478 cregion.dstSubresource.mipLevel = 0;
17479 cregion.dstSubresource.baseArrayLayer = 0;
17480 cregion.dstSubresource.layerCount = 1;
17481 cregion.dstOffset.x = 0;
17482 cregion.dstOffset.y = 0;
17483 cregion.dstOffset.z = 0;
17484 cregion.extent.width = 100;
17485 cregion.extent.height = 100;
17486 cregion.extent.depth = 1;
17487 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17488 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17489 cmdbuf.EndCommandBuffer();
17490
17491 VkSubmitInfo submit_info;
17492 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17493 submit_info.pNext = NULL;
17494 submit_info.waitSemaphoreCount = 0;
17495 submit_info.pWaitSemaphores = NULL;
17496 submit_info.pWaitDstStageMask = NULL;
17497 submit_info.commandBufferCount = 1;
17498 submit_info.pCommandBuffers = &cmdbuf.handle();
17499 submit_info.signalSemaphoreCount = 0;
17500 submit_info.pSignalSemaphores = NULL;
17501
17502 m_errorMonitor->ExpectSuccess();
17503 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17504 m_errorMonitor->VerifyNotFound();
17505
17506 vkQueueWaitIdle(m_device->m_queue);
17507 vkDestroyFence(m_device->device(), fence, nullptr);
17508 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17509 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17510}
17511
17512// This is a positive test. No errors should be generated.
17513TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17514 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17515
17516 m_errorMonitor->ExpectSuccess();
17517 ASSERT_NO_FATAL_FAILURE(InitState());
17518
17519 VkEvent event;
17520 VkEventCreateInfo event_create_info{};
17521 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17522 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17523
17524 VkCommandPool command_pool;
17525 VkCommandPoolCreateInfo pool_create_info{};
17526 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17527 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17528 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17529 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17530
17531 VkCommandBuffer command_buffer;
17532 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17533 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17534 command_buffer_allocate_info.commandPool = command_pool;
17535 command_buffer_allocate_info.commandBufferCount = 1;
17536 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17537 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17538
17539 VkQueue queue = VK_NULL_HANDLE;
17540 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17541
17542 {
17543 VkCommandBufferBeginInfo begin_info{};
17544 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17545 vkBeginCommandBuffer(command_buffer, &begin_info);
17546
17547 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17548 nullptr, 0, nullptr);
17549 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17550 vkEndCommandBuffer(command_buffer);
17551 }
17552 {
17553 VkSubmitInfo submit_info{};
17554 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17555 submit_info.commandBufferCount = 1;
17556 submit_info.pCommandBuffers = &command_buffer;
17557 submit_info.signalSemaphoreCount = 0;
17558 submit_info.pSignalSemaphores = nullptr;
17559 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17560 }
17561 { vkSetEvent(m_device->device(), event); }
17562
17563 vkQueueWaitIdle(queue);
17564
17565 vkDestroyEvent(m_device->device(), event, nullptr);
17566 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17567 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17568
17569 m_errorMonitor->VerifyNotFound();
17570}
17571// This is a positive test. No errors should be generated.
17572TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17573 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17574
17575 ASSERT_NO_FATAL_FAILURE(InitState());
17576 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17577 return;
17578
17579 m_errorMonitor->ExpectSuccess();
17580
17581 VkQueryPool query_pool;
17582 VkQueryPoolCreateInfo query_pool_create_info{};
17583 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17584 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17585 query_pool_create_info.queryCount = 1;
17586 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17587
17588 VkCommandPool command_pool;
17589 VkCommandPoolCreateInfo pool_create_info{};
17590 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17591 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17592 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17593 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17594
17595 VkCommandBuffer command_buffer;
17596 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17597 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17598 command_buffer_allocate_info.commandPool = command_pool;
17599 command_buffer_allocate_info.commandBufferCount = 1;
17600 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17601 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17602
17603 VkCommandBuffer secondary_command_buffer;
17604 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17605 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17606
17607 VkQueue queue = VK_NULL_HANDLE;
17608 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17609
17610 uint32_t qfi = 0;
17611 VkBufferCreateInfo buff_create_info = {};
17612 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17613 buff_create_info.size = 1024;
17614 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17615 buff_create_info.queueFamilyIndexCount = 1;
17616 buff_create_info.pQueueFamilyIndices = &qfi;
17617
17618 VkResult err;
17619 VkBuffer buffer;
17620 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17621 ASSERT_VK_SUCCESS(err);
17622 VkMemoryAllocateInfo mem_alloc = {};
17623 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17624 mem_alloc.pNext = NULL;
17625 mem_alloc.allocationSize = 1024;
17626 mem_alloc.memoryTypeIndex = 0;
17627
17628 VkMemoryRequirements memReqs;
17629 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17630 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17631 if (!pass) {
17632 vkDestroyBuffer(m_device->device(), buffer, NULL);
17633 return;
17634 }
17635
17636 VkDeviceMemory mem;
17637 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17638 ASSERT_VK_SUCCESS(err);
17639 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17640 ASSERT_VK_SUCCESS(err);
17641
17642 VkCommandBufferInheritanceInfo hinfo = {};
17643 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17644 hinfo.renderPass = VK_NULL_HANDLE;
17645 hinfo.subpass = 0;
17646 hinfo.framebuffer = VK_NULL_HANDLE;
17647 hinfo.occlusionQueryEnable = VK_FALSE;
17648 hinfo.queryFlags = 0;
17649 hinfo.pipelineStatistics = 0;
17650
17651 {
17652 VkCommandBufferBeginInfo begin_info{};
17653 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17654 begin_info.pInheritanceInfo = &hinfo;
17655 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17656
17657 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17658 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17659
17660 vkEndCommandBuffer(secondary_command_buffer);
17661
17662 begin_info.pInheritanceInfo = nullptr;
17663 vkBeginCommandBuffer(command_buffer, &begin_info);
17664
17665 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17666 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17667
17668 vkEndCommandBuffer(command_buffer);
17669 }
17670 {
17671 VkSubmitInfo submit_info{};
17672 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17673 submit_info.commandBufferCount = 1;
17674 submit_info.pCommandBuffers = &command_buffer;
17675 submit_info.signalSemaphoreCount = 0;
17676 submit_info.pSignalSemaphores = nullptr;
17677 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17678 }
17679
17680 vkQueueWaitIdle(queue);
17681
17682 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17683 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17684 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17685 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17686 vkDestroyBuffer(m_device->device(), buffer, NULL);
17687 vkFreeMemory(m_device->device(), mem, NULL);
17688
17689 m_errorMonitor->VerifyNotFound();
17690}
17691
17692// This is a positive test. No errors should be generated.
17693TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17694 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17695
17696 ASSERT_NO_FATAL_FAILURE(InitState());
17697 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17698 return;
17699
17700 m_errorMonitor->ExpectSuccess();
17701
17702 VkQueryPool query_pool;
17703 VkQueryPoolCreateInfo query_pool_create_info{};
17704 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17705 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17706 query_pool_create_info.queryCount = 1;
17707 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17708
17709 VkCommandPool command_pool;
17710 VkCommandPoolCreateInfo pool_create_info{};
17711 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17712 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17713 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17714 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17715
17716 VkCommandBuffer command_buffer[2];
17717 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17718 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17719 command_buffer_allocate_info.commandPool = command_pool;
17720 command_buffer_allocate_info.commandBufferCount = 2;
17721 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17722 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17723
17724 VkQueue queue = VK_NULL_HANDLE;
17725 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17726
17727 uint32_t qfi = 0;
17728 VkBufferCreateInfo buff_create_info = {};
17729 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17730 buff_create_info.size = 1024;
17731 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17732 buff_create_info.queueFamilyIndexCount = 1;
17733 buff_create_info.pQueueFamilyIndices = &qfi;
17734
17735 VkResult err;
17736 VkBuffer buffer;
17737 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17738 ASSERT_VK_SUCCESS(err);
17739 VkMemoryAllocateInfo mem_alloc = {};
17740 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17741 mem_alloc.pNext = NULL;
17742 mem_alloc.allocationSize = 1024;
17743 mem_alloc.memoryTypeIndex = 0;
17744
17745 VkMemoryRequirements memReqs;
17746 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17747 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17748 if (!pass) {
17749 vkDestroyBuffer(m_device->device(), buffer, NULL);
17750 return;
17751 }
17752
17753 VkDeviceMemory mem;
17754 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17755 ASSERT_VK_SUCCESS(err);
17756 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17757 ASSERT_VK_SUCCESS(err);
17758
17759 {
17760 VkCommandBufferBeginInfo begin_info{};
17761 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17762 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17763
17764 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17765 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17766
17767 vkEndCommandBuffer(command_buffer[0]);
17768
17769 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17770
17771 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17772
17773 vkEndCommandBuffer(command_buffer[1]);
17774 }
17775 {
17776 VkSubmitInfo submit_info{};
17777 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17778 submit_info.commandBufferCount = 2;
17779 submit_info.pCommandBuffers = command_buffer;
17780 submit_info.signalSemaphoreCount = 0;
17781 submit_info.pSignalSemaphores = nullptr;
17782 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17783 }
17784
17785 vkQueueWaitIdle(queue);
17786
17787 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17788 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17789 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17790 vkDestroyBuffer(m_device->device(), buffer, NULL);
17791 vkFreeMemory(m_device->device(), mem, NULL);
17792
17793 m_errorMonitor->VerifyNotFound();
17794}
17795
Tony Barbourc46924f2016-11-04 11:49:52 -060017796TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017797 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17798
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017799 ASSERT_NO_FATAL_FAILURE(InitState());
17800 VkEvent event;
17801 VkEventCreateInfo event_create_info{};
17802 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17803 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17804
17805 VkCommandPool command_pool;
17806 VkCommandPoolCreateInfo pool_create_info{};
17807 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17808 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17809 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17810 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17811
17812 VkCommandBuffer command_buffer;
17813 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17814 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17815 command_buffer_allocate_info.commandPool = command_pool;
17816 command_buffer_allocate_info.commandBufferCount = 1;
17817 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17818 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17819
17820 VkQueue queue = VK_NULL_HANDLE;
17821 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17822
17823 {
17824 VkCommandBufferBeginInfo begin_info{};
17825 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17826 vkBeginCommandBuffer(command_buffer, &begin_info);
17827
17828 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017829 vkEndCommandBuffer(command_buffer);
17830 }
17831 {
17832 VkSubmitInfo submit_info{};
17833 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17834 submit_info.commandBufferCount = 1;
17835 submit_info.pCommandBuffers = &command_buffer;
17836 submit_info.signalSemaphoreCount = 0;
17837 submit_info.pSignalSemaphores = nullptr;
17838 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17839 }
17840 {
17841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17842 "command buffer.");
17843 vkSetEvent(m_device->device(), event);
17844 m_errorMonitor->VerifyFound();
17845 }
17846
17847 vkQueueWaitIdle(queue);
17848
17849 vkDestroyEvent(m_device->device(), event, nullptr);
17850 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17851 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17852}
17853
17854// This is a positive test. No errors should be generated.
17855TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17856 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17857 "run through a Submit & WaitForFences cycle 3 times. This "
17858 "previously revealed a bug so running this positive test "
17859 "to prevent a regression.");
17860 m_errorMonitor->ExpectSuccess();
17861
17862 ASSERT_NO_FATAL_FAILURE(InitState());
17863 VkQueue queue = VK_NULL_HANDLE;
17864 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17865
17866 static const uint32_t NUM_OBJECTS = 2;
17867 static const uint32_t NUM_FRAMES = 3;
17868 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17869 VkFence fences[NUM_OBJECTS] = {};
17870
17871 VkCommandPool cmd_pool;
17872 VkCommandPoolCreateInfo cmd_pool_ci = {};
17873 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17874 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17875 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17876 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17877 ASSERT_VK_SUCCESS(err);
17878
17879 VkCommandBufferAllocateInfo cmd_buf_info = {};
17880 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17881 cmd_buf_info.commandPool = cmd_pool;
17882 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17883 cmd_buf_info.commandBufferCount = 1;
17884
17885 VkFenceCreateInfo fence_ci = {};
17886 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17887 fence_ci.pNext = nullptr;
17888 fence_ci.flags = 0;
17889
17890 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17891 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17892 ASSERT_VK_SUCCESS(err);
17893 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17894 ASSERT_VK_SUCCESS(err);
17895 }
17896
17897 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17898 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17899 // Create empty cmd buffer
17900 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17901 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17902
17903 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17904 ASSERT_VK_SUCCESS(err);
17905 err = vkEndCommandBuffer(cmd_buffers[obj]);
17906 ASSERT_VK_SUCCESS(err);
17907
17908 VkSubmitInfo submit_info = {};
17909 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17910 submit_info.commandBufferCount = 1;
17911 submit_info.pCommandBuffers = &cmd_buffers[obj];
17912 // Submit cmd buffer and wait for fence
17913 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17914 ASSERT_VK_SUCCESS(err);
17915 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17916 ASSERT_VK_SUCCESS(err);
17917 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17918 ASSERT_VK_SUCCESS(err);
17919 }
17920 }
17921 m_errorMonitor->VerifyNotFound();
17922 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17923 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17924 vkDestroyFence(m_device->device(), fences[i], nullptr);
17925 }
17926}
17927// This is a positive test. No errors should be generated.
17928TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17929
17930 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17931 "submitted on separate queues followed by a QueueWaitIdle.");
17932
17933 ASSERT_NO_FATAL_FAILURE(InitState());
17934 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17935 return;
17936
17937 m_errorMonitor->ExpectSuccess();
17938
17939 VkSemaphore semaphore;
17940 VkSemaphoreCreateInfo semaphore_create_info{};
17941 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17942 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17943
17944 VkCommandPool command_pool;
17945 VkCommandPoolCreateInfo pool_create_info{};
17946 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17947 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17948 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17949 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17950
17951 VkCommandBuffer command_buffer[2];
17952 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17953 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17954 command_buffer_allocate_info.commandPool = command_pool;
17955 command_buffer_allocate_info.commandBufferCount = 2;
17956 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17957 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17958
17959 VkQueue queue = VK_NULL_HANDLE;
17960 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17961
17962 {
17963 VkCommandBufferBeginInfo begin_info{};
17964 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17965 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17966
17967 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17968 nullptr, 0, nullptr, 0, nullptr);
17969
17970 VkViewport viewport{};
17971 viewport.maxDepth = 1.0f;
17972 viewport.minDepth = 0.0f;
17973 viewport.width = 512;
17974 viewport.height = 512;
17975 viewport.x = 0;
17976 viewport.y = 0;
17977 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17978 vkEndCommandBuffer(command_buffer[0]);
17979 }
17980 {
17981 VkCommandBufferBeginInfo begin_info{};
17982 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17983 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17984
17985 VkViewport viewport{};
17986 viewport.maxDepth = 1.0f;
17987 viewport.minDepth = 0.0f;
17988 viewport.width = 512;
17989 viewport.height = 512;
17990 viewport.x = 0;
17991 viewport.y = 0;
17992 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17993 vkEndCommandBuffer(command_buffer[1]);
17994 }
17995 {
17996 VkSubmitInfo submit_info{};
17997 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17998 submit_info.commandBufferCount = 1;
17999 submit_info.pCommandBuffers = &command_buffer[0];
18000 submit_info.signalSemaphoreCount = 1;
18001 submit_info.pSignalSemaphores = &semaphore;
18002 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18003 }
18004 {
18005 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18006 VkSubmitInfo submit_info{};
18007 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18008 submit_info.commandBufferCount = 1;
18009 submit_info.pCommandBuffers = &command_buffer[1];
18010 submit_info.waitSemaphoreCount = 1;
18011 submit_info.pWaitSemaphores = &semaphore;
18012 submit_info.pWaitDstStageMask = flags;
18013 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18014 }
18015
18016 vkQueueWaitIdle(m_device->m_queue);
18017
18018 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18019 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18020 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18021
18022 m_errorMonitor->VerifyNotFound();
18023}
18024
18025// This is a positive test. No errors should be generated.
18026TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18027
18028 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18029 "submitted on separate queues, the second having a fence"
18030 "followed by a QueueWaitIdle.");
18031
18032 ASSERT_NO_FATAL_FAILURE(InitState());
18033 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18034 return;
18035
18036 m_errorMonitor->ExpectSuccess();
18037
18038 VkFence fence;
18039 VkFenceCreateInfo fence_create_info{};
18040 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18041 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18042
18043 VkSemaphore semaphore;
18044 VkSemaphoreCreateInfo semaphore_create_info{};
18045 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18046 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18047
18048 VkCommandPool command_pool;
18049 VkCommandPoolCreateInfo pool_create_info{};
18050 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18051 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18052 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18053 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18054
18055 VkCommandBuffer command_buffer[2];
18056 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18057 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18058 command_buffer_allocate_info.commandPool = command_pool;
18059 command_buffer_allocate_info.commandBufferCount = 2;
18060 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18061 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18062
18063 VkQueue queue = VK_NULL_HANDLE;
18064 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18065
18066 {
18067 VkCommandBufferBeginInfo begin_info{};
18068 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18069 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18070
18071 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18072 nullptr, 0, nullptr, 0, nullptr);
18073
18074 VkViewport viewport{};
18075 viewport.maxDepth = 1.0f;
18076 viewport.minDepth = 0.0f;
18077 viewport.width = 512;
18078 viewport.height = 512;
18079 viewport.x = 0;
18080 viewport.y = 0;
18081 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18082 vkEndCommandBuffer(command_buffer[0]);
18083 }
18084 {
18085 VkCommandBufferBeginInfo begin_info{};
18086 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18087 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18088
18089 VkViewport viewport{};
18090 viewport.maxDepth = 1.0f;
18091 viewport.minDepth = 0.0f;
18092 viewport.width = 512;
18093 viewport.height = 512;
18094 viewport.x = 0;
18095 viewport.y = 0;
18096 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18097 vkEndCommandBuffer(command_buffer[1]);
18098 }
18099 {
18100 VkSubmitInfo submit_info{};
18101 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18102 submit_info.commandBufferCount = 1;
18103 submit_info.pCommandBuffers = &command_buffer[0];
18104 submit_info.signalSemaphoreCount = 1;
18105 submit_info.pSignalSemaphores = &semaphore;
18106 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18107 }
18108 {
18109 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18110 VkSubmitInfo submit_info{};
18111 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18112 submit_info.commandBufferCount = 1;
18113 submit_info.pCommandBuffers = &command_buffer[1];
18114 submit_info.waitSemaphoreCount = 1;
18115 submit_info.pWaitSemaphores = &semaphore;
18116 submit_info.pWaitDstStageMask = flags;
18117 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18118 }
18119
18120 vkQueueWaitIdle(m_device->m_queue);
18121
18122 vkDestroyFence(m_device->device(), fence, nullptr);
18123 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18124 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18125 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18126
18127 m_errorMonitor->VerifyNotFound();
18128}
18129
18130// This is a positive test. No errors should be generated.
18131TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18132
18133 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18134 "submitted on separate queues, the second having a fence"
18135 "followed by two consecutive WaitForFences calls on the same fence.");
18136
18137 ASSERT_NO_FATAL_FAILURE(InitState());
18138 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18139 return;
18140
18141 m_errorMonitor->ExpectSuccess();
18142
18143 VkFence fence;
18144 VkFenceCreateInfo fence_create_info{};
18145 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18146 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18147
18148 VkSemaphore semaphore;
18149 VkSemaphoreCreateInfo semaphore_create_info{};
18150 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18151 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18152
18153 VkCommandPool command_pool;
18154 VkCommandPoolCreateInfo pool_create_info{};
18155 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18156 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18157 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18158 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18159
18160 VkCommandBuffer command_buffer[2];
18161 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18162 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18163 command_buffer_allocate_info.commandPool = command_pool;
18164 command_buffer_allocate_info.commandBufferCount = 2;
18165 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18166 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18167
18168 VkQueue queue = VK_NULL_HANDLE;
18169 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18170
18171 {
18172 VkCommandBufferBeginInfo begin_info{};
18173 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18174 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18175
18176 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18177 nullptr, 0, nullptr, 0, nullptr);
18178
18179 VkViewport viewport{};
18180 viewport.maxDepth = 1.0f;
18181 viewport.minDepth = 0.0f;
18182 viewport.width = 512;
18183 viewport.height = 512;
18184 viewport.x = 0;
18185 viewport.y = 0;
18186 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18187 vkEndCommandBuffer(command_buffer[0]);
18188 }
18189 {
18190 VkCommandBufferBeginInfo begin_info{};
18191 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18192 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18193
18194 VkViewport viewport{};
18195 viewport.maxDepth = 1.0f;
18196 viewport.minDepth = 0.0f;
18197 viewport.width = 512;
18198 viewport.height = 512;
18199 viewport.x = 0;
18200 viewport.y = 0;
18201 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18202 vkEndCommandBuffer(command_buffer[1]);
18203 }
18204 {
18205 VkSubmitInfo submit_info{};
18206 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18207 submit_info.commandBufferCount = 1;
18208 submit_info.pCommandBuffers = &command_buffer[0];
18209 submit_info.signalSemaphoreCount = 1;
18210 submit_info.pSignalSemaphores = &semaphore;
18211 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18212 }
18213 {
18214 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18215 VkSubmitInfo submit_info{};
18216 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18217 submit_info.commandBufferCount = 1;
18218 submit_info.pCommandBuffers = &command_buffer[1];
18219 submit_info.waitSemaphoreCount = 1;
18220 submit_info.pWaitSemaphores = &semaphore;
18221 submit_info.pWaitDstStageMask = flags;
18222 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18223 }
18224
18225 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18226 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18227
18228 vkDestroyFence(m_device->device(), fence, nullptr);
18229 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18230 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18231 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18232
18233 m_errorMonitor->VerifyNotFound();
18234}
18235
18236TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18237
18238 ASSERT_NO_FATAL_FAILURE(InitState());
18239 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18240 printf("Test requires two queues, skipping\n");
18241 return;
18242 }
18243
18244 VkResult err;
18245
18246 m_errorMonitor->ExpectSuccess();
18247
18248 VkQueue q0 = m_device->m_queue;
18249 VkQueue q1 = nullptr;
18250 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18251 ASSERT_NE(q1, nullptr);
18252
18253 // An (empty) command buffer. We must have work in the first submission --
18254 // the layer treats unfenced work differently from fenced work.
18255 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18256 VkCommandPool pool;
18257 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18258 ASSERT_VK_SUCCESS(err);
18259 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18260 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18261 VkCommandBuffer cb;
18262 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18263 ASSERT_VK_SUCCESS(err);
18264 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18265 err = vkBeginCommandBuffer(cb, &cbbi);
18266 ASSERT_VK_SUCCESS(err);
18267 err = vkEndCommandBuffer(cb);
18268 ASSERT_VK_SUCCESS(err);
18269
18270 // A semaphore
18271 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18272 VkSemaphore s;
18273 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18274 ASSERT_VK_SUCCESS(err);
18275
18276 // First submission, to q0
18277 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18278
18279 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18280 ASSERT_VK_SUCCESS(err);
18281
18282 // Second submission, to q1, waiting on s
18283 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18284 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18285
18286 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18287 ASSERT_VK_SUCCESS(err);
18288
18289 // Wait for q0 idle
18290 err = vkQueueWaitIdle(q0);
18291 ASSERT_VK_SUCCESS(err);
18292
18293 // Command buffer should have been completed (it was on q0); reset the pool.
18294 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18295
18296 m_errorMonitor->VerifyNotFound();
18297
18298 // Force device completely idle and clean up resources
18299 vkDeviceWaitIdle(m_device->device());
18300 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18301 vkDestroySemaphore(m_device->device(), s, nullptr);
18302}
18303
18304// This is a positive test. No errors should be generated.
18305TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18306
18307 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18308 "submitted on separate queues, the second having a fence, "
18309 "followed by a WaitForFences call.");
18310
18311 ASSERT_NO_FATAL_FAILURE(InitState());
18312 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18313 return;
18314
18315 m_errorMonitor->ExpectSuccess();
18316
18317 ASSERT_NO_FATAL_FAILURE(InitState());
18318 VkFence fence;
18319 VkFenceCreateInfo fence_create_info{};
18320 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18321 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18322
18323 VkSemaphore semaphore;
18324 VkSemaphoreCreateInfo semaphore_create_info{};
18325 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18326 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18327
18328 VkCommandPool command_pool;
18329 VkCommandPoolCreateInfo pool_create_info{};
18330 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18331 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18332 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18333 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18334
18335 VkCommandBuffer command_buffer[2];
18336 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18337 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18338 command_buffer_allocate_info.commandPool = command_pool;
18339 command_buffer_allocate_info.commandBufferCount = 2;
18340 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18341 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18342
18343 VkQueue queue = VK_NULL_HANDLE;
18344 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18345
18346 {
18347 VkCommandBufferBeginInfo begin_info{};
18348 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18349 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18350
18351 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18352 nullptr, 0, nullptr, 0, nullptr);
18353
18354 VkViewport viewport{};
18355 viewport.maxDepth = 1.0f;
18356 viewport.minDepth = 0.0f;
18357 viewport.width = 512;
18358 viewport.height = 512;
18359 viewport.x = 0;
18360 viewport.y = 0;
18361 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18362 vkEndCommandBuffer(command_buffer[0]);
18363 }
18364 {
18365 VkCommandBufferBeginInfo begin_info{};
18366 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18367 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18368
18369 VkViewport viewport{};
18370 viewport.maxDepth = 1.0f;
18371 viewport.minDepth = 0.0f;
18372 viewport.width = 512;
18373 viewport.height = 512;
18374 viewport.x = 0;
18375 viewport.y = 0;
18376 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18377 vkEndCommandBuffer(command_buffer[1]);
18378 }
18379 {
18380 VkSubmitInfo submit_info{};
18381 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18382 submit_info.commandBufferCount = 1;
18383 submit_info.pCommandBuffers = &command_buffer[0];
18384 submit_info.signalSemaphoreCount = 1;
18385 submit_info.pSignalSemaphores = &semaphore;
18386 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18387 }
18388 {
18389 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18390 VkSubmitInfo submit_info{};
18391 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18392 submit_info.commandBufferCount = 1;
18393 submit_info.pCommandBuffers = &command_buffer[1];
18394 submit_info.waitSemaphoreCount = 1;
18395 submit_info.pWaitSemaphores = &semaphore;
18396 submit_info.pWaitDstStageMask = flags;
18397 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18398 }
18399
18400 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18401
18402 vkDestroyFence(m_device->device(), fence, nullptr);
18403 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18404 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18405 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18406
18407 m_errorMonitor->VerifyNotFound();
18408}
18409
18410// This is a positive test. No errors should be generated.
18411TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18412
18413 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18414 "on the same queue, sharing a signal/wait semaphore, the "
18415 "second having a fence, "
18416 "followed by a WaitForFences call.");
18417
18418 m_errorMonitor->ExpectSuccess();
18419
18420 ASSERT_NO_FATAL_FAILURE(InitState());
18421 VkFence fence;
18422 VkFenceCreateInfo fence_create_info{};
18423 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18424 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18425
18426 VkSemaphore semaphore;
18427 VkSemaphoreCreateInfo semaphore_create_info{};
18428 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18429 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18430
18431 VkCommandPool command_pool;
18432 VkCommandPoolCreateInfo pool_create_info{};
18433 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18434 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18435 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18436 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18437
18438 VkCommandBuffer command_buffer[2];
18439 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18440 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18441 command_buffer_allocate_info.commandPool = command_pool;
18442 command_buffer_allocate_info.commandBufferCount = 2;
18443 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18444 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18445
18446 {
18447 VkCommandBufferBeginInfo begin_info{};
18448 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18449 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18450
18451 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18452 nullptr, 0, nullptr, 0, nullptr);
18453
18454 VkViewport viewport{};
18455 viewport.maxDepth = 1.0f;
18456 viewport.minDepth = 0.0f;
18457 viewport.width = 512;
18458 viewport.height = 512;
18459 viewport.x = 0;
18460 viewport.y = 0;
18461 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18462 vkEndCommandBuffer(command_buffer[0]);
18463 }
18464 {
18465 VkCommandBufferBeginInfo begin_info{};
18466 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18467 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18468
18469 VkViewport viewport{};
18470 viewport.maxDepth = 1.0f;
18471 viewport.minDepth = 0.0f;
18472 viewport.width = 512;
18473 viewport.height = 512;
18474 viewport.x = 0;
18475 viewport.y = 0;
18476 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18477 vkEndCommandBuffer(command_buffer[1]);
18478 }
18479 {
18480 VkSubmitInfo submit_info{};
18481 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18482 submit_info.commandBufferCount = 1;
18483 submit_info.pCommandBuffers = &command_buffer[0];
18484 submit_info.signalSemaphoreCount = 1;
18485 submit_info.pSignalSemaphores = &semaphore;
18486 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18487 }
18488 {
18489 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18490 VkSubmitInfo submit_info{};
18491 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18492 submit_info.commandBufferCount = 1;
18493 submit_info.pCommandBuffers = &command_buffer[1];
18494 submit_info.waitSemaphoreCount = 1;
18495 submit_info.pWaitSemaphores = &semaphore;
18496 submit_info.pWaitDstStageMask = flags;
18497 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18498 }
18499
18500 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18501
18502 vkDestroyFence(m_device->device(), fence, nullptr);
18503 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18504 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18505 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18506
18507 m_errorMonitor->VerifyNotFound();
18508}
18509
18510// This is a positive test. No errors should be generated.
18511TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18512
18513 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18514 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18515 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18516
18517 m_errorMonitor->ExpectSuccess();
18518
18519 ASSERT_NO_FATAL_FAILURE(InitState());
18520 VkFence fence;
18521 VkFenceCreateInfo fence_create_info{};
18522 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18523 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18524
18525 VkCommandPool command_pool;
18526 VkCommandPoolCreateInfo pool_create_info{};
18527 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18528 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18529 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18530 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18531
18532 VkCommandBuffer command_buffer[2];
18533 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18534 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18535 command_buffer_allocate_info.commandPool = command_pool;
18536 command_buffer_allocate_info.commandBufferCount = 2;
18537 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18538 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18539
18540 {
18541 VkCommandBufferBeginInfo begin_info{};
18542 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18543 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18544
18545 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18546 nullptr, 0, nullptr, 0, nullptr);
18547
18548 VkViewport viewport{};
18549 viewport.maxDepth = 1.0f;
18550 viewport.minDepth = 0.0f;
18551 viewport.width = 512;
18552 viewport.height = 512;
18553 viewport.x = 0;
18554 viewport.y = 0;
18555 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18556 vkEndCommandBuffer(command_buffer[0]);
18557 }
18558 {
18559 VkCommandBufferBeginInfo begin_info{};
18560 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18561 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18562
18563 VkViewport viewport{};
18564 viewport.maxDepth = 1.0f;
18565 viewport.minDepth = 0.0f;
18566 viewport.width = 512;
18567 viewport.height = 512;
18568 viewport.x = 0;
18569 viewport.y = 0;
18570 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18571 vkEndCommandBuffer(command_buffer[1]);
18572 }
18573 {
18574 VkSubmitInfo submit_info{};
18575 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18576 submit_info.commandBufferCount = 1;
18577 submit_info.pCommandBuffers = &command_buffer[0];
18578 submit_info.signalSemaphoreCount = 0;
18579 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18580 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18581 }
18582 {
18583 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18584 VkSubmitInfo submit_info{};
18585 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18586 submit_info.commandBufferCount = 1;
18587 submit_info.pCommandBuffers = &command_buffer[1];
18588 submit_info.waitSemaphoreCount = 0;
18589 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18590 submit_info.pWaitDstStageMask = flags;
18591 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18592 }
18593
18594 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18595
18596 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18597 ASSERT_VK_SUCCESS(err);
18598
18599 vkDestroyFence(m_device->device(), fence, nullptr);
18600 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18601 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18602
18603 m_errorMonitor->VerifyNotFound();
18604}
18605
18606// This is a positive test. No errors should be generated.
18607TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18608
18609 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18610 "on the same queue, the second having a fence, followed "
18611 "by a WaitForFences call.");
18612
18613 m_errorMonitor->ExpectSuccess();
18614
18615 ASSERT_NO_FATAL_FAILURE(InitState());
18616 VkFence fence;
18617 VkFenceCreateInfo fence_create_info{};
18618 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18619 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18620
18621 VkCommandPool command_pool;
18622 VkCommandPoolCreateInfo pool_create_info{};
18623 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18624 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18625 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18626 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18627
18628 VkCommandBuffer command_buffer[2];
18629 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18630 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18631 command_buffer_allocate_info.commandPool = command_pool;
18632 command_buffer_allocate_info.commandBufferCount = 2;
18633 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18634 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18635
18636 {
18637 VkCommandBufferBeginInfo begin_info{};
18638 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18639 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18640
18641 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18642 nullptr, 0, nullptr, 0, nullptr);
18643
18644 VkViewport viewport{};
18645 viewport.maxDepth = 1.0f;
18646 viewport.minDepth = 0.0f;
18647 viewport.width = 512;
18648 viewport.height = 512;
18649 viewport.x = 0;
18650 viewport.y = 0;
18651 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18652 vkEndCommandBuffer(command_buffer[0]);
18653 }
18654 {
18655 VkCommandBufferBeginInfo begin_info{};
18656 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18657 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18658
18659 VkViewport viewport{};
18660 viewport.maxDepth = 1.0f;
18661 viewport.minDepth = 0.0f;
18662 viewport.width = 512;
18663 viewport.height = 512;
18664 viewport.x = 0;
18665 viewport.y = 0;
18666 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18667 vkEndCommandBuffer(command_buffer[1]);
18668 }
18669 {
18670 VkSubmitInfo submit_info{};
18671 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18672 submit_info.commandBufferCount = 1;
18673 submit_info.pCommandBuffers = &command_buffer[0];
18674 submit_info.signalSemaphoreCount = 0;
18675 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18676 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18677 }
18678 {
18679 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18680 VkSubmitInfo submit_info{};
18681 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18682 submit_info.commandBufferCount = 1;
18683 submit_info.pCommandBuffers = &command_buffer[1];
18684 submit_info.waitSemaphoreCount = 0;
18685 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18686 submit_info.pWaitDstStageMask = flags;
18687 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18688 }
18689
18690 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18691
18692 vkDestroyFence(m_device->device(), fence, nullptr);
18693 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18694 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18695
18696 m_errorMonitor->VerifyNotFound();
18697}
18698
18699// This is a positive test. No errors should be generated.
18700TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18701
18702 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18703 "QueueSubmit call followed by a WaitForFences call.");
18704 ASSERT_NO_FATAL_FAILURE(InitState());
18705
18706 m_errorMonitor->ExpectSuccess();
18707
18708 VkFence fence;
18709 VkFenceCreateInfo fence_create_info{};
18710 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18711 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18712
18713 VkSemaphore semaphore;
18714 VkSemaphoreCreateInfo semaphore_create_info{};
18715 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18716 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18717
18718 VkCommandPool command_pool;
18719 VkCommandPoolCreateInfo pool_create_info{};
18720 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18721 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18722 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18723 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18724
18725 VkCommandBuffer command_buffer[2];
18726 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18727 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18728 command_buffer_allocate_info.commandPool = command_pool;
18729 command_buffer_allocate_info.commandBufferCount = 2;
18730 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18731 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18732
18733 {
18734 VkCommandBufferBeginInfo begin_info{};
18735 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18736 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18737
18738 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18739 nullptr, 0, nullptr, 0, nullptr);
18740
18741 VkViewport viewport{};
18742 viewport.maxDepth = 1.0f;
18743 viewport.minDepth = 0.0f;
18744 viewport.width = 512;
18745 viewport.height = 512;
18746 viewport.x = 0;
18747 viewport.y = 0;
18748 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18749 vkEndCommandBuffer(command_buffer[0]);
18750 }
18751 {
18752 VkCommandBufferBeginInfo begin_info{};
18753 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18754 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18755
18756 VkViewport viewport{};
18757 viewport.maxDepth = 1.0f;
18758 viewport.minDepth = 0.0f;
18759 viewport.width = 512;
18760 viewport.height = 512;
18761 viewport.x = 0;
18762 viewport.y = 0;
18763 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18764 vkEndCommandBuffer(command_buffer[1]);
18765 }
18766 {
18767 VkSubmitInfo submit_info[2];
18768 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18769
18770 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18771 submit_info[0].pNext = NULL;
18772 submit_info[0].commandBufferCount = 1;
18773 submit_info[0].pCommandBuffers = &command_buffer[0];
18774 submit_info[0].signalSemaphoreCount = 1;
18775 submit_info[0].pSignalSemaphores = &semaphore;
18776 submit_info[0].waitSemaphoreCount = 0;
18777 submit_info[0].pWaitSemaphores = NULL;
18778 submit_info[0].pWaitDstStageMask = 0;
18779
18780 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18781 submit_info[1].pNext = NULL;
18782 submit_info[1].commandBufferCount = 1;
18783 submit_info[1].pCommandBuffers = &command_buffer[1];
18784 submit_info[1].waitSemaphoreCount = 1;
18785 submit_info[1].pWaitSemaphores = &semaphore;
18786 submit_info[1].pWaitDstStageMask = flags;
18787 submit_info[1].signalSemaphoreCount = 0;
18788 submit_info[1].pSignalSemaphores = NULL;
18789 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18790 }
18791
18792 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18793
18794 vkDestroyFence(m_device->device(), fence, nullptr);
18795 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18796 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18797 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18798
18799 m_errorMonitor->VerifyNotFound();
18800}
18801
18802TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18803 m_errorMonitor->ExpectSuccess();
18804
18805 ASSERT_NO_FATAL_FAILURE(InitState());
18806 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18807
18808 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18809 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18810
18811 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18812 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18813 m_errorMonitor->VerifyNotFound();
18814 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18815 m_errorMonitor->VerifyNotFound();
18816 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18817 m_errorMonitor->VerifyNotFound();
18818
18819 m_commandBuffer->EndCommandBuffer();
18820 m_errorMonitor->VerifyNotFound();
18821}
18822
18823TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18824 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18825 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18826 "has a valid layout, and a second subpass then uses a "
18827 "valid *READ_ONLY* layout.");
18828 m_errorMonitor->ExpectSuccess();
18829 ASSERT_NO_FATAL_FAILURE(InitState());
18830
18831 VkAttachmentReference attach[2] = {};
18832 attach[0].attachment = 0;
18833 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18834 attach[1].attachment = 0;
18835 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18836 VkSubpassDescription subpasses[2] = {};
18837 // First subpass clears DS attach on load
18838 subpasses[0].pDepthStencilAttachment = &attach[0];
18839 // 2nd subpass reads in DS as input attachment
18840 subpasses[1].inputAttachmentCount = 1;
18841 subpasses[1].pInputAttachments = &attach[1];
18842 VkAttachmentDescription attach_desc = {};
18843 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18844 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18845 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18846 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18847 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18848 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18849 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18850 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18851 VkRenderPassCreateInfo rpci = {};
18852 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18853 rpci.attachmentCount = 1;
18854 rpci.pAttachments = &attach_desc;
18855 rpci.subpassCount = 2;
18856 rpci.pSubpasses = subpasses;
18857
18858 // Now create RenderPass and verify no errors
18859 VkRenderPass rp;
18860 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18861 m_errorMonitor->VerifyNotFound();
18862
18863 vkDestroyRenderPass(m_device->device(), rp, NULL);
18864}
18865
18866TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18867 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18868 "as vertex attributes");
18869 m_errorMonitor->ExpectSuccess();
18870
18871 ASSERT_NO_FATAL_FAILURE(InitState());
18872 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18873
18874 VkVertexInputBindingDescription input_binding;
18875 memset(&input_binding, 0, sizeof(input_binding));
18876
18877 VkVertexInputAttributeDescription input_attribs[2];
18878 memset(input_attribs, 0, sizeof(input_attribs));
18879
18880 for (int i = 0; i < 2; i++) {
18881 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18882 input_attribs[i].location = i;
18883 }
18884
18885 char const *vsSource = "#version 450\n"
18886 "\n"
18887 "layout(location=0) in mat2x4 x;\n"
18888 "out gl_PerVertex {\n"
18889 " vec4 gl_Position;\n"
18890 "};\n"
18891 "void main(){\n"
18892 " gl_Position = x[0] + x[1];\n"
18893 "}\n";
18894 char const *fsSource = "#version 450\n"
18895 "\n"
18896 "layout(location=0) out vec4 color;\n"
18897 "void main(){\n"
18898 " color = vec4(1);\n"
18899 "}\n";
18900
18901 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18902 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18903
18904 VkPipelineObj pipe(m_device);
18905 pipe.AddColorAttachment();
18906 pipe.AddShader(&vs);
18907 pipe.AddShader(&fs);
18908
18909 pipe.AddVertexInputBindings(&input_binding, 1);
18910 pipe.AddVertexInputAttribs(input_attribs, 2);
18911
18912 VkDescriptorSetObj descriptorSet(m_device);
18913 descriptorSet.AppendDummy();
18914 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18915
18916 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18917
18918 /* expect success */
18919 m_errorMonitor->VerifyNotFound();
18920}
18921
18922TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18923 m_errorMonitor->ExpectSuccess();
18924
18925 ASSERT_NO_FATAL_FAILURE(InitState());
18926 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18927
18928 VkVertexInputBindingDescription input_binding;
18929 memset(&input_binding, 0, sizeof(input_binding));
18930
18931 VkVertexInputAttributeDescription input_attribs[2];
18932 memset(input_attribs, 0, sizeof(input_attribs));
18933
18934 for (int i = 0; i < 2; i++) {
18935 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18936 input_attribs[i].location = i;
18937 }
18938
18939 char const *vsSource = "#version 450\n"
18940 "\n"
18941 "layout(location=0) in vec4 x[2];\n"
18942 "out gl_PerVertex {\n"
18943 " vec4 gl_Position;\n"
18944 "};\n"
18945 "void main(){\n"
18946 " gl_Position = x[0] + x[1];\n"
18947 "}\n";
18948 char const *fsSource = "#version 450\n"
18949 "\n"
18950 "layout(location=0) out vec4 color;\n"
18951 "void main(){\n"
18952 " color = vec4(1);\n"
18953 "}\n";
18954
18955 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18956 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18957
18958 VkPipelineObj pipe(m_device);
18959 pipe.AddColorAttachment();
18960 pipe.AddShader(&vs);
18961 pipe.AddShader(&fs);
18962
18963 pipe.AddVertexInputBindings(&input_binding, 1);
18964 pipe.AddVertexInputAttribs(input_attribs, 2);
18965
18966 VkDescriptorSetObj descriptorSet(m_device);
18967 descriptorSet.AppendDummy();
18968 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18969
18970 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18971
18972 m_errorMonitor->VerifyNotFound();
18973}
18974
18975TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18976 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18977 "through multiple vertex shader inputs, each consuming a different "
18978 "subset of the components.");
18979 m_errorMonitor->ExpectSuccess();
18980
18981 ASSERT_NO_FATAL_FAILURE(InitState());
18982 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18983
18984 VkVertexInputBindingDescription input_binding;
18985 memset(&input_binding, 0, sizeof(input_binding));
18986
18987 VkVertexInputAttributeDescription input_attribs[3];
18988 memset(input_attribs, 0, sizeof(input_attribs));
18989
18990 for (int i = 0; i < 3; i++) {
18991 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18992 input_attribs[i].location = i;
18993 }
18994
18995 char const *vsSource = "#version 450\n"
18996 "\n"
18997 "layout(location=0) in vec4 x;\n"
18998 "layout(location=1) in vec3 y1;\n"
18999 "layout(location=1, component=3) in float y2;\n"
19000 "layout(location=2) in vec4 z;\n"
19001 "out gl_PerVertex {\n"
19002 " vec4 gl_Position;\n"
19003 "};\n"
19004 "void main(){\n"
19005 " gl_Position = x + vec4(y1, y2) + z;\n"
19006 "}\n";
19007 char const *fsSource = "#version 450\n"
19008 "\n"
19009 "layout(location=0) out vec4 color;\n"
19010 "void main(){\n"
19011 " color = vec4(1);\n"
19012 "}\n";
19013
19014 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19015 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19016
19017 VkPipelineObj pipe(m_device);
19018 pipe.AddColorAttachment();
19019 pipe.AddShader(&vs);
19020 pipe.AddShader(&fs);
19021
19022 pipe.AddVertexInputBindings(&input_binding, 1);
19023 pipe.AddVertexInputAttribs(input_attribs, 3);
19024
19025 VkDescriptorSetObj descriptorSet(m_device);
19026 descriptorSet.AppendDummy();
19027 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19028
19029 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19030
19031 m_errorMonitor->VerifyNotFound();
19032}
19033
19034TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19035 m_errorMonitor->ExpectSuccess();
19036
19037 ASSERT_NO_FATAL_FAILURE(InitState());
19038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19039
19040 char const *vsSource = "#version 450\n"
19041 "out gl_PerVertex {\n"
19042 " vec4 gl_Position;\n"
19043 "};\n"
19044 "void main(){\n"
19045 " gl_Position = vec4(0);\n"
19046 "}\n";
19047 char const *fsSource = "#version 450\n"
19048 "\n"
19049 "layout(location=0) out vec4 color;\n"
19050 "void main(){\n"
19051 " color = vec4(1);\n"
19052 "}\n";
19053
19054 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19055 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19056
19057 VkPipelineObj pipe(m_device);
19058 pipe.AddColorAttachment();
19059 pipe.AddShader(&vs);
19060 pipe.AddShader(&fs);
19061
19062 VkDescriptorSetObj descriptorSet(m_device);
19063 descriptorSet.AppendDummy();
19064 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19065
19066 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19067
19068 m_errorMonitor->VerifyNotFound();
19069}
19070
19071TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19072 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19073 "set out in 14.1.3: fundamental type must match, and producer side must "
19074 "have at least as many components");
19075 m_errorMonitor->ExpectSuccess();
19076
19077 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19078
19079 ASSERT_NO_FATAL_FAILURE(InitState());
19080 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19081
19082 char const *vsSource = "#version 450\n"
19083 "out gl_PerVertex {\n"
19084 " vec4 gl_Position;\n"
19085 "};\n"
19086 "layout(location=0) out vec3 x;\n"
19087 "layout(location=1) out ivec3 y;\n"
19088 "layout(location=2) out vec3 z;\n"
19089 "void main(){\n"
19090 " gl_Position = vec4(0);\n"
19091 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19092 "}\n";
19093 char const *fsSource = "#version 450\n"
19094 "\n"
19095 "layout(location=0) out vec4 color;\n"
19096 "layout(location=0) in float x;\n"
19097 "layout(location=1) flat in int y;\n"
19098 "layout(location=2) in vec2 z;\n"
19099 "void main(){\n"
19100 " color = vec4(1 + x + y + z.x);\n"
19101 "}\n";
19102
19103 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19104 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19105
19106 VkPipelineObj pipe(m_device);
19107 pipe.AddColorAttachment();
19108 pipe.AddShader(&vs);
19109 pipe.AddShader(&fs);
19110
19111 VkDescriptorSetObj descriptorSet(m_device);
19112 descriptorSet.AppendDummy();
19113 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19114
19115 VkResult err = VK_SUCCESS;
19116 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19117 ASSERT_VK_SUCCESS(err);
19118
19119 m_errorMonitor->VerifyNotFound();
19120}
19121
19122TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19123 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19124 "passed between the TCS and TES stages");
19125 m_errorMonitor->ExpectSuccess();
19126
19127 ASSERT_NO_FATAL_FAILURE(InitState());
19128 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19129
19130 if (!m_device->phy().features().tessellationShader) {
19131 printf("Device does not support tessellation shaders; skipped.\n");
19132 return;
19133 }
19134
19135 char const *vsSource = "#version 450\n"
19136 "void main(){}\n";
19137 char const *tcsSource = "#version 450\n"
19138 "layout(location=0) out int x[];\n"
19139 "layout(vertices=3) out;\n"
19140 "void main(){\n"
19141 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19142 " gl_TessLevelInner[0] = 1;\n"
19143 " x[gl_InvocationID] = gl_InvocationID;\n"
19144 "}\n";
19145 char const *tesSource = "#version 450\n"
19146 "layout(triangles, equal_spacing, cw) in;\n"
19147 "layout(location=0) in int x[];\n"
19148 "out gl_PerVertex { vec4 gl_Position; };\n"
19149 "void main(){\n"
19150 " gl_Position.xyz = gl_TessCoord;\n"
19151 " gl_Position.w = x[0] + x[1] + x[2];\n"
19152 "}\n";
19153 char const *fsSource = "#version 450\n"
19154 "layout(location=0) out vec4 color;\n"
19155 "void main(){\n"
19156 " color = vec4(1);\n"
19157 "}\n";
19158
19159 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19160 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19161 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19162 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19163
19164 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19165 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19166
19167 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19168
19169 VkPipelineObj pipe(m_device);
19170 pipe.SetInputAssembly(&iasci);
19171 pipe.SetTessellation(&tsci);
19172 pipe.AddColorAttachment();
19173 pipe.AddShader(&vs);
19174 pipe.AddShader(&tcs);
19175 pipe.AddShader(&tes);
19176 pipe.AddShader(&fs);
19177
19178 VkDescriptorSetObj descriptorSet(m_device);
19179 descriptorSet.AppendDummy();
19180 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19181
19182 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19183
19184 m_errorMonitor->VerifyNotFound();
19185}
19186
19187TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19188 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19189 "interface block passed into the geometry shader. This "
19190 "is interesting because the 'extra' array level is not "
19191 "present on the member type, but on the block instance.");
19192 m_errorMonitor->ExpectSuccess();
19193
19194 ASSERT_NO_FATAL_FAILURE(InitState());
19195 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19196
19197 if (!m_device->phy().features().geometryShader) {
19198 printf("Device does not support geometry shaders; skipped.\n");
19199 return;
19200 }
19201
19202 char const *vsSource = "#version 450\n"
19203 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19204 "void main(){\n"
19205 " vs_out.x = vec4(1);\n"
19206 "}\n";
19207 char const *gsSource = "#version 450\n"
19208 "layout(triangles) in;\n"
19209 "layout(triangle_strip, max_vertices=3) out;\n"
19210 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19211 "out gl_PerVertex { vec4 gl_Position; };\n"
19212 "void main() {\n"
19213 " gl_Position = gs_in[0].x;\n"
19214 " EmitVertex();\n"
19215 "}\n";
19216 char const *fsSource = "#version 450\n"
19217 "layout(location=0) out vec4 color;\n"
19218 "void main(){\n"
19219 " color = vec4(1);\n"
19220 "}\n";
19221
19222 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19223 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19224 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19225
19226 VkPipelineObj pipe(m_device);
19227 pipe.AddColorAttachment();
19228 pipe.AddShader(&vs);
19229 pipe.AddShader(&gs);
19230 pipe.AddShader(&fs);
19231
19232 VkDescriptorSetObj descriptorSet(m_device);
19233 descriptorSet.AppendDummy();
19234 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19235
19236 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19237
19238 m_errorMonitor->VerifyNotFound();
19239}
19240
19241TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19242 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19243 "attributes. This is interesting because they consume multiple "
19244 "locations.");
19245 m_errorMonitor->ExpectSuccess();
19246
19247 ASSERT_NO_FATAL_FAILURE(InitState());
19248 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19249
19250 if (!m_device->phy().features().shaderFloat64) {
19251 printf("Device does not support 64bit vertex attributes; skipped.\n");
19252 return;
19253 }
19254
19255 VkVertexInputBindingDescription input_bindings[1];
19256 memset(input_bindings, 0, sizeof(input_bindings));
19257
19258 VkVertexInputAttributeDescription input_attribs[4];
19259 memset(input_attribs, 0, sizeof(input_attribs));
19260 input_attribs[0].location = 0;
19261 input_attribs[0].offset = 0;
19262 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19263 input_attribs[1].location = 2;
19264 input_attribs[1].offset = 32;
19265 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19266 input_attribs[2].location = 4;
19267 input_attribs[2].offset = 64;
19268 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19269 input_attribs[3].location = 6;
19270 input_attribs[3].offset = 96;
19271 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19272
19273 char const *vsSource = "#version 450\n"
19274 "\n"
19275 "layout(location=0) in dmat4 x;\n"
19276 "out gl_PerVertex {\n"
19277 " vec4 gl_Position;\n"
19278 "};\n"
19279 "void main(){\n"
19280 " gl_Position = vec4(x[0][0]);\n"
19281 "}\n";
19282 char const *fsSource = "#version 450\n"
19283 "\n"
19284 "layout(location=0) out vec4 color;\n"
19285 "void main(){\n"
19286 " color = vec4(1);\n"
19287 "}\n";
19288
19289 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19290 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19291
19292 VkPipelineObj pipe(m_device);
19293 pipe.AddColorAttachment();
19294 pipe.AddShader(&vs);
19295 pipe.AddShader(&fs);
19296
19297 pipe.AddVertexInputBindings(input_bindings, 1);
19298 pipe.AddVertexInputAttribs(input_attribs, 4);
19299
19300 VkDescriptorSetObj descriptorSet(m_device);
19301 descriptorSet.AppendDummy();
19302 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19303
19304 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19305
19306 m_errorMonitor->VerifyNotFound();
19307}
19308
19309TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19310 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19311 m_errorMonitor->ExpectSuccess();
19312
19313 ASSERT_NO_FATAL_FAILURE(InitState());
19314
19315 char const *vsSource = "#version 450\n"
19316 "\n"
19317 "out gl_PerVertex {\n"
19318 " vec4 gl_Position;\n"
19319 "};\n"
19320 "void main(){\n"
19321 " gl_Position = vec4(1);\n"
19322 "}\n";
19323 char const *fsSource = "#version 450\n"
19324 "\n"
19325 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19326 "layout(location=0) out vec4 color;\n"
19327 "void main() {\n"
19328 " color = subpassLoad(x);\n"
19329 "}\n";
19330
19331 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19332 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19333
19334 VkPipelineObj pipe(m_device);
19335 pipe.AddShader(&vs);
19336 pipe.AddShader(&fs);
19337 pipe.AddColorAttachment();
19338 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19339
19340 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19341 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19342 VkDescriptorSetLayout dsl;
19343 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19344 ASSERT_VK_SUCCESS(err);
19345
19346 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19347 VkPipelineLayout pl;
19348 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19349 ASSERT_VK_SUCCESS(err);
19350
19351 VkAttachmentDescription descs[2] = {
19352 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19353 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19354 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19355 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19356 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19357 };
19358 VkAttachmentReference color = {
19359 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19360 };
19361 VkAttachmentReference input = {
19362 1, VK_IMAGE_LAYOUT_GENERAL,
19363 };
19364
19365 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19366
19367 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19368 VkRenderPass rp;
19369 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19370 ASSERT_VK_SUCCESS(err);
19371
19372 // should be OK. would go wrong here if it's going to...
19373 pipe.CreateVKPipeline(pl, rp);
19374
19375 m_errorMonitor->VerifyNotFound();
19376
19377 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19378 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19379 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19380}
19381
19382TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19383 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19384 "descriptor-backed resource which is not provided, but the shader does not "
19385 "statically use it. This is interesting because it requires compute pipelines "
19386 "to have a proper descriptor use walk, which they didn't for some time.");
19387 m_errorMonitor->ExpectSuccess();
19388
19389 ASSERT_NO_FATAL_FAILURE(InitState());
19390
19391 char const *csSource = "#version 450\n"
19392 "\n"
19393 "layout(local_size_x=1) in;\n"
19394 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19395 "void main(){\n"
19396 " // x is not used.\n"
19397 "}\n";
19398
19399 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19400
19401 VkDescriptorSetObj descriptorSet(m_device);
19402 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19403
19404 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19405 nullptr,
19406 0,
19407 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19408 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19409 descriptorSet.GetPipelineLayout(),
19410 VK_NULL_HANDLE,
19411 -1 };
19412
19413 VkPipeline pipe;
19414 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19415
19416 m_errorMonitor->VerifyNotFound();
19417
19418 if (err == VK_SUCCESS) {
19419 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19420 }
19421}
19422
19423TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19424 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19425 "sampler portion of a combined image + sampler");
19426 m_errorMonitor->ExpectSuccess();
19427
19428 ASSERT_NO_FATAL_FAILURE(InitState());
19429
19430 VkDescriptorSetLayoutBinding bindings[] = {
19431 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19432 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19433 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19434 };
19435 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19436 VkDescriptorSetLayout dsl;
19437 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19438 ASSERT_VK_SUCCESS(err);
19439
19440 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19441 VkPipelineLayout pl;
19442 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19443 ASSERT_VK_SUCCESS(err);
19444
19445 char const *csSource = "#version 450\n"
19446 "\n"
19447 "layout(local_size_x=1) in;\n"
19448 "layout(set=0, binding=0) uniform sampler s;\n"
19449 "layout(set=0, binding=1) uniform texture2D t;\n"
19450 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19451 "void main() {\n"
19452 " x = texture(sampler2D(t, s), vec2(0));\n"
19453 "}\n";
19454 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19455
19456 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19457 nullptr,
19458 0,
19459 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19460 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19461 pl,
19462 VK_NULL_HANDLE,
19463 -1 };
19464
19465 VkPipeline pipe;
19466 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19467
19468 m_errorMonitor->VerifyNotFound();
19469
19470 if (err == VK_SUCCESS) {
19471 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19472 }
19473
19474 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19475 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19476}
19477
19478TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19479 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19480 "image portion of a combined image + sampler");
19481 m_errorMonitor->ExpectSuccess();
19482
19483 ASSERT_NO_FATAL_FAILURE(InitState());
19484
19485 VkDescriptorSetLayoutBinding bindings[] = {
19486 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19487 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19488 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19489 };
19490 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19491 VkDescriptorSetLayout dsl;
19492 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19493 ASSERT_VK_SUCCESS(err);
19494
19495 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19496 VkPipelineLayout pl;
19497 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19498 ASSERT_VK_SUCCESS(err);
19499
19500 char const *csSource = "#version 450\n"
19501 "\n"
19502 "layout(local_size_x=1) in;\n"
19503 "layout(set=0, binding=0) uniform texture2D t;\n"
19504 "layout(set=0, binding=1) uniform sampler s;\n"
19505 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19506 "void main() {\n"
19507 " x = texture(sampler2D(t, s), vec2(0));\n"
19508 "}\n";
19509 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19510
19511 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19512 nullptr,
19513 0,
19514 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19515 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19516 pl,
19517 VK_NULL_HANDLE,
19518 -1 };
19519
19520 VkPipeline pipe;
19521 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19522
19523 m_errorMonitor->VerifyNotFound();
19524
19525 if (err == VK_SUCCESS) {
19526 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19527 }
19528
19529 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19530 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19531}
19532
19533TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19534 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19535 "both the sampler and the image of a combined image+sampler "
19536 "but via separate variables");
19537 m_errorMonitor->ExpectSuccess();
19538
19539 ASSERT_NO_FATAL_FAILURE(InitState());
19540
19541 VkDescriptorSetLayoutBinding bindings[] = {
19542 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19543 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19544 };
19545 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19546 VkDescriptorSetLayout dsl;
19547 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19548 ASSERT_VK_SUCCESS(err);
19549
19550 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19551 VkPipelineLayout pl;
19552 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19553 ASSERT_VK_SUCCESS(err);
19554
19555 char const *csSource = "#version 450\n"
19556 "\n"
19557 "layout(local_size_x=1) in;\n"
19558 "layout(set=0, binding=0) uniform texture2D t;\n"
19559 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19560 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19561 "void main() {\n"
19562 " x = texture(sampler2D(t, s), vec2(0));\n"
19563 "}\n";
19564 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19565
19566 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19567 nullptr,
19568 0,
19569 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19570 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19571 pl,
19572 VK_NULL_HANDLE,
19573 -1 };
19574
19575 VkPipeline pipe;
19576 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19577
19578 m_errorMonitor->VerifyNotFound();
19579
19580 if (err == VK_SUCCESS) {
19581 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19582 }
19583
19584 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19585 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19586}
19587
19588TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19589 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19590
19591 ASSERT_NO_FATAL_FAILURE(InitState());
19592
19593 // Positive test to check parameter_validation and unique_objects support
19594 // for NV_dedicated_allocation
19595 uint32_t extension_count = 0;
19596 bool supports_nv_dedicated_allocation = false;
19597 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19598 ASSERT_VK_SUCCESS(err);
19599
19600 if (extension_count > 0) {
19601 std::vector<VkExtensionProperties> available_extensions(extension_count);
19602
19603 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19604 ASSERT_VK_SUCCESS(err);
19605
19606 for (const auto &extension_props : available_extensions) {
19607 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19608 supports_nv_dedicated_allocation = true;
19609 }
19610 }
19611 }
19612
19613 if (supports_nv_dedicated_allocation) {
19614 m_errorMonitor->ExpectSuccess();
19615
19616 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19617 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19618 dedicated_buffer_create_info.pNext = nullptr;
19619 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19620
19621 uint32_t queue_family_index = 0;
19622 VkBufferCreateInfo buffer_create_info = {};
19623 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19624 buffer_create_info.pNext = &dedicated_buffer_create_info;
19625 buffer_create_info.size = 1024;
19626 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19627 buffer_create_info.queueFamilyIndexCount = 1;
19628 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19629
19630 VkBuffer buffer;
19631 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19632 ASSERT_VK_SUCCESS(err);
19633
19634 VkMemoryRequirements memory_reqs;
19635 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19636
19637 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19638 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19639 dedicated_memory_info.pNext = nullptr;
19640 dedicated_memory_info.buffer = buffer;
19641 dedicated_memory_info.image = VK_NULL_HANDLE;
19642
19643 VkMemoryAllocateInfo memory_info = {};
19644 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19645 memory_info.pNext = &dedicated_memory_info;
19646 memory_info.allocationSize = memory_reqs.size;
19647
19648 bool pass;
19649 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19650 ASSERT_TRUE(pass);
19651
19652 VkDeviceMemory buffer_memory;
19653 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19654 ASSERT_VK_SUCCESS(err);
19655
19656 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19657 ASSERT_VK_SUCCESS(err);
19658
19659 vkDestroyBuffer(m_device->device(), buffer, NULL);
19660 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19661
19662 m_errorMonitor->VerifyNotFound();
19663 }
19664}
19665
19666TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19667 VkResult err;
19668
19669 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19670
19671 ASSERT_NO_FATAL_FAILURE(InitState());
19672 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19673
19674 std::vector<const char *> device_extension_names;
19675 auto features = m_device->phy().features();
19676 // Artificially disable support for non-solid fill modes
19677 features.fillModeNonSolid = false;
19678 // The sacrificial device object
19679 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19680
19681 VkRenderpassObj render_pass(&test_device);
19682
19683 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19684 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19685 pipeline_layout_ci.setLayoutCount = 0;
19686 pipeline_layout_ci.pSetLayouts = NULL;
19687
19688 VkPipelineLayout pipeline_layout;
19689 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19690 ASSERT_VK_SUCCESS(err);
19691
19692 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19693 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19694 rs_ci.pNext = nullptr;
19695 rs_ci.lineWidth = 1.0f;
19696 rs_ci.rasterizerDiscardEnable = true;
19697
19698 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19699 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19700
19701 // Set polygonMode=FILL. No error is expected
19702 m_errorMonitor->ExpectSuccess();
19703 {
19704 VkPipelineObj pipe(&test_device);
19705 pipe.AddShader(&vs);
19706 pipe.AddShader(&fs);
19707 pipe.AddColorAttachment();
19708 // Set polygonMode to a good value
19709 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19710 pipe.SetRasterization(&rs_ci);
19711 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19712 }
19713 m_errorMonitor->VerifyNotFound();
19714
19715 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19716}
19717
19718TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19719 VkResult err;
19720 ASSERT_NO_FATAL_FAILURE(InitState());
19721 ASSERT_NO_FATAL_FAILURE(InitViewport());
19722 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19723
19724 VkPipelineLayout pipeline_layout;
19725 VkPushConstantRange pc_range = {};
19726 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19727 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19728 pipeline_layout_ci.pushConstantRangeCount = 1;
19729 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19730
19731 //
19732 // Check for invalid push constant ranges in pipeline layouts.
19733 //
19734 struct PipelineLayoutTestCase {
19735 VkPushConstantRange const range;
19736 char const *msg;
19737 };
19738
19739 // Check for overlapping ranges
19740 const uint32_t ranges_per_test = 5;
19741 struct OverlappingRangeTestCase {
19742 VkPushConstantRange const ranges[ranges_per_test];
19743 char const *msg;
19744 };
19745
19746 // Run some positive tests to make sure overlap checking in the layer is OK
19747 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19748 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19749 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19750 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19751 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19752 "" },
19753 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19754 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19755 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19756 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19757 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19758 "" } } };
19759 for (const auto &iter : overlapping_range_tests_pos) {
19760 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19761 m_errorMonitor->ExpectSuccess();
19762 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19763 m_errorMonitor->VerifyNotFound();
19764 if (VK_SUCCESS == err) {
19765 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19766 }
19767 }
19768
19769 //
19770 // CmdPushConstants tests
19771 //
19772 const uint8_t dummy_values[100] = {};
19773
19774 BeginCommandBuffer();
19775
19776 // positive overlapping range tests with cmd
19777 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19778 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19779 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19780 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19781 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19782 } };
19783
19784 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19785 const VkPushConstantRange pc_range4[] = {
19786 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19787 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19788 };
19789
19790 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19791 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19792 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19793 ASSERT_VK_SUCCESS(err);
19794 for (const auto &iter : cmd_overlap_tests_pos) {
19795 m_errorMonitor->ExpectSuccess();
19796 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19797 iter.range.size, dummy_values);
19798 m_errorMonitor->VerifyNotFound();
19799 }
19800 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19801
19802 EndCommandBuffer();
19803}
19804
19805
19806
19807
19808
19809
19810
19811#if 0 // A few devices have issues with this test so disabling for now
19812TEST_F(VkPositiveLayerTest, LongFenceChain)
19813{
19814 m_errorMonitor->ExpectSuccess();
19815
19816 ASSERT_NO_FATAL_FAILURE(InitState());
19817 VkResult err;
19818
19819 std::vector<VkFence> fences;
19820
19821 const int chainLength = 32768;
19822
19823 for (int i = 0; i < chainLength; i++) {
19824 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19825 VkFence fence;
19826 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19827 ASSERT_VK_SUCCESS(err);
19828
19829 fences.push_back(fence);
19830
19831 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19832 0, nullptr, 0, nullptr };
19833 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19834 ASSERT_VK_SUCCESS(err);
19835
19836 }
19837
19838 // BOOM, stack overflow.
19839 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19840
19841 for (auto fence : fences)
19842 vkDestroyFence(m_device->device(), fence, nullptr);
19843
19844 m_errorMonitor->VerifyNotFound();
19845}
19846#endif
19847
19848
Cody Northrop1242dfd2016-07-13 17:24:59 -060019849#if defined(ANDROID) && defined(VALIDATION_APK)
19850static bool initialized = false;
19851static bool active = false;
19852
19853// Convert Intents to argv
19854// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019855std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019856 std::vector<std::string> args;
19857 JavaVM &vm = *app.activity->vm;
19858 JNIEnv *p_env;
19859 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19860 return args;
19861
19862 JNIEnv &env = *p_env;
19863 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019864 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019865 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019866 jmethodID get_string_extra_method =
19867 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019868 jvalue get_string_extra_args;
19869 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019870 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019871
19872 std::string args_str;
19873 if (extra_str) {
19874 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19875 args_str = extra_utf;
19876 env.ReleaseStringUTFChars(extra_str, extra_utf);
19877 env.DeleteLocalRef(extra_str);
19878 }
19879
19880 env.DeleteLocalRef(get_string_extra_args.l);
19881 env.DeleteLocalRef(intent);
19882 vm.DetachCurrentThread();
19883
19884 // split args_str
19885 std::stringstream ss(args_str);
19886 std::string arg;
19887 while (std::getline(ss, arg, ' ')) {
19888 if (!arg.empty())
19889 args.push_back(arg);
19890 }
19891
19892 return args;
19893}
19894
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019895static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019896
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019897static void processCommand(struct android_app *app, int32_t cmd) {
19898 switch (cmd) {
19899 case APP_CMD_INIT_WINDOW: {
19900 if (app->window) {
19901 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019902 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019903 break;
19904 }
19905 case APP_CMD_GAINED_FOCUS: {
19906 active = true;
19907 break;
19908 }
19909 case APP_CMD_LOST_FOCUS: {
19910 active = false;
19911 break;
19912 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019913 }
19914}
19915
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019916void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019917 app_dummy();
19918
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019919 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019920
19921 int vulkanSupport = InitVulkan();
19922 if (vulkanSupport == 0) {
19923 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19924 return;
19925 }
19926
19927 app->onAppCmd = processCommand;
19928 app->onInputEvent = processInput;
19929
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019930 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019931 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019932 struct android_poll_source *source;
19933 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019934 if (source) {
19935 source->process(app, source);
19936 }
19937
19938 if (app->destroyRequested != 0) {
19939 VkTestFramework::Finish();
19940 return;
19941 }
19942 }
19943
19944 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019945 // Use the following key to send arguments to gtest, i.e.
19946 // --es args "--gtest_filter=-VkLayerTest.foo"
19947 const char key[] = "args";
19948 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019949
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019950 std::string filter = "";
19951 if (args.size() > 0) {
19952 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19953 filter += args[0];
19954 } else {
19955 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19956 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019957
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019958 int argc = 2;
19959 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19960 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019961
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019962 // Route output to files until we can override the gtest output
19963 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19964 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019966 ::testing::InitGoogleTest(&argc, argv);
19967 VkTestFramework::InitArgs(&argc, argv);
19968 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019969
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019970 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019971
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019972 if (result != 0) {
19973 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19974 } else {
19975 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19976 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019977
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019978 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019979
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019980 fclose(stdout);
19981 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019982
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019983 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019985 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019986 }
19987 }
19988}
19989#endif
19990
Tony Barbour300a6082015-04-07 13:44:53 -060019991int main(int argc, char **argv) {
19992 int result;
19993
Cody Northrop8e54a402016-03-08 22:25:52 -070019994#ifdef ANDROID
19995 int vulkanSupport = InitVulkan();
19996 if (vulkanSupport == 0)
19997 return 1;
19998#endif
19999
Tony Barbour300a6082015-04-07 13:44:53 -060020000 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020001 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020002
20003 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20004
20005 result = RUN_ALL_TESTS();
20006
Tony Barbour6918cd52015-04-09 12:58:51 -060020007 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020008 return result;
20009}