blob: 3a3f8c33ff9fa4191094e6bceca55c2709b767dd [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060037#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060038#include "vkrenderframework.h"
39#include <limits.h>
40#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060041
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042#define GLM_FORCE_RADIANS
43#include "glm/glm.hpp"
44#include <glm/gtc/matrix_transform.hpp>
45
Dustin Gravesffa90fa2016-05-06 11:20:38 -060046#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060047#define MEM_TRACKER_TESTS 1
48#define OBJ_TRACKER_TESTS 1
49#define DRAW_STATE_TESTS 1
50#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120051#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060052#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060053#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060054
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055//--------------------------------------------------------------------------------------
56// Mesh and VertexFormat Data
57//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070058struct Vertex {
59 float posX, posY, posZ, posW; // Position data
60 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061};
62
Karl Schultz6addd812016-02-02 17:17:23 -070063#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050064
65typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070066 BsoFailNone = 0x00000000,
67 BsoFailLineWidth = 0x00000001,
68 BsoFailDepthBias = 0x00000002,
69 BsoFailViewport = 0x00000004,
70 BsoFailScissor = 0x00000008,
71 BsoFailBlend = 0x00000010,
72 BsoFailDepthBounds = 0x00000020,
73 BsoFailStencilReadMask = 0x00000040,
74 BsoFailStencilWriteMask = 0x00000080,
75 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060076 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060077 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050085};
86
Mark Lobodzinskice751c62016-09-08 10:45:35 -060087static const char bindStateVertShaderText[] = "#version 450\n"
88 "vec2 vertices[3];\n"
89 "out gl_PerVertex {\n"
90 " vec4 gl_Position;\n"
91 "};\n"
92 "void main() {\n"
93 " vertices[0] = vec2(-1.0, -1.0);\n"
94 " vertices[1] = vec2( 1.0, -1.0);\n"
95 " vertices[2] = vec2( 0.0, 1.0);\n"
96 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
97 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060099static const char bindStateFragShaderText[] = "#version 450\n"
100 "\n"
101 "layout(location = 0) out vec4 uFragColor;\n"
102 "void main(){\n"
103 " uFragColor = vec4(0,1,0,1);\n"
104 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500105
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600106static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
107 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
108 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600109
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600110// ErrorMonitor Usage:
111//
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600112// Call SetDesiredFailureMsg with: a string to be compared against all
113// encountered log messages, or a validation error enum identifying
114// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
115// will match all log messages. logMsg will return true for skipCall
116// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117//
118// Call DesiredMsgFound to determine if the desired failure message
119// was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600120class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700121 public:
122 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600123 test_platform_thread_create_mutex(&m_mutex);
124 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200125 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700126 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600127 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600128 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129
Dustin Graves48458142016-04-29 16:11:55 -0600130 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
131
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600132 // ErrorMonitor will look for an error message containing the specified string
Karl Schultz6addd812016-02-02 17:17:23 -0700133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600134 // Also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600136 m_failure_message_strings.clear();
137 // If we are looking for a matching string, ignore any IDs
138 m_desired_message_ids.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600139 m_otherMsgs.clear();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600140 m_desired_message_strings.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700141 m_msgFound = VK_FALSE;
142 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600143 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600144 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600145
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600146 // ErrorMonitor will look for a message ID matching the specified one
147 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
148 // Also discard all collected messages to this point
149 test_platform_thread_lock_mutex(&m_mutex);
150 m_failure_message_strings.clear();
151 // If we are looking for IDs don't look for strings
152 m_desired_message_strings.clear();
153 m_otherMsgs.clear();
154 m_desired_message_ids.insert(msg_id);
155 m_msgFound = VK_FALSE;
156 m_msgFlags = msgFlags;
157 test_platform_thread_unlock_mutex(&m_mutex);
158 }
159
160 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600162 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600163 if (m_bailout != NULL) {
164 *m_bailout = true;
165 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600167 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600168
169 for (auto desired_msg : m_desired_message_strings) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600170 if (desired_msg.length() == 0) {
171 // An empty desired_msg string "" indicates a positive test - not expecting an error.
172 // Return true to avoid calling layers/driver with this error.
173 // And don't erase the "" string, so it remains if another error is found.
174 result = VK_TRUE;
175 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600176 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600177 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600178 m_msgFound = VK_TRUE;
179 result = VK_TRUE;
180 // We only want one match for each expected error so remove from set here
181 // Since we're about the break the loop it's ok to remove from set we're iterating over
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600182 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600183 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186 for (auto desired_id : m_desired_message_ids) {
187 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
188 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
189 // Return true to avoid calling layers/driver with this error.
190 result = VK_TRUE;
191 } else if (desired_id == message_code) {
192 // Double-check that the string matches the error enum
193 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
194 found_expected = true;
195 result = VK_TRUE;
196 m_msgFound = VK_TRUE;
197 m_desired_message_ids.erase(desired_id);
198 break;
199 } else {
200 // Treat this message as a regular unexpected error, but print a warning jic
201 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
202 errorString.c_str(), desired_id, validation_error_map[desired_id]);
203 }
204 }
205 }
206
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600207 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200208 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600209 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600210 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600211 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600212 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600213 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600214
Karl Schultz6addd812016-02-02 17:17:23 -0700215 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600216
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600217 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
218
Karl Schultz6addd812016-02-02 17:17:23 -0700219 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600220
Karl Schultz6addd812016-02-02 17:17:23 -0700221 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600222
Karl Schultz6addd812016-02-02 17:17:23 -0700223 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600224 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600225 if (otherMsgs.size()) {
226 cout << "Other error messages logged for this test were:" << endl;
227 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
228 cout << " " << *iter << endl;
229 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600230 }
231 }
232
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600233 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200234
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600235 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
236 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
237 m_msgFlags = message_flag_mask;
238 // Match ANY message matching specified type
239 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200240 }
241
242 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600243 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200244 if (!DesiredMsgFound()) {
245 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600246 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600247 FAIL() << "Did not receive expected error '" << desired_msg << "'";
248 }
Tony Barbour59b42282016-11-03 13:31:28 -0600249 for (auto desired_id : m_desired_message_ids) {
250 FAIL() << "Did not receive expected error '" << desired_id << "'";
251 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200252 }
253 }
254
255 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600256 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200257 if (DesiredMsgFound()) {
258 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600259 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600260 FAIL() << "Expected to succeed but got error: " << msg;
261 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262 }
263 }
264
Karl Schultz6addd812016-02-02 17:17:23 -0700265 private:
266 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600267 std::unordered_set<uint32_t>m_desired_message_ids;
268 std::unordered_set<string> m_desired_message_strings;
269 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700270 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600271 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700272 bool *m_bailout;
273 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600274};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500275
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600276static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
277 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
278 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600279 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
280 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600281 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600282 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600283 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600284}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500285
Karl Schultz6addd812016-02-02 17:17:23 -0700286class VkLayerTest : public VkRenderFramework {
287 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800288 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
289 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600290 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
291 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700292 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
294 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700295 }
Tony Barbour300a6082015-04-07 13:44:53 -0600296
Tony Barbourfe3351b2015-07-28 10:17:20 -0600297 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600298 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800299 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600300 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
301 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700302 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700304 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600305 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700306 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600307 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
308 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
309 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700310 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
311 }
312 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
313 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
314 }
315
316 protected:
317 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600318 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600319
320 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600321 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600322 std::vector<const char *> instance_extension_names;
323 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600324
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700325 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600326 /*
327 * Since CreateDbgMsgCallback is an instance level extension call
328 * any extension / layer that utilizes that feature also needs
329 * to be enabled at create instance time.
330 */
Karl Schultz6addd812016-02-02 17:17:23 -0700331 // Use Threading layer first to protect others from
332 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700333 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600334 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800335 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700336 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800337 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600338 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700339 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600340
Ian Elliott2c1daf52016-05-12 09:41:46 -0600341 if (m_enableWSI) {
342 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
343 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
344#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
345#if defined(VK_USE_PLATFORM_ANDROID_KHR)
346 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
347#endif // VK_USE_PLATFORM_ANDROID_KHR
348#if defined(VK_USE_PLATFORM_MIR_KHR)
349 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_MIR_KHR
351#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
352 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
353#endif // VK_USE_PLATFORM_WAYLAND_KHR
354#if defined(VK_USE_PLATFORM_WIN32_KHR)
355 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_WIN32_KHR
357#endif // NEED_TO_TEST_THIS_ON_PLATFORM
358#if defined(VK_USE_PLATFORM_XCB_KHR)
359 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
360#elif defined(VK_USE_PLATFORM_XLIB_KHR)
361 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
362#endif // VK_USE_PLATFORM_XLIB_KHR
363 }
364
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600365 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600366 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800367 this->app_info.pApplicationName = "layer_tests";
368 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600369 this->app_info.pEngineName = "unittest";
370 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600371 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600372
Tony Barbour15524c32015-04-29 17:34:29 -0600373 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600374 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600375 }
376
377 virtual void TearDown() {
378 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600379 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600380 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600381 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600382
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600383 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600384};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500385
Karl Schultz6addd812016-02-02 17:17:23 -0700386VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600387 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600388
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800389 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600390
391 /*
392 * For render test all drawing happens in a single render pass
393 * on a single command buffer.
394 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200395 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800396 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600397 }
398
399 return result;
400}
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600403 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600404
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200405 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800406 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200407 }
Tony Barbour300a6082015-04-07 13:44:53 -0600408
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600410
411 return result;
412}
413
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600414void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500415 // Create identity matrix
416 int i;
417 struct vktriangle_vs_uniform data;
418
419 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700420 glm::mat4 View = glm::mat4(1.0f);
421 glm::mat4 Model = glm::mat4(1.0f);
422 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700424 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425
426 memcpy(&data.mvp, &MVP[0][0], matrixSize);
427
Karl Schultz6addd812016-02-02 17:17:23 -0700428 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600429 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500430 };
431
Karl Schultz6addd812016-02-02 17:17:23 -0700432 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 data.position[i][0] = tri_data[i].posX;
434 data.position[i][1] = tri_data[i].posY;
435 data.position[i][2] = tri_data[i].posZ;
436 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700437 data.color[i][0] = tri_data[i].r;
438 data.color[i][1] = tri_data[i].g;
439 data.color[i][2] = tri_data[i].b;
440 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500441 }
442
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 ASSERT_NO_FATAL_FAILURE(InitViewport());
444
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200445 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
446 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Karl Schultz6addd812016-02-02 17:17:23 -0700448 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600449 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
451 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800452 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 pipelineobj.AddShader(&vs);
454 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 if (failMask & BsoFailLineWidth) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600457 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600458 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600459 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
460 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600461 }
462 if (failMask & BsoFailDepthBias) {
463 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600464 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600465 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600466 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600467 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600468 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600469 }
Karl Schultz6addd812016-02-02 17:17:23 -0700470 // Viewport and scissors must stay in synch or other errors will occur than
471 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 if (failMask & BsoFailViewport) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
474 }
475 if (failMask & BsoFailScissor) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
477 }
478 if (failMask & BsoFailBlend) {
479 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600480 VkPipelineColorBlendAttachmentState att_state = {};
481 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
482 att_state.blendEnable = VK_TRUE;
483 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600484 }
485 if (failMask & BsoFailDepthBounds) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
487 }
488 if (failMask & BsoFailStencilReadMask) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
490 }
491 if (failMask & BsoFailStencilWriteMask) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
493 }
494 if (failMask & BsoFailStencilReference) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
496 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500497
498 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600499 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600502 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
Tony Barbourfe3351b2015-07-28 10:17:20 -0600504 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500505
506 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600507 if (failMask & BsoFailIndexBuffer) {
508 // Use DrawIndexed w/o an index buffer bound
509 DrawIndexed(3, 1, 0, 0, 0);
510 } else {
511 Draw(3, 1, 0, 0);
512 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500513
Mark Muellerd4914412016-06-13 17:52:06 -0600514 if (failMask & BsoFailCmdClearAttachments) {
515 VkClearAttachment color_attachment = {};
516 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
517 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
518 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
519
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600520 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600521 }
522
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500523 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600524 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500525
Tony Barbourfe3351b2015-07-28 10:17:20 -0600526 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500527}
528
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600529void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
530 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500531 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500533 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600534 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500535 }
536
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800537 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700538 // Make sure depthWriteEnable is set so that Depth fail test will work
539 // correctly
540 // Make sure stencilTestEnable is set so that Stencil fail test will work
541 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600542 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800543 stencil.failOp = VK_STENCIL_OP_KEEP;
544 stencil.passOp = VK_STENCIL_OP_KEEP;
545 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
546 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600547
548 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
549 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600550 ds_ci.pNext = NULL;
551 ds_ci.depthTestEnable = VK_FALSE;
552 ds_ci.depthWriteEnable = VK_TRUE;
553 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
554 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600555 if (failMask & BsoFailDepthBounds) {
556 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600557 ds_ci.maxDepthBounds = 0.0f;
558 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600559 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600560 ds_ci.stencilTestEnable = VK_TRUE;
561 ds_ci.front = stencil;
562 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600563
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600564 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600565 pipelineobj.SetViewport(m_viewports);
566 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800567 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600568 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600569 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800570 commandBuffer->BindPipeline(pipelineobj);
571 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500572}
573
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600574class VkPositiveLayerTest : public VkLayerTest {
575 public:
576 protected:
577};
578
Ian Elliott2c1daf52016-05-12 09:41:46 -0600579class VkWsiEnabledLayerTest : public VkLayerTest {
580 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 protected:
582 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600583};
584
Mark Muellerdfe37552016-07-07 14:47:42 -0600585class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600586 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600587 enum eTestEnFlags {
588 eDoubleDelete,
589 eInvalidDeviceOffset,
590 eInvalidMemoryOffset,
591 eBindNullBuffer,
592 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600593 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600594 };
595
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600596 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600597
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
599 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600600 return true;
601 }
602 VkDeviceSize offset_limit = 0;
603 if (eInvalidMemoryOffset == aTestFlag) {
604 VkBuffer vulkanBuffer;
605 VkBufferCreateInfo buffer_create_info = {};
606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
607 buffer_create_info.size = 32;
608 buffer_create_info.usage = aBufferUsage;
609
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600610 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600611 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600614 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
615 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
617 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600618 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600620 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600622 }
623 if (eOffsetAlignment < offset_limit) {
624 return true;
625 }
626 return false;
627 }
628
629 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
631 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
633 if (eBindNullBuffer == aTestFlag) {
634 VulkanMemory = 0;
635 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
636 } else {
637 VkBufferCreateInfo buffer_create_info = {};
638 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
639 buffer_create_info.size = 32;
640 buffer_create_info.usage = aBufferUsage;
641
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600643
644 CreateCurrent = true;
645
646 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600647 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600648
649 VkMemoryAllocateInfo memory_allocate_info = {};
650 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
651 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
653 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600654 if (!pass) {
655 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
656 return;
657 }
658
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600659 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600660 AllocateCurrent = true;
661 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
663 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 BoundCurrent = true;
665
666 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
667 }
668 }
669
670 ~VkBufferTest() {
671 if (CreateCurrent) {
672 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
673 }
674 if (AllocateCurrent) {
675 if (InvalidDeleteEn) {
676 union {
677 VkDeviceMemory device_memory;
678 unsigned long long index_access;
679 } bad_index;
680
681 bad_index.device_memory = VulkanMemory;
682 bad_index.index_access++;
683
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600684 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600685 }
686 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
687 }
688 }
689
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600690 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600691
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600692 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600693
694 void TestDoubleDestroy() {
695 // Destroy the buffer but leave the flag set, which will cause
696 // the buffer to be destroyed again in the destructor.
697 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600701 bool AllocateCurrent;
702 bool BoundCurrent;
703 bool CreateCurrent;
704 bool InvalidDeleteEn;
705
706 VkBuffer VulkanBuffer;
707 VkDevice VulkanDevice;
708 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600709};
710
711class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600712 public:
713 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600714 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600716 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600717 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
718 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 BindIdGenerator++; // NB: This can wrap w/misuse
720
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600721 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
722 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
725 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
726 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
727 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
728 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600729
730 unsigned i = 0;
731 do {
732 VertexInputAttributeDescription[i].binding = BindId;
733 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
735 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600736 i++;
737 } while (AttributeCount < i);
738
739 i = 0;
740 do {
741 VertexInputBindingDescription[i].binding = BindId;
742 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600743 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600744 i++;
745 } while (BindingCount < i);
746 }
747
748 ~VkVerticesObj() {
749 if (VertexInputAttributeDescription) {
750 delete[] VertexInputAttributeDescription;
751 }
752 if (VertexInputBindingDescription) {
753 delete[] VertexInputBindingDescription;
754 }
755 }
756
757 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
759 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600760 return true;
761 }
762
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600763 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600764 VkDeviceSize *offsetList;
765 unsigned offsetCount;
766
767 if (aOffsetCount) {
768 offsetList = aOffsetList;
769 offsetCount = aOffsetCount;
770 } else {
771 offsetList = new VkDeviceSize[1]();
772 offsetCount = 1;
773 }
774
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600775 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600776 BoundCurrent = true;
777
778 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600779 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600780 }
781 }
782
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600783 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600784 static uint32_t BindIdGenerator;
785
786 bool BoundCurrent;
787 unsigned AttributeCount;
788 unsigned BindingCount;
789 uint32_t BindId;
790
791 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
792 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
793 VkVertexInputBindingDescription *VertexInputBindingDescription;
794 VkConstantBufferObj VulkanMemoryBuffer;
795};
796
797uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500798// ********************************************************************************************************************
799// ********************************************************************************************************************
800// ********************************************************************************************************************
801// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600802#if PARAMETER_VALIDATION_TESTS
803TEST_F(VkLayerTest, RequiredParameter) {
804 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
805 "pointer, array, and array count parameters");
806
807 ASSERT_NO_FATAL_FAILURE(InitState());
808
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600810 // Specify NULL for a pointer to a handle
811 // Expected to trigger an error with
812 // parameter_validation::validate_required_pointer
813 vkGetPhysicalDeviceFeatures(gpu(), NULL);
814 m_errorMonitor->VerifyFound();
815
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
817 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600818 // Specify NULL for pointer to array count
819 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600820 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600821 m_errorMonitor->VerifyFound();
822
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 // Specify 0 for a required array count
825 // Expected to trigger an error with parameter_validation::validate_array
826 VkViewport view_port = {};
827 m_commandBuffer->SetViewport(0, 0, &view_port);
828 m_errorMonitor->VerifyFound();
829
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for a required array
832 // Expected to trigger an error with parameter_validation::validate_array
833 m_commandBuffer->SetViewport(0, 1, NULL);
834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify VK_NULL_HANDLE for a required handle
838 // Expected to trigger an error with
839 // parameter_validation::validate_required_handle
840 vkUnmapMemory(device(), VK_NULL_HANDLE);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
844 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600845 // Specify VK_NULL_HANDLE for a required handle array entry
846 // Expected to trigger an error with
847 // parameter_validation::validate_required_handle_array
848 VkFence fence = VK_NULL_HANDLE;
849 vkResetFences(device(), 1, &fence);
850 m_errorMonitor->VerifyFound();
851
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600853 // Specify NULL for a required struct pointer
854 // Expected to trigger an error with
855 // parameter_validation::validate_struct_type
856 VkDeviceMemory memory = VK_NULL_HANDLE;
857 vkAllocateMemory(device(), NULL, NULL, &memory);
858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600861 // Specify 0 for a required VkFlags parameter
862 // Expected to trigger an error with parameter_validation::validate_flags
863 m_commandBuffer->SetStencilReference(0, 0);
864 m_errorMonitor->VerifyFound();
865
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600867 // Specify 0 for a required VkFlags array entry
868 // Expected to trigger an error with
869 // parameter_validation::validate_flags_array
870 VkSemaphore semaphore = VK_NULL_HANDLE;
871 VkPipelineStageFlags stageFlags = 0;
872 VkSubmitInfo submitInfo = {};
873 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
874 submitInfo.waitSemaphoreCount = 1;
875 submitInfo.pWaitSemaphores = &semaphore;
876 submitInfo.pWaitDstStageMask = &stageFlags;
877 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
878 m_errorMonitor->VerifyFound();
879}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600880
Dustin Gravesfce74c02016-05-10 11:42:58 -0600881TEST_F(VkLayerTest, ReservedParameter) {
882 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
883
884 ASSERT_NO_FATAL_FAILURE(InitState());
885
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600887 // Specify 0 for a reserved VkFlags parameter
888 // Expected to trigger an error with
889 // parameter_validation::validate_reserved_flags
890 VkEvent event_handle = VK_NULL_HANDLE;
891 VkEventCreateInfo event_info = {};
892 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
893 event_info.flags = 1;
894 vkCreateEvent(device(), &event_info, NULL, &event_handle);
895 m_errorMonitor->VerifyFound();
896}
897
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600898TEST_F(VkLayerTest, InvalidStructSType) {
899 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
900 "structure's sType field");
901
902 ASSERT_NO_FATAL_FAILURE(InitState());
903
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600905 // Zero struct memory, effectively setting sType to
906 // VK_STRUCTURE_TYPE_APPLICATION_INFO
907 // Expected to trigger an error with
908 // parameter_validation::validate_struct_type
909 VkMemoryAllocateInfo alloc_info = {};
910 VkDeviceMemory memory = VK_NULL_HANDLE;
911 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
912 m_errorMonitor->VerifyFound();
913
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915 // Zero struct memory, effectively setting sType to
916 // VK_STRUCTURE_TYPE_APPLICATION_INFO
917 // Expected to trigger an error with
918 // parameter_validation::validate_struct_type_array
919 VkSubmitInfo submit_info = {};
920 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
921 m_errorMonitor->VerifyFound();
922}
923
924TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600925 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600926
927 ASSERT_NO_FATAL_FAILURE(InitState());
928
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600930 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600931 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600932 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600933 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600934 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600935 // Zero-initialization will provide the correct sType
936 VkApplicationInfo app_info = {};
937 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
938 event_alloc_info.pNext = &app_info;
939 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
940 m_errorMonitor->VerifyFound();
941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
943 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
945 // a function that has allowed pNext structure types and specify
946 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600947 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600948 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600949 VkMemoryAllocateInfo memory_alloc_info = {};
950 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
951 memory_alloc_info.pNext = &app_info;
952 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600953 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600954}
Dustin Graves5d33d532016-05-09 16:21:12 -0600955
956TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600957 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600958
959 ASSERT_NO_FATAL_FAILURE(InitState());
960
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
962 "range of the core VkFormat "
963 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600964 // Specify an invalid VkFormat value
965 // Expected to trigger an error with
966 // parameter_validation::validate_ranged_enum
967 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600968 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600969 m_errorMonitor->VerifyFound();
970
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 // Specify an invalid VkFlags bitmask value
973 // Expected to trigger an error with parameter_validation::validate_flags
974 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600975 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
976 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600977 m_errorMonitor->VerifyFound();
978
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 // Specify an invalid VkFlags array entry
981 // Expected to trigger an error with
982 // parameter_validation::validate_flags_array
983 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600984 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600985 VkSubmitInfo submit_info = {};
986 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
987 submit_info.waitSemaphoreCount = 1;
988 submit_info.pWaitSemaphores = &semaphore;
989 submit_info.pWaitDstStageMask = &stage_flags;
990 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
991 m_errorMonitor->VerifyFound();
992
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 // Specify an invalid VkBool32 value
995 // Expected to trigger a warning with
996 // parameter_validation::validate_bool32
997 VkSampler sampler = VK_NULL_HANDLE;
998 VkSamplerCreateInfo sampler_info = {};
999 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1000 sampler_info.pNext = NULL;
1001 sampler_info.magFilter = VK_FILTER_NEAREST;
1002 sampler_info.minFilter = VK_FILTER_NEAREST;
1003 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1004 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1005 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1006 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1007 sampler_info.mipLodBias = 1.0;
1008 sampler_info.maxAnisotropy = 1;
1009 sampler_info.compareEnable = VK_FALSE;
1010 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1011 sampler_info.minLod = 1.0;
1012 sampler_info.maxLod = 1.0;
1013 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1014 sampler_info.unnormalizedCoordinates = VK_FALSE;
1015 // Not VK_TRUE or VK_FALSE
1016 sampler_info.anisotropyEnable = 3;
1017 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1018 m_errorMonitor->VerifyFound();
1019}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001020
1021TEST_F(VkLayerTest, FailedReturnValue) {
1022 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1023
1024 ASSERT_NO_FATAL_FAILURE(InitState());
1025
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001026 // Find an unsupported image format
1027 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1028 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1029 VkFormat format = static_cast<VkFormat>(f);
1030 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001031 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001032 unsupported = format;
1033 break;
1034 }
1035 }
1036
1037 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1039 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001040 // Specify an unsupported VkFormat value to generate a
1041 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1042 // Expected to trigger a warning from
1043 // parameter_validation::validate_result
1044 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001045 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1046 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1048 m_errorMonitor->VerifyFound();
1049 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001050}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001051
1052TEST_F(VkLayerTest, UpdateBufferAlignment) {
1053 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001054 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001055
1056 ASSERT_NO_FATAL_FAILURE(InitState());
1057
1058 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1059 vk_testing::Buffer buffer;
1060 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1061
1062 BeginCommandBuffer();
1063 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1066 m_errorMonitor->VerifyFound();
1067
1068 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1071 m_errorMonitor->VerifyFound();
1072
1073 // Introduce failure by using dataSize that is < 0
1074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001075 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1077 m_errorMonitor->VerifyFound();
1078
1079 // Introduce failure by using dataSize that is > 65536
1080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001081 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001082 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1083 m_errorMonitor->VerifyFound();
1084
1085 EndCommandBuffer();
1086}
1087
1088TEST_F(VkLayerTest, FillBufferAlignment) {
1089 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1090
1091 ASSERT_NO_FATAL_FAILURE(InitState());
1092
1093 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1094 vk_testing::Buffer buffer;
1095 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1096
1097 BeginCommandBuffer();
1098
1099 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1102 m_errorMonitor->VerifyFound();
1103
1104 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001106 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1107 m_errorMonitor->VerifyFound();
1108
1109 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001111 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1112 m_errorMonitor->VerifyFound();
1113
1114 EndCommandBuffer();
1115}
Dustin Graves40f35822016-06-23 11:12:53 -06001116
Cortd889ff92016-07-27 09:51:27 -07001117TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1118 VkResult err;
1119
1120 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001121 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001122
1123 ASSERT_NO_FATAL_FAILURE(InitState());
1124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1125
1126 std::vector<const char *> device_extension_names;
1127 auto features = m_device->phy().features();
1128 // Artificially disable support for non-solid fill modes
1129 features.fillModeNonSolid = false;
1130 // The sacrificial device object
1131 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1132
1133 VkRenderpassObj render_pass(&test_device);
1134
1135 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1136 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1137 pipeline_layout_ci.setLayoutCount = 0;
1138 pipeline_layout_ci.pSetLayouts = NULL;
1139
1140 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001141 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001142 ASSERT_VK_SUCCESS(err);
1143
1144 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1145 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1146 rs_ci.pNext = nullptr;
1147 rs_ci.lineWidth = 1.0f;
1148 rs_ci.rasterizerDiscardEnable = true;
1149
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001150 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1151 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001152
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001153 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1155 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001156 {
1157 VkPipelineObj pipe(&test_device);
1158 pipe.AddShader(&vs);
1159 pipe.AddShader(&fs);
1160 pipe.AddColorAttachment();
1161 // Introduce failure by setting unsupported polygon mode
1162 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1163 pipe.SetRasterization(&rs_ci);
1164 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1165 }
1166 m_errorMonitor->VerifyFound();
1167
1168 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1170 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001171 {
1172 VkPipelineObj pipe(&test_device);
1173 pipe.AddShader(&vs);
1174 pipe.AddShader(&fs);
1175 pipe.AddColorAttachment();
1176 // Introduce failure by setting unsupported polygon mode
1177 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1178 pipe.SetRasterization(&rs_ci);
1179 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1180 }
1181 m_errorMonitor->VerifyFound();
1182
Cortd889ff92016-07-27 09:51:27 -07001183 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1184}
1185
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001186#endif // PARAMETER_VALIDATION_TESTS
1187
Tobin Ehlis0788f522015-05-26 16:11:58 -06001188#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001189#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001190TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001191{
1192 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001193 VkFenceCreateInfo fenceInfo = {};
1194 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1195 fenceInfo.pNext = NULL;
1196 fenceInfo.flags = 0;
1197
Mike Weiblencce7ec72016-10-17 19:33:05 -06001198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001199
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001200 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001201
1202 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1203 vk_testing::Buffer buffer;
1204 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001205
Tony Barbourfe3351b2015-07-28 10:17:20 -06001206 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001207 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001208 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001209
1210 testFence.init(*m_device, fenceInfo);
1211
1212 // Bypass framework since it does the waits automatically
1213 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001214 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001215 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1216 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001217 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001218 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001219 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001220 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001221 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001222 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001223 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001224
1225 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001226 ASSERT_VK_SUCCESS( err );
1227
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001229 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001230
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001231 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232}
1233
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001235{
1236 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001237 VkFenceCreateInfo fenceInfo = {};
1238 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1239 fenceInfo.pNext = NULL;
1240 fenceInfo.flags = 0;
1241
Mike Weiblencce7ec72016-10-17 19:33:05 -06001242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001243
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001244 ASSERT_NO_FATAL_FAILURE(InitState());
1245 ASSERT_NO_FATAL_FAILURE(InitViewport());
1246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1247
Tony Barbourfe3351b2015-07-28 10:17:20 -06001248 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001249 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001250 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251
1252 testFence.init(*m_device, fenceInfo);
1253
1254 // Bypass framework since it does the waits automatically
1255 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001256 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001257 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1258 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001259 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001260 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001261 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001262 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001263 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001264 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001265 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001266
1267 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001268 ASSERT_VK_SUCCESS( err );
1269
Jon Ashburnf19916e2016-01-11 13:12:43 -07001270 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001271 VkCommandBufferBeginInfo info = {};
1272 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1273 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001274 info.renderPass = VK_NULL_HANDLE;
1275 info.subpass = 0;
1276 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001277 info.occlusionQueryEnable = VK_FALSE;
1278 info.queryFlags = 0;
1279 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001280
1281 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001282 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001283
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001284 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001285}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001286#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001287
Tobin Ehlisf11be982016-05-11 13:52:53 -06001288TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1289 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1290 "buffer and image to memory such that they will alias.");
1291 VkResult err;
1292 bool pass;
1293 ASSERT_NO_FATAL_FAILURE(InitState());
1294
Tobin Ehlis077ded32016-05-12 17:39:13 -06001295 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001296 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001297 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001298 VkDeviceMemory mem; // buffer will be bound first
1299 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001300 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001301
1302 VkBufferCreateInfo buf_info = {};
1303 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1304 buf_info.pNext = NULL;
1305 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1306 buf_info.size = 256;
1307 buf_info.queueFamilyIndexCount = 0;
1308 buf_info.pQueueFamilyIndices = NULL;
1309 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1310 buf_info.flags = 0;
1311 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1312 ASSERT_VK_SUCCESS(err);
1313
Tobin Ehlis077ded32016-05-12 17:39:13 -06001314 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001315
1316 VkImageCreateInfo image_create_info = {};
1317 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1318 image_create_info.pNext = NULL;
1319 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1320 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1321 image_create_info.extent.width = 64;
1322 image_create_info.extent.height = 64;
1323 image_create_info.extent.depth = 1;
1324 image_create_info.mipLevels = 1;
1325 image_create_info.arrayLayers = 1;
1326 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001327 // Image tiling must be optimal to trigger error when aliasing linear buffer
1328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001329 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1330 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1331 image_create_info.queueFamilyIndexCount = 0;
1332 image_create_info.pQueueFamilyIndices = NULL;
1333 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1334 image_create_info.flags = 0;
1335
Tobin Ehlisf11be982016-05-11 13:52:53 -06001336 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1337 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001338 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1339 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001340
Tobin Ehlis077ded32016-05-12 17:39:13 -06001341 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1342
1343 VkMemoryAllocateInfo alloc_info = {};
1344 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1345 alloc_info.pNext = NULL;
1346 alloc_info.memoryTypeIndex = 0;
1347 // Ensure memory is big enough for both bindings
1348 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001349 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1350 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001351 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001352 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001353 vkDestroyImage(m_device->device(), image, NULL);
1354 return;
1355 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001356 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1357 ASSERT_VK_SUCCESS(err);
1358 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1359 ASSERT_VK_SUCCESS(err);
1360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001362 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001363 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1364 m_errorMonitor->VerifyFound();
1365
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001366 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001367 // aliasing buffer2
1368 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1369 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001370 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1371 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001372 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001373 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001375 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001376 m_errorMonitor->VerifyFound();
1377
1378 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001379 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001380 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001381 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001382 vkFreeMemory(m_device->device(), mem, NULL);
1383 vkFreeMemory(m_device->device(), mem_img, NULL);
1384}
1385
Tobin Ehlis35372522016-05-12 08:32:31 -06001386TEST_F(VkLayerTest, InvalidMemoryMapping) {
1387 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1388 VkResult err;
1389 bool pass;
1390 ASSERT_NO_FATAL_FAILURE(InitState());
1391
1392 VkBuffer buffer;
1393 VkDeviceMemory mem;
1394 VkMemoryRequirements mem_reqs;
1395
1396 VkBufferCreateInfo buf_info = {};
1397 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1398 buf_info.pNext = NULL;
1399 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1400 buf_info.size = 256;
1401 buf_info.queueFamilyIndexCount = 0;
1402 buf_info.pQueueFamilyIndices = NULL;
1403 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1404 buf_info.flags = 0;
1405 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1406 ASSERT_VK_SUCCESS(err);
1407
1408 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1409 VkMemoryAllocateInfo alloc_info = {};
1410 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1411 alloc_info.pNext = NULL;
1412 alloc_info.memoryTypeIndex = 0;
1413
1414 // Ensure memory is big enough for both bindings
1415 static const VkDeviceSize allocation_size = 0x10000;
1416 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001417 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001418 if (!pass) {
1419 vkDestroyBuffer(m_device->device(), buffer, NULL);
1420 return;
1421 }
1422 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1423 ASSERT_VK_SUCCESS(err);
1424
1425 uint8_t *pData;
1426 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001428 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1429 m_errorMonitor->VerifyFound();
1430 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001431 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001432 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1434 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1435 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001436 m_errorMonitor->VerifyFound();
1437
1438 // Unmap the memory to avoid re-map error
1439 vkUnmapMemory(m_device->device(), mem);
1440 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1442 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1443 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001444 m_errorMonitor->VerifyFound();
1445 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1447 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001448 m_errorMonitor->VerifyFound();
1449 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001451 vkUnmapMemory(m_device->device(), mem);
1452 m_errorMonitor->VerifyFound();
1453 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001454 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001455 ASSERT_VK_SUCCESS(err);
1456 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001457 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001458 mmr.memory = mem;
1459 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") is less than Memory Object's offset (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001461 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1462 m_errorMonitor->VerifyFound();
1463 // Now flush range that oversteps mapped range
1464 vkUnmapMemory(m_device->device(), mem);
1465 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1466 ASSERT_VK_SUCCESS(err);
1467 mmr.offset = 16;
1468 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") exceeds the Memory Object's upper-bound (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001470 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1471 m_errorMonitor->VerifyFound();
1472
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001473 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1474 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001475 if (!pass) {
1476 vkFreeMemory(m_device->device(), mem, NULL);
1477 vkDestroyBuffer(m_device->device(), buffer, NULL);
1478 return;
1479 }
1480 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1481 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1482
1483 vkDestroyBuffer(m_device->device(), buffer, NULL);
1484 vkFreeMemory(m_device->device(), mem, NULL);
1485}
1486
Ian Elliott1c32c772016-04-28 14:47:13 -06001487TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1488 VkResult err;
1489 bool pass;
1490
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001491 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1492 // following declaration (which is temporarily being moved below):
1493 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001494 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001495 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001496 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001497 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001498 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001499 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001500
1501 ASSERT_NO_FATAL_FAILURE(InitState());
1502
Ian Elliott3f06ce52016-04-29 14:46:21 -06001503#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1504#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1505 // Use the functions from the VK_KHR_android_surface extension without
1506 // enabling that extension:
1507
1508 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001509 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1511 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001512 pass = (err != VK_SUCCESS);
1513 ASSERT_TRUE(pass);
1514 m_errorMonitor->VerifyFound();
1515#endif // VK_USE_PLATFORM_ANDROID_KHR
1516
Ian Elliott3f06ce52016-04-29 14:46:21 -06001517#if defined(VK_USE_PLATFORM_MIR_KHR)
1518 // Use the functions from the VK_KHR_mir_surface extension without enabling
1519 // that extension:
1520
1521 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001522 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001524 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1525 pass = (err != VK_SUCCESS);
1526 ASSERT_TRUE(pass);
1527 m_errorMonitor->VerifyFound();
1528
1529 // Tell whether an mir_connection supports presentation:
1530 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1532 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001533 m_errorMonitor->VerifyFound();
1534#endif // VK_USE_PLATFORM_MIR_KHR
1535
Ian Elliott3f06ce52016-04-29 14:46:21 -06001536#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1537 // Use the functions from the VK_KHR_wayland_surface extension without
1538 // enabling that extension:
1539
1540 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001541 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1543 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001544 pass = (err != VK_SUCCESS);
1545 ASSERT_TRUE(pass);
1546 m_errorMonitor->VerifyFound();
1547
1548 // Tell whether an wayland_display supports presentation:
1549 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1551 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001552 m_errorMonitor->VerifyFound();
1553#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001554#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001555
Ian Elliott3f06ce52016-04-29 14:46:21 -06001556#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001557 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1558 // TO NON-LINUX PLATFORMS:
1559 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001560 // Use the functions from the VK_KHR_win32_surface extension without
1561 // enabling that extension:
1562
1563 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001564 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1566 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001567 pass = (err != VK_SUCCESS);
1568 ASSERT_TRUE(pass);
1569 m_errorMonitor->VerifyFound();
1570
1571 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001573 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001574 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001575// Set this (for now, until all platforms are supported and tested):
1576#define NEED_TO_TEST_THIS_ON_PLATFORM
1577#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001578#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001579 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1580 // TO NON-LINUX PLATFORMS:
1581 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001582#endif
1583#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001584 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1585 // that extension:
1586
1587 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001588 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001590 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1591 pass = (err != VK_SUCCESS);
1592 ASSERT_TRUE(pass);
1593 m_errorMonitor->VerifyFound();
1594
1595 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001596 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001597 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1599 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001600 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001601// Set this (for now, until all platforms are supported and tested):
1602#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001603#endif // VK_USE_PLATFORM_XCB_KHR
1604
Ian Elliott12630812016-04-29 14:35:43 -06001605#if defined(VK_USE_PLATFORM_XLIB_KHR)
1606 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1607 // that extension:
1608
1609 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001610 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001612 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1613 pass = (err != VK_SUCCESS);
1614 ASSERT_TRUE(pass);
1615 m_errorMonitor->VerifyFound();
1616
1617 // Tell whether an Xlib VisualID supports presentation:
1618 Display *dpy = NULL;
1619 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001621 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1622 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001623// Set this (for now, until all platforms are supported and tested):
1624#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001625#endif // VK_USE_PLATFORM_XLIB_KHR
1626
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001627// Use the functions from the VK_KHR_surface extension without enabling
1628// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001629
Ian Elliott489eec02016-05-05 14:12:44 -06001630#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001631 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001633 vkDestroySurfaceKHR(instance(), surface, NULL);
1634 m_errorMonitor->VerifyFound();
1635
1636 // Check if surface supports presentation:
1637 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001639 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1640 pass = (err != VK_SUCCESS);
1641 ASSERT_TRUE(pass);
1642 m_errorMonitor->VerifyFound();
1643
1644 // Check surface capabilities:
1645 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1647 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001648 pass = (err != VK_SUCCESS);
1649 ASSERT_TRUE(pass);
1650 m_errorMonitor->VerifyFound();
1651
1652 // Check surface formats:
1653 uint32_t format_count = 0;
1654 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1656 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001657 pass = (err != VK_SUCCESS);
1658 ASSERT_TRUE(pass);
1659 m_errorMonitor->VerifyFound();
1660
1661 // Check surface present modes:
1662 uint32_t present_mode_count = 0;
1663 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1665 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001666 pass = (err != VK_SUCCESS);
1667 ASSERT_TRUE(pass);
1668 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001669#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001670
Ian Elliott1c32c772016-04-28 14:47:13 -06001671 // Use the functions from the VK_KHR_swapchain extension without enabling
1672 // that extension:
1673
1674 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001676 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1677 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001678 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001679 pass = (err != VK_SUCCESS);
1680 ASSERT_TRUE(pass);
1681 m_errorMonitor->VerifyFound();
1682
1683 // Get the images from the swapchain:
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 = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001686 pass = (err != VK_SUCCESS);
1687 ASSERT_TRUE(pass);
1688 m_errorMonitor->VerifyFound();
1689
Chris Forbeseb7d5502016-09-13 18:19:21 +12001690 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1691 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1692 VkFence fence;
1693 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1694
Ian Elliott1c32c772016-04-28 14:47:13 -06001695 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001697 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001698 pass = (err != VK_SUCCESS);
1699 ASSERT_TRUE(pass);
1700 m_errorMonitor->VerifyFound();
1701
Chris Forbeseb7d5502016-09-13 18:19:21 +12001702 vkDestroyFence(m_device->device(), fence, nullptr);
1703
Ian Elliott1c32c772016-04-28 14:47:13 -06001704 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001705 //
1706 // NOTE: Currently can't test this because a real swapchain is needed (as
1707 // opposed to the fake one we created) in order for the layer to lookup the
1708 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001709
1710 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001712 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1713 m_errorMonitor->VerifyFound();
1714}
1715
Karl Schultz6addd812016-02-02 17:17:23 -07001716TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1717 VkResult err;
1718 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001719
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1721 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001722
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001723 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001724
1725 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001726 VkImage image;
1727 VkDeviceMemory mem;
1728 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001729
Karl Schultz6addd812016-02-02 17:17:23 -07001730 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1731 const int32_t tex_width = 32;
1732 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001733
Tony Barboureb254902015-07-15 12:50:33 -06001734 VkImageCreateInfo image_create_info = {};
1735 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001736 image_create_info.pNext = NULL;
1737 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1738 image_create_info.format = tex_format;
1739 image_create_info.extent.width = tex_width;
1740 image_create_info.extent.height = tex_height;
1741 image_create_info.extent.depth = 1;
1742 image_create_info.mipLevels = 1;
1743 image_create_info.arrayLayers = 1;
1744 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1745 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1746 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1747 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001748 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001749
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001750 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001751 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001752 mem_alloc.pNext = NULL;
1753 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001754
Chia-I Wuf7458c52015-10-26 21:10:41 +08001755 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001756 ASSERT_VK_SUCCESS(err);
1757
Karl Schultz6addd812016-02-02 17:17:23 -07001758 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001759
Mark Lobodzinski23065352015-05-29 09:32:35 -05001760 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001761
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001762 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 -07001763 if (!pass) { // If we can't find any unmappable memory this test doesn't
1764 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001765 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001766 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001767 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001768
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001769 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001770 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001771 ASSERT_VK_SUCCESS(err);
1772
1773 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001774 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001775 ASSERT_VK_SUCCESS(err);
1776
1777 // Map memory as if to initialize the image
1778 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001779 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001780
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001781 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001782
Chia-I Wuf7458c52015-10-26 21:10:41 +08001783 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001784 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001785}
1786
Karl Schultz6addd812016-02-02 17:17:23 -07001787TEST_F(VkLayerTest, RebindMemory) {
1788 VkResult err;
1789 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001790
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001792
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001793 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001794
1795 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001796 VkImage image;
1797 VkDeviceMemory mem1;
1798 VkDeviceMemory mem2;
1799 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001800
Karl Schultz6addd812016-02-02 17:17:23 -07001801 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1802 const int32_t tex_width = 32;
1803 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001804
Tony Barboureb254902015-07-15 12:50:33 -06001805 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001806 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1807 image_create_info.pNext = NULL;
1808 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1809 image_create_info.format = tex_format;
1810 image_create_info.extent.width = tex_width;
1811 image_create_info.extent.height = tex_height;
1812 image_create_info.extent.depth = 1;
1813 image_create_info.mipLevels = 1;
1814 image_create_info.arrayLayers = 1;
1815 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1816 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1817 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1818 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001819
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001820 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001821 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1822 mem_alloc.pNext = NULL;
1823 mem_alloc.allocationSize = 0;
1824 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001825
Karl Schultz6addd812016-02-02 17:17:23 -07001826 // Introduce failure, do NOT set memProps to
1827 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001828 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001829 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001830 ASSERT_VK_SUCCESS(err);
1831
Karl Schultz6addd812016-02-02 17:17:23 -07001832 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001833
1834 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001835 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001836 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001837
1838 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001839 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001840 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001841 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001842 ASSERT_VK_SUCCESS(err);
1843
1844 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001845 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001846 ASSERT_VK_SUCCESS(err);
1847
Karl Schultz6addd812016-02-02 17:17:23 -07001848 // Introduce validation failure, try to bind a different memory object to
1849 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001850 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001851
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001852 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001853
Chia-I Wuf7458c52015-10-26 21:10:41 +08001854 vkDestroyImage(m_device->device(), image, NULL);
1855 vkFreeMemory(m_device->device(), mem1, NULL);
1856 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001857}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001858
Karl Schultz6addd812016-02-02 17:17:23 -07001859TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001860 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1863 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001864
1865 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001866 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1867 fenceInfo.pNext = NULL;
1868 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001869
Tony Barbour300a6082015-04-07 13:44:53 -06001870 ASSERT_NO_FATAL_FAILURE(InitState());
1871 ASSERT_NO_FATAL_FAILURE(InitViewport());
1872 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1873
Tony Barbourfe3351b2015-07-28 10:17:20 -06001874 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001875 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001876 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001877
1878 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001879
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001880 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001881 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1882 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001883 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001884 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001885 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001886 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001887 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001888 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001889 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001890
1891 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001892 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001893
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001894 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001895}
Chris Forbes4e44c912016-06-16 10:20:00 +12001896
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001897TEST_F(VkLayerTest, InvalidUsageBits) {
1898 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1899 "Initialize buffer with wrong usage then perform copy expecting errors "
1900 "from both the image and the buffer (2 calls)");
1901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001902
1903 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001904 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001905 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001906 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 -06001907 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001908
Tony Barbourf92621a2016-05-02 14:28:12 -06001909 VkImageView dsv;
1910 VkImageViewCreateInfo dsvci = {};
1911 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1912 dsvci.image = image.handle();
1913 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1914 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1915 dsvci.subresourceRange.layerCount = 1;
1916 dsvci.subresourceRange.baseMipLevel = 0;
1917 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001918 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001919
Tony Barbourf92621a2016-05-02 14:28:12 -06001920 // Create a view with depth / stencil aspect for image with different usage
1921 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001922
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001923 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001924
1925 // Initialize buffer with TRANSFER_DST usage
1926 vk_testing::Buffer buffer;
1927 VkMemoryPropertyFlags reqs = 0;
1928 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1929 VkBufferImageCopy region = {};
1930 region.bufferRowLength = 128;
1931 region.bufferImageHeight = 128;
1932 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1933 region.imageSubresource.layerCount = 1;
1934 region.imageExtent.height = 16;
1935 region.imageExtent.width = 16;
1936 region.imageExtent.depth = 1;
1937
Tony Barbourf92621a2016-05-02 14:28:12 -06001938 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1939 // TRANSFER_DST
1940 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001941
Chris Forbesda581202016-10-06 18:25:26 +13001942 // two separate errors from this call:
1943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1945
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001946 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1947 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001948 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001949}
Tony Barbour75d79f02016-08-30 09:39:07 -06001950
Tony Barbour75d79f02016-08-30 09:39:07 -06001951
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001952#endif // MEM_TRACKER_TESTS
1953
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001954#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001955
1956TEST_F(VkLayerTest, LeakAnObject) {
1957 VkResult err;
1958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001959 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001960
1961 // Note that we have to create a new device since destroying the
1962 // framework's device causes Teardown() to fail and just calling Teardown
1963 // will destroy the errorMonitor.
1964
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001966
1967 ASSERT_NO_FATAL_FAILURE(InitState());
1968
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001969 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001970 std::vector<VkDeviceQueueCreateInfo> queue_info;
1971 queue_info.reserve(queue_props.size());
1972 std::vector<std::vector<float>> queue_priorities;
1973 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
1974 VkDeviceQueueCreateInfo qi = {};
1975 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
1976 qi.pNext = NULL;
1977 qi.queueFamilyIndex = i;
1978 qi.queueCount = queue_props[i].queueCount;
1979 queue_priorities.emplace_back(qi.queueCount, 0.0f);
1980 qi.pQueuePriorities = queue_priorities[i].data();
1981 queue_info.push_back(qi);
1982 }
1983
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001984 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001985
1986 // The sacrificial device object
1987 VkDevice testDevice;
1988 VkDeviceCreateInfo device_create_info = {};
1989 auto features = m_device->phy().features();
1990 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
1991 device_create_info.pNext = NULL;
1992 device_create_info.queueCreateInfoCount = queue_info.size();
1993 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06001994 device_create_info.enabledLayerCount = 0;
1995 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001996 device_create_info.pEnabledFeatures = &features;
1997 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
1998 ASSERT_VK_SUCCESS(err);
1999
2000 VkFence fence;
2001 VkFenceCreateInfo fence_create_info = {};
2002 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2003 fence_create_info.pNext = NULL;
2004 fence_create_info.flags = 0;
2005 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2006 ASSERT_VK_SUCCESS(err);
2007
2008 // Induce failure by not calling vkDestroyFence
2009 vkDestroyDevice(testDevice, NULL);
2010 m_errorMonitor->VerifyFound();
2011}
2012
2013TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2014
2015 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2016 "attempt to delete them from another.");
2017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002019
Cody Northropc31a84f2016-08-22 10:41:47 -06002020 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002021 VkCommandPool command_pool_one;
2022 VkCommandPool command_pool_two;
2023
2024 VkCommandPoolCreateInfo pool_create_info{};
2025 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2026 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2027 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2028
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002029 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002030
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002031 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002032
2033 VkCommandBuffer command_buffer[9];
2034 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002035 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002036 command_buffer_allocate_info.commandPool = command_pool_one;
2037 command_buffer_allocate_info.commandBufferCount = 9;
2038 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002039 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002040
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002041 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002042
2043 m_errorMonitor->VerifyFound();
2044
2045 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2046 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2047}
2048
2049TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2050 VkResult err;
2051
2052 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002053 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002054
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002056
2057 ASSERT_NO_FATAL_FAILURE(InitState());
2058 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2059
2060 VkDescriptorPoolSize ds_type_count = {};
2061 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2062 ds_type_count.descriptorCount = 1;
2063
2064 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2065 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2066 ds_pool_ci.pNext = NULL;
2067 ds_pool_ci.flags = 0;
2068 ds_pool_ci.maxSets = 1;
2069 ds_pool_ci.poolSizeCount = 1;
2070 ds_pool_ci.pPoolSizes = &ds_type_count;
2071
2072 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002073 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002074 ASSERT_VK_SUCCESS(err);
2075
2076 // Create a second descriptor pool
2077 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002078 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002079 ASSERT_VK_SUCCESS(err);
2080
2081 VkDescriptorSetLayoutBinding dsl_binding = {};
2082 dsl_binding.binding = 0;
2083 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2084 dsl_binding.descriptorCount = 1;
2085 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2086 dsl_binding.pImmutableSamplers = NULL;
2087
2088 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2089 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2090 ds_layout_ci.pNext = NULL;
2091 ds_layout_ci.bindingCount = 1;
2092 ds_layout_ci.pBindings = &dsl_binding;
2093
2094 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002095 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002096 ASSERT_VK_SUCCESS(err);
2097
2098 VkDescriptorSet descriptorSet;
2099 VkDescriptorSetAllocateInfo alloc_info = {};
2100 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2101 alloc_info.descriptorSetCount = 1;
2102 alloc_info.descriptorPool = ds_pool_one;
2103 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002104 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002105 ASSERT_VK_SUCCESS(err);
2106
2107 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2108
2109 m_errorMonitor->VerifyFound();
2110
2111 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2112 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2113 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2114}
2115
2116TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002118
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002119 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002120
2121 ASSERT_NO_FATAL_FAILURE(InitState());
2122
2123 // Pass bogus handle into GetImageMemoryRequirements
2124 VkMemoryRequirements mem_reqs;
2125 uint64_t fakeImageHandle = 0xCADECADE;
2126 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2127
2128 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2129
2130 m_errorMonitor->VerifyFound();
2131}
2132
Karl Schultz6addd812016-02-02 17:17:23 -07002133TEST_F(VkLayerTest, PipelineNotBound) {
2134 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002135
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002136 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002137
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002139
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002140 ASSERT_NO_FATAL_FAILURE(InitState());
2141 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002142
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002143 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002144 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2145 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002146
2147 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002148 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2149 ds_pool_ci.pNext = NULL;
2150 ds_pool_ci.maxSets = 1;
2151 ds_pool_ci.poolSizeCount = 1;
2152 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002153
2154 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002155 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002156 ASSERT_VK_SUCCESS(err);
2157
2158 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002159 dsl_binding.binding = 0;
2160 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2161 dsl_binding.descriptorCount = 1;
2162 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2163 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002164
2165 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002166 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2167 ds_layout_ci.pNext = NULL;
2168 ds_layout_ci.bindingCount = 1;
2169 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002170
2171 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002172 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002173 ASSERT_VK_SUCCESS(err);
2174
2175 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002176 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002177 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002178 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002179 alloc_info.descriptorPool = ds_pool;
2180 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002181 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002182 ASSERT_VK_SUCCESS(err);
2183
2184 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002185 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2186 pipeline_layout_ci.pNext = NULL;
2187 pipeline_layout_ci.setLayoutCount = 1;
2188 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002189
2190 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002191 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002192 ASSERT_VK_SUCCESS(err);
2193
Mark Youngad779052016-01-06 14:26:04 -07002194 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002195
2196 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002197 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002198
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002199 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002200
Chia-I Wuf7458c52015-10-26 21:10:41 +08002201 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2202 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2203 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002204}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002205
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002206TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2207 VkResult err;
2208
2209 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2210 "during bind[Buffer|Image]Memory time");
2211
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002212 ASSERT_NO_FATAL_FAILURE(InitState());
2213
2214 // Create an image, allocate memory, set a bad typeIndex and then try to
2215 // bind it
2216 VkImage image;
2217 VkDeviceMemory mem;
2218 VkMemoryRequirements mem_reqs;
2219 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2220 const int32_t tex_width = 32;
2221 const int32_t tex_height = 32;
2222
2223 VkImageCreateInfo image_create_info = {};
2224 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2225 image_create_info.pNext = NULL;
2226 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2227 image_create_info.format = tex_format;
2228 image_create_info.extent.width = tex_width;
2229 image_create_info.extent.height = tex_height;
2230 image_create_info.extent.depth = 1;
2231 image_create_info.mipLevels = 1;
2232 image_create_info.arrayLayers = 1;
2233 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2234 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2235 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2236 image_create_info.flags = 0;
2237
2238 VkMemoryAllocateInfo mem_alloc = {};
2239 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2240 mem_alloc.pNext = NULL;
2241 mem_alloc.allocationSize = 0;
2242 mem_alloc.memoryTypeIndex = 0;
2243
2244 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2245 ASSERT_VK_SUCCESS(err);
2246
2247 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2248 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002249
2250 // Introduce Failure, select invalid TypeIndex
2251 VkPhysicalDeviceMemoryProperties memory_info;
2252
2253 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2254 unsigned int i;
2255 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2256 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2257 mem_alloc.memoryTypeIndex = i;
2258 break;
2259 }
2260 }
2261 if (i >= memory_info.memoryTypeCount) {
2262 printf("No invalid memory type index could be found; skipped.\n");
2263 vkDestroyImage(m_device->device(), image, NULL);
2264 return;
2265 }
2266
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002267 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 -06002268
2269 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2270 ASSERT_VK_SUCCESS(err);
2271
2272 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2273 (void)err;
2274
2275 m_errorMonitor->VerifyFound();
2276
2277 vkDestroyImage(m_device->device(), image, NULL);
2278 vkFreeMemory(m_device->device(), mem, NULL);
2279}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002280
Karl Schultz6addd812016-02-02 17:17:23 -07002281TEST_F(VkLayerTest, BindInvalidMemory) {
2282 VkResult err;
2283 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002284
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002286
Tobin Ehlisec598302015-09-15 15:02:17 -06002287 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002288
2289 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002290 VkImage image;
2291 VkDeviceMemory mem;
2292 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002293
Karl Schultz6addd812016-02-02 17:17:23 -07002294 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2295 const int32_t tex_width = 32;
2296 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002297
2298 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002299 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2300 image_create_info.pNext = NULL;
2301 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2302 image_create_info.format = tex_format;
2303 image_create_info.extent.width = tex_width;
2304 image_create_info.extent.height = tex_height;
2305 image_create_info.extent.depth = 1;
2306 image_create_info.mipLevels = 1;
2307 image_create_info.arrayLayers = 1;
2308 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2309 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2310 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2311 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002312
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002313 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002314 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2315 mem_alloc.pNext = NULL;
2316 mem_alloc.allocationSize = 0;
2317 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002318
Chia-I Wuf7458c52015-10-26 21:10:41 +08002319 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002320 ASSERT_VK_SUCCESS(err);
2321
Karl Schultz6addd812016-02-02 17:17:23 -07002322 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002323
2324 mem_alloc.allocationSize = mem_reqs.size;
2325
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002326 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002327 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002328
2329 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002330 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002331 ASSERT_VK_SUCCESS(err);
2332
2333 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002334 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002335
2336 // Try to bind free memory that has been freed
2337 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2338 // This may very well return an error.
2339 (void)err;
2340
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002341 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002342
Chia-I Wuf7458c52015-10-26 21:10:41 +08002343 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002344}
2345
Karl Schultz6addd812016-02-02 17:17:23 -07002346TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2347 VkResult err;
2348 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002349
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002351
Tobin Ehlisec598302015-09-15 15:02:17 -06002352 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002353
Karl Schultz6addd812016-02-02 17:17:23 -07002354 // Create an image object, allocate memory, destroy the object and then try
2355 // to bind it
2356 VkImage image;
2357 VkDeviceMemory mem;
2358 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002359
Karl Schultz6addd812016-02-02 17:17:23 -07002360 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2361 const int32_t tex_width = 32;
2362 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002363
2364 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002365 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2366 image_create_info.pNext = NULL;
2367 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2368 image_create_info.format = tex_format;
2369 image_create_info.extent.width = tex_width;
2370 image_create_info.extent.height = tex_height;
2371 image_create_info.extent.depth = 1;
2372 image_create_info.mipLevels = 1;
2373 image_create_info.arrayLayers = 1;
2374 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2375 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2376 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2377 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002378
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002379 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002380 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2381 mem_alloc.pNext = NULL;
2382 mem_alloc.allocationSize = 0;
2383 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002384
Chia-I Wuf7458c52015-10-26 21:10:41 +08002385 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002386 ASSERT_VK_SUCCESS(err);
2387
Karl Schultz6addd812016-02-02 17:17:23 -07002388 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002389
2390 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002391 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002392 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002393
2394 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002395 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002396 ASSERT_VK_SUCCESS(err);
2397
2398 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002399 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002400 ASSERT_VK_SUCCESS(err);
2401
2402 // Now Try to bind memory to this destroyed object
2403 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2404 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002405 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002406
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002407 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002408
Chia-I Wuf7458c52015-10-26 21:10:41 +08002409 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002410}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002411
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002412#endif // OBJ_TRACKER_TESTS
2413
Tobin Ehlis0788f522015-05-26 16:11:58 -06002414#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002415
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002416TEST_F(VkLayerTest, ImageSampleCounts) {
2417
2418 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2419 "validation errors.");
2420 ASSERT_NO_FATAL_FAILURE(InitState());
2421
2422 VkMemoryPropertyFlags reqs = 0;
2423 VkImageCreateInfo image_create_info = {};
2424 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2425 image_create_info.pNext = NULL;
2426 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2427 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2428 image_create_info.extent.width = 256;
2429 image_create_info.extent.height = 256;
2430 image_create_info.extent.depth = 1;
2431 image_create_info.mipLevels = 1;
2432 image_create_info.arrayLayers = 1;
2433 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2434 image_create_info.flags = 0;
2435
2436 VkImageBlit blit_region = {};
2437 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2438 blit_region.srcSubresource.baseArrayLayer = 0;
2439 blit_region.srcSubresource.layerCount = 1;
2440 blit_region.srcSubresource.mipLevel = 0;
2441 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2442 blit_region.dstSubresource.baseArrayLayer = 0;
2443 blit_region.dstSubresource.layerCount = 1;
2444 blit_region.dstSubresource.mipLevel = 0;
2445
2446 // Create two images, the source with sampleCount = 2, and attempt to blit
2447 // between them
2448 {
2449 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002450 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002451 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002452 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002453 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002454 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002455 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002456 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002457 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2459 "of VK_SAMPLE_COUNT_2_BIT but "
2460 "must be VK_SAMPLE_COUNT_1_BIT");
2461 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2462 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002463 m_errorMonitor->VerifyFound();
2464 m_commandBuffer->EndCommandBuffer();
2465 }
2466
2467 // Create two images, the dest with sampleCount = 4, and attempt to blit
2468 // between them
2469 {
2470 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002471 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002472 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002473 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002474 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002475 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002476 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002477 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002478 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2480 "of VK_SAMPLE_COUNT_4_BIT but "
2481 "must be VK_SAMPLE_COUNT_1_BIT");
2482 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2483 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002484 m_errorMonitor->VerifyFound();
2485 m_commandBuffer->EndCommandBuffer();
2486 }
2487
2488 VkBufferImageCopy copy_region = {};
2489 copy_region.bufferRowLength = 128;
2490 copy_region.bufferImageHeight = 128;
2491 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2492 copy_region.imageSubresource.layerCount = 1;
2493 copy_region.imageExtent.height = 64;
2494 copy_region.imageExtent.width = 64;
2495 copy_region.imageExtent.depth = 1;
2496
2497 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2498 // buffer to image
2499 {
2500 vk_testing::Buffer src_buffer;
2501 VkMemoryPropertyFlags reqs = 0;
2502 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2503 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002504 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002505 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002506 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002507 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2509 "of VK_SAMPLE_COUNT_8_BIT but "
2510 "must be VK_SAMPLE_COUNT_1_BIT");
2511 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2512 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002513 m_errorMonitor->VerifyFound();
2514 m_commandBuffer->EndCommandBuffer();
2515 }
2516
2517 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2518 // image to buffer
2519 {
2520 vk_testing::Buffer dst_buffer;
2521 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2522 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002523 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002524 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002525 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002526 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2528 "of VK_SAMPLE_COUNT_2_BIT but "
2529 "must be VK_SAMPLE_COUNT_1_BIT");
2530 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002531 dst_buffer.handle(), 1, &copy_region);
2532 m_errorMonitor->VerifyFound();
2533 m_commandBuffer->EndCommandBuffer();
2534 }
2535}
2536
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002537TEST_F(VkLayerTest, BlitImageFormats) {
2538
2539 // Image blit with mismatched formats
2540 const char * expected_message =
2541 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2542 " the other one must also have signed/unsigned integer format";
2543
2544 ASSERT_NO_FATAL_FAILURE(InitState());
2545
2546 VkImageObj src_image(m_device);
2547 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2548 VkImageObj dst_image(m_device);
2549 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2550 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002551 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 -06002552
2553 VkImageBlit blitRegion = {};
2554 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2555 blitRegion.srcSubresource.baseArrayLayer = 0;
2556 blitRegion.srcSubresource.layerCount = 1;
2557 blitRegion.srcSubresource.mipLevel = 0;
2558 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2559 blitRegion.dstSubresource.baseArrayLayer = 0;
2560 blitRegion.dstSubresource.layerCount = 1;
2561 blitRegion.dstSubresource.mipLevel = 0;
2562
2563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2564
2565 // Unsigned int vs not an int
2566 BeginCommandBuffer();
2567 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2568 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2569
2570 m_errorMonitor->VerifyFound();
2571
2572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2573
2574 // Unsigned int vs signed int
2575 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2576 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2577
2578 m_errorMonitor->VerifyFound();
2579
2580 EndCommandBuffer();
2581}
2582
2583
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002584TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2585 VkResult err;
2586 bool pass;
2587
2588 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2589 ASSERT_NO_FATAL_FAILURE(InitState());
2590
2591 // If w/d/h granularity is 1, test is not meaningful
2592 // TODO: When virtual device limits are available, create a set of limits for this test that
2593 // will always have a granularity of > 1 for w, h, and d
2594 auto index = m_device->graphics_queue_node_index_;
2595 auto queue_family_properties = m_device->phy().queue_properties();
2596
2597 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2598 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2599 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2600 return;
2601 }
2602
2603 // Create two images of different types and try to copy between them
2604 VkImage srcImage;
2605 VkImage dstImage;
2606 VkDeviceMemory srcMem;
2607 VkDeviceMemory destMem;
2608 VkMemoryRequirements memReqs;
2609
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002610 VkImageCreateInfo image_create_info = {};
2611 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2612 image_create_info.pNext = NULL;
2613 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2614 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2615 image_create_info.extent.width = 32;
2616 image_create_info.extent.height = 32;
2617 image_create_info.extent.depth = 1;
2618 image_create_info.mipLevels = 1;
2619 image_create_info.arrayLayers = 4;
2620 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2621 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2622 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2623 image_create_info.flags = 0;
2624
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002625 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002626 ASSERT_VK_SUCCESS(err);
2627
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002628 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002629 ASSERT_VK_SUCCESS(err);
2630
2631 // Allocate memory
2632 VkMemoryAllocateInfo memAlloc = {};
2633 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2634 memAlloc.pNext = NULL;
2635 memAlloc.allocationSize = 0;
2636 memAlloc.memoryTypeIndex = 0;
2637
2638 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2639 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002640 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002641 ASSERT_TRUE(pass);
2642 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2643 ASSERT_VK_SUCCESS(err);
2644
2645 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2646 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002647 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002648 ASSERT_VK_SUCCESS(err);
2649 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2650 ASSERT_VK_SUCCESS(err);
2651
2652 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2653 ASSERT_VK_SUCCESS(err);
2654 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2655 ASSERT_VK_SUCCESS(err);
2656
2657 BeginCommandBuffer();
2658 VkImageCopy copyRegion;
2659 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2660 copyRegion.srcSubresource.mipLevel = 0;
2661 copyRegion.srcSubresource.baseArrayLayer = 0;
2662 copyRegion.srcSubresource.layerCount = 1;
2663 copyRegion.srcOffset.x = 0;
2664 copyRegion.srcOffset.y = 0;
2665 copyRegion.srcOffset.z = 0;
2666 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2667 copyRegion.dstSubresource.mipLevel = 0;
2668 copyRegion.dstSubresource.baseArrayLayer = 0;
2669 copyRegion.dstSubresource.layerCount = 1;
2670 copyRegion.dstOffset.x = 0;
2671 copyRegion.dstOffset.y = 0;
2672 copyRegion.dstOffset.z = 0;
2673 copyRegion.extent.width = 1;
2674 copyRegion.extent.height = 1;
2675 copyRegion.extent.depth = 1;
2676
2677 // Introduce failure by setting srcOffset to a bad granularity value
2678 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2680 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002681 m_errorMonitor->VerifyFound();
2682
2683 // Introduce failure by setting extent to a bad granularity value
2684 copyRegion.srcOffset.y = 0;
2685 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2687 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002688 m_errorMonitor->VerifyFound();
2689
2690 // Now do some buffer/image copies
2691 vk_testing::Buffer buffer;
2692 VkMemoryPropertyFlags reqs = 0;
2693 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2694 VkBufferImageCopy region = {};
2695 region.bufferOffset = 0;
2696 region.bufferRowLength = 3;
2697 region.bufferImageHeight = 128;
2698 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2699 region.imageSubresource.layerCount = 1;
2700 region.imageExtent.height = 16;
2701 region.imageExtent.width = 16;
2702 region.imageExtent.depth = 1;
2703 region.imageOffset.x = 0;
2704 region.imageOffset.y = 0;
2705 region.imageOffset.z = 0;
2706
2707 // Introduce failure by setting bufferRowLength to a bad granularity value
2708 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2710 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2711 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002712 m_errorMonitor->VerifyFound();
2713 region.bufferRowLength = 128;
2714
2715 // Introduce failure by setting bufferOffset to a bad granularity value
2716 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2718 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2719 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002720 m_errorMonitor->VerifyFound();
2721 region.bufferOffset = 0;
2722
2723 // Introduce failure by setting bufferImageHeight to a bad granularity value
2724 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2726 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2727 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002728 m_errorMonitor->VerifyFound();
2729 region.bufferImageHeight = 128;
2730
2731 // Introduce failure by setting imageExtent to a bad granularity value
2732 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2734 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2735 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002736 m_errorMonitor->VerifyFound();
2737 region.imageExtent.width = 16;
2738
2739 // Introduce failure by setting imageOffset to a bad granularity value
2740 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2742 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2743 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002744 m_errorMonitor->VerifyFound();
2745
2746 EndCommandBuffer();
2747
2748 vkDestroyImage(m_device->device(), srcImage, NULL);
2749 vkDestroyImage(m_device->device(), dstImage, NULL);
2750 vkFreeMemory(m_device->device(), srcMem, NULL);
2751 vkFreeMemory(m_device->device(), destMem, NULL);
2752}
2753
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002754TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002755 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2756 "attempt to submit them on a queue created in a different "
2757 "queue family.");
2758
Cody Northropc31a84f2016-08-22 10:41:47 -06002759 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002760 // This test is meaningless unless we have multiple queue families
2761 auto queue_family_properties = m_device->phy().queue_properties();
2762 if (queue_family_properties.size() < 2) {
2763 return;
2764 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002766 // Get safe index of another queue family
2767 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2768 ASSERT_NO_FATAL_FAILURE(InitState());
2769 // Create a second queue using a different queue family
2770 VkQueue other_queue;
2771 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2772
2773 // Record an empty cmd buffer
2774 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2775 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2776 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2777 vkEndCommandBuffer(m_commandBuffer->handle());
2778
2779 // And submit on the wrong queue
2780 VkSubmitInfo submit_info = {};
2781 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2782 submit_info.commandBufferCount = 1;
2783 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002784 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002785
2786 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002787}
2788
Chris Forbesa58c4522016-09-28 15:19:39 +13002789TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2790 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2791 ASSERT_NO_FATAL_FAILURE(InitState());
2792
2793 // A renderpass with two subpasses, both writing the same attachment.
2794 VkAttachmentDescription attach[] = {
2795 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2796 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2797 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2798 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2799 },
2800 };
2801 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2802 VkSubpassDescription subpasses[] = {
2803 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2804 1, &ref, nullptr, nullptr, 0, nullptr },
2805 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2806 1, &ref, nullptr, nullptr, 0, nullptr },
2807 };
2808 VkSubpassDependency dep = {
2809 0, 1,
2810 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2811 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2812 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2813 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2814 VK_DEPENDENCY_BY_REGION_BIT
2815 };
2816 VkRenderPassCreateInfo rpci = {
2817 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2818 0, 1, attach, 2, subpasses, 1, &dep
2819 };
2820 VkRenderPass rp;
2821 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2822 ASSERT_VK_SUCCESS(err);
2823
2824 VkImageObj image(m_device);
2825 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2826 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2827 VK_IMAGE_TILING_OPTIMAL, 0);
2828 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2829
2830 VkFramebufferCreateInfo fbci = {
2831 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2832 0, rp, 1, &imageView, 32, 32, 1
2833 };
2834 VkFramebuffer fb;
2835 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2836 ASSERT_VK_SUCCESS(err);
2837
2838 char const *vsSource =
2839 "#version 450\n"
2840 "void main() { gl_Position = vec4(1); }\n";
2841 char const *fsSource =
2842 "#version 450\n"
2843 "layout(location=0) out vec4 color;\n"
2844 "void main() { color = vec4(1); }\n";
2845
2846 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2847 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2848 VkPipelineObj pipe(m_device);
2849 pipe.AddColorAttachment();
2850 pipe.AddShader(&vs);
2851 pipe.AddShader(&fs);
2852 VkViewport view_port = {};
2853 m_viewports.push_back(view_port);
2854 pipe.SetViewport(m_viewports);
2855 VkRect2D rect = {};
2856 m_scissors.push_back(rect);
2857 pipe.SetScissor(m_scissors);
2858
2859 VkPipelineLayoutCreateInfo plci = {
2860 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2861 0, 0, nullptr, 0, nullptr
2862 };
2863 VkPipelineLayout pl;
2864 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2865 ASSERT_VK_SUCCESS(err);
2866 pipe.CreateVKPipeline(pl, rp);
2867
2868 BeginCommandBuffer();
2869
2870 VkRenderPassBeginInfo rpbi = {
2871 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2872 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
2873 };
2874
2875 // subtest 1: bind in the wrong subpass
2876 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2877 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2879 "built for subpass 0 but used in subpass 1");
2880 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2881 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2882 m_errorMonitor->VerifyFound();
2883
2884 vkCmdEndRenderPass(m_commandBuffer->handle());
2885
2886 // subtest 2: bind in correct subpass, then transition to next subpass
2887 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2888 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2889 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2891 "built for subpass 0 but used in subpass 1");
2892 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2893 m_errorMonitor->VerifyFound();
2894
2895 vkCmdEndRenderPass(m_commandBuffer->handle());
2896
2897 EndCommandBuffer();
2898
2899 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
2900 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
2901 vkDestroyRenderPass(m_device->device(), rp, nullptr);
2902}
2903
Tony Barbour4e919972016-08-09 13:27:40 -06002904TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
2905 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
2906 "with extent outside of framebuffer");
2907 ASSERT_NO_FATAL_FAILURE(InitState());
2908 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2909
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
2911 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06002912
2913 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
2914 m_renderPassBeginInfo.renderArea.extent.width = 257;
2915 m_renderPassBeginInfo.renderArea.extent.height = 257;
2916 BeginCommandBuffer();
2917 m_errorMonitor->VerifyFound();
2918}
2919
2920TEST_F(VkLayerTest, DisabledIndependentBlend) {
2921 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
2922 "blend and then specifying different blend states for two "
2923 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06002924 VkPhysicalDeviceFeatures features = {};
2925 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06002926 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06002927
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2929 "Invalid Pipeline CreateInfo: If independent blend feature not "
2930 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06002931
Cody Northropc31a84f2016-08-22 10:41:47 -06002932 VkDescriptorSetObj descriptorSet(m_device);
2933 descriptorSet.AppendDummy();
2934 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06002935
Cody Northropc31a84f2016-08-22 10:41:47 -06002936 VkPipelineObj pipeline(m_device);
2937 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002938 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06002939 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06002940
Cody Northropc31a84f2016-08-22 10:41:47 -06002941 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
2942 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
2943 att_state1.blendEnable = VK_TRUE;
2944 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
2945 att_state2.blendEnable = VK_FALSE;
2946 pipeline.AddColorAttachment(0, &att_state1);
2947 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002948 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06002949 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06002950}
2951
2952TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
2953 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
2954 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06002955 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06002956
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2958 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06002959
2960 // Create a renderPass with a single color attachment
2961 VkAttachmentReference attach = {};
2962 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2963 VkSubpassDescription subpass = {};
2964 VkRenderPassCreateInfo rpci = {};
2965 rpci.subpassCount = 1;
2966 rpci.pSubpasses = &subpass;
2967 rpci.attachmentCount = 1;
2968 VkAttachmentDescription attach_desc = {};
2969 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
2970 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
2971 rpci.pAttachments = &attach_desc;
2972 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
2973 VkRenderPass rp;
2974 subpass.pDepthStencilAttachment = &attach;
2975 subpass.pColorAttachments = NULL;
2976 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
2977 m_errorMonitor->VerifyFound();
2978}
2979
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06002980TEST_F(VkLayerTest, UnusedPreserveAttachment) {
2981 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
2982 "attachment reference of VK_ATTACHMENT_UNUSED");
2983
2984 ASSERT_NO_FATAL_FAILURE(InitState());
2985 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2986
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06002988
2989 VkAttachmentReference color_attach = {};
2990 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
2991 color_attach.attachment = 0;
2992 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
2993 VkSubpassDescription subpass = {};
2994 subpass.colorAttachmentCount = 1;
2995 subpass.pColorAttachments = &color_attach;
2996 subpass.preserveAttachmentCount = 1;
2997 subpass.pPreserveAttachments = &preserve_attachment;
2998
2999 VkRenderPassCreateInfo rpci = {};
3000 rpci.subpassCount = 1;
3001 rpci.pSubpasses = &subpass;
3002 rpci.attachmentCount = 1;
3003 VkAttachmentDescription attach_desc = {};
3004 attach_desc.format = VK_FORMAT_UNDEFINED;
3005 rpci.pAttachments = &attach_desc;
3006 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3007 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003008 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003009
3010 m_errorMonitor->VerifyFound();
3011
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003012 if (result == VK_SUCCESS) {
3013 vkDestroyRenderPass(m_device->device(), rp, NULL);
3014 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003015}
3016
Chris Forbesc5389742016-06-29 11:49:23 +12003017TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003018 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3019 "when the source of a subpass multisample resolve "
3020 "does not have multiple samples.");
3021
Chris Forbesc5389742016-06-29 11:49:23 +12003022 ASSERT_NO_FATAL_FAILURE(InitState());
3023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3025 "Subpass 0 requests multisample resolve from attachment 0 which has "
3026 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003027
3028 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003029 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3030 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3031 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3032 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3033 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3034 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003035 };
3036
3037 VkAttachmentReference color = {
3038 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3039 };
3040
3041 VkAttachmentReference resolve = {
3042 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3043 };
3044
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003045 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003046
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003047 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003048
3049 VkRenderPass rp;
3050 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3051
3052 m_errorMonitor->VerifyFound();
3053
3054 if (err == VK_SUCCESS)
3055 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3056}
3057
3058TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003059 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3060 "when a subpass multisample resolve operation is "
3061 "requested, and the destination of that resolve has "
3062 "multiple samples.");
3063
Chris Forbesc5389742016-06-29 11:49:23 +12003064 ASSERT_NO_FATAL_FAILURE(InitState());
3065
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3067 "Subpass 0 requests multisample resolve into attachment 1, which "
3068 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003069
3070 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003071 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3072 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3073 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3074 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3075 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3076 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003077 };
3078
3079 VkAttachmentReference color = {
3080 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3081 };
3082
3083 VkAttachmentReference resolve = {
3084 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3085 };
3086
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003087 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003088
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003089 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003090
3091 VkRenderPass rp;
3092 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3093
3094 m_errorMonitor->VerifyFound();
3095
3096 if (err == VK_SUCCESS)
3097 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3098}
3099
Chris Forbes3f128ef2016-06-29 14:58:53 +12003100TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003101 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3102 "when the color and depth attachments used by a subpass "
3103 "have inconsistent sample counts");
3104
Chris Forbes3f128ef2016-06-29 14:58:53 +12003105 ASSERT_NO_FATAL_FAILURE(InitState());
3106
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3108 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003109
3110 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003111 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3112 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3113 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3114 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3115 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3116 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003117 };
3118
3119 VkAttachmentReference color[] = {
3120 {
3121 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3122 },
3123 {
3124 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3125 },
3126 };
3127
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003128 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003129
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003130 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003131
3132 VkRenderPass rp;
3133 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3134
3135 m_errorMonitor->VerifyFound();
3136
3137 if (err == VK_SUCCESS)
3138 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3139}
3140
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003141TEST_F(VkLayerTest, FramebufferCreateErrors) {
3142 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003143 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003144 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003145 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3146 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3147 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3148 " 6. Framebuffer attachment where dimensions don't match\n"
3149 " 7. Framebuffer attachment w/o identity swizzle\n"
3150 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003151
3152 ASSERT_NO_FATAL_FAILURE(InitState());
3153 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3154
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3156 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3157 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003158
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003159 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003160 VkAttachmentReference attach = {};
3161 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3162 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003163 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003164 VkRenderPassCreateInfo rpci = {};
3165 rpci.subpassCount = 1;
3166 rpci.pSubpasses = &subpass;
3167 rpci.attachmentCount = 1;
3168 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003169 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003170 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003171 rpci.pAttachments = &attach_desc;
3172 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3173 VkRenderPass rp;
3174 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3175 ASSERT_VK_SUCCESS(err);
3176
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003177 VkImageView ivs[2];
3178 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3179 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003180 VkFramebufferCreateInfo fb_info = {};
3181 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3182 fb_info.pNext = NULL;
3183 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003184 // Set mis-matching attachmentCount
3185 fb_info.attachmentCount = 2;
3186 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003187 fb_info.width = 100;
3188 fb_info.height = 100;
3189 fb_info.layers = 1;
3190
3191 VkFramebuffer fb;
3192 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3193
3194 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003195 if (err == VK_SUCCESS) {
3196 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3197 }
3198 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003199
3200 // Create a renderPass with a depth-stencil attachment created with
3201 // IMAGE_USAGE_COLOR_ATTACHMENT
3202 // Add our color attachment to pDepthStencilAttachment
3203 subpass.pDepthStencilAttachment = &attach;
3204 subpass.pColorAttachments = NULL;
3205 VkRenderPass rp_ds;
3206 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3207 ASSERT_VK_SUCCESS(err);
3208 // Set correct attachment count, but attachment has COLOR usage bit set
3209 fb_info.attachmentCount = 1;
3210 fb_info.renderPass = rp_ds;
3211
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003213 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3214
3215 m_errorMonitor->VerifyFound();
3216 if (err == VK_SUCCESS) {
3217 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3218 }
3219 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003220
3221 // Create new renderpass with alternate attachment format from fb
3222 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3223 subpass.pDepthStencilAttachment = NULL;
3224 subpass.pColorAttachments = &attach;
3225 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3226 ASSERT_VK_SUCCESS(err);
3227
3228 // Cause error due to mis-matched formats between rp & fb
3229 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3230 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3232 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003233 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3234
3235 m_errorMonitor->VerifyFound();
3236 if (err == VK_SUCCESS) {
3237 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3238 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003239 vkDestroyRenderPass(m_device->device(), rp, NULL);
3240
3241 // Create new renderpass with alternate sample count from fb
3242 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3243 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3244 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3245 ASSERT_VK_SUCCESS(err);
3246
3247 // Cause error due to mis-matched sample count between rp & fb
3248 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3250 "that do not match the "
3251 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003252 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3253
3254 m_errorMonitor->VerifyFound();
3255 if (err == VK_SUCCESS) {
3256 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3257 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003258
3259 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003260
3261 // Create a custom imageView with non-1 mip levels
3262 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003263 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 -06003264 ASSERT_TRUE(image.initialized());
3265
3266 VkImageView view;
3267 VkImageViewCreateInfo ivci = {};
3268 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3269 ivci.image = image.handle();
3270 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3271 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3272 ivci.subresourceRange.layerCount = 1;
3273 ivci.subresourceRange.baseMipLevel = 0;
3274 // Set level count 2 (only 1 is allowed for FB attachment)
3275 ivci.subresourceRange.levelCount = 2;
3276 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3277 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3278 ASSERT_VK_SUCCESS(err);
3279 // Re-create renderpass to have matching sample count
3280 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3281 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3282 ASSERT_VK_SUCCESS(err);
3283
3284 fb_info.renderPass = rp;
3285 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003287 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3288
3289 m_errorMonitor->VerifyFound();
3290 if (err == VK_SUCCESS) {
3291 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3292 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003293 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003294 // Update view to original color buffer and grow FB dimensions too big
3295 fb_info.pAttachments = ivs;
3296 fb_info.height = 1024;
3297 fb_info.width = 1024;
3298 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3300 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003301 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3302
3303 m_errorMonitor->VerifyFound();
3304 if (err == VK_SUCCESS) {
3305 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3306 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003307 // Create view attachment with non-identity swizzle
3308 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3309 ivci.image = image.handle();
3310 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3311 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3312 ivci.subresourceRange.layerCount = 1;
3313 ivci.subresourceRange.baseMipLevel = 0;
3314 ivci.subresourceRange.levelCount = 1;
3315 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3316 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3317 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3318 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3319 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3320 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3321 ASSERT_VK_SUCCESS(err);
3322
3323 fb_info.pAttachments = &view;
3324 fb_info.height = 100;
3325 fb_info.width = 100;
3326 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3328 "framebuffer attachments must have "
3329 "been created with the identity "
3330 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003331 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3332
3333 m_errorMonitor->VerifyFound();
3334 if (err == VK_SUCCESS) {
3335 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3336 }
3337 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003338 // Request fb that exceeds max dimensions
3339 // reset attachment to color attachment
3340 fb_info.pAttachments = ivs;
3341 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3342 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3343 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3345 "dimensions exceed physical device "
3346 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003347 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3348
3349 m_errorMonitor->VerifyFound();
3350 if (err == VK_SUCCESS) {
3351 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3352 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003353
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003354 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003355}
3356
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003357TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003358 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3359 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003360
Cody Northropc31a84f2016-08-22 10:41:47 -06003361 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003362 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3364 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003365 m_errorMonitor->VerifyFound();
3366}
3367
3368TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003369 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3370 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003371
Cody Northropc31a84f2016-08-22 10:41:47 -06003372 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003373 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3375 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003376 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003377}
3378
3379TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003380 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3381 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003382
Cody Northropc31a84f2016-08-22 10:41:47 -06003383 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003384 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003385 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 -06003386 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003387 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003388}
3389
3390TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003391 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3392 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003393
Cody Northropc31a84f2016-08-22 10:41:47 -06003394 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003395 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003396 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 -06003397 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003398 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003399}
3400
Cortd713fe82016-07-27 09:51:27 -07003401TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003402 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3403 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003404
3405 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003406 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3408 "Dynamic blend constants state not set for this command buffer");
3409 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003410 m_errorMonitor->VerifyFound();
3411}
3412
3413TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003414 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3415 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003416
3417 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003418 if (!m_device->phy().features().depthBounds) {
3419 printf("Device does not support depthBounds test; skipped.\n");
3420 return;
3421 }
3422 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3424 "Dynamic depth bounds state not set for this command buffer");
3425 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003426 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003427}
3428
3429TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003430 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3431 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003432
3433 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003434 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3436 "Dynamic stencil read mask state not set for this command buffer");
3437 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003438 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003439}
3440
3441TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003442 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3443 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003444
3445 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003446 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3448 "Dynamic stencil write mask state not set for this command buffer");
3449 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003450 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003451}
3452
3453TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003454 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3455 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003456
3457 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003458 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3460 "Dynamic stencil reference state not set for this command buffer");
3461 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003462 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003463}
3464
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003465TEST_F(VkLayerTest, IndexBufferNotBound) {
3466 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003467
3468 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3470 "Index buffer object not bound to this command buffer when Indexed ");
3471 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003472 m_errorMonitor->VerifyFound();
3473}
3474
Karl Schultz6addd812016-02-02 17:17:23 -07003475TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3477 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3478 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003479
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003480 ASSERT_NO_FATAL_FAILURE(InitState());
3481 ASSERT_NO_FATAL_FAILURE(InitViewport());
3482 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3483
Karl Schultz6addd812016-02-02 17:17:23 -07003484 // We luck out b/c by default the framework creates CB w/ the
3485 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003486 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003487 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003488 EndCommandBuffer();
3489
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003490 // Bypass framework since it does the waits automatically
3491 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003492 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003493 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3494 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003495 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003496 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003497 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003498 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003499 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003500 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003501 submit_info.pSignalSemaphores = NULL;
3502
Chris Forbes40028e22016-06-13 09:59:34 +12003503 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003504 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003505 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003506
Karl Schultz6addd812016-02-02 17:17:23 -07003507 // Cause validation error by re-submitting cmd buffer that should only be
3508 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003509 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003510 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003511
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003512 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003513}
3514
Karl Schultz6addd812016-02-02 17:17:23 -07003515TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003516 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07003517 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003518
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
3520 "type "
3521 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003522
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003523 ASSERT_NO_FATAL_FAILURE(InitState());
3524 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003525
Karl Schultz6addd812016-02-02 17:17:23 -07003526 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3527 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003528 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003529 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3530 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003531
3532 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003533 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3534 ds_pool_ci.pNext = NULL;
3535 ds_pool_ci.flags = 0;
3536 ds_pool_ci.maxSets = 1;
3537 ds_pool_ci.poolSizeCount = 1;
3538 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003539
3540 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003541 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003542 ASSERT_VK_SUCCESS(err);
3543
3544 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003545 dsl_binding.binding = 0;
3546 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3547 dsl_binding.descriptorCount = 1;
3548 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3549 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003550
3551 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003552 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3553 ds_layout_ci.pNext = NULL;
3554 ds_layout_ci.bindingCount = 1;
3555 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003556
3557 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003558 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003559 ASSERT_VK_SUCCESS(err);
3560
3561 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003562 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003563 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003564 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003565 alloc_info.descriptorPool = ds_pool;
3566 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003567 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003568
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003569 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003570
Chia-I Wuf7458c52015-10-26 21:10:41 +08003571 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3572 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003573}
3574
Karl Schultz6addd812016-02-02 17:17:23 -07003575TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3576 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003577
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3579 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3580 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003581
Tobin Ehlise735c692015-10-08 13:13:50 -06003582 ASSERT_NO_FATAL_FAILURE(InitState());
3583 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003584
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003585 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003586 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3587 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003588
3589 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003590 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3591 ds_pool_ci.pNext = NULL;
3592 ds_pool_ci.maxSets = 1;
3593 ds_pool_ci.poolSizeCount = 1;
3594 ds_pool_ci.flags = 0;
3595 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3596 // app can only call vkResetDescriptorPool on this pool.;
3597 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003598
3599 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003600 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003601 ASSERT_VK_SUCCESS(err);
3602
3603 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003604 dsl_binding.binding = 0;
3605 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3606 dsl_binding.descriptorCount = 1;
3607 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3608 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003609
3610 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003611 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3612 ds_layout_ci.pNext = NULL;
3613 ds_layout_ci.bindingCount = 1;
3614 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003615
3616 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003617 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003618 ASSERT_VK_SUCCESS(err);
3619
3620 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003621 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003622 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003623 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003624 alloc_info.descriptorPool = ds_pool;
3625 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003626 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003627 ASSERT_VK_SUCCESS(err);
3628
3629 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003630 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003631
Chia-I Wuf7458c52015-10-26 21:10:41 +08003632 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3633 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003634}
3635
Karl Schultz6addd812016-02-02 17:17:23 -07003636TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003637 // Attempt to clear Descriptor Pool with bad object.
3638 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003639
3640 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003642 uint64_t fake_pool_handle = 0xbaad6001;
3643 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3644 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003645 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003646}
3647
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003648TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003649 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3650 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003651 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003652 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003653
3654 uint64_t fake_set_handle = 0xbaad6001;
3655 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003656 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003658
3659 ASSERT_NO_FATAL_FAILURE(InitState());
3660
3661 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3662 layout_bindings[0].binding = 0;
3663 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3664 layout_bindings[0].descriptorCount = 1;
3665 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3666 layout_bindings[0].pImmutableSamplers = NULL;
3667
3668 VkDescriptorSetLayout descriptor_set_layout;
3669 VkDescriptorSetLayoutCreateInfo dslci = {};
3670 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3671 dslci.pNext = NULL;
3672 dslci.bindingCount = 1;
3673 dslci.pBindings = layout_bindings;
3674 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003675 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003676
3677 VkPipelineLayout pipeline_layout;
3678 VkPipelineLayoutCreateInfo plci = {};
3679 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3680 plci.pNext = NULL;
3681 plci.setLayoutCount = 1;
3682 plci.pSetLayouts = &descriptor_set_layout;
3683 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003684 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003685
3686 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003687 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3688 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003689 m_errorMonitor->VerifyFound();
3690 EndCommandBuffer();
3691 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3692 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003693}
3694
Karl Schultz6addd812016-02-02 17:17:23 -07003695TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003696 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3697 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003698 uint64_t fake_layout_handle = 0xbaad6001;
3699 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003701 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003702 VkPipelineLayout pipeline_layout;
3703 VkPipelineLayoutCreateInfo plci = {};
3704 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3705 plci.pNext = NULL;
3706 plci.setLayoutCount = 1;
3707 plci.pSetLayouts = &bad_layout;
3708 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3709
3710 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003711}
3712
Mark Muellerd4914412016-06-13 17:52:06 -06003713TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3714 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3715 "1) A uniform buffer update must have a valid buffer index."
3716 "2) When using an array of descriptors in a single WriteDescriptor,"
3717 " the descriptor types and stageflags must all be the same."
3718 "3) Immutable Sampler state must match across descriptors");
3719
3720 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003721 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3722 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3723 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3724 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3725 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003726
Mark Muellerd4914412016-06-13 17:52:06 -06003727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3728
3729 ASSERT_NO_FATAL_FAILURE(InitState());
3730 VkDescriptorPoolSize ds_type_count[4] = {};
3731 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3732 ds_type_count[0].descriptorCount = 1;
3733 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3734 ds_type_count[1].descriptorCount = 1;
3735 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3736 ds_type_count[2].descriptorCount = 1;
3737 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3738 ds_type_count[3].descriptorCount = 1;
3739
3740 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3741 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3742 ds_pool_ci.maxSets = 1;
3743 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3744 ds_pool_ci.pPoolSizes = ds_type_count;
3745
3746 VkDescriptorPool ds_pool;
3747 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3748 ASSERT_VK_SUCCESS(err);
3749
Mark Muellerb9896722016-06-16 09:54:29 -06003750 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003751 layout_binding[0].binding = 0;
3752 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3753 layout_binding[0].descriptorCount = 1;
3754 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3755 layout_binding[0].pImmutableSamplers = NULL;
3756
3757 layout_binding[1].binding = 1;
3758 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3759 layout_binding[1].descriptorCount = 1;
3760 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3761 layout_binding[1].pImmutableSamplers = NULL;
3762
3763 VkSamplerCreateInfo sampler_ci = {};
3764 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3765 sampler_ci.pNext = NULL;
3766 sampler_ci.magFilter = VK_FILTER_NEAREST;
3767 sampler_ci.minFilter = VK_FILTER_NEAREST;
3768 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3769 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3770 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3771 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3772 sampler_ci.mipLodBias = 1.0;
3773 sampler_ci.anisotropyEnable = VK_FALSE;
3774 sampler_ci.maxAnisotropy = 1;
3775 sampler_ci.compareEnable = VK_FALSE;
3776 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3777 sampler_ci.minLod = 1.0;
3778 sampler_ci.maxLod = 1.0;
3779 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3780 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3781 VkSampler sampler;
3782
3783 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3784 ASSERT_VK_SUCCESS(err);
3785
3786 layout_binding[2].binding = 2;
3787 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3788 layout_binding[2].descriptorCount = 1;
3789 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3790 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3791
Mark Muellerd4914412016-06-13 17:52:06 -06003792 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3793 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3794 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3795 ds_layout_ci.pBindings = layout_binding;
3796 VkDescriptorSetLayout ds_layout;
3797 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3798 ASSERT_VK_SUCCESS(err);
3799
3800 VkDescriptorSetAllocateInfo alloc_info = {};
3801 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3802 alloc_info.descriptorSetCount = 1;
3803 alloc_info.descriptorPool = ds_pool;
3804 alloc_info.pSetLayouts = &ds_layout;
3805 VkDescriptorSet descriptorSet;
3806 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3807 ASSERT_VK_SUCCESS(err);
3808
3809 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3810 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3811 pipeline_layout_ci.pNext = NULL;
3812 pipeline_layout_ci.setLayoutCount = 1;
3813 pipeline_layout_ci.pSetLayouts = &ds_layout;
3814
3815 VkPipelineLayout pipeline_layout;
3816 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3817 ASSERT_VK_SUCCESS(err);
3818
Mark Mueller5c838ce2016-06-16 09:54:29 -06003819 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003820 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3821 descriptor_write.dstSet = descriptorSet;
3822 descriptor_write.dstBinding = 0;
3823 descriptor_write.descriptorCount = 1;
3824 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3825
Mark Mueller5c838ce2016-06-16 09:54:29 -06003826 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003827 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3828 m_errorMonitor->VerifyFound();
3829
3830 // Create a buffer to update the descriptor with
3831 uint32_t qfi = 0;
3832 VkBufferCreateInfo buffCI = {};
3833 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3834 buffCI.size = 1024;
3835 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3836 buffCI.queueFamilyIndexCount = 1;
3837 buffCI.pQueueFamilyIndices = &qfi;
3838
3839 VkBuffer dyub;
3840 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3841 ASSERT_VK_SUCCESS(err);
3842 VkDescriptorBufferInfo buffInfo = {};
3843 buffInfo.buffer = dyub;
3844 buffInfo.offset = 0;
3845 buffInfo.range = 1024;
3846
3847 descriptor_write.pBufferInfo = &buffInfo;
3848 descriptor_write.descriptorCount = 2;
3849
Mark Mueller5c838ce2016-06-16 09:54:29 -06003850 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3852 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3853 m_errorMonitor->VerifyFound();
3854
Mark Mueller5c838ce2016-06-16 09:54:29 -06003855 // 3) The second descriptor has a null_ptr pImmutableSamplers and
3856 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06003857 descriptor_write.dstBinding = 1;
3858 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06003859
Mark Mueller5c838ce2016-06-16 09:54:29 -06003860 // Make pImageInfo index non-null to avoid complaints of it missing
3861 VkDescriptorImageInfo imageInfo = {};
3862 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3863 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06003864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
3865 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3866 m_errorMonitor->VerifyFound();
3867
Mark Muellerd4914412016-06-13 17:52:06 -06003868 vkDestroyBuffer(m_device->device(), dyub, NULL);
3869 vkDestroySampler(m_device->device(), sampler, NULL);
3870 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3871 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3872 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3873}
3874
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003875TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
3876 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
3877 "due to a buffer dependency being destroyed.");
3878 ASSERT_NO_FATAL_FAILURE(InitState());
3879
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003880 VkBuffer buffer;
3881 VkDeviceMemory mem;
3882 VkMemoryRequirements mem_reqs;
3883
3884 VkBufferCreateInfo buf_info = {};
3885 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12003886 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003887 buf_info.size = 256;
3888 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
3889 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
3890 ASSERT_VK_SUCCESS(err);
3891
3892 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
3893
3894 VkMemoryAllocateInfo alloc_info = {};
3895 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3896 alloc_info.allocationSize = 256;
3897 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003898 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 -06003899 if (!pass) {
3900 vkDestroyBuffer(m_device->device(), buffer, NULL);
3901 return;
3902 }
3903 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
3904 ASSERT_VK_SUCCESS(err);
3905
3906 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
3907 ASSERT_VK_SUCCESS(err);
3908
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003909 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12003910 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003911 m_commandBuffer->EndCommandBuffer();
3912
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003914 // Destroy buffer dependency prior to submit to cause ERROR
3915 vkDestroyBuffer(m_device->device(), buffer, NULL);
3916
3917 VkSubmitInfo submit_info = {};
3918 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3919 submit_info.commandBufferCount = 1;
3920 submit_info.pCommandBuffers = &m_commandBuffer->handle();
3921 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3922
3923 m_errorMonitor->VerifyFound();
3924 vkFreeMemory(m_device->handle(), mem, NULL);
3925}
3926
Tobin Ehlisea413442016-09-28 10:23:59 -06003927TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
3928 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
3929
3930 ASSERT_NO_FATAL_FAILURE(InitState());
3931 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3932
3933 VkDescriptorPoolSize ds_type_count;
3934 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
3935 ds_type_count.descriptorCount = 1;
3936
3937 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3938 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3939 ds_pool_ci.maxSets = 1;
3940 ds_pool_ci.poolSizeCount = 1;
3941 ds_pool_ci.pPoolSizes = &ds_type_count;
3942
3943 VkDescriptorPool ds_pool;
3944 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3945 ASSERT_VK_SUCCESS(err);
3946
3947 VkDescriptorSetLayoutBinding layout_binding;
3948 layout_binding.binding = 0;
3949 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
3950 layout_binding.descriptorCount = 1;
3951 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3952 layout_binding.pImmutableSamplers = NULL;
3953
3954 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3955 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3956 ds_layout_ci.bindingCount = 1;
3957 ds_layout_ci.pBindings = &layout_binding;
3958 VkDescriptorSetLayout ds_layout;
3959 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3960 ASSERT_VK_SUCCESS(err);
3961
3962 VkDescriptorSetAllocateInfo alloc_info = {};
3963 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3964 alloc_info.descriptorSetCount = 1;
3965 alloc_info.descriptorPool = ds_pool;
3966 alloc_info.pSetLayouts = &ds_layout;
3967 VkDescriptorSet descriptor_set;
3968 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
3969 ASSERT_VK_SUCCESS(err);
3970
3971 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3972 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3973 pipeline_layout_ci.pNext = NULL;
3974 pipeline_layout_ci.setLayoutCount = 1;
3975 pipeline_layout_ci.pSetLayouts = &ds_layout;
3976
3977 VkPipelineLayout pipeline_layout;
3978 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3979 ASSERT_VK_SUCCESS(err);
3980
3981 VkBuffer buffer;
3982 uint32_t queue_family_index = 0;
3983 VkBufferCreateInfo buffer_create_info = {};
3984 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3985 buffer_create_info.size = 1024;
3986 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
3987 buffer_create_info.queueFamilyIndexCount = 1;
3988 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
3989
3990 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
3991 ASSERT_VK_SUCCESS(err);
3992
3993 VkMemoryRequirements memory_reqs;
3994 VkDeviceMemory buffer_memory;
3995
3996 VkMemoryAllocateInfo memory_info = {};
3997 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3998 memory_info.allocationSize = 0;
3999 memory_info.memoryTypeIndex = 0;
4000
4001 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4002 memory_info.allocationSize = memory_reqs.size;
4003 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4004 ASSERT_TRUE(pass);
4005
4006 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4007 ASSERT_VK_SUCCESS(err);
4008 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4009 ASSERT_VK_SUCCESS(err);
4010
4011 VkBufferView view;
4012 VkBufferViewCreateInfo bvci = {};
4013 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4014 bvci.buffer = buffer;
4015 bvci.format = VK_FORMAT_R8_UNORM;
4016 bvci.range = VK_WHOLE_SIZE;
4017
4018 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4019 ASSERT_VK_SUCCESS(err);
4020
4021 VkWriteDescriptorSet descriptor_write = {};
4022 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4023 descriptor_write.dstSet = descriptor_set;
4024 descriptor_write.dstBinding = 0;
4025 descriptor_write.descriptorCount = 1;
4026 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4027 descriptor_write.pTexelBufferView = &view;
4028
4029 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4030
4031 char const *vsSource = "#version 450\n"
4032 "\n"
4033 "out gl_PerVertex { \n"
4034 " vec4 gl_Position;\n"
4035 "};\n"
4036 "void main(){\n"
4037 " gl_Position = vec4(1);\n"
4038 "}\n";
4039 char const *fsSource = "#version 450\n"
4040 "\n"
4041 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4042 "layout(location=0) out vec4 x;\n"
4043 "void main(){\n"
4044 " x = imageLoad(s, 0);\n"
4045 "}\n";
4046 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4047 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4048 VkPipelineObj pipe(m_device);
4049 pipe.AddShader(&vs);
4050 pipe.AddShader(&fs);
4051 pipe.AddColorAttachment();
4052 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4053
4054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4056
4057 BeginCommandBuffer();
4058 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4059 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4060 VkRect2D scissor = {{0, 0}, {16, 16}};
4061 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4062 // Bind pipeline to cmd buffer
4063 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4064 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4065 &descriptor_set, 0, nullptr);
4066 Draw(1, 0, 0, 0);
4067 EndCommandBuffer();
4068
4069 // Delete BufferView in order to invalidate cmd buffer
4070 vkDestroyBufferView(m_device->device(), view, NULL);
4071 // Now attempt submit of cmd buffer
4072 VkSubmitInfo submit_info = {};
4073 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4074 submit_info.commandBufferCount = 1;
4075 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4076 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4077 m_errorMonitor->VerifyFound();
4078
4079 // Clean-up
4080 vkDestroyBuffer(m_device->device(), buffer, NULL);
4081 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4082 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4083 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4084 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4085}
4086
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004087TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4088 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4089 "due to an image dependency being destroyed.");
4090 ASSERT_NO_FATAL_FAILURE(InitState());
4091
4092 VkImage image;
4093 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4094 VkImageCreateInfo image_create_info = {};
4095 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4096 image_create_info.pNext = NULL;
4097 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4098 image_create_info.format = tex_format;
4099 image_create_info.extent.width = 32;
4100 image_create_info.extent.height = 32;
4101 image_create_info.extent.depth = 1;
4102 image_create_info.mipLevels = 1;
4103 image_create_info.arrayLayers = 1;
4104 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4105 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004106 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004107 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004108 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004109 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004110 // Have to bind memory to image before recording cmd in cmd buffer using it
4111 VkMemoryRequirements mem_reqs;
4112 VkDeviceMemory image_mem;
4113 bool pass;
4114 VkMemoryAllocateInfo mem_alloc = {};
4115 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4116 mem_alloc.pNext = NULL;
4117 mem_alloc.memoryTypeIndex = 0;
4118 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4119 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004120 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004121 ASSERT_TRUE(pass);
4122 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4123 ASSERT_VK_SUCCESS(err);
4124 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4125 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004126
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004127 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004128 VkClearColorValue ccv;
4129 ccv.float32[0] = 1.0f;
4130 ccv.float32[1] = 1.0f;
4131 ccv.float32[2] = 1.0f;
4132 ccv.float32[3] = 1.0f;
4133 VkImageSubresourceRange isr = {};
4134 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004135 isr.baseArrayLayer = 0;
4136 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004137 isr.layerCount = 1;
4138 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004139 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004140 m_commandBuffer->EndCommandBuffer();
4141
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004143 // Destroy image dependency prior to submit to cause ERROR
4144 vkDestroyImage(m_device->device(), image, NULL);
4145
4146 VkSubmitInfo submit_info = {};
4147 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4148 submit_info.commandBufferCount = 1;
4149 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4150 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4151
4152 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004153 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004154}
4155
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004156TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4157 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4158 "due to a framebuffer image dependency being destroyed.");
4159 VkFormatProperties format_properties;
4160 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004161 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4162 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004163 return;
4164 }
4165
4166 ASSERT_NO_FATAL_FAILURE(InitState());
4167 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4168
4169 VkImageCreateInfo image_ci = {};
4170 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4171 image_ci.pNext = NULL;
4172 image_ci.imageType = VK_IMAGE_TYPE_2D;
4173 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4174 image_ci.extent.width = 32;
4175 image_ci.extent.height = 32;
4176 image_ci.extent.depth = 1;
4177 image_ci.mipLevels = 1;
4178 image_ci.arrayLayers = 1;
4179 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4180 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004181 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004182 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4183 image_ci.flags = 0;
4184 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004185 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004186
4187 VkMemoryRequirements memory_reqs;
4188 VkDeviceMemory image_memory;
4189 bool pass;
4190 VkMemoryAllocateInfo memory_info = {};
4191 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4192 memory_info.pNext = NULL;
4193 memory_info.allocationSize = 0;
4194 memory_info.memoryTypeIndex = 0;
4195 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4196 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004197 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004198 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004199 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004200 ASSERT_VK_SUCCESS(err);
4201 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4202 ASSERT_VK_SUCCESS(err);
4203
4204 VkImageViewCreateInfo ivci = {
4205 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4206 nullptr,
4207 0,
4208 image,
4209 VK_IMAGE_VIEW_TYPE_2D,
4210 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004211 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004212 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4213 };
4214 VkImageView view;
4215 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4216 ASSERT_VK_SUCCESS(err);
4217
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004218 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004219 VkFramebuffer fb;
4220 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4221 ASSERT_VK_SUCCESS(err);
4222
4223 // Just use default renderpass with our framebuffer
4224 m_renderPassBeginInfo.framebuffer = fb;
4225 // Create Null cmd buffer for submit
4226 BeginCommandBuffer();
4227 EndCommandBuffer();
4228 // Destroy image attached to framebuffer to invalidate cmd buffer
4229 vkDestroyImage(m_device->device(), image, NULL);
4230 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004232 QueueCommandBuffer(false);
4233 m_errorMonitor->VerifyFound();
4234
4235 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4236 vkDestroyImageView(m_device->device(), view, nullptr);
4237 vkFreeMemory(m_device->device(), image_memory, nullptr);
4238}
4239
Tobin Ehlisb329f992016-10-12 13:20:29 -06004240TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4241 TEST_DESCRIPTION("Delete in-use framebuffer.");
4242 VkFormatProperties format_properties;
4243 VkResult err = VK_SUCCESS;
4244 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4245
4246 ASSERT_NO_FATAL_FAILURE(InitState());
4247 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4248
4249 VkImageObj image(m_device);
4250 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4251 ASSERT_TRUE(image.initialized());
4252 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4253
4254 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4255 VkFramebuffer fb;
4256 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4257 ASSERT_VK_SUCCESS(err);
4258
4259 // Just use default renderpass with our framebuffer
4260 m_renderPassBeginInfo.framebuffer = fb;
4261 // Create Null cmd buffer for submit
4262 BeginCommandBuffer();
4263 EndCommandBuffer();
4264 // Submit cmd buffer to put it in-flight
4265 VkSubmitInfo submit_info = {};
4266 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4267 submit_info.commandBufferCount = 1;
4268 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4269 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4270 // Destroy framebuffer while in-flight
4271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4272 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4273 m_errorMonitor->VerifyFound();
4274 // Wait for queue to complete so we can safely destroy everything
4275 vkQueueWaitIdle(m_device->m_queue);
4276 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4277}
4278
Tobin Ehlis88becd72016-09-21 14:33:41 -06004279TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4280 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4281 VkFormatProperties format_properties;
4282 VkResult err = VK_SUCCESS;
4283 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004284
4285 ASSERT_NO_FATAL_FAILURE(InitState());
4286 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4287
4288 VkImageCreateInfo image_ci = {};
4289 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4290 image_ci.pNext = NULL;
4291 image_ci.imageType = VK_IMAGE_TYPE_2D;
4292 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4293 image_ci.extent.width = 256;
4294 image_ci.extent.height = 256;
4295 image_ci.extent.depth = 1;
4296 image_ci.mipLevels = 1;
4297 image_ci.arrayLayers = 1;
4298 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4299 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004300 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004301 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4302 image_ci.flags = 0;
4303 VkImage image;
4304 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4305
4306 VkMemoryRequirements memory_reqs;
4307 VkDeviceMemory image_memory;
4308 bool pass;
4309 VkMemoryAllocateInfo memory_info = {};
4310 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4311 memory_info.pNext = NULL;
4312 memory_info.allocationSize = 0;
4313 memory_info.memoryTypeIndex = 0;
4314 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4315 memory_info.allocationSize = memory_reqs.size;
4316 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4317 ASSERT_TRUE(pass);
4318 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4319 ASSERT_VK_SUCCESS(err);
4320 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4321 ASSERT_VK_SUCCESS(err);
4322
4323 VkImageViewCreateInfo ivci = {
4324 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4325 nullptr,
4326 0,
4327 image,
4328 VK_IMAGE_VIEW_TYPE_2D,
4329 VK_FORMAT_B8G8R8A8_UNORM,
4330 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4331 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4332 };
4333 VkImageView view;
4334 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4335 ASSERT_VK_SUCCESS(err);
4336
4337 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4338 VkFramebuffer fb;
4339 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4340 ASSERT_VK_SUCCESS(err);
4341
4342 // Just use default renderpass with our framebuffer
4343 m_renderPassBeginInfo.framebuffer = fb;
4344 // Create Null cmd buffer for submit
4345 BeginCommandBuffer();
4346 EndCommandBuffer();
4347 // Submit cmd buffer to put it (and attached imageView) in-flight
4348 VkSubmitInfo submit_info = {};
4349 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4350 submit_info.commandBufferCount = 1;
4351 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4352 // Submit cmd buffer to put framebuffer and children in-flight
4353 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4354 // Destroy image attached to framebuffer while in-flight
4355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4356 vkDestroyImage(m_device->device(), image, NULL);
4357 m_errorMonitor->VerifyFound();
4358 // Wait for queue to complete so we can safely destroy image and other objects
4359 vkQueueWaitIdle(m_device->m_queue);
4360 vkDestroyImage(m_device->device(), image, NULL);
4361 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4362 vkDestroyImageView(m_device->device(), view, nullptr);
4363 vkFreeMemory(m_device->device(), image_memory, nullptr);
4364}
4365
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004366TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4367 TEST_DESCRIPTION("Delete in-use renderPass.");
4368
4369 ASSERT_NO_FATAL_FAILURE(InitState());
4370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4371
4372 // Create simple renderpass
4373 VkAttachmentReference attach = {};
4374 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4375 VkSubpassDescription subpass = {};
4376 subpass.pColorAttachments = &attach;
4377 VkRenderPassCreateInfo rpci = {};
4378 rpci.subpassCount = 1;
4379 rpci.pSubpasses = &subpass;
4380 rpci.attachmentCount = 1;
4381 VkAttachmentDescription attach_desc = {};
4382 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4383 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4384 rpci.pAttachments = &attach_desc;
4385 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4386 VkRenderPass rp;
4387 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4388 ASSERT_VK_SUCCESS(err);
4389
4390 // Create a pipeline that uses the given renderpass
4391 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4392 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4393
4394 VkPipelineLayout pipeline_layout;
4395 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4396 ASSERT_VK_SUCCESS(err);
4397
4398 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4399 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4400 vp_state_ci.viewportCount = 1;
4401 VkViewport vp = {}; // Just need dummy vp to point to
4402 vp_state_ci.pViewports = &vp;
4403 vp_state_ci.scissorCount = 1;
4404 VkRect2D scissors = {}; // Dummy scissors to point to
4405 vp_state_ci.pScissors = &scissors;
4406
4407 VkPipelineShaderStageCreateInfo shaderStages[2];
4408 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4409
4410 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4411 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4412 // but add it to be able to run on more devices
4413 shaderStages[0] = vs.GetStageCreateInfo();
4414 shaderStages[1] = fs.GetStageCreateInfo();
4415
4416 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4417 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4418
4419 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4420 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4421 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4422
4423 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4424 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4425 rs_ci.rasterizerDiscardEnable = true;
4426 rs_ci.lineWidth = 1.0f;
4427
4428 VkPipelineColorBlendAttachmentState att = {};
4429 att.blendEnable = VK_FALSE;
4430 att.colorWriteMask = 0xf;
4431
4432 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4433 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4434 cb_ci.attachmentCount = 1;
4435 cb_ci.pAttachments = &att;
4436
4437 VkGraphicsPipelineCreateInfo gp_ci = {};
4438 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4439 gp_ci.stageCount = 2;
4440 gp_ci.pStages = shaderStages;
4441 gp_ci.pVertexInputState = &vi_ci;
4442 gp_ci.pInputAssemblyState = &ia_ci;
4443 gp_ci.pViewportState = &vp_state_ci;
4444 gp_ci.pRasterizationState = &rs_ci;
4445 gp_ci.pColorBlendState = &cb_ci;
4446 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4447 gp_ci.layout = pipeline_layout;
4448 gp_ci.renderPass = rp;
4449
4450 VkPipelineCacheCreateInfo pc_ci = {};
4451 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4452
4453 VkPipeline pipeline;
4454 VkPipelineCache pipe_cache;
4455 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4456 ASSERT_VK_SUCCESS(err);
4457
4458 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4459 ASSERT_VK_SUCCESS(err);
4460 // Bind pipeline to cmd buffer, will also bind renderpass
4461 m_commandBuffer->BeginCommandBuffer();
4462 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4463 m_commandBuffer->EndCommandBuffer();
4464
4465 VkSubmitInfo submit_info = {};
4466 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4467 submit_info.commandBufferCount = 1;
4468 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4469 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4470
4471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4472 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4473 m_errorMonitor->VerifyFound();
4474
4475 // Wait for queue to complete so we can safely destroy everything
4476 vkQueueWaitIdle(m_device->m_queue);
4477 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4478 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4479 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4480 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4481}
4482
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004483TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004484 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004485 ASSERT_NO_FATAL_FAILURE(InitState());
4486
4487 VkImage image;
4488 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4489 VkImageCreateInfo image_create_info = {};
4490 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4491 image_create_info.pNext = NULL;
4492 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4493 image_create_info.format = tex_format;
4494 image_create_info.extent.width = 32;
4495 image_create_info.extent.height = 32;
4496 image_create_info.extent.depth = 1;
4497 image_create_info.mipLevels = 1;
4498 image_create_info.arrayLayers = 1;
4499 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4500 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004501 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004502 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004503 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004504 ASSERT_VK_SUCCESS(err);
4505 // Have to bind memory to image before recording cmd in cmd buffer using it
4506 VkMemoryRequirements mem_reqs;
4507 VkDeviceMemory image_mem;
4508 bool pass;
4509 VkMemoryAllocateInfo mem_alloc = {};
4510 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4511 mem_alloc.pNext = NULL;
4512 mem_alloc.memoryTypeIndex = 0;
4513 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4514 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004515 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004516 ASSERT_TRUE(pass);
4517 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4518 ASSERT_VK_SUCCESS(err);
4519
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004520 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004522 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004523
4524 m_commandBuffer->BeginCommandBuffer();
4525 VkClearColorValue ccv;
4526 ccv.float32[0] = 1.0f;
4527 ccv.float32[1] = 1.0f;
4528 ccv.float32[2] = 1.0f;
4529 ccv.float32[3] = 1.0f;
4530 VkImageSubresourceRange isr = {};
4531 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4532 isr.baseArrayLayer = 0;
4533 isr.baseMipLevel = 0;
4534 isr.layerCount = 1;
4535 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004536 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004537 m_commandBuffer->EndCommandBuffer();
4538
4539 m_errorMonitor->VerifyFound();
4540 vkDestroyImage(m_device->device(), image, NULL);
4541 vkFreeMemory(m_device->device(), image_mem, nullptr);
4542}
4543
4544TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004545 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004546 ASSERT_NO_FATAL_FAILURE(InitState());
4547
4548 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004549 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 -06004550 VK_IMAGE_TILING_OPTIMAL, 0);
4551 ASSERT_TRUE(image.initialized());
4552
4553 VkBuffer buffer;
4554 VkDeviceMemory mem;
4555 VkMemoryRequirements mem_reqs;
4556
4557 VkBufferCreateInfo buf_info = {};
4558 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004559 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004560 buf_info.size = 256;
4561 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4562 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4563 ASSERT_VK_SUCCESS(err);
4564
4565 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4566
4567 VkMemoryAllocateInfo alloc_info = {};
4568 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4569 alloc_info.allocationSize = 256;
4570 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004571 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 -06004572 if (!pass) {
4573 vkDestroyBuffer(m_device->device(), buffer, NULL);
4574 return;
4575 }
4576 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4577 ASSERT_VK_SUCCESS(err);
4578
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004579 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004581 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004582 VkBufferImageCopy region = {};
4583 region.bufferRowLength = 128;
4584 region.bufferImageHeight = 128;
4585 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4586
4587 region.imageSubresource.layerCount = 1;
4588 region.imageExtent.height = 4;
4589 region.imageExtent.width = 4;
4590 region.imageExtent.depth = 1;
4591 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004592 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4593 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004594 m_commandBuffer->EndCommandBuffer();
4595
4596 m_errorMonitor->VerifyFound();
4597
4598 vkDestroyBuffer(m_device->device(), buffer, NULL);
4599 vkFreeMemory(m_device->handle(), mem, NULL);
4600}
4601
Tobin Ehlis85940f52016-07-07 16:57:21 -06004602TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4603 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4604 "due to an event dependency being destroyed.");
4605 ASSERT_NO_FATAL_FAILURE(InitState());
4606
4607 VkEvent event;
4608 VkEventCreateInfo evci = {};
4609 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4610 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4611 ASSERT_VK_SUCCESS(result);
4612
4613 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004614 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004615 m_commandBuffer->EndCommandBuffer();
4616
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004618 // Destroy event dependency prior to submit to cause ERROR
4619 vkDestroyEvent(m_device->device(), event, NULL);
4620
4621 VkSubmitInfo submit_info = {};
4622 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4623 submit_info.commandBufferCount = 1;
4624 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4625 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4626
4627 m_errorMonitor->VerifyFound();
4628}
4629
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004630TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4631 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4632 "due to a query pool dependency being destroyed.");
4633 ASSERT_NO_FATAL_FAILURE(InitState());
4634
4635 VkQueryPool query_pool;
4636 VkQueryPoolCreateInfo qpci{};
4637 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4638 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4639 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004640 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004641 ASSERT_VK_SUCCESS(result);
4642
4643 m_commandBuffer->BeginCommandBuffer();
4644 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4645 m_commandBuffer->EndCommandBuffer();
4646
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004648 // Destroy query pool dependency prior to submit to cause ERROR
4649 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4650
4651 VkSubmitInfo submit_info = {};
4652 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4653 submit_info.commandBufferCount = 1;
4654 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4655 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4656
4657 m_errorMonitor->VerifyFound();
4658}
4659
Tobin Ehlis24130d92016-07-08 15:50:53 -06004660TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4661 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4662 "due to a pipeline dependency being destroyed.");
4663 ASSERT_NO_FATAL_FAILURE(InitState());
4664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4665
4666 VkResult err;
4667
4668 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4669 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4670
4671 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004672 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004673 ASSERT_VK_SUCCESS(err);
4674
4675 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4676 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4677 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004678 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004679 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004680 vp_state_ci.scissorCount = 1;
4681 VkRect2D scissors = {}; // Dummy scissors to point to
4682 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004683
4684 VkPipelineShaderStageCreateInfo shaderStages[2];
4685 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4686
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004687 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4688 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4689 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004690 shaderStages[0] = vs.GetStageCreateInfo();
4691 shaderStages[1] = fs.GetStageCreateInfo();
4692
4693 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4694 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4695
4696 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4697 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4698 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4699
4700 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4701 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004702 rs_ci.rasterizerDiscardEnable = true;
4703 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004704
4705 VkPipelineColorBlendAttachmentState att = {};
4706 att.blendEnable = VK_FALSE;
4707 att.colorWriteMask = 0xf;
4708
4709 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4710 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4711 cb_ci.attachmentCount = 1;
4712 cb_ci.pAttachments = &att;
4713
4714 VkGraphicsPipelineCreateInfo gp_ci = {};
4715 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4716 gp_ci.stageCount = 2;
4717 gp_ci.pStages = shaderStages;
4718 gp_ci.pVertexInputState = &vi_ci;
4719 gp_ci.pInputAssemblyState = &ia_ci;
4720 gp_ci.pViewportState = &vp_state_ci;
4721 gp_ci.pRasterizationState = &rs_ci;
4722 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004723 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4724 gp_ci.layout = pipeline_layout;
4725 gp_ci.renderPass = renderPass();
4726
4727 VkPipelineCacheCreateInfo pc_ci = {};
4728 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4729
4730 VkPipeline pipeline;
4731 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004732 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004733 ASSERT_VK_SUCCESS(err);
4734
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004735 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004736 ASSERT_VK_SUCCESS(err);
4737
4738 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004739 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004740 m_commandBuffer->EndCommandBuffer();
4741 // Now destroy pipeline in order to cause error when submitting
4742 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004745
4746 VkSubmitInfo submit_info = {};
4747 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4748 submit_info.commandBufferCount = 1;
4749 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4750 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4751
4752 m_errorMonitor->VerifyFound();
4753 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4754 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4755}
4756
Tobin Ehlis31289162016-08-17 14:57:58 -06004757TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4758 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4759 "due to a bound descriptor set with a buffer dependency "
4760 "being destroyed.");
4761 ASSERT_NO_FATAL_FAILURE(InitState());
4762 ASSERT_NO_FATAL_FAILURE(InitViewport());
4763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4764
4765 VkDescriptorPoolSize ds_type_count = {};
4766 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4767 ds_type_count.descriptorCount = 1;
4768
4769 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4770 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4771 ds_pool_ci.pNext = NULL;
4772 ds_pool_ci.maxSets = 1;
4773 ds_pool_ci.poolSizeCount = 1;
4774 ds_pool_ci.pPoolSizes = &ds_type_count;
4775
4776 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004777 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004778 ASSERT_VK_SUCCESS(err);
4779
4780 VkDescriptorSetLayoutBinding dsl_binding = {};
4781 dsl_binding.binding = 0;
4782 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4783 dsl_binding.descriptorCount = 1;
4784 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4785 dsl_binding.pImmutableSamplers = NULL;
4786
4787 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4788 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4789 ds_layout_ci.pNext = NULL;
4790 ds_layout_ci.bindingCount = 1;
4791 ds_layout_ci.pBindings = &dsl_binding;
4792 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004793 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004794 ASSERT_VK_SUCCESS(err);
4795
4796 VkDescriptorSet descriptorSet;
4797 VkDescriptorSetAllocateInfo alloc_info = {};
4798 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4799 alloc_info.descriptorSetCount = 1;
4800 alloc_info.descriptorPool = ds_pool;
4801 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004802 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004803 ASSERT_VK_SUCCESS(err);
4804
4805 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4806 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4807 pipeline_layout_ci.pNext = NULL;
4808 pipeline_layout_ci.setLayoutCount = 1;
4809 pipeline_layout_ci.pSetLayouts = &ds_layout;
4810
4811 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004812 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004813 ASSERT_VK_SUCCESS(err);
4814
4815 // Create a buffer to update the descriptor with
4816 uint32_t qfi = 0;
4817 VkBufferCreateInfo buffCI = {};
4818 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4819 buffCI.size = 1024;
4820 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4821 buffCI.queueFamilyIndexCount = 1;
4822 buffCI.pQueueFamilyIndices = &qfi;
4823
4824 VkBuffer buffer;
4825 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4826 ASSERT_VK_SUCCESS(err);
4827 // Allocate memory and bind to buffer so we can make it to the appropriate
4828 // error
4829 VkMemoryAllocateInfo mem_alloc = {};
4830 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4831 mem_alloc.pNext = NULL;
4832 mem_alloc.allocationSize = 1024;
4833 mem_alloc.memoryTypeIndex = 0;
4834
4835 VkMemoryRequirements memReqs;
4836 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004837 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004838 if (!pass) {
4839 vkDestroyBuffer(m_device->device(), buffer, NULL);
4840 return;
4841 }
4842
4843 VkDeviceMemory mem;
4844 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4845 ASSERT_VK_SUCCESS(err);
4846 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4847 ASSERT_VK_SUCCESS(err);
4848 // Correctly update descriptor to avoid "NOT_UPDATED" error
4849 VkDescriptorBufferInfo buffInfo = {};
4850 buffInfo.buffer = buffer;
4851 buffInfo.offset = 0;
4852 buffInfo.range = 1024;
4853
4854 VkWriteDescriptorSet descriptor_write;
4855 memset(&descriptor_write, 0, sizeof(descriptor_write));
4856 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4857 descriptor_write.dstSet = descriptorSet;
4858 descriptor_write.dstBinding = 0;
4859 descriptor_write.descriptorCount = 1;
4860 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4861 descriptor_write.pBufferInfo = &buffInfo;
4862
4863 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4864
4865 // Create PSO to be used for draw-time errors below
4866 char const *vsSource = "#version 450\n"
4867 "\n"
4868 "out gl_PerVertex { \n"
4869 " vec4 gl_Position;\n"
4870 "};\n"
4871 "void main(){\n"
4872 " gl_Position = vec4(1);\n"
4873 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004874 char const *fsSource = "#version 450\n"
4875 "\n"
4876 "layout(location=0) out vec4 x;\n"
4877 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4878 "void main(){\n"
4879 " x = vec4(bar.y);\n"
4880 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06004881 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4882 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4883 VkPipelineObj pipe(m_device);
4884 pipe.AddShader(&vs);
4885 pipe.AddShader(&fs);
4886 pipe.AddColorAttachment();
4887 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4888
4889 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004890 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4891 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4892 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06004893 Draw(1, 0, 0, 0);
4894 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06004896 // Destroy buffer should invalidate the cmd buffer, causing error on submit
4897 vkDestroyBuffer(m_device->device(), buffer, NULL);
4898 // Attempt to submit cmd buffer
4899 VkSubmitInfo submit_info = {};
4900 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4901 submit_info.commandBufferCount = 1;
4902 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4903 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4904 m_errorMonitor->VerifyFound();
4905 // Cleanup
4906 vkFreeMemory(m_device->device(), mem, NULL);
4907
4908 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4909 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4910 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4911}
4912
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004913TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
4914 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4915 "due to a bound descriptor sets with a combined image "
4916 "sampler having their image, sampler, and descriptor set "
4917 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06004918 "submit associated cmd buffers. Attempt to destroy a "
4919 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004920 ASSERT_NO_FATAL_FAILURE(InitState());
4921 ASSERT_NO_FATAL_FAILURE(InitViewport());
4922 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4923
4924 VkDescriptorPoolSize ds_type_count = {};
4925 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4926 ds_type_count.descriptorCount = 1;
4927
4928 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4929 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4930 ds_pool_ci.pNext = NULL;
4931 ds_pool_ci.maxSets = 1;
4932 ds_pool_ci.poolSizeCount = 1;
4933 ds_pool_ci.pPoolSizes = &ds_type_count;
4934
4935 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004936 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004937 ASSERT_VK_SUCCESS(err);
4938
4939 VkDescriptorSetLayoutBinding dsl_binding = {};
4940 dsl_binding.binding = 0;
4941 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4942 dsl_binding.descriptorCount = 1;
4943 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4944 dsl_binding.pImmutableSamplers = NULL;
4945
4946 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4947 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4948 ds_layout_ci.pNext = NULL;
4949 ds_layout_ci.bindingCount = 1;
4950 ds_layout_ci.pBindings = &dsl_binding;
4951 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004952 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004953 ASSERT_VK_SUCCESS(err);
4954
4955 VkDescriptorSet descriptorSet;
4956 VkDescriptorSetAllocateInfo alloc_info = {};
4957 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4958 alloc_info.descriptorSetCount = 1;
4959 alloc_info.descriptorPool = ds_pool;
4960 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004961 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004962 ASSERT_VK_SUCCESS(err);
4963
4964 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4965 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4966 pipeline_layout_ci.pNext = NULL;
4967 pipeline_layout_ci.setLayoutCount = 1;
4968 pipeline_layout_ci.pSetLayouts = &ds_layout;
4969
4970 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004971 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004972 ASSERT_VK_SUCCESS(err);
4973
4974 // Create images to update the descriptor with
4975 VkImage image;
4976 VkImage image2;
4977 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4978 const int32_t tex_width = 32;
4979 const int32_t tex_height = 32;
4980 VkImageCreateInfo image_create_info = {};
4981 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4982 image_create_info.pNext = NULL;
4983 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4984 image_create_info.format = tex_format;
4985 image_create_info.extent.width = tex_width;
4986 image_create_info.extent.height = tex_height;
4987 image_create_info.extent.depth = 1;
4988 image_create_info.mipLevels = 1;
4989 image_create_info.arrayLayers = 1;
4990 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4991 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
4992 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4993 image_create_info.flags = 0;
4994 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
4995 ASSERT_VK_SUCCESS(err);
4996 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
4997 ASSERT_VK_SUCCESS(err);
4998
4999 VkMemoryRequirements memory_reqs;
5000 VkDeviceMemory image_memory;
5001 bool pass;
5002 VkMemoryAllocateInfo memory_info = {};
5003 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5004 memory_info.pNext = NULL;
5005 memory_info.allocationSize = 0;
5006 memory_info.memoryTypeIndex = 0;
5007 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5008 // Allocate enough memory for both images
5009 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005010 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005011 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005012 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005013 ASSERT_VK_SUCCESS(err);
5014 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5015 ASSERT_VK_SUCCESS(err);
5016 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005017 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005018 ASSERT_VK_SUCCESS(err);
5019
5020 VkImageViewCreateInfo image_view_create_info = {};
5021 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5022 image_view_create_info.image = image;
5023 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5024 image_view_create_info.format = tex_format;
5025 image_view_create_info.subresourceRange.layerCount = 1;
5026 image_view_create_info.subresourceRange.baseMipLevel = 0;
5027 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005028 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005029
5030 VkImageView view;
5031 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005032 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005033 ASSERT_VK_SUCCESS(err);
5034 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005035 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005036 ASSERT_VK_SUCCESS(err);
5037 // Create Samplers
5038 VkSamplerCreateInfo sampler_ci = {};
5039 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5040 sampler_ci.pNext = NULL;
5041 sampler_ci.magFilter = VK_FILTER_NEAREST;
5042 sampler_ci.minFilter = VK_FILTER_NEAREST;
5043 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5044 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5045 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5046 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5047 sampler_ci.mipLodBias = 1.0;
5048 sampler_ci.anisotropyEnable = VK_FALSE;
5049 sampler_ci.maxAnisotropy = 1;
5050 sampler_ci.compareEnable = VK_FALSE;
5051 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5052 sampler_ci.minLod = 1.0;
5053 sampler_ci.maxLod = 1.0;
5054 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5055 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5056 VkSampler sampler;
5057 VkSampler sampler2;
5058 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5059 ASSERT_VK_SUCCESS(err);
5060 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5061 ASSERT_VK_SUCCESS(err);
5062 // Update descriptor with image and sampler
5063 VkDescriptorImageInfo img_info = {};
5064 img_info.sampler = sampler;
5065 img_info.imageView = view;
5066 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5067
5068 VkWriteDescriptorSet descriptor_write;
5069 memset(&descriptor_write, 0, sizeof(descriptor_write));
5070 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5071 descriptor_write.dstSet = descriptorSet;
5072 descriptor_write.dstBinding = 0;
5073 descriptor_write.descriptorCount = 1;
5074 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5075 descriptor_write.pImageInfo = &img_info;
5076
5077 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5078
5079 // Create PSO to be used for draw-time errors below
5080 char const *vsSource = "#version 450\n"
5081 "\n"
5082 "out gl_PerVertex { \n"
5083 " vec4 gl_Position;\n"
5084 "};\n"
5085 "void main(){\n"
5086 " gl_Position = vec4(1);\n"
5087 "}\n";
5088 char const *fsSource = "#version 450\n"
5089 "\n"
5090 "layout(set=0, binding=0) uniform sampler2D s;\n"
5091 "layout(location=0) out vec4 x;\n"
5092 "void main(){\n"
5093 " x = texture(s, vec2(1));\n"
5094 "}\n";
5095 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5096 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5097 VkPipelineObj pipe(m_device);
5098 pipe.AddShader(&vs);
5099 pipe.AddShader(&fs);
5100 pipe.AddColorAttachment();
5101 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5102
5103 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005105 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005106 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5107 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5108 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005109 Draw(1, 0, 0, 0);
5110 EndCommandBuffer();
5111 // Destroy sampler invalidates the cmd buffer, causing error on submit
5112 vkDestroySampler(m_device->device(), sampler, NULL);
5113 // Attempt to submit cmd buffer
5114 VkSubmitInfo submit_info = {};
5115 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5116 submit_info.commandBufferCount = 1;
5117 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5118 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5119 m_errorMonitor->VerifyFound();
5120 // Now re-update descriptor with valid sampler and delete image
5121 img_info.sampler = sampler2;
5122 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005124 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005125 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5126 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5127 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005128 Draw(1, 0, 0, 0);
5129 EndCommandBuffer();
5130 // Destroy image invalidates the cmd buffer, causing error on submit
5131 vkDestroyImage(m_device->device(), image, NULL);
5132 // Attempt to submit cmd buffer
5133 submit_info = {};
5134 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5135 submit_info.commandBufferCount = 1;
5136 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5137 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5138 m_errorMonitor->VerifyFound();
5139 // Now update descriptor to be valid, but then free descriptor
5140 img_info.imageView = view2;
5141 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005143 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005144 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5145 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5146 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005147 Draw(1, 0, 0, 0);
5148 EndCommandBuffer();
5149 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005151 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005152 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005153 // Attempt to submit cmd buffer
5154 submit_info = {};
5155 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5156 submit_info.commandBufferCount = 1;
5157 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5158 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5159 m_errorMonitor->VerifyFound();
5160 // Cleanup
5161 vkFreeMemory(m_device->device(), image_memory, NULL);
5162 vkDestroySampler(m_device->device(), sampler2, NULL);
5163 vkDestroyImage(m_device->device(), image2, NULL);
5164 vkDestroyImageView(m_device->device(), view, NULL);
5165 vkDestroyImageView(m_device->device(), view2, NULL);
5166 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5167 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5168 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5169}
5170
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005171TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5172 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5173 ASSERT_NO_FATAL_FAILURE(InitState());
5174 ASSERT_NO_FATAL_FAILURE(InitViewport());
5175 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5176
5177 VkDescriptorPoolSize ds_type_count = {};
5178 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5179 ds_type_count.descriptorCount = 1;
5180
5181 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5182 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5183 ds_pool_ci.pNext = NULL;
5184 ds_pool_ci.maxSets = 1;
5185 ds_pool_ci.poolSizeCount = 1;
5186 ds_pool_ci.pPoolSizes = &ds_type_count;
5187
5188 VkDescriptorPool ds_pool;
5189 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5190 ASSERT_VK_SUCCESS(err);
5191
5192 VkDescriptorSetLayoutBinding dsl_binding = {};
5193 dsl_binding.binding = 0;
5194 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5195 dsl_binding.descriptorCount = 1;
5196 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5197 dsl_binding.pImmutableSamplers = NULL;
5198
5199 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5200 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5201 ds_layout_ci.pNext = NULL;
5202 ds_layout_ci.bindingCount = 1;
5203 ds_layout_ci.pBindings = &dsl_binding;
5204 VkDescriptorSetLayout ds_layout;
5205 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5206 ASSERT_VK_SUCCESS(err);
5207
5208 VkDescriptorSet descriptor_set;
5209 VkDescriptorSetAllocateInfo alloc_info = {};
5210 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5211 alloc_info.descriptorSetCount = 1;
5212 alloc_info.descriptorPool = ds_pool;
5213 alloc_info.pSetLayouts = &ds_layout;
5214 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5215 ASSERT_VK_SUCCESS(err);
5216
5217 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5218 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5219 pipeline_layout_ci.pNext = NULL;
5220 pipeline_layout_ci.setLayoutCount = 1;
5221 pipeline_layout_ci.pSetLayouts = &ds_layout;
5222
5223 VkPipelineLayout pipeline_layout;
5224 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5225 ASSERT_VK_SUCCESS(err);
5226
5227 // Create image to update the descriptor with
5228 VkImageObj image(m_device);
5229 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5230 ASSERT_TRUE(image.initialized());
5231
5232 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5233 // Create Sampler
5234 VkSamplerCreateInfo sampler_ci = {};
5235 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5236 sampler_ci.pNext = NULL;
5237 sampler_ci.magFilter = VK_FILTER_NEAREST;
5238 sampler_ci.minFilter = VK_FILTER_NEAREST;
5239 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5240 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5241 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5242 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5243 sampler_ci.mipLodBias = 1.0;
5244 sampler_ci.anisotropyEnable = VK_FALSE;
5245 sampler_ci.maxAnisotropy = 1;
5246 sampler_ci.compareEnable = VK_FALSE;
5247 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5248 sampler_ci.minLod = 1.0;
5249 sampler_ci.maxLod = 1.0;
5250 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5251 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5252 VkSampler sampler;
5253 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5254 ASSERT_VK_SUCCESS(err);
5255 // Update descriptor with image and sampler
5256 VkDescriptorImageInfo img_info = {};
5257 img_info.sampler = sampler;
5258 img_info.imageView = view;
5259 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5260
5261 VkWriteDescriptorSet descriptor_write;
5262 memset(&descriptor_write, 0, sizeof(descriptor_write));
5263 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5264 descriptor_write.dstSet = descriptor_set;
5265 descriptor_write.dstBinding = 0;
5266 descriptor_write.descriptorCount = 1;
5267 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5268 descriptor_write.pImageInfo = &img_info;
5269
5270 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5271
5272 // Create PSO to be used for draw-time errors below
5273 char const *vsSource = "#version 450\n"
5274 "\n"
5275 "out gl_PerVertex { \n"
5276 " vec4 gl_Position;\n"
5277 "};\n"
5278 "void main(){\n"
5279 " gl_Position = vec4(1);\n"
5280 "}\n";
5281 char const *fsSource = "#version 450\n"
5282 "\n"
5283 "layout(set=0, binding=0) uniform sampler2D s;\n"
5284 "layout(location=0) out vec4 x;\n"
5285 "void main(){\n"
5286 " x = texture(s, vec2(1));\n"
5287 "}\n";
5288 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5289 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5290 VkPipelineObj pipe(m_device);
5291 pipe.AddShader(&vs);
5292 pipe.AddShader(&fs);
5293 pipe.AddColorAttachment();
5294 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5295
5296 BeginCommandBuffer();
5297 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5298 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5299 &descriptor_set, 0, NULL);
5300 Draw(1, 0, 0, 0);
5301 EndCommandBuffer();
5302 // Submit cmd buffer to put pool in-flight
5303 VkSubmitInfo submit_info = {};
5304 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5305 submit_info.commandBufferCount = 1;
5306 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5307 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5308 // Destroy pool while in-flight, causing error
5309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5310 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5311 m_errorMonitor->VerifyFound();
5312 vkQueueWaitIdle(m_device->m_queue);
5313 // Cleanup
5314 vkDestroySampler(m_device->device(), sampler, NULL);
5315 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5316 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5317 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5318}
5319
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005320TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5321 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5322 ASSERT_NO_FATAL_FAILURE(InitState());
5323 ASSERT_NO_FATAL_FAILURE(InitViewport());
5324 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5325
5326 VkDescriptorPoolSize ds_type_count = {};
5327 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5328 ds_type_count.descriptorCount = 1;
5329
5330 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5331 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5332 ds_pool_ci.pNext = NULL;
5333 ds_pool_ci.maxSets = 1;
5334 ds_pool_ci.poolSizeCount = 1;
5335 ds_pool_ci.pPoolSizes = &ds_type_count;
5336
5337 VkDescriptorPool ds_pool;
5338 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5339 ASSERT_VK_SUCCESS(err);
5340
5341 VkDescriptorSetLayoutBinding dsl_binding = {};
5342 dsl_binding.binding = 0;
5343 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5344 dsl_binding.descriptorCount = 1;
5345 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5346 dsl_binding.pImmutableSamplers = NULL;
5347
5348 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5349 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5350 ds_layout_ci.pNext = NULL;
5351 ds_layout_ci.bindingCount = 1;
5352 ds_layout_ci.pBindings = &dsl_binding;
5353 VkDescriptorSetLayout ds_layout;
5354 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5355 ASSERT_VK_SUCCESS(err);
5356
5357 VkDescriptorSet descriptorSet;
5358 VkDescriptorSetAllocateInfo alloc_info = {};
5359 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5360 alloc_info.descriptorSetCount = 1;
5361 alloc_info.descriptorPool = ds_pool;
5362 alloc_info.pSetLayouts = &ds_layout;
5363 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5364 ASSERT_VK_SUCCESS(err);
5365
5366 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5367 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5368 pipeline_layout_ci.pNext = NULL;
5369 pipeline_layout_ci.setLayoutCount = 1;
5370 pipeline_layout_ci.pSetLayouts = &ds_layout;
5371
5372 VkPipelineLayout pipeline_layout;
5373 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5374 ASSERT_VK_SUCCESS(err);
5375
5376 // Create images to update the descriptor with
5377 VkImage image;
5378 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5379 const int32_t tex_width = 32;
5380 const int32_t tex_height = 32;
5381 VkImageCreateInfo image_create_info = {};
5382 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5383 image_create_info.pNext = NULL;
5384 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5385 image_create_info.format = tex_format;
5386 image_create_info.extent.width = tex_width;
5387 image_create_info.extent.height = tex_height;
5388 image_create_info.extent.depth = 1;
5389 image_create_info.mipLevels = 1;
5390 image_create_info.arrayLayers = 1;
5391 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5392 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5393 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5394 image_create_info.flags = 0;
5395 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5396 ASSERT_VK_SUCCESS(err);
5397 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5398 VkMemoryRequirements memory_reqs;
5399 VkDeviceMemory image_memory;
5400 bool pass;
5401 VkMemoryAllocateInfo memory_info = {};
5402 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5403 memory_info.pNext = NULL;
5404 memory_info.allocationSize = 0;
5405 memory_info.memoryTypeIndex = 0;
5406 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5407 // Allocate enough memory for image
5408 memory_info.allocationSize = memory_reqs.size;
5409 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5410 ASSERT_TRUE(pass);
5411 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5412 ASSERT_VK_SUCCESS(err);
5413 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5414 ASSERT_VK_SUCCESS(err);
5415
5416 VkImageViewCreateInfo image_view_create_info = {};
5417 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5418 image_view_create_info.image = image;
5419 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5420 image_view_create_info.format = tex_format;
5421 image_view_create_info.subresourceRange.layerCount = 1;
5422 image_view_create_info.subresourceRange.baseMipLevel = 0;
5423 image_view_create_info.subresourceRange.levelCount = 1;
5424 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5425
5426 VkImageView view;
5427 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5428 ASSERT_VK_SUCCESS(err);
5429 // Create Samplers
5430 VkSamplerCreateInfo sampler_ci = {};
5431 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5432 sampler_ci.pNext = NULL;
5433 sampler_ci.magFilter = VK_FILTER_NEAREST;
5434 sampler_ci.minFilter = VK_FILTER_NEAREST;
5435 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5436 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5437 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5438 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5439 sampler_ci.mipLodBias = 1.0;
5440 sampler_ci.anisotropyEnable = VK_FALSE;
5441 sampler_ci.maxAnisotropy = 1;
5442 sampler_ci.compareEnable = VK_FALSE;
5443 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5444 sampler_ci.minLod = 1.0;
5445 sampler_ci.maxLod = 1.0;
5446 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5447 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5448 VkSampler sampler;
5449 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5450 ASSERT_VK_SUCCESS(err);
5451 // Update descriptor with image and sampler
5452 VkDescriptorImageInfo img_info = {};
5453 img_info.sampler = sampler;
5454 img_info.imageView = view;
5455 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5456
5457 VkWriteDescriptorSet descriptor_write;
5458 memset(&descriptor_write, 0, sizeof(descriptor_write));
5459 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5460 descriptor_write.dstSet = descriptorSet;
5461 descriptor_write.dstBinding = 0;
5462 descriptor_write.descriptorCount = 1;
5463 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5464 descriptor_write.pImageInfo = &img_info;
5465 // Break memory binding and attempt update
5466 vkFreeMemory(m_device->device(), image_memory, nullptr);
5467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005468 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5470 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5471 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5472 m_errorMonitor->VerifyFound();
5473 // Cleanup
5474 vkDestroyImage(m_device->device(), image, NULL);
5475 vkDestroySampler(m_device->device(), sampler, NULL);
5476 vkDestroyImageView(m_device->device(), view, NULL);
5477 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5478 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5479 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5480}
5481
Karl Schultz6addd812016-02-02 17:17:23 -07005482TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005483 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5484 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005485 // Create a valid cmd buffer
5486 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005487 uint64_t fake_pipeline_handle = 0xbaad6001;
5488 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005489 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005490 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5491
5492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005493 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005494 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005495 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005496
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005497 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005498 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 -06005499 Draw(1, 0, 0, 0);
5500 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005501
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005502 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005503 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 +12005504 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005505 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5506 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005507}
5508
Karl Schultz6addd812016-02-02 17:17:23 -07005509TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005510 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005511 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005512
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005514
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005515 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005516 ASSERT_NO_FATAL_FAILURE(InitViewport());
5517 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005518 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005519 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5520 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005521
5522 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005523 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5524 ds_pool_ci.pNext = NULL;
5525 ds_pool_ci.maxSets = 1;
5526 ds_pool_ci.poolSizeCount = 1;
5527 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005528
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005529 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005530 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005531 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005532
Tony Barboureb254902015-07-15 12:50:33 -06005533 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005534 dsl_binding.binding = 0;
5535 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5536 dsl_binding.descriptorCount = 1;
5537 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5538 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005539
Tony Barboureb254902015-07-15 12:50:33 -06005540 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005541 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5542 ds_layout_ci.pNext = NULL;
5543 ds_layout_ci.bindingCount = 1;
5544 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005545 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005546 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005547 ASSERT_VK_SUCCESS(err);
5548
5549 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005550 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005551 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005552 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005553 alloc_info.descriptorPool = ds_pool;
5554 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005555 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005556 ASSERT_VK_SUCCESS(err);
5557
Tony Barboureb254902015-07-15 12:50:33 -06005558 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005559 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5560 pipeline_layout_ci.pNext = NULL;
5561 pipeline_layout_ci.setLayoutCount = 1;
5562 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005563
5564 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005565 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005566 ASSERT_VK_SUCCESS(err);
5567
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005568 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005569 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005570 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005571 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005572
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005573 VkPipelineObj pipe(m_device);
5574 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005575 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005576 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005577 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005578
5579 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005580 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5581 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5582 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005583
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005584 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005585
Chia-I Wuf7458c52015-10-26 21:10:41 +08005586 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5587 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5588 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005589}
5590
Karl Schultz6addd812016-02-02 17:17:23 -07005591TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005592 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005593 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005594
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5596 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005597
5598 ASSERT_NO_FATAL_FAILURE(InitState());
5599 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005600 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5601 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005602
5603 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005604 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5605 ds_pool_ci.pNext = NULL;
5606 ds_pool_ci.maxSets = 1;
5607 ds_pool_ci.poolSizeCount = 1;
5608 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005609
5610 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005611 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005612 ASSERT_VK_SUCCESS(err);
5613
5614 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005615 dsl_binding.binding = 0;
5616 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5617 dsl_binding.descriptorCount = 1;
5618 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5619 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005620
5621 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005622 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5623 ds_layout_ci.pNext = NULL;
5624 ds_layout_ci.bindingCount = 1;
5625 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005626 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005627 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005628 ASSERT_VK_SUCCESS(err);
5629
5630 VkDescriptorSet descriptorSet;
5631 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005632 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005633 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005634 alloc_info.descriptorPool = ds_pool;
5635 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005636 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005637 ASSERT_VK_SUCCESS(err);
5638
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005639 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005640 VkWriteDescriptorSet descriptor_write;
5641 memset(&descriptor_write, 0, sizeof(descriptor_write));
5642 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5643 descriptor_write.dstSet = descriptorSet;
5644 descriptor_write.dstBinding = 0;
5645 descriptor_write.descriptorCount = 1;
5646 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5647 descriptor_write.pTexelBufferView = &view;
5648
5649 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5650
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005651 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005652
5653 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5654 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5655}
5656
Mark Youngd339ba32016-05-30 13:28:35 -06005657TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005658 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 -06005659
5660 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005662 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005663
5664 ASSERT_NO_FATAL_FAILURE(InitState());
5665
5666 // Create a buffer with no bound memory and then attempt to create
5667 // a buffer view.
5668 VkBufferCreateInfo buff_ci = {};
5669 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005670 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005671 buff_ci.size = 256;
5672 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5673 VkBuffer buffer;
5674 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5675 ASSERT_VK_SUCCESS(err);
5676
5677 VkBufferViewCreateInfo buff_view_ci = {};
5678 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5679 buff_view_ci.buffer = buffer;
5680 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5681 buff_view_ci.range = VK_WHOLE_SIZE;
5682 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005683 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005684
5685 m_errorMonitor->VerifyFound();
5686 vkDestroyBuffer(m_device->device(), buffer, NULL);
5687 // If last error is success, it still created the view, so delete it.
5688 if (err == VK_SUCCESS) {
5689 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5690 }
5691}
5692
Karl Schultz6addd812016-02-02 17:17:23 -07005693TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5694 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5695 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005696 // 1. No dynamicOffset supplied
5697 // 2. Too many dynamicOffsets supplied
5698 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005699 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5701 "0 dynamicOffsets are left in "
5702 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005703
5704 ASSERT_NO_FATAL_FAILURE(InitState());
5705 ASSERT_NO_FATAL_FAILURE(InitViewport());
5706 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5707
5708 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005709 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5710 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005711
5712 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005713 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5714 ds_pool_ci.pNext = NULL;
5715 ds_pool_ci.maxSets = 1;
5716 ds_pool_ci.poolSizeCount = 1;
5717 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005718
5719 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005720 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005721 ASSERT_VK_SUCCESS(err);
5722
5723 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005724 dsl_binding.binding = 0;
5725 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5726 dsl_binding.descriptorCount = 1;
5727 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5728 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005729
5730 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005731 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5732 ds_layout_ci.pNext = NULL;
5733 ds_layout_ci.bindingCount = 1;
5734 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005735 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005736 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005737 ASSERT_VK_SUCCESS(err);
5738
5739 VkDescriptorSet descriptorSet;
5740 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005741 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005742 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005743 alloc_info.descriptorPool = ds_pool;
5744 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005745 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005746 ASSERT_VK_SUCCESS(err);
5747
5748 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005749 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5750 pipeline_layout_ci.pNext = NULL;
5751 pipeline_layout_ci.setLayoutCount = 1;
5752 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005753
5754 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005755 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005756 ASSERT_VK_SUCCESS(err);
5757
5758 // Create a buffer to update the descriptor with
5759 uint32_t qfi = 0;
5760 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005761 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5762 buffCI.size = 1024;
5763 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5764 buffCI.queueFamilyIndexCount = 1;
5765 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005766
5767 VkBuffer dyub;
5768 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5769 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005770 // Allocate memory and bind to buffer so we can make it to the appropriate
5771 // error
5772 VkMemoryAllocateInfo mem_alloc = {};
5773 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5774 mem_alloc.pNext = NULL;
5775 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005776 mem_alloc.memoryTypeIndex = 0;
5777
5778 VkMemoryRequirements memReqs;
5779 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005780 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005781 if (!pass) {
5782 vkDestroyBuffer(m_device->device(), dyub, NULL);
5783 return;
5784 }
5785
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005786 VkDeviceMemory mem;
5787 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5788 ASSERT_VK_SUCCESS(err);
5789 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5790 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005791 // Correctly update descriptor to avoid "NOT_UPDATED" error
5792 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005793 buffInfo.buffer = dyub;
5794 buffInfo.offset = 0;
5795 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005796
5797 VkWriteDescriptorSet descriptor_write;
5798 memset(&descriptor_write, 0, sizeof(descriptor_write));
5799 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5800 descriptor_write.dstSet = descriptorSet;
5801 descriptor_write.dstBinding = 0;
5802 descriptor_write.descriptorCount = 1;
5803 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5804 descriptor_write.pBufferInfo = &buffInfo;
5805
5806 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5807
5808 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005809 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5810 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005811 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005812 uint32_t pDynOff[2] = {512, 756};
5813 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5815 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5816 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5817 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005818 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005819 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5821 "offset 0 and range 1024 that "
5822 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005823 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005824 char const *vsSource = "#version 450\n"
5825 "\n"
5826 "out gl_PerVertex { \n"
5827 " vec4 gl_Position;\n"
5828 "};\n"
5829 "void main(){\n"
5830 " gl_Position = vec4(1);\n"
5831 "}\n";
5832 char const *fsSource = "#version 450\n"
5833 "\n"
5834 "layout(location=0) out vec4 x;\n"
5835 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5836 "void main(){\n"
5837 " x = vec4(bar.y);\n"
5838 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005839 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5840 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5841 VkPipelineObj pipe(m_device);
5842 pipe.AddShader(&vs);
5843 pipe.AddShader(&fs);
5844 pipe.AddColorAttachment();
5845 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5846
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005847 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005848 // This update should succeed, but offset size of 512 will overstep buffer
5849 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005850 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5851 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005852 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005853 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005854
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005855 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005856 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005857
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005858 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005859 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005860 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5861}
5862
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005863TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
5864 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
5865 "that doesn't have memory bound");
5866 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005868 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5870 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005871
5872 ASSERT_NO_FATAL_FAILURE(InitState());
5873 ASSERT_NO_FATAL_FAILURE(InitViewport());
5874 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5875
5876 VkDescriptorPoolSize ds_type_count = {};
5877 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5878 ds_type_count.descriptorCount = 1;
5879
5880 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5881 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5882 ds_pool_ci.pNext = NULL;
5883 ds_pool_ci.maxSets = 1;
5884 ds_pool_ci.poolSizeCount = 1;
5885 ds_pool_ci.pPoolSizes = &ds_type_count;
5886
5887 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005888 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005889 ASSERT_VK_SUCCESS(err);
5890
5891 VkDescriptorSetLayoutBinding dsl_binding = {};
5892 dsl_binding.binding = 0;
5893 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5894 dsl_binding.descriptorCount = 1;
5895 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5896 dsl_binding.pImmutableSamplers = NULL;
5897
5898 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5899 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5900 ds_layout_ci.pNext = NULL;
5901 ds_layout_ci.bindingCount = 1;
5902 ds_layout_ci.pBindings = &dsl_binding;
5903 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005904 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005905 ASSERT_VK_SUCCESS(err);
5906
5907 VkDescriptorSet descriptorSet;
5908 VkDescriptorSetAllocateInfo alloc_info = {};
5909 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5910 alloc_info.descriptorSetCount = 1;
5911 alloc_info.descriptorPool = ds_pool;
5912 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005913 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005914 ASSERT_VK_SUCCESS(err);
5915
5916 // Create a buffer to update the descriptor with
5917 uint32_t qfi = 0;
5918 VkBufferCreateInfo buffCI = {};
5919 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5920 buffCI.size = 1024;
5921 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5922 buffCI.queueFamilyIndexCount = 1;
5923 buffCI.pQueueFamilyIndices = &qfi;
5924
5925 VkBuffer dyub;
5926 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5927 ASSERT_VK_SUCCESS(err);
5928
5929 // Attempt to update descriptor without binding memory to it
5930 VkDescriptorBufferInfo buffInfo = {};
5931 buffInfo.buffer = dyub;
5932 buffInfo.offset = 0;
5933 buffInfo.range = 1024;
5934
5935 VkWriteDescriptorSet descriptor_write;
5936 memset(&descriptor_write, 0, sizeof(descriptor_write));
5937 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5938 descriptor_write.dstSet = descriptorSet;
5939 descriptor_write.dstBinding = 0;
5940 descriptor_write.descriptorCount = 1;
5941 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5942 descriptor_write.pBufferInfo = &buffInfo;
5943
5944 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5945 m_errorMonitor->VerifyFound();
5946
5947 vkDestroyBuffer(m_device->device(), dyub, NULL);
5948 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5949 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5950}
5951
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005952TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005953 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005954 ASSERT_NO_FATAL_FAILURE(InitState());
5955 ASSERT_NO_FATAL_FAILURE(InitViewport());
5956 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5957
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005958 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005959 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005960 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5961 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5962 pipeline_layout_ci.pushConstantRangeCount = 1;
5963 pipeline_layout_ci.pPushConstantRanges = &pc_range;
5964
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005965 //
5966 // Check for invalid push constant ranges in pipeline layouts.
5967 //
5968 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005969 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005970 char const *msg;
5971 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005972
Karl Schultzc81037d2016-05-12 08:11:23 -06005973 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
5974 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
5975 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5976 "vkCreatePipelineLayout() call has push constants index 0 with "
5977 "size 0."},
5978 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5979 "vkCreatePipelineLayout() call has push constants index 0 with "
5980 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005981 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06005982 "vkCreatePipelineLayout() call has push constants index 0 with "
5983 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005984 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06005985 "vkCreatePipelineLayout() call has push constants index 0 with "
5986 "size 0."},
5987 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5988 "vkCreatePipelineLayout() call has push constants index 0 with "
5989 "offset 1. Offset must"},
5990 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
5991 "vkCreatePipelineLayout() call has push constants index 0 "
5992 "with offset "},
5993 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
5994 "vkCreatePipelineLayout() call has push constants "
5995 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005996 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06005997 "vkCreatePipelineLayout() call has push constants index 0 "
5998 "with offset "},
5999 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6000 "vkCreatePipelineLayout() call has push "
6001 "constants index 0 with offset "},
6002 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6003 "vkCreatePipelineLayout() call has push "
6004 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006005 }};
6006
6007 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006008 for (const auto &iter : range_tests) {
6009 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6011 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006012 m_errorMonitor->VerifyFound();
6013 if (VK_SUCCESS == err) {
6014 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6015 }
6016 }
6017
6018 // Check for invalid stage flag
6019 pc_range.offset = 0;
6020 pc_range.size = 16;
6021 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006022 m_errorMonitor->SetDesiredFailureMsg(
6023 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6024 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006025 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006026 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006027 if (VK_SUCCESS == err) {
6028 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6029 }
6030
6031 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006032 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006033 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006034 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006035 char const *msg;
6036 };
6037
Karl Schultzc81037d2016-05-12 08:11:23 -06006038 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006039 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6040 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6041 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6042 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6043 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006044 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006045 {
6046 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6047 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6048 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6049 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6050 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006051 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006052 },
6053 {
6054 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6055 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6056 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6057 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6058 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006059 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006060 },
6061 {
6062 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6063 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6064 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6065 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6066 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006067 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006068 },
6069 {
6070 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6071 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6072 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6073 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6074 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006075 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006076 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006077
Karl Schultzc81037d2016-05-12 08:11:23 -06006078 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006079 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006080 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6082 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006083 m_errorMonitor->VerifyFound();
6084 if (VK_SUCCESS == err) {
6085 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6086 }
6087 }
6088
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006089 //
6090 // CmdPushConstants tests
6091 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006092 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006093
6094 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006095 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6096 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006097 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6098 "vkCmdPushConstants() call has push constants with size 1. Size "
6099 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006100 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006101 "vkCmdPushConstants() call has push constants with size 1. Size "
6102 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006103 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006104 "vkCmdPushConstants() call has push constants with offset 1. "
6105 "Offset must be a multiple of 4."},
6106 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6107 "vkCmdPushConstants() call has push constants with offset 1. "
6108 "Offset must be a multiple of 4."},
6109 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6110 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6111 "0x1 not within flag-matching ranges in pipeline layout"},
6112 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6113 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6114 "0x1 not within flag-matching ranges in pipeline layout"},
6115 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6116 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6117 "0x1 not within flag-matching ranges in pipeline layout"},
6118 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6119 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6120 "0x1 not within flag-matching ranges in pipeline layout"},
6121 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6122 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6123 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006124 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006125 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6126 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006127 }};
6128
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006129 BeginCommandBuffer();
6130
6131 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006132 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006133 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006134 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006135 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006136 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006137 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006138 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006139 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6141 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006142 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006143 m_errorMonitor->VerifyFound();
6144 }
6145
6146 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006148 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006149 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006150 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006151
Karl Schultzc81037d2016-05-12 08:11:23 -06006152 // overlapping range tests with cmd
6153 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6154 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6155 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6156 "0x1 not within flag-matching ranges in pipeline layout"},
6157 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6158 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6159 "0x1 not within flag-matching ranges in pipeline layout"},
6160 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6161 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6162 "0x1 not within flag-matching ranges in pipeline layout"},
6163 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006164 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006165 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006166 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6167 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006168 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006169 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006170 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006171 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006172 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006173 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6175 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006176 iter.range.size, dummy_values);
6177 m_errorMonitor->VerifyFound();
6178 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006179 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6180
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006181 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006182}
6183
Karl Schultz6addd812016-02-02 17:17:23 -07006184TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006185 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006186 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006187
6188 ASSERT_NO_FATAL_FAILURE(InitState());
6189 ASSERT_NO_FATAL_FAILURE(InitViewport());
6190 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6191
Mike Stroyanb8a61002016-06-20 16:00:28 -06006192 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6193 VkImageTiling tiling;
6194 VkFormatProperties format_properties;
6195 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006196 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006197 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006198 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006199 tiling = VK_IMAGE_TILING_OPTIMAL;
6200 } else {
6201 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6202 "skipped.\n");
6203 return;
6204 }
6205
Tobin Ehlis559c6382015-11-05 09:52:49 -07006206 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6207 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006208 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6209 ds_type_count[0].descriptorCount = 10;
6210 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6211 ds_type_count[1].descriptorCount = 2;
6212 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6213 ds_type_count[2].descriptorCount = 2;
6214 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6215 ds_type_count[3].descriptorCount = 5;
6216 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6217 // type
6218 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6219 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6220 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006221
6222 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006223 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6224 ds_pool_ci.pNext = NULL;
6225 ds_pool_ci.maxSets = 5;
6226 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6227 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006228
6229 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006230 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006231 ASSERT_VK_SUCCESS(err);
6232
6233 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6234 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006235 dsl_binding[0].binding = 0;
6236 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6237 dsl_binding[0].descriptorCount = 5;
6238 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6239 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006240
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006241 // Create layout identical to set0 layout but w/ different stageFlags
6242 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006243 dsl_fs_stage_only.binding = 0;
6244 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6245 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006246 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6247 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006248 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006249 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006250 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6251 ds_layout_ci.pNext = NULL;
6252 ds_layout_ci.bindingCount = 1;
6253 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006254 static const uint32_t NUM_LAYOUTS = 4;
6255 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006256 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006257 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6258 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006259 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006260 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006261 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006262 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006263 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006264 dsl_binding[0].binding = 0;
6265 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006266 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006267 dsl_binding[1].binding = 1;
6268 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6269 dsl_binding[1].descriptorCount = 2;
6270 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6271 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006272 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006273 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006274 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006275 ASSERT_VK_SUCCESS(err);
6276 dsl_binding[0].binding = 0;
6277 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006278 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006279 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006280 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006281 ASSERT_VK_SUCCESS(err);
6282 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006283 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006284 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006285 ASSERT_VK_SUCCESS(err);
6286
6287 static const uint32_t NUM_SETS = 4;
6288 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6289 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006290 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006291 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006292 alloc_info.descriptorPool = ds_pool;
6293 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006294 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006295 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006296 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006297 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006298 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006299 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006300 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006301
6302 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006303 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6304 pipeline_layout_ci.pNext = NULL;
6305 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6306 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006307
6308 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006309 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006310 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006311 // Create pipelineLayout with only one setLayout
6312 pipeline_layout_ci.setLayoutCount = 1;
6313 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006314 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006315 ASSERT_VK_SUCCESS(err);
6316 // Create pipelineLayout with 2 descriptor setLayout at index 0
6317 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6318 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006319 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006320 ASSERT_VK_SUCCESS(err);
6321 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6322 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6323 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006324 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006325 ASSERT_VK_SUCCESS(err);
6326 // Create pipelineLayout with UB type, but stageFlags for FS only
6327 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6328 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006329 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006330 ASSERT_VK_SUCCESS(err);
6331 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6332 VkDescriptorSetLayout pl_bad_s0[2] = {};
6333 pl_bad_s0[0] = ds_layout_fs_only;
6334 pl_bad_s0[1] = ds_layout[1];
6335 pipeline_layout_ci.setLayoutCount = 2;
6336 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6337 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006338 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006339 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006340
6341 // Create a buffer to update the descriptor with
6342 uint32_t qfi = 0;
6343 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006344 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6345 buffCI.size = 1024;
6346 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6347 buffCI.queueFamilyIndexCount = 1;
6348 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006349
6350 VkBuffer dyub;
6351 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6352 ASSERT_VK_SUCCESS(err);
6353 // Correctly update descriptor to avoid "NOT_UPDATED" error
6354 static const uint32_t NUM_BUFFS = 5;
6355 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006356 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006357 buffInfo[i].buffer = dyub;
6358 buffInfo[i].offset = 0;
6359 buffInfo[i].range = 1024;
6360 }
Karl Schultz6addd812016-02-02 17:17:23 -07006361 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006362 const int32_t tex_width = 32;
6363 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006364 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006365 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6366 image_create_info.pNext = NULL;
6367 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6368 image_create_info.format = tex_format;
6369 image_create_info.extent.width = tex_width;
6370 image_create_info.extent.height = tex_height;
6371 image_create_info.extent.depth = 1;
6372 image_create_info.mipLevels = 1;
6373 image_create_info.arrayLayers = 1;
6374 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006375 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006376 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006377 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006378 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6379 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006380
Karl Schultz6addd812016-02-02 17:17:23 -07006381 VkMemoryRequirements memReqs;
6382 VkDeviceMemory imageMem;
6383 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006384 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006385 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6386 memAlloc.pNext = NULL;
6387 memAlloc.allocationSize = 0;
6388 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006389 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6390 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006391 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006392 ASSERT_TRUE(pass);
6393 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6394 ASSERT_VK_SUCCESS(err);
6395 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6396 ASSERT_VK_SUCCESS(err);
6397
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006398 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006399 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6400 image_view_create_info.image = image;
6401 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6402 image_view_create_info.format = tex_format;
6403 image_view_create_info.subresourceRange.layerCount = 1;
6404 image_view_create_info.subresourceRange.baseMipLevel = 0;
6405 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006406 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006407
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006408 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006409 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006410 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006411 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006412 imageInfo[0].imageView = view;
6413 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6414 imageInfo[1].imageView = view;
6415 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006416 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006417 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006418 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006419 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006420
6421 static const uint32_t NUM_SET_UPDATES = 3;
6422 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6423 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6424 descriptor_write[0].dstSet = descriptorSet[0];
6425 descriptor_write[0].dstBinding = 0;
6426 descriptor_write[0].descriptorCount = 5;
6427 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6428 descriptor_write[0].pBufferInfo = buffInfo;
6429 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6430 descriptor_write[1].dstSet = descriptorSet[1];
6431 descriptor_write[1].dstBinding = 0;
6432 descriptor_write[1].descriptorCount = 2;
6433 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6434 descriptor_write[1].pImageInfo = imageInfo;
6435 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6436 descriptor_write[2].dstSet = descriptorSet[1];
6437 descriptor_write[2].dstBinding = 1;
6438 descriptor_write[2].descriptorCount = 2;
6439 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006440 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006441
6442 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006443
Tobin Ehlis88452832015-12-03 09:40:56 -07006444 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006445 char const *vsSource = "#version 450\n"
6446 "\n"
6447 "out gl_PerVertex {\n"
6448 " vec4 gl_Position;\n"
6449 "};\n"
6450 "void main(){\n"
6451 " gl_Position = vec4(1);\n"
6452 "}\n";
6453 char const *fsSource = "#version 450\n"
6454 "\n"
6455 "layout(location=0) out vec4 x;\n"
6456 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6457 "void main(){\n"
6458 " x = vec4(bar.y);\n"
6459 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006460 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6461 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006462 VkPipelineObj pipe(m_device);
6463 pipe.AddShader(&vs);
6464 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006465 pipe.AddColorAttachment();
6466 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006467
6468 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006469
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006470 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006471 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6472 // of PSO
6473 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6474 // cmd_pipeline.c
6475 // due to the fact that cmd_alloc_dset_data() has not been called in
6476 // cmd_bind_graphics_pipeline()
6477 // TODO : Want to cause various binding incompatibility issues here to test
6478 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006479 // First cause various verify_layout_compatibility() fails
6480 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006481 // verify_set_layout_compatibility fail cases:
6482 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6484 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6485 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006486 m_errorMonitor->VerifyFound();
6487
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006488 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6490 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6491 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006492 m_errorMonitor->VerifyFound();
6493
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006494 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006495 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6496 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6498 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6499 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006500 m_errorMonitor->VerifyFound();
6501
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006502 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6503 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6505 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6506 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006507 m_errorMonitor->VerifyFound();
6508
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006509 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6510 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6512 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6513 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6514 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006515 m_errorMonitor->VerifyFound();
6516
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006517 // Cause INFO messages due to disturbing previously bound Sets
6518 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006519 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6520 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006521 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6523 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6524 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006525 m_errorMonitor->VerifyFound();
6526
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006527 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6528 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006529 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6531 "any subsequent sets were disturbed ");
6532 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6533 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006534 m_errorMonitor->VerifyFound();
6535
Tobin Ehlis10fad692016-07-07 12:00:36 -06006536 // Now that we're done actively using the pipelineLayout that gfx pipeline
6537 // was created with, we should be able to delete it. Do that now to verify
6538 // that validation obeys pipelineLayout lifetime
6539 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6540
Tobin Ehlis88452832015-12-03 09:40:56 -07006541 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006542 // 1. Error due to not binding required set (we actually use same code as
6543 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006544 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6545 &descriptorSet[0], 0, NULL);
6546 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6547 &descriptorSet[1], 0, NULL);
6548 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 -07006549 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006550 m_errorMonitor->VerifyFound();
6551
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006552 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006553 // 2. Error due to bound set not being compatible with PSO's
6554 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006555 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6556 &descriptorSet[0], 0, NULL);
6557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006558 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006559 m_errorMonitor->VerifyFound();
6560
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006561 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006562 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006563 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6564 }
6565 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006566 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006567 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6568 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006569 vkFreeMemory(m_device->device(), imageMem, NULL);
6570 vkDestroyImage(m_device->device(), image, NULL);
6571 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006572}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006573
Karl Schultz6addd812016-02-02 17:17:23 -07006574TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006575
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6577 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006578
6579 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006580 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006581 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006582 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006583
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006584 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006585}
6586
Karl Schultz6addd812016-02-02 17:17:23 -07006587TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6588 VkResult err;
6589 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006590
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006592
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006593 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006594
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006595 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006596 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006597 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006598 cmd.commandPool = m_commandPool;
6599 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006600 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006601
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006602 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006603 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006604
6605 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006606 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006607 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006608 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006609 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006610 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 -07006611 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006612
6613 // The error should be caught by validation of the BeginCommandBuffer call
6614 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6615
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006616 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006617 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006618}
6619
Karl Schultz6addd812016-02-02 17:17:23 -07006620TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006621 // Cause error due to Begin while recording CB
6622 // Then cause 2 errors for attempting to reset CB w/o having
6623 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6624 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006626
6627 ASSERT_NO_FATAL_FAILURE(InitState());
6628
6629 // Calls AllocateCommandBuffers
6630 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6631
Karl Schultz6addd812016-02-02 17:17:23 -07006632 // Force the failure by setting the Renderpass and Framebuffer fields with
6633 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006634 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006635 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006636 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6637 cmd_buf_info.pNext = NULL;
6638 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006639 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006640
6641 // Begin CB to transition to recording state
6642 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6643 // Can't re-begin. This should trigger error
6644 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006645 m_errorMonitor->VerifyFound();
6646
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006648 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6649 // Reset attempt will trigger error due to incorrect CommandPool state
6650 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006651 m_errorMonitor->VerifyFound();
6652
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006654 // Transition CB to RECORDED state
6655 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6656 // Now attempting to Begin will implicitly reset, which triggers error
6657 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006658 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006659}
6660
Karl Schultz6addd812016-02-02 17:17:23 -07006661TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006662 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006663 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006664
Mike Weiblencce7ec72016-10-17 19:33:05 -06006665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006666
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006667 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006668 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006669
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006670 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006671 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6672 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006673
6674 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006675 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6676 ds_pool_ci.pNext = NULL;
6677 ds_pool_ci.maxSets = 1;
6678 ds_pool_ci.poolSizeCount = 1;
6679 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006680
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006681 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006682 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006683 ASSERT_VK_SUCCESS(err);
6684
Tony Barboureb254902015-07-15 12:50:33 -06006685 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006686 dsl_binding.binding = 0;
6687 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6688 dsl_binding.descriptorCount = 1;
6689 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6690 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006691
Tony Barboureb254902015-07-15 12:50:33 -06006692 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006693 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6694 ds_layout_ci.pNext = NULL;
6695 ds_layout_ci.bindingCount = 1;
6696 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006697
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006698 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006699 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006700 ASSERT_VK_SUCCESS(err);
6701
6702 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006703 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006704 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006705 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006706 alloc_info.descriptorPool = ds_pool;
6707 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006708 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006709 ASSERT_VK_SUCCESS(err);
6710
Tony Barboureb254902015-07-15 12:50:33 -06006711 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006712 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6713 pipeline_layout_ci.setLayoutCount = 1;
6714 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006715
6716 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006717 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006718 ASSERT_VK_SUCCESS(err);
6719
Tobin Ehlise68360f2015-10-01 11:15:13 -06006720 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006721 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006722
6723 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006724 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6725 vp_state_ci.scissorCount = 1;
6726 vp_state_ci.pScissors = &sc;
6727 vp_state_ci.viewportCount = 1;
6728 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006729
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006730 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6731 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6732 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6733 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6734 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6735 rs_state_ci.depthClampEnable = VK_FALSE;
6736 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6737 rs_state_ci.depthBiasEnable = VK_FALSE;
6738
Tony Barboureb254902015-07-15 12:50:33 -06006739 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006740 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6741 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006742 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006743 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6744 gp_ci.layout = pipeline_layout;
6745 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006746
6747 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006748 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6749 pc_ci.initialDataSize = 0;
6750 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006751
6752 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006753 VkPipelineCache pipelineCache;
6754
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006755 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006756 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006757 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006758
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006759 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006760
Chia-I Wuf7458c52015-10-26 21:10:41 +08006761 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6762 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6763 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6764 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006765}
Tobin Ehlis912df022015-09-17 08:46:18 -06006766/*// TODO : This test should be good, but needs Tess support in compiler to run
6767TEST_F(VkLayerTest, InvalidPatchControlPoints)
6768{
6769 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006770 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006771
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006773 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6774primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006775
Tobin Ehlis912df022015-09-17 08:46:18 -06006776 ASSERT_NO_FATAL_FAILURE(InitState());
6777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006778
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006779 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006780 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006781 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006782
6783 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6784 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6785 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006786 ds_pool_ci.poolSizeCount = 1;
6787 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006788
6789 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006790 err = vkCreateDescriptorPool(m_device->device(),
6791VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006792 ASSERT_VK_SUCCESS(err);
6793
6794 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006795 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006796 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006797 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006798 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6799 dsl_binding.pImmutableSamplers = NULL;
6800
6801 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006802 ds_layout_ci.sType =
6803VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006804 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006805 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006806 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006807
6808 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006809 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6810&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006811 ASSERT_VK_SUCCESS(err);
6812
6813 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006814 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6815VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006816 ASSERT_VK_SUCCESS(err);
6817
6818 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006819 pipeline_layout_ci.sType =
6820VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006821 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006822 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006823 pipeline_layout_ci.pSetLayouts = &ds_layout;
6824
6825 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006826 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6827&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006828 ASSERT_VK_SUCCESS(err);
6829
6830 VkPipelineShaderStageCreateInfo shaderStages[3];
6831 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6832
Karl Schultz6addd812016-02-02 17:17:23 -07006833 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6834this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006835 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006836 VkShaderObj
6837tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6838this);
6839 VkShaderObj
6840te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6841this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006842
Karl Schultz6addd812016-02-02 17:17:23 -07006843 shaderStages[0].sType =
6844VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006845 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006846 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006847 shaderStages[1].sType =
6848VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006849 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006850 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006851 shaderStages[2].sType =
6852VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006853 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006854 shaderStages[2].shader = te.handle();
6855
6856 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006857 iaCI.sType =
6858VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006859 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006860
6861 VkPipelineTessellationStateCreateInfo tsCI = {};
6862 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6863 tsCI.patchControlPoints = 0; // This will cause an error
6864
6865 VkGraphicsPipelineCreateInfo gp_ci = {};
6866 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6867 gp_ci.pNext = NULL;
6868 gp_ci.stageCount = 3;
6869 gp_ci.pStages = shaderStages;
6870 gp_ci.pVertexInputState = NULL;
6871 gp_ci.pInputAssemblyState = &iaCI;
6872 gp_ci.pTessellationState = &tsCI;
6873 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006874 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006875 gp_ci.pMultisampleState = NULL;
6876 gp_ci.pDepthStencilState = NULL;
6877 gp_ci.pColorBlendState = NULL;
6878 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6879 gp_ci.layout = pipeline_layout;
6880 gp_ci.renderPass = renderPass();
6881
6882 VkPipelineCacheCreateInfo pc_ci = {};
6883 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6884 pc_ci.pNext = NULL;
6885 pc_ci.initialSize = 0;
6886 pc_ci.initialData = 0;
6887 pc_ci.maxSize = 0;
6888
6889 VkPipeline pipeline;
6890 VkPipelineCache pipelineCache;
6891
Karl Schultz6addd812016-02-02 17:17:23 -07006892 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6893&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006894 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006895 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6896&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006897
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006898 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006899
Chia-I Wuf7458c52015-10-26 21:10:41 +08006900 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6901 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6902 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6903 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006904}
6905*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006906// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006907TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006908 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006909
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6911 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006912
Tobin Ehlise68360f2015-10-01 11:15:13 -06006913 ASSERT_NO_FATAL_FAILURE(InitState());
6914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006915
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006916 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006917 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6918 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006919
6920 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006921 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6922 ds_pool_ci.maxSets = 1;
6923 ds_pool_ci.poolSizeCount = 1;
6924 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006925
6926 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006927 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006928 ASSERT_VK_SUCCESS(err);
6929
6930 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006931 dsl_binding.binding = 0;
6932 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6933 dsl_binding.descriptorCount = 1;
6934 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006935
6936 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006937 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6938 ds_layout_ci.bindingCount = 1;
6939 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006940
6941 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006942 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006943 ASSERT_VK_SUCCESS(err);
6944
6945 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006946 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006947 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006948 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006949 alloc_info.descriptorPool = ds_pool;
6950 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006951 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006952 ASSERT_VK_SUCCESS(err);
6953
6954 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006955 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6956 pipeline_layout_ci.setLayoutCount = 1;
6957 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006958
6959 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006960 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006961 ASSERT_VK_SUCCESS(err);
6962
6963 VkViewport vp = {}; // Just need dummy vp to point to
6964
6965 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006966 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6967 vp_state_ci.scissorCount = 0;
6968 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
6969 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006970
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006971 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6972 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6973 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6974 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6975 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6976 rs_state_ci.depthClampEnable = VK_FALSE;
6977 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6978 rs_state_ci.depthBiasEnable = VK_FALSE;
6979
Cody Northropeb3a6c12015-10-05 14:44:45 -06006980 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006981 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006983 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
6984 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
6985 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006986 shaderStages[0] = vs.GetStageCreateInfo();
6987 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006988
6989 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006990 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6991 gp_ci.stageCount = 2;
6992 gp_ci.pStages = shaderStages;
6993 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006994 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006995 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6996 gp_ci.layout = pipeline_layout;
6997 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006998
6999 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007000 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007001
7002 VkPipeline pipeline;
7003 VkPipelineCache pipelineCache;
7004
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007005 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007006 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007007 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007008
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007009 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007010
Chia-I Wuf7458c52015-10-26 21:10:41 +08007011 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7012 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7013 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7014 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007015}
Karl Schultz6addd812016-02-02 17:17:23 -07007016// Don't set viewport state in PSO. This is an error b/c we always need this
7017// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007018// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007019TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007020 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007021 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007022
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007024
Tobin Ehlise68360f2015-10-01 11:15:13 -06007025 ASSERT_NO_FATAL_FAILURE(InitState());
7026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007027
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007028 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007029 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7030 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007031
7032 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007033 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7034 ds_pool_ci.maxSets = 1;
7035 ds_pool_ci.poolSizeCount = 1;
7036 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007037
7038 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007039 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007040 ASSERT_VK_SUCCESS(err);
7041
7042 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007043 dsl_binding.binding = 0;
7044 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7045 dsl_binding.descriptorCount = 1;
7046 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007047
7048 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007049 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7050 ds_layout_ci.bindingCount = 1;
7051 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007052
7053 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007054 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007055 ASSERT_VK_SUCCESS(err);
7056
7057 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007058 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007059 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007060 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007061 alloc_info.descriptorPool = ds_pool;
7062 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007063 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007064 ASSERT_VK_SUCCESS(err);
7065
7066 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007067 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7068 pipeline_layout_ci.setLayoutCount = 1;
7069 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007070
7071 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007072 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007073 ASSERT_VK_SUCCESS(err);
7074
7075 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7076 // Set scissor as dynamic to avoid second error
7077 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007078 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7079 dyn_state_ci.dynamicStateCount = 1;
7080 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007081
Cody Northropeb3a6c12015-10-05 14:44:45 -06007082 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007083 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007084
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007085 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7086 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7087 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007088 shaderStages[0] = vs.GetStageCreateInfo();
7089 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007090
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007091 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7092 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7093 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7094 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7095 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7096 rs_state_ci.depthClampEnable = VK_FALSE;
7097 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7098 rs_state_ci.depthBiasEnable = VK_FALSE;
7099
Tobin Ehlise68360f2015-10-01 11:15:13 -06007100 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007101 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7102 gp_ci.stageCount = 2;
7103 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007104 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007105 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7106 // should cause validation error
7107 gp_ci.pDynamicState = &dyn_state_ci;
7108 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7109 gp_ci.layout = pipeline_layout;
7110 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007111
7112 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007113 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007114
7115 VkPipeline pipeline;
7116 VkPipelineCache pipelineCache;
7117
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007118 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007119 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007120 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007121
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007122 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007123
Chia-I Wuf7458c52015-10-26 21:10:41 +08007124 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7125 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7126 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7127 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007128}
7129// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007130// Then run second test where dynamic scissor count doesn't match PSO scissor
7131// count
7132TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7133 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007134
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7136 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007137
Tobin Ehlise68360f2015-10-01 11:15:13 -06007138 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007139
7140 if (!m_device->phy().features().multiViewport) {
7141 printf("Device does not support multiple viewports/scissors; skipped.\n");
7142 return;
7143 }
7144
Tobin Ehlise68360f2015-10-01 11:15:13 -06007145 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007146
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007147 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007148 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7149 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007150
7151 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007152 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7153 ds_pool_ci.maxSets = 1;
7154 ds_pool_ci.poolSizeCount = 1;
7155 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007156
7157 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007158 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007159 ASSERT_VK_SUCCESS(err);
7160
7161 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007162 dsl_binding.binding = 0;
7163 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7164 dsl_binding.descriptorCount = 1;
7165 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007166
7167 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007168 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7169 ds_layout_ci.bindingCount = 1;
7170 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007171
7172 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007173 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007174 ASSERT_VK_SUCCESS(err);
7175
7176 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007177 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007178 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007179 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007180 alloc_info.descriptorPool = ds_pool;
7181 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007182 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007183 ASSERT_VK_SUCCESS(err);
7184
7185 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007186 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7187 pipeline_layout_ci.setLayoutCount = 1;
7188 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007189
7190 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007191 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007192 ASSERT_VK_SUCCESS(err);
7193
7194 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007195 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7196 vp_state_ci.viewportCount = 1;
7197 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7198 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007199 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007200
7201 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7202 // Set scissor as dynamic to avoid that error
7203 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007204 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7205 dyn_state_ci.dynamicStateCount = 1;
7206 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007207
Cody Northropeb3a6c12015-10-05 14:44:45 -06007208 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007209 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007210
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007211 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7212 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7213 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007214 shaderStages[0] = vs.GetStageCreateInfo();
7215 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007216
Cody Northropf6622dc2015-10-06 10:33:21 -06007217 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7218 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7219 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007220 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007221 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007222 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007223 vi_ci.pVertexAttributeDescriptions = nullptr;
7224
7225 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7226 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7227 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7228
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007229 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007230 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007231 rs_ci.pNext = nullptr;
7232
Mark Youngc89c6312016-03-31 16:03:20 -06007233 VkPipelineColorBlendAttachmentState att = {};
7234 att.blendEnable = VK_FALSE;
7235 att.colorWriteMask = 0xf;
7236
Cody Northropf6622dc2015-10-06 10:33:21 -06007237 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7238 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7239 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007240 cb_ci.attachmentCount = 1;
7241 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007242
Tobin Ehlise68360f2015-10-01 11:15:13 -06007243 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007244 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7245 gp_ci.stageCount = 2;
7246 gp_ci.pStages = shaderStages;
7247 gp_ci.pVertexInputState = &vi_ci;
7248 gp_ci.pInputAssemblyState = &ia_ci;
7249 gp_ci.pViewportState = &vp_state_ci;
7250 gp_ci.pRasterizationState = &rs_ci;
7251 gp_ci.pColorBlendState = &cb_ci;
7252 gp_ci.pDynamicState = &dyn_state_ci;
7253 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7254 gp_ci.layout = pipeline_layout;
7255 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007256
7257 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007258 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007259
7260 VkPipeline pipeline;
7261 VkPipelineCache pipelineCache;
7262
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007263 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007264 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007265 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007266
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007267 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007268
Tobin Ehlisd332f282015-10-02 11:00:56 -06007269 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007270 // First need to successfully create the PSO from above by setting
7271 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007272 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 -07007273
7274 VkViewport vp = {}; // Just need dummy vp to point to
7275 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007276 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007277 ASSERT_VK_SUCCESS(err);
7278 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007279 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007280 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007281 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007282 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007283 Draw(1, 0, 0, 0);
7284
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007285 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007286
7287 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7288 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7289 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7290 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007291 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007292}
7293// Create PSO w/o non-zero scissorCount but no scissor data
7294// Then run second test where dynamic viewportCount doesn't match PSO
7295// viewportCount
7296TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7297 VkResult err;
7298
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007299 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 -07007300
7301 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007302
7303 if (!m_device->phy().features().multiViewport) {
7304 printf("Device does not support multiple viewports/scissors; skipped.\n");
7305 return;
7306 }
7307
Karl Schultz6addd812016-02-02 17:17:23 -07007308 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7309
7310 VkDescriptorPoolSize ds_type_count = {};
7311 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7312 ds_type_count.descriptorCount = 1;
7313
7314 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7315 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7316 ds_pool_ci.maxSets = 1;
7317 ds_pool_ci.poolSizeCount = 1;
7318 ds_pool_ci.pPoolSizes = &ds_type_count;
7319
7320 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007321 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007322 ASSERT_VK_SUCCESS(err);
7323
7324 VkDescriptorSetLayoutBinding dsl_binding = {};
7325 dsl_binding.binding = 0;
7326 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7327 dsl_binding.descriptorCount = 1;
7328 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7329
7330 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7331 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7332 ds_layout_ci.bindingCount = 1;
7333 ds_layout_ci.pBindings = &dsl_binding;
7334
7335 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007336 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007337 ASSERT_VK_SUCCESS(err);
7338
7339 VkDescriptorSet descriptorSet;
7340 VkDescriptorSetAllocateInfo alloc_info = {};
7341 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7342 alloc_info.descriptorSetCount = 1;
7343 alloc_info.descriptorPool = ds_pool;
7344 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007345 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007346 ASSERT_VK_SUCCESS(err);
7347
7348 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7349 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7350 pipeline_layout_ci.setLayoutCount = 1;
7351 pipeline_layout_ci.pSetLayouts = &ds_layout;
7352
7353 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007354 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007355 ASSERT_VK_SUCCESS(err);
7356
7357 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7358 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7359 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007360 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007361 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007362 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007363
7364 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7365 // Set scissor as dynamic to avoid that error
7366 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7367 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7368 dyn_state_ci.dynamicStateCount = 1;
7369 dyn_state_ci.pDynamicStates = &vp_state;
7370
7371 VkPipelineShaderStageCreateInfo shaderStages[2];
7372 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7373
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007374 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7375 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7376 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007377 shaderStages[0] = vs.GetStageCreateInfo();
7378 shaderStages[1] = fs.GetStageCreateInfo();
7379
7380 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7381 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7382 vi_ci.pNext = nullptr;
7383 vi_ci.vertexBindingDescriptionCount = 0;
7384 vi_ci.pVertexBindingDescriptions = nullptr;
7385 vi_ci.vertexAttributeDescriptionCount = 0;
7386 vi_ci.pVertexAttributeDescriptions = nullptr;
7387
7388 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7389 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7390 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7391
7392 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7393 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7394 rs_ci.pNext = nullptr;
7395
Mark Youngc89c6312016-03-31 16:03:20 -06007396 VkPipelineColorBlendAttachmentState att = {};
7397 att.blendEnable = VK_FALSE;
7398 att.colorWriteMask = 0xf;
7399
Karl Schultz6addd812016-02-02 17:17:23 -07007400 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7401 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7402 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007403 cb_ci.attachmentCount = 1;
7404 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007405
7406 VkGraphicsPipelineCreateInfo gp_ci = {};
7407 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7408 gp_ci.stageCount = 2;
7409 gp_ci.pStages = shaderStages;
7410 gp_ci.pVertexInputState = &vi_ci;
7411 gp_ci.pInputAssemblyState = &ia_ci;
7412 gp_ci.pViewportState = &vp_state_ci;
7413 gp_ci.pRasterizationState = &rs_ci;
7414 gp_ci.pColorBlendState = &cb_ci;
7415 gp_ci.pDynamicState = &dyn_state_ci;
7416 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7417 gp_ci.layout = pipeline_layout;
7418 gp_ci.renderPass = renderPass();
7419
7420 VkPipelineCacheCreateInfo pc_ci = {};
7421 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7422
7423 VkPipeline pipeline;
7424 VkPipelineCache pipelineCache;
7425
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007426 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007427 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007428 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007429
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007430 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007431
7432 // Now hit second fail case where we set scissor w/ different count than PSO
7433 // First need to successfully create the PSO from above by setting
7434 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007435 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 -06007436
Tobin Ehlisd332f282015-10-02 11:00:56 -06007437 VkRect2D sc = {}; // Just need dummy vp to point to
7438 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007439 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007440 ASSERT_VK_SUCCESS(err);
7441 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007442 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007443 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007444 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007445 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007446 Draw(1, 0, 0, 0);
7447
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007448 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007449
Chia-I Wuf7458c52015-10-26 21:10:41 +08007450 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7451 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7452 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7453 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007454 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007455}
7456
Mark Young7394fdd2016-03-31 14:56:43 -06007457TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7458 VkResult err;
7459
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007461
7462 ASSERT_NO_FATAL_FAILURE(InitState());
7463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7464
7465 VkDescriptorPoolSize ds_type_count = {};
7466 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7467 ds_type_count.descriptorCount = 1;
7468
7469 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7470 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7471 ds_pool_ci.maxSets = 1;
7472 ds_pool_ci.poolSizeCount = 1;
7473 ds_pool_ci.pPoolSizes = &ds_type_count;
7474
7475 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007476 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007477 ASSERT_VK_SUCCESS(err);
7478
7479 VkDescriptorSetLayoutBinding dsl_binding = {};
7480 dsl_binding.binding = 0;
7481 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7482 dsl_binding.descriptorCount = 1;
7483 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7484
7485 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7486 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7487 ds_layout_ci.bindingCount = 1;
7488 ds_layout_ci.pBindings = &dsl_binding;
7489
7490 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007491 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007492 ASSERT_VK_SUCCESS(err);
7493
7494 VkDescriptorSet descriptorSet;
7495 VkDescriptorSetAllocateInfo alloc_info = {};
7496 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7497 alloc_info.descriptorSetCount = 1;
7498 alloc_info.descriptorPool = ds_pool;
7499 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007500 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007501 ASSERT_VK_SUCCESS(err);
7502
7503 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7504 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7505 pipeline_layout_ci.setLayoutCount = 1;
7506 pipeline_layout_ci.pSetLayouts = &ds_layout;
7507
7508 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007509 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007510 ASSERT_VK_SUCCESS(err);
7511
7512 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7513 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7514 vp_state_ci.scissorCount = 1;
7515 vp_state_ci.pScissors = NULL;
7516 vp_state_ci.viewportCount = 1;
7517 vp_state_ci.pViewports = NULL;
7518
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007519 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007520 // Set scissor as dynamic to avoid that error
7521 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7522 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7523 dyn_state_ci.dynamicStateCount = 2;
7524 dyn_state_ci.pDynamicStates = dynamic_states;
7525
7526 VkPipelineShaderStageCreateInfo shaderStages[2];
7527 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7528
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007529 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7530 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007531 this); // TODO - We shouldn't need a fragment shader
7532 // but add it to be able to run on more devices
7533 shaderStages[0] = vs.GetStageCreateInfo();
7534 shaderStages[1] = fs.GetStageCreateInfo();
7535
7536 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7537 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7538 vi_ci.pNext = nullptr;
7539 vi_ci.vertexBindingDescriptionCount = 0;
7540 vi_ci.pVertexBindingDescriptions = nullptr;
7541 vi_ci.vertexAttributeDescriptionCount = 0;
7542 vi_ci.pVertexAttributeDescriptions = nullptr;
7543
7544 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7545 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7546 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7547
7548 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7549 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7550 rs_ci.pNext = nullptr;
7551
Mark Young47107952016-05-02 15:59:55 -06007552 // Check too low (line width of -1.0f).
7553 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007554
7555 VkPipelineColorBlendAttachmentState att = {};
7556 att.blendEnable = VK_FALSE;
7557 att.colorWriteMask = 0xf;
7558
7559 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7560 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7561 cb_ci.pNext = nullptr;
7562 cb_ci.attachmentCount = 1;
7563 cb_ci.pAttachments = &att;
7564
7565 VkGraphicsPipelineCreateInfo gp_ci = {};
7566 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7567 gp_ci.stageCount = 2;
7568 gp_ci.pStages = shaderStages;
7569 gp_ci.pVertexInputState = &vi_ci;
7570 gp_ci.pInputAssemblyState = &ia_ci;
7571 gp_ci.pViewportState = &vp_state_ci;
7572 gp_ci.pRasterizationState = &rs_ci;
7573 gp_ci.pColorBlendState = &cb_ci;
7574 gp_ci.pDynamicState = &dyn_state_ci;
7575 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7576 gp_ci.layout = pipeline_layout;
7577 gp_ci.renderPass = renderPass();
7578
7579 VkPipelineCacheCreateInfo pc_ci = {};
7580 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7581
7582 VkPipeline pipeline;
7583 VkPipelineCache pipelineCache;
7584
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007585 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007586 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007587 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007588
7589 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007590 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007591
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007593
7594 // Check too high (line width of 65536.0f).
7595 rs_ci.lineWidth = 65536.0f;
7596
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007597 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007598 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007599 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007600
7601 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007602 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007603
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007605
7606 dyn_state_ci.dynamicStateCount = 3;
7607
7608 rs_ci.lineWidth = 1.0f;
7609
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007610 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007611 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007612 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007613 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007614 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007615
7616 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007617 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007618 m_errorMonitor->VerifyFound();
7619
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007621
7622 // Check too high with dynamic setting.
7623 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7624 m_errorMonitor->VerifyFound();
7625 EndCommandBuffer();
7626
7627 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7628 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7629 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7630 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007631 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007632}
7633
Karl Schultz6addd812016-02-02 17:17:23 -07007634TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007635 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7637 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007638
7639 ASSERT_NO_FATAL_FAILURE(InitState());
7640 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007641
Tony Barbourfe3351b2015-07-28 10:17:20 -06007642 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007643 // Don't care about RenderPass handle b/c error should be flagged before
7644 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007645 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007646
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007647 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007648}
7649
Karl Schultz6addd812016-02-02 17:17:23 -07007650TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007651 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7653 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007654
7655 ASSERT_NO_FATAL_FAILURE(InitState());
7656 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007657
Tony Barbourfe3351b2015-07-28 10:17:20 -06007658 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007659 // Just create a dummy Renderpass that's non-NULL so we can get to the
7660 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007661 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007662
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007663 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007664}
7665
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007666TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7667 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7668 "the number of renderPass attachments that use loadOp"
7669 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7670
7671 ASSERT_NO_FATAL_FAILURE(InitState());
7672 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7673
7674 // Create a renderPass with a single attachment that uses loadOp CLEAR
7675 VkAttachmentReference attach = {};
7676 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7677 VkSubpassDescription subpass = {};
7678 subpass.inputAttachmentCount = 1;
7679 subpass.pInputAttachments = &attach;
7680 VkRenderPassCreateInfo rpci = {};
7681 rpci.subpassCount = 1;
7682 rpci.pSubpasses = &subpass;
7683 rpci.attachmentCount = 1;
7684 VkAttachmentDescription attach_desc = {};
7685 attach_desc.format = VK_FORMAT_UNDEFINED;
7686 // Set loadOp to CLEAR
7687 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7688 rpci.pAttachments = &attach_desc;
7689 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7690 VkRenderPass rp;
7691 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7692
7693 VkCommandBufferInheritanceInfo hinfo = {};
7694 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7695 hinfo.renderPass = VK_NULL_HANDLE;
7696 hinfo.subpass = 0;
7697 hinfo.framebuffer = VK_NULL_HANDLE;
7698 hinfo.occlusionQueryEnable = VK_FALSE;
7699 hinfo.queryFlags = 0;
7700 hinfo.pipelineStatistics = 0;
7701 VkCommandBufferBeginInfo info = {};
7702 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7703 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7704 info.pInheritanceInfo = &hinfo;
7705
7706 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7707 VkRenderPassBeginInfo rp_begin = {};
7708 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7709 rp_begin.pNext = NULL;
7710 rp_begin.renderPass = renderPass();
7711 rp_begin.framebuffer = framebuffer();
7712 rp_begin.clearValueCount = 0; // Should be 1
7713
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7715 "there must be at least 1 entries in "
7716 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007717
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007718 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007719
7720 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007721
7722 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007723}
7724
Cody Northrop3bb4d962016-05-09 16:15:57 -06007725TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7726
7727 TEST_DESCRIPTION("End a command buffer with an active render pass");
7728
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7730 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007731
7732 ASSERT_NO_FATAL_FAILURE(InitState());
7733 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7734
7735 // The framework's BeginCommandBuffer calls CreateRenderPass
7736 BeginCommandBuffer();
7737
7738 // Call directly into vkEndCommandBuffer instead of the
7739 // the framework's EndCommandBuffer, which inserts a
7740 // vkEndRenderPass
7741 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7742
7743 m_errorMonitor->VerifyFound();
7744
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007745 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7746 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007747}
7748
Karl Schultz6addd812016-02-02 17:17:23 -07007749TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007750 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7752 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007753
7754 ASSERT_NO_FATAL_FAILURE(InitState());
7755 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007756
7757 // Renderpass is started here
7758 BeginCommandBuffer();
7759
7760 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007761 vk_testing::Buffer dstBuffer;
7762 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007763
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007764 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007765
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007766 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007767}
7768
Karl Schultz6addd812016-02-02 17:17:23 -07007769TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007770 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7772 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007773
7774 ASSERT_NO_FATAL_FAILURE(InitState());
7775 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007776
7777 // Renderpass is started here
7778 BeginCommandBuffer();
7779
7780 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007781 vk_testing::Buffer dstBuffer;
7782 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007783
Karl Schultz6addd812016-02-02 17:17:23 -07007784 VkDeviceSize dstOffset = 0;
7785 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007786 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007787
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007788 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007789
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007790 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007791}
7792
Karl Schultz6addd812016-02-02 17:17:23 -07007793TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007794 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7796 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007797
7798 ASSERT_NO_FATAL_FAILURE(InitState());
7799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007800
7801 // Renderpass is started here
7802 BeginCommandBuffer();
7803
Michael Lentine0a369f62016-02-03 16:51:46 -06007804 VkClearColorValue clear_color;
7805 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007806 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7807 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7808 const int32_t tex_width = 32;
7809 const int32_t tex_height = 32;
7810 VkImageCreateInfo image_create_info = {};
7811 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7812 image_create_info.pNext = NULL;
7813 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7814 image_create_info.format = tex_format;
7815 image_create_info.extent.width = tex_width;
7816 image_create_info.extent.height = tex_height;
7817 image_create_info.extent.depth = 1;
7818 image_create_info.mipLevels = 1;
7819 image_create_info.arrayLayers = 1;
7820 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7821 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7822 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007823
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007824 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007825 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007826
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007827 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007828
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007829 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007830
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007831 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007832}
7833
Karl Schultz6addd812016-02-02 17:17:23 -07007834TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007835 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7837 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007838
7839 ASSERT_NO_FATAL_FAILURE(InitState());
7840 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007841
7842 // Renderpass is started here
7843 BeginCommandBuffer();
7844
7845 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007846 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007847 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7848 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7849 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7850 image_create_info.extent.width = 64;
7851 image_create_info.extent.height = 64;
7852 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7853 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007854
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007855 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007856 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007857
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007858 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007859
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007860 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7861 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007862
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007863 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007864}
7865
Karl Schultz6addd812016-02-02 17:17:23 -07007866TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007867 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007868 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007869
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
7871 "must be issued inside an active "
7872 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007873
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007874 ASSERT_NO_FATAL_FAILURE(InitState());
7875 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007876
7877 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007878 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007879 ASSERT_VK_SUCCESS(err);
7880
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007881 VkClearAttachment color_attachment;
7882 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7883 color_attachment.clearValue.color.float32[0] = 0;
7884 color_attachment.clearValue.color.float32[1] = 0;
7885 color_attachment.clearValue.color.float32[2] = 0;
7886 color_attachment.clearValue.color.float32[3] = 0;
7887 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007888 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007889 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007890
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007891 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007892}
7893
Chris Forbes3b97e932016-09-07 11:29:24 +12007894TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
7895 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
7896 "called too many times in a renderpass instance");
7897
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
7899 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12007900
7901 ASSERT_NO_FATAL_FAILURE(InitState());
7902 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7903
7904 BeginCommandBuffer();
7905
7906 // error here.
7907 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
7908 m_errorMonitor->VerifyFound();
7909
7910 EndCommandBuffer();
7911}
7912
Chris Forbes6d624702016-09-07 13:57:05 +12007913TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
7914 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
7915 "called before the final subpass has been reached");
7916
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
7918 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12007919
7920 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007921 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
7922 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12007923
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007924 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12007925
7926 VkRenderPass rp;
7927 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
7928 ASSERT_VK_SUCCESS(err);
7929
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007930 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12007931
7932 VkFramebuffer fb;
7933 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
7934 ASSERT_VK_SUCCESS(err);
7935
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007936 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12007937
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007938 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 +12007939
7940 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
7941
7942 // Error here.
7943 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7944 m_errorMonitor->VerifyFound();
7945
7946 // Clean up.
7947 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
7948 vkDestroyRenderPass(m_device->device(), rp, nullptr);
7949}
7950
Karl Schultz9e66a292016-04-21 15:57:51 -06007951TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
7952 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7954 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06007955
7956 ASSERT_NO_FATAL_FAILURE(InitState());
7957 BeginCommandBuffer();
7958
7959 VkBufferMemoryBarrier buf_barrier = {};
7960 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7961 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7962 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7963 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7964 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7965 buf_barrier.buffer = VK_NULL_HANDLE;
7966 buf_barrier.offset = 0;
7967 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007968 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7969 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06007970
7971 m_errorMonitor->VerifyFound();
7972}
7973
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007974TEST_F(VkLayerTest, InvalidBarriers) {
7975 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
7976
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007978
7979 ASSERT_NO_FATAL_FAILURE(InitState());
7980 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7981
7982 VkMemoryBarrier mem_barrier = {};
7983 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
7984 mem_barrier.pNext = NULL;
7985 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7986 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7987 BeginCommandBuffer();
7988 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007989 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007990 &mem_barrier, 0, nullptr, 0, nullptr);
7991 m_errorMonitor->VerifyFound();
7992
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007994 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007995 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 -06007996 ASSERT_TRUE(image.initialized());
7997 VkImageMemoryBarrier img_barrier = {};
7998 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
7999 img_barrier.pNext = NULL;
8000 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8001 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8002 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8003 // New layout can't be UNDEFINED
8004 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8005 img_barrier.image = image.handle();
8006 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8007 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8008 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8009 img_barrier.subresourceRange.baseArrayLayer = 0;
8010 img_barrier.subresourceRange.baseMipLevel = 0;
8011 img_barrier.subresourceRange.layerCount = 1;
8012 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008013 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8014 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008015 m_errorMonitor->VerifyFound();
8016 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8019 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008020 // baseArrayLayer + layerCount must be <= image's arrayLayers
8021 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008022 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8023 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008024 m_errorMonitor->VerifyFound();
8025 img_barrier.subresourceRange.baseArrayLayer = 0;
8026
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008028 // baseMipLevel + levelCount must be <= image's mipLevels
8029 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008030 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8031 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008032 m_errorMonitor->VerifyFound();
8033 img_barrier.subresourceRange.baseMipLevel = 0;
8034
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008035 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 -06008036 vk_testing::Buffer buffer;
8037 buffer.init(*m_device, 256);
8038 VkBufferMemoryBarrier buf_barrier = {};
8039 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8040 buf_barrier.pNext = NULL;
8041 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8042 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8043 buf_barrier.buffer = buffer.handle();
8044 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8045 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8046 buf_barrier.offset = 0;
8047 buf_barrier.size = VK_WHOLE_SIZE;
8048 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008049 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8050 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008051 m_errorMonitor->VerifyFound();
8052 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8053
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008055 buf_barrier.offset = 257;
8056 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008057 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8058 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008059 m_errorMonitor->VerifyFound();
8060 buf_barrier.offset = 0;
8061
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008063 buf_barrier.size = 257;
8064 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008065 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8066 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008067 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008068
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008069 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008070 m_errorMonitor->SetDesiredFailureMsg(
8071 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8072 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8073 m_errorMonitor->SetDesiredFailureMsg(
8074 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8075 "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 -06008076 VkDepthStencilObj ds_image(m_device);
8077 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8078 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008079 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8080 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008081 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008082 // Use of COLOR aspect on DS image is error
8083 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008084 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8085 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008086 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008087 // Now test depth-only
8088 VkFormatProperties format_props;
8089
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008090 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8091 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8093 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8095 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008096 VkDepthStencilObj d_image(m_device);
8097 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8098 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008099 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008100 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008101 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008102 // Use of COLOR aspect on depth image is error
8103 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008104 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8105 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008106 m_errorMonitor->VerifyFound();
8107 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008108 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8109 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008110 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8112 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008113 VkDepthStencilObj s_image(m_device);
8114 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8115 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008116 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008117 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008118 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008119 // Use of COLOR aspect on depth image is error
8120 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008121 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8122 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008123 m_errorMonitor->VerifyFound();
8124 }
8125 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8127 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8129 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008130 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008131 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 -06008132 ASSERT_TRUE(c_image.initialized());
8133 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8134 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8135 img_barrier.image = c_image.handle();
8136 // Set aspect to depth (non-color)
8137 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008138 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8139 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008140 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008141}
8142
Tony Barbour18ba25c2016-09-29 13:42:40 -06008143TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8144 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8145
8146 m_errorMonitor->SetDesiredFailureMsg(
8147 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8148 "must have required access bit");
8149 ASSERT_NO_FATAL_FAILURE(InitState());
8150 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008151 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 -06008152 ASSERT_TRUE(image.initialized());
8153
8154 VkImageMemoryBarrier barrier = {};
8155 VkImageSubresourceRange range;
8156 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8157 barrier.srcAccessMask = 0;
8158 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8159 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8160 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8161 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8162 barrier.image = image.handle();
8163 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8164 range.baseMipLevel = 0;
8165 range.levelCount = 1;
8166 range.baseArrayLayer = 0;
8167 range.layerCount = 1;
8168 barrier.subresourceRange = range;
8169 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8170 cmdbuf.BeginCommandBuffer();
8171 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8172 &barrier);
8173 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8174 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8175 barrier.srcAccessMask = 0;
8176 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8177 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8178 &barrier);
8179
8180 m_errorMonitor->VerifyFound();
8181}
8182
Karl Schultz6addd812016-02-02 17:17:23 -07008183TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008184 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008185 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008186
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008188
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008189 ASSERT_NO_FATAL_FAILURE(InitState());
8190 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008191 uint32_t qfi = 0;
8192 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008193 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8194 buffCI.size = 1024;
8195 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8196 buffCI.queueFamilyIndexCount = 1;
8197 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008198
8199 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008200 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008201 ASSERT_VK_SUCCESS(err);
8202
8203 BeginCommandBuffer();
8204 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008205 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8206 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008207 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008208 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008209
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008210 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008211
Chia-I Wuf7458c52015-10-26 21:10:41 +08008212 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008213}
8214
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008215TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8216 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8218 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8219 "of the indices specified when the device was created, via the "
8220 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008221
8222 ASSERT_NO_FATAL_FAILURE(InitState());
8223 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8224 VkBufferCreateInfo buffCI = {};
8225 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8226 buffCI.size = 1024;
8227 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8228 buffCI.queueFamilyIndexCount = 1;
8229 // Introduce failure by specifying invalid queue_family_index
8230 uint32_t qfi = 777;
8231 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008232 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008233
8234 VkBuffer ib;
8235 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8236
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008237 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008238 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008239}
8240
Karl Schultz6addd812016-02-02 17:17:23 -07008241TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008242TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008243 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008244
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008245 ASSERT_NO_FATAL_FAILURE(InitState());
8246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008247
Chris Forbesf29a84f2016-10-06 18:39:28 +13008248 // An empty primary command buffer
8249 VkCommandBufferObj cb(m_device, m_commandPool);
8250 cb.BeginCommandBuffer();
8251 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008252
Chris Forbesf29a84f2016-10-06 18:39:28 +13008253 m_commandBuffer->BeginCommandBuffer();
8254 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8255 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008256
Chris Forbesf29a84f2016-10-06 18:39:28 +13008257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8258 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008259 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008260}
8261
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008262TEST_F(VkLayerTest, DSUsageBitsErrors) {
8263 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8264 "that do not have correct usage bits sets.");
8265 VkResult err;
8266
8267 ASSERT_NO_FATAL_FAILURE(InitState());
8268 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8269 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8270 ds_type_count[i].type = VkDescriptorType(i);
8271 ds_type_count[i].descriptorCount = 1;
8272 }
8273 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8274 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8275 ds_pool_ci.pNext = NULL;
8276 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8277 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8278 ds_pool_ci.pPoolSizes = ds_type_count;
8279
8280 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008281 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008282 ASSERT_VK_SUCCESS(err);
8283
8284 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008285 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008286 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8287 dsl_binding[i].binding = 0;
8288 dsl_binding[i].descriptorType = VkDescriptorType(i);
8289 dsl_binding[i].descriptorCount = 1;
8290 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8291 dsl_binding[i].pImmutableSamplers = NULL;
8292 }
8293
8294 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8295 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8296 ds_layout_ci.pNext = NULL;
8297 ds_layout_ci.bindingCount = 1;
8298 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8299 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8300 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008301 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008302 ASSERT_VK_SUCCESS(err);
8303 }
8304 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8305 VkDescriptorSetAllocateInfo alloc_info = {};
8306 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8307 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8308 alloc_info.descriptorPool = ds_pool;
8309 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008310 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008311 ASSERT_VK_SUCCESS(err);
8312
8313 // Create a buffer & bufferView to be used for invalid updates
8314 VkBufferCreateInfo buff_ci = {};
8315 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8316 // This usage is not valid for any descriptor type
8317 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8318 buff_ci.size = 256;
8319 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8320 VkBuffer buffer;
8321 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8322 ASSERT_VK_SUCCESS(err);
8323
8324 VkBufferViewCreateInfo buff_view_ci = {};
8325 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8326 buff_view_ci.buffer = buffer;
8327 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8328 buff_view_ci.range = VK_WHOLE_SIZE;
8329 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008330 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008331 ASSERT_VK_SUCCESS(err);
8332
8333 // Create an image to be used for invalid updates
8334 VkImageCreateInfo image_ci = {};
8335 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8336 image_ci.imageType = VK_IMAGE_TYPE_2D;
8337 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8338 image_ci.extent.width = 64;
8339 image_ci.extent.height = 64;
8340 image_ci.extent.depth = 1;
8341 image_ci.mipLevels = 1;
8342 image_ci.arrayLayers = 1;
8343 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8344 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8345 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8346 // This usage is not valid for any descriptor type
8347 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8348 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8349 VkImage image;
8350 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8351 ASSERT_VK_SUCCESS(err);
8352 // Bind memory to image
8353 VkMemoryRequirements mem_reqs;
8354 VkDeviceMemory image_mem;
8355 bool pass;
8356 VkMemoryAllocateInfo mem_alloc = {};
8357 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8358 mem_alloc.pNext = NULL;
8359 mem_alloc.allocationSize = 0;
8360 mem_alloc.memoryTypeIndex = 0;
8361 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8362 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008363 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008364 ASSERT_TRUE(pass);
8365 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8366 ASSERT_VK_SUCCESS(err);
8367 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8368 ASSERT_VK_SUCCESS(err);
8369 // Now create view for image
8370 VkImageViewCreateInfo image_view_ci = {};
8371 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8372 image_view_ci.image = image;
8373 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8374 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8375 image_view_ci.subresourceRange.layerCount = 1;
8376 image_view_ci.subresourceRange.baseArrayLayer = 0;
8377 image_view_ci.subresourceRange.levelCount = 1;
8378 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8379 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008380 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008381 ASSERT_VK_SUCCESS(err);
8382
8383 VkDescriptorBufferInfo buff_info = {};
8384 buff_info.buffer = buffer;
8385 VkDescriptorImageInfo img_info = {};
8386 img_info.imageView = image_view;
8387 VkWriteDescriptorSet descriptor_write = {};
8388 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8389 descriptor_write.dstBinding = 0;
8390 descriptor_write.descriptorCount = 1;
8391 descriptor_write.pTexelBufferView = &buff_view;
8392 descriptor_write.pBufferInfo = &buff_info;
8393 descriptor_write.pImageInfo = &img_info;
8394
8395 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008396 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8397 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8398 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8399 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8400 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8401 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8402 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8403 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8404 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8405 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8406 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008407 // Start loop at 1 as SAMPLER desc type has no usage bit error
8408 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8409 descriptor_write.descriptorType = VkDescriptorType(i);
8410 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008412
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008413 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008414
8415 m_errorMonitor->VerifyFound();
8416 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8417 }
8418 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8419 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008420 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008421 vkDestroyImageView(m_device->device(), image_view, NULL);
8422 vkDestroyBuffer(m_device->device(), buffer, NULL);
8423 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008424 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008425 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8426}
8427
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008428TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008429 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8430 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8431 "1. offset value greater than buffer size\n"
8432 "2. range value of 0\n"
8433 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008434 VkResult err;
8435
8436 ASSERT_NO_FATAL_FAILURE(InitState());
8437 VkDescriptorPoolSize ds_type_count = {};
8438 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8439 ds_type_count.descriptorCount = 1;
8440
8441 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8442 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8443 ds_pool_ci.pNext = NULL;
8444 ds_pool_ci.maxSets = 1;
8445 ds_pool_ci.poolSizeCount = 1;
8446 ds_pool_ci.pPoolSizes = &ds_type_count;
8447
8448 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008449 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008450 ASSERT_VK_SUCCESS(err);
8451
8452 // Create layout with single uniform buffer descriptor
8453 VkDescriptorSetLayoutBinding dsl_binding = {};
8454 dsl_binding.binding = 0;
8455 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8456 dsl_binding.descriptorCount = 1;
8457 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8458 dsl_binding.pImmutableSamplers = NULL;
8459
8460 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8461 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8462 ds_layout_ci.pNext = NULL;
8463 ds_layout_ci.bindingCount = 1;
8464 ds_layout_ci.pBindings = &dsl_binding;
8465 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008466 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008467 ASSERT_VK_SUCCESS(err);
8468
8469 VkDescriptorSet descriptor_set = {};
8470 VkDescriptorSetAllocateInfo alloc_info = {};
8471 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8472 alloc_info.descriptorSetCount = 1;
8473 alloc_info.descriptorPool = ds_pool;
8474 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008475 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008476 ASSERT_VK_SUCCESS(err);
8477
8478 // Create a buffer to be used for invalid updates
8479 VkBufferCreateInfo buff_ci = {};
8480 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8481 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8482 buff_ci.size = 256;
8483 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8484 VkBuffer buffer;
8485 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8486 ASSERT_VK_SUCCESS(err);
8487 // Have to bind memory to buffer before descriptor update
8488 VkMemoryAllocateInfo mem_alloc = {};
8489 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8490 mem_alloc.pNext = NULL;
8491 mem_alloc.allocationSize = 256;
8492 mem_alloc.memoryTypeIndex = 0;
8493
8494 VkMemoryRequirements mem_reqs;
8495 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008496 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008497 if (!pass) {
8498 vkDestroyBuffer(m_device->device(), buffer, NULL);
8499 return;
8500 }
8501
8502 VkDeviceMemory mem;
8503 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8504 ASSERT_VK_SUCCESS(err);
8505 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8506 ASSERT_VK_SUCCESS(err);
8507
8508 VkDescriptorBufferInfo buff_info = {};
8509 buff_info.buffer = buffer;
8510 // First make offset 1 larger than buffer size
8511 buff_info.offset = 257;
8512 buff_info.range = VK_WHOLE_SIZE;
8513 VkWriteDescriptorSet descriptor_write = {};
8514 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8515 descriptor_write.dstBinding = 0;
8516 descriptor_write.descriptorCount = 1;
8517 descriptor_write.pTexelBufferView = nullptr;
8518 descriptor_write.pBufferInfo = &buff_info;
8519 descriptor_write.pImageInfo = nullptr;
8520
8521 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8522 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008524
8525 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8526
8527 m_errorMonitor->VerifyFound();
8528 // Now cause error due to range of 0
8529 buff_info.offset = 0;
8530 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8532 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008533
8534 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8535
8536 m_errorMonitor->VerifyFound();
8537 // Now cause error due to range exceeding buffer size - offset
8538 buff_info.offset = 128;
8539 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008540 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 -06008541
8542 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8543
8544 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008545 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008546 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8547 vkDestroyBuffer(m_device->device(), buffer, NULL);
8548 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8549 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8550}
8551
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008552TEST_F(VkLayerTest, DSAspectBitsErrors) {
8553 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8554 // are set, but could expand this test to hit more cases.
8555 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8556 "that do not have correct aspect bits sets.");
8557 VkResult err;
8558
8559 ASSERT_NO_FATAL_FAILURE(InitState());
8560 VkDescriptorPoolSize ds_type_count = {};
8561 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8562 ds_type_count.descriptorCount = 1;
8563
8564 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8565 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8566 ds_pool_ci.pNext = NULL;
8567 ds_pool_ci.maxSets = 5;
8568 ds_pool_ci.poolSizeCount = 1;
8569 ds_pool_ci.pPoolSizes = &ds_type_count;
8570
8571 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008572 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008573 ASSERT_VK_SUCCESS(err);
8574
8575 VkDescriptorSetLayoutBinding dsl_binding = {};
8576 dsl_binding.binding = 0;
8577 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8578 dsl_binding.descriptorCount = 1;
8579 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8580 dsl_binding.pImmutableSamplers = NULL;
8581
8582 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8583 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8584 ds_layout_ci.pNext = NULL;
8585 ds_layout_ci.bindingCount = 1;
8586 ds_layout_ci.pBindings = &dsl_binding;
8587 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008588 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008589 ASSERT_VK_SUCCESS(err);
8590
8591 VkDescriptorSet descriptor_set = {};
8592 VkDescriptorSetAllocateInfo alloc_info = {};
8593 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8594 alloc_info.descriptorSetCount = 1;
8595 alloc_info.descriptorPool = ds_pool;
8596 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008597 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008598 ASSERT_VK_SUCCESS(err);
8599
8600 // Create an image to be used for invalid updates
8601 VkImageCreateInfo image_ci = {};
8602 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8603 image_ci.imageType = VK_IMAGE_TYPE_2D;
8604 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8605 image_ci.extent.width = 64;
8606 image_ci.extent.height = 64;
8607 image_ci.extent.depth = 1;
8608 image_ci.mipLevels = 1;
8609 image_ci.arrayLayers = 1;
8610 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8611 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8612 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8613 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8614 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8615 VkImage image;
8616 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8617 ASSERT_VK_SUCCESS(err);
8618 // Bind memory to image
8619 VkMemoryRequirements mem_reqs;
8620 VkDeviceMemory image_mem;
8621 bool pass;
8622 VkMemoryAllocateInfo mem_alloc = {};
8623 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8624 mem_alloc.pNext = NULL;
8625 mem_alloc.allocationSize = 0;
8626 mem_alloc.memoryTypeIndex = 0;
8627 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8628 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008629 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008630 ASSERT_TRUE(pass);
8631 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8632 ASSERT_VK_SUCCESS(err);
8633 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8634 ASSERT_VK_SUCCESS(err);
8635 // Now create view for image
8636 VkImageViewCreateInfo image_view_ci = {};
8637 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8638 image_view_ci.image = image;
8639 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8640 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8641 image_view_ci.subresourceRange.layerCount = 1;
8642 image_view_ci.subresourceRange.baseArrayLayer = 0;
8643 image_view_ci.subresourceRange.levelCount = 1;
8644 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008645 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008646
8647 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008648 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008649 ASSERT_VK_SUCCESS(err);
8650
8651 VkDescriptorImageInfo img_info = {};
8652 img_info.imageView = image_view;
8653 VkWriteDescriptorSet descriptor_write = {};
8654 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8655 descriptor_write.dstBinding = 0;
8656 descriptor_write.descriptorCount = 1;
8657 descriptor_write.pTexelBufferView = NULL;
8658 descriptor_write.pBufferInfo = NULL;
8659 descriptor_write.pImageInfo = &img_info;
8660 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8661 descriptor_write.dstSet = descriptor_set;
8662 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8663 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008665
8666 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8667
8668 m_errorMonitor->VerifyFound();
8669 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8670 vkDestroyImage(m_device->device(), image, NULL);
8671 vkFreeMemory(m_device->device(), image_mem, NULL);
8672 vkDestroyImageView(m_device->device(), image_view, NULL);
8673 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8674 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8675}
8676
Karl Schultz6addd812016-02-02 17:17:23 -07008677TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008678 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008679 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008680
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8682 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8683 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008684
Tobin Ehlis3b780662015-05-28 12:11:26 -06008685 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008686 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008687 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008688 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8689 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008690
8691 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008692 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8693 ds_pool_ci.pNext = NULL;
8694 ds_pool_ci.maxSets = 1;
8695 ds_pool_ci.poolSizeCount = 1;
8696 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008697
Tobin Ehlis3b780662015-05-28 12:11:26 -06008698 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008699 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008700 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008701 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008702 dsl_binding.binding = 0;
8703 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8704 dsl_binding.descriptorCount = 1;
8705 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8706 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008707
Tony Barboureb254902015-07-15 12:50:33 -06008708 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008709 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8710 ds_layout_ci.pNext = NULL;
8711 ds_layout_ci.bindingCount = 1;
8712 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008713
Tobin Ehlis3b780662015-05-28 12:11:26 -06008714 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008715 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008716 ASSERT_VK_SUCCESS(err);
8717
8718 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008719 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008720 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008721 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008722 alloc_info.descriptorPool = ds_pool;
8723 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008724 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008725 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008726
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008727 VkSamplerCreateInfo sampler_ci = {};
8728 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8729 sampler_ci.pNext = NULL;
8730 sampler_ci.magFilter = VK_FILTER_NEAREST;
8731 sampler_ci.minFilter = VK_FILTER_NEAREST;
8732 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8733 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8734 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8735 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8736 sampler_ci.mipLodBias = 1.0;
8737 sampler_ci.anisotropyEnable = VK_FALSE;
8738 sampler_ci.maxAnisotropy = 1;
8739 sampler_ci.compareEnable = VK_FALSE;
8740 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8741 sampler_ci.minLod = 1.0;
8742 sampler_ci.maxLod = 1.0;
8743 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8744 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8745 VkSampler sampler;
8746 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8747 ASSERT_VK_SUCCESS(err);
8748
8749 VkDescriptorImageInfo info = {};
8750 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008751
8752 VkWriteDescriptorSet descriptor_write;
8753 memset(&descriptor_write, 0, sizeof(descriptor_write));
8754 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008755 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008756 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008757 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008758 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008759 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008760
8761 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8762
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008763 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008764
Chia-I Wuf7458c52015-10-26 21:10:41 +08008765 vkDestroySampler(m_device->device(), sampler, NULL);
8766 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8767 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008768}
8769
Karl Schultz6addd812016-02-02 17:17:23 -07008770TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008771 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008772 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008773
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8775 " binding #0 with 1 total descriptors but update of 1 descriptors "
8776 "starting at binding offset of 0 combined with update array element "
8777 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008778
Tobin Ehlis3b780662015-05-28 12:11:26 -06008779 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008780 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008781 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008782 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8783 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008784
8785 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008786 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8787 ds_pool_ci.pNext = NULL;
8788 ds_pool_ci.maxSets = 1;
8789 ds_pool_ci.poolSizeCount = 1;
8790 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008791
Tobin Ehlis3b780662015-05-28 12:11:26 -06008792 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008793 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008794 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008795
Tony Barboureb254902015-07-15 12:50:33 -06008796 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008797 dsl_binding.binding = 0;
8798 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8799 dsl_binding.descriptorCount = 1;
8800 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8801 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008802
8803 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008804 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8805 ds_layout_ci.pNext = NULL;
8806 ds_layout_ci.bindingCount = 1;
8807 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008808
Tobin Ehlis3b780662015-05-28 12:11:26 -06008809 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008810 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008811 ASSERT_VK_SUCCESS(err);
8812
8813 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008814 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008815 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008816 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008817 alloc_info.descriptorPool = ds_pool;
8818 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008819 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008820 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008821
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008822 // Correctly update descriptor to avoid "NOT_UPDATED" error
8823 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008824 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008825 buff_info.offset = 0;
8826 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008827
8828 VkWriteDescriptorSet descriptor_write;
8829 memset(&descriptor_write, 0, sizeof(descriptor_write));
8830 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008831 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008832 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008833 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008834 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8835 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008836
8837 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8838
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008839 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008840
Chia-I Wuf7458c52015-10-26 21:10:41 +08008841 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8842 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008843}
8844
Karl Schultz6addd812016-02-02 17:17:23 -07008845TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8846 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8847 // index 2
8848 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008849
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008851
Tobin Ehlis3b780662015-05-28 12:11:26 -06008852 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008853 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008854 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008855 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8856 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008857
8858 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008859 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8860 ds_pool_ci.pNext = NULL;
8861 ds_pool_ci.maxSets = 1;
8862 ds_pool_ci.poolSizeCount = 1;
8863 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008864
Tobin Ehlis3b780662015-05-28 12:11:26 -06008865 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008866 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008867 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008868
Tony Barboureb254902015-07-15 12:50:33 -06008869 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008870 dsl_binding.binding = 0;
8871 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8872 dsl_binding.descriptorCount = 1;
8873 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8874 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008875
8876 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008877 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8878 ds_layout_ci.pNext = NULL;
8879 ds_layout_ci.bindingCount = 1;
8880 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008881 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008882 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008883 ASSERT_VK_SUCCESS(err);
8884
8885 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008886 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008887 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008888 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008889 alloc_info.descriptorPool = ds_pool;
8890 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008891 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008892 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008893
Tony Barboureb254902015-07-15 12:50:33 -06008894 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008895 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8896 sampler_ci.pNext = NULL;
8897 sampler_ci.magFilter = VK_FILTER_NEAREST;
8898 sampler_ci.minFilter = VK_FILTER_NEAREST;
8899 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8900 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8901 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8902 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8903 sampler_ci.mipLodBias = 1.0;
8904 sampler_ci.anisotropyEnable = VK_FALSE;
8905 sampler_ci.maxAnisotropy = 1;
8906 sampler_ci.compareEnable = VK_FALSE;
8907 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8908 sampler_ci.minLod = 1.0;
8909 sampler_ci.maxLod = 1.0;
8910 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8911 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008912
Tobin Ehlis3b780662015-05-28 12:11:26 -06008913 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008914 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008915 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008916
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008917 VkDescriptorImageInfo info = {};
8918 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008919
8920 VkWriteDescriptorSet descriptor_write;
8921 memset(&descriptor_write, 0, sizeof(descriptor_write));
8922 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008923 descriptor_write.dstSet = descriptorSet;
8924 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008925 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008926 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008927 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008928 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008929
8930 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8931
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008932 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008933
Chia-I Wuf7458c52015-10-26 21:10:41 +08008934 vkDestroySampler(m_device->device(), sampler, NULL);
8935 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8936 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008937}
8938
Karl Schultz6addd812016-02-02 17:17:23 -07008939TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8940 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8941 // types
8942 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008943
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008945
Tobin Ehlis3b780662015-05-28 12:11:26 -06008946 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008947
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008948 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008949 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8950 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008951
8952 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008953 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8954 ds_pool_ci.pNext = NULL;
8955 ds_pool_ci.maxSets = 1;
8956 ds_pool_ci.poolSizeCount = 1;
8957 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008958
Tobin Ehlis3b780662015-05-28 12:11:26 -06008959 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008960 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008961 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008962 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008963 dsl_binding.binding = 0;
8964 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8965 dsl_binding.descriptorCount = 1;
8966 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8967 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008968
Tony Barboureb254902015-07-15 12:50:33 -06008969 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008970 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8971 ds_layout_ci.pNext = NULL;
8972 ds_layout_ci.bindingCount = 1;
8973 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008974
Tobin Ehlis3b780662015-05-28 12:11:26 -06008975 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008976 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008977 ASSERT_VK_SUCCESS(err);
8978
8979 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008980 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008981 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008982 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008983 alloc_info.descriptorPool = ds_pool;
8984 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008985 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008986 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008987
Tony Barboureb254902015-07-15 12:50:33 -06008988 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008989 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8990 sampler_ci.pNext = NULL;
8991 sampler_ci.magFilter = VK_FILTER_NEAREST;
8992 sampler_ci.minFilter = VK_FILTER_NEAREST;
8993 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8994 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8995 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8996 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8997 sampler_ci.mipLodBias = 1.0;
8998 sampler_ci.anisotropyEnable = VK_FALSE;
8999 sampler_ci.maxAnisotropy = 1;
9000 sampler_ci.compareEnable = VK_FALSE;
9001 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9002 sampler_ci.minLod = 1.0;
9003 sampler_ci.maxLod = 1.0;
9004 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9005 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009006 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009007 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009008 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009009
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009010 VkDescriptorImageInfo info = {};
9011 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009012
9013 VkWriteDescriptorSet descriptor_write;
9014 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009015 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009016 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009017 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009018 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009019 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009020 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009021
9022 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9023
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009024 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009025
Chia-I Wuf7458c52015-10-26 21:10:41 +08009026 vkDestroySampler(m_device->device(), sampler, NULL);
9027 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9028 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009029}
9030
Karl Schultz6addd812016-02-02 17:17:23 -07009031TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009032 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009033 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009034
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9036 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009037
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009038 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009039 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9040 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009041 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009042 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9043 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009044
9045 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009046 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9047 ds_pool_ci.pNext = NULL;
9048 ds_pool_ci.maxSets = 1;
9049 ds_pool_ci.poolSizeCount = 1;
9050 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009051
9052 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009053 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009054 ASSERT_VK_SUCCESS(err);
9055
9056 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009057 dsl_binding.binding = 0;
9058 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9059 dsl_binding.descriptorCount = 1;
9060 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9061 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009062
9063 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009064 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9065 ds_layout_ci.pNext = NULL;
9066 ds_layout_ci.bindingCount = 1;
9067 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009068 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009069 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009070 ASSERT_VK_SUCCESS(err);
9071
9072 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009073 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009074 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009075 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009076 alloc_info.descriptorPool = ds_pool;
9077 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009078 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009079 ASSERT_VK_SUCCESS(err);
9080
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009081 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009082
9083 VkDescriptorImageInfo descriptor_info;
9084 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9085 descriptor_info.sampler = sampler;
9086
9087 VkWriteDescriptorSet descriptor_write;
9088 memset(&descriptor_write, 0, sizeof(descriptor_write));
9089 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009090 descriptor_write.dstSet = descriptorSet;
9091 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009092 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009093 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9094 descriptor_write.pImageInfo = &descriptor_info;
9095
9096 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9097
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009098 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009099
Chia-I Wuf7458c52015-10-26 21:10:41 +08009100 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9101 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009102}
9103
Karl Schultz6addd812016-02-02 17:17:23 -07009104TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9105 // Create a single combined Image/Sampler descriptor and send it an invalid
9106 // imageView
9107 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009108
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9110 "image sampler descriptor failed due "
9111 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009112
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009113 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009114 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009115 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9116 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009117
9118 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009119 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9120 ds_pool_ci.pNext = NULL;
9121 ds_pool_ci.maxSets = 1;
9122 ds_pool_ci.poolSizeCount = 1;
9123 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009124
9125 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009126 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009127 ASSERT_VK_SUCCESS(err);
9128
9129 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009130 dsl_binding.binding = 0;
9131 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9132 dsl_binding.descriptorCount = 1;
9133 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9134 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009135
9136 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009137 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9138 ds_layout_ci.pNext = NULL;
9139 ds_layout_ci.bindingCount = 1;
9140 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009141 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009142 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009143 ASSERT_VK_SUCCESS(err);
9144
9145 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009146 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009147 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009148 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009149 alloc_info.descriptorPool = ds_pool;
9150 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009151 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009152 ASSERT_VK_SUCCESS(err);
9153
9154 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009155 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9156 sampler_ci.pNext = NULL;
9157 sampler_ci.magFilter = VK_FILTER_NEAREST;
9158 sampler_ci.minFilter = VK_FILTER_NEAREST;
9159 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9160 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9161 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9162 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9163 sampler_ci.mipLodBias = 1.0;
9164 sampler_ci.anisotropyEnable = VK_FALSE;
9165 sampler_ci.maxAnisotropy = 1;
9166 sampler_ci.compareEnable = VK_FALSE;
9167 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9168 sampler_ci.minLod = 1.0;
9169 sampler_ci.maxLod = 1.0;
9170 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9171 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009172
9173 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009174 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009175 ASSERT_VK_SUCCESS(err);
9176
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009177 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009178
9179 VkDescriptorImageInfo descriptor_info;
9180 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9181 descriptor_info.sampler = sampler;
9182 descriptor_info.imageView = view;
9183
9184 VkWriteDescriptorSet descriptor_write;
9185 memset(&descriptor_write, 0, sizeof(descriptor_write));
9186 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009187 descriptor_write.dstSet = descriptorSet;
9188 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009189 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009190 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9191 descriptor_write.pImageInfo = &descriptor_info;
9192
9193 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9194
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009195 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009196
Chia-I Wuf7458c52015-10-26 21:10:41 +08009197 vkDestroySampler(m_device->device(), sampler, NULL);
9198 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9199 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009200}
9201
Karl Schultz6addd812016-02-02 17:17:23 -07009202TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9203 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9204 // into the other
9205 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009206
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9208 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9209 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009210
Tobin Ehlis04356f92015-10-27 16:35:27 -06009211 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009212 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009213 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009214 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9215 ds_type_count[0].descriptorCount = 1;
9216 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9217 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009218
9219 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009220 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9221 ds_pool_ci.pNext = NULL;
9222 ds_pool_ci.maxSets = 1;
9223 ds_pool_ci.poolSizeCount = 2;
9224 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009225
9226 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009227 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009228 ASSERT_VK_SUCCESS(err);
9229 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009230 dsl_binding[0].binding = 0;
9231 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9232 dsl_binding[0].descriptorCount = 1;
9233 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9234 dsl_binding[0].pImmutableSamplers = NULL;
9235 dsl_binding[1].binding = 1;
9236 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9237 dsl_binding[1].descriptorCount = 1;
9238 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9239 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009240
9241 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009242 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9243 ds_layout_ci.pNext = NULL;
9244 ds_layout_ci.bindingCount = 2;
9245 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009246
9247 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009248 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009249 ASSERT_VK_SUCCESS(err);
9250
9251 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009252 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009253 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009254 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009255 alloc_info.descriptorPool = ds_pool;
9256 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009257 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009258 ASSERT_VK_SUCCESS(err);
9259
9260 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009261 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9262 sampler_ci.pNext = NULL;
9263 sampler_ci.magFilter = VK_FILTER_NEAREST;
9264 sampler_ci.minFilter = VK_FILTER_NEAREST;
9265 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9266 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9267 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9268 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9269 sampler_ci.mipLodBias = 1.0;
9270 sampler_ci.anisotropyEnable = VK_FALSE;
9271 sampler_ci.maxAnisotropy = 1;
9272 sampler_ci.compareEnable = VK_FALSE;
9273 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9274 sampler_ci.minLod = 1.0;
9275 sampler_ci.maxLod = 1.0;
9276 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9277 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009278
9279 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009280 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009281 ASSERT_VK_SUCCESS(err);
9282
9283 VkDescriptorImageInfo info = {};
9284 info.sampler = sampler;
9285
9286 VkWriteDescriptorSet descriptor_write;
9287 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9288 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009289 descriptor_write.dstSet = descriptorSet;
9290 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009291 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009292 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9293 descriptor_write.pImageInfo = &info;
9294 // This write update should succeed
9295 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9296 // Now perform a copy update that fails due to type mismatch
9297 VkCopyDescriptorSet copy_ds_update;
9298 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9299 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9300 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009301 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009302 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009303 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009304 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009305 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9306
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009307 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009308 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009309 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 -06009310 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9311 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9312 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009313 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009314 copy_ds_update.dstSet = descriptorSet;
9315 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009316 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009317 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9318
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009319 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009320
Tobin Ehlis04356f92015-10-27 16:35:27 -06009321 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9323 "update array offset of 0 and update of "
9324 "5 descriptors oversteps total number "
9325 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009326
Tobin Ehlis04356f92015-10-27 16:35:27 -06009327 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9328 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9329 copy_ds_update.srcSet = descriptorSet;
9330 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009331 copy_ds_update.dstSet = descriptorSet;
9332 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009333 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009334 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9335
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009336 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009337
Chia-I Wuf7458c52015-10-26 21:10:41 +08009338 vkDestroySampler(m_device->device(), sampler, NULL);
9339 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9340 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009341}
9342
Karl Schultz6addd812016-02-02 17:17:23 -07009343TEST_F(VkLayerTest, NumSamplesMismatch) {
9344 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9345 // sampleCount
9346 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009347
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009349
Tobin Ehlis3b780662015-05-28 12:11:26 -06009350 ASSERT_NO_FATAL_FAILURE(InitState());
9351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009352 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009353 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009354 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009355
9356 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009357 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9358 ds_pool_ci.pNext = NULL;
9359 ds_pool_ci.maxSets = 1;
9360 ds_pool_ci.poolSizeCount = 1;
9361 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009362
Tobin Ehlis3b780662015-05-28 12:11:26 -06009363 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009364 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009365 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009366
Tony Barboureb254902015-07-15 12:50:33 -06009367 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009368 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009369 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009370 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009371 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9372 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009373
Tony Barboureb254902015-07-15 12:50:33 -06009374 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9375 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9376 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009377 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009378 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009379
Tobin Ehlis3b780662015-05-28 12:11:26 -06009380 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009381 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009382 ASSERT_VK_SUCCESS(err);
9383
9384 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009385 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009386 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009387 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009388 alloc_info.descriptorPool = ds_pool;
9389 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009390 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009391 ASSERT_VK_SUCCESS(err);
9392
Tony Barboureb254902015-07-15 12:50:33 -06009393 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009394 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009395 pipe_ms_state_ci.pNext = NULL;
9396 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9397 pipe_ms_state_ci.sampleShadingEnable = 0;
9398 pipe_ms_state_ci.minSampleShading = 1.0;
9399 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009400
Tony Barboureb254902015-07-15 12:50:33 -06009401 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009402 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9403 pipeline_layout_ci.pNext = NULL;
9404 pipeline_layout_ci.setLayoutCount = 1;
9405 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009406
9407 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009408 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009409 ASSERT_VK_SUCCESS(err);
9410
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009411 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9412 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9413 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009414 VkPipelineObj pipe(m_device);
9415 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009416 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009417 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009418 pipe.SetMSAA(&pipe_ms_state_ci);
9419 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009420
Tony Barbourfe3351b2015-07-28 10:17:20 -06009421 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009422 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009423
Mark Young29927482016-05-04 14:38:51 -06009424 // Render triangle (the error should trigger on the attempt to draw).
9425 Draw(3, 1, 0, 0);
9426
9427 // Finalize recording of the command buffer
9428 EndCommandBuffer();
9429
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009430 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009431
Chia-I Wuf7458c52015-10-26 21:10:41 +08009432 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9433 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9434 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009435}
Mark Young29927482016-05-04 14:38:51 -06009436
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009437TEST_F(VkLayerTest, RenderPassIncompatible) {
9438 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9439 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009440 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009441 VkResult err;
9442
9443 ASSERT_NO_FATAL_FAILURE(InitState());
9444 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9445
9446 VkDescriptorSetLayoutBinding dsl_binding = {};
9447 dsl_binding.binding = 0;
9448 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9449 dsl_binding.descriptorCount = 1;
9450 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9451 dsl_binding.pImmutableSamplers = NULL;
9452
9453 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9454 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9455 ds_layout_ci.pNext = NULL;
9456 ds_layout_ci.bindingCount = 1;
9457 ds_layout_ci.pBindings = &dsl_binding;
9458
9459 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009460 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009461 ASSERT_VK_SUCCESS(err);
9462
9463 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9464 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9465 pipeline_layout_ci.pNext = NULL;
9466 pipeline_layout_ci.setLayoutCount = 1;
9467 pipeline_layout_ci.pSetLayouts = &ds_layout;
9468
9469 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009470 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009471 ASSERT_VK_SUCCESS(err);
9472
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009473 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9474 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9475 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009476 // Create a renderpass that will be incompatible with default renderpass
9477 VkAttachmentReference attach = {};
9478 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9479 VkAttachmentReference color_att = {};
9480 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9481 VkSubpassDescription subpass = {};
9482 subpass.inputAttachmentCount = 1;
9483 subpass.pInputAttachments = &attach;
9484 subpass.colorAttachmentCount = 1;
9485 subpass.pColorAttachments = &color_att;
9486 VkRenderPassCreateInfo rpci = {};
9487 rpci.subpassCount = 1;
9488 rpci.pSubpasses = &subpass;
9489 rpci.attachmentCount = 1;
9490 VkAttachmentDescription attach_desc = {};
9491 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009492 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9493 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009494 rpci.pAttachments = &attach_desc;
9495 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9496 VkRenderPass rp;
9497 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9498 VkPipelineObj pipe(m_device);
9499 pipe.AddShader(&vs);
9500 pipe.AddShader(&fs);
9501 pipe.AddColorAttachment();
9502 VkViewport view_port = {};
9503 m_viewports.push_back(view_port);
9504 pipe.SetViewport(m_viewports);
9505 VkRect2D rect = {};
9506 m_scissors.push_back(rect);
9507 pipe.SetScissor(m_scissors);
9508 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9509
9510 VkCommandBufferInheritanceInfo cbii = {};
9511 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9512 cbii.renderPass = rp;
9513 cbii.subpass = 0;
9514 VkCommandBufferBeginInfo cbbi = {};
9515 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9516 cbbi.pInheritanceInfo = &cbii;
9517 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9518 VkRenderPassBeginInfo rpbi = {};
9519 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9520 rpbi.framebuffer = m_framebuffer;
9521 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009522 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9523 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009524
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009526 // Render triangle (the error should trigger on the attempt to draw).
9527 Draw(3, 1, 0, 0);
9528
9529 // Finalize recording of the command buffer
9530 EndCommandBuffer();
9531
9532 m_errorMonitor->VerifyFound();
9533
9534 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9535 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9536 vkDestroyRenderPass(m_device->device(), rp, NULL);
9537}
9538
Mark Youngc89c6312016-03-31 16:03:20 -06009539TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9540 // Create Pipeline where the number of blend attachments doesn't match the
9541 // number of color attachments. In this case, we don't add any color
9542 // blend attachments even though we have a color attachment.
9543 VkResult err;
9544
9545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009546 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009547
9548 ASSERT_NO_FATAL_FAILURE(InitState());
9549 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9550 VkDescriptorPoolSize ds_type_count = {};
9551 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9552 ds_type_count.descriptorCount = 1;
9553
9554 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9555 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9556 ds_pool_ci.pNext = NULL;
9557 ds_pool_ci.maxSets = 1;
9558 ds_pool_ci.poolSizeCount = 1;
9559 ds_pool_ci.pPoolSizes = &ds_type_count;
9560
9561 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009562 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009563 ASSERT_VK_SUCCESS(err);
9564
9565 VkDescriptorSetLayoutBinding dsl_binding = {};
9566 dsl_binding.binding = 0;
9567 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9568 dsl_binding.descriptorCount = 1;
9569 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9570 dsl_binding.pImmutableSamplers = NULL;
9571
9572 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9573 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9574 ds_layout_ci.pNext = NULL;
9575 ds_layout_ci.bindingCount = 1;
9576 ds_layout_ci.pBindings = &dsl_binding;
9577
9578 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009579 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009580 ASSERT_VK_SUCCESS(err);
9581
9582 VkDescriptorSet descriptorSet;
9583 VkDescriptorSetAllocateInfo alloc_info = {};
9584 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9585 alloc_info.descriptorSetCount = 1;
9586 alloc_info.descriptorPool = ds_pool;
9587 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009588 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009589 ASSERT_VK_SUCCESS(err);
9590
9591 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009592 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009593 pipe_ms_state_ci.pNext = NULL;
9594 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9595 pipe_ms_state_ci.sampleShadingEnable = 0;
9596 pipe_ms_state_ci.minSampleShading = 1.0;
9597 pipe_ms_state_ci.pSampleMask = NULL;
9598
9599 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9600 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9601 pipeline_layout_ci.pNext = NULL;
9602 pipeline_layout_ci.setLayoutCount = 1;
9603 pipeline_layout_ci.pSetLayouts = &ds_layout;
9604
9605 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009606 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009607 ASSERT_VK_SUCCESS(err);
9608
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009609 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9610 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9611 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009612 VkPipelineObj pipe(m_device);
9613 pipe.AddShader(&vs);
9614 pipe.AddShader(&fs);
9615 pipe.SetMSAA(&pipe_ms_state_ci);
9616 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9617
9618 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009619 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009620
Mark Young29927482016-05-04 14:38:51 -06009621 // Render triangle (the error should trigger on the attempt to draw).
9622 Draw(3, 1, 0, 0);
9623
9624 // Finalize recording of the command buffer
9625 EndCommandBuffer();
9626
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009627 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009628
9629 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9630 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9631 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9632}
Mark Young29927482016-05-04 14:38:51 -06009633
Mark Muellerd4914412016-06-13 17:52:06 -06009634TEST_F(VkLayerTest, MissingClearAttachment) {
9635 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9636 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009637 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009639 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009640
9641 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9642 m_errorMonitor->VerifyFound();
9643}
9644
Karl Schultz6addd812016-02-02 17:17:23 -07009645TEST_F(VkLayerTest, ClearCmdNoDraw) {
9646 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9647 // to issuing a Draw
9648 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009649
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009651 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009652
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009653 ASSERT_NO_FATAL_FAILURE(InitState());
9654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009655
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009656 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009657 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9658 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009659
9660 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009661 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9662 ds_pool_ci.pNext = NULL;
9663 ds_pool_ci.maxSets = 1;
9664 ds_pool_ci.poolSizeCount = 1;
9665 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009666
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009667 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009668 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009669 ASSERT_VK_SUCCESS(err);
9670
Tony Barboureb254902015-07-15 12:50:33 -06009671 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009672 dsl_binding.binding = 0;
9673 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9674 dsl_binding.descriptorCount = 1;
9675 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9676 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009677
Tony Barboureb254902015-07-15 12:50:33 -06009678 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009679 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9680 ds_layout_ci.pNext = NULL;
9681 ds_layout_ci.bindingCount = 1;
9682 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009683
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009684 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009685 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009686 ASSERT_VK_SUCCESS(err);
9687
9688 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009689 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009690 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009691 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009692 alloc_info.descriptorPool = ds_pool;
9693 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009694 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009695 ASSERT_VK_SUCCESS(err);
9696
Tony Barboureb254902015-07-15 12:50:33 -06009697 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009698 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009699 pipe_ms_state_ci.pNext = NULL;
9700 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9701 pipe_ms_state_ci.sampleShadingEnable = 0;
9702 pipe_ms_state_ci.minSampleShading = 1.0;
9703 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009704
Tony Barboureb254902015-07-15 12:50:33 -06009705 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009706 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9707 pipeline_layout_ci.pNext = NULL;
9708 pipeline_layout_ci.setLayoutCount = 1;
9709 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009710
9711 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009712 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009713 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009714
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009715 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009716 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009717 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009718 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009719
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009720 VkPipelineObj pipe(m_device);
9721 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009722 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009723 pipe.SetMSAA(&pipe_ms_state_ci);
9724 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009725
9726 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009727
Karl Schultz6addd812016-02-02 17:17:23 -07009728 // Main thing we care about for this test is that the VkImage obj we're
9729 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009730 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009731 VkClearAttachment color_attachment;
9732 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9733 color_attachment.clearValue.color.float32[0] = 1.0;
9734 color_attachment.clearValue.color.float32[1] = 1.0;
9735 color_attachment.clearValue.color.float32[2] = 1.0;
9736 color_attachment.clearValue.color.float32[3] = 1.0;
9737 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009738 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009739
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009740 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009741
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009742 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009743
Chia-I Wuf7458c52015-10-26 21:10:41 +08009744 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9745 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9746 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009747}
9748
Karl Schultz6addd812016-02-02 17:17:23 -07009749TEST_F(VkLayerTest, VtxBufferBadIndex) {
9750 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009751
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9753 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009754
Tobin Ehlis502480b2015-06-24 15:53:07 -06009755 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009756 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009757 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009758
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009759 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009760 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9761 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009762
9763 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009764 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9765 ds_pool_ci.pNext = NULL;
9766 ds_pool_ci.maxSets = 1;
9767 ds_pool_ci.poolSizeCount = 1;
9768 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009769
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009770 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009771 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009772 ASSERT_VK_SUCCESS(err);
9773
Tony Barboureb254902015-07-15 12:50:33 -06009774 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009775 dsl_binding.binding = 0;
9776 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9777 dsl_binding.descriptorCount = 1;
9778 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9779 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009780
Tony Barboureb254902015-07-15 12:50:33 -06009781 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009782 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9783 ds_layout_ci.pNext = NULL;
9784 ds_layout_ci.bindingCount = 1;
9785 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009786
Tobin Ehlis502480b2015-06-24 15:53:07 -06009787 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009788 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009789 ASSERT_VK_SUCCESS(err);
9790
9791 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009792 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009793 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009794 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009795 alloc_info.descriptorPool = ds_pool;
9796 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009797 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009798 ASSERT_VK_SUCCESS(err);
9799
Tony Barboureb254902015-07-15 12:50:33 -06009800 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009801 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009802 pipe_ms_state_ci.pNext = NULL;
9803 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9804 pipe_ms_state_ci.sampleShadingEnable = 0;
9805 pipe_ms_state_ci.minSampleShading = 1.0;
9806 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009807
Tony Barboureb254902015-07-15 12:50:33 -06009808 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009809 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9810 pipeline_layout_ci.pNext = NULL;
9811 pipeline_layout_ci.setLayoutCount = 1;
9812 pipeline_layout_ci.pSetLayouts = &ds_layout;
9813 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009814
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009815 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009816 ASSERT_VK_SUCCESS(err);
9817
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009818 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9819 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9820 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009821 VkPipelineObj pipe(m_device);
9822 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009823 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009824 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009825 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009826 pipe.SetViewport(m_viewports);
9827 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009828 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009829
9830 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009831 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009832 // Don't care about actual data, just need to get to draw to flag error
9833 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009834 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009835 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009836 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009837
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009838 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009839
Chia-I Wuf7458c52015-10-26 21:10:41 +08009840 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9841 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9842 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009843}
Mark Muellerdfe37552016-07-07 14:47:42 -06009844
Mark Mueller2ee294f2016-08-04 12:59:48 -06009845TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
9846 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
9847 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -06009848 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -06009849
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009850 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
9851 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009852
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009853 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
9854 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009855
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009856 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009857
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -06009859 // The following test fails with recent NVidia drivers.
9860 // By the time core_validation is reached, the NVidia
9861 // driver has sanitized the invalid condition and core_validation
9862 // is not introduced to the failure condition. This is not the case
9863 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009864 // uint32_t count = static_cast<uint32_t>(~0);
9865 // VkPhysicalDevice physical_device;
9866 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
9867 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -06009868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009870 float queue_priority = 0.0;
9871
9872 VkDeviceQueueCreateInfo queue_create_info = {};
9873 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
9874 queue_create_info.queueCount = 1;
9875 queue_create_info.pQueuePriorities = &queue_priority;
9876 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
9877
9878 VkPhysicalDeviceFeatures features = m_device->phy().features();
9879 VkDevice testDevice;
9880 VkDeviceCreateInfo device_create_info = {};
9881 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
9882 device_create_info.queueCreateInfoCount = 1;
9883 device_create_info.pQueueCreateInfos = &queue_create_info;
9884 device_create_info.pEnabledFeatures = &features;
9885 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9886 m_errorMonitor->VerifyFound();
9887
9888 queue_create_info.queueFamilyIndex = 1;
9889
9890 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
9891 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
9892 for (unsigned i = 0; i < feature_count; i++) {
9893 if (VK_FALSE == feature_array[i]) {
9894 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009896 device_create_info.pEnabledFeatures = &features;
9897 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9898 m_errorMonitor->VerifyFound();
9899 break;
9900 }
9901 }
9902}
9903
9904TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
9905 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
9906 "End a command buffer with a query still in progress.");
9907
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009908 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
9909 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
9910 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009912 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009913
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009915
9916 ASSERT_NO_FATAL_FAILURE(InitState());
9917
9918 VkEvent event;
9919 VkEventCreateInfo event_create_info{};
9920 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9921 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9922
Mark Mueller2ee294f2016-08-04 12:59:48 -06009923 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009924 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009925
9926 BeginCommandBuffer();
9927
9928 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009929 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 -06009930 ASSERT_TRUE(image.initialized());
9931 VkImageMemoryBarrier img_barrier = {};
9932 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9933 img_barrier.pNext = NULL;
9934 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9935 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9936 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9937 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9938 img_barrier.image = image.handle();
9939 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -06009940
9941 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
9942 // that layer validation catches the case when it is not.
9943 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -06009944 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9945 img_barrier.subresourceRange.baseArrayLayer = 0;
9946 img_barrier.subresourceRange.baseMipLevel = 0;
9947 img_barrier.subresourceRange.layerCount = 1;
9948 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009949 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
9950 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009951 m_errorMonitor->VerifyFound();
9952
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009954
9955 VkQueryPool query_pool;
9956 VkQueryPoolCreateInfo query_pool_create_info = {};
9957 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
9958 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
9959 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009960 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009961
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009962 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009963 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
9964
9965 vkEndCommandBuffer(m_commandBuffer->handle());
9966 m_errorMonitor->VerifyFound();
9967
9968 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
9969 vkDestroyEvent(m_device->device(), event, nullptr);
9970}
9971
Mark Muellerdfe37552016-07-07 14:47:42 -06009972TEST_F(VkLayerTest, VertexBufferInvalid) {
9973 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
9974 "delete a buffer twice, use an invalid offset for each "
9975 "buffer type, and attempt to bind a null buffer");
9976
9977 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
9978 "using deleted buffer ";
9979 const char *double_destroy_message = "Cannot free buffer 0x";
9980 const char *invalid_offset_message = "vkBindBufferMemory(): "
9981 "memoryOffset is 0x";
9982 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
9983 "storage memoryOffset "
9984 "is 0x";
9985 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
9986 "texel memoryOffset "
9987 "is 0x";
9988 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
9989 "uniform memoryOffset "
9990 "is 0x";
9991 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
9992 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -06009993 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -06009994
9995 ASSERT_NO_FATAL_FAILURE(InitState());
9996 ASSERT_NO_FATAL_FAILURE(InitViewport());
9997 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9998
9999 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010000 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010001 pipe_ms_state_ci.pNext = NULL;
10002 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10003 pipe_ms_state_ci.sampleShadingEnable = 0;
10004 pipe_ms_state_ci.minSampleShading = 1.0;
10005 pipe_ms_state_ci.pSampleMask = nullptr;
10006
10007 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10008 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10009 VkPipelineLayout pipeline_layout;
10010
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010011 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010012 ASSERT_VK_SUCCESS(err);
10013
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010014 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10015 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010016 VkPipelineObj pipe(m_device);
10017 pipe.AddShader(&vs);
10018 pipe.AddShader(&fs);
10019 pipe.AddColorAttachment();
10020 pipe.SetMSAA(&pipe_ms_state_ci);
10021 pipe.SetViewport(m_viewports);
10022 pipe.SetScissor(m_scissors);
10023 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10024
10025 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010026 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010027
10028 {
10029 // Create and bind a vertex buffer in a reduced scope, which will cause
10030 // it to be deleted upon leaving this scope
10031 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010032 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010033 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10034 draw_verticies.AddVertexInputToPipe(pipe);
10035 }
10036
10037 Draw(1, 0, 0, 0);
10038
10039 EndCommandBuffer();
10040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010042 QueueCommandBuffer(false);
10043 m_errorMonitor->VerifyFound();
10044
10045 {
10046 // Create and bind a vertex buffer in a reduced scope, and delete it
10047 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010048 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010050 buffer_test.TestDoubleDestroy();
10051 }
10052 m_errorMonitor->VerifyFound();
10053
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010054 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010055 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10057 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10058 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010059 m_errorMonitor->VerifyFound();
10060 }
10061
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010062 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10063 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010064 // Create and bind a memory buffer with an invalid offset again,
10065 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10067 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10068 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010069 m_errorMonitor->VerifyFound();
10070 }
10071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010072 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010073 // Create and bind a memory buffer with an invalid offset again, but
10074 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10076 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10077 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010078 m_errorMonitor->VerifyFound();
10079 }
10080
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010081 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010082 // Create and bind a memory buffer with an invalid offset again, but
10083 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10085 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10086 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010087 m_errorMonitor->VerifyFound();
10088 }
10089
10090 {
10091 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10093 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10094 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010095 m_errorMonitor->VerifyFound();
10096 }
10097
10098 {
10099 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10101 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10102 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010103 }
10104 m_errorMonitor->VerifyFound();
10105
10106 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10107}
10108
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010109// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10110TEST_F(VkLayerTest, InvalidImageLayout) {
10111 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010112 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10113 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010114 // 3 in ValidateCmdBufImageLayouts
10115 // * -1 Attempt to submit cmd buf w/ deleted image
10116 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10117 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10119 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010120
10121 ASSERT_NO_FATAL_FAILURE(InitState());
10122 // Create src & dst images to use for copy operations
10123 VkImage src_image;
10124 VkImage dst_image;
10125
10126 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10127 const int32_t tex_width = 32;
10128 const int32_t tex_height = 32;
10129
10130 VkImageCreateInfo image_create_info = {};
10131 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10132 image_create_info.pNext = NULL;
10133 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10134 image_create_info.format = tex_format;
10135 image_create_info.extent.width = tex_width;
10136 image_create_info.extent.height = tex_height;
10137 image_create_info.extent.depth = 1;
10138 image_create_info.mipLevels = 1;
10139 image_create_info.arrayLayers = 4;
10140 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10141 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10142 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10143 image_create_info.flags = 0;
10144
10145 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10146 ASSERT_VK_SUCCESS(err);
10147 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10148 ASSERT_VK_SUCCESS(err);
10149
10150 BeginCommandBuffer();
10151 VkImageCopy copyRegion;
10152 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10153 copyRegion.srcSubresource.mipLevel = 0;
10154 copyRegion.srcSubresource.baseArrayLayer = 0;
10155 copyRegion.srcSubresource.layerCount = 1;
10156 copyRegion.srcOffset.x = 0;
10157 copyRegion.srcOffset.y = 0;
10158 copyRegion.srcOffset.z = 0;
10159 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10160 copyRegion.dstSubresource.mipLevel = 0;
10161 copyRegion.dstSubresource.baseArrayLayer = 0;
10162 copyRegion.dstSubresource.layerCount = 1;
10163 copyRegion.dstOffset.x = 0;
10164 copyRegion.dstOffset.y = 0;
10165 copyRegion.dstOffset.z = 0;
10166 copyRegion.extent.width = 1;
10167 copyRegion.extent.height = 1;
10168 copyRegion.extent.depth = 1;
10169 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10170 m_errorMonitor->VerifyFound();
10171 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10173 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10174 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010175 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10176 m_errorMonitor->VerifyFound();
10177 // Final src error is due to bad layout type
10178 m_errorMonitor->SetDesiredFailureMsg(
10179 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10180 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10181 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10182 m_errorMonitor->VerifyFound();
10183 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10185 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010186 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10187 m_errorMonitor->VerifyFound();
10188 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10190 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10191 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010192 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10193 m_errorMonitor->VerifyFound();
10194 m_errorMonitor->SetDesiredFailureMsg(
10195 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10196 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10197 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10198 m_errorMonitor->VerifyFound();
10199 // Now cause error due to bad image layout transition in PipelineBarrier
10200 VkImageMemoryBarrier image_barrier[1] = {};
10201 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10202 image_barrier[0].image = src_image;
10203 image_barrier[0].subresourceRange.layerCount = 2;
10204 image_barrier[0].subresourceRange.levelCount = 2;
10205 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10207 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10208 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10209 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10210 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010211 m_errorMonitor->VerifyFound();
10212
10213 // Finally some layout errors at RenderPass create time
10214 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10215 VkAttachmentReference attach = {};
10216 // perf warning for GENERAL layout w/ non-DS input attachment
10217 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10218 VkSubpassDescription subpass = {};
10219 subpass.inputAttachmentCount = 1;
10220 subpass.pInputAttachments = &attach;
10221 VkRenderPassCreateInfo rpci = {};
10222 rpci.subpassCount = 1;
10223 rpci.pSubpasses = &subpass;
10224 rpci.attachmentCount = 1;
10225 VkAttachmentDescription attach_desc = {};
10226 attach_desc.format = VK_FORMAT_UNDEFINED;
10227 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010228 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010229 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10231 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010232 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10233 m_errorMonitor->VerifyFound();
10234 // error w/ non-general layout
10235 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10236
10237 m_errorMonitor->SetDesiredFailureMsg(
10238 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10239 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10240 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10241 m_errorMonitor->VerifyFound();
10242 subpass.inputAttachmentCount = 0;
10243 subpass.colorAttachmentCount = 1;
10244 subpass.pColorAttachments = &attach;
10245 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10246 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10248 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010249 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10250 m_errorMonitor->VerifyFound();
10251 // error w/ non-color opt or GENERAL layout for color attachment
10252 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10253 m_errorMonitor->SetDesiredFailureMsg(
10254 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10255 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10256 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10257 m_errorMonitor->VerifyFound();
10258 subpass.colorAttachmentCount = 0;
10259 subpass.pDepthStencilAttachment = &attach;
10260 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10261 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10263 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010264 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10265 m_errorMonitor->VerifyFound();
10266 // error w/ non-ds opt or GENERAL layout for color attachment
10267 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10269 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10270 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010271 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10272 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010273 // For this error we need a valid renderpass so create default one
10274 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10275 attach.attachment = 0;
10276 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10277 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10278 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10279 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10280 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10281 // Can't do a CLEAR load on READ_ONLY initialLayout
10282 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10283 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10284 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10286 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10287 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010288 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10289 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010290
10291 vkDestroyImage(m_device->device(), src_image, NULL);
10292 vkDestroyImage(m_device->device(), dst_image, NULL);
10293}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010294
Tobin Ehlise0936662016-10-11 08:10:51 -060010295TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10296 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10297 VkResult err;
10298
10299 ASSERT_NO_FATAL_FAILURE(InitState());
10300
10301 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10302 VkImageTiling tiling;
10303 VkFormatProperties format_properties;
10304 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10305 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10306 tiling = VK_IMAGE_TILING_LINEAR;
10307 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10308 tiling = VK_IMAGE_TILING_OPTIMAL;
10309 } else {
10310 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10311 "skipped.\n");
10312 return;
10313 }
10314
10315 VkDescriptorPoolSize ds_type = {};
10316 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10317 ds_type.descriptorCount = 1;
10318
10319 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10320 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10321 ds_pool_ci.maxSets = 1;
10322 ds_pool_ci.poolSizeCount = 1;
10323 ds_pool_ci.pPoolSizes = &ds_type;
10324 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10325
10326 VkDescriptorPool ds_pool;
10327 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10328 ASSERT_VK_SUCCESS(err);
10329
10330 VkDescriptorSetLayoutBinding dsl_binding = {};
10331 dsl_binding.binding = 0;
10332 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10333 dsl_binding.descriptorCount = 1;
10334 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10335 dsl_binding.pImmutableSamplers = NULL;
10336
10337 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10338 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10339 ds_layout_ci.pNext = NULL;
10340 ds_layout_ci.bindingCount = 1;
10341 ds_layout_ci.pBindings = &dsl_binding;
10342
10343 VkDescriptorSetLayout ds_layout;
10344 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10345 ASSERT_VK_SUCCESS(err);
10346
10347 VkDescriptorSetAllocateInfo alloc_info = {};
10348 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10349 alloc_info.descriptorSetCount = 1;
10350 alloc_info.descriptorPool = ds_pool;
10351 alloc_info.pSetLayouts = &ds_layout;
10352 VkDescriptorSet descriptor_set;
10353 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10354 ASSERT_VK_SUCCESS(err);
10355
10356 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10357 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10358 pipeline_layout_ci.pNext = NULL;
10359 pipeline_layout_ci.setLayoutCount = 1;
10360 pipeline_layout_ci.pSetLayouts = &ds_layout;
10361 VkPipelineLayout pipeline_layout;
10362 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10363 ASSERT_VK_SUCCESS(err);
10364
10365 VkImageObj image(m_device);
10366 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10367 ASSERT_TRUE(image.initialized());
10368 VkImageView view = image.targetView(tex_format);
10369
10370 VkDescriptorImageInfo image_info = {};
10371 image_info.imageView = view;
10372 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10373
10374 VkWriteDescriptorSet descriptor_write = {};
10375 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10376 descriptor_write.dstSet = descriptor_set;
10377 descriptor_write.dstBinding = 0;
10378 descriptor_write.descriptorCount = 1;
10379 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10380 descriptor_write.pImageInfo = &image_info;
10381
10382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10383 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10384 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10385 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10386 m_errorMonitor->VerifyFound();
10387
10388 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10389 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10390 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10391 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10392}
10393
Mark Mueller93b938f2016-08-18 10:27:40 -060010394TEST_F(VkLayerTest, SimultaneousUse) {
10395 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10396 "in primary and secondary command buffers.");
10397
10398 ASSERT_NO_FATAL_FAILURE(InitState());
10399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10400
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010401 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010402 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10403 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010404
10405 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010406 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010407 command_buffer_allocate_info.commandPool = m_commandPool;
10408 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10409 command_buffer_allocate_info.commandBufferCount = 1;
10410
10411 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010412 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010413 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10414 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010415 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010416 command_buffer_inheritance_info.renderPass = m_renderPass;
10417 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10418 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010419 command_buffer_begin_info.flags =
10420 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010421 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10422
10423 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010424 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10425 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010426 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010427 vkEndCommandBuffer(secondary_command_buffer);
10428
Mark Mueller93b938f2016-08-18 10:27:40 -060010429 VkSubmitInfo submit_info = {};
10430 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10431 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010432 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010433 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010434
Mark Mueller4042b652016-09-05 22:52:21 -060010435 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010436 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10438 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010439 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010440 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10441 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010442
10443 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010444 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10445
Mark Mueller4042b652016-09-05 22:52:21 -060010446 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010447 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010448 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10451 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010452 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010453 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10454 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010455}
10456
Mark Mueller917f6bc2016-08-30 10:57:19 -060010457TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10458 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10459 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010460 "Delete objects that are inuse. Call VkQueueSubmit "
10461 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010462
10463 ASSERT_NO_FATAL_FAILURE(InitState());
10464 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10465
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010466 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10467 const char *cannot_delete_event_message = "Cannot delete event 0x";
10468 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10469 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010470
10471 BeginCommandBuffer();
10472
10473 VkEvent event;
10474 VkEventCreateInfo event_create_info = {};
10475 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10476 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010477 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010478
Mark Muellerc8d441e2016-08-23 17:36:00 -060010479 EndCommandBuffer();
10480 vkDestroyEvent(m_device->device(), event, nullptr);
10481
10482 VkSubmitInfo submit_info = {};
10483 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10484 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010485 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010487 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10488 m_errorMonitor->VerifyFound();
10489
10490 m_errorMonitor->SetDesiredFailureMsg(0, "");
10491 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10492
10493 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10494
Mark Mueller917f6bc2016-08-30 10:57:19 -060010495 VkSemaphoreCreateInfo semaphore_create_info = {};
10496 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10497 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010498 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010499 VkFenceCreateInfo fence_create_info = {};
10500 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10501 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010502 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010503
10504 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010505 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010506 descriptor_pool_type_count.descriptorCount = 1;
10507
10508 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10509 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10510 descriptor_pool_create_info.maxSets = 1;
10511 descriptor_pool_create_info.poolSizeCount = 1;
10512 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010513 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010514
10515 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010516 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010517
10518 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010519 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010520 descriptorset_layout_binding.descriptorCount = 1;
10521 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10522
10523 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010524 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010525 descriptorset_layout_create_info.bindingCount = 1;
10526 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10527
10528 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010529 ASSERT_VK_SUCCESS(
10530 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010531
10532 VkDescriptorSet descriptorset;
10533 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010534 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010535 descriptorset_allocate_info.descriptorSetCount = 1;
10536 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10537 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010538 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010539
Mark Mueller4042b652016-09-05 22:52:21 -060010540 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10541
10542 VkDescriptorBufferInfo buffer_info = {};
10543 buffer_info.buffer = buffer_test.GetBuffer();
10544 buffer_info.offset = 0;
10545 buffer_info.range = 1024;
10546
10547 VkWriteDescriptorSet write_descriptor_set = {};
10548 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10549 write_descriptor_set.dstSet = descriptorset;
10550 write_descriptor_set.descriptorCount = 1;
10551 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10552 write_descriptor_set.pBufferInfo = &buffer_info;
10553
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010554 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010555
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010556 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10557 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010558
10559 VkPipelineObj pipe(m_device);
10560 pipe.AddColorAttachment();
10561 pipe.AddShader(&vs);
10562 pipe.AddShader(&fs);
10563
10564 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010565 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010566 pipeline_layout_create_info.setLayoutCount = 1;
10567 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10568
10569 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010570 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010571
10572 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10573
Mark Muellerc8d441e2016-08-23 17:36:00 -060010574 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010575 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010576
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010577 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10578 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10579 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010580
Mark Muellerc8d441e2016-08-23 17:36:00 -060010581 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010582
Mark Mueller917f6bc2016-08-30 10:57:19 -060010583 submit_info.signalSemaphoreCount = 1;
10584 submit_info.pSignalSemaphores = &semaphore;
10585 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010586
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010588 vkDestroyEvent(m_device->device(), event, nullptr);
10589 m_errorMonitor->VerifyFound();
10590
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010592 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10593 m_errorMonitor->VerifyFound();
10594
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010596 vkDestroyFence(m_device->device(), fence, nullptr);
10597 m_errorMonitor->VerifyFound();
10598
Tobin Ehlis122207b2016-09-01 08:50:06 -070010599 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010600 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10601 vkDestroyFence(m_device->device(), fence, nullptr);
10602 vkDestroyEvent(m_device->device(), event, nullptr);
10603 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010604 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010605 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10606}
10607
Tobin Ehlis2adda372016-09-01 08:51:06 -070010608TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10609 TEST_DESCRIPTION("Delete in-use query pool.");
10610
10611 ASSERT_NO_FATAL_FAILURE(InitState());
10612 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10613
10614 VkQueryPool query_pool;
10615 VkQueryPoolCreateInfo query_pool_ci{};
10616 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10617 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10618 query_pool_ci.queryCount = 1;
10619 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10620 BeginCommandBuffer();
10621 // Reset query pool to create binding with cmd buffer
10622 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10623
10624 EndCommandBuffer();
10625
10626 VkSubmitInfo submit_info = {};
10627 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10628 submit_info.commandBufferCount = 1;
10629 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10630 // Submit cmd buffer and then destroy query pool while in-flight
10631 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10632
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010634 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10635 m_errorMonitor->VerifyFound();
10636
10637 vkQueueWaitIdle(m_device->m_queue);
10638 // Now that cmd buffer done we can safely destroy query_pool
10639 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10640}
10641
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010642TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10643 TEST_DESCRIPTION("Delete in-use pipeline.");
10644
10645 ASSERT_NO_FATAL_FAILURE(InitState());
10646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10647
10648 // Empty pipeline layout used for binding PSO
10649 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10650 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10651 pipeline_layout_ci.setLayoutCount = 0;
10652 pipeline_layout_ci.pSetLayouts = NULL;
10653
10654 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010655 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010656 ASSERT_VK_SUCCESS(err);
10657
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010659 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010660 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10661 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010662 // Store pipeline handle so we can actually delete it before test finishes
10663 VkPipeline delete_this_pipeline;
10664 { // Scope pipeline so it will be auto-deleted
10665 VkPipelineObj pipe(m_device);
10666 pipe.AddShader(&vs);
10667 pipe.AddShader(&fs);
10668 pipe.AddColorAttachment();
10669 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10670 delete_this_pipeline = pipe.handle();
10671
10672 BeginCommandBuffer();
10673 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010674 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010675
10676 EndCommandBuffer();
10677
10678 VkSubmitInfo submit_info = {};
10679 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10680 submit_info.commandBufferCount = 1;
10681 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10682 // Submit cmd buffer and then pipeline destroyed while in-flight
10683 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10684 } // Pipeline deletion triggered here
10685 m_errorMonitor->VerifyFound();
10686 // Make sure queue finished and then actually delete pipeline
10687 vkQueueWaitIdle(m_device->m_queue);
10688 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10689 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10690}
10691
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010692TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10693 TEST_DESCRIPTION("Delete in-use imageView.");
10694
10695 ASSERT_NO_FATAL_FAILURE(InitState());
10696 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10697
10698 VkDescriptorPoolSize ds_type_count;
10699 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10700 ds_type_count.descriptorCount = 1;
10701
10702 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10703 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10704 ds_pool_ci.maxSets = 1;
10705 ds_pool_ci.poolSizeCount = 1;
10706 ds_pool_ci.pPoolSizes = &ds_type_count;
10707
10708 VkDescriptorPool ds_pool;
10709 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10710 ASSERT_VK_SUCCESS(err);
10711
10712 VkSamplerCreateInfo sampler_ci = {};
10713 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10714 sampler_ci.pNext = NULL;
10715 sampler_ci.magFilter = VK_FILTER_NEAREST;
10716 sampler_ci.minFilter = VK_FILTER_NEAREST;
10717 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10718 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10719 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10720 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10721 sampler_ci.mipLodBias = 1.0;
10722 sampler_ci.anisotropyEnable = VK_FALSE;
10723 sampler_ci.maxAnisotropy = 1;
10724 sampler_ci.compareEnable = VK_FALSE;
10725 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10726 sampler_ci.minLod = 1.0;
10727 sampler_ci.maxLod = 1.0;
10728 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10729 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10730 VkSampler sampler;
10731
10732 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10733 ASSERT_VK_SUCCESS(err);
10734
10735 VkDescriptorSetLayoutBinding layout_binding;
10736 layout_binding.binding = 0;
10737 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10738 layout_binding.descriptorCount = 1;
10739 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10740 layout_binding.pImmutableSamplers = NULL;
10741
10742 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10743 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10744 ds_layout_ci.bindingCount = 1;
10745 ds_layout_ci.pBindings = &layout_binding;
10746 VkDescriptorSetLayout ds_layout;
10747 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10748 ASSERT_VK_SUCCESS(err);
10749
10750 VkDescriptorSetAllocateInfo alloc_info = {};
10751 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10752 alloc_info.descriptorSetCount = 1;
10753 alloc_info.descriptorPool = ds_pool;
10754 alloc_info.pSetLayouts = &ds_layout;
10755 VkDescriptorSet descriptor_set;
10756 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10757 ASSERT_VK_SUCCESS(err);
10758
10759 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10760 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10761 pipeline_layout_ci.pNext = NULL;
10762 pipeline_layout_ci.setLayoutCount = 1;
10763 pipeline_layout_ci.pSetLayouts = &ds_layout;
10764
10765 VkPipelineLayout pipeline_layout;
10766 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10767 ASSERT_VK_SUCCESS(err);
10768
10769 VkImageObj image(m_device);
10770 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
10771 ASSERT_TRUE(image.initialized());
10772
10773 VkImageView view;
10774 VkImageViewCreateInfo ivci = {};
10775 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10776 ivci.image = image.handle();
10777 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10778 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
10779 ivci.subresourceRange.layerCount = 1;
10780 ivci.subresourceRange.baseMipLevel = 0;
10781 ivci.subresourceRange.levelCount = 1;
10782 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10783
10784 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
10785 ASSERT_VK_SUCCESS(err);
10786
10787 VkDescriptorImageInfo image_info{};
10788 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10789 image_info.imageView = view;
10790 image_info.sampler = sampler;
10791
10792 VkWriteDescriptorSet descriptor_write = {};
10793 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10794 descriptor_write.dstSet = descriptor_set;
10795 descriptor_write.dstBinding = 0;
10796 descriptor_write.descriptorCount = 1;
10797 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10798 descriptor_write.pImageInfo = &image_info;
10799
10800 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10801
10802 // Create PSO to use the sampler
10803 char const *vsSource = "#version 450\n"
10804 "\n"
10805 "out gl_PerVertex { \n"
10806 " vec4 gl_Position;\n"
10807 "};\n"
10808 "void main(){\n"
10809 " gl_Position = vec4(1);\n"
10810 "}\n";
10811 char const *fsSource = "#version 450\n"
10812 "\n"
10813 "layout(set=0, binding=0) uniform sampler2D s;\n"
10814 "layout(location=0) out vec4 x;\n"
10815 "void main(){\n"
10816 " x = texture(s, vec2(1));\n"
10817 "}\n";
10818 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10819 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10820 VkPipelineObj pipe(m_device);
10821 pipe.AddShader(&vs);
10822 pipe.AddShader(&fs);
10823 pipe.AddColorAttachment();
10824 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10825
10826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
10827
10828 BeginCommandBuffer();
10829 // Bind pipeline to cmd buffer
10830 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10831 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10832 &descriptor_set, 0, nullptr);
10833 Draw(1, 0, 0, 0);
10834 EndCommandBuffer();
10835 // Submit cmd buffer then destroy sampler
10836 VkSubmitInfo submit_info = {};
10837 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10838 submit_info.commandBufferCount = 1;
10839 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10840 // Submit cmd buffer and then destroy imageView while in-flight
10841 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10842
10843 vkDestroyImageView(m_device->device(), view, nullptr);
10844 m_errorMonitor->VerifyFound();
10845 vkQueueWaitIdle(m_device->m_queue);
10846 // Now we can actually destroy imageView
10847 vkDestroyImageView(m_device->device(), view, NULL);
10848 vkDestroySampler(m_device->device(), sampler, nullptr);
10849 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10850 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10851 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10852}
10853
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060010854TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
10855 TEST_DESCRIPTION("Delete in-use bufferView.");
10856
10857 ASSERT_NO_FATAL_FAILURE(InitState());
10858 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10859
10860 VkDescriptorPoolSize ds_type_count;
10861 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10862 ds_type_count.descriptorCount = 1;
10863
10864 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10865 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10866 ds_pool_ci.maxSets = 1;
10867 ds_pool_ci.poolSizeCount = 1;
10868 ds_pool_ci.pPoolSizes = &ds_type_count;
10869
10870 VkDescriptorPool ds_pool;
10871 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10872 ASSERT_VK_SUCCESS(err);
10873
10874 VkDescriptorSetLayoutBinding layout_binding;
10875 layout_binding.binding = 0;
10876 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10877 layout_binding.descriptorCount = 1;
10878 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10879 layout_binding.pImmutableSamplers = NULL;
10880
10881 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10882 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10883 ds_layout_ci.bindingCount = 1;
10884 ds_layout_ci.pBindings = &layout_binding;
10885 VkDescriptorSetLayout ds_layout;
10886 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10887 ASSERT_VK_SUCCESS(err);
10888
10889 VkDescriptorSetAllocateInfo alloc_info = {};
10890 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10891 alloc_info.descriptorSetCount = 1;
10892 alloc_info.descriptorPool = ds_pool;
10893 alloc_info.pSetLayouts = &ds_layout;
10894 VkDescriptorSet descriptor_set;
10895 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10896 ASSERT_VK_SUCCESS(err);
10897
10898 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10899 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10900 pipeline_layout_ci.pNext = NULL;
10901 pipeline_layout_ci.setLayoutCount = 1;
10902 pipeline_layout_ci.pSetLayouts = &ds_layout;
10903
10904 VkPipelineLayout pipeline_layout;
10905 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10906 ASSERT_VK_SUCCESS(err);
10907
10908 VkBuffer buffer;
10909 uint32_t queue_family_index = 0;
10910 VkBufferCreateInfo buffer_create_info = {};
10911 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10912 buffer_create_info.size = 1024;
10913 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10914 buffer_create_info.queueFamilyIndexCount = 1;
10915 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
10916
10917 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
10918 ASSERT_VK_SUCCESS(err);
10919
10920 VkMemoryRequirements memory_reqs;
10921 VkDeviceMemory buffer_memory;
10922
10923 VkMemoryAllocateInfo memory_info = {};
10924 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10925 memory_info.allocationSize = 0;
10926 memory_info.memoryTypeIndex = 0;
10927
10928 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
10929 memory_info.allocationSize = memory_reqs.size;
10930 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
10931 ASSERT_TRUE(pass);
10932
10933 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
10934 ASSERT_VK_SUCCESS(err);
10935 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
10936 ASSERT_VK_SUCCESS(err);
10937
10938 VkBufferView view;
10939 VkBufferViewCreateInfo bvci = {};
10940 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10941 bvci.buffer = buffer;
10942 bvci.format = VK_FORMAT_R8_UNORM;
10943 bvci.range = VK_WHOLE_SIZE;
10944
10945 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
10946 ASSERT_VK_SUCCESS(err);
10947
10948 VkWriteDescriptorSet descriptor_write = {};
10949 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10950 descriptor_write.dstSet = descriptor_set;
10951 descriptor_write.dstBinding = 0;
10952 descriptor_write.descriptorCount = 1;
10953 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10954 descriptor_write.pTexelBufferView = &view;
10955
10956 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10957
10958 char const *vsSource = "#version 450\n"
10959 "\n"
10960 "out gl_PerVertex { \n"
10961 " vec4 gl_Position;\n"
10962 "};\n"
10963 "void main(){\n"
10964 " gl_Position = vec4(1);\n"
10965 "}\n";
10966 char const *fsSource = "#version 450\n"
10967 "\n"
10968 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
10969 "layout(location=0) out vec4 x;\n"
10970 "void main(){\n"
10971 " x = imageLoad(s, 0);\n"
10972 "}\n";
10973 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10974 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10975 VkPipelineObj pipe(m_device);
10976 pipe.AddShader(&vs);
10977 pipe.AddShader(&fs);
10978 pipe.AddColorAttachment();
10979 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10980
10981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
10982
10983 BeginCommandBuffer();
10984 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10985 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10986 VkRect2D scissor = {{0, 0}, {16, 16}};
10987 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10988 // Bind pipeline to cmd buffer
10989 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10990 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10991 &descriptor_set, 0, nullptr);
10992 Draw(1, 0, 0, 0);
10993 EndCommandBuffer();
10994
10995 VkSubmitInfo submit_info = {};
10996 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10997 submit_info.commandBufferCount = 1;
10998 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10999 // Submit cmd buffer and then destroy bufferView while in-flight
11000 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11001
11002 vkDestroyBufferView(m_device->device(), view, nullptr);
11003 m_errorMonitor->VerifyFound();
11004 vkQueueWaitIdle(m_device->m_queue);
11005 // Now we can actually destroy bufferView
11006 vkDestroyBufferView(m_device->device(), view, NULL);
11007 vkDestroyBuffer(m_device->device(), buffer, NULL);
11008 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11009 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11010 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11011 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11012}
11013
Tobin Ehlis209532e2016-09-07 13:52:18 -060011014TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11015 TEST_DESCRIPTION("Delete in-use sampler.");
11016
11017 ASSERT_NO_FATAL_FAILURE(InitState());
11018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11019
11020 VkDescriptorPoolSize ds_type_count;
11021 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11022 ds_type_count.descriptorCount = 1;
11023
11024 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11025 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11026 ds_pool_ci.maxSets = 1;
11027 ds_pool_ci.poolSizeCount = 1;
11028 ds_pool_ci.pPoolSizes = &ds_type_count;
11029
11030 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011031 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011032 ASSERT_VK_SUCCESS(err);
11033
11034 VkSamplerCreateInfo sampler_ci = {};
11035 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11036 sampler_ci.pNext = NULL;
11037 sampler_ci.magFilter = VK_FILTER_NEAREST;
11038 sampler_ci.minFilter = VK_FILTER_NEAREST;
11039 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11040 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11041 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11042 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11043 sampler_ci.mipLodBias = 1.0;
11044 sampler_ci.anisotropyEnable = VK_FALSE;
11045 sampler_ci.maxAnisotropy = 1;
11046 sampler_ci.compareEnable = VK_FALSE;
11047 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11048 sampler_ci.minLod = 1.0;
11049 sampler_ci.maxLod = 1.0;
11050 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11051 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11052 VkSampler sampler;
11053
11054 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11055 ASSERT_VK_SUCCESS(err);
11056
11057 VkDescriptorSetLayoutBinding layout_binding;
11058 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011059 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011060 layout_binding.descriptorCount = 1;
11061 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11062 layout_binding.pImmutableSamplers = NULL;
11063
11064 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11065 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11066 ds_layout_ci.bindingCount = 1;
11067 ds_layout_ci.pBindings = &layout_binding;
11068 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011069 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011070 ASSERT_VK_SUCCESS(err);
11071
11072 VkDescriptorSetAllocateInfo alloc_info = {};
11073 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11074 alloc_info.descriptorSetCount = 1;
11075 alloc_info.descriptorPool = ds_pool;
11076 alloc_info.pSetLayouts = &ds_layout;
11077 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011078 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011079 ASSERT_VK_SUCCESS(err);
11080
11081 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11082 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11083 pipeline_layout_ci.pNext = NULL;
11084 pipeline_layout_ci.setLayoutCount = 1;
11085 pipeline_layout_ci.pSetLayouts = &ds_layout;
11086
11087 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011088 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011089 ASSERT_VK_SUCCESS(err);
11090
11091 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011092 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 -060011093 ASSERT_TRUE(image.initialized());
11094
11095 VkImageView view;
11096 VkImageViewCreateInfo ivci = {};
11097 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11098 ivci.image = image.handle();
11099 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11100 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11101 ivci.subresourceRange.layerCount = 1;
11102 ivci.subresourceRange.baseMipLevel = 0;
11103 ivci.subresourceRange.levelCount = 1;
11104 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11105
11106 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11107 ASSERT_VK_SUCCESS(err);
11108
11109 VkDescriptorImageInfo image_info{};
11110 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11111 image_info.imageView = view;
11112 image_info.sampler = sampler;
11113
11114 VkWriteDescriptorSet descriptor_write = {};
11115 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11116 descriptor_write.dstSet = descriptor_set;
11117 descriptor_write.dstBinding = 0;
11118 descriptor_write.descriptorCount = 1;
11119 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11120 descriptor_write.pImageInfo = &image_info;
11121
11122 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11123
11124 // Create PSO to use the sampler
11125 char const *vsSource = "#version 450\n"
11126 "\n"
11127 "out gl_PerVertex { \n"
11128 " vec4 gl_Position;\n"
11129 "};\n"
11130 "void main(){\n"
11131 " gl_Position = vec4(1);\n"
11132 "}\n";
11133 char const *fsSource = "#version 450\n"
11134 "\n"
11135 "layout(set=0, binding=0) uniform sampler2D s;\n"
11136 "layout(location=0) out vec4 x;\n"
11137 "void main(){\n"
11138 " x = texture(s, vec2(1));\n"
11139 "}\n";
11140 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11141 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11142 VkPipelineObj pipe(m_device);
11143 pipe.AddShader(&vs);
11144 pipe.AddShader(&fs);
11145 pipe.AddColorAttachment();
11146 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11147
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011149
11150 BeginCommandBuffer();
11151 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011152 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11153 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11154 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011155 Draw(1, 0, 0, 0);
11156 EndCommandBuffer();
11157 // Submit cmd buffer then destroy sampler
11158 VkSubmitInfo submit_info = {};
11159 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11160 submit_info.commandBufferCount = 1;
11161 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11162 // Submit cmd buffer and then destroy sampler while in-flight
11163 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11164
11165 vkDestroySampler(m_device->device(), sampler, nullptr);
11166 m_errorMonitor->VerifyFound();
11167 vkQueueWaitIdle(m_device->m_queue);
11168 // Now we can actually destroy sampler
11169 vkDestroySampler(m_device->device(), sampler, nullptr);
11170 vkDestroyImageView(m_device->device(), view, NULL);
11171 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11172 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11173 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11174}
11175
Mark Mueller1cd9f412016-08-25 13:23:52 -060011176TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011177 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011178 "signaled but not waited on by the queue. Wait on a "
11179 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011180
11181 ASSERT_NO_FATAL_FAILURE(InitState());
11182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11183
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011184 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11185 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11186 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011187
11188 BeginCommandBuffer();
11189 EndCommandBuffer();
11190
11191 VkSemaphoreCreateInfo semaphore_create_info = {};
11192 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11193 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011194 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011195 VkSubmitInfo submit_info = {};
11196 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11197 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011198 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011199 submit_info.signalSemaphoreCount = 1;
11200 submit_info.pSignalSemaphores = &semaphore;
11201 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11202 m_errorMonitor->SetDesiredFailureMsg(0, "");
11203 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11204 BeginCommandBuffer();
11205 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011207 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11208 m_errorMonitor->VerifyFound();
11209
Mark Mueller1cd9f412016-08-25 13:23:52 -060011210 VkFenceCreateInfo fence_create_info = {};
11211 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11212 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011213 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011216 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11217 m_errorMonitor->VerifyFound();
11218
Mark Mueller4042b652016-09-05 22:52:21 -060011219 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011220 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011221 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11222}
11223
Tobin Ehlis4af23302016-07-19 10:50:30 -060011224TEST_F(VkLayerTest, FramebufferIncompatible) {
11225 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11226 "that does not match the framebuffer for the active "
11227 "renderpass.");
11228 ASSERT_NO_FATAL_FAILURE(InitState());
11229 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11230
11231 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011232 VkAttachmentDescription attachment = {0,
11233 VK_FORMAT_B8G8R8A8_UNORM,
11234 VK_SAMPLE_COUNT_1_BIT,
11235 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11236 VK_ATTACHMENT_STORE_OP_STORE,
11237 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11238 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11239 VK_IMAGE_LAYOUT_UNDEFINED,
11240 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011242 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011243
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011244 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011245
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011246 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011247
11248 VkRenderPass rp;
11249 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11250 ASSERT_VK_SUCCESS(err);
11251
11252 // A compatible framebuffer.
11253 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011254 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 -060011255 ASSERT_TRUE(image.initialized());
11256
11257 VkImageViewCreateInfo ivci = {
11258 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11259 nullptr,
11260 0,
11261 image.handle(),
11262 VK_IMAGE_VIEW_TYPE_2D,
11263 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011264 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11265 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011266 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11267 };
11268 VkImageView view;
11269 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11270 ASSERT_VK_SUCCESS(err);
11271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011272 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011273 VkFramebuffer fb;
11274 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11275 ASSERT_VK_SUCCESS(err);
11276
11277 VkCommandBufferAllocateInfo cbai = {};
11278 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11279 cbai.commandPool = m_commandPool;
11280 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11281 cbai.commandBufferCount = 1;
11282
11283 VkCommandBuffer sec_cb;
11284 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11285 ASSERT_VK_SUCCESS(err);
11286 VkCommandBufferBeginInfo cbbi = {};
11287 VkCommandBufferInheritanceInfo cbii = {};
11288 cbii.renderPass = renderPass();
11289 cbii.framebuffer = fb;
11290 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11291 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011292 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 -060011293 cbbi.pInheritanceInfo = &cbii;
11294 vkBeginCommandBuffer(sec_cb, &cbbi);
11295 vkEndCommandBuffer(sec_cb);
11296
Chris Forbes3400bc52016-09-13 18:10:34 +120011297 VkCommandBufferBeginInfo cbbi2 = {
11298 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11299 0, nullptr
11300 };
11301 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11302 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011303
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011305 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011306 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11307 m_errorMonitor->VerifyFound();
11308 // Cleanup
11309 vkDestroyImageView(m_device->device(), view, NULL);
11310 vkDestroyRenderPass(m_device->device(), rp, NULL);
11311 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11312}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011313
11314TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11315 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11316 "invalid value. If logicOp is not available, attempt to "
11317 "use it and verify that we see the correct error.");
11318 ASSERT_NO_FATAL_FAILURE(InitState());
11319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11320
11321 auto features = m_device->phy().features();
11322 // Set the expected error depending on whether or not logicOp available
11323 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11325 "enabled, logicOpEnable must be "
11326 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011327 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011329 }
11330 // Create a pipeline using logicOp
11331 VkResult err;
11332
11333 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11334 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11335
11336 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011337 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011338 ASSERT_VK_SUCCESS(err);
11339
11340 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11341 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11342 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011343 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011344 vp_state_ci.pViewports = &vp;
11345 vp_state_ci.scissorCount = 1;
11346 VkRect2D scissors = {}; // Dummy scissors to point to
11347 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011348
11349 VkPipelineShaderStageCreateInfo shaderStages[2];
11350 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11351
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011352 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11353 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011354 shaderStages[0] = vs.GetStageCreateInfo();
11355 shaderStages[1] = fs.GetStageCreateInfo();
11356
11357 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11358 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11359
11360 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11361 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11362 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11363
11364 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11365 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011366 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011367
11368 VkPipelineColorBlendAttachmentState att = {};
11369 att.blendEnable = VK_FALSE;
11370 att.colorWriteMask = 0xf;
11371
11372 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11373 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11374 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11375 cb_ci.logicOpEnable = VK_TRUE;
11376 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11377 cb_ci.attachmentCount = 1;
11378 cb_ci.pAttachments = &att;
11379
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011380 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11381 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11382 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11383
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011384 VkGraphicsPipelineCreateInfo gp_ci = {};
11385 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11386 gp_ci.stageCount = 2;
11387 gp_ci.pStages = shaderStages;
11388 gp_ci.pVertexInputState = &vi_ci;
11389 gp_ci.pInputAssemblyState = &ia_ci;
11390 gp_ci.pViewportState = &vp_state_ci;
11391 gp_ci.pRasterizationState = &rs_ci;
11392 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011393 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011394 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11395 gp_ci.layout = pipeline_layout;
11396 gp_ci.renderPass = renderPass();
11397
11398 VkPipelineCacheCreateInfo pc_ci = {};
11399 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11400
11401 VkPipeline pipeline;
11402 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011403 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011404 ASSERT_VK_SUCCESS(err);
11405
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011406 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011407 m_errorMonitor->VerifyFound();
11408 if (VK_SUCCESS == err) {
11409 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11410 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011411 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11412 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11413}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011414#endif // DRAW_STATE_TESTS
11415
Tobin Ehlis0788f522015-05-26 16:11:58 -060011416#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011417#if GTEST_IS_THREADSAFE
11418struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011419 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011420 VkEvent event;
11421 bool bailout;
11422};
11423
Karl Schultz6addd812016-02-02 17:17:23 -070011424extern "C" void *AddToCommandBuffer(void *arg) {
11425 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011426
Mike Stroyana6d14942016-07-13 15:10:05 -060011427 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011428 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011429 if (data->bailout) {
11430 break;
11431 }
11432 }
11433 return NULL;
11434}
11435
Karl Schultz6addd812016-02-02 17:17:23 -070011436TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011437 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011438
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011440
Mike Stroyanaccf7692015-05-12 16:00:45 -060011441 ASSERT_NO_FATAL_FAILURE(InitState());
11442 ASSERT_NO_FATAL_FAILURE(InitViewport());
11443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11444
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011445 // Calls AllocateCommandBuffers
11446 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011447
11448 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011449 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011450
11451 VkEventCreateInfo event_info;
11452 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011453 VkResult err;
11454
11455 memset(&event_info, 0, sizeof(event_info));
11456 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11457
Chia-I Wuf7458c52015-10-26 21:10:41 +080011458 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011459 ASSERT_VK_SUCCESS(err);
11460
Mike Stroyanaccf7692015-05-12 16:00:45 -060011461 err = vkResetEvent(device(), event);
11462 ASSERT_VK_SUCCESS(err);
11463
11464 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011465 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011466 data.event = event;
11467 data.bailout = false;
11468 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011469
11470 // First do some correct operations using multiple threads.
11471 // Add many entries to command buffer from another thread.
11472 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11473 // Make non-conflicting calls from this thread at the same time.
11474 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011475 uint32_t count;
11476 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011477 }
11478 test_platform_thread_join(thread, NULL);
11479
11480 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011481 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011482 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011483 // Add many entries to command buffer from this thread at the same time.
11484 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011485
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011486 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011487 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011488
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011489 m_errorMonitor->SetBailout(NULL);
11490
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011491 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011492
Chia-I Wuf7458c52015-10-26 21:10:41 +080011493 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011494}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011495#endif // GTEST_IS_THREADSAFE
11496#endif // THREADING_TESTS
11497
Chris Forbes9f7ff632015-05-25 11:13:08 +120011498#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011499TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011500 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11501 "with an impossible code size");
11502
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011504
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011505 ASSERT_NO_FATAL_FAILURE(InitState());
11506 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11507
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011508 VkShaderModule module;
11509 VkShaderModuleCreateInfo moduleCreateInfo;
11510 struct icd_spv_header spv;
11511
11512 spv.magic = ICD_SPV_MAGIC;
11513 spv.version = ICD_SPV_VERSION;
11514 spv.gen_magic = 0;
11515
11516 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11517 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011518 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011519 moduleCreateInfo.codeSize = 4;
11520 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011521 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011522
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011523 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011524}
11525
Karl Schultz6addd812016-02-02 17:17:23 -070011526TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011527 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11528 "with a bad magic number");
11529
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011531
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011532 ASSERT_NO_FATAL_FAILURE(InitState());
11533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11534
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011535 VkShaderModule module;
11536 VkShaderModuleCreateInfo moduleCreateInfo;
11537 struct icd_spv_header spv;
11538
11539 spv.magic = ~ICD_SPV_MAGIC;
11540 spv.version = ICD_SPV_VERSION;
11541 spv.gen_magic = 0;
11542
11543 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11544 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011545 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011546 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11547 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011548 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011549
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011550 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011551}
11552
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011553#if 0
11554// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011555TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011557 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011558
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011559 ASSERT_NO_FATAL_FAILURE(InitState());
11560 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11561
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011562 VkShaderModule module;
11563 VkShaderModuleCreateInfo moduleCreateInfo;
11564 struct icd_spv_header spv;
11565
11566 spv.magic = ICD_SPV_MAGIC;
11567 spv.version = ~ICD_SPV_VERSION;
11568 spv.gen_magic = 0;
11569
11570 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11571 moduleCreateInfo.pNext = NULL;
11572
Karl Schultz6addd812016-02-02 17:17:23 -070011573 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011574 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11575 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011576 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011577
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011578 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011579}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011580#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011581
Karl Schultz6addd812016-02-02 17:17:23 -070011582TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011583 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11584 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011586
Chris Forbes9f7ff632015-05-25 11:13:08 +120011587 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011588 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011589
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011590 char const *vsSource = "#version 450\n"
11591 "\n"
11592 "layout(location=0) out float x;\n"
11593 "out gl_PerVertex {\n"
11594 " vec4 gl_Position;\n"
11595 "};\n"
11596 "void main(){\n"
11597 " gl_Position = vec4(1);\n"
11598 " x = 0;\n"
11599 "}\n";
11600 char const *fsSource = "#version 450\n"
11601 "\n"
11602 "layout(location=0) out vec4 color;\n"
11603 "void main(){\n"
11604 " color = vec4(1);\n"
11605 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011606
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011607 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11608 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011609
11610 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011611 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011612 pipe.AddShader(&vs);
11613 pipe.AddShader(&fs);
11614
Chris Forbes9f7ff632015-05-25 11:13:08 +120011615 VkDescriptorSetObj descriptorSet(m_device);
11616 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011617 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011618
Tony Barbour5781e8f2015-08-04 16:23:11 -060011619 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011620
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011621 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011622}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011623
Mark Mueller098c9cb2016-09-08 09:01:57 -060011624TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11625 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11626
11627 ASSERT_NO_FATAL_FAILURE(InitState());
11628 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11629
11630 const char *bad_specialization_message =
11631 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11632
11633 char const *vsSource =
11634 "#version 450\n"
11635 "\n"
11636 "out gl_PerVertex {\n"
11637 " vec4 gl_Position;\n"
11638 "};\n"
11639 "void main(){\n"
11640 " gl_Position = vec4(1);\n"
11641 "}\n";
11642
11643 char const *fsSource =
11644 "#version 450\n"
11645 "\n"
11646 "layout (constant_id = 0) const float r = 0.0f;\n"
11647 "layout(location = 0) out vec4 uFragColor;\n"
11648 "void main(){\n"
11649 " uFragColor = vec4(r,1,0,1);\n"
11650 "}\n";
11651
11652 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11653 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11654
11655 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11656 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11657
11658 VkPipelineLayout pipeline_layout;
11659 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11660
11661 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11662 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11663 vp_state_create_info.viewportCount = 1;
11664 VkViewport viewport = {};
11665 vp_state_create_info.pViewports = &viewport;
11666 vp_state_create_info.scissorCount = 1;
11667 VkRect2D scissors = {};
11668 vp_state_create_info.pScissors = &scissors;
11669
11670 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11671
11672 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11673 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11674 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11675 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11676
11677 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11678 vs.GetStageCreateInfo(),
11679 fs.GetStageCreateInfo()
11680 };
11681
11682 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11683 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11684
11685 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11686 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11687 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11688
11689 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11690 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11691 rasterization_state_create_info.pNext = nullptr;
11692 rasterization_state_create_info.lineWidth = 1.0f;
11693 rasterization_state_create_info.rasterizerDiscardEnable = true;
11694
11695 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11696 color_blend_attachment_state.blendEnable = VK_FALSE;
11697 color_blend_attachment_state.colorWriteMask = 0xf;
11698
11699 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11700 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11701 color_blend_state_create_info.attachmentCount = 1;
11702 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11703
11704 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11705 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11706 graphicspipe_create_info.stageCount = 2;
11707 graphicspipe_create_info.pStages = shader_stage_create_info;
11708 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11709 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11710 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11711 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11712 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11713 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11714 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11715 graphicspipe_create_info.layout = pipeline_layout;
11716 graphicspipe_create_info.renderPass = renderPass();
11717
11718 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
11719 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11720
11721 VkPipelineCache pipelineCache;
11722 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
11723
11724 // This structure maps constant ids to data locations.
11725 const VkSpecializationMapEntry entry =
11726 // id, offset, size
11727 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
11728
11729 uint32_t data = 1;
11730
11731 // Set up the info describing spec map and data
11732 const VkSpecializationInfo specialization_info = {
11733 1,
11734 &entry,
11735 1 * sizeof(float),
11736 &data,
11737 };
11738 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
11739
11740 VkPipeline pipeline;
11741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
11742 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
11743 m_errorMonitor->VerifyFound();
11744
11745 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
11746 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11747}
11748
11749TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
11750 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11751
11752 ASSERT_NO_FATAL_FAILURE(InitState());
11753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11754
11755 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
11756
11757 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
11758 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11759 descriptor_pool_type_count[0].descriptorCount = 1;
11760 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11761 descriptor_pool_type_count[1].descriptorCount = 1;
11762
11763 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11764 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11765 descriptor_pool_create_info.maxSets = 1;
11766 descriptor_pool_create_info.poolSizeCount = 2;
11767 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
11768 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11769
11770 VkDescriptorPool descriptorset_pool;
11771 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11772
11773 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11774 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11775 descriptorset_layout_binding.descriptorCount = 1;
11776 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11777
11778 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11779 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11780 descriptorset_layout_create_info.bindingCount = 1;
11781 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11782
11783 VkDescriptorSetLayout descriptorset_layout;
11784 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
11785
11786 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11787 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11788 descriptorset_allocate_info.descriptorSetCount = 1;
11789 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11790 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11791 VkDescriptorSet descriptorset;
11792 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11793
11794 // Challenge core_validation with a non uniform buffer type.
11795 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
11796
Mark Mueller098c9cb2016-09-08 09:01:57 -060011797 char const *vsSource =
11798 "#version 450\n"
11799 "\n"
11800 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11801 " mat4 mvp;\n"
11802 "} ubuf;\n"
11803 "out gl_PerVertex {\n"
11804 " vec4 gl_Position;\n"
11805 "};\n"
11806 "void main(){\n"
11807 " gl_Position = ubuf.mvp * vec4(1);\n"
11808 "}\n";
11809
11810 char const *fsSource =
11811 "#version 450\n"
11812 "\n"
11813 "layout(location = 0) out vec4 uFragColor;\n"
11814 "void main(){\n"
11815 " uFragColor = vec4(0,1,0,1);\n"
11816 "}\n";
11817
11818 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11819 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11820
11821 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11822 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11823 pipeline_layout_create_info.setLayoutCount = 1;
11824 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11825
11826 VkPipelineLayout pipeline_layout;
11827 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11828
11829 VkPipelineObj pipe(m_device);
11830 pipe.AddColorAttachment();
11831 pipe.AddShader(&vs);
11832 pipe.AddShader(&fs);
11833
11834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
11835 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11836 m_errorMonitor->VerifyFound();
11837
11838 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11839 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11840 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11841}
11842
11843TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
11844 TEST_DESCRIPTION(
11845 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
11846
11847 ASSERT_NO_FATAL_FAILURE(InitState());
11848 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11849
11850 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
11851
11852 VkDescriptorPoolSize descriptor_pool_type_count = {};
11853 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11854 descriptor_pool_type_count.descriptorCount = 1;
11855
11856 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11857 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11858 descriptor_pool_create_info.maxSets = 1;
11859 descriptor_pool_create_info.poolSizeCount = 1;
11860 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
11861 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11862
11863 VkDescriptorPool descriptorset_pool;
11864 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11865
11866 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11867 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11868 descriptorset_layout_binding.descriptorCount = 1;
11869 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
11870 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11871
11872 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11873 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11874 descriptorset_layout_create_info.bindingCount = 1;
11875 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11876
11877 VkDescriptorSetLayout descriptorset_layout;
11878 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
11879 nullptr, &descriptorset_layout));
11880
11881 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11882 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11883 descriptorset_allocate_info.descriptorSetCount = 1;
11884 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11885 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11886 VkDescriptorSet descriptorset;
11887 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11888
11889 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11890
Mark Mueller098c9cb2016-09-08 09:01:57 -060011891 char const *vsSource =
11892 "#version 450\n"
11893 "\n"
11894 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11895 " mat4 mvp;\n"
11896 "} ubuf;\n"
11897 "out gl_PerVertex {\n"
11898 " vec4 gl_Position;\n"
11899 "};\n"
11900 "void main(){\n"
11901 " gl_Position = ubuf.mvp * vec4(1);\n"
11902 "}\n";
11903
11904 char const *fsSource =
11905 "#version 450\n"
11906 "\n"
11907 "layout(location = 0) out vec4 uFragColor;\n"
11908 "void main(){\n"
11909 " uFragColor = vec4(0,1,0,1);\n"
11910 "}\n";
11911
11912 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11913 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11914
11915 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11916 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11917 pipeline_layout_create_info.setLayoutCount = 1;
11918 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11919
11920 VkPipelineLayout pipeline_layout;
11921 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11922
11923 VkPipelineObj pipe(m_device);
11924 pipe.AddColorAttachment();
11925 pipe.AddShader(&vs);
11926 pipe.AddShader(&fs);
11927
11928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
11929 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11930 m_errorMonitor->VerifyFound();
11931
11932 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11933 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11934 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11935}
11936
11937TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
11938 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
11939 "accessible from the current shader stage.");
11940
11941 ASSERT_NO_FATAL_FAILURE(InitState());
11942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11943
11944 const char *push_constant_not_accessible_message =
11945 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
11946
11947 char const *vsSource =
11948 "#version 450\n"
11949 "\n"
11950 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
11951 "out gl_PerVertex {\n"
11952 " vec4 gl_Position;\n"
11953 "};\n"
11954 "void main(){\n"
11955 " gl_Position = vec4(consts.x);\n"
11956 "}\n";
11957
11958 char const *fsSource =
11959 "#version 450\n"
11960 "\n"
11961 "layout(location = 0) out vec4 uFragColor;\n"
11962 "void main(){\n"
11963 " uFragColor = vec4(0,1,0,1);\n"
11964 "}\n";
11965
11966 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11967 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11968
11969 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11970 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11971
11972 // Set up a push constant range
11973 VkPushConstantRange push_constant_ranges = {};
11974 // Set to the wrong stage to challenge core_validation
11975 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11976 push_constant_ranges.size = 4;
11977
11978 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
11979 pipeline_layout_create_info.pushConstantRangeCount = 1;
11980
11981 VkPipelineLayout pipeline_layout;
11982 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11983
11984 VkPipelineObj pipe(m_device);
11985 pipe.AddColorAttachment();
11986 pipe.AddShader(&vs);
11987 pipe.AddShader(&fs);
11988
11989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
11990 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11991 m_errorMonitor->VerifyFound();
11992
11993 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11994}
11995
11996TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
11997 TEST_DESCRIPTION(
11998 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
11999
12000 ASSERT_NO_FATAL_FAILURE(InitState());
12001 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12002
12003 const char *feature_not_enabled_message =
12004 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12005
12006 // Some awkward steps are required to test with custom device features.
12007 std::vector<const char *> device_extension_names;
12008 auto features = m_device->phy().features();
12009 // Disable support for 64 bit floats
12010 features.shaderFloat64 = false;
12011 // The sacrificial device object
12012 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12013
12014 char const *vsSource = "#version 450\n"
12015 "\n"
12016 "out gl_PerVertex {\n"
12017 " vec4 gl_Position;\n"
12018 "};\n"
12019 "void main(){\n"
12020 " gl_Position = vec4(1);\n"
12021 "}\n";
12022 char const *fsSource = "#version 450\n"
12023 "\n"
12024 "layout(location=0) out vec4 color;\n"
12025 "void main(){\n"
12026 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12027 " color = vec4(green);\n"
12028 "}\n";
12029
12030 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12031 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12032
12033 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012034
12035 VkPipelineObj pipe(&test_device);
12036 pipe.AddColorAttachment();
12037 pipe.AddShader(&vs);
12038 pipe.AddShader(&fs);
12039
12040 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12041 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12042 VkPipelineLayout pipeline_layout;
12043 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12044
12045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12046 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12047 m_errorMonitor->VerifyFound();
12048
12049 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12050}
12051
12052TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12053 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12054
12055 ASSERT_NO_FATAL_FAILURE(InitState());
12056 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12057
12058 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12059
12060 char const *vsSource = "#version 450\n"
12061 "\n"
12062 "out gl_PerVertex {\n"
12063 " vec4 gl_Position;\n"
12064 "};\n"
12065 "layout(xfb_buffer = 1) out;"
12066 "void main(){\n"
12067 " gl_Position = vec4(1);\n"
12068 "}\n";
12069 char const *fsSource = "#version 450\n"
12070 "\n"
12071 "layout(location=0) out vec4 color;\n"
12072 "void main(){\n"
12073 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12074 " color = vec4(green);\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 VkPipelineObj pipe(m_device);
12081 pipe.AddColorAttachment();
12082 pipe.AddShader(&vs);
12083 pipe.AddShader(&fs);
12084
12085 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12086 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12087 VkPipelineLayout pipeline_layout;
12088 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12089
12090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12091 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12092 m_errorMonitor->VerifyFound();
12093
12094 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12095}
12096
Karl Schultz6addd812016-02-02 17:17:23 -070012097TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012098 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12099 "which is not present in the outputs of the previous stage");
12100
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012102
Chris Forbes59cb88d2015-05-25 11:13:13 +120012103 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012104 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012106 char const *vsSource = "#version 450\n"
12107 "\n"
12108 "out gl_PerVertex {\n"
12109 " vec4 gl_Position;\n"
12110 "};\n"
12111 "void main(){\n"
12112 " gl_Position = vec4(1);\n"
12113 "}\n";
12114 char const *fsSource = "#version 450\n"
12115 "\n"
12116 "layout(location=0) in float x;\n"
12117 "layout(location=0) out vec4 color;\n"
12118 "void main(){\n"
12119 " color = vec4(x);\n"
12120 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012121
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012122 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12123 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012124
12125 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012126 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012127 pipe.AddShader(&vs);
12128 pipe.AddShader(&fs);
12129
Chris Forbes59cb88d2015-05-25 11:13:13 +120012130 VkDescriptorSetObj descriptorSet(m_device);
12131 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012132 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012133
Tony Barbour5781e8f2015-08-04 16:23:11 -060012134 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012135
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012136 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012137}
12138
Karl Schultz6addd812016-02-02 17:17:23 -070012139TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012140 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12141 "within an interace block, which is not present in the outputs "
12142 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012144
12145 ASSERT_NO_FATAL_FAILURE(InitState());
12146 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12147
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012148 char const *vsSource = "#version 450\n"
12149 "\n"
12150 "out gl_PerVertex {\n"
12151 " vec4 gl_Position;\n"
12152 "};\n"
12153 "void main(){\n"
12154 " gl_Position = vec4(1);\n"
12155 "}\n";
12156 char const *fsSource = "#version 450\n"
12157 "\n"
12158 "in block { layout(location=0) float x; } ins;\n"
12159 "layout(location=0) out vec4 color;\n"
12160 "void main(){\n"
12161 " color = vec4(ins.x);\n"
12162 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012163
12164 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12165 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12166
12167 VkPipelineObj pipe(m_device);
12168 pipe.AddColorAttachment();
12169 pipe.AddShader(&vs);
12170 pipe.AddShader(&fs);
12171
12172 VkDescriptorSetObj descriptorSet(m_device);
12173 descriptorSet.AppendDummy();
12174 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12175
12176 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12177
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012178 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012179}
12180
Karl Schultz6addd812016-02-02 17:17:23 -070012181TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012182 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012183 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12185 "output arr[2] of float32' vs 'ptr to "
12186 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012187
12188 ASSERT_NO_FATAL_FAILURE(InitState());
12189 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012191 char const *vsSource = "#version 450\n"
12192 "\n"
12193 "layout(location=0) out float x[2];\n"
12194 "out gl_PerVertex {\n"
12195 " vec4 gl_Position;\n"
12196 "};\n"
12197 "void main(){\n"
12198 " x[0] = 0; x[1] = 0;\n"
12199 " gl_Position = vec4(1);\n"
12200 "}\n";
12201 char const *fsSource = "#version 450\n"
12202 "\n"
12203 "layout(location=0) in float x[3];\n"
12204 "layout(location=0) out vec4 color;\n"
12205 "void main(){\n"
12206 " color = vec4(x[0] + x[1] + x[2]);\n"
12207 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012208
12209 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12210 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12211
12212 VkPipelineObj pipe(m_device);
12213 pipe.AddColorAttachment();
12214 pipe.AddShader(&vs);
12215 pipe.AddShader(&fs);
12216
12217 VkDescriptorSetObj descriptorSet(m_device);
12218 descriptorSet.AppendDummy();
12219 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12220
12221 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12222
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012223 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012224}
12225
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012226
Karl Schultz6addd812016-02-02 17:17:23 -070012227TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012228 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012229 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012231
Chris Forbesb56af562015-05-25 11:13:17 +120012232 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012234
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012235 char const *vsSource = "#version 450\n"
12236 "\n"
12237 "layout(location=0) out int x;\n"
12238 "out gl_PerVertex {\n"
12239 " vec4 gl_Position;\n"
12240 "};\n"
12241 "void main(){\n"
12242 " x = 0;\n"
12243 " gl_Position = vec4(1);\n"
12244 "}\n";
12245 char const *fsSource = "#version 450\n"
12246 "\n"
12247 "layout(location=0) in float x;\n" /* VS writes int */
12248 "layout(location=0) out vec4 color;\n"
12249 "void main(){\n"
12250 " color = vec4(x);\n"
12251 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012252
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012253 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12254 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012255
12256 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012257 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012258 pipe.AddShader(&vs);
12259 pipe.AddShader(&fs);
12260
Chris Forbesb56af562015-05-25 11:13:17 +120012261 VkDescriptorSetObj descriptorSet(m_device);
12262 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012263 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012264
Tony Barbour5781e8f2015-08-04 16:23:11 -060012265 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012266
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012267 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012268}
12269
Karl Schultz6addd812016-02-02 17:17:23 -070012270TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012271 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012272 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012273 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012275
12276 ASSERT_NO_FATAL_FAILURE(InitState());
12277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12278
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012279 char const *vsSource = "#version 450\n"
12280 "\n"
12281 "out block { layout(location=0) int x; } outs;\n"
12282 "out gl_PerVertex {\n"
12283 " vec4 gl_Position;\n"
12284 "};\n"
12285 "void main(){\n"
12286 " outs.x = 0;\n"
12287 " gl_Position = vec4(1);\n"
12288 "}\n";
12289 char const *fsSource = "#version 450\n"
12290 "\n"
12291 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12292 "layout(location=0) out vec4 color;\n"
12293 "void main(){\n"
12294 " color = vec4(ins.x);\n"
12295 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012296
12297 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12298 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12299
12300 VkPipelineObj pipe(m_device);
12301 pipe.AddColorAttachment();
12302 pipe.AddShader(&vs);
12303 pipe.AddShader(&fs);
12304
12305 VkDescriptorSetObj descriptorSet(m_device);
12306 descriptorSet.AppendDummy();
12307 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12308
12309 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12310
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012311 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012312}
12313
12314TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012315 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012316 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012317 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012318 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 +130012319
12320 ASSERT_NO_FATAL_FAILURE(InitState());
12321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12322
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012323 char const *vsSource = "#version 450\n"
12324 "\n"
12325 "out block { layout(location=1) float x; } outs;\n"
12326 "out gl_PerVertex {\n"
12327 " vec4 gl_Position;\n"
12328 "};\n"
12329 "void main(){\n"
12330 " outs.x = 0;\n"
12331 " gl_Position = vec4(1);\n"
12332 "}\n";
12333 char const *fsSource = "#version 450\n"
12334 "\n"
12335 "in block { layout(location=0) float x; } ins;\n"
12336 "layout(location=0) out vec4 color;\n"
12337 "void main(){\n"
12338 " color = vec4(ins.x);\n"
12339 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012340
12341 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12342 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12343
12344 VkPipelineObj pipe(m_device);
12345 pipe.AddColorAttachment();
12346 pipe.AddShader(&vs);
12347 pipe.AddShader(&fs);
12348
12349 VkDescriptorSetObj descriptorSet(m_device);
12350 descriptorSet.AppendDummy();
12351 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12352
12353 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12354
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012355 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012356}
12357
12358TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012359 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012360 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012361 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012362 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 +130012363
12364 ASSERT_NO_FATAL_FAILURE(InitState());
12365 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12366
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012367 char const *vsSource = "#version 450\n"
12368 "\n"
12369 "out block { layout(location=0, component=0) float x; } outs;\n"
12370 "out gl_PerVertex {\n"
12371 " vec4 gl_Position;\n"
12372 "};\n"
12373 "void main(){\n"
12374 " outs.x = 0;\n"
12375 " gl_Position = vec4(1);\n"
12376 "}\n";
12377 char const *fsSource = "#version 450\n"
12378 "\n"
12379 "in block { layout(location=0, component=1) float x; } ins;\n"
12380 "layout(location=0) out vec4 color;\n"
12381 "void main(){\n"
12382 " color = vec4(ins.x);\n"
12383 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012384
12385 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12386 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12387
12388 VkPipelineObj pipe(m_device);
12389 pipe.AddColorAttachment();
12390 pipe.AddShader(&vs);
12391 pipe.AddShader(&fs);
12392
12393 VkDescriptorSetObj descriptorSet(m_device);
12394 descriptorSet.AppendDummy();
12395 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12396
12397 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12398
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012399 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012400}
12401
Karl Schultz6addd812016-02-02 17:17:23 -070012402TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012403 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12404 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012406
Chris Forbesde136e02015-05-25 11:13:28 +120012407 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012408 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012409
12410 VkVertexInputBindingDescription input_binding;
12411 memset(&input_binding, 0, sizeof(input_binding));
12412
12413 VkVertexInputAttributeDescription input_attrib;
12414 memset(&input_attrib, 0, sizeof(input_attrib));
12415 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12416
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012417 char const *vsSource = "#version 450\n"
12418 "\n"
12419 "out gl_PerVertex {\n"
12420 " vec4 gl_Position;\n"
12421 "};\n"
12422 "void main(){\n"
12423 " gl_Position = vec4(1);\n"
12424 "}\n";
12425 char const *fsSource = "#version 450\n"
12426 "\n"
12427 "layout(location=0) out vec4 color;\n"
12428 "void main(){\n"
12429 " color = vec4(1);\n"
12430 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012431
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012432 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12433 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012434
12435 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012436 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012437 pipe.AddShader(&vs);
12438 pipe.AddShader(&fs);
12439
12440 pipe.AddVertexInputBindings(&input_binding, 1);
12441 pipe.AddVertexInputAttribs(&input_attrib, 1);
12442
Chris Forbesde136e02015-05-25 11:13:28 +120012443 VkDescriptorSetObj descriptorSet(m_device);
12444 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012445 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012446
Tony Barbour5781e8f2015-08-04 16:23:11 -060012447 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012448
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012449 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012450}
12451
Karl Schultz6addd812016-02-02 17:17:23 -070012452TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012453 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12454 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012456
12457 ASSERT_NO_FATAL_FAILURE(InitState());
12458 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12459
12460 VkVertexInputBindingDescription input_binding;
12461 memset(&input_binding, 0, sizeof(input_binding));
12462
12463 VkVertexInputAttributeDescription input_attrib;
12464 memset(&input_attrib, 0, sizeof(input_attrib));
12465 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12466
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012467 char const *vsSource = "#version 450\n"
12468 "\n"
12469 "layout(location=1) in float x;\n"
12470 "out gl_PerVertex {\n"
12471 " vec4 gl_Position;\n"
12472 "};\n"
12473 "void main(){\n"
12474 " gl_Position = vec4(x);\n"
12475 "}\n";
12476 char const *fsSource = "#version 450\n"
12477 "\n"
12478 "layout(location=0) out vec4 color;\n"
12479 "void main(){\n"
12480 " color = vec4(1);\n"
12481 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012482
12483 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12484 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12485
12486 VkPipelineObj pipe(m_device);
12487 pipe.AddColorAttachment();
12488 pipe.AddShader(&vs);
12489 pipe.AddShader(&fs);
12490
12491 pipe.AddVertexInputBindings(&input_binding, 1);
12492 pipe.AddVertexInputAttribs(&input_attrib, 1);
12493
12494 VkDescriptorSetObj descriptorSet(m_device);
12495 descriptorSet.AppendDummy();
12496 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12497
12498 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12499
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012500 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012501}
12502
Karl Schultz6addd812016-02-02 17:17:23 -070012503TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012504 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012505 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012506 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 -060012507
Chris Forbes62e8e502015-05-25 11:13:29 +120012508 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012510
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012511 char const *vsSource = "#version 450\n"
12512 "\n"
12513 "layout(location=0) in vec4 x;\n" /* not provided */
12514 "out gl_PerVertex {\n"
12515 " vec4 gl_Position;\n"
12516 "};\n"
12517 "void main(){\n"
12518 " gl_Position = x;\n"
12519 "}\n";
12520 char const *fsSource = "#version 450\n"
12521 "\n"
12522 "layout(location=0) out vec4 color;\n"
12523 "void main(){\n"
12524 " color = vec4(1);\n"
12525 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012526
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012527 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12528 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012529
12530 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012531 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012532 pipe.AddShader(&vs);
12533 pipe.AddShader(&fs);
12534
Chris Forbes62e8e502015-05-25 11:13:29 +120012535 VkDescriptorSetObj descriptorSet(m_device);
12536 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012537 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012538
Tony Barbour5781e8f2015-08-04 16:23:11 -060012539 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012540
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012541 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012542}
12543
Karl Schultz6addd812016-02-02 17:17:23 -070012544TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012545 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12546 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012547 "vertex shader input that consumes it");
12548 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 -060012549
Chris Forbesc97d98e2015-05-25 11:13:31 +120012550 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012551 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012552
12553 VkVertexInputBindingDescription input_binding;
12554 memset(&input_binding, 0, sizeof(input_binding));
12555
12556 VkVertexInputAttributeDescription input_attrib;
12557 memset(&input_attrib, 0, sizeof(input_attrib));
12558 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12559
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012560 char const *vsSource = "#version 450\n"
12561 "\n"
12562 "layout(location=0) in int x;\n" /* attrib provided float */
12563 "out gl_PerVertex {\n"
12564 " vec4 gl_Position;\n"
12565 "};\n"
12566 "void main(){\n"
12567 " gl_Position = vec4(x);\n"
12568 "}\n";
12569 char const *fsSource = "#version 450\n"
12570 "\n"
12571 "layout(location=0) out vec4 color;\n"
12572 "void main(){\n"
12573 " color = vec4(1);\n"
12574 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012575
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012576 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12577 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012578
12579 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012580 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012581 pipe.AddShader(&vs);
12582 pipe.AddShader(&fs);
12583
12584 pipe.AddVertexInputBindings(&input_binding, 1);
12585 pipe.AddVertexInputAttribs(&input_attrib, 1);
12586
Chris Forbesc97d98e2015-05-25 11:13:31 +120012587 VkDescriptorSetObj descriptorSet(m_device);
12588 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012589 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012590
Tony Barbour5781e8f2015-08-04 16:23:11 -060012591 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012592
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012593 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012594}
12595
Chris Forbesc68b43c2016-04-06 11:18:47 +120012596TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012597 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12598 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12600 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012601
12602 ASSERT_NO_FATAL_FAILURE(InitState());
12603 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12604
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012605 char const *vsSource = "#version 450\n"
12606 "\n"
12607 "out gl_PerVertex {\n"
12608 " vec4 gl_Position;\n"
12609 "};\n"
12610 "void main(){\n"
12611 " gl_Position = vec4(1);\n"
12612 "}\n";
12613 char const *fsSource = "#version 450\n"
12614 "\n"
12615 "layout(location=0) out vec4 color;\n"
12616 "void main(){\n"
12617 " color = vec4(1);\n"
12618 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012619
12620 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12621 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12622
12623 VkPipelineObj pipe(m_device);
12624 pipe.AddColorAttachment();
12625 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012626 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012627 pipe.AddShader(&fs);
12628
12629 VkDescriptorSetObj descriptorSet(m_device);
12630 descriptorSet.AppendDummy();
12631 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12632
12633 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12634
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012635 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012636}
12637
Chris Forbes82ff92a2016-09-09 10:50:24 +120012638TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12640 "No entrypoint found named `foo`");
12641
12642 ASSERT_NO_FATAL_FAILURE(InitState());
12643 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12644
12645 char const *vsSource = "#version 450\n"
12646 "out gl_PerVertex {\n"
12647 " vec4 gl_Position;\n"
12648 "};\n"
12649 "void main(){\n"
12650 " gl_Position = vec4(0);\n"
12651 "}\n";
12652 char const *fsSource = "#version 450\n"
12653 "\n"
12654 "layout(location=0) out vec4 color;\n"
12655 "void main(){\n"
12656 " color = vec4(1);\n"
12657 "}\n";
12658
12659 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12660 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12661
12662 VkPipelineObj pipe(m_device);
12663 pipe.AddColorAttachment();
12664 pipe.AddShader(&vs);
12665 pipe.AddShader(&fs);
12666
12667 VkDescriptorSetObj descriptorSet(m_device);
12668 descriptorSet.AppendDummy();
12669 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12670
12671 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12672
12673 m_errorMonitor->VerifyFound();
12674}
12675
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012676TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12677 m_errorMonitor->SetDesiredFailureMsg(
12678 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12679 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12680 "uses a depth/stencil attachment");
12681
12682 ASSERT_NO_FATAL_FAILURE(InitState());
12683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12684
12685 char const *vsSource = "#version 450\n"
12686 "void main(){ gl_Position = vec4(0); }\n";
12687 char const *fsSource = "#version 450\n"
12688 "\n"
12689 "layout(location=0) out vec4 color;\n"
12690 "void main(){\n"
12691 " color = vec4(1);\n"
12692 "}\n";
12693
12694 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12695 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12696
12697 VkPipelineObj pipe(m_device);
12698 pipe.AddColorAttachment();
12699 pipe.AddShader(&vs);
12700 pipe.AddShader(&fs);
12701
12702 VkDescriptorSetObj descriptorSet(m_device);
12703 descriptorSet.AppendDummy();
12704 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12705
12706 VkAttachmentDescription attachments[] = {
12707 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12708 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12709 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12710 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12711 },
12712 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12713 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12714 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12715 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12716 },
12717 };
12718 VkAttachmentReference refs[] = {
12719 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
12720 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
12721 };
12722 VkSubpassDescription subpass = {
12723 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
12724 1, &refs[0], nullptr, &refs[1],
12725 0, nullptr
12726 };
12727 VkRenderPassCreateInfo rpci = {
12728 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
12729 0, 2, attachments, 1, &subpass, 0, nullptr
12730 };
12731 VkRenderPass rp;
12732 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12733 ASSERT_VK_SUCCESS(err);
12734
12735 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
12736
12737 m_errorMonitor->VerifyFound();
12738
12739 vkDestroyRenderPass(m_device->device(), rp, nullptr);
12740}
12741
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012742TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012743 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
12744 "the TCS without the patch decoration, but consumed in the TES "
12745 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
12747 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120012748
12749 ASSERT_NO_FATAL_FAILURE(InitState());
12750 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12751
Chris Forbesc1e852d2016-04-04 19:26:42 +120012752 if (!m_device->phy().features().tessellationShader) {
12753 printf("Device does not support tessellation shaders; skipped.\n");
12754 return;
12755 }
12756
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012757 char const *vsSource = "#version 450\n"
12758 "void main(){}\n";
12759 char const *tcsSource = "#version 450\n"
12760 "layout(location=0) out int x[];\n"
12761 "layout(vertices=3) out;\n"
12762 "void main(){\n"
12763 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
12764 " gl_TessLevelInner[0] = 1;\n"
12765 " x[gl_InvocationID] = gl_InvocationID;\n"
12766 "}\n";
12767 char const *tesSource = "#version 450\n"
12768 "layout(triangles, equal_spacing, cw) in;\n"
12769 "layout(location=0) patch in int x;\n"
12770 "out gl_PerVertex { vec4 gl_Position; };\n"
12771 "void main(){\n"
12772 " gl_Position.xyz = gl_TessCoord;\n"
12773 " gl_Position.w = x;\n"
12774 "}\n";
12775 char const *fsSource = "#version 450\n"
12776 "layout(location=0) out vec4 color;\n"
12777 "void main(){\n"
12778 " color = vec4(1);\n"
12779 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120012780
12781 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12782 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
12783 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
12784 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12785
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012786 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
12787 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012788
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012789 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012790
12791 VkPipelineObj pipe(m_device);
12792 pipe.SetInputAssembly(&iasci);
12793 pipe.SetTessellation(&tsci);
12794 pipe.AddColorAttachment();
12795 pipe.AddShader(&vs);
12796 pipe.AddShader(&tcs);
12797 pipe.AddShader(&tes);
12798 pipe.AddShader(&fs);
12799
12800 VkDescriptorSetObj descriptorSet(m_device);
12801 descriptorSet.AppendDummy();
12802 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12803
12804 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12805
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012806 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120012807}
12808
Karl Schultz6addd812016-02-02 17:17:23 -070012809TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012810 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
12811 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12813 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012814
Chris Forbes280ba2c2015-06-12 11:16:41 +120012815 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012816 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012817
12818 /* Two binding descriptions for binding 0 */
12819 VkVertexInputBindingDescription input_bindings[2];
12820 memset(input_bindings, 0, sizeof(input_bindings));
12821
12822 VkVertexInputAttributeDescription input_attrib;
12823 memset(&input_attrib, 0, sizeof(input_attrib));
12824 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12825
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012826 char const *vsSource = "#version 450\n"
12827 "\n"
12828 "layout(location=0) in float x;\n" /* attrib provided float */
12829 "out gl_PerVertex {\n"
12830 " vec4 gl_Position;\n"
12831 "};\n"
12832 "void main(){\n"
12833 " gl_Position = vec4(x);\n"
12834 "}\n";
12835 char const *fsSource = "#version 450\n"
12836 "\n"
12837 "layout(location=0) out vec4 color;\n"
12838 "void main(){\n"
12839 " color = vec4(1);\n"
12840 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120012841
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012842 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12843 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012844
12845 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012846 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012847 pipe.AddShader(&vs);
12848 pipe.AddShader(&fs);
12849
12850 pipe.AddVertexInputBindings(input_bindings, 2);
12851 pipe.AddVertexInputAttribs(&input_attrib, 1);
12852
Chris Forbes280ba2c2015-06-12 11:16:41 +120012853 VkDescriptorSetObj descriptorSet(m_device);
12854 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012855 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012856
Tony Barbour5781e8f2015-08-04 16:23:11 -060012857 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012858
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012859 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012860}
Chris Forbes8f68b562015-05-25 11:13:32 +120012861
Karl Schultz6addd812016-02-02 17:17:23 -070012862TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012863 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012864 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012866
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012867 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012868
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012869 char const *vsSource = "#version 450\n"
12870 "\n"
12871 "out gl_PerVertex {\n"
12872 " vec4 gl_Position;\n"
12873 "};\n"
12874 "void main(){\n"
12875 " gl_Position = vec4(1);\n"
12876 "}\n";
12877 char const *fsSource = "#version 450\n"
12878 "\n"
12879 "void main(){\n"
12880 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012881
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012882 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12883 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012884
12885 VkPipelineObj pipe(m_device);
12886 pipe.AddShader(&vs);
12887 pipe.AddShader(&fs);
12888
Chia-I Wu08accc62015-07-07 11:50:03 +080012889 /* set up CB 0, not written */
12890 pipe.AddColorAttachment();
12891 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012892
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012893 VkDescriptorSetObj descriptorSet(m_device);
12894 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012895 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012896
Tony Barbour5781e8f2015-08-04 16:23:11 -060012897 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012898
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012899 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012900}
12901
Karl Schultz6addd812016-02-02 17:17:23 -070012902TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012903 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120012904 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012906 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012907
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012908 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012909
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012910 char const *vsSource = "#version 450\n"
12911 "\n"
12912 "out gl_PerVertex {\n"
12913 " vec4 gl_Position;\n"
12914 "};\n"
12915 "void main(){\n"
12916 " gl_Position = vec4(1);\n"
12917 "}\n";
12918 char const *fsSource = "#version 450\n"
12919 "\n"
12920 "layout(location=0) out vec4 x;\n"
12921 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
12922 "void main(){\n"
12923 " x = vec4(1);\n"
12924 " y = vec4(1);\n"
12925 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012926
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012927 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12928 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012929
12930 VkPipelineObj pipe(m_device);
12931 pipe.AddShader(&vs);
12932 pipe.AddShader(&fs);
12933
Chia-I Wu08accc62015-07-07 11:50:03 +080012934 /* set up CB 0, not written */
12935 pipe.AddColorAttachment();
12936 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012937 /* FS writes CB 1, but we don't configure it */
12938
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012939 VkDescriptorSetObj descriptorSet(m_device);
12940 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012941 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012942
Tony Barbour5781e8f2015-08-04 16:23:11 -060012943 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012944
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012945 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012946}
12947
Karl Schultz6addd812016-02-02 17:17:23 -070012948TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012949 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012950 "type of an fragment shader output variable, and the format of the corresponding attachment");
12951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012952
Chris Forbesa36d69e2015-05-25 11:13:44 +120012953 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012954
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012955 char const *vsSource = "#version 450\n"
12956 "\n"
12957 "out gl_PerVertex {\n"
12958 " vec4 gl_Position;\n"
12959 "};\n"
12960 "void main(){\n"
12961 " gl_Position = vec4(1);\n"
12962 "}\n";
12963 char const *fsSource = "#version 450\n"
12964 "\n"
12965 "layout(location=0) out ivec4 x;\n" /* not UNORM */
12966 "void main(){\n"
12967 " x = ivec4(1);\n"
12968 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120012969
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012970 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12971 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120012972
12973 VkPipelineObj pipe(m_device);
12974 pipe.AddShader(&vs);
12975 pipe.AddShader(&fs);
12976
Chia-I Wu08accc62015-07-07 11:50:03 +080012977 /* set up CB 0; type is UNORM by default */
12978 pipe.AddColorAttachment();
12979 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012980
Chris Forbesa36d69e2015-05-25 11:13:44 +120012981 VkDescriptorSetObj descriptorSet(m_device);
12982 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012983 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120012984
Tony Barbour5781e8f2015-08-04 16:23:11 -060012985 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012986
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012987 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120012988}
Chris Forbes7b1b8932015-06-05 14:43:36 +120012989
Karl Schultz6addd812016-02-02 17:17:23 -070012990TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012991 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
12992 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012994
Chris Forbes556c76c2015-08-14 12:04:59 +120012995 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120012996
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012997 char const *vsSource = "#version 450\n"
12998 "\n"
12999 "out gl_PerVertex {\n"
13000 " vec4 gl_Position;\n"
13001 "};\n"
13002 "void main(){\n"
13003 " gl_Position = vec4(1);\n"
13004 "}\n";
13005 char const *fsSource = "#version 450\n"
13006 "\n"
13007 "layout(location=0) out vec4 x;\n"
13008 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13009 "void main(){\n"
13010 " x = vec4(bar.y);\n"
13011 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013012
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013013 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13014 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013015
Chris Forbes556c76c2015-08-14 12:04:59 +120013016 VkPipelineObj pipe(m_device);
13017 pipe.AddShader(&vs);
13018 pipe.AddShader(&fs);
13019
13020 /* set up CB 0; type is UNORM by default */
13021 pipe.AddColorAttachment();
13022 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13023
13024 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013025 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013026
13027 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13028
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013029 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013030}
13031
Chris Forbes5c59e902016-02-26 16:56:09 +130013032TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013033 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13034 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013036
13037 ASSERT_NO_FATAL_FAILURE(InitState());
13038
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013039 char const *vsSource = "#version 450\n"
13040 "\n"
13041 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13042 "out gl_PerVertex {\n"
13043 " vec4 gl_Position;\n"
13044 "};\n"
13045 "void main(){\n"
13046 " gl_Position = vec4(consts.x);\n"
13047 "}\n";
13048 char const *fsSource = "#version 450\n"
13049 "\n"
13050 "layout(location=0) out vec4 x;\n"
13051 "void main(){\n"
13052 " x = vec4(1);\n"
13053 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013054
13055 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13056 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13057
13058 VkPipelineObj pipe(m_device);
13059 pipe.AddShader(&vs);
13060 pipe.AddShader(&fs);
13061
13062 /* set up CB 0; type is UNORM by default */
13063 pipe.AddColorAttachment();
13064 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13065
13066 VkDescriptorSetObj descriptorSet(m_device);
13067 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13068
13069 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13070
13071 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013072 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013073}
13074
Chris Forbes3fb17902016-08-22 14:57:55 +120013075TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13076 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13077 "which is not included in the subpass description");
13078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13079 "consumes input attachment index 0 but not provided in subpass");
13080
13081 ASSERT_NO_FATAL_FAILURE(InitState());
13082
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013083 char const *vsSource = "#version 450\n"
13084 "\n"
13085 "out gl_PerVertex {\n"
13086 " vec4 gl_Position;\n"
13087 "};\n"
13088 "void main(){\n"
13089 " gl_Position = vec4(1);\n"
13090 "}\n";
13091 char const *fsSource = "#version 450\n"
13092 "\n"
13093 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13094 "layout(location=0) out vec4 color;\n"
13095 "void main() {\n"
13096 " color = subpassLoad(x);\n"
13097 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013098
13099 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13100 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13101
13102 VkPipelineObj pipe(m_device);
13103 pipe.AddShader(&vs);
13104 pipe.AddShader(&fs);
13105 pipe.AddColorAttachment();
13106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013108 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13109 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013110 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013111 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013112 ASSERT_VK_SUCCESS(err);
13113
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013114 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013115 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013116 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013117 ASSERT_VK_SUCCESS(err);
13118
13119 // error here.
13120 pipe.CreateVKPipeline(pl, renderPass());
13121
13122 m_errorMonitor->VerifyFound();
13123
13124 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13125 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13126}
13127
Chris Forbes5a9a0472016-08-22 16:02:09 +120013128TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13129 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13130 "with a format having a different fundamental type");
13131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13132 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13133
13134 ASSERT_NO_FATAL_FAILURE(InitState());
13135
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013136 char const *vsSource = "#version 450\n"
13137 "\n"
13138 "out gl_PerVertex {\n"
13139 " vec4 gl_Position;\n"
13140 "};\n"
13141 "void main(){\n"
13142 " gl_Position = vec4(1);\n"
13143 "}\n";
13144 char const *fsSource = "#version 450\n"
13145 "\n"
13146 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13147 "layout(location=0) out vec4 color;\n"
13148 "void main() {\n"
13149 " color = subpassLoad(x);\n"
13150 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013151
13152 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13153 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13154
13155 VkPipelineObj pipe(m_device);
13156 pipe.AddShader(&vs);
13157 pipe.AddShader(&fs);
13158 pipe.AddColorAttachment();
13159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13160
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013161 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13162 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013163 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013164 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013165 ASSERT_VK_SUCCESS(err);
13166
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013167 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013168 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013169 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013170 ASSERT_VK_SUCCESS(err);
13171
13172 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013173 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13174 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13175 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13176 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13177 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 +120013178 };
13179 VkAttachmentReference color = {
13180 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13181 };
13182 VkAttachmentReference input = {
13183 1, VK_IMAGE_LAYOUT_GENERAL,
13184 };
13185
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013186 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013187
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013188 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013189 VkRenderPass rp;
13190 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13191 ASSERT_VK_SUCCESS(err);
13192
13193 // error here.
13194 pipe.CreateVKPipeline(pl, rp);
13195
13196 m_errorMonitor->VerifyFound();
13197
13198 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13199 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13200 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13201}
13202
Chris Forbes541f7b02016-08-22 15:30:27 +120013203TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13204 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13205 "which is not included in the subpass description -- array case");
13206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13207 "consumes input attachment index 1 but not provided in subpass");
13208
13209 ASSERT_NO_FATAL_FAILURE(InitState());
13210
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013211 char const *vsSource = "#version 450\n"
13212 "\n"
13213 "out gl_PerVertex {\n"
13214 " vec4 gl_Position;\n"
13215 "};\n"
13216 "void main(){\n"
13217 " gl_Position = vec4(1);\n"
13218 "}\n";
13219 char const *fsSource = "#version 450\n"
13220 "\n"
13221 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13222 "layout(location=0) out vec4 color;\n"
13223 "void main() {\n"
13224 " color = subpassLoad(xs[1]);\n"
13225 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013226
13227 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13228 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13229
13230 VkPipelineObj pipe(m_device);
13231 pipe.AddShader(&vs);
13232 pipe.AddShader(&fs);
13233 pipe.AddColorAttachment();
13234 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13235
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013236 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13237 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013238 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013239 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013240 ASSERT_VK_SUCCESS(err);
13241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013242 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013243 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013244 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013245 ASSERT_VK_SUCCESS(err);
13246
13247 // error here.
13248 pipe.CreateVKPipeline(pl, renderPass());
13249
13250 m_errorMonitor->VerifyFound();
13251
13252 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13253 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13254}
13255
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013256TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013257 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13258 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013260
13261 ASSERT_NO_FATAL_FAILURE(InitState());
13262
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013263 char const *csSource = "#version 450\n"
13264 "\n"
13265 "layout(local_size_x=1) in;\n"
13266 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13267 "void main(){\n"
13268 " x = vec4(1);\n"
13269 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013270
13271 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13272
13273 VkDescriptorSetObj descriptorSet(m_device);
13274 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13275
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013276 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13277 nullptr,
13278 0,
13279 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13280 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13281 descriptorSet.GetPipelineLayout(),
13282 VK_NULL_HANDLE,
13283 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013284
13285 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013286 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013287
13288 m_errorMonitor->VerifyFound();
13289
13290 if (err == VK_SUCCESS) {
13291 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13292 }
13293}
13294
Chris Forbes22a9b092016-07-19 14:34:05 +120013295TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013296 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13297 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13299 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013300
13301 ASSERT_NO_FATAL_FAILURE(InitState());
13302
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013303 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13304 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013305 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013306 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013307 ASSERT_VK_SUCCESS(err);
13308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013309 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013310 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013311 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013312 ASSERT_VK_SUCCESS(err);
13313
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013314 char const *csSource = "#version 450\n"
13315 "\n"
13316 "layout(local_size_x=1) in;\n"
13317 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13318 "void main() {\n"
13319 " x.x = 1.0f;\n"
13320 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013321 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13322
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013323 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13324 nullptr,
13325 0,
13326 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13327 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13328 pl,
13329 VK_NULL_HANDLE,
13330 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013331
13332 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013333 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013334
13335 m_errorMonitor->VerifyFound();
13336
13337 if (err == VK_SUCCESS) {
13338 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13339 }
13340
13341 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13342 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13343}
13344
Chris Forbes50020592016-07-27 13:52:41 +120013345TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13346 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13347 "does not match the dimensionality declared in the shader");
13348
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013349 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 +120013350
13351 ASSERT_NO_FATAL_FAILURE(InitState());
13352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13353
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013354 char const *vsSource = "#version 450\n"
13355 "\n"
13356 "out gl_PerVertex { vec4 gl_Position; };\n"
13357 "void main() { gl_Position = vec4(0); }\n";
13358 char const *fsSource = "#version 450\n"
13359 "\n"
13360 "layout(set=0, binding=0) uniform sampler3D s;\n"
13361 "layout(location=0) out vec4 color;\n"
13362 "void main() {\n"
13363 " color = texture(s, vec3(0));\n"
13364 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013365 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13366 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13367
13368 VkPipelineObj pipe(m_device);
13369 pipe.AddShader(&vs);
13370 pipe.AddShader(&fs);
13371 pipe.AddColorAttachment();
13372
13373 VkTextureObj texture(m_device, nullptr);
13374 VkSamplerObj sampler(m_device);
13375
13376 VkDescriptorSetObj descriptorSet(m_device);
13377 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13378 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13379
13380 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13381 ASSERT_VK_SUCCESS(err);
13382
13383 BeginCommandBuffer();
13384
13385 m_commandBuffer->BindPipeline(pipe);
13386 m_commandBuffer->BindDescriptorSet(descriptorSet);
13387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013388 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013389 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013390 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013391 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13392
13393 // error produced here.
13394 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13395
13396 m_errorMonitor->VerifyFound();
13397
13398 EndCommandBuffer();
13399}
13400
Chris Forbes5533bfc2016-07-27 14:12:34 +120013401TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13402 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13403 "are consumed via singlesample images types in the shader, or vice versa.");
13404
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013406
13407 ASSERT_NO_FATAL_FAILURE(InitState());
13408 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13409
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013410 char const *vsSource = "#version 450\n"
13411 "\n"
13412 "out gl_PerVertex { vec4 gl_Position; };\n"
13413 "void main() { gl_Position = vec4(0); }\n";
13414 char const *fsSource = "#version 450\n"
13415 "\n"
13416 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13417 "layout(location=0) out vec4 color;\n"
13418 "void main() {\n"
13419 " color = texelFetch(s, ivec2(0), 0);\n"
13420 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013421 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13422 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13423
13424 VkPipelineObj pipe(m_device);
13425 pipe.AddShader(&vs);
13426 pipe.AddShader(&fs);
13427 pipe.AddColorAttachment();
13428
13429 VkTextureObj texture(m_device, nullptr);
13430 VkSamplerObj sampler(m_device);
13431
13432 VkDescriptorSetObj descriptorSet(m_device);
13433 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13434 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13435
13436 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13437 ASSERT_VK_SUCCESS(err);
13438
13439 BeginCommandBuffer();
13440
13441 m_commandBuffer->BindPipeline(pipe);
13442 m_commandBuffer->BindDescriptorSet(descriptorSet);
13443
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013444 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013445 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013446 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013447 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13448
13449 // error produced here.
13450 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13451
13452 m_errorMonitor->VerifyFound();
13453
13454 EndCommandBuffer();
13455}
13456
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013457#endif // SHADER_CHECKER_TESTS
13458
13459#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013460TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013462
13463 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013464
13465 // Create an image
13466 VkImage image;
13467
Karl Schultz6addd812016-02-02 17:17:23 -070013468 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13469 const int32_t tex_width = 32;
13470 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013471
13472 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013473 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13474 image_create_info.pNext = NULL;
13475 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13476 image_create_info.format = tex_format;
13477 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013478 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013479 image_create_info.extent.depth = 1;
13480 image_create_info.mipLevels = 1;
13481 image_create_info.arrayLayers = 1;
13482 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13483 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13484 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13485 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013486
13487 // Introduce error by sending down a bogus width extent
13488 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013489 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013490
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013491 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013492}
13493
Mark Youngc48c4c12016-04-11 14:26:49 -060013494TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13496 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013497
13498 ASSERT_NO_FATAL_FAILURE(InitState());
13499
13500 // Create an image
13501 VkImage image;
13502
13503 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13504 const int32_t tex_width = 32;
13505 const int32_t tex_height = 32;
13506
13507 VkImageCreateInfo image_create_info = {};
13508 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13509 image_create_info.pNext = NULL;
13510 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13511 image_create_info.format = tex_format;
13512 image_create_info.extent.width = tex_width;
13513 image_create_info.extent.height = tex_height;
13514 image_create_info.extent.depth = 1;
13515 image_create_info.mipLevels = 1;
13516 image_create_info.arrayLayers = 1;
13517 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13518 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13519 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13520 image_create_info.flags = 0;
13521
13522 // Introduce error by sending down a bogus width extent
13523 image_create_info.extent.width = 0;
13524 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13525
13526 m_errorMonitor->VerifyFound();
13527}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013528#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013529
Tobin Ehliscde08892015-09-22 10:11:37 -060013530#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013531TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13532 TEST_DESCRIPTION("Create a render pass with an attachment description "
13533 "format set to VK_FORMAT_UNDEFINED");
13534
13535 ASSERT_NO_FATAL_FAILURE(InitState());
13536 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13537
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013539
13540 VkAttachmentReference color_attach = {};
13541 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13542 color_attach.attachment = 0;
13543 VkSubpassDescription subpass = {};
13544 subpass.colorAttachmentCount = 1;
13545 subpass.pColorAttachments = &color_attach;
13546
13547 VkRenderPassCreateInfo rpci = {};
13548 rpci.subpassCount = 1;
13549 rpci.pSubpasses = &subpass;
13550 rpci.attachmentCount = 1;
13551 VkAttachmentDescription attach_desc = {};
13552 attach_desc.format = VK_FORMAT_UNDEFINED;
13553 rpci.pAttachments = &attach_desc;
13554 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13555 VkRenderPass rp;
13556 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13557
13558 m_errorMonitor->VerifyFound();
13559
13560 if (result == VK_SUCCESS) {
13561 vkDestroyRenderPass(m_device->device(), rp, NULL);
13562 }
13563}
13564
Karl Schultz6addd812016-02-02 17:17:23 -070013565TEST_F(VkLayerTest, InvalidImageView) {
13566 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013567
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013569
Tobin Ehliscde08892015-09-22 10:11:37 -060013570 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013571
Mike Stroyana3082432015-09-25 13:39:21 -060013572 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013573 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013574
Karl Schultz6addd812016-02-02 17:17:23 -070013575 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13576 const int32_t tex_width = 32;
13577 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013578
13579 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013580 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13581 image_create_info.pNext = NULL;
13582 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13583 image_create_info.format = tex_format;
13584 image_create_info.extent.width = tex_width;
13585 image_create_info.extent.height = tex_height;
13586 image_create_info.extent.depth = 1;
13587 image_create_info.mipLevels = 1;
13588 image_create_info.arrayLayers = 1;
13589 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13590 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13591 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13592 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013593
Chia-I Wuf7458c52015-10-26 21:10:41 +080013594 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013595 ASSERT_VK_SUCCESS(err);
13596
13597 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013598 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13599 image_view_create_info.image = image;
13600 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13601 image_view_create_info.format = tex_format;
13602 image_view_create_info.subresourceRange.layerCount = 1;
13603 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13604 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013605 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013606
13607 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013608 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013609
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013610 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013611 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013612}
Mike Stroyana3082432015-09-25 13:39:21 -060013613
Mark Youngd339ba32016-05-30 13:28:35 -060013614TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13615 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013617 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013618
13619 ASSERT_NO_FATAL_FAILURE(InitState());
13620
13621 // Create an image and try to create a view with no memory backing the image
13622 VkImage image;
13623
13624 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13625 const int32_t tex_width = 32;
13626 const int32_t tex_height = 32;
13627
13628 VkImageCreateInfo image_create_info = {};
13629 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13630 image_create_info.pNext = NULL;
13631 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13632 image_create_info.format = tex_format;
13633 image_create_info.extent.width = tex_width;
13634 image_create_info.extent.height = tex_height;
13635 image_create_info.extent.depth = 1;
13636 image_create_info.mipLevels = 1;
13637 image_create_info.arrayLayers = 1;
13638 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13639 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13640 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13641 image_create_info.flags = 0;
13642
13643 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13644 ASSERT_VK_SUCCESS(err);
13645
13646 VkImageViewCreateInfo image_view_create_info = {};
13647 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13648 image_view_create_info.image = image;
13649 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13650 image_view_create_info.format = tex_format;
13651 image_view_create_info.subresourceRange.layerCount = 1;
13652 image_view_create_info.subresourceRange.baseMipLevel = 0;
13653 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013654 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013655
13656 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013657 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013658
13659 m_errorMonitor->VerifyFound();
13660 vkDestroyImage(m_device->device(), image, NULL);
13661 // If last error is success, it still created the view, so delete it.
13662 if (err == VK_SUCCESS) {
13663 vkDestroyImageView(m_device->device(), view, NULL);
13664 }
Mark Youngd339ba32016-05-30 13:28:35 -060013665}
13666
Karl Schultz6addd812016-02-02 17:17:23 -070013667TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013668 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013670 "formats must have ONLY the "
13671 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13673 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013674
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013675 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013676
Karl Schultz6addd812016-02-02 17:17:23 -070013677 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013678 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013679 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013680 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013681
13682 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013683 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013684 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013685 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13686 image_view_create_info.format = tex_format;
13687 image_view_create_info.subresourceRange.baseMipLevel = 0;
13688 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013689 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013690 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013691 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013692
13693 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013694 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013695
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013696 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013697}
13698
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013699TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013700 VkResult err;
13701 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013702
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13704 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013705
Mike Stroyana3082432015-09-25 13:39:21 -060013706 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013707
13708 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013709 VkImage srcImage;
13710 VkImage dstImage;
13711 VkDeviceMemory srcMem;
13712 VkDeviceMemory destMem;
13713 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013714
13715 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013716 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13717 image_create_info.pNext = NULL;
13718 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13719 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13720 image_create_info.extent.width = 32;
13721 image_create_info.extent.height = 32;
13722 image_create_info.extent.depth = 1;
13723 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013724 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070013725 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13726 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13727 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13728 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013729
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013730 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013731 ASSERT_VK_SUCCESS(err);
13732
Mark Lobodzinski867787a2016-10-14 11:49:55 -060013733 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013734 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013735 ASSERT_VK_SUCCESS(err);
13736
13737 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013738 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013739 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13740 memAlloc.pNext = NULL;
13741 memAlloc.allocationSize = 0;
13742 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013743
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060013744 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013745 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013746 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060013747 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013748 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013749 ASSERT_VK_SUCCESS(err);
13750
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013751 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013752 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013753 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013754 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013755 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013756 ASSERT_VK_SUCCESS(err);
13757
13758 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
13759 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013760 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013761 ASSERT_VK_SUCCESS(err);
13762
13763 BeginCommandBuffer();
13764 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013765 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060013766 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060013767 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013768 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060013769 copyRegion.srcOffset.x = 0;
13770 copyRegion.srcOffset.y = 0;
13771 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013772 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013773 copyRegion.dstSubresource.mipLevel = 0;
13774 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013775 // Introduce failure by forcing the dst layerCount to differ from src
13776 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013777 copyRegion.dstOffset.x = 0;
13778 copyRegion.dstOffset.y = 0;
13779 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013780 copyRegion.extent.width = 1;
13781 copyRegion.extent.height = 1;
13782 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013783 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060013784 EndCommandBuffer();
13785
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013786 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060013787
Chia-I Wuf7458c52015-10-26 21:10:41 +080013788 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013789 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080013790 vkFreeMemory(m_device->device(), srcMem, NULL);
13791 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060013792}
13793
Tony Barbourd6673642016-05-05 14:46:39 -060013794TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
13795
13796 TEST_DESCRIPTION("Creating images with unsuported formats ");
13797
13798 ASSERT_NO_FATAL_FAILURE(InitState());
13799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13800 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013801 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 -060013802 VK_IMAGE_TILING_OPTIMAL, 0);
13803 ASSERT_TRUE(image.initialized());
13804
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013805 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
13806 VkImageCreateInfo image_create_info;
13807 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13808 image_create_info.pNext = NULL;
13809 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13810 image_create_info.format = VK_FORMAT_UNDEFINED;
13811 image_create_info.extent.width = 32;
13812 image_create_info.extent.height = 32;
13813 image_create_info.extent.depth = 1;
13814 image_create_info.mipLevels = 1;
13815 image_create_info.arrayLayers = 1;
13816 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13817 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13818 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13819 image_create_info.flags = 0;
13820
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13822 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013823
13824 VkImage localImage;
13825 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
13826 m_errorMonitor->VerifyFound();
13827
Tony Barbourd6673642016-05-05 14:46:39 -060013828 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013829 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060013830 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
13831 VkFormat format = static_cast<VkFormat>(f);
13832 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013833 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060013834 unsupported = format;
13835 break;
13836 }
13837 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013838
Tony Barbourd6673642016-05-05 14:46:39 -060013839 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060013840 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060013842
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013843 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060013844 m_errorMonitor->VerifyFound();
13845 }
13846}
13847
13848TEST_F(VkLayerTest, ImageLayerViewTests) {
13849 VkResult ret;
13850 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
13851
13852 ASSERT_NO_FATAL_FAILURE(InitState());
13853
13854 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013855 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 -060013856 VK_IMAGE_TILING_OPTIMAL, 0);
13857 ASSERT_TRUE(image.initialized());
13858
13859 VkImageView imgView;
13860 VkImageViewCreateInfo imgViewInfo = {};
13861 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13862 imgViewInfo.image = image.handle();
13863 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
13864 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13865 imgViewInfo.subresourceRange.layerCount = 1;
13866 imgViewInfo.subresourceRange.baseMipLevel = 0;
13867 imgViewInfo.subresourceRange.levelCount = 1;
13868 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13869
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060013871 // View can't have baseMipLevel >= image's mipLevels - Expect
13872 // VIEW_CREATE_ERROR
13873 imgViewInfo.subresourceRange.baseMipLevel = 1;
13874 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13875 m_errorMonitor->VerifyFound();
13876 imgViewInfo.subresourceRange.baseMipLevel = 0;
13877
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060013879 // View can't have baseArrayLayer >= image's arraySize - Expect
13880 // VIEW_CREATE_ERROR
13881 imgViewInfo.subresourceRange.baseArrayLayer = 1;
13882 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13883 m_errorMonitor->VerifyFound();
13884 imgViewInfo.subresourceRange.baseArrayLayer = 0;
13885
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13887 "pCreateInfo->subresourceRange."
13888 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060013889 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
13890 imgViewInfo.subresourceRange.levelCount = 0;
13891 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13892 m_errorMonitor->VerifyFound();
13893 imgViewInfo.subresourceRange.levelCount = 1;
13894
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13896 "pCreateInfo->subresourceRange."
13897 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013898 m_errorMonitor->SetDesiredFailureMsg(
13899 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13900 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060013901 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
13902 imgViewInfo.subresourceRange.layerCount = 0;
13903 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13904 m_errorMonitor->VerifyFound();
13905 imgViewInfo.subresourceRange.layerCount = 1;
13906
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13909 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13910 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013911 // Can't use depth format for view into color image - Expect INVALID_FORMAT
13912 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
13913 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13914 m_errorMonitor->VerifyFound();
13915 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13916
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13918 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13919 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013920 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
13921 // VIEW_CREATE_ERROR
13922 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
13923 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13924 m_errorMonitor->VerifyFound();
13925 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13926
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
13928 "differing formats but they must be "
13929 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013930 // TODO: Update framework to easily passing mutable flag into ImageObj init
13931 // For now just allowing image for this one test to not have memory bound
13932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13933 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060013934 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
13935 // VIEW_CREATE_ERROR
13936 VkImageCreateInfo mutImgInfo = image.create_info();
13937 VkImage mutImage;
13938 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013939 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060013940 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
13941 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
13942 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
13943 ASSERT_VK_SUCCESS(ret);
13944 imgViewInfo.image = mutImage;
13945 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13946 m_errorMonitor->VerifyFound();
13947 imgViewInfo.image = image.handle();
13948 vkDestroyImage(m_device->handle(), mutImage, NULL);
13949}
13950
13951TEST_F(VkLayerTest, MiscImageLayerTests) {
13952
13953 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
13954
13955 ASSERT_NO_FATAL_FAILURE(InitState());
13956
13957 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013958 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 -060013959 VK_IMAGE_TILING_OPTIMAL, 0);
13960 ASSERT_TRUE(image.initialized());
13961
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060013963 vk_testing::Buffer buffer;
13964 VkMemoryPropertyFlags reqs = 0;
13965 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
13966 VkBufferImageCopy region = {};
13967 region.bufferRowLength = 128;
13968 region.bufferImageHeight = 128;
13969 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13970 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
13971 region.imageSubresource.layerCount = 0;
13972 region.imageExtent.height = 4;
13973 region.imageExtent.width = 4;
13974 region.imageExtent.depth = 1;
13975 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013976 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13977 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060013978 m_errorMonitor->VerifyFound();
13979 region.imageSubresource.layerCount = 1;
13980
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013981 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
13982 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
13983 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
13985 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13986 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013987 m_errorMonitor->VerifyFound();
13988
13989 // BufferOffset must be a multiple of 4
13990 // Introduce failure by setting bufferOffset to a value not divisible by 4
13991 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
13993 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13994 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013995 m_errorMonitor->VerifyFound();
13996
13997 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
13998 region.bufferOffset = 0;
13999 region.imageExtent.height = 128;
14000 region.imageExtent.width = 128;
14001 // Introduce failure by setting bufferRowLength > 0 but less than width
14002 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14004 "must be zero or greater-than-or-equal-to imageExtent.width");
14005 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14006 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014007 m_errorMonitor->VerifyFound();
14008
14009 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14010 region.bufferRowLength = 128;
14011 // Introduce failure by setting bufferRowHeight > 0 but less than height
14012 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14014 "must be zero or greater-than-or-equal-to imageExtent.height");
14015 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14016 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014017 m_errorMonitor->VerifyFound();
14018
14019 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
14021 "specify only COLOR or DEPTH or "
14022 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060014023 // Expect MISMATCHED_IMAGE_ASPECT
14024 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014025 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14026 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014027 m_errorMonitor->VerifyFound();
14028 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14029
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14031 "If the format of srcImage is a depth, stencil, depth stencil or "
14032 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014033 // Expect INVALID_FILTER
14034 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014035 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 -060014036 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014037 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 -060014038 VkImageBlit blitRegion = {};
14039 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14040 blitRegion.srcSubresource.baseArrayLayer = 0;
14041 blitRegion.srcSubresource.layerCount = 1;
14042 blitRegion.srcSubresource.mipLevel = 0;
14043 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14044 blitRegion.dstSubresource.baseArrayLayer = 0;
14045 blitRegion.dstSubresource.layerCount = 1;
14046 blitRegion.dstSubresource.mipLevel = 0;
14047
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014048 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14049 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014050 m_errorMonitor->VerifyFound();
14051
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014052 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14054 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14055 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014056 m_errorMonitor->VerifyFound();
14057
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014059 VkImageMemoryBarrier img_barrier;
14060 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14061 img_barrier.pNext = NULL;
14062 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14063 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14064 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14065 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14066 img_barrier.image = image.handle();
14067 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14068 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14069 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14070 img_barrier.subresourceRange.baseArrayLayer = 0;
14071 img_barrier.subresourceRange.baseMipLevel = 0;
14072 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14073 img_barrier.subresourceRange.layerCount = 0;
14074 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014075 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14076 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014077 m_errorMonitor->VerifyFound();
14078 img_barrier.subresourceRange.layerCount = 1;
14079}
14080
14081TEST_F(VkLayerTest, ImageFormatLimits) {
14082
14083 TEST_DESCRIPTION("Exceed the limits of image format ");
14084
Cody Northropc31a84f2016-08-22 10:41:47 -060014085 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014087 VkImageCreateInfo image_create_info = {};
14088 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14089 image_create_info.pNext = NULL;
14090 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14091 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14092 image_create_info.extent.width = 32;
14093 image_create_info.extent.height = 32;
14094 image_create_info.extent.depth = 1;
14095 image_create_info.mipLevels = 1;
14096 image_create_info.arrayLayers = 1;
14097 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14098 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14099 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14100 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14101 image_create_info.flags = 0;
14102
14103 VkImage nullImg;
14104 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014105 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14106 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014107 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14108 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14109 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14110 m_errorMonitor->VerifyFound();
14111 image_create_info.extent.depth = 1;
14112
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014114 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14115 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14116 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14117 m_errorMonitor->VerifyFound();
14118 image_create_info.mipLevels = 1;
14119
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014121 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14122 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14123 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14124 m_errorMonitor->VerifyFound();
14125 image_create_info.arrayLayers = 1;
14126
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014128 int samples = imgFmtProps.sampleCounts >> 1;
14129 image_create_info.samples = (VkSampleCountFlagBits)samples;
14130 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14131 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14132 m_errorMonitor->VerifyFound();
14133 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14134
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14136 "VK_IMAGE_LAYOUT_UNDEFINED or "
14137 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014138 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14139 // Expect INVALID_LAYOUT
14140 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14141 m_errorMonitor->VerifyFound();
14142 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14143}
14144
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014145TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14146
14147 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014149
14150 ASSERT_NO_FATAL_FAILURE(InitState());
14151
14152 VkImageObj src_image(m_device);
14153 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14154 VkImageObj dst_image(m_device);
14155 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14156
14157 BeginCommandBuffer();
14158 VkImageCopy copy_region;
14159 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14160 copy_region.srcSubresource.mipLevel = 0;
14161 copy_region.srcSubresource.baseArrayLayer = 0;
14162 copy_region.srcSubresource.layerCount = 0;
14163 copy_region.srcOffset.x = 0;
14164 copy_region.srcOffset.y = 0;
14165 copy_region.srcOffset.z = 0;
14166 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14167 copy_region.dstSubresource.mipLevel = 0;
14168 copy_region.dstSubresource.baseArrayLayer = 0;
14169 copy_region.dstSubresource.layerCount = 0;
14170 copy_region.dstOffset.x = 0;
14171 copy_region.dstOffset.y = 0;
14172 copy_region.dstOffset.z = 0;
14173 copy_region.extent.width = 64;
14174 copy_region.extent.height = 64;
14175 copy_region.extent.depth = 1;
14176 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14177 &copy_region);
14178 EndCommandBuffer();
14179
14180 m_errorMonitor->VerifyFound();
14181}
14182
14183TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14184
14185 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014187
14188 ASSERT_NO_FATAL_FAILURE(InitState());
14189
14190 VkImageObj src_image(m_device);
14191 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14192 VkImageObj dst_image(m_device);
14193 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14194
14195 BeginCommandBuffer();
14196 VkImageCopy copy_region;
14197 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14198 copy_region.srcSubresource.mipLevel = 0;
14199 copy_region.srcSubresource.baseArrayLayer = 0;
14200 copy_region.srcSubresource.layerCount = 0;
14201 copy_region.srcOffset.x = 0;
14202 copy_region.srcOffset.y = 0;
14203 copy_region.srcOffset.z = 0;
14204 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14205 copy_region.dstSubresource.mipLevel = 0;
14206 copy_region.dstSubresource.baseArrayLayer = 0;
14207 copy_region.dstSubresource.layerCount = 0;
14208 copy_region.dstOffset.x = 0;
14209 copy_region.dstOffset.y = 0;
14210 copy_region.dstOffset.z = 0;
14211 copy_region.extent.width = 64;
14212 copy_region.extent.height = 64;
14213 copy_region.extent.depth = 1;
14214 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14215 &copy_region);
14216 EndCommandBuffer();
14217
14218 m_errorMonitor->VerifyFound();
14219}
14220
Karl Schultz6addd812016-02-02 17:17:23 -070014221TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014222 VkResult err;
14223 bool pass;
14224
14225 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14227 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014228
14229 ASSERT_NO_FATAL_FAILURE(InitState());
14230
14231 // Create two images of different types and try to copy between them
14232 VkImage srcImage;
14233 VkImage dstImage;
14234 VkDeviceMemory srcMem;
14235 VkDeviceMemory destMem;
14236 VkMemoryRequirements memReqs;
14237
14238 VkImageCreateInfo image_create_info = {};
14239 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14240 image_create_info.pNext = NULL;
14241 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14242 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14243 image_create_info.extent.width = 32;
14244 image_create_info.extent.height = 32;
14245 image_create_info.extent.depth = 1;
14246 image_create_info.mipLevels = 1;
14247 image_create_info.arrayLayers = 1;
14248 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14249 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14250 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14251 image_create_info.flags = 0;
14252
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014253 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014254 ASSERT_VK_SUCCESS(err);
14255
14256 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14257 // Introduce failure by creating second image with a different-sized format.
14258 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014260 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014261 ASSERT_VK_SUCCESS(err);
14262
14263 // Allocate memory
14264 VkMemoryAllocateInfo memAlloc = {};
14265 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14266 memAlloc.pNext = NULL;
14267 memAlloc.allocationSize = 0;
14268 memAlloc.memoryTypeIndex = 0;
14269
14270 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14271 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014272 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014273 ASSERT_TRUE(pass);
14274 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14275 ASSERT_VK_SUCCESS(err);
14276
14277 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14278 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014279 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014280 ASSERT_TRUE(pass);
14281 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14282 ASSERT_VK_SUCCESS(err);
14283
14284 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14285 ASSERT_VK_SUCCESS(err);
14286 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14287 ASSERT_VK_SUCCESS(err);
14288
14289 BeginCommandBuffer();
14290 VkImageCopy copyRegion;
14291 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14292 copyRegion.srcSubresource.mipLevel = 0;
14293 copyRegion.srcSubresource.baseArrayLayer = 0;
14294 copyRegion.srcSubresource.layerCount = 0;
14295 copyRegion.srcOffset.x = 0;
14296 copyRegion.srcOffset.y = 0;
14297 copyRegion.srcOffset.z = 0;
14298 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14299 copyRegion.dstSubresource.mipLevel = 0;
14300 copyRegion.dstSubresource.baseArrayLayer = 0;
14301 copyRegion.dstSubresource.layerCount = 0;
14302 copyRegion.dstOffset.x = 0;
14303 copyRegion.dstOffset.y = 0;
14304 copyRegion.dstOffset.z = 0;
14305 copyRegion.extent.width = 1;
14306 copyRegion.extent.height = 1;
14307 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014308 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014309 EndCommandBuffer();
14310
14311 m_errorMonitor->VerifyFound();
14312
14313 vkDestroyImage(m_device->device(), srcImage, NULL);
14314 vkDestroyImage(m_device->device(), dstImage, NULL);
14315 vkFreeMemory(m_device->device(), srcMem, NULL);
14316 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014317}
14318
Karl Schultz6addd812016-02-02 17:17:23 -070014319TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14320 VkResult err;
14321 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014322
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014323 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14325 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014326
Mike Stroyana3082432015-09-25 13:39:21 -060014327 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014328
14329 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014330 VkImage srcImage;
14331 VkImage dstImage;
14332 VkDeviceMemory srcMem;
14333 VkDeviceMemory destMem;
14334 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014335
14336 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014337 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14338 image_create_info.pNext = NULL;
14339 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14340 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14341 image_create_info.extent.width = 32;
14342 image_create_info.extent.height = 32;
14343 image_create_info.extent.depth = 1;
14344 image_create_info.mipLevels = 1;
14345 image_create_info.arrayLayers = 1;
14346 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14347 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14348 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14349 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014350
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014351 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014352 ASSERT_VK_SUCCESS(err);
14353
Karl Schultzbdb75952016-04-19 11:36:49 -060014354 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14355
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014356 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014357 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014358 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014359 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014360
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014361 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014362 ASSERT_VK_SUCCESS(err);
14363
14364 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014365 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014366 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14367 memAlloc.pNext = NULL;
14368 memAlloc.allocationSize = 0;
14369 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014370
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014371 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014372 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014373 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014374 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014375 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014376 ASSERT_VK_SUCCESS(err);
14377
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014378 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014379 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014380 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014381 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014382 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014383 ASSERT_VK_SUCCESS(err);
14384
14385 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14386 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014387 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014388 ASSERT_VK_SUCCESS(err);
14389
14390 BeginCommandBuffer();
14391 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014392 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014393 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014394 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014395 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014396 copyRegion.srcOffset.x = 0;
14397 copyRegion.srcOffset.y = 0;
14398 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014399 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014400 copyRegion.dstSubresource.mipLevel = 0;
14401 copyRegion.dstSubresource.baseArrayLayer = 0;
14402 copyRegion.dstSubresource.layerCount = 0;
14403 copyRegion.dstOffset.x = 0;
14404 copyRegion.dstOffset.y = 0;
14405 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014406 copyRegion.extent.width = 1;
14407 copyRegion.extent.height = 1;
14408 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014409 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014410 EndCommandBuffer();
14411
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014412 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014413
Chia-I Wuf7458c52015-10-26 21:10:41 +080014414 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014415 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014416 vkFreeMemory(m_device->device(), srcMem, NULL);
14417 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014418}
14419
Karl Schultz6addd812016-02-02 17:17:23 -070014420TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14421 VkResult err;
14422 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014423
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14425 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014426
Mike Stroyana3082432015-09-25 13:39:21 -060014427 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014428
14429 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014430 VkImage srcImage;
14431 VkImage dstImage;
14432 VkDeviceMemory srcMem;
14433 VkDeviceMemory destMem;
14434 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014435
14436 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014437 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14438 image_create_info.pNext = NULL;
14439 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14440 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14441 image_create_info.extent.width = 32;
14442 image_create_info.extent.height = 1;
14443 image_create_info.extent.depth = 1;
14444 image_create_info.mipLevels = 1;
14445 image_create_info.arrayLayers = 1;
14446 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14447 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14448 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14449 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014450
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014451 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014452 ASSERT_VK_SUCCESS(err);
14453
Karl Schultz6addd812016-02-02 17:17:23 -070014454 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014455
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014456 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014457 ASSERT_VK_SUCCESS(err);
14458
14459 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014460 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014461 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14462 memAlloc.pNext = NULL;
14463 memAlloc.allocationSize = 0;
14464 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014465
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014466 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014467 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014468 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014469 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014470 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014471 ASSERT_VK_SUCCESS(err);
14472
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014473 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014474 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014475 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014476 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014477 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014478 ASSERT_VK_SUCCESS(err);
14479
14480 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14481 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014482 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014483 ASSERT_VK_SUCCESS(err);
14484
14485 BeginCommandBuffer();
14486 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014487 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14488 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014489 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014490 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014491 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014492 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014493 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014494 resolveRegion.srcOffset.x = 0;
14495 resolveRegion.srcOffset.y = 0;
14496 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014497 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014498 resolveRegion.dstSubresource.mipLevel = 0;
14499 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014500 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014501 resolveRegion.dstOffset.x = 0;
14502 resolveRegion.dstOffset.y = 0;
14503 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014504 resolveRegion.extent.width = 1;
14505 resolveRegion.extent.height = 1;
14506 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014507 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014508 EndCommandBuffer();
14509
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014510 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014511
Chia-I Wuf7458c52015-10-26 21:10:41 +080014512 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014513 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014514 vkFreeMemory(m_device->device(), srcMem, NULL);
14515 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014516}
14517
Karl Schultz6addd812016-02-02 17:17:23 -070014518TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14519 VkResult err;
14520 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014521
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14523 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014524
Mike Stroyana3082432015-09-25 13:39:21 -060014525 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014526
Chris Forbesa7530692016-05-08 12:35:39 +120014527 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014528 VkImage srcImage;
14529 VkImage dstImage;
14530 VkDeviceMemory srcMem;
14531 VkDeviceMemory destMem;
14532 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014533
14534 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014535 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14536 image_create_info.pNext = NULL;
14537 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14538 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14539 image_create_info.extent.width = 32;
14540 image_create_info.extent.height = 1;
14541 image_create_info.extent.depth = 1;
14542 image_create_info.mipLevels = 1;
14543 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014544 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014545 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14546 // Note: Some implementations expect color attachment usage for any
14547 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014548 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014549 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014550
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014551 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014552 ASSERT_VK_SUCCESS(err);
14553
Karl Schultz6addd812016-02-02 17:17:23 -070014554 // Note: Some implementations expect color attachment usage for any
14555 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014556 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014557
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014558 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014559 ASSERT_VK_SUCCESS(err);
14560
14561 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014562 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014563 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14564 memAlloc.pNext = NULL;
14565 memAlloc.allocationSize = 0;
14566 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014567
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014568 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014569 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014570 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014571 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014572 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014573 ASSERT_VK_SUCCESS(err);
14574
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014575 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014576 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014577 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014578 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014579 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014580 ASSERT_VK_SUCCESS(err);
14581
14582 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14583 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014584 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014585 ASSERT_VK_SUCCESS(err);
14586
14587 BeginCommandBuffer();
14588 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014589 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14590 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014591 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014592 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014593 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014594 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014595 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014596 resolveRegion.srcOffset.x = 0;
14597 resolveRegion.srcOffset.y = 0;
14598 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014599 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014600 resolveRegion.dstSubresource.mipLevel = 0;
14601 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014602 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014603 resolveRegion.dstOffset.x = 0;
14604 resolveRegion.dstOffset.y = 0;
14605 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014606 resolveRegion.extent.width = 1;
14607 resolveRegion.extent.height = 1;
14608 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014609 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014610 EndCommandBuffer();
14611
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014612 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014613
Chia-I Wuf7458c52015-10-26 21:10:41 +080014614 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014615 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014616 vkFreeMemory(m_device->device(), srcMem, NULL);
14617 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014618}
14619
Karl Schultz6addd812016-02-02 17:17:23 -070014620TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14621 VkResult err;
14622 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014623
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14625 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014626
Mike Stroyana3082432015-09-25 13:39:21 -060014627 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014628
14629 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014630 VkImage srcImage;
14631 VkImage dstImage;
14632 VkDeviceMemory srcMem;
14633 VkDeviceMemory destMem;
14634 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014635
14636 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014637 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14638 image_create_info.pNext = NULL;
14639 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14640 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14641 image_create_info.extent.width = 32;
14642 image_create_info.extent.height = 1;
14643 image_create_info.extent.depth = 1;
14644 image_create_info.mipLevels = 1;
14645 image_create_info.arrayLayers = 1;
14646 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14647 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14648 // Note: Some implementations expect color attachment usage for any
14649 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014650 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014651 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014652
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014653 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014654 ASSERT_VK_SUCCESS(err);
14655
Karl Schultz6addd812016-02-02 17:17:23 -070014656 // Set format to something other than source image
14657 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14658 // Note: Some implementations expect color attachment usage for any
14659 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014660 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014661 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014662
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014663 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014664 ASSERT_VK_SUCCESS(err);
14665
14666 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014667 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014668 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14669 memAlloc.pNext = NULL;
14670 memAlloc.allocationSize = 0;
14671 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014672
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014673 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014674 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014675 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014676 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014677 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014678 ASSERT_VK_SUCCESS(err);
14679
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014680 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014681 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014682 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014683 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014684 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014685 ASSERT_VK_SUCCESS(err);
14686
14687 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14688 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014689 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014690 ASSERT_VK_SUCCESS(err);
14691
14692 BeginCommandBuffer();
14693 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014694 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14695 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014696 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014697 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014698 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014699 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014700 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014701 resolveRegion.srcOffset.x = 0;
14702 resolveRegion.srcOffset.y = 0;
14703 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014704 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014705 resolveRegion.dstSubresource.mipLevel = 0;
14706 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014707 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014708 resolveRegion.dstOffset.x = 0;
14709 resolveRegion.dstOffset.y = 0;
14710 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014711 resolveRegion.extent.width = 1;
14712 resolveRegion.extent.height = 1;
14713 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014714 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014715 EndCommandBuffer();
14716
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014717 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014718
Chia-I Wuf7458c52015-10-26 21:10:41 +080014719 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014720 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014721 vkFreeMemory(m_device->device(), srcMem, NULL);
14722 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014723}
14724
Karl Schultz6addd812016-02-02 17:17:23 -070014725TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
14726 VkResult err;
14727 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014728
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14730 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014731
Mike Stroyana3082432015-09-25 13:39:21 -060014732 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014733
14734 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014735 VkImage srcImage;
14736 VkImage dstImage;
14737 VkDeviceMemory srcMem;
14738 VkDeviceMemory destMem;
14739 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014740
14741 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014742 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14743 image_create_info.pNext = NULL;
14744 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14745 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14746 image_create_info.extent.width = 32;
14747 image_create_info.extent.height = 1;
14748 image_create_info.extent.depth = 1;
14749 image_create_info.mipLevels = 1;
14750 image_create_info.arrayLayers = 1;
14751 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14752 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14753 // Note: Some implementations expect color attachment usage for any
14754 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014755 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014756 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014757
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014758 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014759 ASSERT_VK_SUCCESS(err);
14760
Karl Schultz6addd812016-02-02 17:17:23 -070014761 image_create_info.imageType = VK_IMAGE_TYPE_1D;
14762 // Note: Some implementations expect color attachment usage for any
14763 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014764 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014765 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014766
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014767 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014768 ASSERT_VK_SUCCESS(err);
14769
14770 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014771 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014772 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14773 memAlloc.pNext = NULL;
14774 memAlloc.allocationSize = 0;
14775 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014776
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014777 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014778 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014779 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014780 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014781 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014782 ASSERT_VK_SUCCESS(err);
14783
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014784 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014785 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014786 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014787 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014788 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014789 ASSERT_VK_SUCCESS(err);
14790
14791 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14792 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014793 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014794 ASSERT_VK_SUCCESS(err);
14795
14796 BeginCommandBuffer();
14797 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014798 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14799 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014800 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014801 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014802 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014803 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014804 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014805 resolveRegion.srcOffset.x = 0;
14806 resolveRegion.srcOffset.y = 0;
14807 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014808 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014809 resolveRegion.dstSubresource.mipLevel = 0;
14810 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014811 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014812 resolveRegion.dstOffset.x = 0;
14813 resolveRegion.dstOffset.y = 0;
14814 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014815 resolveRegion.extent.width = 1;
14816 resolveRegion.extent.height = 1;
14817 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014818 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014819 EndCommandBuffer();
14820
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014821 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014822
Chia-I Wuf7458c52015-10-26 21:10:41 +080014823 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014824 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014825 vkFreeMemory(m_device->device(), srcMem, NULL);
14826 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014827}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014828
Karl Schultz6addd812016-02-02 17:17:23 -070014829TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014830 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070014831 // to using a DS format, then cause it to hit error due to COLOR_BIT not
14832 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014833 // The image format check comes 2nd in validation so we trigger it first,
14834 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070014835 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014836
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14838 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014839
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014840 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014841
Chia-I Wu1b99bb22015-10-27 19:25:11 +080014842 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014843 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14844 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014845
14846 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014847 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14848 ds_pool_ci.pNext = NULL;
14849 ds_pool_ci.maxSets = 1;
14850 ds_pool_ci.poolSizeCount = 1;
14851 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014852
14853 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014854 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014855 ASSERT_VK_SUCCESS(err);
14856
14857 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014858 dsl_binding.binding = 0;
14859 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14860 dsl_binding.descriptorCount = 1;
14861 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
14862 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014863
14864 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014865 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14866 ds_layout_ci.pNext = NULL;
14867 ds_layout_ci.bindingCount = 1;
14868 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014869 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014870 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014871 ASSERT_VK_SUCCESS(err);
14872
14873 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014874 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080014875 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070014876 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014877 alloc_info.descriptorPool = ds_pool;
14878 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014879 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014880 ASSERT_VK_SUCCESS(err);
14881
Karl Schultz6addd812016-02-02 17:17:23 -070014882 VkImage image_bad;
14883 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014884 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060014885 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014886 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070014887 const int32_t tex_width = 32;
14888 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014889
14890 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014891 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14892 image_create_info.pNext = NULL;
14893 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14894 image_create_info.format = tex_format_bad;
14895 image_create_info.extent.width = tex_width;
14896 image_create_info.extent.height = tex_height;
14897 image_create_info.extent.depth = 1;
14898 image_create_info.mipLevels = 1;
14899 image_create_info.arrayLayers = 1;
14900 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14901 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014902 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014903 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014904
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014905 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014906 ASSERT_VK_SUCCESS(err);
14907 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014908 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14909 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014910 ASSERT_VK_SUCCESS(err);
14911
14912 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014913 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14914 image_view_create_info.image = image_bad;
14915 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14916 image_view_create_info.format = tex_format_bad;
14917 image_view_create_info.subresourceRange.baseArrayLayer = 0;
14918 image_view_create_info.subresourceRange.baseMipLevel = 0;
14919 image_view_create_info.subresourceRange.layerCount = 1;
14920 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014921 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014922
14923 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014924 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014925
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014926 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014927
Chia-I Wuf7458c52015-10-26 21:10:41 +080014928 vkDestroyImage(m_device->device(), image_bad, NULL);
14929 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014930 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
14931 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014932}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014933
14934TEST_F(VkLayerTest, ClearImageErrors) {
14935 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
14936 "ClearDepthStencilImage with a color image.");
14937
14938 ASSERT_NO_FATAL_FAILURE(InitState());
14939 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14940
14941 // Renderpass is started here so end it as Clear cmds can't be in renderpass
14942 BeginCommandBuffer();
14943 m_commandBuffer->EndRenderPass();
14944
14945 // Color image
14946 VkClearColorValue clear_color;
14947 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
14948 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
14949 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
14950 const int32_t img_width = 32;
14951 const int32_t img_height = 32;
14952 VkImageCreateInfo image_create_info = {};
14953 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14954 image_create_info.pNext = NULL;
14955 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14956 image_create_info.format = color_format;
14957 image_create_info.extent.width = img_width;
14958 image_create_info.extent.height = img_height;
14959 image_create_info.extent.depth = 1;
14960 image_create_info.mipLevels = 1;
14961 image_create_info.arrayLayers = 1;
14962 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14963 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14964 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14965
14966 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014967 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014968
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014969 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014970
14971 // Depth/Stencil image
14972 VkClearDepthStencilValue clear_value = {0};
14973 reqs = 0; // don't need HOST_VISIBLE DS image
14974 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
14975 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
14976 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
14977 ds_image_create_info.extent.width = 64;
14978 ds_image_create_info.extent.height = 64;
14979 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14980 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
14981
14982 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014983 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014985 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 -060014986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014989 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014990 &color_range);
14991
14992 m_errorMonitor->VerifyFound();
14993
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
14995 "image created without "
14996 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060014997
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014998 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060014999 &color_range);
15000
15001 m_errorMonitor->VerifyFound();
15002
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015003 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15005 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015006
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015007 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15008 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015009
15010 m_errorMonitor->VerifyFound();
15011}
Tobin Ehliscde08892015-09-22 10:11:37 -060015012#endif // IMAGE_TESTS
15013
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015014
15015// WSI Enabled Tests
15016//
15017TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15018
15019#if defined(VK_USE_PLATFORM_XCB_KHR)
15020 VkSurfaceKHR surface = VK_NULL_HANDLE;
15021
15022 VkResult err;
15023 bool pass;
15024 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15025 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15026 // uint32_t swapchain_image_count = 0;
15027 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15028 // uint32_t image_index = 0;
15029 // VkPresentInfoKHR present_info = {};
15030
15031 ASSERT_NO_FATAL_FAILURE(InitState());
15032
15033 // Use the create function from one of the VK_KHR_*_surface extension in
15034 // order to create a surface, testing all known errors in the process,
15035 // before successfully creating a surface:
15036 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15038 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15039 pass = (err != VK_SUCCESS);
15040 ASSERT_TRUE(pass);
15041 m_errorMonitor->VerifyFound();
15042
15043 // Next, try to create a surface with the wrong
15044 // VkXcbSurfaceCreateInfoKHR::sType:
15045 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15046 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15048 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15049 pass = (err != VK_SUCCESS);
15050 ASSERT_TRUE(pass);
15051 m_errorMonitor->VerifyFound();
15052
15053 // Create a native window, and then correctly create a surface:
15054 xcb_connection_t *connection;
15055 xcb_screen_t *screen;
15056 xcb_window_t xcb_window;
15057 xcb_intern_atom_reply_t *atom_wm_delete_window;
15058
15059 const xcb_setup_t *setup;
15060 xcb_screen_iterator_t iter;
15061 int scr;
15062 uint32_t value_mask, value_list[32];
15063 int width = 1;
15064 int height = 1;
15065
15066 connection = xcb_connect(NULL, &scr);
15067 ASSERT_TRUE(connection != NULL);
15068 setup = xcb_get_setup(connection);
15069 iter = xcb_setup_roots_iterator(setup);
15070 while (scr-- > 0)
15071 xcb_screen_next(&iter);
15072 screen = iter.data;
15073
15074 xcb_window = xcb_generate_id(connection);
15075
15076 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15077 value_list[0] = screen->black_pixel;
15078 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15079
15080 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15081 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15082
15083 /* Magic code that will send notification when window is destroyed */
15084 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15085 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15086
15087 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15088 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15089 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15090 free(reply);
15091
15092 xcb_map_window(connection, xcb_window);
15093
15094 // Force the x/y coordinates to 100,100 results are identical in consecutive
15095 // runs
15096 const uint32_t coords[] = { 100, 100 };
15097 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15098
15099 // Finally, try to correctly create a surface:
15100 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15101 xcb_create_info.pNext = NULL;
15102 xcb_create_info.flags = 0;
15103 xcb_create_info.connection = connection;
15104 xcb_create_info.window = xcb_window;
15105 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15106 pass = (err == VK_SUCCESS);
15107 ASSERT_TRUE(pass);
15108
15109 // Check if surface supports presentation:
15110
15111 // 1st, do so without having queried the queue families:
15112 VkBool32 supported = false;
15113 // TODO: Get the following error to come out:
15114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15115 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15116 "function");
15117 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15118 pass = (err != VK_SUCCESS);
15119 // ASSERT_TRUE(pass);
15120 // m_errorMonitor->VerifyFound();
15121
15122 // Next, query a queue family index that's too large:
15123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15124 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15125 pass = (err != VK_SUCCESS);
15126 ASSERT_TRUE(pass);
15127 m_errorMonitor->VerifyFound();
15128
15129 // Finally, do so correctly:
15130 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15131 // SUPPORTED
15132 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15133 pass = (err == VK_SUCCESS);
15134 ASSERT_TRUE(pass);
15135
15136 // Before proceeding, try to create a swapchain without having called
15137 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15138 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15139 swapchain_create_info.pNext = NULL;
15140 swapchain_create_info.flags = 0;
15141 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15142 swapchain_create_info.surface = surface;
15143 swapchain_create_info.imageArrayLayers = 1;
15144 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15145 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15147 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15148 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15149 pass = (err != VK_SUCCESS);
15150 ASSERT_TRUE(pass);
15151 m_errorMonitor->VerifyFound();
15152
15153 // Get the surface capabilities:
15154 VkSurfaceCapabilitiesKHR surface_capabilities;
15155
15156 // Do so correctly (only error logged by this entrypoint is if the
15157 // extension isn't enabled):
15158 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15159 pass = (err == VK_SUCCESS);
15160 ASSERT_TRUE(pass);
15161
15162 // Get the surface formats:
15163 uint32_t surface_format_count;
15164
15165 // First, try without a pointer to surface_format_count:
15166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15167 "specified as NULL");
15168 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15169 pass = (err == VK_SUCCESS);
15170 ASSERT_TRUE(pass);
15171 m_errorMonitor->VerifyFound();
15172
15173 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15174 // correctly done a 1st try (to get the count):
15175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15176 surface_format_count = 0;
15177 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15178 pass = (err == VK_SUCCESS);
15179 ASSERT_TRUE(pass);
15180 m_errorMonitor->VerifyFound();
15181
15182 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15183 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15184 pass = (err == VK_SUCCESS);
15185 ASSERT_TRUE(pass);
15186
15187 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15188 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15189
15190 // Next, do a 2nd try with surface_format_count being set too high:
15191 surface_format_count += 5;
15192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15193 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15194 pass = (err == VK_SUCCESS);
15195 ASSERT_TRUE(pass);
15196 m_errorMonitor->VerifyFound();
15197
15198 // Finally, do a correct 1st and 2nd try:
15199 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15200 pass = (err == VK_SUCCESS);
15201 ASSERT_TRUE(pass);
15202 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15203 pass = (err == VK_SUCCESS);
15204 ASSERT_TRUE(pass);
15205
15206 // Get the surface present modes:
15207 uint32_t surface_present_mode_count;
15208
15209 // First, try without a pointer to surface_format_count:
15210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15211 "specified as NULL");
15212
15213 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15214 pass = (err == VK_SUCCESS);
15215 ASSERT_TRUE(pass);
15216 m_errorMonitor->VerifyFound();
15217
15218 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15219 // correctly done a 1st try (to get the count):
15220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15221 surface_present_mode_count = 0;
15222 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15223 (VkPresentModeKHR *)&surface_present_mode_count);
15224 pass = (err == VK_SUCCESS);
15225 ASSERT_TRUE(pass);
15226 m_errorMonitor->VerifyFound();
15227
15228 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15229 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15230 pass = (err == VK_SUCCESS);
15231 ASSERT_TRUE(pass);
15232
15233 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15234 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15235
15236 // Next, do a 2nd try with surface_format_count being set too high:
15237 surface_present_mode_count += 5;
15238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15239 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15240 pass = (err == VK_SUCCESS);
15241 ASSERT_TRUE(pass);
15242 m_errorMonitor->VerifyFound();
15243
15244 // Finally, do a correct 1st and 2nd try:
15245 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15246 pass = (err == VK_SUCCESS);
15247 ASSERT_TRUE(pass);
15248 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15249 pass = (err == VK_SUCCESS);
15250 ASSERT_TRUE(pass);
15251
15252 // Create a swapchain:
15253
15254 // First, try without a pointer to swapchain_create_info:
15255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15256 "specified as NULL");
15257
15258 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15259 pass = (err != VK_SUCCESS);
15260 ASSERT_TRUE(pass);
15261 m_errorMonitor->VerifyFound();
15262
15263 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15264 // sType:
15265 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15267
15268 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15269 pass = (err != VK_SUCCESS);
15270 ASSERT_TRUE(pass);
15271 m_errorMonitor->VerifyFound();
15272
15273 // Next, call with a NULL swapchain pointer:
15274 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15275 swapchain_create_info.pNext = NULL;
15276 swapchain_create_info.flags = 0;
15277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15278 "specified as NULL");
15279
15280 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15281 pass = (err != VK_SUCCESS);
15282 ASSERT_TRUE(pass);
15283 m_errorMonitor->VerifyFound();
15284
15285 // TODO: Enhance swapchain layer so that
15286 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15287
15288 // Next, call with a queue family index that's too large:
15289 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15290 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15291 swapchain_create_info.queueFamilyIndexCount = 2;
15292 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15294 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15295 pass = (err != VK_SUCCESS);
15296 ASSERT_TRUE(pass);
15297 m_errorMonitor->VerifyFound();
15298
15299 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15300 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15301 swapchain_create_info.queueFamilyIndexCount = 1;
15302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15303 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15304 "pCreateInfo->pQueueFamilyIndices).");
15305 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15306 pass = (err != VK_SUCCESS);
15307 ASSERT_TRUE(pass);
15308 m_errorMonitor->VerifyFound();
15309
15310 // Next, call with an invalid imageSharingMode:
15311 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15312 swapchain_create_info.queueFamilyIndexCount = 1;
15313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15314 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15315 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15316 pass = (err != VK_SUCCESS);
15317 ASSERT_TRUE(pass);
15318 m_errorMonitor->VerifyFound();
15319 // Fix for the future:
15320 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15321 // SUPPORTED
15322 swapchain_create_info.queueFamilyIndexCount = 0;
15323 queueFamilyIndex[0] = 0;
15324 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15325
15326 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15327 // Get the images from a swapchain:
15328 // Acquire an image from a swapchain:
15329 // Present an image to a swapchain:
15330 // Destroy the swapchain:
15331
15332 // TODOs:
15333 //
15334 // - Try destroying the device without first destroying the swapchain
15335 //
15336 // - Try destroying the device without first destroying the surface
15337 //
15338 // - Try destroying the surface without first destroying the swapchain
15339
15340 // Destroy the surface:
15341 vkDestroySurfaceKHR(instance(), surface, NULL);
15342
15343 // Tear down the window:
15344 xcb_destroy_window(connection, xcb_window);
15345 xcb_disconnect(connection);
15346
15347#else // VK_USE_PLATFORM_XCB_KHR
15348 return;
15349#endif // VK_USE_PLATFORM_XCB_KHR
15350}
15351
15352//
15353// POSITIVE VALIDATION TESTS
15354//
15355// These tests do not expect to encounter ANY validation errors pass only if this is true
15356
Tobin Ehlise0006882016-11-03 10:14:28 -060015357TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15358 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15359 "by a transition in the primary.");
15360 VkResult err;
15361 m_errorMonitor->ExpectSuccess();
15362 ASSERT_NO_FATAL_FAILURE(InitState());
15363 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15364 // Allocate a secondary and primary cmd buffer
15365 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15366 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15367 command_buffer_allocate_info.commandPool = m_commandPool;
15368 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15369 command_buffer_allocate_info.commandBufferCount = 1;
15370
15371 VkCommandBuffer secondary_command_buffer;
15372 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15373 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15374 VkCommandBuffer primary_command_buffer;
15375 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15376 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15377 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15378 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15379 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15380 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15381 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15382
15383 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15384 ASSERT_VK_SUCCESS(err);
15385 VkImageObj image(m_device);
15386 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15387 ASSERT_TRUE(image.initialized());
15388 VkImageMemoryBarrier img_barrier = {};
15389 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15390 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15391 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15392 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15393 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15394 img_barrier.image = image.handle();
15395 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15396 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15397 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15398 img_barrier.subresourceRange.baseArrayLayer = 0;
15399 img_barrier.subresourceRange.baseMipLevel = 0;
15400 img_barrier.subresourceRange.layerCount = 1;
15401 img_barrier.subresourceRange.levelCount = 1;
15402 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15403 0, nullptr, 1, &img_barrier);
15404 err = vkEndCommandBuffer(secondary_command_buffer);
15405 ASSERT_VK_SUCCESS(err);
15406
15407 // Now update primary cmd buffer to execute secondary and transitions image
15408 command_buffer_begin_info.pInheritanceInfo = nullptr;
15409 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15410 ASSERT_VK_SUCCESS(err);
15411 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15412 VkImageMemoryBarrier img_barrier2 = {};
15413 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15414 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15415 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15416 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15417 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15418 img_barrier2.image = image.handle();
15419 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15420 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15421 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15422 img_barrier2.subresourceRange.baseArrayLayer = 0;
15423 img_barrier2.subresourceRange.baseMipLevel = 0;
15424 img_barrier2.subresourceRange.layerCount = 1;
15425 img_barrier2.subresourceRange.levelCount = 1;
15426 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15427 nullptr, 1, &img_barrier2);
15428 err = vkEndCommandBuffer(primary_command_buffer);
15429 ASSERT_VK_SUCCESS(err);
15430 VkSubmitInfo submit_info = {};
15431 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15432 submit_info.commandBufferCount = 1;
15433 submit_info.pCommandBuffers = &primary_command_buffer;
15434 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15435 ASSERT_VK_SUCCESS(err);
15436 m_errorMonitor->VerifyNotFound();
15437 err = vkDeviceWaitIdle(m_device->device());
15438 ASSERT_VK_SUCCESS(err);
15439 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15440 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15441}
15442
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015443// This is a positive test. No failures are expected.
15444TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15445 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15446 "is ignoring VkWriteDescriptorSet members that are not "
15447 "related to the descriptor type specified by "
15448 "VkWriteDescriptorSet::descriptorType. Correct "
15449 "validation behavior will result in the test running to "
15450 "completion without validation errors.");
15451
15452 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15453
15454 ASSERT_NO_FATAL_FAILURE(InitState());
15455
15456 // Image Case
15457 {
15458 m_errorMonitor->ExpectSuccess();
15459
15460 VkImage image;
15461 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15462 const int32_t tex_width = 32;
15463 const int32_t tex_height = 32;
15464 VkImageCreateInfo image_create_info = {};
15465 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15466 image_create_info.pNext = NULL;
15467 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15468 image_create_info.format = tex_format;
15469 image_create_info.extent.width = tex_width;
15470 image_create_info.extent.height = tex_height;
15471 image_create_info.extent.depth = 1;
15472 image_create_info.mipLevels = 1;
15473 image_create_info.arrayLayers = 1;
15474 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15475 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15476 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15477 image_create_info.flags = 0;
15478 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15479 ASSERT_VK_SUCCESS(err);
15480
15481 VkMemoryRequirements memory_reqs;
15482 VkDeviceMemory image_memory;
15483 bool pass;
15484 VkMemoryAllocateInfo memory_info = {};
15485 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15486 memory_info.pNext = NULL;
15487 memory_info.allocationSize = 0;
15488 memory_info.memoryTypeIndex = 0;
15489 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15490 memory_info.allocationSize = memory_reqs.size;
15491 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15492 ASSERT_TRUE(pass);
15493 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15494 ASSERT_VK_SUCCESS(err);
15495 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15496 ASSERT_VK_SUCCESS(err);
15497
15498 VkImageViewCreateInfo image_view_create_info = {};
15499 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15500 image_view_create_info.image = image;
15501 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15502 image_view_create_info.format = tex_format;
15503 image_view_create_info.subresourceRange.layerCount = 1;
15504 image_view_create_info.subresourceRange.baseMipLevel = 0;
15505 image_view_create_info.subresourceRange.levelCount = 1;
15506 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15507
15508 VkImageView view;
15509 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15510 ASSERT_VK_SUCCESS(err);
15511
15512 VkDescriptorPoolSize ds_type_count = {};
15513 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15514 ds_type_count.descriptorCount = 1;
15515
15516 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15517 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15518 ds_pool_ci.pNext = NULL;
15519 ds_pool_ci.maxSets = 1;
15520 ds_pool_ci.poolSizeCount = 1;
15521 ds_pool_ci.pPoolSizes = &ds_type_count;
15522
15523 VkDescriptorPool ds_pool;
15524 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15525 ASSERT_VK_SUCCESS(err);
15526
15527 VkDescriptorSetLayoutBinding dsl_binding = {};
15528 dsl_binding.binding = 0;
15529 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15530 dsl_binding.descriptorCount = 1;
15531 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15532 dsl_binding.pImmutableSamplers = NULL;
15533
15534 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15535 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15536 ds_layout_ci.pNext = NULL;
15537 ds_layout_ci.bindingCount = 1;
15538 ds_layout_ci.pBindings = &dsl_binding;
15539 VkDescriptorSetLayout ds_layout;
15540 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15541 ASSERT_VK_SUCCESS(err);
15542
15543 VkDescriptorSet descriptor_set;
15544 VkDescriptorSetAllocateInfo alloc_info = {};
15545 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15546 alloc_info.descriptorSetCount = 1;
15547 alloc_info.descriptorPool = ds_pool;
15548 alloc_info.pSetLayouts = &ds_layout;
15549 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15550 ASSERT_VK_SUCCESS(err);
15551
15552 VkDescriptorImageInfo image_info = {};
15553 image_info.imageView = view;
15554 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15555
15556 VkWriteDescriptorSet descriptor_write;
15557 memset(&descriptor_write, 0, sizeof(descriptor_write));
15558 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15559 descriptor_write.dstSet = descriptor_set;
15560 descriptor_write.dstBinding = 0;
15561 descriptor_write.descriptorCount = 1;
15562 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15563 descriptor_write.pImageInfo = &image_info;
15564
15565 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15566 // be
15567 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15568 // This will most likely produce a crash if the parameter_validation
15569 // layer
15570 // does not correctly ignore pBufferInfo.
15571 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15572 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15573
15574 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15575
15576 m_errorMonitor->VerifyNotFound();
15577
15578 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15579 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15580 vkDestroyImageView(m_device->device(), view, NULL);
15581 vkDestroyImage(m_device->device(), image, NULL);
15582 vkFreeMemory(m_device->device(), image_memory, NULL);
15583 }
15584
15585 // Buffer Case
15586 {
15587 m_errorMonitor->ExpectSuccess();
15588
15589 VkBuffer buffer;
15590 uint32_t queue_family_index = 0;
15591 VkBufferCreateInfo buffer_create_info = {};
15592 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15593 buffer_create_info.size = 1024;
15594 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15595 buffer_create_info.queueFamilyIndexCount = 1;
15596 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15597
15598 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15599 ASSERT_VK_SUCCESS(err);
15600
15601 VkMemoryRequirements memory_reqs;
15602 VkDeviceMemory buffer_memory;
15603 bool pass;
15604 VkMemoryAllocateInfo memory_info = {};
15605 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15606 memory_info.pNext = NULL;
15607 memory_info.allocationSize = 0;
15608 memory_info.memoryTypeIndex = 0;
15609
15610 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15611 memory_info.allocationSize = memory_reqs.size;
15612 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15613 ASSERT_TRUE(pass);
15614
15615 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15616 ASSERT_VK_SUCCESS(err);
15617 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15618 ASSERT_VK_SUCCESS(err);
15619
15620 VkDescriptorPoolSize ds_type_count = {};
15621 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15622 ds_type_count.descriptorCount = 1;
15623
15624 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15625 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15626 ds_pool_ci.pNext = NULL;
15627 ds_pool_ci.maxSets = 1;
15628 ds_pool_ci.poolSizeCount = 1;
15629 ds_pool_ci.pPoolSizes = &ds_type_count;
15630
15631 VkDescriptorPool ds_pool;
15632 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15633 ASSERT_VK_SUCCESS(err);
15634
15635 VkDescriptorSetLayoutBinding dsl_binding = {};
15636 dsl_binding.binding = 0;
15637 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15638 dsl_binding.descriptorCount = 1;
15639 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15640 dsl_binding.pImmutableSamplers = NULL;
15641
15642 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15643 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15644 ds_layout_ci.pNext = NULL;
15645 ds_layout_ci.bindingCount = 1;
15646 ds_layout_ci.pBindings = &dsl_binding;
15647 VkDescriptorSetLayout ds_layout;
15648 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15649 ASSERT_VK_SUCCESS(err);
15650
15651 VkDescriptorSet descriptor_set;
15652 VkDescriptorSetAllocateInfo alloc_info = {};
15653 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15654 alloc_info.descriptorSetCount = 1;
15655 alloc_info.descriptorPool = ds_pool;
15656 alloc_info.pSetLayouts = &ds_layout;
15657 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15658 ASSERT_VK_SUCCESS(err);
15659
15660 VkDescriptorBufferInfo buffer_info = {};
15661 buffer_info.buffer = buffer;
15662 buffer_info.offset = 0;
15663 buffer_info.range = 1024;
15664
15665 VkWriteDescriptorSet descriptor_write;
15666 memset(&descriptor_write, 0, sizeof(descriptor_write));
15667 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15668 descriptor_write.dstSet = descriptor_set;
15669 descriptor_write.dstBinding = 0;
15670 descriptor_write.descriptorCount = 1;
15671 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15672 descriptor_write.pBufferInfo = &buffer_info;
15673
15674 // Set pImageInfo and pTexelBufferView to invalid values, which should
15675 // be
15676 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15677 // This will most likely produce a crash if the parameter_validation
15678 // layer
15679 // does not correctly ignore pImageInfo.
15680 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15681 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15682
15683 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15684
15685 m_errorMonitor->VerifyNotFound();
15686
15687 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15688 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15689 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15690 vkDestroyBuffer(m_device->device(), buffer, NULL);
15691 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15692 }
15693
15694 // Texel Buffer Case
15695 {
15696 m_errorMonitor->ExpectSuccess();
15697
15698 VkBuffer buffer;
15699 uint32_t queue_family_index = 0;
15700 VkBufferCreateInfo buffer_create_info = {};
15701 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15702 buffer_create_info.size = 1024;
15703 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15704 buffer_create_info.queueFamilyIndexCount = 1;
15705 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15706
15707 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15708 ASSERT_VK_SUCCESS(err);
15709
15710 VkMemoryRequirements memory_reqs;
15711 VkDeviceMemory buffer_memory;
15712 bool pass;
15713 VkMemoryAllocateInfo memory_info = {};
15714 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15715 memory_info.pNext = NULL;
15716 memory_info.allocationSize = 0;
15717 memory_info.memoryTypeIndex = 0;
15718
15719 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15720 memory_info.allocationSize = memory_reqs.size;
15721 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15722 ASSERT_TRUE(pass);
15723
15724 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15725 ASSERT_VK_SUCCESS(err);
15726 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15727 ASSERT_VK_SUCCESS(err);
15728
15729 VkBufferViewCreateInfo buff_view_ci = {};
15730 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
15731 buff_view_ci.buffer = buffer;
15732 buff_view_ci.format = VK_FORMAT_R8_UNORM;
15733 buff_view_ci.range = VK_WHOLE_SIZE;
15734 VkBufferView buffer_view;
15735 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
15736
15737 VkDescriptorPoolSize ds_type_count = {};
15738 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15739 ds_type_count.descriptorCount = 1;
15740
15741 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15742 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15743 ds_pool_ci.pNext = NULL;
15744 ds_pool_ci.maxSets = 1;
15745 ds_pool_ci.poolSizeCount = 1;
15746 ds_pool_ci.pPoolSizes = &ds_type_count;
15747
15748 VkDescriptorPool ds_pool;
15749 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15750 ASSERT_VK_SUCCESS(err);
15751
15752 VkDescriptorSetLayoutBinding dsl_binding = {};
15753 dsl_binding.binding = 0;
15754 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15755 dsl_binding.descriptorCount = 1;
15756 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15757 dsl_binding.pImmutableSamplers = NULL;
15758
15759 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15760 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15761 ds_layout_ci.pNext = NULL;
15762 ds_layout_ci.bindingCount = 1;
15763 ds_layout_ci.pBindings = &dsl_binding;
15764 VkDescriptorSetLayout ds_layout;
15765 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15766 ASSERT_VK_SUCCESS(err);
15767
15768 VkDescriptorSet descriptor_set;
15769 VkDescriptorSetAllocateInfo alloc_info = {};
15770 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15771 alloc_info.descriptorSetCount = 1;
15772 alloc_info.descriptorPool = ds_pool;
15773 alloc_info.pSetLayouts = &ds_layout;
15774 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15775 ASSERT_VK_SUCCESS(err);
15776
15777 VkWriteDescriptorSet descriptor_write;
15778 memset(&descriptor_write, 0, sizeof(descriptor_write));
15779 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15780 descriptor_write.dstSet = descriptor_set;
15781 descriptor_write.dstBinding = 0;
15782 descriptor_write.descriptorCount = 1;
15783 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15784 descriptor_write.pTexelBufferView = &buffer_view;
15785
15786 // Set pImageInfo and pBufferInfo to invalid values, which should be
15787 // ignored for descriptorType ==
15788 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
15789 // This will most likely produce a crash if the parameter_validation
15790 // layer
15791 // does not correctly ignore pImageInfo and pBufferInfo.
15792 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15793 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15794
15795 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15796
15797 m_errorMonitor->VerifyNotFound();
15798
15799 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15800 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15801 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15802 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
15803 vkDestroyBuffer(m_device->device(), buffer, NULL);
15804 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15805 }
15806}
15807
Tobin Ehlisf7428442016-10-25 07:58:24 -060015808TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
15809 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
15810
15811 ASSERT_NO_FATAL_FAILURE(InitState());
15812 // Create layout where two binding #s are "1"
15813 static const uint32_t NUM_BINDINGS = 3;
15814 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15815 dsl_binding[0].binding = 1;
15816 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15817 dsl_binding[0].descriptorCount = 1;
15818 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15819 dsl_binding[0].pImmutableSamplers = NULL;
15820 dsl_binding[1].binding = 0;
15821 dsl_binding[1].descriptorCount = 1;
15822 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15823 dsl_binding[1].descriptorCount = 1;
15824 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15825 dsl_binding[1].pImmutableSamplers = NULL;
15826 dsl_binding[2].binding = 1; // Duplicate binding should cause error
15827 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15828 dsl_binding[2].descriptorCount = 1;
15829 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15830 dsl_binding[2].pImmutableSamplers = NULL;
15831
15832 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15833 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15834 ds_layout_ci.pNext = NULL;
15835 ds_layout_ci.bindingCount = NUM_BINDINGS;
15836 ds_layout_ci.pBindings = dsl_binding;
15837 VkDescriptorSetLayout ds_layout;
15838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
15839 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15840 m_errorMonitor->VerifyFound();
15841}
15842
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060015843TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015844 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
15845
15846 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015847
15848 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015849
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060015850 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
15851
15852 {
15853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
15854 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
15855 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15856 m_errorMonitor->VerifyFound();
15857 }
15858
15859 {
15860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
15861 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
15862 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15863 m_errorMonitor->VerifyFound();
15864 }
15865
15866 {
15867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
15868 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
15869 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15870 m_errorMonitor->VerifyFound();
15871 }
15872
15873 {
15874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
15875 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
15876 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15877 m_errorMonitor->VerifyFound();
15878 }
15879
15880 {
15881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
15882 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
15883 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15884 m_errorMonitor->VerifyFound();
15885 }
15886
15887 {
15888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
15889 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
15890 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15891 m_errorMonitor->VerifyFound();
15892 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015893
15894 {
15895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
15896 VkRect2D scissor = {{-1, 0}, {16, 16}};
15897 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15898 m_errorMonitor->VerifyFound();
15899 }
15900
15901 {
15902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
15903 VkRect2D scissor = {{0, -2}, {16, 16}};
15904 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15905 m_errorMonitor->VerifyFound();
15906 }
15907
15908 {
15909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
15910 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
15911 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15912 m_errorMonitor->VerifyFound();
15913 }
15914
15915 {
15916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
15917 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
15918 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15919 m_errorMonitor->VerifyFound();
15920 }
15921
15922 EndCommandBuffer();
15923}
15924
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015925// This is a positive test. No failures are expected.
15926TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
15927 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
15928 VkResult err;
15929
15930 ASSERT_NO_FATAL_FAILURE(InitState());
15931 m_errorMonitor->ExpectSuccess();
15932 VkDescriptorPoolSize ds_type_count = {};
15933 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15934 ds_type_count.descriptorCount = 2;
15935
15936 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15937 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15938 ds_pool_ci.pNext = NULL;
15939 ds_pool_ci.maxSets = 1;
15940 ds_pool_ci.poolSizeCount = 1;
15941 ds_pool_ci.pPoolSizes = &ds_type_count;
15942
15943 VkDescriptorPool ds_pool;
15944 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15945 ASSERT_VK_SUCCESS(err);
15946
15947 // Create layout with two uniform buffer descriptors w/ empty binding between them
15948 static const uint32_t NUM_BINDINGS = 3;
15949 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15950 dsl_binding[0].binding = 0;
15951 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15952 dsl_binding[0].descriptorCount = 1;
15953 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
15954 dsl_binding[0].pImmutableSamplers = NULL;
15955 dsl_binding[1].binding = 1;
15956 dsl_binding[1].descriptorCount = 0; // empty binding
15957 dsl_binding[2].binding = 2;
15958 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15959 dsl_binding[2].descriptorCount = 1;
15960 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
15961 dsl_binding[2].pImmutableSamplers = NULL;
15962
15963 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15964 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15965 ds_layout_ci.pNext = NULL;
15966 ds_layout_ci.bindingCount = NUM_BINDINGS;
15967 ds_layout_ci.pBindings = dsl_binding;
15968 VkDescriptorSetLayout ds_layout;
15969 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15970 ASSERT_VK_SUCCESS(err);
15971
15972 VkDescriptorSet descriptor_set = {};
15973 VkDescriptorSetAllocateInfo alloc_info = {};
15974 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15975 alloc_info.descriptorSetCount = 1;
15976 alloc_info.descriptorPool = ds_pool;
15977 alloc_info.pSetLayouts = &ds_layout;
15978 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15979 ASSERT_VK_SUCCESS(err);
15980
15981 // Create a buffer to be used for update
15982 VkBufferCreateInfo buff_ci = {};
15983 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15984 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15985 buff_ci.size = 256;
15986 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
15987 VkBuffer buffer;
15988 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
15989 ASSERT_VK_SUCCESS(err);
15990 // Have to bind memory to buffer before descriptor update
15991 VkMemoryAllocateInfo mem_alloc = {};
15992 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15993 mem_alloc.pNext = NULL;
15994 mem_alloc.allocationSize = 512; // one allocation for both buffers
15995 mem_alloc.memoryTypeIndex = 0;
15996
15997 VkMemoryRequirements mem_reqs;
15998 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
15999 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16000 if (!pass) {
16001 vkDestroyBuffer(m_device->device(), buffer, NULL);
16002 return;
16003 }
16004
16005 VkDeviceMemory mem;
16006 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16007 ASSERT_VK_SUCCESS(err);
16008 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16009 ASSERT_VK_SUCCESS(err);
16010
16011 // Only update the descriptor at binding 2
16012 VkDescriptorBufferInfo buff_info = {};
16013 buff_info.buffer = buffer;
16014 buff_info.offset = 0;
16015 buff_info.range = VK_WHOLE_SIZE;
16016 VkWriteDescriptorSet descriptor_write = {};
16017 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16018 descriptor_write.dstBinding = 2;
16019 descriptor_write.descriptorCount = 1;
16020 descriptor_write.pTexelBufferView = nullptr;
16021 descriptor_write.pBufferInfo = &buff_info;
16022 descriptor_write.pImageInfo = nullptr;
16023 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16024 descriptor_write.dstSet = descriptor_set;
16025
16026 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16027
16028 m_errorMonitor->VerifyNotFound();
16029 // Cleanup
16030 vkFreeMemory(m_device->device(), mem, NULL);
16031 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16032 vkDestroyBuffer(m_device->device(), buffer, NULL);
16033 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16034}
16035
16036// This is a positive test. No failures are expected.
16037TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16038 VkResult err;
16039 bool pass;
16040
16041 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16042 "the buffer, create an image, and bind the same memory to "
16043 "it");
16044
16045 m_errorMonitor->ExpectSuccess();
16046
16047 ASSERT_NO_FATAL_FAILURE(InitState());
16048
16049 VkBuffer buffer;
16050 VkImage image;
16051 VkDeviceMemory mem;
16052 VkMemoryRequirements mem_reqs;
16053
16054 VkBufferCreateInfo buf_info = {};
16055 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16056 buf_info.pNext = NULL;
16057 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16058 buf_info.size = 256;
16059 buf_info.queueFamilyIndexCount = 0;
16060 buf_info.pQueueFamilyIndices = NULL;
16061 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16062 buf_info.flags = 0;
16063 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16064 ASSERT_VK_SUCCESS(err);
16065
16066 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16067
16068 VkMemoryAllocateInfo alloc_info = {};
16069 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16070 alloc_info.pNext = NULL;
16071 alloc_info.memoryTypeIndex = 0;
16072
16073 // Ensure memory is big enough for both bindings
16074 alloc_info.allocationSize = 0x10000;
16075
16076 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16077 if (!pass) {
16078 vkDestroyBuffer(m_device->device(), buffer, NULL);
16079 return;
16080 }
16081
16082 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16083 ASSERT_VK_SUCCESS(err);
16084
16085 uint8_t *pData;
16086 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16087 ASSERT_VK_SUCCESS(err);
16088
16089 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16090
16091 vkUnmapMemory(m_device->device(), mem);
16092
16093 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16094 ASSERT_VK_SUCCESS(err);
16095
16096 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16097 // memory. In fact, it was never used by the GPU.
16098 // Just be be sure, wait for idle.
16099 vkDestroyBuffer(m_device->device(), buffer, NULL);
16100 vkDeviceWaitIdle(m_device->device());
16101
16102 VkImageCreateInfo image_create_info = {};
16103 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16104 image_create_info.pNext = NULL;
16105 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16106 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16107 image_create_info.extent.width = 64;
16108 image_create_info.extent.height = 64;
16109 image_create_info.extent.depth = 1;
16110 image_create_info.mipLevels = 1;
16111 image_create_info.arrayLayers = 1;
16112 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16113 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16114 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16115 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16116 image_create_info.queueFamilyIndexCount = 0;
16117 image_create_info.pQueueFamilyIndices = NULL;
16118 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16119 image_create_info.flags = 0;
16120
16121 VkMemoryAllocateInfo mem_alloc = {};
16122 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16123 mem_alloc.pNext = NULL;
16124 mem_alloc.allocationSize = 0;
16125 mem_alloc.memoryTypeIndex = 0;
16126
16127 /* Create a mappable image. It will be the texture if linear images are ok
16128 * to be textures or it will be the staging image if they are not.
16129 */
16130 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16131 ASSERT_VK_SUCCESS(err);
16132
16133 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16134
16135 mem_alloc.allocationSize = mem_reqs.size;
16136
16137 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16138 if (!pass) {
16139 vkDestroyImage(m_device->device(), image, NULL);
16140 return;
16141 }
16142
16143 // VALIDATION FAILURE:
16144 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16145 ASSERT_VK_SUCCESS(err);
16146
16147 m_errorMonitor->VerifyNotFound();
16148
16149 vkFreeMemory(m_device->device(), mem, NULL);
16150 vkDestroyBuffer(m_device->device(), buffer, NULL);
16151 vkDestroyImage(m_device->device(), image, NULL);
16152}
16153
16154TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16155
16156 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16157 "mapping while using VK_WHOLE_SIZE does not cause access "
16158 "violations");
16159 VkResult err;
16160 uint8_t *pData;
16161 ASSERT_NO_FATAL_FAILURE(InitState());
16162
16163 VkDeviceMemory mem;
16164 VkMemoryRequirements mem_reqs;
16165 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
16166 VkMemoryAllocateInfo alloc_info = {};
16167 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16168 alloc_info.pNext = NULL;
16169 alloc_info.memoryTypeIndex = 0;
16170
16171 static const VkDeviceSize allocation_size = 0x1000;
16172 alloc_info.allocationSize = allocation_size;
16173
16174 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16175 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16176 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16177 if (!pass) {
16178 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16179 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16180 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16181 if (!pass) {
16182 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16183 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16184 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16185 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16186 if (!pass) {
16187 return;
16188 }
16189 }
16190 }
16191
16192 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16193 ASSERT_VK_SUCCESS(err);
16194
16195 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16196 // mapped range
16197 m_errorMonitor->ExpectSuccess();
16198 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16199 ASSERT_VK_SUCCESS(err);
16200 VkMappedMemoryRange mmr = {};
16201 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16202 mmr.memory = mem;
16203 mmr.offset = 0;
16204 mmr.size = VK_WHOLE_SIZE;
16205 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16206 ASSERT_VK_SUCCESS(err);
16207 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16208 ASSERT_VK_SUCCESS(err);
16209 m_errorMonitor->VerifyNotFound();
16210 vkUnmapMemory(m_device->device(), mem);
16211
16212 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16213 // mapped range
16214 m_errorMonitor->ExpectSuccess();
16215 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16216 ASSERT_VK_SUCCESS(err);
16217 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16218 mmr.memory = mem;
16219 mmr.offset = 13;
16220 mmr.size = VK_WHOLE_SIZE;
16221 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16222 ASSERT_VK_SUCCESS(err);
16223 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16224 ASSERT_VK_SUCCESS(err);
16225 m_errorMonitor->VerifyNotFound();
16226 vkUnmapMemory(m_device->device(), mem);
16227
16228 // Map with prime offset and size
16229 // Flush/Invalidate subrange of mapped area with prime offset and size
16230 m_errorMonitor->ExpectSuccess();
16231 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16232 ASSERT_VK_SUCCESS(err);
16233 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16234 mmr.memory = mem;
16235 mmr.offset = allocation_size - 107;
16236 mmr.size = 61;
16237 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16238 ASSERT_VK_SUCCESS(err);
16239 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16240 ASSERT_VK_SUCCESS(err);
16241 m_errorMonitor->VerifyNotFound();
16242 vkUnmapMemory(m_device->device(), mem);
16243
16244 // Map without offset and flush WHOLE_SIZE with two separate offsets
16245 m_errorMonitor->ExpectSuccess();
16246 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16247 ASSERT_VK_SUCCESS(err);
16248 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16249 mmr.memory = mem;
16250 mmr.offset = allocation_size - 100;
16251 mmr.size = VK_WHOLE_SIZE;
16252 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16253 ASSERT_VK_SUCCESS(err);
16254 mmr.offset = allocation_size - 200;
16255 mmr.size = VK_WHOLE_SIZE;
16256 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16257 ASSERT_VK_SUCCESS(err);
16258 m_errorMonitor->VerifyNotFound();
16259 vkUnmapMemory(m_device->device(), mem);
16260
16261 vkFreeMemory(m_device->device(), mem, NULL);
16262}
16263
16264// This is a positive test. We used to expect error in this case but spec now allows it
16265TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16266 m_errorMonitor->ExpectSuccess();
16267 vk_testing::Fence testFence;
16268 VkFenceCreateInfo fenceInfo = {};
16269 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16270 fenceInfo.pNext = NULL;
16271
16272 ASSERT_NO_FATAL_FAILURE(InitState());
16273 testFence.init(*m_device, fenceInfo);
16274 VkFence fences[1] = { testFence.handle() };
16275 VkResult result = vkResetFences(m_device->device(), 1, fences);
16276 ASSERT_VK_SUCCESS(result);
16277
16278 m_errorMonitor->VerifyNotFound();
16279}
16280
16281TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16282 m_errorMonitor->ExpectSuccess();
16283
16284 ASSERT_NO_FATAL_FAILURE(InitState());
16285 VkResult err;
16286
16287 // Record (empty!) command buffer that can be submitted multiple times
16288 // simultaneously.
16289 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16290 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16291 m_commandBuffer->BeginCommandBuffer(&cbbi);
16292 m_commandBuffer->EndCommandBuffer();
16293
16294 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16295 VkFence fence;
16296 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16297 ASSERT_VK_SUCCESS(err);
16298
16299 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16300 VkSemaphore s1, s2;
16301 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16302 ASSERT_VK_SUCCESS(err);
16303 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16304 ASSERT_VK_SUCCESS(err);
16305
16306 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16307 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16308 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16309 ASSERT_VK_SUCCESS(err);
16310
16311 // Submit CB again, signaling s2.
16312 si.pSignalSemaphores = &s2;
16313 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16314 ASSERT_VK_SUCCESS(err);
16315
16316 // Wait for fence.
16317 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16318 ASSERT_VK_SUCCESS(err);
16319
16320 // CB is still in flight from second submission, but semaphore s1 is no
16321 // longer in flight. delete it.
16322 vkDestroySemaphore(m_device->device(), s1, nullptr);
16323
16324 m_errorMonitor->VerifyNotFound();
16325
16326 // Force device idle and clean up remaining objects
16327 vkDeviceWaitIdle(m_device->device());
16328 vkDestroySemaphore(m_device->device(), s2, nullptr);
16329 vkDestroyFence(m_device->device(), fence, nullptr);
16330}
16331
16332TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16333 m_errorMonitor->ExpectSuccess();
16334
16335 ASSERT_NO_FATAL_FAILURE(InitState());
16336 VkResult err;
16337
16338 // A fence created signaled
16339 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16340 VkFence f1;
16341 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16342 ASSERT_VK_SUCCESS(err);
16343
16344 // A fence created not
16345 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16346 VkFence f2;
16347 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16348 ASSERT_VK_SUCCESS(err);
16349
16350 // Submit the unsignaled fence
16351 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16352 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16353
16354 // Wait on both fences, with signaled first.
16355 VkFence fences[] = { f1, f2 };
16356 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16357
16358 // Should have both retired!
16359 vkDestroyFence(m_device->device(), f1, nullptr);
16360 vkDestroyFence(m_device->device(), f2, nullptr);
16361
16362 m_errorMonitor->VerifyNotFound();
16363}
16364
16365TEST_F(VkPositiveLayerTest, ValidUsage) {
16366 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16367 "doesn't generate validation errors");
16368
16369 ASSERT_NO_FATAL_FAILURE(InitState());
16370
16371 m_errorMonitor->ExpectSuccess();
16372 // Verify that we can create a view with usage INPUT_ATTACHMENT
16373 VkImageObj image(m_device);
16374 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16375 ASSERT_TRUE(image.initialized());
16376 VkImageView imageView;
16377 VkImageViewCreateInfo ivci = {};
16378 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16379 ivci.image = image.handle();
16380 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16381 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16382 ivci.subresourceRange.layerCount = 1;
16383 ivci.subresourceRange.baseMipLevel = 0;
16384 ivci.subresourceRange.levelCount = 1;
16385 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16386
16387 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16388 m_errorMonitor->VerifyNotFound();
16389 vkDestroyImageView(m_device->device(), imageView, NULL);
16390}
16391
16392// This is a positive test. No failures are expected.
16393TEST_F(VkPositiveLayerTest, BindSparse) {
16394 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16395 "and then free the memory");
16396
16397 ASSERT_NO_FATAL_FAILURE(InitState());
16398
16399 auto index = m_device->graphics_queue_node_index_;
16400 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16401 return;
16402
16403 m_errorMonitor->ExpectSuccess();
16404
16405 VkImage image;
16406 VkImageCreateInfo image_create_info = {};
16407 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16408 image_create_info.pNext = NULL;
16409 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16410 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16411 image_create_info.extent.width = 64;
16412 image_create_info.extent.height = 64;
16413 image_create_info.extent.depth = 1;
16414 image_create_info.mipLevels = 1;
16415 image_create_info.arrayLayers = 1;
16416 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16417 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16418 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16419 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16420 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16421 ASSERT_VK_SUCCESS(err);
16422
16423 VkMemoryRequirements memory_reqs;
16424 VkDeviceMemory memory_one, memory_two;
16425 bool pass;
16426 VkMemoryAllocateInfo memory_info = {};
16427 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16428 memory_info.pNext = NULL;
16429 memory_info.allocationSize = 0;
16430 memory_info.memoryTypeIndex = 0;
16431 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16432 // Find an image big enough to allow sparse mapping of 2 memory regions
16433 // Increase the image size until it is at least twice the
16434 // size of the required alignment, to ensure we can bind both
16435 // allocated memory blocks to the image on aligned offsets.
16436 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16437 vkDestroyImage(m_device->device(), image, nullptr);
16438 image_create_info.extent.width *= 2;
16439 image_create_info.extent.height *= 2;
16440 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16441 ASSERT_VK_SUCCESS(err);
16442 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16443 }
16444 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16445 // at the end of the first
16446 memory_info.allocationSize = memory_reqs.alignment;
16447 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16448 ASSERT_TRUE(pass);
16449 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16450 ASSERT_VK_SUCCESS(err);
16451 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16452 ASSERT_VK_SUCCESS(err);
16453 VkSparseMemoryBind binds[2];
16454 binds[0].flags = 0;
16455 binds[0].memory = memory_one;
16456 binds[0].memoryOffset = 0;
16457 binds[0].resourceOffset = 0;
16458 binds[0].size = memory_info.allocationSize;
16459 binds[1].flags = 0;
16460 binds[1].memory = memory_two;
16461 binds[1].memoryOffset = 0;
16462 binds[1].resourceOffset = memory_info.allocationSize;
16463 binds[1].size = memory_info.allocationSize;
16464
16465 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16466 opaqueBindInfo.image = image;
16467 opaqueBindInfo.bindCount = 2;
16468 opaqueBindInfo.pBinds = binds;
16469
16470 VkFence fence = VK_NULL_HANDLE;
16471 VkBindSparseInfo bindSparseInfo = {};
16472 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16473 bindSparseInfo.imageOpaqueBindCount = 1;
16474 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16475
16476 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16477 vkQueueWaitIdle(m_device->m_queue);
16478 vkDestroyImage(m_device->device(), image, NULL);
16479 vkFreeMemory(m_device->device(), memory_one, NULL);
16480 vkFreeMemory(m_device->device(), memory_two, NULL);
16481 m_errorMonitor->VerifyNotFound();
16482}
16483
16484TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16485 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16486 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16487 "the command buffer has prior knowledge of that "
16488 "attachment's layout.");
16489
16490 m_errorMonitor->ExpectSuccess();
16491
16492 ASSERT_NO_FATAL_FAILURE(InitState());
16493
16494 // A renderpass with one color attachment.
16495 VkAttachmentDescription attachment = { 0,
16496 VK_FORMAT_R8G8B8A8_UNORM,
16497 VK_SAMPLE_COUNT_1_BIT,
16498 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16499 VK_ATTACHMENT_STORE_OP_STORE,
16500 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16501 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16502 VK_IMAGE_LAYOUT_UNDEFINED,
16503 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16504
16505 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16506
16507 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16508
16509 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16510
16511 VkRenderPass rp;
16512 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16513 ASSERT_VK_SUCCESS(err);
16514
16515 // A compatible framebuffer.
16516 VkImageObj image(m_device);
16517 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16518 ASSERT_TRUE(image.initialized());
16519
16520 VkImageViewCreateInfo ivci = {
16521 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16522 nullptr,
16523 0,
16524 image.handle(),
16525 VK_IMAGE_VIEW_TYPE_2D,
16526 VK_FORMAT_R8G8B8A8_UNORM,
16527 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16528 VK_COMPONENT_SWIZZLE_IDENTITY },
16529 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16530 };
16531 VkImageView view;
16532 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16533 ASSERT_VK_SUCCESS(err);
16534
16535 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16536 VkFramebuffer fb;
16537 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16538 ASSERT_VK_SUCCESS(err);
16539
16540 // Record a single command buffer which uses this renderpass twice. The
16541 // bug is triggered at the beginning of the second renderpass, when the
16542 // command buffer already has a layout recorded for the attachment.
16543 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16544 BeginCommandBuffer();
16545 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16546 vkCmdEndRenderPass(m_commandBuffer->handle());
16547 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16548
16549 m_errorMonitor->VerifyNotFound();
16550
16551 vkCmdEndRenderPass(m_commandBuffer->handle());
16552 EndCommandBuffer();
16553
16554 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16555 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16556 vkDestroyImageView(m_device->device(), view, nullptr);
16557}
16558
16559TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
16560 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
16561 "command buffer, bind them together, then destroy "
16562 "command pool and framebuffer and verify there are no "
16563 "errors.");
16564
16565 m_errorMonitor->ExpectSuccess();
16566
16567 ASSERT_NO_FATAL_FAILURE(InitState());
16568
16569 // A renderpass with one color attachment.
16570 VkAttachmentDescription attachment = { 0,
16571 VK_FORMAT_R8G8B8A8_UNORM,
16572 VK_SAMPLE_COUNT_1_BIT,
16573 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16574 VK_ATTACHMENT_STORE_OP_STORE,
16575 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16576 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16577 VK_IMAGE_LAYOUT_UNDEFINED,
16578 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16579
16580 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16581
16582 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16583
16584 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16585
16586 VkRenderPass rp;
16587 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16588 ASSERT_VK_SUCCESS(err);
16589
16590 // A compatible framebuffer.
16591 VkImageObj image(m_device);
16592 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16593 ASSERT_TRUE(image.initialized());
16594
16595 VkImageViewCreateInfo ivci = {
16596 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16597 nullptr,
16598 0,
16599 image.handle(),
16600 VK_IMAGE_VIEW_TYPE_2D,
16601 VK_FORMAT_R8G8B8A8_UNORM,
16602 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16603 VK_COMPONENT_SWIZZLE_IDENTITY },
16604 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16605 };
16606 VkImageView view;
16607 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16608 ASSERT_VK_SUCCESS(err);
16609
16610 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16611 VkFramebuffer fb;
16612 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16613 ASSERT_VK_SUCCESS(err);
16614
16615 // Explicitly create a command buffer to bind the FB to so that we can then
16616 // destroy the command pool in order to implicitly free command buffer
16617 VkCommandPool command_pool;
16618 VkCommandPoolCreateInfo pool_create_info{};
16619 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16620 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16621 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16622 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16623
16624 VkCommandBuffer command_buffer;
16625 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16626 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16627 command_buffer_allocate_info.commandPool = command_pool;
16628 command_buffer_allocate_info.commandBufferCount = 1;
16629 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16630 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16631
16632 // Begin our cmd buffer with renderpass using our framebuffer
16633 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16634 VkCommandBufferBeginInfo begin_info{};
16635 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16636 vkBeginCommandBuffer(command_buffer, &begin_info);
16637
16638 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16639 vkCmdEndRenderPass(command_buffer);
16640 vkEndCommandBuffer(command_buffer);
16641 vkDestroyImageView(m_device->device(), view, nullptr);
16642 // Destroy command pool to implicitly free command buffer
16643 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16644 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16645 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16646 m_errorMonitor->VerifyNotFound();
16647}
16648
16649TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
16650 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
16651 "transitions for the first subpass");
16652
16653 m_errorMonitor->ExpectSuccess();
16654
16655 ASSERT_NO_FATAL_FAILURE(InitState());
16656
16657 // A renderpass with one color attachment.
16658 VkAttachmentDescription attachment = { 0,
16659 VK_FORMAT_R8G8B8A8_UNORM,
16660 VK_SAMPLE_COUNT_1_BIT,
16661 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16662 VK_ATTACHMENT_STORE_OP_STORE,
16663 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16664 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16665 VK_IMAGE_LAYOUT_UNDEFINED,
16666 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16667
16668 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16669
16670 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16671
16672 VkSubpassDependency dep = { 0,
16673 0,
16674 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16675 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16676 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16677 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16678 VK_DEPENDENCY_BY_REGION_BIT };
16679
16680 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16681
16682 VkResult err;
16683 VkRenderPass rp;
16684 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16685 ASSERT_VK_SUCCESS(err);
16686
16687 // A compatible framebuffer.
16688 VkImageObj image(m_device);
16689 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16690 ASSERT_TRUE(image.initialized());
16691
16692 VkImageViewCreateInfo ivci = {
16693 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16694 nullptr,
16695 0,
16696 image.handle(),
16697 VK_IMAGE_VIEW_TYPE_2D,
16698 VK_FORMAT_R8G8B8A8_UNORM,
16699 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16700 VK_COMPONENT_SWIZZLE_IDENTITY },
16701 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16702 };
16703 VkImageView view;
16704 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16705 ASSERT_VK_SUCCESS(err);
16706
16707 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16708 VkFramebuffer fb;
16709 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16710 ASSERT_VK_SUCCESS(err);
16711
16712 // Record a single command buffer which issues a pipeline barrier w/
16713 // image memory barrier for the attachment. This detects the previously
16714 // missing tracking of the subpass layout by throwing a validation error
16715 // if it doesn't occur.
16716 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16717 BeginCommandBuffer();
16718 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16719
16720 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
16721 nullptr,
16722 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16723 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16724 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16725 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16726 VK_QUEUE_FAMILY_IGNORED,
16727 VK_QUEUE_FAMILY_IGNORED,
16728 image.handle(),
16729 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
16730 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16731 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16732 &imb);
16733
16734 vkCmdEndRenderPass(m_commandBuffer->handle());
16735 m_errorMonitor->VerifyNotFound();
16736 EndCommandBuffer();
16737
16738 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16739 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16740 vkDestroyImageView(m_device->device(), view, nullptr);
16741}
16742
16743TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
16744 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
16745 "is used as a depth/stencil framebuffer attachment, the "
16746 "aspectMask is ignored and both depth and stencil image "
16747 "subresources are used.");
16748
16749 VkFormatProperties format_properties;
16750 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
16751 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
16752 return;
16753 }
16754
16755 m_errorMonitor->ExpectSuccess();
16756
16757 ASSERT_NO_FATAL_FAILURE(InitState());
16758
16759 VkAttachmentDescription attachment = { 0,
16760 VK_FORMAT_D32_SFLOAT_S8_UINT,
16761 VK_SAMPLE_COUNT_1_BIT,
16762 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16763 VK_ATTACHMENT_STORE_OP_STORE,
16764 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16765 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16766 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
16767 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16768
16769 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16770
16771 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
16772
16773 VkSubpassDependency dep = { 0,
16774 0,
16775 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16776 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16777 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16778 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16779 VK_DEPENDENCY_BY_REGION_BIT};
16780
16781 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16782
16783 VkResult err;
16784 VkRenderPass rp;
16785 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16786 ASSERT_VK_SUCCESS(err);
16787
16788 VkImageObj image(m_device);
16789 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
16790 0x26, // usage
16791 VK_IMAGE_TILING_OPTIMAL, 0);
16792 ASSERT_TRUE(image.initialized());
16793 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
16794
16795 VkImageViewCreateInfo ivci = {
16796 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16797 nullptr,
16798 0,
16799 image.handle(),
16800 VK_IMAGE_VIEW_TYPE_2D,
16801 VK_FORMAT_D32_SFLOAT_S8_UINT,
16802 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
16803 { 0x2, 0, 1, 0, 1 },
16804 };
16805 VkImageView view;
16806 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16807 ASSERT_VK_SUCCESS(err);
16808
16809 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16810 VkFramebuffer fb;
16811 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16812 ASSERT_VK_SUCCESS(err);
16813
16814 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16815 BeginCommandBuffer();
16816 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16817
16818 VkImageMemoryBarrier imb = {};
16819 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16820 imb.pNext = nullptr;
16821 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16822 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16823 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16824 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16825 imb.srcQueueFamilyIndex = 0;
16826 imb.dstQueueFamilyIndex = 0;
16827 imb.image = image.handle();
16828 imb.subresourceRange.aspectMask = 0x6;
16829 imb.subresourceRange.baseMipLevel = 0;
16830 imb.subresourceRange.levelCount = 0x1;
16831 imb.subresourceRange.baseArrayLayer = 0;
16832 imb.subresourceRange.layerCount = 0x1;
16833
16834 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16835 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16836 &imb);
16837
16838 vkCmdEndRenderPass(m_commandBuffer->handle());
16839 EndCommandBuffer();
16840 QueueCommandBuffer(false);
16841 m_errorMonitor->VerifyNotFound();
16842
16843 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16844 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16845 vkDestroyImageView(m_device->device(), view, nullptr);
16846}
16847
16848TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
16849 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
16850 "errors, when an attachment reference is "
16851 "VK_ATTACHMENT_UNUSED");
16852
16853 m_errorMonitor->ExpectSuccess();
16854
16855 ASSERT_NO_FATAL_FAILURE(InitState());
16856
16857 // A renderpass with no attachments
16858 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16859
16860 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16861
16862 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
16863
16864 VkRenderPass rp;
16865 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16866 ASSERT_VK_SUCCESS(err);
16867
16868 // A compatible framebuffer.
16869 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
16870 VkFramebuffer fb;
16871 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16872 ASSERT_VK_SUCCESS(err);
16873
16874 // Record a command buffer which just begins and ends the renderpass. The
16875 // bug manifests in BeginRenderPass.
16876 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16877 BeginCommandBuffer();
16878 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16879 vkCmdEndRenderPass(m_commandBuffer->handle());
16880 m_errorMonitor->VerifyNotFound();
16881 EndCommandBuffer();
16882
16883 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16884 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16885}
16886
16887// This is a positive test. No errors are expected.
16888TEST_F(VkPositiveLayerTest, StencilLoadOp) {
16889 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
16890 "CLEAR. stencil[Load|Store]Op used to be ignored.");
16891 VkResult result = VK_SUCCESS;
16892 VkImageFormatProperties formatProps;
16893 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
16894 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
16895 &formatProps);
16896 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
16897 return;
16898 }
16899
16900 ASSERT_NO_FATAL_FAILURE(InitState());
16901 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
16902 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
16903 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
16904 VkAttachmentDescription att = {};
16905 VkAttachmentReference ref = {};
16906 att.format = depth_stencil_fmt;
16907 att.samples = VK_SAMPLE_COUNT_1_BIT;
16908 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
16909 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
16910 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
16911 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
16912 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16913 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16914
16915 VkClearValue clear;
16916 clear.depthStencil.depth = 1.0;
16917 clear.depthStencil.stencil = 0;
16918 ref.attachment = 0;
16919 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16920
16921 VkSubpassDescription subpass = {};
16922 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
16923 subpass.flags = 0;
16924 subpass.inputAttachmentCount = 0;
16925 subpass.pInputAttachments = NULL;
16926 subpass.colorAttachmentCount = 0;
16927 subpass.pColorAttachments = NULL;
16928 subpass.pResolveAttachments = NULL;
16929 subpass.pDepthStencilAttachment = &ref;
16930 subpass.preserveAttachmentCount = 0;
16931 subpass.pPreserveAttachments = NULL;
16932
16933 VkRenderPass rp;
16934 VkRenderPassCreateInfo rp_info = {};
16935 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16936 rp_info.attachmentCount = 1;
16937 rp_info.pAttachments = &att;
16938 rp_info.subpassCount = 1;
16939 rp_info.pSubpasses = &subpass;
16940 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
16941 ASSERT_VK_SUCCESS(result);
16942
16943 VkImageView *depthView = m_depthStencil->BindInfo();
16944 VkFramebufferCreateInfo fb_info = {};
16945 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
16946 fb_info.pNext = NULL;
16947 fb_info.renderPass = rp;
16948 fb_info.attachmentCount = 1;
16949 fb_info.pAttachments = depthView;
16950 fb_info.width = 100;
16951 fb_info.height = 100;
16952 fb_info.layers = 1;
16953 VkFramebuffer fb;
16954 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
16955 ASSERT_VK_SUCCESS(result);
16956
16957 VkRenderPassBeginInfo rpbinfo = {};
16958 rpbinfo.clearValueCount = 1;
16959 rpbinfo.pClearValues = &clear;
16960 rpbinfo.pNext = NULL;
16961 rpbinfo.renderPass = rp;
16962 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
16963 rpbinfo.renderArea.extent.width = 100;
16964 rpbinfo.renderArea.extent.height = 100;
16965 rpbinfo.renderArea.offset.x = 0;
16966 rpbinfo.renderArea.offset.y = 0;
16967 rpbinfo.framebuffer = fb;
16968
16969 VkFence fence = {};
16970 VkFenceCreateInfo fence_ci = {};
16971 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16972 fence_ci.pNext = nullptr;
16973 fence_ci.flags = 0;
16974 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
16975 ASSERT_VK_SUCCESS(result);
16976
16977 m_commandBuffer->BeginCommandBuffer();
16978 m_commandBuffer->BeginRenderPass(rpbinfo);
16979 m_commandBuffer->EndRenderPass();
16980 m_commandBuffer->EndCommandBuffer();
16981 m_commandBuffer->QueueCommandBuffer(fence);
16982
16983 VkImageObj destImage(m_device);
16984 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16985 VK_IMAGE_TILING_OPTIMAL, 0);
16986 VkImageMemoryBarrier barrier = {};
16987 VkImageSubresourceRange range;
16988 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16989 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16990 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
16991 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16992 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
16993 barrier.image = m_depthStencil->handle();
16994 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16995 range.baseMipLevel = 0;
16996 range.levelCount = 1;
16997 range.baseArrayLayer = 0;
16998 range.layerCount = 1;
16999 barrier.subresourceRange = range;
17000 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17001 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17002 cmdbuf.BeginCommandBuffer();
17003 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17004 &barrier);
17005 barrier.srcAccessMask = 0;
17006 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17007 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17008 barrier.image = destImage.handle();
17009 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17010 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17011 &barrier);
17012 VkImageCopy cregion;
17013 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17014 cregion.srcSubresource.mipLevel = 0;
17015 cregion.srcSubresource.baseArrayLayer = 0;
17016 cregion.srcSubresource.layerCount = 1;
17017 cregion.srcOffset.x = 0;
17018 cregion.srcOffset.y = 0;
17019 cregion.srcOffset.z = 0;
17020 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17021 cregion.dstSubresource.mipLevel = 0;
17022 cregion.dstSubresource.baseArrayLayer = 0;
17023 cregion.dstSubresource.layerCount = 1;
17024 cregion.dstOffset.x = 0;
17025 cregion.dstOffset.y = 0;
17026 cregion.dstOffset.z = 0;
17027 cregion.extent.width = 100;
17028 cregion.extent.height = 100;
17029 cregion.extent.depth = 1;
17030 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17031 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17032 cmdbuf.EndCommandBuffer();
17033
17034 VkSubmitInfo submit_info;
17035 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17036 submit_info.pNext = NULL;
17037 submit_info.waitSemaphoreCount = 0;
17038 submit_info.pWaitSemaphores = NULL;
17039 submit_info.pWaitDstStageMask = NULL;
17040 submit_info.commandBufferCount = 1;
17041 submit_info.pCommandBuffers = &cmdbuf.handle();
17042 submit_info.signalSemaphoreCount = 0;
17043 submit_info.pSignalSemaphores = NULL;
17044
17045 m_errorMonitor->ExpectSuccess();
17046 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17047 m_errorMonitor->VerifyNotFound();
17048
17049 vkQueueWaitIdle(m_device->m_queue);
17050 vkDestroyFence(m_device->device(), fence, nullptr);
17051 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17052 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17053}
17054
17055// This is a positive test. No errors should be generated.
17056TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17057 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17058
17059 m_errorMonitor->ExpectSuccess();
17060 ASSERT_NO_FATAL_FAILURE(InitState());
17061
17062 VkEvent event;
17063 VkEventCreateInfo event_create_info{};
17064 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17065 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17066
17067 VkCommandPool command_pool;
17068 VkCommandPoolCreateInfo pool_create_info{};
17069 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17070 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17071 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17072 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17073
17074 VkCommandBuffer command_buffer;
17075 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17076 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17077 command_buffer_allocate_info.commandPool = command_pool;
17078 command_buffer_allocate_info.commandBufferCount = 1;
17079 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17080 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17081
17082 VkQueue queue = VK_NULL_HANDLE;
17083 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17084
17085 {
17086 VkCommandBufferBeginInfo begin_info{};
17087 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17088 vkBeginCommandBuffer(command_buffer, &begin_info);
17089
17090 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17091 nullptr, 0, nullptr);
17092 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17093 vkEndCommandBuffer(command_buffer);
17094 }
17095 {
17096 VkSubmitInfo submit_info{};
17097 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17098 submit_info.commandBufferCount = 1;
17099 submit_info.pCommandBuffers = &command_buffer;
17100 submit_info.signalSemaphoreCount = 0;
17101 submit_info.pSignalSemaphores = nullptr;
17102 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17103 }
17104 { vkSetEvent(m_device->device(), event); }
17105
17106 vkQueueWaitIdle(queue);
17107
17108 vkDestroyEvent(m_device->device(), event, nullptr);
17109 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17110 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17111
17112 m_errorMonitor->VerifyNotFound();
17113}
17114// This is a positive test. No errors should be generated.
17115TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17116 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17117
17118 ASSERT_NO_FATAL_FAILURE(InitState());
17119 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17120 return;
17121
17122 m_errorMonitor->ExpectSuccess();
17123
17124 VkQueryPool query_pool;
17125 VkQueryPoolCreateInfo query_pool_create_info{};
17126 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17127 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17128 query_pool_create_info.queryCount = 1;
17129 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17130
17131 VkCommandPool command_pool;
17132 VkCommandPoolCreateInfo pool_create_info{};
17133 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17134 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17135 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17136 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17137
17138 VkCommandBuffer command_buffer;
17139 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17140 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17141 command_buffer_allocate_info.commandPool = command_pool;
17142 command_buffer_allocate_info.commandBufferCount = 1;
17143 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17144 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17145
17146 VkCommandBuffer secondary_command_buffer;
17147 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17148 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17149
17150 VkQueue queue = VK_NULL_HANDLE;
17151 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17152
17153 uint32_t qfi = 0;
17154 VkBufferCreateInfo buff_create_info = {};
17155 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17156 buff_create_info.size = 1024;
17157 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17158 buff_create_info.queueFamilyIndexCount = 1;
17159 buff_create_info.pQueueFamilyIndices = &qfi;
17160
17161 VkResult err;
17162 VkBuffer buffer;
17163 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17164 ASSERT_VK_SUCCESS(err);
17165 VkMemoryAllocateInfo mem_alloc = {};
17166 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17167 mem_alloc.pNext = NULL;
17168 mem_alloc.allocationSize = 1024;
17169 mem_alloc.memoryTypeIndex = 0;
17170
17171 VkMemoryRequirements memReqs;
17172 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17173 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17174 if (!pass) {
17175 vkDestroyBuffer(m_device->device(), buffer, NULL);
17176 return;
17177 }
17178
17179 VkDeviceMemory mem;
17180 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17181 ASSERT_VK_SUCCESS(err);
17182 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17183 ASSERT_VK_SUCCESS(err);
17184
17185 VkCommandBufferInheritanceInfo hinfo = {};
17186 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17187 hinfo.renderPass = VK_NULL_HANDLE;
17188 hinfo.subpass = 0;
17189 hinfo.framebuffer = VK_NULL_HANDLE;
17190 hinfo.occlusionQueryEnable = VK_FALSE;
17191 hinfo.queryFlags = 0;
17192 hinfo.pipelineStatistics = 0;
17193
17194 {
17195 VkCommandBufferBeginInfo begin_info{};
17196 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17197 begin_info.pInheritanceInfo = &hinfo;
17198 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17199
17200 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17201 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17202
17203 vkEndCommandBuffer(secondary_command_buffer);
17204
17205 begin_info.pInheritanceInfo = nullptr;
17206 vkBeginCommandBuffer(command_buffer, &begin_info);
17207
17208 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17209 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17210
17211 vkEndCommandBuffer(command_buffer);
17212 }
17213 {
17214 VkSubmitInfo submit_info{};
17215 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17216 submit_info.commandBufferCount = 1;
17217 submit_info.pCommandBuffers = &command_buffer;
17218 submit_info.signalSemaphoreCount = 0;
17219 submit_info.pSignalSemaphores = nullptr;
17220 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17221 }
17222
17223 vkQueueWaitIdle(queue);
17224
17225 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17226 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17227 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17228 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17229 vkDestroyBuffer(m_device->device(), buffer, NULL);
17230 vkFreeMemory(m_device->device(), mem, NULL);
17231
17232 m_errorMonitor->VerifyNotFound();
17233}
17234
17235// This is a positive test. No errors should be generated.
17236TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17237 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17238
17239 ASSERT_NO_FATAL_FAILURE(InitState());
17240 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17241 return;
17242
17243 m_errorMonitor->ExpectSuccess();
17244
17245 VkQueryPool query_pool;
17246 VkQueryPoolCreateInfo query_pool_create_info{};
17247 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17248 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17249 query_pool_create_info.queryCount = 1;
17250 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17251
17252 VkCommandPool command_pool;
17253 VkCommandPoolCreateInfo pool_create_info{};
17254 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17255 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17256 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17257 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17258
17259 VkCommandBuffer command_buffer[2];
17260 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17261 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17262 command_buffer_allocate_info.commandPool = command_pool;
17263 command_buffer_allocate_info.commandBufferCount = 2;
17264 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17265 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17266
17267 VkQueue queue = VK_NULL_HANDLE;
17268 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17269
17270 uint32_t qfi = 0;
17271 VkBufferCreateInfo buff_create_info = {};
17272 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17273 buff_create_info.size = 1024;
17274 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17275 buff_create_info.queueFamilyIndexCount = 1;
17276 buff_create_info.pQueueFamilyIndices = &qfi;
17277
17278 VkResult err;
17279 VkBuffer buffer;
17280 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17281 ASSERT_VK_SUCCESS(err);
17282 VkMemoryAllocateInfo mem_alloc = {};
17283 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17284 mem_alloc.pNext = NULL;
17285 mem_alloc.allocationSize = 1024;
17286 mem_alloc.memoryTypeIndex = 0;
17287
17288 VkMemoryRequirements memReqs;
17289 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17290 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17291 if (!pass) {
17292 vkDestroyBuffer(m_device->device(), buffer, NULL);
17293 return;
17294 }
17295
17296 VkDeviceMemory mem;
17297 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17298 ASSERT_VK_SUCCESS(err);
17299 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17300 ASSERT_VK_SUCCESS(err);
17301
17302 {
17303 VkCommandBufferBeginInfo begin_info{};
17304 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17305 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17306
17307 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17308 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17309
17310 vkEndCommandBuffer(command_buffer[0]);
17311
17312 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17313
17314 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17315
17316 vkEndCommandBuffer(command_buffer[1]);
17317 }
17318 {
17319 VkSubmitInfo submit_info{};
17320 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17321 submit_info.commandBufferCount = 2;
17322 submit_info.pCommandBuffers = command_buffer;
17323 submit_info.signalSemaphoreCount = 0;
17324 submit_info.pSignalSemaphores = nullptr;
17325 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17326 }
17327
17328 vkQueueWaitIdle(queue);
17329
17330 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17331 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17332 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17333 vkDestroyBuffer(m_device->device(), buffer, NULL);
17334 vkFreeMemory(m_device->device(), mem, NULL);
17335
17336 m_errorMonitor->VerifyNotFound();
17337}
17338
Tony Barbourc46924f2016-11-04 11:49:52 -060017339TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017340 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17341
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017342 ASSERT_NO_FATAL_FAILURE(InitState());
17343 VkEvent event;
17344 VkEventCreateInfo event_create_info{};
17345 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17346 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17347
17348 VkCommandPool command_pool;
17349 VkCommandPoolCreateInfo pool_create_info{};
17350 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17351 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17352 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17353 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17354
17355 VkCommandBuffer command_buffer;
17356 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17357 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17358 command_buffer_allocate_info.commandPool = command_pool;
17359 command_buffer_allocate_info.commandBufferCount = 1;
17360 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17361 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17362
17363 VkQueue queue = VK_NULL_HANDLE;
17364 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17365
17366 {
17367 VkCommandBufferBeginInfo begin_info{};
17368 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17369 vkBeginCommandBuffer(command_buffer, &begin_info);
17370
17371 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017372 vkEndCommandBuffer(command_buffer);
17373 }
17374 {
17375 VkSubmitInfo submit_info{};
17376 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17377 submit_info.commandBufferCount = 1;
17378 submit_info.pCommandBuffers = &command_buffer;
17379 submit_info.signalSemaphoreCount = 0;
17380 submit_info.pSignalSemaphores = nullptr;
17381 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17382 }
17383 {
17384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17385 "command buffer.");
17386 vkSetEvent(m_device->device(), event);
17387 m_errorMonitor->VerifyFound();
17388 }
17389
17390 vkQueueWaitIdle(queue);
17391
17392 vkDestroyEvent(m_device->device(), event, nullptr);
17393 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17394 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17395}
17396
17397// This is a positive test. No errors should be generated.
17398TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17399 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17400 "run through a Submit & WaitForFences cycle 3 times. This "
17401 "previously revealed a bug so running this positive test "
17402 "to prevent a regression.");
17403 m_errorMonitor->ExpectSuccess();
17404
17405 ASSERT_NO_FATAL_FAILURE(InitState());
17406 VkQueue queue = VK_NULL_HANDLE;
17407 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17408
17409 static const uint32_t NUM_OBJECTS = 2;
17410 static const uint32_t NUM_FRAMES = 3;
17411 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17412 VkFence fences[NUM_OBJECTS] = {};
17413
17414 VkCommandPool cmd_pool;
17415 VkCommandPoolCreateInfo cmd_pool_ci = {};
17416 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17417 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17418 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17419 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17420 ASSERT_VK_SUCCESS(err);
17421
17422 VkCommandBufferAllocateInfo cmd_buf_info = {};
17423 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17424 cmd_buf_info.commandPool = cmd_pool;
17425 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17426 cmd_buf_info.commandBufferCount = 1;
17427
17428 VkFenceCreateInfo fence_ci = {};
17429 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17430 fence_ci.pNext = nullptr;
17431 fence_ci.flags = 0;
17432
17433 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17434 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17435 ASSERT_VK_SUCCESS(err);
17436 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17437 ASSERT_VK_SUCCESS(err);
17438 }
17439
17440 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17441 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17442 // Create empty cmd buffer
17443 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17444 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17445
17446 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17447 ASSERT_VK_SUCCESS(err);
17448 err = vkEndCommandBuffer(cmd_buffers[obj]);
17449 ASSERT_VK_SUCCESS(err);
17450
17451 VkSubmitInfo submit_info = {};
17452 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17453 submit_info.commandBufferCount = 1;
17454 submit_info.pCommandBuffers = &cmd_buffers[obj];
17455 // Submit cmd buffer and wait for fence
17456 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17457 ASSERT_VK_SUCCESS(err);
17458 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17459 ASSERT_VK_SUCCESS(err);
17460 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17461 ASSERT_VK_SUCCESS(err);
17462 }
17463 }
17464 m_errorMonitor->VerifyNotFound();
17465 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17466 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17467 vkDestroyFence(m_device->device(), fences[i], nullptr);
17468 }
17469}
17470// This is a positive test. No errors should be generated.
17471TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17472
17473 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17474 "submitted on separate queues followed by a QueueWaitIdle.");
17475
17476 ASSERT_NO_FATAL_FAILURE(InitState());
17477 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17478 return;
17479
17480 m_errorMonitor->ExpectSuccess();
17481
17482 VkSemaphore semaphore;
17483 VkSemaphoreCreateInfo semaphore_create_info{};
17484 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17485 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17486
17487 VkCommandPool command_pool;
17488 VkCommandPoolCreateInfo pool_create_info{};
17489 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17490 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17491 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17492 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17493
17494 VkCommandBuffer command_buffer[2];
17495 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17496 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17497 command_buffer_allocate_info.commandPool = command_pool;
17498 command_buffer_allocate_info.commandBufferCount = 2;
17499 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17500 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17501
17502 VkQueue queue = VK_NULL_HANDLE;
17503 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17504
17505 {
17506 VkCommandBufferBeginInfo begin_info{};
17507 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17508 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17509
17510 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17511 nullptr, 0, nullptr, 0, nullptr);
17512
17513 VkViewport viewport{};
17514 viewport.maxDepth = 1.0f;
17515 viewport.minDepth = 0.0f;
17516 viewport.width = 512;
17517 viewport.height = 512;
17518 viewport.x = 0;
17519 viewport.y = 0;
17520 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17521 vkEndCommandBuffer(command_buffer[0]);
17522 }
17523 {
17524 VkCommandBufferBeginInfo begin_info{};
17525 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17526 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17527
17528 VkViewport viewport{};
17529 viewport.maxDepth = 1.0f;
17530 viewport.minDepth = 0.0f;
17531 viewport.width = 512;
17532 viewport.height = 512;
17533 viewport.x = 0;
17534 viewport.y = 0;
17535 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17536 vkEndCommandBuffer(command_buffer[1]);
17537 }
17538 {
17539 VkSubmitInfo submit_info{};
17540 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17541 submit_info.commandBufferCount = 1;
17542 submit_info.pCommandBuffers = &command_buffer[0];
17543 submit_info.signalSemaphoreCount = 1;
17544 submit_info.pSignalSemaphores = &semaphore;
17545 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17546 }
17547 {
17548 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17549 VkSubmitInfo submit_info{};
17550 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17551 submit_info.commandBufferCount = 1;
17552 submit_info.pCommandBuffers = &command_buffer[1];
17553 submit_info.waitSemaphoreCount = 1;
17554 submit_info.pWaitSemaphores = &semaphore;
17555 submit_info.pWaitDstStageMask = flags;
17556 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17557 }
17558
17559 vkQueueWaitIdle(m_device->m_queue);
17560
17561 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17562 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17563 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17564
17565 m_errorMonitor->VerifyNotFound();
17566}
17567
17568// This is a positive test. No errors should be generated.
17569TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
17570
17571 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17572 "submitted on separate queues, the second having a fence"
17573 "followed by a QueueWaitIdle.");
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 VkFence fence;
17582 VkFenceCreateInfo fence_create_info{};
17583 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17584 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17585
17586 VkSemaphore semaphore;
17587 VkSemaphoreCreateInfo semaphore_create_info{};
17588 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17589 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17590
17591 VkCommandPool command_pool;
17592 VkCommandPoolCreateInfo pool_create_info{};
17593 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17594 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17595 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17596 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17597
17598 VkCommandBuffer command_buffer[2];
17599 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17600 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17601 command_buffer_allocate_info.commandPool = command_pool;
17602 command_buffer_allocate_info.commandBufferCount = 2;
17603 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17604 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17605
17606 VkQueue queue = VK_NULL_HANDLE;
17607 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17608
17609 {
17610 VkCommandBufferBeginInfo begin_info{};
17611 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17612 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17613
17614 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17615 nullptr, 0, nullptr, 0, nullptr);
17616
17617 VkViewport viewport{};
17618 viewport.maxDepth = 1.0f;
17619 viewport.minDepth = 0.0f;
17620 viewport.width = 512;
17621 viewport.height = 512;
17622 viewport.x = 0;
17623 viewport.y = 0;
17624 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17625 vkEndCommandBuffer(command_buffer[0]);
17626 }
17627 {
17628 VkCommandBufferBeginInfo begin_info{};
17629 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17630 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17631
17632 VkViewport viewport{};
17633 viewport.maxDepth = 1.0f;
17634 viewport.minDepth = 0.0f;
17635 viewport.width = 512;
17636 viewport.height = 512;
17637 viewport.x = 0;
17638 viewport.y = 0;
17639 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17640 vkEndCommandBuffer(command_buffer[1]);
17641 }
17642 {
17643 VkSubmitInfo submit_info{};
17644 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17645 submit_info.commandBufferCount = 1;
17646 submit_info.pCommandBuffers = &command_buffer[0];
17647 submit_info.signalSemaphoreCount = 1;
17648 submit_info.pSignalSemaphores = &semaphore;
17649 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17650 }
17651 {
17652 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17653 VkSubmitInfo submit_info{};
17654 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17655 submit_info.commandBufferCount = 1;
17656 submit_info.pCommandBuffers = &command_buffer[1];
17657 submit_info.waitSemaphoreCount = 1;
17658 submit_info.pWaitSemaphores = &semaphore;
17659 submit_info.pWaitDstStageMask = flags;
17660 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17661 }
17662
17663 vkQueueWaitIdle(m_device->m_queue);
17664
17665 vkDestroyFence(m_device->device(), fence, nullptr);
17666 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17667 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17668 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17669
17670 m_errorMonitor->VerifyNotFound();
17671}
17672
17673// This is a positive test. No errors should be generated.
17674TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
17675
17676 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17677 "submitted on separate queues, the second having a fence"
17678 "followed by two consecutive WaitForFences calls on the same fence.");
17679
17680 ASSERT_NO_FATAL_FAILURE(InitState());
17681 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17682 return;
17683
17684 m_errorMonitor->ExpectSuccess();
17685
17686 VkFence fence;
17687 VkFenceCreateInfo fence_create_info{};
17688 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17689 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17690
17691 VkSemaphore semaphore;
17692 VkSemaphoreCreateInfo semaphore_create_info{};
17693 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17694 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17695
17696 VkCommandPool command_pool;
17697 VkCommandPoolCreateInfo pool_create_info{};
17698 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17699 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17700 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17701 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17702
17703 VkCommandBuffer command_buffer[2];
17704 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17705 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17706 command_buffer_allocate_info.commandPool = command_pool;
17707 command_buffer_allocate_info.commandBufferCount = 2;
17708 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17709 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17710
17711 VkQueue queue = VK_NULL_HANDLE;
17712 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17713
17714 {
17715 VkCommandBufferBeginInfo begin_info{};
17716 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17717 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17718
17719 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17720 nullptr, 0, nullptr, 0, nullptr);
17721
17722 VkViewport viewport{};
17723 viewport.maxDepth = 1.0f;
17724 viewport.minDepth = 0.0f;
17725 viewport.width = 512;
17726 viewport.height = 512;
17727 viewport.x = 0;
17728 viewport.y = 0;
17729 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17730 vkEndCommandBuffer(command_buffer[0]);
17731 }
17732 {
17733 VkCommandBufferBeginInfo begin_info{};
17734 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17735 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17736
17737 VkViewport viewport{};
17738 viewport.maxDepth = 1.0f;
17739 viewport.minDepth = 0.0f;
17740 viewport.width = 512;
17741 viewport.height = 512;
17742 viewport.x = 0;
17743 viewport.y = 0;
17744 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17745 vkEndCommandBuffer(command_buffer[1]);
17746 }
17747 {
17748 VkSubmitInfo submit_info{};
17749 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17750 submit_info.commandBufferCount = 1;
17751 submit_info.pCommandBuffers = &command_buffer[0];
17752 submit_info.signalSemaphoreCount = 1;
17753 submit_info.pSignalSemaphores = &semaphore;
17754 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17755 }
17756 {
17757 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17758 VkSubmitInfo submit_info{};
17759 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17760 submit_info.commandBufferCount = 1;
17761 submit_info.pCommandBuffers = &command_buffer[1];
17762 submit_info.waitSemaphoreCount = 1;
17763 submit_info.pWaitSemaphores = &semaphore;
17764 submit_info.pWaitDstStageMask = flags;
17765 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17766 }
17767
17768 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17769 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17770
17771 vkDestroyFence(m_device->device(), fence, nullptr);
17772 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17773 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17774 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17775
17776 m_errorMonitor->VerifyNotFound();
17777}
17778
17779TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
17780
17781 ASSERT_NO_FATAL_FAILURE(InitState());
17782 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
17783 printf("Test requires two queues, skipping\n");
17784 return;
17785 }
17786
17787 VkResult err;
17788
17789 m_errorMonitor->ExpectSuccess();
17790
17791 VkQueue q0 = m_device->m_queue;
17792 VkQueue q1 = nullptr;
17793 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
17794 ASSERT_NE(q1, nullptr);
17795
17796 // An (empty) command buffer. We must have work in the first submission --
17797 // the layer treats unfenced work differently from fenced work.
17798 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
17799 VkCommandPool pool;
17800 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
17801 ASSERT_VK_SUCCESS(err);
17802 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
17803 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
17804 VkCommandBuffer cb;
17805 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
17806 ASSERT_VK_SUCCESS(err);
17807 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
17808 err = vkBeginCommandBuffer(cb, &cbbi);
17809 ASSERT_VK_SUCCESS(err);
17810 err = vkEndCommandBuffer(cb);
17811 ASSERT_VK_SUCCESS(err);
17812
17813 // A semaphore
17814 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17815 VkSemaphore s;
17816 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
17817 ASSERT_VK_SUCCESS(err);
17818
17819 // First submission, to q0
17820 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
17821
17822 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
17823 ASSERT_VK_SUCCESS(err);
17824
17825 // Second submission, to q1, waiting on s
17826 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
17827 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
17828
17829 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
17830 ASSERT_VK_SUCCESS(err);
17831
17832 // Wait for q0 idle
17833 err = vkQueueWaitIdle(q0);
17834 ASSERT_VK_SUCCESS(err);
17835
17836 // Command buffer should have been completed (it was on q0); reset the pool.
17837 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
17838
17839 m_errorMonitor->VerifyNotFound();
17840
17841 // Force device completely idle and clean up resources
17842 vkDeviceWaitIdle(m_device->device());
17843 vkDestroyCommandPool(m_device->device(), pool, nullptr);
17844 vkDestroySemaphore(m_device->device(), s, nullptr);
17845}
17846
17847// This is a positive test. No errors should be generated.
17848TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
17849
17850 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17851 "submitted on separate queues, the second having a fence, "
17852 "followed by a WaitForFences call.");
17853
17854 ASSERT_NO_FATAL_FAILURE(InitState());
17855 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17856 return;
17857
17858 m_errorMonitor->ExpectSuccess();
17859
17860 ASSERT_NO_FATAL_FAILURE(InitState());
17861 VkFence fence;
17862 VkFenceCreateInfo fence_create_info{};
17863 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17864 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17865
17866 VkSemaphore semaphore;
17867 VkSemaphoreCreateInfo semaphore_create_info{};
17868 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17869 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17870
17871 VkCommandPool command_pool;
17872 VkCommandPoolCreateInfo pool_create_info{};
17873 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17874 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17875 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17876 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17877
17878 VkCommandBuffer command_buffer[2];
17879 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17880 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17881 command_buffer_allocate_info.commandPool = command_pool;
17882 command_buffer_allocate_info.commandBufferCount = 2;
17883 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17884 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17885
17886 VkQueue queue = VK_NULL_HANDLE;
17887 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17888
17889 {
17890 VkCommandBufferBeginInfo begin_info{};
17891 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17892 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17893
17894 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17895 nullptr, 0, nullptr, 0, nullptr);
17896
17897 VkViewport viewport{};
17898 viewport.maxDepth = 1.0f;
17899 viewport.minDepth = 0.0f;
17900 viewport.width = 512;
17901 viewport.height = 512;
17902 viewport.x = 0;
17903 viewport.y = 0;
17904 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17905 vkEndCommandBuffer(command_buffer[0]);
17906 }
17907 {
17908 VkCommandBufferBeginInfo begin_info{};
17909 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17910 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17911
17912 VkViewport viewport{};
17913 viewport.maxDepth = 1.0f;
17914 viewport.minDepth = 0.0f;
17915 viewport.width = 512;
17916 viewport.height = 512;
17917 viewport.x = 0;
17918 viewport.y = 0;
17919 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17920 vkEndCommandBuffer(command_buffer[1]);
17921 }
17922 {
17923 VkSubmitInfo submit_info{};
17924 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17925 submit_info.commandBufferCount = 1;
17926 submit_info.pCommandBuffers = &command_buffer[0];
17927 submit_info.signalSemaphoreCount = 1;
17928 submit_info.pSignalSemaphores = &semaphore;
17929 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17930 }
17931 {
17932 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17933 VkSubmitInfo submit_info{};
17934 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17935 submit_info.commandBufferCount = 1;
17936 submit_info.pCommandBuffers = &command_buffer[1];
17937 submit_info.waitSemaphoreCount = 1;
17938 submit_info.pWaitSemaphores = &semaphore;
17939 submit_info.pWaitDstStageMask = flags;
17940 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17941 }
17942
17943 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17944
17945 vkDestroyFence(m_device->device(), fence, nullptr);
17946 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17947 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17948 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17949
17950 m_errorMonitor->VerifyNotFound();
17951}
17952
17953// This is a positive test. No errors should be generated.
17954TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
17955
17956 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17957 "on the same queue, sharing a signal/wait semaphore, the "
17958 "second having a fence, "
17959 "followed by a WaitForFences call.");
17960
17961 m_errorMonitor->ExpectSuccess();
17962
17963 ASSERT_NO_FATAL_FAILURE(InitState());
17964 VkFence fence;
17965 VkFenceCreateInfo fence_create_info{};
17966 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17967 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17968
17969 VkSemaphore semaphore;
17970 VkSemaphoreCreateInfo semaphore_create_info{};
17971 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17972 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17973
17974 VkCommandPool command_pool;
17975 VkCommandPoolCreateInfo pool_create_info{};
17976 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17977 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17978 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17979 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17980
17981 VkCommandBuffer command_buffer[2];
17982 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17983 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17984 command_buffer_allocate_info.commandPool = command_pool;
17985 command_buffer_allocate_info.commandBufferCount = 2;
17986 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17987 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17988
17989 {
17990 VkCommandBufferBeginInfo begin_info{};
17991 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17992 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17993
17994 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17995 nullptr, 0, nullptr, 0, nullptr);
17996
17997 VkViewport viewport{};
17998 viewport.maxDepth = 1.0f;
17999 viewport.minDepth = 0.0f;
18000 viewport.width = 512;
18001 viewport.height = 512;
18002 viewport.x = 0;
18003 viewport.y = 0;
18004 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18005 vkEndCommandBuffer(command_buffer[0]);
18006 }
18007 {
18008 VkCommandBufferBeginInfo begin_info{};
18009 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18010 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18011
18012 VkViewport viewport{};
18013 viewport.maxDepth = 1.0f;
18014 viewport.minDepth = 0.0f;
18015 viewport.width = 512;
18016 viewport.height = 512;
18017 viewport.x = 0;
18018 viewport.y = 0;
18019 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18020 vkEndCommandBuffer(command_buffer[1]);
18021 }
18022 {
18023 VkSubmitInfo submit_info{};
18024 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18025 submit_info.commandBufferCount = 1;
18026 submit_info.pCommandBuffers = &command_buffer[0];
18027 submit_info.signalSemaphoreCount = 1;
18028 submit_info.pSignalSemaphores = &semaphore;
18029 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18030 }
18031 {
18032 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18033 VkSubmitInfo submit_info{};
18034 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18035 submit_info.commandBufferCount = 1;
18036 submit_info.pCommandBuffers = &command_buffer[1];
18037 submit_info.waitSemaphoreCount = 1;
18038 submit_info.pWaitSemaphores = &semaphore;
18039 submit_info.pWaitDstStageMask = flags;
18040 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18041 }
18042
18043 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18044
18045 vkDestroyFence(m_device->device(), fence, nullptr);
18046 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18047 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18048 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18049
18050 m_errorMonitor->VerifyNotFound();
18051}
18052
18053// This is a positive test. No errors should be generated.
18054TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18055
18056 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18057 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18058 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18059
18060 m_errorMonitor->ExpectSuccess();
18061
18062 ASSERT_NO_FATAL_FAILURE(InitState());
18063 VkFence fence;
18064 VkFenceCreateInfo fence_create_info{};
18065 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18066 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18067
18068 VkCommandPool command_pool;
18069 VkCommandPoolCreateInfo pool_create_info{};
18070 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18071 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18072 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18073 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18074
18075 VkCommandBuffer command_buffer[2];
18076 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18077 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18078 command_buffer_allocate_info.commandPool = command_pool;
18079 command_buffer_allocate_info.commandBufferCount = 2;
18080 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18081 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18082
18083 {
18084 VkCommandBufferBeginInfo begin_info{};
18085 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18086 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18087
18088 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18089 nullptr, 0, nullptr, 0, nullptr);
18090
18091 VkViewport viewport{};
18092 viewport.maxDepth = 1.0f;
18093 viewport.minDepth = 0.0f;
18094 viewport.width = 512;
18095 viewport.height = 512;
18096 viewport.x = 0;
18097 viewport.y = 0;
18098 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18099 vkEndCommandBuffer(command_buffer[0]);
18100 }
18101 {
18102 VkCommandBufferBeginInfo begin_info{};
18103 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18104 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18105
18106 VkViewport viewport{};
18107 viewport.maxDepth = 1.0f;
18108 viewport.minDepth = 0.0f;
18109 viewport.width = 512;
18110 viewport.height = 512;
18111 viewport.x = 0;
18112 viewport.y = 0;
18113 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18114 vkEndCommandBuffer(command_buffer[1]);
18115 }
18116 {
18117 VkSubmitInfo submit_info{};
18118 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18119 submit_info.commandBufferCount = 1;
18120 submit_info.pCommandBuffers = &command_buffer[0];
18121 submit_info.signalSemaphoreCount = 0;
18122 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18123 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18124 }
18125 {
18126 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18127 VkSubmitInfo submit_info{};
18128 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18129 submit_info.commandBufferCount = 1;
18130 submit_info.pCommandBuffers = &command_buffer[1];
18131 submit_info.waitSemaphoreCount = 0;
18132 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18133 submit_info.pWaitDstStageMask = flags;
18134 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18135 }
18136
18137 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18138
18139 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18140 ASSERT_VK_SUCCESS(err);
18141
18142 vkDestroyFence(m_device->device(), fence, nullptr);
18143 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18144 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18145
18146 m_errorMonitor->VerifyNotFound();
18147}
18148
18149// This is a positive test. No errors should be generated.
18150TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18151
18152 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18153 "on the same queue, the second having a fence, followed "
18154 "by a WaitForFences call.");
18155
18156 m_errorMonitor->ExpectSuccess();
18157
18158 ASSERT_NO_FATAL_FAILURE(InitState());
18159 VkFence fence;
18160 VkFenceCreateInfo fence_create_info{};
18161 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18162 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18163
18164 VkCommandPool command_pool;
18165 VkCommandPoolCreateInfo pool_create_info{};
18166 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18167 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18168 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18169 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18170
18171 VkCommandBuffer command_buffer[2];
18172 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18173 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18174 command_buffer_allocate_info.commandPool = command_pool;
18175 command_buffer_allocate_info.commandBufferCount = 2;
18176 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18177 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18178
18179 {
18180 VkCommandBufferBeginInfo begin_info{};
18181 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18182 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18183
18184 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18185 nullptr, 0, nullptr, 0, nullptr);
18186
18187 VkViewport viewport{};
18188 viewport.maxDepth = 1.0f;
18189 viewport.minDepth = 0.0f;
18190 viewport.width = 512;
18191 viewport.height = 512;
18192 viewport.x = 0;
18193 viewport.y = 0;
18194 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18195 vkEndCommandBuffer(command_buffer[0]);
18196 }
18197 {
18198 VkCommandBufferBeginInfo begin_info{};
18199 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18200 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18201
18202 VkViewport viewport{};
18203 viewport.maxDepth = 1.0f;
18204 viewport.minDepth = 0.0f;
18205 viewport.width = 512;
18206 viewport.height = 512;
18207 viewport.x = 0;
18208 viewport.y = 0;
18209 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18210 vkEndCommandBuffer(command_buffer[1]);
18211 }
18212 {
18213 VkSubmitInfo submit_info{};
18214 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18215 submit_info.commandBufferCount = 1;
18216 submit_info.pCommandBuffers = &command_buffer[0];
18217 submit_info.signalSemaphoreCount = 0;
18218 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18219 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18220 }
18221 {
18222 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18223 VkSubmitInfo submit_info{};
18224 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18225 submit_info.commandBufferCount = 1;
18226 submit_info.pCommandBuffers = &command_buffer[1];
18227 submit_info.waitSemaphoreCount = 0;
18228 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18229 submit_info.pWaitDstStageMask = flags;
18230 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18231 }
18232
18233 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18234
18235 vkDestroyFence(m_device->device(), fence, nullptr);
18236 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18237 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18238
18239 m_errorMonitor->VerifyNotFound();
18240}
18241
18242// This is a positive test. No errors should be generated.
18243TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18244
18245 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18246 "QueueSubmit call followed by a WaitForFences call.");
18247 ASSERT_NO_FATAL_FAILURE(InitState());
18248
18249 m_errorMonitor->ExpectSuccess();
18250
18251 VkFence fence;
18252 VkFenceCreateInfo fence_create_info{};
18253 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18254 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18255
18256 VkSemaphore semaphore;
18257 VkSemaphoreCreateInfo semaphore_create_info{};
18258 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18259 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18260
18261 VkCommandPool command_pool;
18262 VkCommandPoolCreateInfo pool_create_info{};
18263 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18264 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18265 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18266 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18267
18268 VkCommandBuffer command_buffer[2];
18269 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18270 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18271 command_buffer_allocate_info.commandPool = command_pool;
18272 command_buffer_allocate_info.commandBufferCount = 2;
18273 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18274 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18275
18276 {
18277 VkCommandBufferBeginInfo begin_info{};
18278 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18279 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18280
18281 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18282 nullptr, 0, nullptr, 0, nullptr);
18283
18284 VkViewport viewport{};
18285 viewport.maxDepth = 1.0f;
18286 viewport.minDepth = 0.0f;
18287 viewport.width = 512;
18288 viewport.height = 512;
18289 viewport.x = 0;
18290 viewport.y = 0;
18291 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18292 vkEndCommandBuffer(command_buffer[0]);
18293 }
18294 {
18295 VkCommandBufferBeginInfo begin_info{};
18296 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18297 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18298
18299 VkViewport viewport{};
18300 viewport.maxDepth = 1.0f;
18301 viewport.minDepth = 0.0f;
18302 viewport.width = 512;
18303 viewport.height = 512;
18304 viewport.x = 0;
18305 viewport.y = 0;
18306 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18307 vkEndCommandBuffer(command_buffer[1]);
18308 }
18309 {
18310 VkSubmitInfo submit_info[2];
18311 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18312
18313 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18314 submit_info[0].pNext = NULL;
18315 submit_info[0].commandBufferCount = 1;
18316 submit_info[0].pCommandBuffers = &command_buffer[0];
18317 submit_info[0].signalSemaphoreCount = 1;
18318 submit_info[0].pSignalSemaphores = &semaphore;
18319 submit_info[0].waitSemaphoreCount = 0;
18320 submit_info[0].pWaitSemaphores = NULL;
18321 submit_info[0].pWaitDstStageMask = 0;
18322
18323 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18324 submit_info[1].pNext = NULL;
18325 submit_info[1].commandBufferCount = 1;
18326 submit_info[1].pCommandBuffers = &command_buffer[1];
18327 submit_info[1].waitSemaphoreCount = 1;
18328 submit_info[1].pWaitSemaphores = &semaphore;
18329 submit_info[1].pWaitDstStageMask = flags;
18330 submit_info[1].signalSemaphoreCount = 0;
18331 submit_info[1].pSignalSemaphores = NULL;
18332 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18333 }
18334
18335 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18336
18337 vkDestroyFence(m_device->device(), fence, nullptr);
18338 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18339 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18340 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18341
18342 m_errorMonitor->VerifyNotFound();
18343}
18344
18345TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18346 m_errorMonitor->ExpectSuccess();
18347
18348 ASSERT_NO_FATAL_FAILURE(InitState());
18349 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18350
18351 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18352 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18353
18354 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18355 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18356 m_errorMonitor->VerifyNotFound();
18357 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18358 m_errorMonitor->VerifyNotFound();
18359 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18360 m_errorMonitor->VerifyNotFound();
18361
18362 m_commandBuffer->EndCommandBuffer();
18363 m_errorMonitor->VerifyNotFound();
18364}
18365
18366TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18367 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18368 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18369 "has a valid layout, and a second subpass then uses a "
18370 "valid *READ_ONLY* layout.");
18371 m_errorMonitor->ExpectSuccess();
18372 ASSERT_NO_FATAL_FAILURE(InitState());
18373
18374 VkAttachmentReference attach[2] = {};
18375 attach[0].attachment = 0;
18376 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18377 attach[1].attachment = 0;
18378 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18379 VkSubpassDescription subpasses[2] = {};
18380 // First subpass clears DS attach on load
18381 subpasses[0].pDepthStencilAttachment = &attach[0];
18382 // 2nd subpass reads in DS as input attachment
18383 subpasses[1].inputAttachmentCount = 1;
18384 subpasses[1].pInputAttachments = &attach[1];
18385 VkAttachmentDescription attach_desc = {};
18386 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18387 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18388 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18389 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18390 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18391 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18392 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18393 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18394 VkRenderPassCreateInfo rpci = {};
18395 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18396 rpci.attachmentCount = 1;
18397 rpci.pAttachments = &attach_desc;
18398 rpci.subpassCount = 2;
18399 rpci.pSubpasses = subpasses;
18400
18401 // Now create RenderPass and verify no errors
18402 VkRenderPass rp;
18403 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18404 m_errorMonitor->VerifyNotFound();
18405
18406 vkDestroyRenderPass(m_device->device(), rp, NULL);
18407}
18408
18409TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18410 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18411 "as vertex attributes");
18412 m_errorMonitor->ExpectSuccess();
18413
18414 ASSERT_NO_FATAL_FAILURE(InitState());
18415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18416
18417 VkVertexInputBindingDescription input_binding;
18418 memset(&input_binding, 0, sizeof(input_binding));
18419
18420 VkVertexInputAttributeDescription input_attribs[2];
18421 memset(input_attribs, 0, sizeof(input_attribs));
18422
18423 for (int i = 0; i < 2; i++) {
18424 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18425 input_attribs[i].location = i;
18426 }
18427
18428 char const *vsSource = "#version 450\n"
18429 "\n"
18430 "layout(location=0) in mat2x4 x;\n"
18431 "out gl_PerVertex {\n"
18432 " vec4 gl_Position;\n"
18433 "};\n"
18434 "void main(){\n"
18435 " gl_Position = x[0] + x[1];\n"
18436 "}\n";
18437 char const *fsSource = "#version 450\n"
18438 "\n"
18439 "layout(location=0) out vec4 color;\n"
18440 "void main(){\n"
18441 " color = vec4(1);\n"
18442 "}\n";
18443
18444 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18445 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18446
18447 VkPipelineObj pipe(m_device);
18448 pipe.AddColorAttachment();
18449 pipe.AddShader(&vs);
18450 pipe.AddShader(&fs);
18451
18452 pipe.AddVertexInputBindings(&input_binding, 1);
18453 pipe.AddVertexInputAttribs(input_attribs, 2);
18454
18455 VkDescriptorSetObj descriptorSet(m_device);
18456 descriptorSet.AppendDummy();
18457 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18458
18459 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18460
18461 /* expect success */
18462 m_errorMonitor->VerifyNotFound();
18463}
18464
18465TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18466 m_errorMonitor->ExpectSuccess();
18467
18468 ASSERT_NO_FATAL_FAILURE(InitState());
18469 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18470
18471 VkVertexInputBindingDescription input_binding;
18472 memset(&input_binding, 0, sizeof(input_binding));
18473
18474 VkVertexInputAttributeDescription input_attribs[2];
18475 memset(input_attribs, 0, sizeof(input_attribs));
18476
18477 for (int i = 0; i < 2; i++) {
18478 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18479 input_attribs[i].location = i;
18480 }
18481
18482 char const *vsSource = "#version 450\n"
18483 "\n"
18484 "layout(location=0) in vec4 x[2];\n"
18485 "out gl_PerVertex {\n"
18486 " vec4 gl_Position;\n"
18487 "};\n"
18488 "void main(){\n"
18489 " gl_Position = x[0] + x[1];\n"
18490 "}\n";
18491 char const *fsSource = "#version 450\n"
18492 "\n"
18493 "layout(location=0) out vec4 color;\n"
18494 "void main(){\n"
18495 " color = vec4(1);\n"
18496 "}\n";
18497
18498 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18499 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18500
18501 VkPipelineObj pipe(m_device);
18502 pipe.AddColorAttachment();
18503 pipe.AddShader(&vs);
18504 pipe.AddShader(&fs);
18505
18506 pipe.AddVertexInputBindings(&input_binding, 1);
18507 pipe.AddVertexInputAttribs(input_attribs, 2);
18508
18509 VkDescriptorSetObj descriptorSet(m_device);
18510 descriptorSet.AppendDummy();
18511 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18512
18513 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18514
18515 m_errorMonitor->VerifyNotFound();
18516}
18517
18518TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18519 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18520 "through multiple vertex shader inputs, each consuming a different "
18521 "subset of the components.");
18522 m_errorMonitor->ExpectSuccess();
18523
18524 ASSERT_NO_FATAL_FAILURE(InitState());
18525 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18526
18527 VkVertexInputBindingDescription input_binding;
18528 memset(&input_binding, 0, sizeof(input_binding));
18529
18530 VkVertexInputAttributeDescription input_attribs[3];
18531 memset(input_attribs, 0, sizeof(input_attribs));
18532
18533 for (int i = 0; i < 3; i++) {
18534 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18535 input_attribs[i].location = i;
18536 }
18537
18538 char const *vsSource = "#version 450\n"
18539 "\n"
18540 "layout(location=0) in vec4 x;\n"
18541 "layout(location=1) in vec3 y1;\n"
18542 "layout(location=1, component=3) in float y2;\n"
18543 "layout(location=2) in vec4 z;\n"
18544 "out gl_PerVertex {\n"
18545 " vec4 gl_Position;\n"
18546 "};\n"
18547 "void main(){\n"
18548 " gl_Position = x + vec4(y1, y2) + z;\n"
18549 "}\n";
18550 char const *fsSource = "#version 450\n"
18551 "\n"
18552 "layout(location=0) out vec4 color;\n"
18553 "void main(){\n"
18554 " color = vec4(1);\n"
18555 "}\n";
18556
18557 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18558 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18559
18560 VkPipelineObj pipe(m_device);
18561 pipe.AddColorAttachment();
18562 pipe.AddShader(&vs);
18563 pipe.AddShader(&fs);
18564
18565 pipe.AddVertexInputBindings(&input_binding, 1);
18566 pipe.AddVertexInputAttribs(input_attribs, 3);
18567
18568 VkDescriptorSetObj descriptorSet(m_device);
18569 descriptorSet.AppendDummy();
18570 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18571
18572 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18573
18574 m_errorMonitor->VerifyNotFound();
18575}
18576
18577TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
18578 m_errorMonitor->ExpectSuccess();
18579
18580 ASSERT_NO_FATAL_FAILURE(InitState());
18581 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18582
18583 char const *vsSource = "#version 450\n"
18584 "out gl_PerVertex {\n"
18585 " vec4 gl_Position;\n"
18586 "};\n"
18587 "void main(){\n"
18588 " gl_Position = vec4(0);\n"
18589 "}\n";
18590 char const *fsSource = "#version 450\n"
18591 "\n"
18592 "layout(location=0) out vec4 color;\n"
18593 "void main(){\n"
18594 " color = vec4(1);\n"
18595 "}\n";
18596
18597 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18598 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18599
18600 VkPipelineObj pipe(m_device);
18601 pipe.AddColorAttachment();
18602 pipe.AddShader(&vs);
18603 pipe.AddShader(&fs);
18604
18605 VkDescriptorSetObj descriptorSet(m_device);
18606 descriptorSet.AppendDummy();
18607 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18608
18609 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18610
18611 m_errorMonitor->VerifyNotFound();
18612}
18613
18614TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
18615 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
18616 "set out in 14.1.3: fundamental type must match, and producer side must "
18617 "have at least as many components");
18618 m_errorMonitor->ExpectSuccess();
18619
18620 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
18621
18622 ASSERT_NO_FATAL_FAILURE(InitState());
18623 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18624
18625 char const *vsSource = "#version 450\n"
18626 "out gl_PerVertex {\n"
18627 " vec4 gl_Position;\n"
18628 "};\n"
18629 "layout(location=0) out vec3 x;\n"
18630 "layout(location=1) out ivec3 y;\n"
18631 "layout(location=2) out vec3 z;\n"
18632 "void main(){\n"
18633 " gl_Position = vec4(0);\n"
18634 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
18635 "}\n";
18636 char const *fsSource = "#version 450\n"
18637 "\n"
18638 "layout(location=0) out vec4 color;\n"
18639 "layout(location=0) in float x;\n"
18640 "layout(location=1) flat in int y;\n"
18641 "layout(location=2) in vec2 z;\n"
18642 "void main(){\n"
18643 " color = vec4(1 + x + y + z.x);\n"
18644 "}\n";
18645
18646 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18647 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18648
18649 VkPipelineObj pipe(m_device);
18650 pipe.AddColorAttachment();
18651 pipe.AddShader(&vs);
18652 pipe.AddShader(&fs);
18653
18654 VkDescriptorSetObj descriptorSet(m_device);
18655 descriptorSet.AppendDummy();
18656 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18657
18658 VkResult err = VK_SUCCESS;
18659 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18660 ASSERT_VK_SUCCESS(err);
18661
18662 m_errorMonitor->VerifyNotFound();
18663}
18664
18665TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
18666 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
18667 "passed between the TCS and TES stages");
18668 m_errorMonitor->ExpectSuccess();
18669
18670 ASSERT_NO_FATAL_FAILURE(InitState());
18671 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18672
18673 if (!m_device->phy().features().tessellationShader) {
18674 printf("Device does not support tessellation shaders; skipped.\n");
18675 return;
18676 }
18677
18678 char const *vsSource = "#version 450\n"
18679 "void main(){}\n";
18680 char const *tcsSource = "#version 450\n"
18681 "layout(location=0) out int x[];\n"
18682 "layout(vertices=3) out;\n"
18683 "void main(){\n"
18684 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
18685 " gl_TessLevelInner[0] = 1;\n"
18686 " x[gl_InvocationID] = gl_InvocationID;\n"
18687 "}\n";
18688 char const *tesSource = "#version 450\n"
18689 "layout(triangles, equal_spacing, cw) in;\n"
18690 "layout(location=0) in int x[];\n"
18691 "out gl_PerVertex { vec4 gl_Position; };\n"
18692 "void main(){\n"
18693 " gl_Position.xyz = gl_TessCoord;\n"
18694 " gl_Position.w = x[0] + x[1] + x[2];\n"
18695 "}\n";
18696 char const *fsSource = "#version 450\n"
18697 "layout(location=0) out vec4 color;\n"
18698 "void main(){\n"
18699 " color = vec4(1);\n"
18700 "}\n";
18701
18702 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18703 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
18704 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
18705 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18706
18707 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
18708 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
18709
18710 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
18711
18712 VkPipelineObj pipe(m_device);
18713 pipe.SetInputAssembly(&iasci);
18714 pipe.SetTessellation(&tsci);
18715 pipe.AddColorAttachment();
18716 pipe.AddShader(&vs);
18717 pipe.AddShader(&tcs);
18718 pipe.AddShader(&tes);
18719 pipe.AddShader(&fs);
18720
18721 VkDescriptorSetObj descriptorSet(m_device);
18722 descriptorSet.AppendDummy();
18723 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18724
18725 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18726
18727 m_errorMonitor->VerifyNotFound();
18728}
18729
18730TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
18731 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
18732 "interface block passed into the geometry shader. This "
18733 "is interesting because the 'extra' array level is not "
18734 "present on the member type, but on the block instance.");
18735 m_errorMonitor->ExpectSuccess();
18736
18737 ASSERT_NO_FATAL_FAILURE(InitState());
18738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18739
18740 if (!m_device->phy().features().geometryShader) {
18741 printf("Device does not support geometry shaders; skipped.\n");
18742 return;
18743 }
18744
18745 char const *vsSource = "#version 450\n"
18746 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
18747 "void main(){\n"
18748 " vs_out.x = vec4(1);\n"
18749 "}\n";
18750 char const *gsSource = "#version 450\n"
18751 "layout(triangles) in;\n"
18752 "layout(triangle_strip, max_vertices=3) out;\n"
18753 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
18754 "out gl_PerVertex { vec4 gl_Position; };\n"
18755 "void main() {\n"
18756 " gl_Position = gs_in[0].x;\n"
18757 " EmitVertex();\n"
18758 "}\n";
18759 char const *fsSource = "#version 450\n"
18760 "layout(location=0) out vec4 color;\n"
18761 "void main(){\n"
18762 " color = vec4(1);\n"
18763 "}\n";
18764
18765 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18766 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
18767 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18768
18769 VkPipelineObj pipe(m_device);
18770 pipe.AddColorAttachment();
18771 pipe.AddShader(&vs);
18772 pipe.AddShader(&gs);
18773 pipe.AddShader(&fs);
18774
18775 VkDescriptorSetObj descriptorSet(m_device);
18776 descriptorSet.AppendDummy();
18777 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18778
18779 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18780
18781 m_errorMonitor->VerifyNotFound();
18782}
18783
18784TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
18785 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
18786 "attributes. This is interesting because they consume multiple "
18787 "locations.");
18788 m_errorMonitor->ExpectSuccess();
18789
18790 ASSERT_NO_FATAL_FAILURE(InitState());
18791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18792
18793 if (!m_device->phy().features().shaderFloat64) {
18794 printf("Device does not support 64bit vertex attributes; skipped.\n");
18795 return;
18796 }
18797
18798 VkVertexInputBindingDescription input_bindings[1];
18799 memset(input_bindings, 0, sizeof(input_bindings));
18800
18801 VkVertexInputAttributeDescription input_attribs[4];
18802 memset(input_attribs, 0, sizeof(input_attribs));
18803 input_attribs[0].location = 0;
18804 input_attribs[0].offset = 0;
18805 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18806 input_attribs[1].location = 2;
18807 input_attribs[1].offset = 32;
18808 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18809 input_attribs[2].location = 4;
18810 input_attribs[2].offset = 64;
18811 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18812 input_attribs[3].location = 6;
18813 input_attribs[3].offset = 96;
18814 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18815
18816 char const *vsSource = "#version 450\n"
18817 "\n"
18818 "layout(location=0) in dmat4 x;\n"
18819 "out gl_PerVertex {\n"
18820 " vec4 gl_Position;\n"
18821 "};\n"
18822 "void main(){\n"
18823 " gl_Position = vec4(x[0][0]);\n"
18824 "}\n";
18825 char const *fsSource = "#version 450\n"
18826 "\n"
18827 "layout(location=0) out vec4 color;\n"
18828 "void main(){\n"
18829 " color = vec4(1);\n"
18830 "}\n";
18831
18832 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18833 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18834
18835 VkPipelineObj pipe(m_device);
18836 pipe.AddColorAttachment();
18837 pipe.AddShader(&vs);
18838 pipe.AddShader(&fs);
18839
18840 pipe.AddVertexInputBindings(input_bindings, 1);
18841 pipe.AddVertexInputAttribs(input_attribs, 4);
18842
18843 VkDescriptorSetObj descriptorSet(m_device);
18844 descriptorSet.AppendDummy();
18845 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18846
18847 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18848
18849 m_errorMonitor->VerifyNotFound();
18850}
18851
18852TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
18853 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
18854 m_errorMonitor->ExpectSuccess();
18855
18856 ASSERT_NO_FATAL_FAILURE(InitState());
18857
18858 char const *vsSource = "#version 450\n"
18859 "\n"
18860 "out gl_PerVertex {\n"
18861 " vec4 gl_Position;\n"
18862 "};\n"
18863 "void main(){\n"
18864 " gl_Position = vec4(1);\n"
18865 "}\n";
18866 char const *fsSource = "#version 450\n"
18867 "\n"
18868 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
18869 "layout(location=0) out vec4 color;\n"
18870 "void main() {\n"
18871 " color = subpassLoad(x);\n"
18872 "}\n";
18873
18874 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18875 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18876
18877 VkPipelineObj pipe(m_device);
18878 pipe.AddShader(&vs);
18879 pipe.AddShader(&fs);
18880 pipe.AddColorAttachment();
18881 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18882
18883 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
18884 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
18885 VkDescriptorSetLayout dsl;
18886 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18887 ASSERT_VK_SUCCESS(err);
18888
18889 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18890 VkPipelineLayout pl;
18891 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18892 ASSERT_VK_SUCCESS(err);
18893
18894 VkAttachmentDescription descs[2] = {
18895 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18896 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18897 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
18898 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18899 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
18900 };
18901 VkAttachmentReference color = {
18902 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18903 };
18904 VkAttachmentReference input = {
18905 1, VK_IMAGE_LAYOUT_GENERAL,
18906 };
18907
18908 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
18909
18910 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
18911 VkRenderPass rp;
18912 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18913 ASSERT_VK_SUCCESS(err);
18914
18915 // should be OK. would go wrong here if it's going to...
18916 pipe.CreateVKPipeline(pl, rp);
18917
18918 m_errorMonitor->VerifyNotFound();
18919
18920 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18921 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18922 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18923}
18924
18925TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
18926 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
18927 "descriptor-backed resource which is not provided, but the shader does not "
18928 "statically use it. This is interesting because it requires compute pipelines "
18929 "to have a proper descriptor use walk, which they didn't for some time.");
18930 m_errorMonitor->ExpectSuccess();
18931
18932 ASSERT_NO_FATAL_FAILURE(InitState());
18933
18934 char const *csSource = "#version 450\n"
18935 "\n"
18936 "layout(local_size_x=1) in;\n"
18937 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
18938 "void main(){\n"
18939 " // x is not used.\n"
18940 "}\n";
18941
18942 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18943
18944 VkDescriptorSetObj descriptorSet(m_device);
18945 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18946
18947 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18948 nullptr,
18949 0,
18950 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18951 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18952 descriptorSet.GetPipelineLayout(),
18953 VK_NULL_HANDLE,
18954 -1 };
18955
18956 VkPipeline pipe;
18957 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18958
18959 m_errorMonitor->VerifyNotFound();
18960
18961 if (err == VK_SUCCESS) {
18962 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18963 }
18964}
18965
18966TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
18967 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
18968 "sampler portion of a combined image + sampler");
18969 m_errorMonitor->ExpectSuccess();
18970
18971 ASSERT_NO_FATAL_FAILURE(InitState());
18972
18973 VkDescriptorSetLayoutBinding bindings[] = {
18974 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18975 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18976 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18977 };
18978 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
18979 VkDescriptorSetLayout dsl;
18980 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18981 ASSERT_VK_SUCCESS(err);
18982
18983 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18984 VkPipelineLayout pl;
18985 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18986 ASSERT_VK_SUCCESS(err);
18987
18988 char const *csSource = "#version 450\n"
18989 "\n"
18990 "layout(local_size_x=1) in;\n"
18991 "layout(set=0, binding=0) uniform sampler s;\n"
18992 "layout(set=0, binding=1) uniform texture2D t;\n"
18993 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
18994 "void main() {\n"
18995 " x = texture(sampler2D(t, s), vec2(0));\n"
18996 "}\n";
18997 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18998
18999 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19000 nullptr,
19001 0,
19002 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19003 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19004 pl,
19005 VK_NULL_HANDLE,
19006 -1 };
19007
19008 VkPipeline pipe;
19009 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19010
19011 m_errorMonitor->VerifyNotFound();
19012
19013 if (err == VK_SUCCESS) {
19014 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19015 }
19016
19017 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19018 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19019}
19020
19021TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19022 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19023 "image portion of a combined image + sampler");
19024 m_errorMonitor->ExpectSuccess();
19025
19026 ASSERT_NO_FATAL_FAILURE(InitState());
19027
19028 VkDescriptorSetLayoutBinding bindings[] = {
19029 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19030 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19031 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19032 };
19033 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19034 VkDescriptorSetLayout dsl;
19035 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19036 ASSERT_VK_SUCCESS(err);
19037
19038 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19039 VkPipelineLayout pl;
19040 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19041 ASSERT_VK_SUCCESS(err);
19042
19043 char const *csSource = "#version 450\n"
19044 "\n"
19045 "layout(local_size_x=1) in;\n"
19046 "layout(set=0, binding=0) uniform texture2D t;\n"
19047 "layout(set=0, binding=1) uniform sampler s;\n"
19048 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19049 "void main() {\n"
19050 " x = texture(sampler2D(t, s), vec2(0));\n"
19051 "}\n";
19052 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19053
19054 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19055 nullptr,
19056 0,
19057 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19058 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19059 pl,
19060 VK_NULL_HANDLE,
19061 -1 };
19062
19063 VkPipeline pipe;
19064 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19065
19066 m_errorMonitor->VerifyNotFound();
19067
19068 if (err == VK_SUCCESS) {
19069 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19070 }
19071
19072 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19073 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19074}
19075
19076TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19077 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19078 "both the sampler and the image of a combined image+sampler "
19079 "but via separate variables");
19080 m_errorMonitor->ExpectSuccess();
19081
19082 ASSERT_NO_FATAL_FAILURE(InitState());
19083
19084 VkDescriptorSetLayoutBinding bindings[] = {
19085 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19086 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19087 };
19088 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19089 VkDescriptorSetLayout dsl;
19090 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19091 ASSERT_VK_SUCCESS(err);
19092
19093 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19094 VkPipelineLayout pl;
19095 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19096 ASSERT_VK_SUCCESS(err);
19097
19098 char const *csSource = "#version 450\n"
19099 "\n"
19100 "layout(local_size_x=1) in;\n"
19101 "layout(set=0, binding=0) uniform texture2D t;\n"
19102 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19103 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19104 "void main() {\n"
19105 " x = texture(sampler2D(t, s), vec2(0));\n"
19106 "}\n";
19107 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19108
19109 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19110 nullptr,
19111 0,
19112 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19113 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19114 pl,
19115 VK_NULL_HANDLE,
19116 -1 };
19117
19118 VkPipeline pipe;
19119 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19120
19121 m_errorMonitor->VerifyNotFound();
19122
19123 if (err == VK_SUCCESS) {
19124 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19125 }
19126
19127 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19128 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19129}
19130
19131TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19132 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19133
19134 ASSERT_NO_FATAL_FAILURE(InitState());
19135
19136 // Positive test to check parameter_validation and unique_objects support
19137 // for NV_dedicated_allocation
19138 uint32_t extension_count = 0;
19139 bool supports_nv_dedicated_allocation = false;
19140 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19141 ASSERT_VK_SUCCESS(err);
19142
19143 if (extension_count > 0) {
19144 std::vector<VkExtensionProperties> available_extensions(extension_count);
19145
19146 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19147 ASSERT_VK_SUCCESS(err);
19148
19149 for (const auto &extension_props : available_extensions) {
19150 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19151 supports_nv_dedicated_allocation = true;
19152 }
19153 }
19154 }
19155
19156 if (supports_nv_dedicated_allocation) {
19157 m_errorMonitor->ExpectSuccess();
19158
19159 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19160 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19161 dedicated_buffer_create_info.pNext = nullptr;
19162 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19163
19164 uint32_t queue_family_index = 0;
19165 VkBufferCreateInfo buffer_create_info = {};
19166 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19167 buffer_create_info.pNext = &dedicated_buffer_create_info;
19168 buffer_create_info.size = 1024;
19169 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19170 buffer_create_info.queueFamilyIndexCount = 1;
19171 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19172
19173 VkBuffer buffer;
19174 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19175 ASSERT_VK_SUCCESS(err);
19176
19177 VkMemoryRequirements memory_reqs;
19178 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19179
19180 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19181 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19182 dedicated_memory_info.pNext = nullptr;
19183 dedicated_memory_info.buffer = buffer;
19184 dedicated_memory_info.image = VK_NULL_HANDLE;
19185
19186 VkMemoryAllocateInfo memory_info = {};
19187 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19188 memory_info.pNext = &dedicated_memory_info;
19189 memory_info.allocationSize = memory_reqs.size;
19190
19191 bool pass;
19192 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19193 ASSERT_TRUE(pass);
19194
19195 VkDeviceMemory buffer_memory;
19196 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19197 ASSERT_VK_SUCCESS(err);
19198
19199 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19200 ASSERT_VK_SUCCESS(err);
19201
19202 vkDestroyBuffer(m_device->device(), buffer, NULL);
19203 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19204
19205 m_errorMonitor->VerifyNotFound();
19206 }
19207}
19208
19209TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19210 VkResult err;
19211
19212 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19213
19214 ASSERT_NO_FATAL_FAILURE(InitState());
19215 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19216
19217 std::vector<const char *> device_extension_names;
19218 auto features = m_device->phy().features();
19219 // Artificially disable support for non-solid fill modes
19220 features.fillModeNonSolid = false;
19221 // The sacrificial device object
19222 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19223
19224 VkRenderpassObj render_pass(&test_device);
19225
19226 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19227 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19228 pipeline_layout_ci.setLayoutCount = 0;
19229 pipeline_layout_ci.pSetLayouts = NULL;
19230
19231 VkPipelineLayout pipeline_layout;
19232 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19233 ASSERT_VK_SUCCESS(err);
19234
19235 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19236 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19237 rs_ci.pNext = nullptr;
19238 rs_ci.lineWidth = 1.0f;
19239 rs_ci.rasterizerDiscardEnable = true;
19240
19241 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19242 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19243
19244 // Set polygonMode=FILL. No error is expected
19245 m_errorMonitor->ExpectSuccess();
19246 {
19247 VkPipelineObj pipe(&test_device);
19248 pipe.AddShader(&vs);
19249 pipe.AddShader(&fs);
19250 pipe.AddColorAttachment();
19251 // Set polygonMode to a good value
19252 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19253 pipe.SetRasterization(&rs_ci);
19254 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19255 }
19256 m_errorMonitor->VerifyNotFound();
19257
19258 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19259}
19260
19261TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19262 VkResult err;
19263 ASSERT_NO_FATAL_FAILURE(InitState());
19264 ASSERT_NO_FATAL_FAILURE(InitViewport());
19265 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19266
19267 VkPipelineLayout pipeline_layout;
19268 VkPushConstantRange pc_range = {};
19269 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19270 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19271 pipeline_layout_ci.pushConstantRangeCount = 1;
19272 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19273
19274 //
19275 // Check for invalid push constant ranges in pipeline layouts.
19276 //
19277 struct PipelineLayoutTestCase {
19278 VkPushConstantRange const range;
19279 char const *msg;
19280 };
19281
19282 // Check for overlapping ranges
19283 const uint32_t ranges_per_test = 5;
19284 struct OverlappingRangeTestCase {
19285 VkPushConstantRange const ranges[ranges_per_test];
19286 char const *msg;
19287 };
19288
19289 // Run some positive tests to make sure overlap checking in the layer is OK
19290 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19291 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19292 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19293 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19294 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19295 "" },
19296 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19297 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19298 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19299 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19300 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19301 "" } } };
19302 for (const auto &iter : overlapping_range_tests_pos) {
19303 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19304 m_errorMonitor->ExpectSuccess();
19305 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19306 m_errorMonitor->VerifyNotFound();
19307 if (VK_SUCCESS == err) {
19308 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19309 }
19310 }
19311
19312 //
19313 // CmdPushConstants tests
19314 //
19315 const uint8_t dummy_values[100] = {};
19316
19317 BeginCommandBuffer();
19318
19319 // positive overlapping range tests with cmd
19320 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19321 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19322 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19323 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19324 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19325 } };
19326
19327 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19328 const VkPushConstantRange pc_range4[] = {
19329 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19330 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19331 };
19332
19333 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19334 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19335 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19336 ASSERT_VK_SUCCESS(err);
19337 for (const auto &iter : cmd_overlap_tests_pos) {
19338 m_errorMonitor->ExpectSuccess();
19339 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19340 iter.range.size, dummy_values);
19341 m_errorMonitor->VerifyNotFound();
19342 }
19343 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19344
19345 EndCommandBuffer();
19346}
19347
19348
19349
19350
19351
19352
19353
19354#if 0 // A few devices have issues with this test so disabling for now
19355TEST_F(VkPositiveLayerTest, LongFenceChain)
19356{
19357 m_errorMonitor->ExpectSuccess();
19358
19359 ASSERT_NO_FATAL_FAILURE(InitState());
19360 VkResult err;
19361
19362 std::vector<VkFence> fences;
19363
19364 const int chainLength = 32768;
19365
19366 for (int i = 0; i < chainLength; i++) {
19367 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19368 VkFence fence;
19369 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19370 ASSERT_VK_SUCCESS(err);
19371
19372 fences.push_back(fence);
19373
19374 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19375 0, nullptr, 0, nullptr };
19376 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19377 ASSERT_VK_SUCCESS(err);
19378
19379 }
19380
19381 // BOOM, stack overflow.
19382 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19383
19384 for (auto fence : fences)
19385 vkDestroyFence(m_device->device(), fence, nullptr);
19386
19387 m_errorMonitor->VerifyNotFound();
19388}
19389#endif
19390
19391
Cody Northrop1242dfd2016-07-13 17:24:59 -060019392#if defined(ANDROID) && defined(VALIDATION_APK)
19393static bool initialized = false;
19394static bool active = false;
19395
19396// Convert Intents to argv
19397// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019398std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019399 std::vector<std::string> args;
19400 JavaVM &vm = *app.activity->vm;
19401 JNIEnv *p_env;
19402 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19403 return args;
19404
19405 JNIEnv &env = *p_env;
19406 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019407 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019408 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019409 jmethodID get_string_extra_method =
19410 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019411 jvalue get_string_extra_args;
19412 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019413 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019414
19415 std::string args_str;
19416 if (extra_str) {
19417 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19418 args_str = extra_utf;
19419 env.ReleaseStringUTFChars(extra_str, extra_utf);
19420 env.DeleteLocalRef(extra_str);
19421 }
19422
19423 env.DeleteLocalRef(get_string_extra_args.l);
19424 env.DeleteLocalRef(intent);
19425 vm.DetachCurrentThread();
19426
19427 // split args_str
19428 std::stringstream ss(args_str);
19429 std::string arg;
19430 while (std::getline(ss, arg, ' ')) {
19431 if (!arg.empty())
19432 args.push_back(arg);
19433 }
19434
19435 return args;
19436}
19437
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019438static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019439
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019440static void processCommand(struct android_app *app, int32_t cmd) {
19441 switch (cmd) {
19442 case APP_CMD_INIT_WINDOW: {
19443 if (app->window) {
19444 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019445 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019446 break;
19447 }
19448 case APP_CMD_GAINED_FOCUS: {
19449 active = true;
19450 break;
19451 }
19452 case APP_CMD_LOST_FOCUS: {
19453 active = false;
19454 break;
19455 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019456 }
19457}
19458
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019459void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019460 app_dummy();
19461
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019462 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019463
19464 int vulkanSupport = InitVulkan();
19465 if (vulkanSupport == 0) {
19466 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19467 return;
19468 }
19469
19470 app->onAppCmd = processCommand;
19471 app->onInputEvent = processInput;
19472
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019473 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019474 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019475 struct android_poll_source *source;
19476 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019477 if (source) {
19478 source->process(app, source);
19479 }
19480
19481 if (app->destroyRequested != 0) {
19482 VkTestFramework::Finish();
19483 return;
19484 }
19485 }
19486
19487 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019488 // Use the following key to send arguments to gtest, i.e.
19489 // --es args "--gtest_filter=-VkLayerTest.foo"
19490 const char key[] = "args";
19491 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019492
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019493 std::string filter = "";
19494 if (args.size() > 0) {
19495 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19496 filter += args[0];
19497 } else {
19498 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19499 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019500
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019501 int argc = 2;
19502 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19503 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019504
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019505 // Route output to files until we can override the gtest output
19506 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19507 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019508
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019509 ::testing::InitGoogleTest(&argc, argv);
19510 VkTestFramework::InitArgs(&argc, argv);
19511 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019512
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019513 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019514
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019515 if (result != 0) {
19516 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19517 } else {
19518 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19519 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019520
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019521 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019522
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019523 fclose(stdout);
19524 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019525
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019526 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019527
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019528 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019529 }
19530 }
19531}
19532#endif
19533
Tony Barbour300a6082015-04-07 13:44:53 -060019534int main(int argc, char **argv) {
19535 int result;
19536
Cody Northrop8e54a402016-03-08 22:25:52 -070019537#ifdef ANDROID
19538 int vulkanSupport = InitVulkan();
19539 if (vulkanSupport == 0)
19540 return 1;
19541#endif
19542
Tony Barbour300a6082015-04-07 13:44:53 -060019543 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060019544 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060019545
19546 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
19547
19548 result = RUN_ALL_TESTS();
19549
Tony Barbour6918cd52015-04-09 12:58:51 -060019550 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060019551 return result;
19552}