blob: 41e798b8694c2ba730ebf589bc2f94eb71fcb395 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060037#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060038#include "vkrenderframework.h"
39#include <limits.h>
40#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060041
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042#define GLM_FORCE_RADIANS
43#include "glm/glm.hpp"
44#include <glm/gtc/matrix_transform.hpp>
45
Dustin Gravesffa90fa2016-05-06 11:20:38 -060046#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060047#define MEM_TRACKER_TESTS 1
48#define OBJ_TRACKER_TESTS 1
49#define DRAW_STATE_TESTS 1
50#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120051#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060052#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060053#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060054
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055//--------------------------------------------------------------------------------------
56// Mesh and VertexFormat Data
57//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070058struct Vertex {
59 float posX, posY, posZ, posW; // Position data
60 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061};
62
Karl Schultz6addd812016-02-02 17:17:23 -070063#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050064
65typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070066 BsoFailNone = 0x00000000,
67 BsoFailLineWidth = 0x00000001,
68 BsoFailDepthBias = 0x00000002,
69 BsoFailViewport = 0x00000004,
70 BsoFailScissor = 0x00000008,
71 BsoFailBlend = 0x00000010,
72 BsoFailDepthBounds = 0x00000020,
73 BsoFailStencilReadMask = 0x00000040,
74 BsoFailStencilWriteMask = 0x00000080,
75 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060076 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060077 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050085};
86
Mark Lobodzinskice751c62016-09-08 10:45:35 -060087static const char bindStateVertShaderText[] = "#version 450\n"
88 "vec2 vertices[3];\n"
89 "out gl_PerVertex {\n"
90 " vec4 gl_Position;\n"
91 "};\n"
92 "void main() {\n"
93 " vertices[0] = vec2(-1.0, -1.0);\n"
94 " vertices[1] = vec2( 1.0, -1.0);\n"
95 " vertices[2] = vec2( 0.0, 1.0);\n"
96 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
97 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060099static const char bindStateFragShaderText[] = "#version 450\n"
100 "\n"
101 "layout(location = 0) out vec4 uFragColor;\n"
102 "void main(){\n"
103 " uFragColor = vec4(0,1,0,1);\n"
104 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500105
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600106static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
107 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
108 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600109
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600110// ErrorMonitor Usage:
111//
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600112// Call SetDesiredFailureMsg with: a string to be compared against all
113// encountered log messages, or a validation error enum identifying
114// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
115// will match all log messages. logMsg will return true for skipCall
116// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117//
118// Call DesiredMsgFound to determine if the desired failure message
119// was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600120class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700121 public:
122 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600123 test_platform_thread_create_mutex(&m_mutex);
124 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200125 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700126 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600127 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600128 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129
Dustin Graves48458142016-04-29 16:11:55 -0600130 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
131
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600132 // ErrorMonitor will look for an error message containing the specified string
Karl Schultz6addd812016-02-02 17:17:23 -0700133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600134 // Also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600136 m_failure_message_strings.clear();
137 // If we are looking for a matching string, ignore any IDs
138 m_desired_message_ids.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600139 m_otherMsgs.clear();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600140 m_desired_message_strings.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700141 m_msgFound = VK_FALSE;
142 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600143 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600144 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600145
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600146 // ErrorMonitor will look for a message ID matching the specified one
147 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
148 // Also discard all collected messages to this point
149 test_platform_thread_lock_mutex(&m_mutex);
150 m_failure_message_strings.clear();
151 // If we are looking for IDs don't look for strings
152 m_desired_message_strings.clear();
153 m_otherMsgs.clear();
154 m_desired_message_ids.insert(msg_id);
155 m_msgFound = VK_FALSE;
156 m_msgFlags = msgFlags;
157 test_platform_thread_unlock_mutex(&m_mutex);
158 }
159
160 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600162 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600163 if (m_bailout != NULL) {
164 *m_bailout = true;
165 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600167 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600168
169 for (auto desired_msg : m_desired_message_strings) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600170 if (desired_msg.length() == 0) {
171 // An empty desired_msg string "" indicates a positive test - not expecting an error.
172 // Return true to avoid calling layers/driver with this error.
173 // And don't erase the "" string, so it remains if another error is found.
174 result = VK_TRUE;
175 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600176 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600177 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600178 m_msgFound = VK_TRUE;
179 result = VK_TRUE;
180 // We only want one match for each expected error so remove from set here
181 // Since we're about the break the loop it's ok to remove from set we're iterating over
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600182 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600183 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186 for (auto desired_id : m_desired_message_ids) {
187 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
188 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
189 // Return true to avoid calling layers/driver with this error.
190 result = VK_TRUE;
191 } else if (desired_id == message_code) {
192 // Double-check that the string matches the error enum
193 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
194 found_expected = true;
195 result = VK_TRUE;
196 m_msgFound = VK_TRUE;
197 m_desired_message_ids.erase(desired_id);
198 break;
199 } else {
200 // Treat this message as a regular unexpected error, but print a warning jic
201 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
202 errorString.c_str(), desired_id, validation_error_map[desired_id]);
203 }
204 }
205 }
206
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600207 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200208 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600209 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600210 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600211 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600212 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600213 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600214
Karl Schultz6addd812016-02-02 17:17:23 -0700215 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600216
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600217 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
218
Karl Schultz6addd812016-02-02 17:17:23 -0700219 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600220
Karl Schultz6addd812016-02-02 17:17:23 -0700221 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600222
Karl Schultz6addd812016-02-02 17:17:23 -0700223 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600224 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600225 if (otherMsgs.size()) {
226 cout << "Other error messages logged for this test were:" << endl;
227 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
228 cout << " " << *iter << endl;
229 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600230 }
231 }
232
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600233 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200234
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600235 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
236 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
237 m_msgFlags = message_flag_mask;
238 // Match ANY message matching specified type
239 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200240 }
241
242 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600243 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200244 if (!DesiredMsgFound()) {
245 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600246 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600247 FAIL() << "Did not receive expected error '" << desired_msg << "'";
248 }
Tony Barbour59b42282016-11-03 13:31:28 -0600249 for (auto desired_id : m_desired_message_ids) {
250 FAIL() << "Did not receive expected error '" << desired_id << "'";
251 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200252 }
253 }
254
255 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600256 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200257 if (DesiredMsgFound()) {
258 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600259 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600260 FAIL() << "Expected to succeed but got error: " << msg;
261 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262 }
263 }
264
Karl Schultz6addd812016-02-02 17:17:23 -0700265 private:
266 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600267 std::unordered_set<uint32_t>m_desired_message_ids;
268 std::unordered_set<string> m_desired_message_strings;
269 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700270 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600271 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700272 bool *m_bailout;
273 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600274};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500275
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600276static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
277 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
278 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600279 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
280 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600281 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600282 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600283 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600284}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500285
Karl Schultz6addd812016-02-02 17:17:23 -0700286class VkLayerTest : public VkRenderFramework {
287 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800288 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
289 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600290 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
291 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700292 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
294 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700295 }
Tony Barbour300a6082015-04-07 13:44:53 -0600296
Tony Barbourfe3351b2015-07-28 10:17:20 -0600297 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600298 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800299 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600300 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
301 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700302 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700304 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600305 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700306 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600307 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
308 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
309 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700310 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
311 }
312 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
313 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
314 }
315
316 protected:
317 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600318 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600319
320 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600321 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600322 std::vector<const char *> instance_extension_names;
323 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600324
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700325 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600326 /*
327 * Since CreateDbgMsgCallback is an instance level extension call
328 * any extension / layer that utilizes that feature also needs
329 * to be enabled at create instance time.
330 */
Karl Schultz6addd812016-02-02 17:17:23 -0700331 // Use Threading layer first to protect others from
332 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700333 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600334 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800335 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700336 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800337 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600338 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700339 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600340
Ian Elliott2c1daf52016-05-12 09:41:46 -0600341 if (m_enableWSI) {
342 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
343 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
344#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
345#if defined(VK_USE_PLATFORM_ANDROID_KHR)
346 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
347#endif // VK_USE_PLATFORM_ANDROID_KHR
348#if defined(VK_USE_PLATFORM_MIR_KHR)
349 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_MIR_KHR
351#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
352 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
353#endif // VK_USE_PLATFORM_WAYLAND_KHR
354#if defined(VK_USE_PLATFORM_WIN32_KHR)
355 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_WIN32_KHR
357#endif // NEED_TO_TEST_THIS_ON_PLATFORM
358#if defined(VK_USE_PLATFORM_XCB_KHR)
359 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
360#elif defined(VK_USE_PLATFORM_XLIB_KHR)
361 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
362#endif // VK_USE_PLATFORM_XLIB_KHR
363 }
364
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600365 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600366 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800367 this->app_info.pApplicationName = "layer_tests";
368 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600369 this->app_info.pEngineName = "unittest";
370 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600371 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600372
Tony Barbour15524c32015-04-29 17:34:29 -0600373 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600374 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600375 }
376
377 virtual void TearDown() {
378 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600379 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600380 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600381 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600382
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600383 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600384};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500385
Karl Schultz6addd812016-02-02 17:17:23 -0700386VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600387 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600388
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800389 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600390
391 /*
392 * For render test all drawing happens in a single render pass
393 * on a single command buffer.
394 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200395 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800396 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600397 }
398
399 return result;
400}
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600403 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600404
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200405 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800406 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200407 }
Tony Barbour300a6082015-04-07 13:44:53 -0600408
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600410
411 return result;
412}
413
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600414void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500415 // Create identity matrix
416 int i;
417 struct vktriangle_vs_uniform data;
418
419 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700420 glm::mat4 View = glm::mat4(1.0f);
421 glm::mat4 Model = glm::mat4(1.0f);
422 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700424 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425
426 memcpy(&data.mvp, &MVP[0][0], matrixSize);
427
Karl Schultz6addd812016-02-02 17:17:23 -0700428 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600429 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500430 };
431
Karl Schultz6addd812016-02-02 17:17:23 -0700432 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 data.position[i][0] = tri_data[i].posX;
434 data.position[i][1] = tri_data[i].posY;
435 data.position[i][2] = tri_data[i].posZ;
436 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700437 data.color[i][0] = tri_data[i].r;
438 data.color[i][1] = tri_data[i].g;
439 data.color[i][2] = tri_data[i].b;
440 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500441 }
442
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 ASSERT_NO_FATAL_FAILURE(InitViewport());
444
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200445 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
446 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Karl Schultz6addd812016-02-02 17:17:23 -0700448 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600449 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
451 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800452 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 pipelineobj.AddShader(&vs);
454 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 if (failMask & BsoFailLineWidth) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600457 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600458 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600459 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
460 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600461 }
462 if (failMask & BsoFailDepthBias) {
463 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600464 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600465 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600466 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600467 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600468 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600469 }
Karl Schultz6addd812016-02-02 17:17:23 -0700470 // Viewport and scissors must stay in synch or other errors will occur than
471 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 if (failMask & BsoFailViewport) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
474 }
475 if (failMask & BsoFailScissor) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
477 }
478 if (failMask & BsoFailBlend) {
479 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600480 VkPipelineColorBlendAttachmentState att_state = {};
481 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
482 att_state.blendEnable = VK_TRUE;
483 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600484 }
485 if (failMask & BsoFailDepthBounds) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
487 }
488 if (failMask & BsoFailStencilReadMask) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
490 }
491 if (failMask & BsoFailStencilWriteMask) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
493 }
494 if (failMask & BsoFailStencilReference) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
496 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500497
498 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600499 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600502 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
Tony Barbourfe3351b2015-07-28 10:17:20 -0600504 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500505
506 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600507 if (failMask & BsoFailIndexBuffer) {
508 // Use DrawIndexed w/o an index buffer bound
509 DrawIndexed(3, 1, 0, 0, 0);
510 } else {
511 Draw(3, 1, 0, 0);
512 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500513
Mark Muellerd4914412016-06-13 17:52:06 -0600514 if (failMask & BsoFailCmdClearAttachments) {
515 VkClearAttachment color_attachment = {};
516 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
517 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
518 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
519
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600520 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600521 }
522
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500523 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600524 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500525
Tony Barbourfe3351b2015-07-28 10:17:20 -0600526 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500527}
528
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600529void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
530 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500531 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500533 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600534 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500535 }
536
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800537 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700538 // Make sure depthWriteEnable is set so that Depth fail test will work
539 // correctly
540 // Make sure stencilTestEnable is set so that Stencil fail test will work
541 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600542 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800543 stencil.failOp = VK_STENCIL_OP_KEEP;
544 stencil.passOp = VK_STENCIL_OP_KEEP;
545 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
546 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600547
548 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
549 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600550 ds_ci.pNext = NULL;
551 ds_ci.depthTestEnable = VK_FALSE;
552 ds_ci.depthWriteEnable = VK_TRUE;
553 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
554 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600555 if (failMask & BsoFailDepthBounds) {
556 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600557 ds_ci.maxDepthBounds = 0.0f;
558 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600559 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600560 ds_ci.stencilTestEnable = VK_TRUE;
561 ds_ci.front = stencil;
562 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600563
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600564 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600565 pipelineobj.SetViewport(m_viewports);
566 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800567 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600568 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600569 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800570 commandBuffer->BindPipeline(pipelineobj);
571 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500572}
573
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600574class VkPositiveLayerTest : public VkLayerTest {
575 public:
576 protected:
577};
578
Ian Elliott2c1daf52016-05-12 09:41:46 -0600579class VkWsiEnabledLayerTest : public VkLayerTest {
580 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 protected:
582 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600583};
584
Mark Muellerdfe37552016-07-07 14:47:42 -0600585class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600586 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600587 enum eTestEnFlags {
588 eDoubleDelete,
589 eInvalidDeviceOffset,
590 eInvalidMemoryOffset,
591 eBindNullBuffer,
592 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600593 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600594 };
595
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600596 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600597
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
599 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600600 return true;
601 }
602 VkDeviceSize offset_limit = 0;
603 if (eInvalidMemoryOffset == aTestFlag) {
604 VkBuffer vulkanBuffer;
605 VkBufferCreateInfo buffer_create_info = {};
606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
607 buffer_create_info.size = 32;
608 buffer_create_info.usage = aBufferUsage;
609
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600610 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600611 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600614 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
615 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
617 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600618 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600620 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600622 }
623 if (eOffsetAlignment < offset_limit) {
624 return true;
625 }
626 return false;
627 }
628
629 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
631 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
633 if (eBindNullBuffer == aTestFlag) {
634 VulkanMemory = 0;
635 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
636 } else {
637 VkBufferCreateInfo buffer_create_info = {};
638 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
639 buffer_create_info.size = 32;
640 buffer_create_info.usage = aBufferUsage;
641
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600643
644 CreateCurrent = true;
645
646 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600647 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600648
649 VkMemoryAllocateInfo memory_allocate_info = {};
650 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
651 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
653 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600654 if (!pass) {
655 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
656 return;
657 }
658
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600659 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600660 AllocateCurrent = true;
661 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
663 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 BoundCurrent = true;
665
666 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
667 }
668 }
669
670 ~VkBufferTest() {
671 if (CreateCurrent) {
672 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
673 }
674 if (AllocateCurrent) {
675 if (InvalidDeleteEn) {
676 union {
677 VkDeviceMemory device_memory;
678 unsigned long long index_access;
679 } bad_index;
680
681 bad_index.device_memory = VulkanMemory;
682 bad_index.index_access++;
683
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600684 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600685 }
686 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
687 }
688 }
689
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600690 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600691
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600692 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600693
694 void TestDoubleDestroy() {
695 // Destroy the buffer but leave the flag set, which will cause
696 // the buffer to be destroyed again in the destructor.
697 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600701 bool AllocateCurrent;
702 bool BoundCurrent;
703 bool CreateCurrent;
704 bool InvalidDeleteEn;
705
706 VkBuffer VulkanBuffer;
707 VkDevice VulkanDevice;
708 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600709};
710
711class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600712 public:
713 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600714 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600716 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600717 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
718 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 BindIdGenerator++; // NB: This can wrap w/misuse
720
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600721 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
722 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
725 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
726 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
727 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
728 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600729
730 unsigned i = 0;
731 do {
732 VertexInputAttributeDescription[i].binding = BindId;
733 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
735 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600736 i++;
737 } while (AttributeCount < i);
738
739 i = 0;
740 do {
741 VertexInputBindingDescription[i].binding = BindId;
742 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600743 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600744 i++;
745 } while (BindingCount < i);
746 }
747
748 ~VkVerticesObj() {
749 if (VertexInputAttributeDescription) {
750 delete[] VertexInputAttributeDescription;
751 }
752 if (VertexInputBindingDescription) {
753 delete[] VertexInputBindingDescription;
754 }
755 }
756
757 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
759 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600760 return true;
761 }
762
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600763 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600764 VkDeviceSize *offsetList;
765 unsigned offsetCount;
766
767 if (aOffsetCount) {
768 offsetList = aOffsetList;
769 offsetCount = aOffsetCount;
770 } else {
771 offsetList = new VkDeviceSize[1]();
772 offsetCount = 1;
773 }
774
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600775 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600776 BoundCurrent = true;
777
778 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600779 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600780 }
781 }
782
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600783 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600784 static uint32_t BindIdGenerator;
785
786 bool BoundCurrent;
787 unsigned AttributeCount;
788 unsigned BindingCount;
789 uint32_t BindId;
790
791 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
792 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
793 VkVertexInputBindingDescription *VertexInputBindingDescription;
794 VkConstantBufferObj VulkanMemoryBuffer;
795};
796
797uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500798// ********************************************************************************************************************
799// ********************************************************************************************************************
800// ********************************************************************************************************************
801// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600802#if PARAMETER_VALIDATION_TESTS
803TEST_F(VkLayerTest, RequiredParameter) {
804 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
805 "pointer, array, and array count parameters");
806
807 ASSERT_NO_FATAL_FAILURE(InitState());
808
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600810 // Specify NULL for a pointer to a handle
811 // Expected to trigger an error with
812 // parameter_validation::validate_required_pointer
813 vkGetPhysicalDeviceFeatures(gpu(), NULL);
814 m_errorMonitor->VerifyFound();
815
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
817 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600818 // Specify NULL for pointer to array count
819 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600820 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600821 m_errorMonitor->VerifyFound();
822
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 // Specify 0 for a required array count
825 // Expected to trigger an error with parameter_validation::validate_array
826 VkViewport view_port = {};
827 m_commandBuffer->SetViewport(0, 0, &view_port);
828 m_errorMonitor->VerifyFound();
829
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for a required array
832 // Expected to trigger an error with parameter_validation::validate_array
833 m_commandBuffer->SetViewport(0, 1, NULL);
834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify VK_NULL_HANDLE for a required handle
838 // Expected to trigger an error with
839 // parameter_validation::validate_required_handle
840 vkUnmapMemory(device(), VK_NULL_HANDLE);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
844 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600845 // Specify VK_NULL_HANDLE for a required handle array entry
846 // Expected to trigger an error with
847 // parameter_validation::validate_required_handle_array
848 VkFence fence = VK_NULL_HANDLE;
849 vkResetFences(device(), 1, &fence);
850 m_errorMonitor->VerifyFound();
851
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600853 // Specify NULL for a required struct pointer
854 // Expected to trigger an error with
855 // parameter_validation::validate_struct_type
856 VkDeviceMemory memory = VK_NULL_HANDLE;
857 vkAllocateMemory(device(), NULL, NULL, &memory);
858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600861 // Specify 0 for a required VkFlags parameter
862 // Expected to trigger an error with parameter_validation::validate_flags
863 m_commandBuffer->SetStencilReference(0, 0);
864 m_errorMonitor->VerifyFound();
865
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600867 // Specify 0 for a required VkFlags array entry
868 // Expected to trigger an error with
869 // parameter_validation::validate_flags_array
870 VkSemaphore semaphore = VK_NULL_HANDLE;
871 VkPipelineStageFlags stageFlags = 0;
872 VkSubmitInfo submitInfo = {};
873 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
874 submitInfo.waitSemaphoreCount = 1;
875 submitInfo.pWaitSemaphores = &semaphore;
876 submitInfo.pWaitDstStageMask = &stageFlags;
877 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
878 m_errorMonitor->VerifyFound();
879}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600880
Dustin Gravesfce74c02016-05-10 11:42:58 -0600881TEST_F(VkLayerTest, ReservedParameter) {
882 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
883
884 ASSERT_NO_FATAL_FAILURE(InitState());
885
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600887 // Specify 0 for a reserved VkFlags parameter
888 // Expected to trigger an error with
889 // parameter_validation::validate_reserved_flags
890 VkEvent event_handle = VK_NULL_HANDLE;
891 VkEventCreateInfo event_info = {};
892 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
893 event_info.flags = 1;
894 vkCreateEvent(device(), &event_info, NULL, &event_handle);
895 m_errorMonitor->VerifyFound();
896}
897
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600898TEST_F(VkLayerTest, InvalidStructSType) {
899 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
900 "structure's sType field");
901
902 ASSERT_NO_FATAL_FAILURE(InitState());
903
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600905 // Zero struct memory, effectively setting sType to
906 // VK_STRUCTURE_TYPE_APPLICATION_INFO
907 // Expected to trigger an error with
908 // parameter_validation::validate_struct_type
909 VkMemoryAllocateInfo alloc_info = {};
910 VkDeviceMemory memory = VK_NULL_HANDLE;
911 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
912 m_errorMonitor->VerifyFound();
913
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915 // Zero struct memory, effectively setting sType to
916 // VK_STRUCTURE_TYPE_APPLICATION_INFO
917 // Expected to trigger an error with
918 // parameter_validation::validate_struct_type_array
919 VkSubmitInfo submit_info = {};
920 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
921 m_errorMonitor->VerifyFound();
922}
923
924TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600925 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600926
927 ASSERT_NO_FATAL_FAILURE(InitState());
928
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600930 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600931 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600932 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600933 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600934 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600935 // Zero-initialization will provide the correct sType
936 VkApplicationInfo app_info = {};
937 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
938 event_alloc_info.pNext = &app_info;
939 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
940 m_errorMonitor->VerifyFound();
941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
943 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
945 // a function that has allowed pNext structure types and specify
946 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600947 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600948 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600949 VkMemoryAllocateInfo memory_alloc_info = {};
950 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
951 memory_alloc_info.pNext = &app_info;
952 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600953 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600954}
Dustin Graves5d33d532016-05-09 16:21:12 -0600955
956TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600957 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600958
959 ASSERT_NO_FATAL_FAILURE(InitState());
960
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
962 "range of the core VkFormat "
963 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600964 // Specify an invalid VkFormat value
965 // Expected to trigger an error with
966 // parameter_validation::validate_ranged_enum
967 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600968 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600969 m_errorMonitor->VerifyFound();
970
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 // Specify an invalid VkFlags bitmask value
973 // Expected to trigger an error with parameter_validation::validate_flags
974 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600975 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
976 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600977 m_errorMonitor->VerifyFound();
978
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 // Specify an invalid VkFlags array entry
981 // Expected to trigger an error with
982 // parameter_validation::validate_flags_array
983 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600984 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600985 VkSubmitInfo submit_info = {};
986 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
987 submit_info.waitSemaphoreCount = 1;
988 submit_info.pWaitSemaphores = &semaphore;
989 submit_info.pWaitDstStageMask = &stage_flags;
990 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
991 m_errorMonitor->VerifyFound();
992
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 // Specify an invalid VkBool32 value
995 // Expected to trigger a warning with
996 // parameter_validation::validate_bool32
997 VkSampler sampler = VK_NULL_HANDLE;
998 VkSamplerCreateInfo sampler_info = {};
999 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1000 sampler_info.pNext = NULL;
1001 sampler_info.magFilter = VK_FILTER_NEAREST;
1002 sampler_info.minFilter = VK_FILTER_NEAREST;
1003 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1004 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1005 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1006 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1007 sampler_info.mipLodBias = 1.0;
1008 sampler_info.maxAnisotropy = 1;
1009 sampler_info.compareEnable = VK_FALSE;
1010 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1011 sampler_info.minLod = 1.0;
1012 sampler_info.maxLod = 1.0;
1013 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1014 sampler_info.unnormalizedCoordinates = VK_FALSE;
1015 // Not VK_TRUE or VK_FALSE
1016 sampler_info.anisotropyEnable = 3;
1017 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1018 m_errorMonitor->VerifyFound();
1019}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001020
1021TEST_F(VkLayerTest, FailedReturnValue) {
1022 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1023
1024 ASSERT_NO_FATAL_FAILURE(InitState());
1025
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001026 // Find an unsupported image format
1027 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1028 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1029 VkFormat format = static_cast<VkFormat>(f);
1030 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001031 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001032 unsupported = format;
1033 break;
1034 }
1035 }
1036
1037 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1039 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001040 // Specify an unsupported VkFormat value to generate a
1041 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1042 // Expected to trigger a warning from
1043 // parameter_validation::validate_result
1044 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001045 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1046 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1048 m_errorMonitor->VerifyFound();
1049 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001050}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001051
1052TEST_F(VkLayerTest, UpdateBufferAlignment) {
1053 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001054 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001055
1056 ASSERT_NO_FATAL_FAILURE(InitState());
1057
1058 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1059 vk_testing::Buffer buffer;
1060 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1061
1062 BeginCommandBuffer();
1063 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1066 m_errorMonitor->VerifyFound();
1067
1068 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1071 m_errorMonitor->VerifyFound();
1072
1073 // Introduce failure by using dataSize that is < 0
1074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001075 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1077 m_errorMonitor->VerifyFound();
1078
1079 // Introduce failure by using dataSize that is > 65536
1080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001081 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001082 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1083 m_errorMonitor->VerifyFound();
1084
1085 EndCommandBuffer();
1086}
1087
1088TEST_F(VkLayerTest, FillBufferAlignment) {
1089 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1090
1091 ASSERT_NO_FATAL_FAILURE(InitState());
1092
1093 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1094 vk_testing::Buffer buffer;
1095 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1096
1097 BeginCommandBuffer();
1098
1099 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1102 m_errorMonitor->VerifyFound();
1103
1104 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001106 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1107 m_errorMonitor->VerifyFound();
1108
1109 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001111 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1112 m_errorMonitor->VerifyFound();
1113
1114 EndCommandBuffer();
1115}
Dustin Graves40f35822016-06-23 11:12:53 -06001116
Cortd889ff92016-07-27 09:51:27 -07001117TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1118 VkResult err;
1119
1120 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001121 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001122
1123 ASSERT_NO_FATAL_FAILURE(InitState());
1124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1125
1126 std::vector<const char *> device_extension_names;
1127 auto features = m_device->phy().features();
1128 // Artificially disable support for non-solid fill modes
1129 features.fillModeNonSolid = false;
1130 // The sacrificial device object
1131 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1132
1133 VkRenderpassObj render_pass(&test_device);
1134
1135 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1136 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1137 pipeline_layout_ci.setLayoutCount = 0;
1138 pipeline_layout_ci.pSetLayouts = NULL;
1139
1140 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001141 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001142 ASSERT_VK_SUCCESS(err);
1143
1144 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1145 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1146 rs_ci.pNext = nullptr;
1147 rs_ci.lineWidth = 1.0f;
1148 rs_ci.rasterizerDiscardEnable = true;
1149
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001150 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1151 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001152
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001153 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1155 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001156 {
1157 VkPipelineObj pipe(&test_device);
1158 pipe.AddShader(&vs);
1159 pipe.AddShader(&fs);
1160 pipe.AddColorAttachment();
1161 // Introduce failure by setting unsupported polygon mode
1162 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1163 pipe.SetRasterization(&rs_ci);
1164 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1165 }
1166 m_errorMonitor->VerifyFound();
1167
1168 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1170 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001171 {
1172 VkPipelineObj pipe(&test_device);
1173 pipe.AddShader(&vs);
1174 pipe.AddShader(&fs);
1175 pipe.AddColorAttachment();
1176 // Introduce failure by setting unsupported polygon mode
1177 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1178 pipe.SetRasterization(&rs_ci);
1179 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1180 }
1181 m_errorMonitor->VerifyFound();
1182
Cortd889ff92016-07-27 09:51:27 -07001183 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1184}
1185
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001186#endif // PARAMETER_VALIDATION_TESTS
1187
Tobin Ehlis0788f522015-05-26 16:11:58 -06001188#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001189#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001190TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001191{
1192 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001193 VkFenceCreateInfo fenceInfo = {};
1194 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1195 fenceInfo.pNext = NULL;
1196 fenceInfo.flags = 0;
1197
Mike Weiblencce7ec72016-10-17 19:33:05 -06001198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001199
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001200 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001201
1202 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1203 vk_testing::Buffer buffer;
1204 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001205
Tony Barbourfe3351b2015-07-28 10:17:20 -06001206 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001207 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001208 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001209
1210 testFence.init(*m_device, fenceInfo);
1211
1212 // Bypass framework since it does the waits automatically
1213 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001214 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001215 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1216 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001217 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001218 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001219 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001220 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001221 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001222 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001223 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001224
1225 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001226 ASSERT_VK_SUCCESS( err );
1227
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001229 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001230
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001231 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232}
1233
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001235{
1236 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001237 VkFenceCreateInfo fenceInfo = {};
1238 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1239 fenceInfo.pNext = NULL;
1240 fenceInfo.flags = 0;
1241
Mike Weiblencce7ec72016-10-17 19:33:05 -06001242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001243
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001244 ASSERT_NO_FATAL_FAILURE(InitState());
1245 ASSERT_NO_FATAL_FAILURE(InitViewport());
1246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1247
Tony Barbourfe3351b2015-07-28 10:17:20 -06001248 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001249 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001250 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251
1252 testFence.init(*m_device, fenceInfo);
1253
1254 // Bypass framework since it does the waits automatically
1255 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001256 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001257 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1258 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001259 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001260 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001261 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001262 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001263 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001264 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001265 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001266
1267 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001268 ASSERT_VK_SUCCESS( err );
1269
Jon Ashburnf19916e2016-01-11 13:12:43 -07001270 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001271 VkCommandBufferBeginInfo info = {};
1272 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1273 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001274 info.renderPass = VK_NULL_HANDLE;
1275 info.subpass = 0;
1276 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001277 info.occlusionQueryEnable = VK_FALSE;
1278 info.queryFlags = 0;
1279 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001280
1281 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001282 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001283
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001284 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001285}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001286#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001287
Tobin Ehlisf11be982016-05-11 13:52:53 -06001288TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1289 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1290 "buffer and image to memory such that they will alias.");
1291 VkResult err;
1292 bool pass;
1293 ASSERT_NO_FATAL_FAILURE(InitState());
1294
Tobin Ehlis077ded32016-05-12 17:39:13 -06001295 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001296 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001297 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001298 VkDeviceMemory mem; // buffer will be bound first
1299 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001300 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001301
1302 VkBufferCreateInfo buf_info = {};
1303 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1304 buf_info.pNext = NULL;
1305 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1306 buf_info.size = 256;
1307 buf_info.queueFamilyIndexCount = 0;
1308 buf_info.pQueueFamilyIndices = NULL;
1309 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1310 buf_info.flags = 0;
1311 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1312 ASSERT_VK_SUCCESS(err);
1313
Tobin Ehlis077ded32016-05-12 17:39:13 -06001314 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001315
1316 VkImageCreateInfo image_create_info = {};
1317 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1318 image_create_info.pNext = NULL;
1319 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1320 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1321 image_create_info.extent.width = 64;
1322 image_create_info.extent.height = 64;
1323 image_create_info.extent.depth = 1;
1324 image_create_info.mipLevels = 1;
1325 image_create_info.arrayLayers = 1;
1326 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001327 // Image tiling must be optimal to trigger error when aliasing linear buffer
1328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001329 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1330 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1331 image_create_info.queueFamilyIndexCount = 0;
1332 image_create_info.pQueueFamilyIndices = NULL;
1333 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1334 image_create_info.flags = 0;
1335
Tobin Ehlisf11be982016-05-11 13:52:53 -06001336 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1337 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001338 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1339 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001340
Tobin Ehlis077ded32016-05-12 17:39:13 -06001341 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1342
1343 VkMemoryAllocateInfo alloc_info = {};
1344 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1345 alloc_info.pNext = NULL;
1346 alloc_info.memoryTypeIndex = 0;
1347 // Ensure memory is big enough for both bindings
1348 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001349 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1350 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001351 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001352 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001353 vkDestroyImage(m_device->device(), image, NULL);
1354 return;
1355 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001356 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1357 ASSERT_VK_SUCCESS(err);
1358 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1359 ASSERT_VK_SUCCESS(err);
1360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001362 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001363 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1364 m_errorMonitor->VerifyFound();
1365
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001366 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001367 // aliasing buffer2
1368 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1369 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001370 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1371 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001372 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001373 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001375 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001376 m_errorMonitor->VerifyFound();
1377
1378 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001379 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001380 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001381 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001382 vkFreeMemory(m_device->device(), mem, NULL);
1383 vkFreeMemory(m_device->device(), mem_img, NULL);
1384}
1385
Tobin Ehlis35372522016-05-12 08:32:31 -06001386TEST_F(VkLayerTest, InvalidMemoryMapping) {
1387 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1388 VkResult err;
1389 bool pass;
1390 ASSERT_NO_FATAL_FAILURE(InitState());
1391
1392 VkBuffer buffer;
1393 VkDeviceMemory mem;
1394 VkMemoryRequirements mem_reqs;
1395
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001396 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1397
Tobin Ehlis35372522016-05-12 08:32:31 -06001398 VkBufferCreateInfo buf_info = {};
1399 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1400 buf_info.pNext = NULL;
1401 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1402 buf_info.size = 256;
1403 buf_info.queueFamilyIndexCount = 0;
1404 buf_info.pQueueFamilyIndices = NULL;
1405 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1406 buf_info.flags = 0;
1407 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1408 ASSERT_VK_SUCCESS(err);
1409
1410 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1411 VkMemoryAllocateInfo alloc_info = {};
1412 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1413 alloc_info.pNext = NULL;
1414 alloc_info.memoryTypeIndex = 0;
1415
1416 // Ensure memory is big enough for both bindings
1417 static const VkDeviceSize allocation_size = 0x10000;
1418 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001419 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001420 if (!pass) {
1421 vkDestroyBuffer(m_device->device(), buffer, NULL);
1422 return;
1423 }
1424 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1425 ASSERT_VK_SUCCESS(err);
1426
1427 uint8_t *pData;
1428 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001430 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1431 m_errorMonitor->VerifyFound();
1432 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001433 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001434 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1436 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1437 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001438 m_errorMonitor->VerifyFound();
1439
1440 // Unmap the memory to avoid re-map error
1441 vkUnmapMemory(m_device->device(), mem);
1442 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1444 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1445 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001446 m_errorMonitor->VerifyFound();
1447 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1449 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001450 m_errorMonitor->VerifyFound();
1451 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001453 vkUnmapMemory(m_device->device(), mem);
1454 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001455
Tobin Ehlis35372522016-05-12 08:32:31 -06001456 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001457 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001458 ASSERT_VK_SUCCESS(err);
1459 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001460 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001461 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001462 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001464 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1465 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001466
Tobin Ehlis35372522016-05-12 08:32:31 -06001467 // Now flush range that oversteps mapped range
1468 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001469 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001470 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001471 mmr.offset = atom_size;
1472 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1474 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1475 m_errorMonitor->VerifyFound();
1476
1477 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1478 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001479 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001480 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001481 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001482 mmr.size = VK_WHOLE_SIZE;
1483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001484 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1485 m_errorMonitor->VerifyFound();
1486
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001487 // Some platforms have an atomsize of 1 which makes the test meaningless
1488 if (atom_size > 3) {
1489 // Now with an offset NOT a multiple of the device limit
1490 vkUnmapMemory(m_device->device(), mem);
1491 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1492 ASSERT_VK_SUCCESS(err);
1493 mmr.offset = 3; // Not a multiple of atom_size
1494 mmr.size = VK_WHOLE_SIZE;
1495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1496 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1497 m_errorMonitor->VerifyFound();
1498
1499 // Now with a size NOT a multiple of the device limit
1500 vkUnmapMemory(m_device->device(), mem);
1501 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1502 ASSERT_VK_SUCCESS(err);
1503 mmr.offset = atom_size;
1504 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1506 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1507 m_errorMonitor->VerifyFound();
1508 }
1509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001510 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1511 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001512 if (!pass) {
1513 vkFreeMemory(m_device->device(), mem, NULL);
1514 vkDestroyBuffer(m_device->device(), buffer, NULL);
1515 return;
1516 }
1517 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1518 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1519
1520 vkDestroyBuffer(m_device->device(), buffer, NULL);
1521 vkFreeMemory(m_device->device(), mem, NULL);
1522}
1523
Ian Elliott1c32c772016-04-28 14:47:13 -06001524TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1525 VkResult err;
1526 bool pass;
1527
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001528 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1529 // following declaration (which is temporarily being moved below):
1530 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001531 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001532 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001533 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001534 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001535 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001536 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001537
1538 ASSERT_NO_FATAL_FAILURE(InitState());
1539
Ian Elliott3f06ce52016-04-29 14:46:21 -06001540#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1541#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1542 // Use the functions from the VK_KHR_android_surface extension without
1543 // enabling that extension:
1544
1545 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001546 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1548 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001549 pass = (err != VK_SUCCESS);
1550 ASSERT_TRUE(pass);
1551 m_errorMonitor->VerifyFound();
1552#endif // VK_USE_PLATFORM_ANDROID_KHR
1553
Ian Elliott3f06ce52016-04-29 14:46:21 -06001554#if defined(VK_USE_PLATFORM_MIR_KHR)
1555 // Use the functions from the VK_KHR_mir_surface extension without enabling
1556 // that extension:
1557
1558 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001559 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001561 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1562 pass = (err != VK_SUCCESS);
1563 ASSERT_TRUE(pass);
1564 m_errorMonitor->VerifyFound();
1565
1566 // Tell whether an mir_connection supports presentation:
1567 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1569 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001570 m_errorMonitor->VerifyFound();
1571#endif // VK_USE_PLATFORM_MIR_KHR
1572
Ian Elliott3f06ce52016-04-29 14:46:21 -06001573#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1574 // Use the functions from the VK_KHR_wayland_surface extension without
1575 // enabling that extension:
1576
1577 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001578 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1580 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001581 pass = (err != VK_SUCCESS);
1582 ASSERT_TRUE(pass);
1583 m_errorMonitor->VerifyFound();
1584
1585 // Tell whether an wayland_display supports presentation:
1586 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1588 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001589 m_errorMonitor->VerifyFound();
1590#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001591#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001592
Ian Elliott3f06ce52016-04-29 14:46:21 -06001593#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001594 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1595 // TO NON-LINUX PLATFORMS:
1596 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001597 // Use the functions from the VK_KHR_win32_surface extension without
1598 // enabling that extension:
1599
1600 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001601 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1603 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001604 pass = (err != VK_SUCCESS);
1605 ASSERT_TRUE(pass);
1606 m_errorMonitor->VerifyFound();
1607
1608 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001610 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001611 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001612// Set this (for now, until all platforms are supported and tested):
1613#define NEED_TO_TEST_THIS_ON_PLATFORM
1614#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001615#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001616 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1617 // TO NON-LINUX PLATFORMS:
1618 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001619#endif
1620#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001621 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1622 // that extension:
1623
1624 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001625 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001627 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1628 pass = (err != VK_SUCCESS);
1629 ASSERT_TRUE(pass);
1630 m_errorMonitor->VerifyFound();
1631
1632 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001633 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001634 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1636 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001637 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001638// Set this (for now, until all platforms are supported and tested):
1639#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001640#endif // VK_USE_PLATFORM_XCB_KHR
1641
Ian Elliott12630812016-04-29 14:35:43 -06001642#if defined(VK_USE_PLATFORM_XLIB_KHR)
1643 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1644 // that extension:
1645
1646 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001647 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001649 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1650 pass = (err != VK_SUCCESS);
1651 ASSERT_TRUE(pass);
1652 m_errorMonitor->VerifyFound();
1653
1654 // Tell whether an Xlib VisualID supports presentation:
1655 Display *dpy = NULL;
1656 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001658 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1659 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001660// Set this (for now, until all platforms are supported and tested):
1661#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001662#endif // VK_USE_PLATFORM_XLIB_KHR
1663
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001664// Use the functions from the VK_KHR_surface extension without enabling
1665// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001666
Ian Elliott489eec02016-05-05 14:12:44 -06001667#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001668 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001670 vkDestroySurfaceKHR(instance(), surface, NULL);
1671 m_errorMonitor->VerifyFound();
1672
1673 // Check if surface supports presentation:
1674 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001676 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1677 pass = (err != VK_SUCCESS);
1678 ASSERT_TRUE(pass);
1679 m_errorMonitor->VerifyFound();
1680
1681 // Check surface capabilities:
1682 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1684 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001685 pass = (err != VK_SUCCESS);
1686 ASSERT_TRUE(pass);
1687 m_errorMonitor->VerifyFound();
1688
1689 // Check surface formats:
1690 uint32_t format_count = 0;
1691 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1693 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001694 pass = (err != VK_SUCCESS);
1695 ASSERT_TRUE(pass);
1696 m_errorMonitor->VerifyFound();
1697
1698 // Check surface present modes:
1699 uint32_t present_mode_count = 0;
1700 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1702 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001703 pass = (err != VK_SUCCESS);
1704 ASSERT_TRUE(pass);
1705 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001706#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001707
Ian Elliott1c32c772016-04-28 14:47:13 -06001708 // Use the functions from the VK_KHR_swapchain extension without enabling
1709 // that extension:
1710
1711 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001713 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1714 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001715 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001716 pass = (err != VK_SUCCESS);
1717 ASSERT_TRUE(pass);
1718 m_errorMonitor->VerifyFound();
1719
1720 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1722 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001723 pass = (err != VK_SUCCESS);
1724 ASSERT_TRUE(pass);
1725 m_errorMonitor->VerifyFound();
1726
Chris Forbeseb7d5502016-09-13 18:19:21 +12001727 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1728 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1729 VkFence fence;
1730 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1731
Ian Elliott1c32c772016-04-28 14:47:13 -06001732 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001734 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001735 pass = (err != VK_SUCCESS);
1736 ASSERT_TRUE(pass);
1737 m_errorMonitor->VerifyFound();
1738
Chris Forbeseb7d5502016-09-13 18:19:21 +12001739 vkDestroyFence(m_device->device(), fence, nullptr);
1740
Ian Elliott1c32c772016-04-28 14:47:13 -06001741 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001742 //
1743 // NOTE: Currently can't test this because a real swapchain is needed (as
1744 // opposed to the fake one we created) in order for the layer to lookup the
1745 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001746
1747 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001749 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1750 m_errorMonitor->VerifyFound();
1751}
1752
Karl Schultz6addd812016-02-02 17:17:23 -07001753TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1754 VkResult err;
1755 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001756
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1758 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001759
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001760 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001761
1762 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001763 VkImage image;
1764 VkDeviceMemory mem;
1765 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001766
Karl Schultz6addd812016-02-02 17:17:23 -07001767 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1768 const int32_t tex_width = 32;
1769 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001770
Tony Barboureb254902015-07-15 12:50:33 -06001771 VkImageCreateInfo image_create_info = {};
1772 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001773 image_create_info.pNext = NULL;
1774 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1775 image_create_info.format = tex_format;
1776 image_create_info.extent.width = tex_width;
1777 image_create_info.extent.height = tex_height;
1778 image_create_info.extent.depth = 1;
1779 image_create_info.mipLevels = 1;
1780 image_create_info.arrayLayers = 1;
1781 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1782 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1783 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1784 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001785 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001786
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001787 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001788 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001789 mem_alloc.pNext = NULL;
1790 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001791
Chia-I Wuf7458c52015-10-26 21:10:41 +08001792 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001793 ASSERT_VK_SUCCESS(err);
1794
Karl Schultz6addd812016-02-02 17:17:23 -07001795 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001796
Mark Lobodzinski23065352015-05-29 09:32:35 -05001797 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001798
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001799 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Karl Schultz6addd812016-02-02 17:17:23 -07001800 if (!pass) { // If we can't find any unmappable memory this test doesn't
1801 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001802 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001803 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001804 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001805
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001806 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001807 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001808 ASSERT_VK_SUCCESS(err);
1809
1810 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001811 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001812 ASSERT_VK_SUCCESS(err);
1813
1814 // Map memory as if to initialize the image
1815 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001816 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001817
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001818 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001819
Chia-I Wuf7458c52015-10-26 21:10:41 +08001820 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001821 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001822}
1823
Karl Schultz6addd812016-02-02 17:17:23 -07001824TEST_F(VkLayerTest, RebindMemory) {
1825 VkResult err;
1826 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001827
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001829
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001830 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001831
1832 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001833 VkImage image;
1834 VkDeviceMemory mem1;
1835 VkDeviceMemory mem2;
1836 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001837
Karl Schultz6addd812016-02-02 17:17:23 -07001838 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1839 const int32_t tex_width = 32;
1840 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001841
Tony Barboureb254902015-07-15 12:50:33 -06001842 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001843 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1844 image_create_info.pNext = NULL;
1845 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1846 image_create_info.format = tex_format;
1847 image_create_info.extent.width = tex_width;
1848 image_create_info.extent.height = tex_height;
1849 image_create_info.extent.depth = 1;
1850 image_create_info.mipLevels = 1;
1851 image_create_info.arrayLayers = 1;
1852 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1853 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1854 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1855 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001856
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001857 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001858 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1859 mem_alloc.pNext = NULL;
1860 mem_alloc.allocationSize = 0;
1861 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001862
Karl Schultz6addd812016-02-02 17:17:23 -07001863 // Introduce failure, do NOT set memProps to
1864 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001865 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001866 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001867 ASSERT_VK_SUCCESS(err);
1868
Karl Schultz6addd812016-02-02 17:17:23 -07001869 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001870
1871 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001872 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001873 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001874
1875 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001876 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001877 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001878 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001879 ASSERT_VK_SUCCESS(err);
1880
1881 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001882 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001883 ASSERT_VK_SUCCESS(err);
1884
Karl Schultz6addd812016-02-02 17:17:23 -07001885 // Introduce validation failure, try to bind a different memory object to
1886 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001887 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001888
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001889 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001890
Chia-I Wuf7458c52015-10-26 21:10:41 +08001891 vkDestroyImage(m_device->device(), image, NULL);
1892 vkFreeMemory(m_device->device(), mem1, NULL);
1893 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001894}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001895
Karl Schultz6addd812016-02-02 17:17:23 -07001896TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001897 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001898
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1900 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001901
1902 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001903 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1904 fenceInfo.pNext = NULL;
1905 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001906
Tony Barbour300a6082015-04-07 13:44:53 -06001907 ASSERT_NO_FATAL_FAILURE(InitState());
1908 ASSERT_NO_FATAL_FAILURE(InitViewport());
1909 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1910
Tony Barbourfe3351b2015-07-28 10:17:20 -06001911 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001912 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001913 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001914
1915 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001916
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001917 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001918 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1919 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001920 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001921 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001922 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001923 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001924 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001925 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001926 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001927
1928 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001929 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001930
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001931 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001932}
Chris Forbes4e44c912016-06-16 10:20:00 +12001933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001934TEST_F(VkLayerTest, InvalidUsageBits) {
1935 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1936 "Initialize buffer with wrong usage then perform copy expecting errors "
1937 "from both the image and the buffer (2 calls)");
1938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001939
1940 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001941 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001942 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001943 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001944 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001945
Tony Barbourf92621a2016-05-02 14:28:12 -06001946 VkImageView dsv;
1947 VkImageViewCreateInfo dsvci = {};
1948 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1949 dsvci.image = image.handle();
1950 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1951 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1952 dsvci.subresourceRange.layerCount = 1;
1953 dsvci.subresourceRange.baseMipLevel = 0;
1954 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001955 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001956
Tony Barbourf92621a2016-05-02 14:28:12 -06001957 // Create a view with depth / stencil aspect for image with different usage
1958 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001959
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001960 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001961
1962 // Initialize buffer with TRANSFER_DST usage
1963 vk_testing::Buffer buffer;
1964 VkMemoryPropertyFlags reqs = 0;
1965 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1966 VkBufferImageCopy region = {};
1967 region.bufferRowLength = 128;
1968 region.bufferImageHeight = 128;
1969 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1970 region.imageSubresource.layerCount = 1;
1971 region.imageExtent.height = 16;
1972 region.imageExtent.width = 16;
1973 region.imageExtent.depth = 1;
1974
Tony Barbourf92621a2016-05-02 14:28:12 -06001975 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1976 // TRANSFER_DST
1977 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001978
Chris Forbesda581202016-10-06 18:25:26 +13001979 // two separate errors from this call:
1980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001983 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1984 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001985 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001986}
Tony Barbour75d79f02016-08-30 09:39:07 -06001987
Tony Barbour75d79f02016-08-30 09:39:07 -06001988
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001989#endif // MEM_TRACKER_TESTS
1990
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001991#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001992
1993TEST_F(VkLayerTest, LeakAnObject) {
1994 VkResult err;
1995
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001996 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001997
1998 // Note that we have to create a new device since destroying the
1999 // framework's device causes Teardown() to fail and just calling Teardown
2000 // will destroy the errorMonitor.
2001
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002003
2004 ASSERT_NO_FATAL_FAILURE(InitState());
2005
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002006 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002007 std::vector<VkDeviceQueueCreateInfo> queue_info;
2008 queue_info.reserve(queue_props.size());
2009 std::vector<std::vector<float>> queue_priorities;
2010 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2011 VkDeviceQueueCreateInfo qi = {};
2012 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2013 qi.pNext = NULL;
2014 qi.queueFamilyIndex = i;
2015 qi.queueCount = queue_props[i].queueCount;
2016 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2017 qi.pQueuePriorities = queue_priorities[i].data();
2018 queue_info.push_back(qi);
2019 }
2020
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002021 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002022
2023 // The sacrificial device object
2024 VkDevice testDevice;
2025 VkDeviceCreateInfo device_create_info = {};
2026 auto features = m_device->phy().features();
2027 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2028 device_create_info.pNext = NULL;
2029 device_create_info.queueCreateInfoCount = queue_info.size();
2030 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002031 device_create_info.enabledLayerCount = 0;
2032 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002033 device_create_info.pEnabledFeatures = &features;
2034 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2035 ASSERT_VK_SUCCESS(err);
2036
2037 VkFence fence;
2038 VkFenceCreateInfo fence_create_info = {};
2039 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2040 fence_create_info.pNext = NULL;
2041 fence_create_info.flags = 0;
2042 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2043 ASSERT_VK_SUCCESS(err);
2044
2045 // Induce failure by not calling vkDestroyFence
2046 vkDestroyDevice(testDevice, NULL);
2047 m_errorMonitor->VerifyFound();
2048}
2049
2050TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2051
2052 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2053 "attempt to delete them from another.");
2054
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002056
Cody Northropc31a84f2016-08-22 10:41:47 -06002057 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002058 VkCommandPool command_pool_one;
2059 VkCommandPool command_pool_two;
2060
2061 VkCommandPoolCreateInfo pool_create_info{};
2062 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2063 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2064 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2065
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002066 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002067
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002068 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002069
2070 VkCommandBuffer command_buffer[9];
2071 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002072 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002073 command_buffer_allocate_info.commandPool = command_pool_one;
2074 command_buffer_allocate_info.commandBufferCount = 9;
2075 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002076 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002077
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002078 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002079
2080 m_errorMonitor->VerifyFound();
2081
2082 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2083 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2084}
2085
2086TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2087 VkResult err;
2088
2089 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002090 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002091
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002093
2094 ASSERT_NO_FATAL_FAILURE(InitState());
2095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2096
2097 VkDescriptorPoolSize ds_type_count = {};
2098 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2099 ds_type_count.descriptorCount = 1;
2100
2101 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2102 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2103 ds_pool_ci.pNext = NULL;
2104 ds_pool_ci.flags = 0;
2105 ds_pool_ci.maxSets = 1;
2106 ds_pool_ci.poolSizeCount = 1;
2107 ds_pool_ci.pPoolSizes = &ds_type_count;
2108
2109 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002110 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002111 ASSERT_VK_SUCCESS(err);
2112
2113 // Create a second descriptor pool
2114 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002115 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002116 ASSERT_VK_SUCCESS(err);
2117
2118 VkDescriptorSetLayoutBinding dsl_binding = {};
2119 dsl_binding.binding = 0;
2120 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2121 dsl_binding.descriptorCount = 1;
2122 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2123 dsl_binding.pImmutableSamplers = NULL;
2124
2125 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2126 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2127 ds_layout_ci.pNext = NULL;
2128 ds_layout_ci.bindingCount = 1;
2129 ds_layout_ci.pBindings = &dsl_binding;
2130
2131 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002132 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002133 ASSERT_VK_SUCCESS(err);
2134
2135 VkDescriptorSet descriptorSet;
2136 VkDescriptorSetAllocateInfo alloc_info = {};
2137 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2138 alloc_info.descriptorSetCount = 1;
2139 alloc_info.descriptorPool = ds_pool_one;
2140 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002141 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002142 ASSERT_VK_SUCCESS(err);
2143
2144 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2145
2146 m_errorMonitor->VerifyFound();
2147
2148 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2149 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2150 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2151}
2152
2153TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002155
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002156 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002157
2158 ASSERT_NO_FATAL_FAILURE(InitState());
2159
2160 // Pass bogus handle into GetImageMemoryRequirements
2161 VkMemoryRequirements mem_reqs;
2162 uint64_t fakeImageHandle = 0xCADECADE;
2163 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2164
2165 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2166
2167 m_errorMonitor->VerifyFound();
2168}
2169
Karl Schultz6addd812016-02-02 17:17:23 -07002170TEST_F(VkLayerTest, PipelineNotBound) {
2171 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002172
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002173 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002174
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002176
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002177 ASSERT_NO_FATAL_FAILURE(InitState());
2178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002179
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002180 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002181 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2182 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002183
2184 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002185 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2186 ds_pool_ci.pNext = NULL;
2187 ds_pool_ci.maxSets = 1;
2188 ds_pool_ci.poolSizeCount = 1;
2189 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002190
2191 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002192 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002193 ASSERT_VK_SUCCESS(err);
2194
2195 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002196 dsl_binding.binding = 0;
2197 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2198 dsl_binding.descriptorCount = 1;
2199 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2200 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002201
2202 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002203 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2204 ds_layout_ci.pNext = NULL;
2205 ds_layout_ci.bindingCount = 1;
2206 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002207
2208 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002209 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002210 ASSERT_VK_SUCCESS(err);
2211
2212 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002213 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002214 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002215 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002216 alloc_info.descriptorPool = ds_pool;
2217 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002218 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002219 ASSERT_VK_SUCCESS(err);
2220
2221 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002222 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2223 pipeline_layout_ci.pNext = NULL;
2224 pipeline_layout_ci.setLayoutCount = 1;
2225 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002226
2227 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002228 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002229 ASSERT_VK_SUCCESS(err);
2230
Mark Youngad779052016-01-06 14:26:04 -07002231 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002232
2233 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002234 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002235
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002236 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002237
Chia-I Wuf7458c52015-10-26 21:10:41 +08002238 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2239 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2240 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002241}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002242
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002243TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2244 VkResult err;
2245
2246 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2247 "during bind[Buffer|Image]Memory time");
2248
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002249 ASSERT_NO_FATAL_FAILURE(InitState());
2250
2251 // Create an image, allocate memory, set a bad typeIndex and then try to
2252 // bind it
2253 VkImage image;
2254 VkDeviceMemory mem;
2255 VkMemoryRequirements mem_reqs;
2256 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2257 const int32_t tex_width = 32;
2258 const int32_t tex_height = 32;
2259
2260 VkImageCreateInfo image_create_info = {};
2261 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2262 image_create_info.pNext = NULL;
2263 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2264 image_create_info.format = tex_format;
2265 image_create_info.extent.width = tex_width;
2266 image_create_info.extent.height = tex_height;
2267 image_create_info.extent.depth = 1;
2268 image_create_info.mipLevels = 1;
2269 image_create_info.arrayLayers = 1;
2270 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2271 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2272 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2273 image_create_info.flags = 0;
2274
2275 VkMemoryAllocateInfo mem_alloc = {};
2276 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2277 mem_alloc.pNext = NULL;
2278 mem_alloc.allocationSize = 0;
2279 mem_alloc.memoryTypeIndex = 0;
2280
2281 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2282 ASSERT_VK_SUCCESS(err);
2283
2284 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2285 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002286
2287 // Introduce Failure, select invalid TypeIndex
2288 VkPhysicalDeviceMemoryProperties memory_info;
2289
2290 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2291 unsigned int i;
2292 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2293 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2294 mem_alloc.memoryTypeIndex = i;
2295 break;
2296 }
2297 }
2298 if (i >= memory_info.memoryTypeCount) {
2299 printf("No invalid memory type index could be found; skipped.\n");
2300 vkDestroyImage(m_device->device(), image, NULL);
2301 return;
2302 }
2303
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002305
2306 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2307 ASSERT_VK_SUCCESS(err);
2308
2309 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2310 (void)err;
2311
2312 m_errorMonitor->VerifyFound();
2313
2314 vkDestroyImage(m_device->device(), image, NULL);
2315 vkFreeMemory(m_device->device(), mem, NULL);
2316}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002317
Karl Schultz6addd812016-02-02 17:17:23 -07002318TEST_F(VkLayerTest, BindInvalidMemory) {
2319 VkResult err;
2320 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002321
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002323
Tobin Ehlisec598302015-09-15 15:02:17 -06002324 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002325
2326 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002327 VkImage image;
2328 VkDeviceMemory mem;
2329 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002330
Karl Schultz6addd812016-02-02 17:17:23 -07002331 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2332 const int32_t tex_width = 32;
2333 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002334
2335 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002336 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2337 image_create_info.pNext = NULL;
2338 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2339 image_create_info.format = tex_format;
2340 image_create_info.extent.width = tex_width;
2341 image_create_info.extent.height = tex_height;
2342 image_create_info.extent.depth = 1;
2343 image_create_info.mipLevels = 1;
2344 image_create_info.arrayLayers = 1;
2345 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2346 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2347 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2348 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002349
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002350 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002351 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2352 mem_alloc.pNext = NULL;
2353 mem_alloc.allocationSize = 0;
2354 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002355
Chia-I Wuf7458c52015-10-26 21:10:41 +08002356 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002357 ASSERT_VK_SUCCESS(err);
2358
Karl Schultz6addd812016-02-02 17:17:23 -07002359 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002360
2361 mem_alloc.allocationSize = mem_reqs.size;
2362
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002363 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002364 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002365
2366 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002367 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002368 ASSERT_VK_SUCCESS(err);
2369
2370 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002371 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002372
2373 // Try to bind free memory that has been freed
2374 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2375 // This may very well return an error.
2376 (void)err;
2377
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002378 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002379
Chia-I Wuf7458c52015-10-26 21:10:41 +08002380 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002381}
2382
Karl Schultz6addd812016-02-02 17:17:23 -07002383TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2384 VkResult err;
2385 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002388
Tobin Ehlisec598302015-09-15 15:02:17 -06002389 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002390
Karl Schultz6addd812016-02-02 17:17:23 -07002391 // Create an image object, allocate memory, destroy the object and then try
2392 // to bind it
2393 VkImage image;
2394 VkDeviceMemory mem;
2395 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002396
Karl Schultz6addd812016-02-02 17:17:23 -07002397 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2398 const int32_t tex_width = 32;
2399 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002400
2401 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002402 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2403 image_create_info.pNext = NULL;
2404 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2405 image_create_info.format = tex_format;
2406 image_create_info.extent.width = tex_width;
2407 image_create_info.extent.height = tex_height;
2408 image_create_info.extent.depth = 1;
2409 image_create_info.mipLevels = 1;
2410 image_create_info.arrayLayers = 1;
2411 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2412 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2413 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2414 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002415
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002416 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002417 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2418 mem_alloc.pNext = NULL;
2419 mem_alloc.allocationSize = 0;
2420 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002421
Chia-I Wuf7458c52015-10-26 21:10:41 +08002422 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002423 ASSERT_VK_SUCCESS(err);
2424
Karl Schultz6addd812016-02-02 17:17:23 -07002425 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002426
2427 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002428 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002429 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002430
2431 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002432 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002433 ASSERT_VK_SUCCESS(err);
2434
2435 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002436 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002437 ASSERT_VK_SUCCESS(err);
2438
2439 // Now Try to bind memory to this destroyed object
2440 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2441 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002442 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002443
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002444 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002445
Chia-I Wuf7458c52015-10-26 21:10:41 +08002446 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002447}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002448
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002449#endif // OBJ_TRACKER_TESTS
2450
Tobin Ehlis0788f522015-05-26 16:11:58 -06002451#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002452
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002453TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2454 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2455
2456 ASSERT_NO_FATAL_FAILURE(InitState());
2457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2458
2459 VkVertexInputBindingDescription input_binding;
2460 memset(&input_binding, 0, sizeof(input_binding));
2461
2462 VkVertexInputAttributeDescription input_attribs;
2463 memset(&input_attribs, 0, sizeof(input_attribs));
2464
2465 // Pick a really bad format for this purpose and make sure it should fail
2466 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2467 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2468 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2469 printf("Format unsuitable for test; skipped.\n");
2470 return;
2471 }
2472
2473 input_attribs.location = 0;
2474 char const *vsSource = "#version 450\n"
2475 "\n"
2476 "out gl_PerVertex {\n"
2477 " vec4 gl_Position;\n"
2478 "};\n"
2479 "void main(){\n"
2480 " gl_Position = vec4(1);\n"
2481 "}\n";
2482 char const *fsSource = "#version 450\n"
2483 "\n"
2484 "layout(location=0) out vec4 color;\n"
2485 "void main(){\n"
2486 " color = vec4(1);\n"
2487 "}\n";
2488
2489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2490 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2491 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2492
2493 VkPipelineObj pipe(m_device);
2494 pipe.AddColorAttachment();
2495 pipe.AddShader(&vs);
2496 pipe.AddShader(&fs);
2497
2498 pipe.AddVertexInputBindings(&input_binding, 1);
2499 pipe.AddVertexInputAttribs(&input_attribs, 1);
2500
2501 VkDescriptorSetObj descriptorSet(m_device);
2502 descriptorSet.AppendDummy();
2503 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2504
2505 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2506
2507 m_errorMonitor->VerifyFound();
2508}
2509
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002510TEST_F(VkLayerTest, ImageSampleCounts) {
2511
2512 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2513 "validation errors.");
2514 ASSERT_NO_FATAL_FAILURE(InitState());
2515
2516 VkMemoryPropertyFlags reqs = 0;
2517 VkImageCreateInfo image_create_info = {};
2518 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2519 image_create_info.pNext = NULL;
2520 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2521 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2522 image_create_info.extent.width = 256;
2523 image_create_info.extent.height = 256;
2524 image_create_info.extent.depth = 1;
2525 image_create_info.mipLevels = 1;
2526 image_create_info.arrayLayers = 1;
2527 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2528 image_create_info.flags = 0;
2529
2530 VkImageBlit blit_region = {};
2531 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2532 blit_region.srcSubresource.baseArrayLayer = 0;
2533 blit_region.srcSubresource.layerCount = 1;
2534 blit_region.srcSubresource.mipLevel = 0;
2535 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2536 blit_region.dstSubresource.baseArrayLayer = 0;
2537 blit_region.dstSubresource.layerCount = 1;
2538 blit_region.dstSubresource.mipLevel = 0;
2539
2540 // Create two images, the source with sampleCount = 2, and attempt to blit
2541 // between them
2542 {
2543 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002544 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002545 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002546 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002547 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002548 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002549 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002550 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002551 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2553 "of VK_SAMPLE_COUNT_2_BIT but "
2554 "must be VK_SAMPLE_COUNT_1_BIT");
2555 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2556 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002557 m_errorMonitor->VerifyFound();
2558 m_commandBuffer->EndCommandBuffer();
2559 }
2560
2561 // Create two images, the dest with sampleCount = 4, and attempt to blit
2562 // between them
2563 {
2564 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002565 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002566 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002567 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002568 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002569 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002570 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002571 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002572 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2574 "of VK_SAMPLE_COUNT_4_BIT but "
2575 "must be VK_SAMPLE_COUNT_1_BIT");
2576 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2577 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002578 m_errorMonitor->VerifyFound();
2579 m_commandBuffer->EndCommandBuffer();
2580 }
2581
2582 VkBufferImageCopy copy_region = {};
2583 copy_region.bufferRowLength = 128;
2584 copy_region.bufferImageHeight = 128;
2585 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2586 copy_region.imageSubresource.layerCount = 1;
2587 copy_region.imageExtent.height = 64;
2588 copy_region.imageExtent.width = 64;
2589 copy_region.imageExtent.depth = 1;
2590
2591 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2592 // buffer to image
2593 {
2594 vk_testing::Buffer src_buffer;
2595 VkMemoryPropertyFlags reqs = 0;
2596 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2597 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002598 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002599 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002600 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002601 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2603 "of VK_SAMPLE_COUNT_8_BIT but "
2604 "must be VK_SAMPLE_COUNT_1_BIT");
2605 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2606 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002607 m_errorMonitor->VerifyFound();
2608 m_commandBuffer->EndCommandBuffer();
2609 }
2610
2611 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2612 // image to buffer
2613 {
2614 vk_testing::Buffer dst_buffer;
2615 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2616 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002617 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002618 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002619 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002620 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2622 "of VK_SAMPLE_COUNT_2_BIT but "
2623 "must be VK_SAMPLE_COUNT_1_BIT");
2624 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002625 dst_buffer.handle(), 1, &copy_region);
2626 m_errorMonitor->VerifyFound();
2627 m_commandBuffer->EndCommandBuffer();
2628 }
2629}
2630
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002631TEST_F(VkLayerTest, BlitImageFormats) {
2632
2633 // Image blit with mismatched formats
2634 const char * expected_message =
2635 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2636 " the other one must also have signed/unsigned integer format";
2637
2638 ASSERT_NO_FATAL_FAILURE(InitState());
2639
2640 VkImageObj src_image(m_device);
2641 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2642 VkImageObj dst_image(m_device);
2643 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2644 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002645 dst_image2.init(64, 64, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002646
2647 VkImageBlit blitRegion = {};
2648 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2649 blitRegion.srcSubresource.baseArrayLayer = 0;
2650 blitRegion.srcSubresource.layerCount = 1;
2651 blitRegion.srcSubresource.mipLevel = 0;
2652 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2653 blitRegion.dstSubresource.baseArrayLayer = 0;
2654 blitRegion.dstSubresource.layerCount = 1;
2655 blitRegion.dstSubresource.mipLevel = 0;
2656
2657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2658
2659 // Unsigned int vs not an int
2660 BeginCommandBuffer();
2661 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2662 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2663
2664 m_errorMonitor->VerifyFound();
2665
2666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2667
2668 // Unsigned int vs signed int
2669 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2670 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2671
2672 m_errorMonitor->VerifyFound();
2673
2674 EndCommandBuffer();
2675}
2676
2677
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002678TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2679 VkResult err;
2680 bool pass;
2681
2682 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2683 ASSERT_NO_FATAL_FAILURE(InitState());
2684
2685 // If w/d/h granularity is 1, test is not meaningful
2686 // TODO: When virtual device limits are available, create a set of limits for this test that
2687 // will always have a granularity of > 1 for w, h, and d
2688 auto index = m_device->graphics_queue_node_index_;
2689 auto queue_family_properties = m_device->phy().queue_properties();
2690
2691 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2692 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2693 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2694 return;
2695 }
2696
2697 // Create two images of different types and try to copy between them
2698 VkImage srcImage;
2699 VkImage dstImage;
2700 VkDeviceMemory srcMem;
2701 VkDeviceMemory destMem;
2702 VkMemoryRequirements memReqs;
2703
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002704 VkImageCreateInfo image_create_info = {};
2705 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2706 image_create_info.pNext = NULL;
2707 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2708 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2709 image_create_info.extent.width = 32;
2710 image_create_info.extent.height = 32;
2711 image_create_info.extent.depth = 1;
2712 image_create_info.mipLevels = 1;
2713 image_create_info.arrayLayers = 4;
2714 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2715 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2716 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2717 image_create_info.flags = 0;
2718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002719 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002720 ASSERT_VK_SUCCESS(err);
2721
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002722 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002723 ASSERT_VK_SUCCESS(err);
2724
2725 // Allocate memory
2726 VkMemoryAllocateInfo memAlloc = {};
2727 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2728 memAlloc.pNext = NULL;
2729 memAlloc.allocationSize = 0;
2730 memAlloc.memoryTypeIndex = 0;
2731
2732 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2733 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002734 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002735 ASSERT_TRUE(pass);
2736 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2737 ASSERT_VK_SUCCESS(err);
2738
2739 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2740 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002741 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002742 ASSERT_VK_SUCCESS(err);
2743 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2744 ASSERT_VK_SUCCESS(err);
2745
2746 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2747 ASSERT_VK_SUCCESS(err);
2748 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2749 ASSERT_VK_SUCCESS(err);
2750
2751 BeginCommandBuffer();
2752 VkImageCopy copyRegion;
2753 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2754 copyRegion.srcSubresource.mipLevel = 0;
2755 copyRegion.srcSubresource.baseArrayLayer = 0;
2756 copyRegion.srcSubresource.layerCount = 1;
2757 copyRegion.srcOffset.x = 0;
2758 copyRegion.srcOffset.y = 0;
2759 copyRegion.srcOffset.z = 0;
2760 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2761 copyRegion.dstSubresource.mipLevel = 0;
2762 copyRegion.dstSubresource.baseArrayLayer = 0;
2763 copyRegion.dstSubresource.layerCount = 1;
2764 copyRegion.dstOffset.x = 0;
2765 copyRegion.dstOffset.y = 0;
2766 copyRegion.dstOffset.z = 0;
2767 copyRegion.extent.width = 1;
2768 copyRegion.extent.height = 1;
2769 copyRegion.extent.depth = 1;
2770
2771 // Introduce failure by setting srcOffset to a bad granularity value
2772 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2774 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002775 m_errorMonitor->VerifyFound();
2776
2777 // Introduce failure by setting extent to a bad granularity value
2778 copyRegion.srcOffset.y = 0;
2779 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2781 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002782 m_errorMonitor->VerifyFound();
2783
2784 // Now do some buffer/image copies
2785 vk_testing::Buffer buffer;
2786 VkMemoryPropertyFlags reqs = 0;
2787 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2788 VkBufferImageCopy region = {};
2789 region.bufferOffset = 0;
2790 region.bufferRowLength = 3;
2791 region.bufferImageHeight = 128;
2792 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2793 region.imageSubresource.layerCount = 1;
2794 region.imageExtent.height = 16;
2795 region.imageExtent.width = 16;
2796 region.imageExtent.depth = 1;
2797 region.imageOffset.x = 0;
2798 region.imageOffset.y = 0;
2799 region.imageOffset.z = 0;
2800
2801 // Introduce failure by setting bufferRowLength to a bad granularity value
2802 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2804 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2805 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002806 m_errorMonitor->VerifyFound();
2807 region.bufferRowLength = 128;
2808
2809 // Introduce failure by setting bufferOffset to a bad granularity value
2810 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2812 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2813 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002814 m_errorMonitor->VerifyFound();
2815 region.bufferOffset = 0;
2816
2817 // Introduce failure by setting bufferImageHeight to a bad granularity value
2818 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2820 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2821 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002822 m_errorMonitor->VerifyFound();
2823 region.bufferImageHeight = 128;
2824
2825 // Introduce failure by setting imageExtent to a bad granularity value
2826 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2828 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2829 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002830 m_errorMonitor->VerifyFound();
2831 region.imageExtent.width = 16;
2832
2833 // Introduce failure by setting imageOffset to a bad granularity value
2834 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2836 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2837 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002838 m_errorMonitor->VerifyFound();
2839
2840 EndCommandBuffer();
2841
2842 vkDestroyImage(m_device->device(), srcImage, NULL);
2843 vkDestroyImage(m_device->device(), dstImage, NULL);
2844 vkFreeMemory(m_device->device(), srcMem, NULL);
2845 vkFreeMemory(m_device->device(), destMem, NULL);
2846}
2847
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002848TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002849 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2850 "attempt to submit them on a queue created in a different "
2851 "queue family.");
2852
Cody Northropc31a84f2016-08-22 10:41:47 -06002853 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002854 // This test is meaningless unless we have multiple queue families
2855 auto queue_family_properties = m_device->phy().queue_properties();
2856 if (queue_family_properties.size() < 2) {
2857 return;
2858 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002860 // Get safe index of another queue family
2861 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2862 ASSERT_NO_FATAL_FAILURE(InitState());
2863 // Create a second queue using a different queue family
2864 VkQueue other_queue;
2865 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2866
2867 // Record an empty cmd buffer
2868 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2869 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2870 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2871 vkEndCommandBuffer(m_commandBuffer->handle());
2872
2873 // And submit on the wrong queue
2874 VkSubmitInfo submit_info = {};
2875 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2876 submit_info.commandBufferCount = 1;
2877 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002878 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002879
2880 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002881}
2882
Chris Forbes4c24a922016-11-16 08:59:10 +13002883TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2884 ASSERT_NO_FATAL_FAILURE(InitState());
2885
2886 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2887 VkSubpassDescription subpasses[] = {
2888 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr },
2889 };
2890
2891 VkRenderPassCreateInfo rpci = {
2892 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2893 0, 0, nullptr, 1, subpasses, 0, nullptr
2894 };
2895 VkRenderPass rp;
2896
2897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2898 "must be less than the total number of attachments");
2899 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2900 m_errorMonitor->VerifyFound();
2901}
2902
Chris Forbesa58c4522016-09-28 15:19:39 +13002903TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2904 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2905 ASSERT_NO_FATAL_FAILURE(InitState());
2906
2907 // A renderpass with two subpasses, both writing the same attachment.
2908 VkAttachmentDescription attach[] = {
2909 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2910 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2911 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2912 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2913 },
2914 };
2915 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2916 VkSubpassDescription subpasses[] = {
2917 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2918 1, &ref, nullptr, nullptr, 0, nullptr },
2919 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2920 1, &ref, nullptr, nullptr, 0, nullptr },
2921 };
2922 VkSubpassDependency dep = {
2923 0, 1,
2924 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2925 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2926 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2927 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2928 VK_DEPENDENCY_BY_REGION_BIT
2929 };
2930 VkRenderPassCreateInfo rpci = {
2931 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2932 0, 1, attach, 2, subpasses, 1, &dep
2933 };
2934 VkRenderPass rp;
2935 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2936 ASSERT_VK_SUCCESS(err);
2937
2938 VkImageObj image(m_device);
2939 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2940 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2941 VK_IMAGE_TILING_OPTIMAL, 0);
2942 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2943
2944 VkFramebufferCreateInfo fbci = {
2945 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2946 0, rp, 1, &imageView, 32, 32, 1
2947 };
2948 VkFramebuffer fb;
2949 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2950 ASSERT_VK_SUCCESS(err);
2951
2952 char const *vsSource =
2953 "#version 450\n"
2954 "void main() { gl_Position = vec4(1); }\n";
2955 char const *fsSource =
2956 "#version 450\n"
2957 "layout(location=0) out vec4 color;\n"
2958 "void main() { color = vec4(1); }\n";
2959
2960 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2961 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2962 VkPipelineObj pipe(m_device);
2963 pipe.AddColorAttachment();
2964 pipe.AddShader(&vs);
2965 pipe.AddShader(&fs);
2966 VkViewport view_port = {};
2967 m_viewports.push_back(view_port);
2968 pipe.SetViewport(m_viewports);
2969 VkRect2D rect = {};
2970 m_scissors.push_back(rect);
2971 pipe.SetScissor(m_scissors);
2972
2973 VkPipelineLayoutCreateInfo plci = {
2974 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2975 0, 0, nullptr, 0, nullptr
2976 };
2977 VkPipelineLayout pl;
2978 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2979 ASSERT_VK_SUCCESS(err);
2980 pipe.CreateVKPipeline(pl, rp);
2981
2982 BeginCommandBuffer();
2983
2984 VkRenderPassBeginInfo rpbi = {
2985 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2986 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
2987 };
2988
2989 // subtest 1: bind in the wrong subpass
2990 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2991 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2993 "built for subpass 0 but used in subpass 1");
2994 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2995 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2996 m_errorMonitor->VerifyFound();
2997
2998 vkCmdEndRenderPass(m_commandBuffer->handle());
2999
3000 // subtest 2: bind in correct subpass, then transition to next subpass
3001 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3002 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3003 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3005 "built for subpass 0 but used in subpass 1");
3006 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3007 m_errorMonitor->VerifyFound();
3008
3009 vkCmdEndRenderPass(m_commandBuffer->handle());
3010
3011 EndCommandBuffer();
3012
3013 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3014 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3015 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3016}
3017
Tony Barbour4e919972016-08-09 13:27:40 -06003018TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3019 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3020 "with extent outside of framebuffer");
3021 ASSERT_NO_FATAL_FAILURE(InitState());
3022 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3025 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003026
3027 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3028 m_renderPassBeginInfo.renderArea.extent.width = 257;
3029 m_renderPassBeginInfo.renderArea.extent.height = 257;
3030 BeginCommandBuffer();
3031 m_errorMonitor->VerifyFound();
3032}
3033
3034TEST_F(VkLayerTest, DisabledIndependentBlend) {
3035 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3036 "blend and then specifying different blend states for two "
3037 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003038 VkPhysicalDeviceFeatures features = {};
3039 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003040 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003041
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3043 "Invalid Pipeline CreateInfo: If independent blend feature not "
3044 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003045
Cody Northropc31a84f2016-08-22 10:41:47 -06003046 VkDescriptorSetObj descriptorSet(m_device);
3047 descriptorSet.AppendDummy();
3048 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003049
Cody Northropc31a84f2016-08-22 10:41:47 -06003050 VkPipelineObj pipeline(m_device);
3051 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003052 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003053 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003054
Cody Northropc31a84f2016-08-22 10:41:47 -06003055 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3056 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3057 att_state1.blendEnable = VK_TRUE;
3058 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3059 att_state2.blendEnable = VK_FALSE;
3060 pipeline.AddColorAttachment(0, &att_state1);
3061 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003062 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003063 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003064}
3065
3066TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3067 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3068 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003069 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003070
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3072 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003073
3074 // Create a renderPass with a single color attachment
3075 VkAttachmentReference attach = {};
3076 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3077 VkSubpassDescription subpass = {};
3078 VkRenderPassCreateInfo rpci = {};
3079 rpci.subpassCount = 1;
3080 rpci.pSubpasses = &subpass;
3081 rpci.attachmentCount = 1;
3082 VkAttachmentDescription attach_desc = {};
3083 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3084 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3085 rpci.pAttachments = &attach_desc;
3086 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3087 VkRenderPass rp;
3088 subpass.pDepthStencilAttachment = &attach;
3089 subpass.pColorAttachments = NULL;
3090 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3091 m_errorMonitor->VerifyFound();
3092}
3093
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003094TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3095 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3096 "attachment reference of VK_ATTACHMENT_UNUSED");
3097
3098 ASSERT_NO_FATAL_FAILURE(InitState());
3099 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3100
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003102
3103 VkAttachmentReference color_attach = {};
3104 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3105 color_attach.attachment = 0;
3106 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3107 VkSubpassDescription subpass = {};
3108 subpass.colorAttachmentCount = 1;
3109 subpass.pColorAttachments = &color_attach;
3110 subpass.preserveAttachmentCount = 1;
3111 subpass.pPreserveAttachments = &preserve_attachment;
3112
3113 VkRenderPassCreateInfo rpci = {};
3114 rpci.subpassCount = 1;
3115 rpci.pSubpasses = &subpass;
3116 rpci.attachmentCount = 1;
3117 VkAttachmentDescription attach_desc = {};
3118 attach_desc.format = VK_FORMAT_UNDEFINED;
3119 rpci.pAttachments = &attach_desc;
3120 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3121 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003122 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003123
3124 m_errorMonitor->VerifyFound();
3125
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003126 if (result == VK_SUCCESS) {
3127 vkDestroyRenderPass(m_device->device(), rp, NULL);
3128 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003129}
3130
Chris Forbesc5389742016-06-29 11:49:23 +12003131TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003132 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3133 "when the source of a subpass multisample resolve "
3134 "does not have multiple samples.");
3135
Chris Forbesc5389742016-06-29 11:49:23 +12003136 ASSERT_NO_FATAL_FAILURE(InitState());
3137
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3139 "Subpass 0 requests multisample resolve from attachment 0 which has "
3140 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003141
3142 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003143 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3144 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3145 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3146 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3147 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3148 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003149 };
3150
3151 VkAttachmentReference color = {
3152 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3153 };
3154
3155 VkAttachmentReference resolve = {
3156 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3157 };
3158
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003159 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003160
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003161 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003162
3163 VkRenderPass rp;
3164 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3165
3166 m_errorMonitor->VerifyFound();
3167
3168 if (err == VK_SUCCESS)
3169 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3170}
3171
3172TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003173 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3174 "when a subpass multisample resolve operation is "
3175 "requested, and the destination of that resolve has "
3176 "multiple samples.");
3177
Chris Forbesc5389742016-06-29 11:49:23 +12003178 ASSERT_NO_FATAL_FAILURE(InitState());
3179
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3181 "Subpass 0 requests multisample resolve into attachment 1, which "
3182 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003183
3184 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003185 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3186 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3187 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3188 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3189 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3190 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003191 };
3192
3193 VkAttachmentReference color = {
3194 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3195 };
3196
3197 VkAttachmentReference resolve = {
3198 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3199 };
3200
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003201 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003202
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003203 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003204
3205 VkRenderPass rp;
3206 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3207
3208 m_errorMonitor->VerifyFound();
3209
3210 if (err == VK_SUCCESS)
3211 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3212}
3213
Chris Forbes3f128ef2016-06-29 14:58:53 +12003214TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003215 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3216 "when the color and depth attachments used by a subpass "
3217 "have inconsistent sample counts");
3218
Chris Forbes3f128ef2016-06-29 14:58:53 +12003219 ASSERT_NO_FATAL_FAILURE(InitState());
3220
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3222 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003223
3224 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003225 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3226 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3227 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3228 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3229 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3230 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003231 };
3232
3233 VkAttachmentReference color[] = {
3234 {
3235 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3236 },
3237 {
3238 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3239 },
3240 };
3241
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003242 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003243
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003244 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003245
3246 VkRenderPass rp;
3247 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3248
3249 m_errorMonitor->VerifyFound();
3250
3251 if (err == VK_SUCCESS)
3252 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3253}
3254
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003255TEST_F(VkLayerTest, FramebufferCreateErrors) {
3256 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003257 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003258 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003259 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3260 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3261 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3262 " 6. Framebuffer attachment where dimensions don't match\n"
3263 " 7. Framebuffer attachment w/o identity swizzle\n"
3264 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003265
3266 ASSERT_NO_FATAL_FAILURE(InitState());
3267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3268
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3270 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3271 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003272
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003273 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003274 VkAttachmentReference attach = {};
3275 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3276 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003277 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003278 VkRenderPassCreateInfo rpci = {};
3279 rpci.subpassCount = 1;
3280 rpci.pSubpasses = &subpass;
3281 rpci.attachmentCount = 1;
3282 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003283 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003284 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003285 rpci.pAttachments = &attach_desc;
3286 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3287 VkRenderPass rp;
3288 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3289 ASSERT_VK_SUCCESS(err);
3290
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003291 VkImageView ivs[2];
3292 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3293 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003294 VkFramebufferCreateInfo fb_info = {};
3295 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3296 fb_info.pNext = NULL;
3297 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003298 // Set mis-matching attachmentCount
3299 fb_info.attachmentCount = 2;
3300 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003301 fb_info.width = 100;
3302 fb_info.height = 100;
3303 fb_info.layers = 1;
3304
3305 VkFramebuffer fb;
3306 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3307
3308 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003309 if (err == VK_SUCCESS) {
3310 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3311 }
3312 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003313
3314 // Create a renderPass with a depth-stencil attachment created with
3315 // IMAGE_USAGE_COLOR_ATTACHMENT
3316 // Add our color attachment to pDepthStencilAttachment
3317 subpass.pDepthStencilAttachment = &attach;
3318 subpass.pColorAttachments = NULL;
3319 VkRenderPass rp_ds;
3320 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3321 ASSERT_VK_SUCCESS(err);
3322 // Set correct attachment count, but attachment has COLOR usage bit set
3323 fb_info.attachmentCount = 1;
3324 fb_info.renderPass = rp_ds;
3325
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003327 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3328
3329 m_errorMonitor->VerifyFound();
3330 if (err == VK_SUCCESS) {
3331 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3332 }
3333 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003334
3335 // Create new renderpass with alternate attachment format from fb
3336 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3337 subpass.pDepthStencilAttachment = NULL;
3338 subpass.pColorAttachments = &attach;
3339 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3340 ASSERT_VK_SUCCESS(err);
3341
3342 // Cause error due to mis-matched formats between rp & fb
3343 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3344 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3346 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -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 Ehlis77d717c2016-06-22 14:19:19 -06003353 vkDestroyRenderPass(m_device->device(), rp, NULL);
3354
3355 // Create new renderpass with alternate sample count from fb
3356 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3357 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3358 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3359 ASSERT_VK_SUCCESS(err);
3360
3361 // Cause error due to mis-matched sample count between rp & fb
3362 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3364 "that do not match the "
3365 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003366 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3367
3368 m_errorMonitor->VerifyFound();
3369 if (err == VK_SUCCESS) {
3370 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3371 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003372
3373 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003374
3375 // Create a custom imageView with non-1 mip levels
3376 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003377 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 -06003378 ASSERT_TRUE(image.initialized());
3379
3380 VkImageView view;
3381 VkImageViewCreateInfo ivci = {};
3382 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3383 ivci.image = image.handle();
3384 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3385 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3386 ivci.subresourceRange.layerCount = 1;
3387 ivci.subresourceRange.baseMipLevel = 0;
3388 // Set level count 2 (only 1 is allowed for FB attachment)
3389 ivci.subresourceRange.levelCount = 2;
3390 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3391 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3392 ASSERT_VK_SUCCESS(err);
3393 // Re-create renderpass to have matching sample count
3394 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3395 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3396 ASSERT_VK_SUCCESS(err);
3397
3398 fb_info.renderPass = rp;
3399 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003401 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3402
3403 m_errorMonitor->VerifyFound();
3404 if (err == VK_SUCCESS) {
3405 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3406 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003407 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003408 // Update view to original color buffer and grow FB dimensions too big
3409 fb_info.pAttachments = ivs;
3410 fb_info.height = 1024;
3411 fb_info.width = 1024;
3412 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3414 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003415 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3416
3417 m_errorMonitor->VerifyFound();
3418 if (err == VK_SUCCESS) {
3419 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3420 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003421 // Create view attachment with non-identity swizzle
3422 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3423 ivci.image = image.handle();
3424 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3425 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3426 ivci.subresourceRange.layerCount = 1;
3427 ivci.subresourceRange.baseMipLevel = 0;
3428 ivci.subresourceRange.levelCount = 1;
3429 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3430 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3431 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3432 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3433 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3434 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3435 ASSERT_VK_SUCCESS(err);
3436
3437 fb_info.pAttachments = &view;
3438 fb_info.height = 100;
3439 fb_info.width = 100;
3440 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3442 "framebuffer attachments must have "
3443 "been created with the identity "
3444 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003445 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3446
3447 m_errorMonitor->VerifyFound();
3448 if (err == VK_SUCCESS) {
3449 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3450 }
3451 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003452 // Request fb that exceeds max dimensions
3453 // reset attachment to color attachment
3454 fb_info.pAttachments = ivs;
3455 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3456 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3457 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3459 "dimensions exceed physical device "
3460 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003461 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3462
3463 m_errorMonitor->VerifyFound();
3464 if (err == VK_SUCCESS) {
3465 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3466 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003467
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003468 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003469}
3470
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003471TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003472 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3473 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003474
Cody Northropc31a84f2016-08-22 10:41:47 -06003475 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003476 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3478 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003479 m_errorMonitor->VerifyFound();
3480}
3481
3482TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003483 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3484 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003485
Cody Northropc31a84f2016-08-22 10:41:47 -06003486 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003487 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3489 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003490 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003491}
3492
3493TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003494 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3495 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003496
Cody Northropc31a84f2016-08-22 10:41:47 -06003497 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003498 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003499 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 -06003500 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003501 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003502}
3503
3504TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003505 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3506 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003507
Cody Northropc31a84f2016-08-22 10:41:47 -06003508 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003509 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003510 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 -06003511 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003512 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003513}
3514
Cortd713fe82016-07-27 09:51:27 -07003515TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003516 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3517 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003518
3519 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003520 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3522 "Dynamic blend constants state not set for this command buffer");
3523 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003524 m_errorMonitor->VerifyFound();
3525}
3526
3527TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003528 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3529 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003530
3531 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003532 if (!m_device->phy().features().depthBounds) {
3533 printf("Device does not support depthBounds test; skipped.\n");
3534 return;
3535 }
3536 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3538 "Dynamic depth bounds state not set for this command buffer");
3539 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003540 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003541}
3542
3543TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003544 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3545 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003546
3547 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003548 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3550 "Dynamic stencil read mask state not set for this command buffer");
3551 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003552 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003553}
3554
3555TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003556 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3557 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003558
3559 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003560 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3562 "Dynamic stencil write mask state not set for this command buffer");
3563 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003564 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003565}
3566
3567TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003568 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3569 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003570
3571 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003572 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3574 "Dynamic stencil reference state not set for this command buffer");
3575 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003576 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003577}
3578
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003579TEST_F(VkLayerTest, IndexBufferNotBound) {
3580 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003581
3582 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3584 "Index buffer object not bound to this command buffer when Indexed ");
3585 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003586 m_errorMonitor->VerifyFound();
3587}
3588
Karl Schultz6addd812016-02-02 17:17:23 -07003589TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3591 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3592 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003593
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003594 ASSERT_NO_FATAL_FAILURE(InitState());
3595 ASSERT_NO_FATAL_FAILURE(InitViewport());
3596 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3597
Karl Schultz6addd812016-02-02 17:17:23 -07003598 // We luck out b/c by default the framework creates CB w/ the
3599 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003600 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003601 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003602 EndCommandBuffer();
3603
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003604 // Bypass framework since it does the waits automatically
3605 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003606 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003607 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3608 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003609 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003610 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003611 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003612 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003613 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003614 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003615 submit_info.pSignalSemaphores = NULL;
3616
Chris Forbes40028e22016-06-13 09:59:34 +12003617 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003618 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003619 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003620
Karl Schultz6addd812016-02-02 17:17:23 -07003621 // Cause validation error by re-submitting cmd buffer that should only be
3622 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003623 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003624 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003625
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003626 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003627}
3628
Karl Schultz6addd812016-02-02 17:17:23 -07003629TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003630 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07003631 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003632
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
3634 "type "
3635 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003636
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003637 ASSERT_NO_FATAL_FAILURE(InitState());
3638 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003639
Karl Schultz6addd812016-02-02 17:17:23 -07003640 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3641 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003642 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003643 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3644 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003645
3646 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003647 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3648 ds_pool_ci.pNext = NULL;
3649 ds_pool_ci.flags = 0;
3650 ds_pool_ci.maxSets = 1;
3651 ds_pool_ci.poolSizeCount = 1;
3652 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003653
3654 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003655 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003656 ASSERT_VK_SUCCESS(err);
3657
3658 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003659 dsl_binding.binding = 0;
3660 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3661 dsl_binding.descriptorCount = 1;
3662 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3663 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003664
3665 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003666 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3667 ds_layout_ci.pNext = NULL;
3668 ds_layout_ci.bindingCount = 1;
3669 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003670
3671 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003672 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003673 ASSERT_VK_SUCCESS(err);
3674
3675 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003676 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003677 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003678 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003679 alloc_info.descriptorPool = ds_pool;
3680 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003681 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003682
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003683 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003684
Chia-I Wuf7458c52015-10-26 21:10:41 +08003685 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3686 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003687}
3688
Karl Schultz6addd812016-02-02 17:17:23 -07003689TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3690 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003691
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3693 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3694 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003695
Tobin Ehlise735c692015-10-08 13:13:50 -06003696 ASSERT_NO_FATAL_FAILURE(InitState());
3697 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003698
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003699 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003700 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3701 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003702
3703 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003704 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3705 ds_pool_ci.pNext = NULL;
3706 ds_pool_ci.maxSets = 1;
3707 ds_pool_ci.poolSizeCount = 1;
3708 ds_pool_ci.flags = 0;
3709 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3710 // app can only call vkResetDescriptorPool on this pool.;
3711 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003712
3713 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003714 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003715 ASSERT_VK_SUCCESS(err);
3716
3717 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003718 dsl_binding.binding = 0;
3719 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3720 dsl_binding.descriptorCount = 1;
3721 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3722 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003723
3724 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003725 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3726 ds_layout_ci.pNext = NULL;
3727 ds_layout_ci.bindingCount = 1;
3728 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003729
3730 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003731 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003732 ASSERT_VK_SUCCESS(err);
3733
3734 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003735 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003736 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003737 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003738 alloc_info.descriptorPool = ds_pool;
3739 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003740 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003741 ASSERT_VK_SUCCESS(err);
3742
3743 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003744 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003745
Chia-I Wuf7458c52015-10-26 21:10:41 +08003746 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3747 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003748}
3749
Karl Schultz6addd812016-02-02 17:17:23 -07003750TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003751 // Attempt to clear Descriptor Pool with bad object.
3752 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003753
3754 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003756 uint64_t fake_pool_handle = 0xbaad6001;
3757 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3758 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003759 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003760}
3761
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003762TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003763 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3764 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003765 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003766 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003767
3768 uint64_t fake_set_handle = 0xbaad6001;
3769 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003770 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003772
3773 ASSERT_NO_FATAL_FAILURE(InitState());
3774
3775 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3776 layout_bindings[0].binding = 0;
3777 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3778 layout_bindings[0].descriptorCount = 1;
3779 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3780 layout_bindings[0].pImmutableSamplers = NULL;
3781
3782 VkDescriptorSetLayout descriptor_set_layout;
3783 VkDescriptorSetLayoutCreateInfo dslci = {};
3784 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3785 dslci.pNext = NULL;
3786 dslci.bindingCount = 1;
3787 dslci.pBindings = layout_bindings;
3788 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003789 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003790
3791 VkPipelineLayout pipeline_layout;
3792 VkPipelineLayoutCreateInfo plci = {};
3793 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3794 plci.pNext = NULL;
3795 plci.setLayoutCount = 1;
3796 plci.pSetLayouts = &descriptor_set_layout;
3797 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003798 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003799
3800 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003801 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3802 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003803 m_errorMonitor->VerifyFound();
3804 EndCommandBuffer();
3805 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3806 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003807}
3808
Karl Schultz6addd812016-02-02 17:17:23 -07003809TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003810 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3811 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003812 uint64_t fake_layout_handle = 0xbaad6001;
3813 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003815 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003816 VkPipelineLayout pipeline_layout;
3817 VkPipelineLayoutCreateInfo plci = {};
3818 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3819 plci.pNext = NULL;
3820 plci.setLayoutCount = 1;
3821 plci.pSetLayouts = &bad_layout;
3822 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3823
3824 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003825}
3826
Mark Muellerd4914412016-06-13 17:52:06 -06003827TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3828 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3829 "1) A uniform buffer update must have a valid buffer index."
3830 "2) When using an array of descriptors in a single WriteDescriptor,"
3831 " the descriptor types and stageflags must all be the same."
3832 "3) Immutable Sampler state must match across descriptors");
3833
3834 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003835 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3836 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3837 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3838 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3839 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003840
Mark Muellerd4914412016-06-13 17:52:06 -06003841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3842
3843 ASSERT_NO_FATAL_FAILURE(InitState());
3844 VkDescriptorPoolSize ds_type_count[4] = {};
3845 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3846 ds_type_count[0].descriptorCount = 1;
3847 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3848 ds_type_count[1].descriptorCount = 1;
3849 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3850 ds_type_count[2].descriptorCount = 1;
3851 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3852 ds_type_count[3].descriptorCount = 1;
3853
3854 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3855 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3856 ds_pool_ci.maxSets = 1;
3857 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3858 ds_pool_ci.pPoolSizes = ds_type_count;
3859
3860 VkDescriptorPool ds_pool;
3861 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3862 ASSERT_VK_SUCCESS(err);
3863
Mark Muellerb9896722016-06-16 09:54:29 -06003864 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003865 layout_binding[0].binding = 0;
3866 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3867 layout_binding[0].descriptorCount = 1;
3868 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3869 layout_binding[0].pImmutableSamplers = NULL;
3870
3871 layout_binding[1].binding = 1;
3872 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3873 layout_binding[1].descriptorCount = 1;
3874 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3875 layout_binding[1].pImmutableSamplers = NULL;
3876
3877 VkSamplerCreateInfo sampler_ci = {};
3878 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3879 sampler_ci.pNext = NULL;
3880 sampler_ci.magFilter = VK_FILTER_NEAREST;
3881 sampler_ci.minFilter = VK_FILTER_NEAREST;
3882 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3883 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3884 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3885 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3886 sampler_ci.mipLodBias = 1.0;
3887 sampler_ci.anisotropyEnable = VK_FALSE;
3888 sampler_ci.maxAnisotropy = 1;
3889 sampler_ci.compareEnable = VK_FALSE;
3890 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3891 sampler_ci.minLod = 1.0;
3892 sampler_ci.maxLod = 1.0;
3893 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3894 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3895 VkSampler sampler;
3896
3897 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3898 ASSERT_VK_SUCCESS(err);
3899
3900 layout_binding[2].binding = 2;
3901 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3902 layout_binding[2].descriptorCount = 1;
3903 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3904 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3905
Mark Muellerd4914412016-06-13 17:52:06 -06003906 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3907 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3908 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3909 ds_layout_ci.pBindings = layout_binding;
3910 VkDescriptorSetLayout ds_layout;
3911 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3912 ASSERT_VK_SUCCESS(err);
3913
3914 VkDescriptorSetAllocateInfo alloc_info = {};
3915 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3916 alloc_info.descriptorSetCount = 1;
3917 alloc_info.descriptorPool = ds_pool;
3918 alloc_info.pSetLayouts = &ds_layout;
3919 VkDescriptorSet descriptorSet;
3920 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3921 ASSERT_VK_SUCCESS(err);
3922
3923 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3924 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3925 pipeline_layout_ci.pNext = NULL;
3926 pipeline_layout_ci.setLayoutCount = 1;
3927 pipeline_layout_ci.pSetLayouts = &ds_layout;
3928
3929 VkPipelineLayout pipeline_layout;
3930 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3931 ASSERT_VK_SUCCESS(err);
3932
Mark Mueller5c838ce2016-06-16 09:54:29 -06003933 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003934 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3935 descriptor_write.dstSet = descriptorSet;
3936 descriptor_write.dstBinding = 0;
3937 descriptor_write.descriptorCount = 1;
3938 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3939
Mark Mueller5c838ce2016-06-16 09:54:29 -06003940 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003941 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3942 m_errorMonitor->VerifyFound();
3943
3944 // Create a buffer to update the descriptor with
3945 uint32_t qfi = 0;
3946 VkBufferCreateInfo buffCI = {};
3947 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3948 buffCI.size = 1024;
3949 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3950 buffCI.queueFamilyIndexCount = 1;
3951 buffCI.pQueueFamilyIndices = &qfi;
3952
3953 VkBuffer dyub;
3954 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3955 ASSERT_VK_SUCCESS(err);
3956 VkDescriptorBufferInfo buffInfo = {};
3957 buffInfo.buffer = dyub;
3958 buffInfo.offset = 0;
3959 buffInfo.range = 1024;
3960
3961 descriptor_write.pBufferInfo = &buffInfo;
3962 descriptor_write.descriptorCount = 2;
3963
Mark Mueller5c838ce2016-06-16 09:54:29 -06003964 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3966 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3967 m_errorMonitor->VerifyFound();
3968
Mark Mueller5c838ce2016-06-16 09:54:29 -06003969 // 3) The second descriptor has a null_ptr pImmutableSamplers and
3970 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06003971 descriptor_write.dstBinding = 1;
3972 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06003973
Mark Mueller5c838ce2016-06-16 09:54:29 -06003974 // Make pImageInfo index non-null to avoid complaints of it missing
3975 VkDescriptorImageInfo imageInfo = {};
3976 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3977 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06003978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
3979 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3980 m_errorMonitor->VerifyFound();
3981
Mark Muellerd4914412016-06-13 17:52:06 -06003982 vkDestroyBuffer(m_device->device(), dyub, NULL);
3983 vkDestroySampler(m_device->device(), sampler, NULL);
3984 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3985 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3986 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3987}
3988
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003989TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
3990 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
3991 "due to a buffer dependency being destroyed.");
3992 ASSERT_NO_FATAL_FAILURE(InitState());
3993
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003994 VkBuffer buffer;
3995 VkDeviceMemory mem;
3996 VkMemoryRequirements mem_reqs;
3997
3998 VkBufferCreateInfo buf_info = {};
3999 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004000 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004001 buf_info.size = 256;
4002 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4003 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4004 ASSERT_VK_SUCCESS(err);
4005
4006 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4007
4008 VkMemoryAllocateInfo alloc_info = {};
4009 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4010 alloc_info.allocationSize = 256;
4011 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004012 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 -06004013 if (!pass) {
4014 vkDestroyBuffer(m_device->device(), buffer, NULL);
4015 return;
4016 }
4017 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4018 ASSERT_VK_SUCCESS(err);
4019
4020 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4021 ASSERT_VK_SUCCESS(err);
4022
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004023 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004024 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004025 m_commandBuffer->EndCommandBuffer();
4026
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004028 // Destroy buffer dependency prior to submit to cause ERROR
4029 vkDestroyBuffer(m_device->device(), buffer, NULL);
4030
4031 VkSubmitInfo submit_info = {};
4032 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4033 submit_info.commandBufferCount = 1;
4034 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4035 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4036
4037 m_errorMonitor->VerifyFound();
4038 vkFreeMemory(m_device->handle(), mem, NULL);
4039}
4040
Tobin Ehlisea413442016-09-28 10:23:59 -06004041TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4042 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4043
4044 ASSERT_NO_FATAL_FAILURE(InitState());
4045 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4046
4047 VkDescriptorPoolSize ds_type_count;
4048 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4049 ds_type_count.descriptorCount = 1;
4050
4051 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4052 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4053 ds_pool_ci.maxSets = 1;
4054 ds_pool_ci.poolSizeCount = 1;
4055 ds_pool_ci.pPoolSizes = &ds_type_count;
4056
4057 VkDescriptorPool ds_pool;
4058 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4059 ASSERT_VK_SUCCESS(err);
4060
4061 VkDescriptorSetLayoutBinding layout_binding;
4062 layout_binding.binding = 0;
4063 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4064 layout_binding.descriptorCount = 1;
4065 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4066 layout_binding.pImmutableSamplers = NULL;
4067
4068 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4069 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4070 ds_layout_ci.bindingCount = 1;
4071 ds_layout_ci.pBindings = &layout_binding;
4072 VkDescriptorSetLayout ds_layout;
4073 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4074 ASSERT_VK_SUCCESS(err);
4075
4076 VkDescriptorSetAllocateInfo alloc_info = {};
4077 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4078 alloc_info.descriptorSetCount = 1;
4079 alloc_info.descriptorPool = ds_pool;
4080 alloc_info.pSetLayouts = &ds_layout;
4081 VkDescriptorSet descriptor_set;
4082 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4083 ASSERT_VK_SUCCESS(err);
4084
4085 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4086 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4087 pipeline_layout_ci.pNext = NULL;
4088 pipeline_layout_ci.setLayoutCount = 1;
4089 pipeline_layout_ci.pSetLayouts = &ds_layout;
4090
4091 VkPipelineLayout pipeline_layout;
4092 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4093 ASSERT_VK_SUCCESS(err);
4094
4095 VkBuffer buffer;
4096 uint32_t queue_family_index = 0;
4097 VkBufferCreateInfo buffer_create_info = {};
4098 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4099 buffer_create_info.size = 1024;
4100 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4101 buffer_create_info.queueFamilyIndexCount = 1;
4102 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4103
4104 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4105 ASSERT_VK_SUCCESS(err);
4106
4107 VkMemoryRequirements memory_reqs;
4108 VkDeviceMemory buffer_memory;
4109
4110 VkMemoryAllocateInfo memory_info = {};
4111 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4112 memory_info.allocationSize = 0;
4113 memory_info.memoryTypeIndex = 0;
4114
4115 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4116 memory_info.allocationSize = memory_reqs.size;
4117 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4118 ASSERT_TRUE(pass);
4119
4120 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4121 ASSERT_VK_SUCCESS(err);
4122 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4123 ASSERT_VK_SUCCESS(err);
4124
4125 VkBufferView view;
4126 VkBufferViewCreateInfo bvci = {};
4127 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4128 bvci.buffer = buffer;
4129 bvci.format = VK_FORMAT_R8_UNORM;
4130 bvci.range = VK_WHOLE_SIZE;
4131
4132 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4133 ASSERT_VK_SUCCESS(err);
4134
4135 VkWriteDescriptorSet descriptor_write = {};
4136 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4137 descriptor_write.dstSet = descriptor_set;
4138 descriptor_write.dstBinding = 0;
4139 descriptor_write.descriptorCount = 1;
4140 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4141 descriptor_write.pTexelBufferView = &view;
4142
4143 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4144
4145 char const *vsSource = "#version 450\n"
4146 "\n"
4147 "out gl_PerVertex { \n"
4148 " vec4 gl_Position;\n"
4149 "};\n"
4150 "void main(){\n"
4151 " gl_Position = vec4(1);\n"
4152 "}\n";
4153 char const *fsSource = "#version 450\n"
4154 "\n"
4155 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4156 "layout(location=0) out vec4 x;\n"
4157 "void main(){\n"
4158 " x = imageLoad(s, 0);\n"
4159 "}\n";
4160 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4161 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4162 VkPipelineObj pipe(m_device);
4163 pipe.AddShader(&vs);
4164 pipe.AddShader(&fs);
4165 pipe.AddColorAttachment();
4166 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4167
4168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4170
4171 BeginCommandBuffer();
4172 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4173 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4174 VkRect2D scissor = {{0, 0}, {16, 16}};
4175 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4176 // Bind pipeline to cmd buffer
4177 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4178 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4179 &descriptor_set, 0, nullptr);
4180 Draw(1, 0, 0, 0);
4181 EndCommandBuffer();
4182
4183 // Delete BufferView in order to invalidate cmd buffer
4184 vkDestroyBufferView(m_device->device(), view, NULL);
4185 // Now attempt submit of cmd buffer
4186 VkSubmitInfo submit_info = {};
4187 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4188 submit_info.commandBufferCount = 1;
4189 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4190 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4191 m_errorMonitor->VerifyFound();
4192
4193 // Clean-up
4194 vkDestroyBuffer(m_device->device(), buffer, NULL);
4195 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4196 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4197 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4198 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4199}
4200
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004201TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4202 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4203 "due to an image dependency being destroyed.");
4204 ASSERT_NO_FATAL_FAILURE(InitState());
4205
4206 VkImage image;
4207 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4208 VkImageCreateInfo image_create_info = {};
4209 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4210 image_create_info.pNext = NULL;
4211 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4212 image_create_info.format = tex_format;
4213 image_create_info.extent.width = 32;
4214 image_create_info.extent.height = 32;
4215 image_create_info.extent.depth = 1;
4216 image_create_info.mipLevels = 1;
4217 image_create_info.arrayLayers = 1;
4218 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4219 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004220 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004221 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004222 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004223 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004224 // Have to bind memory to image before recording cmd in cmd buffer using it
4225 VkMemoryRequirements mem_reqs;
4226 VkDeviceMemory image_mem;
4227 bool pass;
4228 VkMemoryAllocateInfo mem_alloc = {};
4229 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4230 mem_alloc.pNext = NULL;
4231 mem_alloc.memoryTypeIndex = 0;
4232 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4233 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004234 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004235 ASSERT_TRUE(pass);
4236 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4237 ASSERT_VK_SUCCESS(err);
4238 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4239 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004240
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004241 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004242 VkClearColorValue ccv;
4243 ccv.float32[0] = 1.0f;
4244 ccv.float32[1] = 1.0f;
4245 ccv.float32[2] = 1.0f;
4246 ccv.float32[3] = 1.0f;
4247 VkImageSubresourceRange isr = {};
4248 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004249 isr.baseArrayLayer = 0;
4250 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004251 isr.layerCount = 1;
4252 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004253 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004254 m_commandBuffer->EndCommandBuffer();
4255
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004257 // Destroy image dependency prior to submit to cause ERROR
4258 vkDestroyImage(m_device->device(), image, NULL);
4259
4260 VkSubmitInfo submit_info = {};
4261 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4262 submit_info.commandBufferCount = 1;
4263 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4264 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4265
4266 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004267 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004268}
4269
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004270TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4271 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4272 "due to a framebuffer image dependency being destroyed.");
4273 VkFormatProperties format_properties;
4274 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004275 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4276 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004277 return;
4278 }
4279
4280 ASSERT_NO_FATAL_FAILURE(InitState());
4281 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4282
4283 VkImageCreateInfo image_ci = {};
4284 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4285 image_ci.pNext = NULL;
4286 image_ci.imageType = VK_IMAGE_TYPE_2D;
4287 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4288 image_ci.extent.width = 32;
4289 image_ci.extent.height = 32;
4290 image_ci.extent.depth = 1;
4291 image_ci.mipLevels = 1;
4292 image_ci.arrayLayers = 1;
4293 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4294 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004295 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004296 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4297 image_ci.flags = 0;
4298 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004299 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004300
4301 VkMemoryRequirements memory_reqs;
4302 VkDeviceMemory image_memory;
4303 bool pass;
4304 VkMemoryAllocateInfo memory_info = {};
4305 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4306 memory_info.pNext = NULL;
4307 memory_info.allocationSize = 0;
4308 memory_info.memoryTypeIndex = 0;
4309 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4310 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004311 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004312 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004313 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004314 ASSERT_VK_SUCCESS(err);
4315 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4316 ASSERT_VK_SUCCESS(err);
4317
4318 VkImageViewCreateInfo ivci = {
4319 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4320 nullptr,
4321 0,
4322 image,
4323 VK_IMAGE_VIEW_TYPE_2D,
4324 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004325 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004326 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4327 };
4328 VkImageView view;
4329 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4330 ASSERT_VK_SUCCESS(err);
4331
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004332 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004333 VkFramebuffer fb;
4334 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4335 ASSERT_VK_SUCCESS(err);
4336
4337 // Just use default renderpass with our framebuffer
4338 m_renderPassBeginInfo.framebuffer = fb;
4339 // Create Null cmd buffer for submit
4340 BeginCommandBuffer();
4341 EndCommandBuffer();
4342 // Destroy image attached to framebuffer to invalidate cmd buffer
4343 vkDestroyImage(m_device->device(), image, NULL);
4344 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004346 QueueCommandBuffer(false);
4347 m_errorMonitor->VerifyFound();
4348
4349 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4350 vkDestroyImageView(m_device->device(), view, nullptr);
4351 vkFreeMemory(m_device->device(), image_memory, nullptr);
4352}
4353
Tobin Ehlisb329f992016-10-12 13:20:29 -06004354TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4355 TEST_DESCRIPTION("Delete in-use framebuffer.");
4356 VkFormatProperties format_properties;
4357 VkResult err = VK_SUCCESS;
4358 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4359
4360 ASSERT_NO_FATAL_FAILURE(InitState());
4361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4362
4363 VkImageObj image(m_device);
4364 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4365 ASSERT_TRUE(image.initialized());
4366 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4367
4368 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4369 VkFramebuffer fb;
4370 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4371 ASSERT_VK_SUCCESS(err);
4372
4373 // Just use default renderpass with our framebuffer
4374 m_renderPassBeginInfo.framebuffer = fb;
4375 // Create Null cmd buffer for submit
4376 BeginCommandBuffer();
4377 EndCommandBuffer();
4378 // Submit cmd buffer to put it in-flight
4379 VkSubmitInfo submit_info = {};
4380 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4381 submit_info.commandBufferCount = 1;
4382 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4383 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4384 // Destroy framebuffer while in-flight
4385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4386 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4387 m_errorMonitor->VerifyFound();
4388 // Wait for queue to complete so we can safely destroy everything
4389 vkQueueWaitIdle(m_device->m_queue);
4390 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4391}
4392
Tobin Ehlis88becd72016-09-21 14:33:41 -06004393TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4394 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4395 VkFormatProperties format_properties;
4396 VkResult err = VK_SUCCESS;
4397 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004398
4399 ASSERT_NO_FATAL_FAILURE(InitState());
4400 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4401
4402 VkImageCreateInfo image_ci = {};
4403 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4404 image_ci.pNext = NULL;
4405 image_ci.imageType = VK_IMAGE_TYPE_2D;
4406 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4407 image_ci.extent.width = 256;
4408 image_ci.extent.height = 256;
4409 image_ci.extent.depth = 1;
4410 image_ci.mipLevels = 1;
4411 image_ci.arrayLayers = 1;
4412 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4413 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004414 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004415 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4416 image_ci.flags = 0;
4417 VkImage image;
4418 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4419
4420 VkMemoryRequirements memory_reqs;
4421 VkDeviceMemory image_memory;
4422 bool pass;
4423 VkMemoryAllocateInfo memory_info = {};
4424 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4425 memory_info.pNext = NULL;
4426 memory_info.allocationSize = 0;
4427 memory_info.memoryTypeIndex = 0;
4428 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4429 memory_info.allocationSize = memory_reqs.size;
4430 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4431 ASSERT_TRUE(pass);
4432 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4433 ASSERT_VK_SUCCESS(err);
4434 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4435 ASSERT_VK_SUCCESS(err);
4436
4437 VkImageViewCreateInfo ivci = {
4438 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4439 nullptr,
4440 0,
4441 image,
4442 VK_IMAGE_VIEW_TYPE_2D,
4443 VK_FORMAT_B8G8R8A8_UNORM,
4444 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4445 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4446 };
4447 VkImageView view;
4448 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4449 ASSERT_VK_SUCCESS(err);
4450
4451 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4452 VkFramebuffer fb;
4453 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4454 ASSERT_VK_SUCCESS(err);
4455
4456 // Just use default renderpass with our framebuffer
4457 m_renderPassBeginInfo.framebuffer = fb;
4458 // Create Null cmd buffer for submit
4459 BeginCommandBuffer();
4460 EndCommandBuffer();
4461 // Submit cmd buffer to put it (and attached imageView) in-flight
4462 VkSubmitInfo submit_info = {};
4463 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4464 submit_info.commandBufferCount = 1;
4465 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4466 // Submit cmd buffer to put framebuffer and children in-flight
4467 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4468 // Destroy image attached to framebuffer while in-flight
4469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4470 vkDestroyImage(m_device->device(), image, NULL);
4471 m_errorMonitor->VerifyFound();
4472 // Wait for queue to complete so we can safely destroy image and other objects
4473 vkQueueWaitIdle(m_device->m_queue);
4474 vkDestroyImage(m_device->device(), image, NULL);
4475 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4476 vkDestroyImageView(m_device->device(), view, nullptr);
4477 vkFreeMemory(m_device->device(), image_memory, nullptr);
4478}
4479
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004480TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4481 TEST_DESCRIPTION("Delete in-use renderPass.");
4482
4483 ASSERT_NO_FATAL_FAILURE(InitState());
4484 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4485
4486 // Create simple renderpass
4487 VkAttachmentReference attach = {};
4488 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4489 VkSubpassDescription subpass = {};
4490 subpass.pColorAttachments = &attach;
4491 VkRenderPassCreateInfo rpci = {};
4492 rpci.subpassCount = 1;
4493 rpci.pSubpasses = &subpass;
4494 rpci.attachmentCount = 1;
4495 VkAttachmentDescription attach_desc = {};
4496 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4497 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4498 rpci.pAttachments = &attach_desc;
4499 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4500 VkRenderPass rp;
4501 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4502 ASSERT_VK_SUCCESS(err);
4503
4504 // Create a pipeline that uses the given renderpass
4505 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4506 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4507
4508 VkPipelineLayout pipeline_layout;
4509 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4510 ASSERT_VK_SUCCESS(err);
4511
4512 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4513 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4514 vp_state_ci.viewportCount = 1;
4515 VkViewport vp = {}; // Just need dummy vp to point to
4516 vp_state_ci.pViewports = &vp;
4517 vp_state_ci.scissorCount = 1;
4518 VkRect2D scissors = {}; // Dummy scissors to point to
4519 vp_state_ci.pScissors = &scissors;
4520
4521 VkPipelineShaderStageCreateInfo shaderStages[2];
4522 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4523
4524 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4525 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4526 // but add it to be able to run on more devices
4527 shaderStages[0] = vs.GetStageCreateInfo();
4528 shaderStages[1] = fs.GetStageCreateInfo();
4529
4530 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4531 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4532
4533 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4534 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4535 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4536
4537 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4538 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4539 rs_ci.rasterizerDiscardEnable = true;
4540 rs_ci.lineWidth = 1.0f;
4541
4542 VkPipelineColorBlendAttachmentState att = {};
4543 att.blendEnable = VK_FALSE;
4544 att.colorWriteMask = 0xf;
4545
4546 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4547 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4548 cb_ci.attachmentCount = 1;
4549 cb_ci.pAttachments = &att;
4550
4551 VkGraphicsPipelineCreateInfo gp_ci = {};
4552 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4553 gp_ci.stageCount = 2;
4554 gp_ci.pStages = shaderStages;
4555 gp_ci.pVertexInputState = &vi_ci;
4556 gp_ci.pInputAssemblyState = &ia_ci;
4557 gp_ci.pViewportState = &vp_state_ci;
4558 gp_ci.pRasterizationState = &rs_ci;
4559 gp_ci.pColorBlendState = &cb_ci;
4560 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4561 gp_ci.layout = pipeline_layout;
4562 gp_ci.renderPass = rp;
4563
4564 VkPipelineCacheCreateInfo pc_ci = {};
4565 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4566
4567 VkPipeline pipeline;
4568 VkPipelineCache pipe_cache;
4569 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4570 ASSERT_VK_SUCCESS(err);
4571
4572 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4573 ASSERT_VK_SUCCESS(err);
4574 // Bind pipeline to cmd buffer, will also bind renderpass
4575 m_commandBuffer->BeginCommandBuffer();
4576 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4577 m_commandBuffer->EndCommandBuffer();
4578
4579 VkSubmitInfo submit_info = {};
4580 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4581 submit_info.commandBufferCount = 1;
4582 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4583 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4584
4585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4586 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4587 m_errorMonitor->VerifyFound();
4588
4589 // Wait for queue to complete so we can safely destroy everything
4590 vkQueueWaitIdle(m_device->m_queue);
4591 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4592 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4593 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4594 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4595}
4596
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004597TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004598 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004599 ASSERT_NO_FATAL_FAILURE(InitState());
4600
4601 VkImage image;
4602 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4603 VkImageCreateInfo image_create_info = {};
4604 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4605 image_create_info.pNext = NULL;
4606 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4607 image_create_info.format = tex_format;
4608 image_create_info.extent.width = 32;
4609 image_create_info.extent.height = 32;
4610 image_create_info.extent.depth = 1;
4611 image_create_info.mipLevels = 1;
4612 image_create_info.arrayLayers = 1;
4613 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4614 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004615 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004616 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004617 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004618 ASSERT_VK_SUCCESS(err);
4619 // Have to bind memory to image before recording cmd in cmd buffer using it
4620 VkMemoryRequirements mem_reqs;
4621 VkDeviceMemory image_mem;
4622 bool pass;
4623 VkMemoryAllocateInfo mem_alloc = {};
4624 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4625 mem_alloc.pNext = NULL;
4626 mem_alloc.memoryTypeIndex = 0;
4627 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4628 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004629 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004630 ASSERT_TRUE(pass);
4631 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4632 ASSERT_VK_SUCCESS(err);
4633
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004634 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004636 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004637
4638 m_commandBuffer->BeginCommandBuffer();
4639 VkClearColorValue ccv;
4640 ccv.float32[0] = 1.0f;
4641 ccv.float32[1] = 1.0f;
4642 ccv.float32[2] = 1.0f;
4643 ccv.float32[3] = 1.0f;
4644 VkImageSubresourceRange isr = {};
4645 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4646 isr.baseArrayLayer = 0;
4647 isr.baseMipLevel = 0;
4648 isr.layerCount = 1;
4649 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004650 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004651 m_commandBuffer->EndCommandBuffer();
4652
4653 m_errorMonitor->VerifyFound();
4654 vkDestroyImage(m_device->device(), image, NULL);
4655 vkFreeMemory(m_device->device(), image_mem, nullptr);
4656}
4657
4658TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004659 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004660 ASSERT_NO_FATAL_FAILURE(InitState());
4661
4662 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004663 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 -06004664 VK_IMAGE_TILING_OPTIMAL, 0);
4665 ASSERT_TRUE(image.initialized());
4666
4667 VkBuffer buffer;
4668 VkDeviceMemory mem;
4669 VkMemoryRequirements mem_reqs;
4670
4671 VkBufferCreateInfo buf_info = {};
4672 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004673 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004674 buf_info.size = 256;
4675 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4676 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4677 ASSERT_VK_SUCCESS(err);
4678
4679 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4680
4681 VkMemoryAllocateInfo alloc_info = {};
4682 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4683 alloc_info.allocationSize = 256;
4684 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004685 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 -06004686 if (!pass) {
4687 vkDestroyBuffer(m_device->device(), buffer, NULL);
4688 return;
4689 }
4690 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4691 ASSERT_VK_SUCCESS(err);
4692
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004693 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004695 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004696 VkBufferImageCopy region = {};
4697 region.bufferRowLength = 128;
4698 region.bufferImageHeight = 128;
4699 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4700
4701 region.imageSubresource.layerCount = 1;
4702 region.imageExtent.height = 4;
4703 region.imageExtent.width = 4;
4704 region.imageExtent.depth = 1;
4705 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004706 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4707 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004708 m_commandBuffer->EndCommandBuffer();
4709
4710 m_errorMonitor->VerifyFound();
4711
4712 vkDestroyBuffer(m_device->device(), buffer, NULL);
4713 vkFreeMemory(m_device->handle(), mem, NULL);
4714}
4715
Tobin Ehlis85940f52016-07-07 16:57:21 -06004716TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4717 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4718 "due to an event dependency being destroyed.");
4719 ASSERT_NO_FATAL_FAILURE(InitState());
4720
4721 VkEvent event;
4722 VkEventCreateInfo evci = {};
4723 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4724 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4725 ASSERT_VK_SUCCESS(result);
4726
4727 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004728 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004729 m_commandBuffer->EndCommandBuffer();
4730
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004732 // Destroy event dependency prior to submit to cause ERROR
4733 vkDestroyEvent(m_device->device(), event, NULL);
4734
4735 VkSubmitInfo submit_info = {};
4736 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4737 submit_info.commandBufferCount = 1;
4738 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4739 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4740
4741 m_errorMonitor->VerifyFound();
4742}
4743
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004744TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4745 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4746 "due to a query pool dependency being destroyed.");
4747 ASSERT_NO_FATAL_FAILURE(InitState());
4748
4749 VkQueryPool query_pool;
4750 VkQueryPoolCreateInfo qpci{};
4751 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4752 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4753 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004754 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004755 ASSERT_VK_SUCCESS(result);
4756
4757 m_commandBuffer->BeginCommandBuffer();
4758 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4759 m_commandBuffer->EndCommandBuffer();
4760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004762 // Destroy query pool dependency prior to submit to cause ERROR
4763 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4764
4765 VkSubmitInfo submit_info = {};
4766 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4767 submit_info.commandBufferCount = 1;
4768 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4769 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4770
4771 m_errorMonitor->VerifyFound();
4772}
4773
Tobin Ehlis24130d92016-07-08 15:50:53 -06004774TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4775 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4776 "due to a pipeline dependency being destroyed.");
4777 ASSERT_NO_FATAL_FAILURE(InitState());
4778 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4779
4780 VkResult err;
4781
4782 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4783 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4784
4785 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004786 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004787 ASSERT_VK_SUCCESS(err);
4788
4789 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4790 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4791 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004792 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004793 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004794 vp_state_ci.scissorCount = 1;
4795 VkRect2D scissors = {}; // Dummy scissors to point to
4796 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004797
4798 VkPipelineShaderStageCreateInfo shaderStages[2];
4799 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4800
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004801 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4802 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4803 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004804 shaderStages[0] = vs.GetStageCreateInfo();
4805 shaderStages[1] = fs.GetStageCreateInfo();
4806
4807 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4808 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4809
4810 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4811 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4812 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4813
4814 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4815 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004816 rs_ci.rasterizerDiscardEnable = true;
4817 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004818
4819 VkPipelineColorBlendAttachmentState att = {};
4820 att.blendEnable = VK_FALSE;
4821 att.colorWriteMask = 0xf;
4822
4823 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4824 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4825 cb_ci.attachmentCount = 1;
4826 cb_ci.pAttachments = &att;
4827
4828 VkGraphicsPipelineCreateInfo gp_ci = {};
4829 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4830 gp_ci.stageCount = 2;
4831 gp_ci.pStages = shaderStages;
4832 gp_ci.pVertexInputState = &vi_ci;
4833 gp_ci.pInputAssemblyState = &ia_ci;
4834 gp_ci.pViewportState = &vp_state_ci;
4835 gp_ci.pRasterizationState = &rs_ci;
4836 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004837 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4838 gp_ci.layout = pipeline_layout;
4839 gp_ci.renderPass = renderPass();
4840
4841 VkPipelineCacheCreateInfo pc_ci = {};
4842 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4843
4844 VkPipeline pipeline;
4845 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004846 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004847 ASSERT_VK_SUCCESS(err);
4848
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004849 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004850 ASSERT_VK_SUCCESS(err);
4851
4852 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004853 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004854 m_commandBuffer->EndCommandBuffer();
4855 // Now destroy pipeline in order to cause error when submitting
4856 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4857
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004859
4860 VkSubmitInfo submit_info = {};
4861 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4862 submit_info.commandBufferCount = 1;
4863 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4864 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4865
4866 m_errorMonitor->VerifyFound();
4867 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4868 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4869}
4870
Tobin Ehlis31289162016-08-17 14:57:58 -06004871TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4872 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4873 "due to a bound descriptor set with a buffer dependency "
4874 "being destroyed.");
4875 ASSERT_NO_FATAL_FAILURE(InitState());
4876 ASSERT_NO_FATAL_FAILURE(InitViewport());
4877 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4878
4879 VkDescriptorPoolSize ds_type_count = {};
4880 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4881 ds_type_count.descriptorCount = 1;
4882
4883 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4884 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4885 ds_pool_ci.pNext = NULL;
4886 ds_pool_ci.maxSets = 1;
4887 ds_pool_ci.poolSizeCount = 1;
4888 ds_pool_ci.pPoolSizes = &ds_type_count;
4889
4890 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004891 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004892 ASSERT_VK_SUCCESS(err);
4893
4894 VkDescriptorSetLayoutBinding dsl_binding = {};
4895 dsl_binding.binding = 0;
4896 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4897 dsl_binding.descriptorCount = 1;
4898 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4899 dsl_binding.pImmutableSamplers = NULL;
4900
4901 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4902 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4903 ds_layout_ci.pNext = NULL;
4904 ds_layout_ci.bindingCount = 1;
4905 ds_layout_ci.pBindings = &dsl_binding;
4906 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004907 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004908 ASSERT_VK_SUCCESS(err);
4909
4910 VkDescriptorSet descriptorSet;
4911 VkDescriptorSetAllocateInfo alloc_info = {};
4912 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4913 alloc_info.descriptorSetCount = 1;
4914 alloc_info.descriptorPool = ds_pool;
4915 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004916 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004917 ASSERT_VK_SUCCESS(err);
4918
4919 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4920 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4921 pipeline_layout_ci.pNext = NULL;
4922 pipeline_layout_ci.setLayoutCount = 1;
4923 pipeline_layout_ci.pSetLayouts = &ds_layout;
4924
4925 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004926 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004927 ASSERT_VK_SUCCESS(err);
4928
4929 // Create a buffer to update the descriptor with
4930 uint32_t qfi = 0;
4931 VkBufferCreateInfo buffCI = {};
4932 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4933 buffCI.size = 1024;
4934 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4935 buffCI.queueFamilyIndexCount = 1;
4936 buffCI.pQueueFamilyIndices = &qfi;
4937
4938 VkBuffer buffer;
4939 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4940 ASSERT_VK_SUCCESS(err);
4941 // Allocate memory and bind to buffer so we can make it to the appropriate
4942 // error
4943 VkMemoryAllocateInfo mem_alloc = {};
4944 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4945 mem_alloc.pNext = NULL;
4946 mem_alloc.allocationSize = 1024;
4947 mem_alloc.memoryTypeIndex = 0;
4948
4949 VkMemoryRequirements memReqs;
4950 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004951 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004952 if (!pass) {
4953 vkDestroyBuffer(m_device->device(), buffer, NULL);
4954 return;
4955 }
4956
4957 VkDeviceMemory mem;
4958 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4959 ASSERT_VK_SUCCESS(err);
4960 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4961 ASSERT_VK_SUCCESS(err);
4962 // Correctly update descriptor to avoid "NOT_UPDATED" error
4963 VkDescriptorBufferInfo buffInfo = {};
4964 buffInfo.buffer = buffer;
4965 buffInfo.offset = 0;
4966 buffInfo.range = 1024;
4967
4968 VkWriteDescriptorSet descriptor_write;
4969 memset(&descriptor_write, 0, sizeof(descriptor_write));
4970 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4971 descriptor_write.dstSet = descriptorSet;
4972 descriptor_write.dstBinding = 0;
4973 descriptor_write.descriptorCount = 1;
4974 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4975 descriptor_write.pBufferInfo = &buffInfo;
4976
4977 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4978
4979 // Create PSO to be used for draw-time errors below
4980 char const *vsSource = "#version 450\n"
4981 "\n"
4982 "out gl_PerVertex { \n"
4983 " vec4 gl_Position;\n"
4984 "};\n"
4985 "void main(){\n"
4986 " gl_Position = vec4(1);\n"
4987 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004988 char const *fsSource = "#version 450\n"
4989 "\n"
4990 "layout(location=0) out vec4 x;\n"
4991 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4992 "void main(){\n"
4993 " x = vec4(bar.y);\n"
4994 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06004995 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4996 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4997 VkPipelineObj pipe(m_device);
4998 pipe.AddShader(&vs);
4999 pipe.AddShader(&fs);
5000 pipe.AddColorAttachment();
5001 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5002
5003 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005004 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5005 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5006 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005007 Draw(1, 0, 0, 0);
5008 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005010 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5011 vkDestroyBuffer(m_device->device(), buffer, NULL);
5012 // Attempt to submit cmd buffer
5013 VkSubmitInfo submit_info = {};
5014 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5015 submit_info.commandBufferCount = 1;
5016 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5017 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5018 m_errorMonitor->VerifyFound();
5019 // Cleanup
5020 vkFreeMemory(m_device->device(), mem, NULL);
5021
5022 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5023 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5024 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5025}
5026
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005027TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5028 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5029 "due to a bound descriptor sets with a combined image "
5030 "sampler having their image, sampler, and descriptor set "
5031 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005032 "submit associated cmd buffers. Attempt to destroy a "
5033 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005034 ASSERT_NO_FATAL_FAILURE(InitState());
5035 ASSERT_NO_FATAL_FAILURE(InitViewport());
5036 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5037
5038 VkDescriptorPoolSize ds_type_count = {};
5039 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5040 ds_type_count.descriptorCount = 1;
5041
5042 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5043 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5044 ds_pool_ci.pNext = NULL;
5045 ds_pool_ci.maxSets = 1;
5046 ds_pool_ci.poolSizeCount = 1;
5047 ds_pool_ci.pPoolSizes = &ds_type_count;
5048
5049 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005050 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005051 ASSERT_VK_SUCCESS(err);
5052
5053 VkDescriptorSetLayoutBinding dsl_binding = {};
5054 dsl_binding.binding = 0;
5055 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5056 dsl_binding.descriptorCount = 1;
5057 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5058 dsl_binding.pImmutableSamplers = NULL;
5059
5060 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5061 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5062 ds_layout_ci.pNext = NULL;
5063 ds_layout_ci.bindingCount = 1;
5064 ds_layout_ci.pBindings = &dsl_binding;
5065 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005066 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005067 ASSERT_VK_SUCCESS(err);
5068
5069 VkDescriptorSet descriptorSet;
5070 VkDescriptorSetAllocateInfo alloc_info = {};
5071 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5072 alloc_info.descriptorSetCount = 1;
5073 alloc_info.descriptorPool = ds_pool;
5074 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005075 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005076 ASSERT_VK_SUCCESS(err);
5077
5078 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5079 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5080 pipeline_layout_ci.pNext = NULL;
5081 pipeline_layout_ci.setLayoutCount = 1;
5082 pipeline_layout_ci.pSetLayouts = &ds_layout;
5083
5084 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005085 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005086 ASSERT_VK_SUCCESS(err);
5087
5088 // Create images to update the descriptor with
5089 VkImage image;
5090 VkImage image2;
5091 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5092 const int32_t tex_width = 32;
5093 const int32_t tex_height = 32;
5094 VkImageCreateInfo image_create_info = {};
5095 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5096 image_create_info.pNext = NULL;
5097 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5098 image_create_info.format = tex_format;
5099 image_create_info.extent.width = tex_width;
5100 image_create_info.extent.height = tex_height;
5101 image_create_info.extent.depth = 1;
5102 image_create_info.mipLevels = 1;
5103 image_create_info.arrayLayers = 1;
5104 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5105 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5106 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5107 image_create_info.flags = 0;
5108 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5109 ASSERT_VK_SUCCESS(err);
5110 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5111 ASSERT_VK_SUCCESS(err);
5112
5113 VkMemoryRequirements memory_reqs;
5114 VkDeviceMemory image_memory;
5115 bool pass;
5116 VkMemoryAllocateInfo memory_info = {};
5117 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5118 memory_info.pNext = NULL;
5119 memory_info.allocationSize = 0;
5120 memory_info.memoryTypeIndex = 0;
5121 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5122 // Allocate enough memory for both images
5123 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005124 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005125 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005126 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005127 ASSERT_VK_SUCCESS(err);
5128 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5129 ASSERT_VK_SUCCESS(err);
5130 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005131 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005132 ASSERT_VK_SUCCESS(err);
5133
5134 VkImageViewCreateInfo image_view_create_info = {};
5135 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5136 image_view_create_info.image = image;
5137 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5138 image_view_create_info.format = tex_format;
5139 image_view_create_info.subresourceRange.layerCount = 1;
5140 image_view_create_info.subresourceRange.baseMipLevel = 0;
5141 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005142 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005143
5144 VkImageView view;
5145 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005146 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005147 ASSERT_VK_SUCCESS(err);
5148 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005149 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005150 ASSERT_VK_SUCCESS(err);
5151 // Create Samplers
5152 VkSamplerCreateInfo sampler_ci = {};
5153 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5154 sampler_ci.pNext = NULL;
5155 sampler_ci.magFilter = VK_FILTER_NEAREST;
5156 sampler_ci.minFilter = VK_FILTER_NEAREST;
5157 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5158 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5159 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5160 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5161 sampler_ci.mipLodBias = 1.0;
5162 sampler_ci.anisotropyEnable = VK_FALSE;
5163 sampler_ci.maxAnisotropy = 1;
5164 sampler_ci.compareEnable = VK_FALSE;
5165 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5166 sampler_ci.minLod = 1.0;
5167 sampler_ci.maxLod = 1.0;
5168 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5169 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5170 VkSampler sampler;
5171 VkSampler sampler2;
5172 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5173 ASSERT_VK_SUCCESS(err);
5174 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5175 ASSERT_VK_SUCCESS(err);
5176 // Update descriptor with image and sampler
5177 VkDescriptorImageInfo img_info = {};
5178 img_info.sampler = sampler;
5179 img_info.imageView = view;
5180 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5181
5182 VkWriteDescriptorSet descriptor_write;
5183 memset(&descriptor_write, 0, sizeof(descriptor_write));
5184 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5185 descriptor_write.dstSet = descriptorSet;
5186 descriptor_write.dstBinding = 0;
5187 descriptor_write.descriptorCount = 1;
5188 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5189 descriptor_write.pImageInfo = &img_info;
5190
5191 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5192
5193 // Create PSO to be used for draw-time errors below
5194 char const *vsSource = "#version 450\n"
5195 "\n"
5196 "out gl_PerVertex { \n"
5197 " vec4 gl_Position;\n"
5198 "};\n"
5199 "void main(){\n"
5200 " gl_Position = vec4(1);\n"
5201 "}\n";
5202 char const *fsSource = "#version 450\n"
5203 "\n"
5204 "layout(set=0, binding=0) uniform sampler2D s;\n"
5205 "layout(location=0) out vec4 x;\n"
5206 "void main(){\n"
5207 " x = texture(s, vec2(1));\n"
5208 "}\n";
5209 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5210 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5211 VkPipelineObj pipe(m_device);
5212 pipe.AddShader(&vs);
5213 pipe.AddShader(&fs);
5214 pipe.AddColorAttachment();
5215 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5216
5217 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005219 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005220 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5221 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5222 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005223 Draw(1, 0, 0, 0);
5224 EndCommandBuffer();
5225 // Destroy sampler invalidates the cmd buffer, causing error on submit
5226 vkDestroySampler(m_device->device(), sampler, NULL);
5227 // Attempt to submit cmd buffer
5228 VkSubmitInfo submit_info = {};
5229 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5230 submit_info.commandBufferCount = 1;
5231 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5232 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5233 m_errorMonitor->VerifyFound();
5234 // Now re-update descriptor with valid sampler and delete image
5235 img_info.sampler = sampler2;
5236 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005238 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005239 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5240 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5241 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005242 Draw(1, 0, 0, 0);
5243 EndCommandBuffer();
5244 // Destroy image invalidates the cmd buffer, causing error on submit
5245 vkDestroyImage(m_device->device(), image, NULL);
5246 // Attempt to submit cmd buffer
5247 submit_info = {};
5248 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5249 submit_info.commandBufferCount = 1;
5250 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5251 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5252 m_errorMonitor->VerifyFound();
5253 // Now update descriptor to be valid, but then free descriptor
5254 img_info.imageView = view2;
5255 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005257 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005258 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5259 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5260 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005261 Draw(1, 0, 0, 0);
5262 EndCommandBuffer();
5263 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005265 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005266 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005267 // Attempt to submit cmd buffer
5268 submit_info = {};
5269 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5270 submit_info.commandBufferCount = 1;
5271 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5272 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5273 m_errorMonitor->VerifyFound();
5274 // Cleanup
5275 vkFreeMemory(m_device->device(), image_memory, NULL);
5276 vkDestroySampler(m_device->device(), sampler2, NULL);
5277 vkDestroyImage(m_device->device(), image2, NULL);
5278 vkDestroyImageView(m_device->device(), view, NULL);
5279 vkDestroyImageView(m_device->device(), view2, NULL);
5280 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5281 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5282 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5283}
5284
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005285TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5286 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5287 ASSERT_NO_FATAL_FAILURE(InitState());
5288 ASSERT_NO_FATAL_FAILURE(InitViewport());
5289 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5290
5291 VkDescriptorPoolSize ds_type_count = {};
5292 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5293 ds_type_count.descriptorCount = 1;
5294
5295 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5296 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5297 ds_pool_ci.pNext = NULL;
5298 ds_pool_ci.maxSets = 1;
5299 ds_pool_ci.poolSizeCount = 1;
5300 ds_pool_ci.pPoolSizes = &ds_type_count;
5301
5302 VkDescriptorPool ds_pool;
5303 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5304 ASSERT_VK_SUCCESS(err);
5305
5306 VkDescriptorSetLayoutBinding dsl_binding = {};
5307 dsl_binding.binding = 0;
5308 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5309 dsl_binding.descriptorCount = 1;
5310 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5311 dsl_binding.pImmutableSamplers = NULL;
5312
5313 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5314 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5315 ds_layout_ci.pNext = NULL;
5316 ds_layout_ci.bindingCount = 1;
5317 ds_layout_ci.pBindings = &dsl_binding;
5318 VkDescriptorSetLayout ds_layout;
5319 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5320 ASSERT_VK_SUCCESS(err);
5321
5322 VkDescriptorSet descriptor_set;
5323 VkDescriptorSetAllocateInfo alloc_info = {};
5324 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5325 alloc_info.descriptorSetCount = 1;
5326 alloc_info.descriptorPool = ds_pool;
5327 alloc_info.pSetLayouts = &ds_layout;
5328 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5329 ASSERT_VK_SUCCESS(err);
5330
5331 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5332 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5333 pipeline_layout_ci.pNext = NULL;
5334 pipeline_layout_ci.setLayoutCount = 1;
5335 pipeline_layout_ci.pSetLayouts = &ds_layout;
5336
5337 VkPipelineLayout pipeline_layout;
5338 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5339 ASSERT_VK_SUCCESS(err);
5340
5341 // Create image to update the descriptor with
5342 VkImageObj image(m_device);
5343 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5344 ASSERT_TRUE(image.initialized());
5345
5346 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5347 // Create Sampler
5348 VkSamplerCreateInfo sampler_ci = {};
5349 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5350 sampler_ci.pNext = NULL;
5351 sampler_ci.magFilter = VK_FILTER_NEAREST;
5352 sampler_ci.minFilter = VK_FILTER_NEAREST;
5353 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5354 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5355 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5356 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5357 sampler_ci.mipLodBias = 1.0;
5358 sampler_ci.anisotropyEnable = VK_FALSE;
5359 sampler_ci.maxAnisotropy = 1;
5360 sampler_ci.compareEnable = VK_FALSE;
5361 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5362 sampler_ci.minLod = 1.0;
5363 sampler_ci.maxLod = 1.0;
5364 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5365 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5366 VkSampler sampler;
5367 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5368 ASSERT_VK_SUCCESS(err);
5369 // Update descriptor with image and sampler
5370 VkDescriptorImageInfo img_info = {};
5371 img_info.sampler = sampler;
5372 img_info.imageView = view;
5373 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5374
5375 VkWriteDescriptorSet descriptor_write;
5376 memset(&descriptor_write, 0, sizeof(descriptor_write));
5377 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5378 descriptor_write.dstSet = descriptor_set;
5379 descriptor_write.dstBinding = 0;
5380 descriptor_write.descriptorCount = 1;
5381 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5382 descriptor_write.pImageInfo = &img_info;
5383
5384 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5385
5386 // Create PSO to be used for draw-time errors below
5387 char const *vsSource = "#version 450\n"
5388 "\n"
5389 "out gl_PerVertex { \n"
5390 " vec4 gl_Position;\n"
5391 "};\n"
5392 "void main(){\n"
5393 " gl_Position = vec4(1);\n"
5394 "}\n";
5395 char const *fsSource = "#version 450\n"
5396 "\n"
5397 "layout(set=0, binding=0) uniform sampler2D s;\n"
5398 "layout(location=0) out vec4 x;\n"
5399 "void main(){\n"
5400 " x = texture(s, vec2(1));\n"
5401 "}\n";
5402 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5403 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5404 VkPipelineObj pipe(m_device);
5405 pipe.AddShader(&vs);
5406 pipe.AddShader(&fs);
5407 pipe.AddColorAttachment();
5408 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5409
5410 BeginCommandBuffer();
5411 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5412 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5413 &descriptor_set, 0, NULL);
5414 Draw(1, 0, 0, 0);
5415 EndCommandBuffer();
5416 // Submit cmd buffer to put pool in-flight
5417 VkSubmitInfo submit_info = {};
5418 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5419 submit_info.commandBufferCount = 1;
5420 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5421 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5422 // Destroy pool while in-flight, causing error
5423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5424 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5425 m_errorMonitor->VerifyFound();
5426 vkQueueWaitIdle(m_device->m_queue);
5427 // Cleanup
5428 vkDestroySampler(m_device->device(), sampler, NULL);
5429 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5430 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5431 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5432}
5433
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005434TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5435 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5436 ASSERT_NO_FATAL_FAILURE(InitState());
5437 ASSERT_NO_FATAL_FAILURE(InitViewport());
5438 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5439
5440 VkDescriptorPoolSize ds_type_count = {};
5441 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5442 ds_type_count.descriptorCount = 1;
5443
5444 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5445 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5446 ds_pool_ci.pNext = NULL;
5447 ds_pool_ci.maxSets = 1;
5448 ds_pool_ci.poolSizeCount = 1;
5449 ds_pool_ci.pPoolSizes = &ds_type_count;
5450
5451 VkDescriptorPool ds_pool;
5452 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5453 ASSERT_VK_SUCCESS(err);
5454
5455 VkDescriptorSetLayoutBinding dsl_binding = {};
5456 dsl_binding.binding = 0;
5457 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5458 dsl_binding.descriptorCount = 1;
5459 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5460 dsl_binding.pImmutableSamplers = NULL;
5461
5462 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5463 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5464 ds_layout_ci.pNext = NULL;
5465 ds_layout_ci.bindingCount = 1;
5466 ds_layout_ci.pBindings = &dsl_binding;
5467 VkDescriptorSetLayout ds_layout;
5468 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5469 ASSERT_VK_SUCCESS(err);
5470
5471 VkDescriptorSet descriptorSet;
5472 VkDescriptorSetAllocateInfo alloc_info = {};
5473 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5474 alloc_info.descriptorSetCount = 1;
5475 alloc_info.descriptorPool = ds_pool;
5476 alloc_info.pSetLayouts = &ds_layout;
5477 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5478 ASSERT_VK_SUCCESS(err);
5479
5480 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5481 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5482 pipeline_layout_ci.pNext = NULL;
5483 pipeline_layout_ci.setLayoutCount = 1;
5484 pipeline_layout_ci.pSetLayouts = &ds_layout;
5485
5486 VkPipelineLayout pipeline_layout;
5487 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5488 ASSERT_VK_SUCCESS(err);
5489
5490 // Create images to update the descriptor with
5491 VkImage image;
5492 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5493 const int32_t tex_width = 32;
5494 const int32_t tex_height = 32;
5495 VkImageCreateInfo image_create_info = {};
5496 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5497 image_create_info.pNext = NULL;
5498 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5499 image_create_info.format = tex_format;
5500 image_create_info.extent.width = tex_width;
5501 image_create_info.extent.height = tex_height;
5502 image_create_info.extent.depth = 1;
5503 image_create_info.mipLevels = 1;
5504 image_create_info.arrayLayers = 1;
5505 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5506 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5507 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5508 image_create_info.flags = 0;
5509 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5510 ASSERT_VK_SUCCESS(err);
5511 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5512 VkMemoryRequirements memory_reqs;
5513 VkDeviceMemory image_memory;
5514 bool pass;
5515 VkMemoryAllocateInfo memory_info = {};
5516 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5517 memory_info.pNext = NULL;
5518 memory_info.allocationSize = 0;
5519 memory_info.memoryTypeIndex = 0;
5520 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5521 // Allocate enough memory for image
5522 memory_info.allocationSize = memory_reqs.size;
5523 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5524 ASSERT_TRUE(pass);
5525 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5526 ASSERT_VK_SUCCESS(err);
5527 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5528 ASSERT_VK_SUCCESS(err);
5529
5530 VkImageViewCreateInfo image_view_create_info = {};
5531 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5532 image_view_create_info.image = image;
5533 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5534 image_view_create_info.format = tex_format;
5535 image_view_create_info.subresourceRange.layerCount = 1;
5536 image_view_create_info.subresourceRange.baseMipLevel = 0;
5537 image_view_create_info.subresourceRange.levelCount = 1;
5538 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5539
5540 VkImageView view;
5541 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5542 ASSERT_VK_SUCCESS(err);
5543 // Create Samplers
5544 VkSamplerCreateInfo sampler_ci = {};
5545 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5546 sampler_ci.pNext = NULL;
5547 sampler_ci.magFilter = VK_FILTER_NEAREST;
5548 sampler_ci.minFilter = VK_FILTER_NEAREST;
5549 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5550 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5551 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5552 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5553 sampler_ci.mipLodBias = 1.0;
5554 sampler_ci.anisotropyEnable = VK_FALSE;
5555 sampler_ci.maxAnisotropy = 1;
5556 sampler_ci.compareEnable = VK_FALSE;
5557 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5558 sampler_ci.minLod = 1.0;
5559 sampler_ci.maxLod = 1.0;
5560 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5561 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5562 VkSampler sampler;
5563 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5564 ASSERT_VK_SUCCESS(err);
5565 // Update descriptor with image and sampler
5566 VkDescriptorImageInfo img_info = {};
5567 img_info.sampler = sampler;
5568 img_info.imageView = view;
5569 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5570
5571 VkWriteDescriptorSet descriptor_write;
5572 memset(&descriptor_write, 0, sizeof(descriptor_write));
5573 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5574 descriptor_write.dstSet = descriptorSet;
5575 descriptor_write.dstBinding = 0;
5576 descriptor_write.descriptorCount = 1;
5577 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5578 descriptor_write.pImageInfo = &img_info;
5579 // Break memory binding and attempt update
5580 vkFreeMemory(m_device->device(), image_memory, nullptr);
5581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005582 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5584 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5585 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5586 m_errorMonitor->VerifyFound();
5587 // Cleanup
5588 vkDestroyImage(m_device->device(), image, NULL);
5589 vkDestroySampler(m_device->device(), sampler, NULL);
5590 vkDestroyImageView(m_device->device(), view, NULL);
5591 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5592 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5593 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5594}
5595
Karl Schultz6addd812016-02-02 17:17:23 -07005596TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005597 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5598 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005599 // Create a valid cmd buffer
5600 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005601 uint64_t fake_pipeline_handle = 0xbaad6001;
5602 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005603 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005604 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5605
5606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005607 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005608 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005609 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005610
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005611 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005612 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 -06005613 Draw(1, 0, 0, 0);
5614 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005615
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005616 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005617 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 +12005618 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005619 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5620 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005621}
5622
Karl Schultz6addd812016-02-02 17:17:23 -07005623TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005624 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005625 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005626
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005628
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005629 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005630 ASSERT_NO_FATAL_FAILURE(InitViewport());
5631 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005632 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005633 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5634 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005635
5636 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005637 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5638 ds_pool_ci.pNext = NULL;
5639 ds_pool_ci.maxSets = 1;
5640 ds_pool_ci.poolSizeCount = 1;
5641 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005642
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005643 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005644 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005645 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005646
Tony Barboureb254902015-07-15 12:50:33 -06005647 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005648 dsl_binding.binding = 0;
5649 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5650 dsl_binding.descriptorCount = 1;
5651 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5652 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005653
Tony Barboureb254902015-07-15 12:50:33 -06005654 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005655 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5656 ds_layout_ci.pNext = NULL;
5657 ds_layout_ci.bindingCount = 1;
5658 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005659 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005660 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005661 ASSERT_VK_SUCCESS(err);
5662
5663 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005664 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005665 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005666 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005667 alloc_info.descriptorPool = ds_pool;
5668 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005669 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005670 ASSERT_VK_SUCCESS(err);
5671
Tony Barboureb254902015-07-15 12:50:33 -06005672 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005673 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5674 pipeline_layout_ci.pNext = NULL;
5675 pipeline_layout_ci.setLayoutCount = 1;
5676 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005677
5678 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005679 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005680 ASSERT_VK_SUCCESS(err);
5681
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005682 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005683 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005684 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005685 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005686
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005687 VkPipelineObj pipe(m_device);
5688 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005689 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005690 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005691 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005692
5693 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005694 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5695 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5696 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005697
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005698 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005699
Chia-I Wuf7458c52015-10-26 21:10:41 +08005700 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5701 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5702 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005703}
5704
Karl Schultz6addd812016-02-02 17:17:23 -07005705TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005706 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005707 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005708
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5710 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005711
5712 ASSERT_NO_FATAL_FAILURE(InitState());
5713 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005714 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5715 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005716
5717 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005718 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5719 ds_pool_ci.pNext = NULL;
5720 ds_pool_ci.maxSets = 1;
5721 ds_pool_ci.poolSizeCount = 1;
5722 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005723
5724 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005725 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005726 ASSERT_VK_SUCCESS(err);
5727
5728 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005729 dsl_binding.binding = 0;
5730 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5731 dsl_binding.descriptorCount = 1;
5732 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5733 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005734
5735 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005736 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5737 ds_layout_ci.pNext = NULL;
5738 ds_layout_ci.bindingCount = 1;
5739 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005740 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005741 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005742 ASSERT_VK_SUCCESS(err);
5743
5744 VkDescriptorSet descriptorSet;
5745 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005746 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005747 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005748 alloc_info.descriptorPool = ds_pool;
5749 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005750 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005751 ASSERT_VK_SUCCESS(err);
5752
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005753 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005754 VkWriteDescriptorSet descriptor_write;
5755 memset(&descriptor_write, 0, sizeof(descriptor_write));
5756 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5757 descriptor_write.dstSet = descriptorSet;
5758 descriptor_write.dstBinding = 0;
5759 descriptor_write.descriptorCount = 1;
5760 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5761 descriptor_write.pTexelBufferView = &view;
5762
5763 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5764
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005765 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005766
5767 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5768 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5769}
5770
Mark Youngd339ba32016-05-30 13:28:35 -06005771TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005772 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 -06005773
5774 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005776 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005777
5778 ASSERT_NO_FATAL_FAILURE(InitState());
5779
5780 // Create a buffer with no bound memory and then attempt to create
5781 // a buffer view.
5782 VkBufferCreateInfo buff_ci = {};
5783 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005784 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005785 buff_ci.size = 256;
5786 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5787 VkBuffer buffer;
5788 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5789 ASSERT_VK_SUCCESS(err);
5790
5791 VkBufferViewCreateInfo buff_view_ci = {};
5792 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5793 buff_view_ci.buffer = buffer;
5794 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5795 buff_view_ci.range = VK_WHOLE_SIZE;
5796 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005797 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005798
5799 m_errorMonitor->VerifyFound();
5800 vkDestroyBuffer(m_device->device(), buffer, NULL);
5801 // If last error is success, it still created the view, so delete it.
5802 if (err == VK_SUCCESS) {
5803 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5804 }
5805}
5806
Karl Schultz6addd812016-02-02 17:17:23 -07005807TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5808 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5809 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005810 // 1. No dynamicOffset supplied
5811 // 2. Too many dynamicOffsets supplied
5812 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005813 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5815 "0 dynamicOffsets are left in "
5816 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005817
5818 ASSERT_NO_FATAL_FAILURE(InitState());
5819 ASSERT_NO_FATAL_FAILURE(InitViewport());
5820 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5821
5822 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005823 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5824 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005825
5826 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005827 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5828 ds_pool_ci.pNext = NULL;
5829 ds_pool_ci.maxSets = 1;
5830 ds_pool_ci.poolSizeCount = 1;
5831 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005832
5833 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005834 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005835 ASSERT_VK_SUCCESS(err);
5836
5837 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005838 dsl_binding.binding = 0;
5839 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5840 dsl_binding.descriptorCount = 1;
5841 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5842 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005843
5844 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005845 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5846 ds_layout_ci.pNext = NULL;
5847 ds_layout_ci.bindingCount = 1;
5848 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005849 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005850 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005851 ASSERT_VK_SUCCESS(err);
5852
5853 VkDescriptorSet descriptorSet;
5854 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005855 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005856 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005857 alloc_info.descriptorPool = ds_pool;
5858 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005859 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005860 ASSERT_VK_SUCCESS(err);
5861
5862 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005863 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5864 pipeline_layout_ci.pNext = NULL;
5865 pipeline_layout_ci.setLayoutCount = 1;
5866 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005867
5868 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005869 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005870 ASSERT_VK_SUCCESS(err);
5871
5872 // Create a buffer to update the descriptor with
5873 uint32_t qfi = 0;
5874 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005875 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5876 buffCI.size = 1024;
5877 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5878 buffCI.queueFamilyIndexCount = 1;
5879 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005880
5881 VkBuffer dyub;
5882 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5883 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005884 // Allocate memory and bind to buffer so we can make it to the appropriate
5885 // error
5886 VkMemoryAllocateInfo mem_alloc = {};
5887 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5888 mem_alloc.pNext = NULL;
5889 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005890 mem_alloc.memoryTypeIndex = 0;
5891
5892 VkMemoryRequirements memReqs;
5893 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005894 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005895 if (!pass) {
5896 vkDestroyBuffer(m_device->device(), dyub, NULL);
5897 return;
5898 }
5899
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005900 VkDeviceMemory mem;
5901 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5902 ASSERT_VK_SUCCESS(err);
5903 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5904 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005905 // Correctly update descriptor to avoid "NOT_UPDATED" error
5906 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005907 buffInfo.buffer = dyub;
5908 buffInfo.offset = 0;
5909 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005910
5911 VkWriteDescriptorSet descriptor_write;
5912 memset(&descriptor_write, 0, sizeof(descriptor_write));
5913 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5914 descriptor_write.dstSet = descriptorSet;
5915 descriptor_write.dstBinding = 0;
5916 descriptor_write.descriptorCount = 1;
5917 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5918 descriptor_write.pBufferInfo = &buffInfo;
5919
5920 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5921
5922 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005923 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5924 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005925 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005926 uint32_t pDynOff[2] = {512, 756};
5927 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5929 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5930 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5931 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005932 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005933 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5935 "offset 0 and range 1024 that "
5936 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005937 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005938 char const *vsSource = "#version 450\n"
5939 "\n"
5940 "out gl_PerVertex { \n"
5941 " vec4 gl_Position;\n"
5942 "};\n"
5943 "void main(){\n"
5944 " gl_Position = vec4(1);\n"
5945 "}\n";
5946 char const *fsSource = "#version 450\n"
5947 "\n"
5948 "layout(location=0) out vec4 x;\n"
5949 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5950 "void main(){\n"
5951 " x = vec4(bar.y);\n"
5952 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005953 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5954 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5955 VkPipelineObj pipe(m_device);
5956 pipe.AddShader(&vs);
5957 pipe.AddShader(&fs);
5958 pipe.AddColorAttachment();
5959 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5960
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005961 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005962 // This update should succeed, but offset size of 512 will overstep buffer
5963 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005964 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5965 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005966 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005967 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005968
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005969 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005970 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005971
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005972 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005973 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005974 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5975}
5976
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005977TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
5978 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
5979 "that doesn't have memory bound");
5980 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005982 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5984 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005985
5986 ASSERT_NO_FATAL_FAILURE(InitState());
5987 ASSERT_NO_FATAL_FAILURE(InitViewport());
5988 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5989
5990 VkDescriptorPoolSize ds_type_count = {};
5991 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5992 ds_type_count.descriptorCount = 1;
5993
5994 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5995 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5996 ds_pool_ci.pNext = NULL;
5997 ds_pool_ci.maxSets = 1;
5998 ds_pool_ci.poolSizeCount = 1;
5999 ds_pool_ci.pPoolSizes = &ds_type_count;
6000
6001 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006002 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006003 ASSERT_VK_SUCCESS(err);
6004
6005 VkDescriptorSetLayoutBinding dsl_binding = {};
6006 dsl_binding.binding = 0;
6007 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6008 dsl_binding.descriptorCount = 1;
6009 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6010 dsl_binding.pImmutableSamplers = NULL;
6011
6012 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6013 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6014 ds_layout_ci.pNext = NULL;
6015 ds_layout_ci.bindingCount = 1;
6016 ds_layout_ci.pBindings = &dsl_binding;
6017 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006018 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006019 ASSERT_VK_SUCCESS(err);
6020
6021 VkDescriptorSet descriptorSet;
6022 VkDescriptorSetAllocateInfo alloc_info = {};
6023 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6024 alloc_info.descriptorSetCount = 1;
6025 alloc_info.descriptorPool = ds_pool;
6026 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006027 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006028 ASSERT_VK_SUCCESS(err);
6029
6030 // Create a buffer to update the descriptor with
6031 uint32_t qfi = 0;
6032 VkBufferCreateInfo buffCI = {};
6033 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6034 buffCI.size = 1024;
6035 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6036 buffCI.queueFamilyIndexCount = 1;
6037 buffCI.pQueueFamilyIndices = &qfi;
6038
6039 VkBuffer dyub;
6040 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6041 ASSERT_VK_SUCCESS(err);
6042
6043 // Attempt to update descriptor without binding memory to it
6044 VkDescriptorBufferInfo buffInfo = {};
6045 buffInfo.buffer = dyub;
6046 buffInfo.offset = 0;
6047 buffInfo.range = 1024;
6048
6049 VkWriteDescriptorSet descriptor_write;
6050 memset(&descriptor_write, 0, sizeof(descriptor_write));
6051 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6052 descriptor_write.dstSet = descriptorSet;
6053 descriptor_write.dstBinding = 0;
6054 descriptor_write.descriptorCount = 1;
6055 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6056 descriptor_write.pBufferInfo = &buffInfo;
6057
6058 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6059 m_errorMonitor->VerifyFound();
6060
6061 vkDestroyBuffer(m_device->device(), dyub, NULL);
6062 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6063 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6064}
6065
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006066TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006067 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006068 ASSERT_NO_FATAL_FAILURE(InitState());
6069 ASSERT_NO_FATAL_FAILURE(InitViewport());
6070 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6071
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006072 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006073 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006074 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6075 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6076 pipeline_layout_ci.pushConstantRangeCount = 1;
6077 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6078
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006079 //
6080 // Check for invalid push constant ranges in pipeline layouts.
6081 //
6082 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006083 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006084 char const *msg;
6085 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006086
Karl Schultzc81037d2016-05-12 08:11:23 -06006087 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6088 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6089 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6090 "vkCreatePipelineLayout() call has push constants index 0 with "
6091 "size 0."},
6092 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6093 "vkCreatePipelineLayout() call has push constants index 0 with "
6094 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006095 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006096 "vkCreatePipelineLayout() call has push constants index 0 with "
6097 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006098 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006099 "vkCreatePipelineLayout() call has push constants index 0 with "
6100 "size 0."},
6101 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6102 "vkCreatePipelineLayout() call has push constants index 0 with "
6103 "offset 1. Offset must"},
6104 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6105 "vkCreatePipelineLayout() call has push constants index 0 "
6106 "with offset "},
6107 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6108 "vkCreatePipelineLayout() call has push constants "
6109 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006110 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006111 "vkCreatePipelineLayout() call has push constants index 0 "
6112 "with offset "},
6113 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6114 "vkCreatePipelineLayout() call has push "
6115 "constants index 0 with offset "},
6116 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6117 "vkCreatePipelineLayout() call has push "
6118 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006119 }};
6120
6121 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006122 for (const auto &iter : range_tests) {
6123 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6125 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006126 m_errorMonitor->VerifyFound();
6127 if (VK_SUCCESS == err) {
6128 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6129 }
6130 }
6131
6132 // Check for invalid stage flag
6133 pc_range.offset = 0;
6134 pc_range.size = 16;
6135 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006136 m_errorMonitor->SetDesiredFailureMsg(
6137 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6138 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006139 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006140 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006141 if (VK_SUCCESS == err) {
6142 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6143 }
6144
6145 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006146 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006147 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006148 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006149 char const *msg;
6150 };
6151
Karl Schultzc81037d2016-05-12 08:11:23 -06006152 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006153 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6154 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6155 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6156 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6157 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006158 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006159 {
6160 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6161 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6162 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6163 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6164 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006165 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006166 },
6167 {
6168 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6169 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6170 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6171 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6172 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006173 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006174 },
6175 {
6176 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6177 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6178 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6179 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6180 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006181 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006182 },
6183 {
6184 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6185 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6186 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6187 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6188 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006189 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006190 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006191
Karl Schultzc81037d2016-05-12 08:11:23 -06006192 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006193 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006194 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6196 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006197 m_errorMonitor->VerifyFound();
6198 if (VK_SUCCESS == err) {
6199 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6200 }
6201 }
6202
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006203 //
6204 // CmdPushConstants tests
6205 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006206 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006207
6208 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006209 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6210 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006211 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6212 "vkCmdPushConstants() call has push constants with size 1. Size "
6213 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006214 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006215 "vkCmdPushConstants() call has push constants with size 1. Size "
6216 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006217 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006218 "vkCmdPushConstants() call has push constants with offset 1. "
6219 "Offset must be a multiple of 4."},
6220 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6221 "vkCmdPushConstants() call has push constants with offset 1. "
6222 "Offset must be a multiple of 4."},
6223 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6224 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6225 "0x1 not within flag-matching ranges in pipeline layout"},
6226 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6227 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6228 "0x1 not within flag-matching ranges in pipeline layout"},
6229 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6230 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6231 "0x1 not within flag-matching ranges in pipeline layout"},
6232 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6233 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6234 "0x1 not within flag-matching ranges in pipeline layout"},
6235 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6236 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6237 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006238 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006239 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6240 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006241 }};
6242
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006243 BeginCommandBuffer();
6244
6245 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006246 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006247 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006248 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006249 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006250 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006251 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006252 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006253 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6255 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006256 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006257 m_errorMonitor->VerifyFound();
6258 }
6259
6260 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006262 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006263 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006264 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006265
Karl Schultzc81037d2016-05-12 08:11:23 -06006266 // overlapping range tests with cmd
6267 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6268 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6269 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6270 "0x1 not within flag-matching ranges in pipeline layout"},
6271 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6272 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6273 "0x1 not within flag-matching ranges in pipeline layout"},
6274 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6275 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6276 "0x1 not within flag-matching ranges in pipeline layout"},
6277 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006278 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006279 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006280 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6281 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006282 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006283 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006284 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006285 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006286 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006287 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6289 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006290 iter.range.size, dummy_values);
6291 m_errorMonitor->VerifyFound();
6292 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006293 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6294
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006295 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006296}
6297
Karl Schultz6addd812016-02-02 17:17:23 -07006298TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006299 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006300 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006301
6302 ASSERT_NO_FATAL_FAILURE(InitState());
6303 ASSERT_NO_FATAL_FAILURE(InitViewport());
6304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6305
Mike Stroyanb8a61002016-06-20 16:00:28 -06006306 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6307 VkImageTiling tiling;
6308 VkFormatProperties format_properties;
6309 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006310 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006311 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006312 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006313 tiling = VK_IMAGE_TILING_OPTIMAL;
6314 } else {
6315 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6316 "skipped.\n");
6317 return;
6318 }
6319
Tobin Ehlis559c6382015-11-05 09:52:49 -07006320 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6321 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006322 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6323 ds_type_count[0].descriptorCount = 10;
6324 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6325 ds_type_count[1].descriptorCount = 2;
6326 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6327 ds_type_count[2].descriptorCount = 2;
6328 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6329 ds_type_count[3].descriptorCount = 5;
6330 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6331 // type
6332 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6333 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6334 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006335
6336 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006337 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6338 ds_pool_ci.pNext = NULL;
6339 ds_pool_ci.maxSets = 5;
6340 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6341 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006342
6343 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006344 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006345 ASSERT_VK_SUCCESS(err);
6346
6347 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6348 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006349 dsl_binding[0].binding = 0;
6350 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6351 dsl_binding[0].descriptorCount = 5;
6352 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6353 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006354
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006355 // Create layout identical to set0 layout but w/ different stageFlags
6356 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006357 dsl_fs_stage_only.binding = 0;
6358 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6359 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006360 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6361 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006362 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006363 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006364 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6365 ds_layout_ci.pNext = NULL;
6366 ds_layout_ci.bindingCount = 1;
6367 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006368 static const uint32_t NUM_LAYOUTS = 4;
6369 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006370 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006371 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6372 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006373 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006374 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006375 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006376 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006377 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006378 dsl_binding[0].binding = 0;
6379 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006380 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006381 dsl_binding[1].binding = 1;
6382 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6383 dsl_binding[1].descriptorCount = 2;
6384 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6385 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006386 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006387 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006388 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006389 ASSERT_VK_SUCCESS(err);
6390 dsl_binding[0].binding = 0;
6391 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006392 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006393 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006394 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006395 ASSERT_VK_SUCCESS(err);
6396 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006397 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006398 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006399 ASSERT_VK_SUCCESS(err);
6400
6401 static const uint32_t NUM_SETS = 4;
6402 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6403 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006404 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006405 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006406 alloc_info.descriptorPool = ds_pool;
6407 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006408 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006409 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006410 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006411 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006412 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006413 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006414 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006415
6416 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006417 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6418 pipeline_layout_ci.pNext = NULL;
6419 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6420 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006421
6422 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006423 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006424 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006425 // Create pipelineLayout with only one setLayout
6426 pipeline_layout_ci.setLayoutCount = 1;
6427 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006428 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006429 ASSERT_VK_SUCCESS(err);
6430 // Create pipelineLayout with 2 descriptor setLayout at index 0
6431 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6432 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006433 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006434 ASSERT_VK_SUCCESS(err);
6435 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6436 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6437 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006438 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006439 ASSERT_VK_SUCCESS(err);
6440 // Create pipelineLayout with UB type, but stageFlags for FS only
6441 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6442 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006443 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006444 ASSERT_VK_SUCCESS(err);
6445 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6446 VkDescriptorSetLayout pl_bad_s0[2] = {};
6447 pl_bad_s0[0] = ds_layout_fs_only;
6448 pl_bad_s0[1] = ds_layout[1];
6449 pipeline_layout_ci.setLayoutCount = 2;
6450 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6451 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006452 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006453 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006454
6455 // Create a buffer to update the descriptor with
6456 uint32_t qfi = 0;
6457 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006458 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6459 buffCI.size = 1024;
6460 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6461 buffCI.queueFamilyIndexCount = 1;
6462 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006463
6464 VkBuffer dyub;
6465 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6466 ASSERT_VK_SUCCESS(err);
6467 // Correctly update descriptor to avoid "NOT_UPDATED" error
6468 static const uint32_t NUM_BUFFS = 5;
6469 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006470 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006471 buffInfo[i].buffer = dyub;
6472 buffInfo[i].offset = 0;
6473 buffInfo[i].range = 1024;
6474 }
Karl Schultz6addd812016-02-02 17:17:23 -07006475 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006476 const int32_t tex_width = 32;
6477 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006478 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006479 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6480 image_create_info.pNext = NULL;
6481 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6482 image_create_info.format = tex_format;
6483 image_create_info.extent.width = tex_width;
6484 image_create_info.extent.height = tex_height;
6485 image_create_info.extent.depth = 1;
6486 image_create_info.mipLevels = 1;
6487 image_create_info.arrayLayers = 1;
6488 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006489 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006490 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006491 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006492 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6493 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006494
Karl Schultz6addd812016-02-02 17:17:23 -07006495 VkMemoryRequirements memReqs;
6496 VkDeviceMemory imageMem;
6497 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006498 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006499 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6500 memAlloc.pNext = NULL;
6501 memAlloc.allocationSize = 0;
6502 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006503 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6504 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006505 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006506 ASSERT_TRUE(pass);
6507 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6508 ASSERT_VK_SUCCESS(err);
6509 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6510 ASSERT_VK_SUCCESS(err);
6511
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006512 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006513 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6514 image_view_create_info.image = image;
6515 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6516 image_view_create_info.format = tex_format;
6517 image_view_create_info.subresourceRange.layerCount = 1;
6518 image_view_create_info.subresourceRange.baseMipLevel = 0;
6519 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006520 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006521
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006522 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006523 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006524 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006525 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006526 imageInfo[0].imageView = view;
6527 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6528 imageInfo[1].imageView = view;
6529 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006530 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006531 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006532 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006533 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006534
6535 static const uint32_t NUM_SET_UPDATES = 3;
6536 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6537 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6538 descriptor_write[0].dstSet = descriptorSet[0];
6539 descriptor_write[0].dstBinding = 0;
6540 descriptor_write[0].descriptorCount = 5;
6541 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6542 descriptor_write[0].pBufferInfo = buffInfo;
6543 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6544 descriptor_write[1].dstSet = descriptorSet[1];
6545 descriptor_write[1].dstBinding = 0;
6546 descriptor_write[1].descriptorCount = 2;
6547 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6548 descriptor_write[1].pImageInfo = imageInfo;
6549 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6550 descriptor_write[2].dstSet = descriptorSet[1];
6551 descriptor_write[2].dstBinding = 1;
6552 descriptor_write[2].descriptorCount = 2;
6553 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006554 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006555
6556 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006557
Tobin Ehlis88452832015-12-03 09:40:56 -07006558 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006559 char const *vsSource = "#version 450\n"
6560 "\n"
6561 "out gl_PerVertex {\n"
6562 " vec4 gl_Position;\n"
6563 "};\n"
6564 "void main(){\n"
6565 " gl_Position = vec4(1);\n"
6566 "}\n";
6567 char const *fsSource = "#version 450\n"
6568 "\n"
6569 "layout(location=0) out vec4 x;\n"
6570 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6571 "void main(){\n"
6572 " x = vec4(bar.y);\n"
6573 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006574 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6575 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006576 VkPipelineObj pipe(m_device);
6577 pipe.AddShader(&vs);
6578 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006579 pipe.AddColorAttachment();
6580 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006581
6582 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006583
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006584 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006585 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6586 // of PSO
6587 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6588 // cmd_pipeline.c
6589 // due to the fact that cmd_alloc_dset_data() has not been called in
6590 // cmd_bind_graphics_pipeline()
6591 // TODO : Want to cause various binding incompatibility issues here to test
6592 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006593 // First cause various verify_layout_compatibility() fails
6594 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006595 // verify_set_layout_compatibility fail cases:
6596 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6598 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6599 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006600 m_errorMonitor->VerifyFound();
6601
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006602 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6604 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6605 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006606 m_errorMonitor->VerifyFound();
6607
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006608 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006609 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6610 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6612 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6613 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006614 m_errorMonitor->VerifyFound();
6615
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006616 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6617 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6619 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6620 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006621 m_errorMonitor->VerifyFound();
6622
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006623 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6624 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6626 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6627 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6628 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006629 m_errorMonitor->VerifyFound();
6630
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006631 // Cause INFO messages due to disturbing previously bound Sets
6632 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006633 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6634 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006635 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6637 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6638 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006639 m_errorMonitor->VerifyFound();
6640
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006641 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6642 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006643 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6645 "any subsequent sets were disturbed ");
6646 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6647 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006648 m_errorMonitor->VerifyFound();
6649
Tobin Ehlis10fad692016-07-07 12:00:36 -06006650 // Now that we're done actively using the pipelineLayout that gfx pipeline
6651 // was created with, we should be able to delete it. Do that now to verify
6652 // that validation obeys pipelineLayout lifetime
6653 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6654
Tobin Ehlis88452832015-12-03 09:40:56 -07006655 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006656 // 1. Error due to not binding required set (we actually use same code as
6657 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006658 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6659 &descriptorSet[0], 0, NULL);
6660 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6661 &descriptorSet[1], 0, NULL);
6662 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 -07006663 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006664 m_errorMonitor->VerifyFound();
6665
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006666 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006667 // 2. Error due to bound set not being compatible with PSO's
6668 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006669 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6670 &descriptorSet[0], 0, NULL);
6671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006672 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006673 m_errorMonitor->VerifyFound();
6674
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006675 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006676 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006677 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6678 }
6679 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006680 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006681 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6682 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006683 vkFreeMemory(m_device->device(), imageMem, NULL);
6684 vkDestroyImage(m_device->device(), image, NULL);
6685 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006686}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006687
Karl Schultz6addd812016-02-02 17:17:23 -07006688TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006689
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6691 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006692
6693 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006694 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006695 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006696 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006697
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006698 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006699}
6700
Karl Schultz6addd812016-02-02 17:17:23 -07006701TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6702 VkResult err;
6703 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006704
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006706
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006707 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006708
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006709 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006710 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006711 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006712 cmd.commandPool = m_commandPool;
6713 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006714 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006715
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006716 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006717 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006718
6719 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006720 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006721 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006722 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006723 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006724 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 -07006725 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006726
6727 // The error should be caught by validation of the BeginCommandBuffer call
6728 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6729
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006730 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006731 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006732}
6733
Karl Schultz6addd812016-02-02 17:17:23 -07006734TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006735 // Cause error due to Begin while recording CB
6736 // Then cause 2 errors for attempting to reset CB w/o having
6737 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6738 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006740
6741 ASSERT_NO_FATAL_FAILURE(InitState());
6742
6743 // Calls AllocateCommandBuffers
6744 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6745
Karl Schultz6addd812016-02-02 17:17:23 -07006746 // Force the failure by setting the Renderpass and Framebuffer fields with
6747 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006748 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006749 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006750 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6751 cmd_buf_info.pNext = NULL;
6752 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006753 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006754
6755 // Begin CB to transition to recording state
6756 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6757 // Can't re-begin. This should trigger error
6758 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006759 m_errorMonitor->VerifyFound();
6760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006762 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6763 // Reset attempt will trigger error due to incorrect CommandPool state
6764 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006765 m_errorMonitor->VerifyFound();
6766
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006768 // Transition CB to RECORDED state
6769 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6770 // Now attempting to Begin will implicitly reset, which triggers error
6771 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006772 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006773}
6774
Karl Schultz6addd812016-02-02 17:17:23 -07006775TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006776 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006777 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006778
Mike Weiblencce7ec72016-10-17 19:33:05 -06006779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006780
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006781 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006782 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006783
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006784 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006785 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6786 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006787
6788 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006789 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6790 ds_pool_ci.pNext = NULL;
6791 ds_pool_ci.maxSets = 1;
6792 ds_pool_ci.poolSizeCount = 1;
6793 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006794
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006795 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006796 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006797 ASSERT_VK_SUCCESS(err);
6798
Tony Barboureb254902015-07-15 12:50:33 -06006799 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006800 dsl_binding.binding = 0;
6801 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6802 dsl_binding.descriptorCount = 1;
6803 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6804 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006805
Tony Barboureb254902015-07-15 12:50:33 -06006806 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006807 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6808 ds_layout_ci.pNext = NULL;
6809 ds_layout_ci.bindingCount = 1;
6810 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006811
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006812 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006813 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006814 ASSERT_VK_SUCCESS(err);
6815
6816 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006817 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006818 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006819 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006820 alloc_info.descriptorPool = ds_pool;
6821 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006822 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006823 ASSERT_VK_SUCCESS(err);
6824
Tony Barboureb254902015-07-15 12:50:33 -06006825 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006826 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6827 pipeline_layout_ci.setLayoutCount = 1;
6828 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006829
6830 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006831 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006832 ASSERT_VK_SUCCESS(err);
6833
Tobin Ehlise68360f2015-10-01 11:15:13 -06006834 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006835 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006836
6837 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006838 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6839 vp_state_ci.scissorCount = 1;
6840 vp_state_ci.pScissors = &sc;
6841 vp_state_ci.viewportCount = 1;
6842 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006843
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006844 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6845 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6846 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6847 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6848 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6849 rs_state_ci.depthClampEnable = VK_FALSE;
6850 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6851 rs_state_ci.depthBiasEnable = VK_FALSE;
6852
Tony Barboureb254902015-07-15 12:50:33 -06006853 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006854 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6855 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006856 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006857 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6858 gp_ci.layout = pipeline_layout;
6859 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006860
6861 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006862 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6863 pc_ci.initialDataSize = 0;
6864 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006865
6866 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006867 VkPipelineCache pipelineCache;
6868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006869 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006870 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006871 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006872
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006873 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006874
Chia-I Wuf7458c52015-10-26 21:10:41 +08006875 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6876 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6877 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6878 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006879}
Tobin Ehlis912df022015-09-17 08:46:18 -06006880/*// TODO : This test should be good, but needs Tess support in compiler to run
6881TEST_F(VkLayerTest, InvalidPatchControlPoints)
6882{
6883 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006884 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006885
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006887 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6888primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006889
Tobin Ehlis912df022015-09-17 08:46:18 -06006890 ASSERT_NO_FATAL_FAILURE(InitState());
6891 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006892
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006893 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006894 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006895 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006896
6897 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6898 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6899 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006900 ds_pool_ci.poolSizeCount = 1;
6901 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006902
6903 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006904 err = vkCreateDescriptorPool(m_device->device(),
6905VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006906 ASSERT_VK_SUCCESS(err);
6907
6908 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006909 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006910 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006911 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006912 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6913 dsl_binding.pImmutableSamplers = NULL;
6914
6915 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006916 ds_layout_ci.sType =
6917VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006918 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006919 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006920 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006921
6922 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006923 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6924&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006925 ASSERT_VK_SUCCESS(err);
6926
6927 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006928 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6929VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006930 ASSERT_VK_SUCCESS(err);
6931
6932 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006933 pipeline_layout_ci.sType =
6934VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006935 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006936 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006937 pipeline_layout_ci.pSetLayouts = &ds_layout;
6938
6939 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006940 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6941&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006942 ASSERT_VK_SUCCESS(err);
6943
6944 VkPipelineShaderStageCreateInfo shaderStages[3];
6945 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6946
Karl Schultz6addd812016-02-02 17:17:23 -07006947 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6948this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006949 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006950 VkShaderObj
6951tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6952this);
6953 VkShaderObj
6954te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6955this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006956
Karl Schultz6addd812016-02-02 17:17:23 -07006957 shaderStages[0].sType =
6958VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006959 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006960 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006961 shaderStages[1].sType =
6962VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006963 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006964 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006965 shaderStages[2].sType =
6966VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006967 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006968 shaderStages[2].shader = te.handle();
6969
6970 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006971 iaCI.sType =
6972VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006973 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006974
6975 VkPipelineTessellationStateCreateInfo tsCI = {};
6976 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6977 tsCI.patchControlPoints = 0; // This will cause an error
6978
6979 VkGraphicsPipelineCreateInfo gp_ci = {};
6980 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6981 gp_ci.pNext = NULL;
6982 gp_ci.stageCount = 3;
6983 gp_ci.pStages = shaderStages;
6984 gp_ci.pVertexInputState = NULL;
6985 gp_ci.pInputAssemblyState = &iaCI;
6986 gp_ci.pTessellationState = &tsCI;
6987 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006988 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006989 gp_ci.pMultisampleState = NULL;
6990 gp_ci.pDepthStencilState = NULL;
6991 gp_ci.pColorBlendState = NULL;
6992 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6993 gp_ci.layout = pipeline_layout;
6994 gp_ci.renderPass = renderPass();
6995
6996 VkPipelineCacheCreateInfo pc_ci = {};
6997 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6998 pc_ci.pNext = NULL;
6999 pc_ci.initialSize = 0;
7000 pc_ci.initialData = 0;
7001 pc_ci.maxSize = 0;
7002
7003 VkPipeline pipeline;
7004 VkPipelineCache pipelineCache;
7005
Karl Schultz6addd812016-02-02 17:17:23 -07007006 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7007&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007008 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007009 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7010&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007011
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007012 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007013
Chia-I Wuf7458c52015-10-26 21:10:41 +08007014 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7015 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7016 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7017 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007018}
7019*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06007020// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07007021TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007022 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7025 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007026
Tobin Ehlise68360f2015-10-01 11:15:13 -06007027 ASSERT_NO_FATAL_FAILURE(InitState());
7028 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007029
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007030 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007031 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7032 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007033
7034 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007035 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7036 ds_pool_ci.maxSets = 1;
7037 ds_pool_ci.poolSizeCount = 1;
7038 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007039
7040 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007041 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007042 ASSERT_VK_SUCCESS(err);
7043
7044 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007045 dsl_binding.binding = 0;
7046 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7047 dsl_binding.descriptorCount = 1;
7048 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007049
7050 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007051 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7052 ds_layout_ci.bindingCount = 1;
7053 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007054
7055 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007056 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007057 ASSERT_VK_SUCCESS(err);
7058
7059 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007060 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007061 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007062 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007063 alloc_info.descriptorPool = ds_pool;
7064 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007065 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007066 ASSERT_VK_SUCCESS(err);
7067
7068 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007069 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7070 pipeline_layout_ci.setLayoutCount = 1;
7071 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007072
7073 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007074 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007075 ASSERT_VK_SUCCESS(err);
7076
7077 VkViewport vp = {}; // Just need dummy vp to point to
7078
7079 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007080 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7081 vp_state_ci.scissorCount = 0;
7082 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7083 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007084
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007085 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7086 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7087 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7088 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7089 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7090 rs_state_ci.depthClampEnable = VK_FALSE;
7091 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7092 rs_state_ci.depthBiasEnable = VK_FALSE;
7093
Cody Northropeb3a6c12015-10-05 14:44:45 -06007094 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007095 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007096
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007097 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7098 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7099 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007100 shaderStages[0] = vs.GetStageCreateInfo();
7101 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007102
7103 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007104 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7105 gp_ci.stageCount = 2;
7106 gp_ci.pStages = shaderStages;
7107 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007108 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007109 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7110 gp_ci.layout = pipeline_layout;
7111 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007112
7113 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007114 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007115
7116 VkPipeline pipeline;
7117 VkPipelineCache pipelineCache;
7118
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007119 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007120 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007121 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007122
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007123 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007124
Chia-I Wuf7458c52015-10-26 21:10:41 +08007125 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7126 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7127 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7128 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007129}
Karl Schultz6addd812016-02-02 17:17:23 -07007130// Don't set viewport state in PSO. This is an error b/c we always need this
7131// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007132// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007133TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007134 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007135 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007136
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007138
Tobin Ehlise68360f2015-10-01 11:15:13 -06007139 ASSERT_NO_FATAL_FAILURE(InitState());
7140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007141
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007142 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007143 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7144 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007145
7146 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007147 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7148 ds_pool_ci.maxSets = 1;
7149 ds_pool_ci.poolSizeCount = 1;
7150 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007151
7152 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007153 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007154 ASSERT_VK_SUCCESS(err);
7155
7156 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007157 dsl_binding.binding = 0;
7158 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7159 dsl_binding.descriptorCount = 1;
7160 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007161
7162 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007163 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7164 ds_layout_ci.bindingCount = 1;
7165 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007166
7167 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007168 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007169 ASSERT_VK_SUCCESS(err);
7170
7171 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007172 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007173 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007174 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007175 alloc_info.descriptorPool = ds_pool;
7176 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007177 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007178 ASSERT_VK_SUCCESS(err);
7179
7180 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007181 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7182 pipeline_layout_ci.setLayoutCount = 1;
7183 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007184
7185 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007186 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007187 ASSERT_VK_SUCCESS(err);
7188
7189 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7190 // Set scissor as dynamic to avoid second error
7191 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007192 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7193 dyn_state_ci.dynamicStateCount = 1;
7194 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007195
Cody Northropeb3a6c12015-10-05 14:44:45 -06007196 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007197 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007198
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007199 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7200 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7201 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007202 shaderStages[0] = vs.GetStageCreateInfo();
7203 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007204
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007205 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7206 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7207 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7208 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7209 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7210 rs_state_ci.depthClampEnable = VK_FALSE;
7211 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7212 rs_state_ci.depthBiasEnable = VK_FALSE;
7213
Tobin Ehlise68360f2015-10-01 11:15:13 -06007214 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007215 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7216 gp_ci.stageCount = 2;
7217 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007218 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007219 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7220 // should cause validation error
7221 gp_ci.pDynamicState = &dyn_state_ci;
7222 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7223 gp_ci.layout = pipeline_layout;
7224 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007225
7226 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007227 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007228
7229 VkPipeline pipeline;
7230 VkPipelineCache pipelineCache;
7231
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007232 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007233 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007234 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007235
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007236 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007237
Chia-I Wuf7458c52015-10-26 21:10:41 +08007238 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7239 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7240 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7241 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007242}
7243// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007244// Then run second test where dynamic scissor count doesn't match PSO scissor
7245// count
7246TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7247 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007248
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7250 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007251
Tobin Ehlise68360f2015-10-01 11:15:13 -06007252 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007253
7254 if (!m_device->phy().features().multiViewport) {
7255 printf("Device does not support multiple viewports/scissors; skipped.\n");
7256 return;
7257 }
7258
Tobin Ehlise68360f2015-10-01 11:15:13 -06007259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007260
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007261 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007262 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7263 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007264
7265 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007266 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7267 ds_pool_ci.maxSets = 1;
7268 ds_pool_ci.poolSizeCount = 1;
7269 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007270
7271 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007272 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007273 ASSERT_VK_SUCCESS(err);
7274
7275 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007276 dsl_binding.binding = 0;
7277 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7278 dsl_binding.descriptorCount = 1;
7279 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007280
7281 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007282 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7283 ds_layout_ci.bindingCount = 1;
7284 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007285
7286 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007287 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007288 ASSERT_VK_SUCCESS(err);
7289
7290 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007291 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007292 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007293 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007294 alloc_info.descriptorPool = ds_pool;
7295 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007296 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007297 ASSERT_VK_SUCCESS(err);
7298
7299 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007300 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7301 pipeline_layout_ci.setLayoutCount = 1;
7302 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007303
7304 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007305 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007306 ASSERT_VK_SUCCESS(err);
7307
7308 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007309 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7310 vp_state_ci.viewportCount = 1;
7311 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7312 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007313 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007314
7315 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7316 // Set scissor as dynamic to avoid that error
7317 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007318 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7319 dyn_state_ci.dynamicStateCount = 1;
7320 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007321
Cody Northropeb3a6c12015-10-05 14:44:45 -06007322 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007323 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007324
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007325 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7326 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7327 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007328 shaderStages[0] = vs.GetStageCreateInfo();
7329 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007330
Cody Northropf6622dc2015-10-06 10:33:21 -06007331 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7332 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7333 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007334 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007335 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007336 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007337 vi_ci.pVertexAttributeDescriptions = nullptr;
7338
7339 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7340 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7341 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7342
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007343 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007344 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007345 rs_ci.pNext = nullptr;
7346
Mark Youngc89c6312016-03-31 16:03:20 -06007347 VkPipelineColorBlendAttachmentState att = {};
7348 att.blendEnable = VK_FALSE;
7349 att.colorWriteMask = 0xf;
7350
Cody Northropf6622dc2015-10-06 10:33:21 -06007351 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7352 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7353 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007354 cb_ci.attachmentCount = 1;
7355 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007356
Tobin Ehlise68360f2015-10-01 11:15:13 -06007357 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007358 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7359 gp_ci.stageCount = 2;
7360 gp_ci.pStages = shaderStages;
7361 gp_ci.pVertexInputState = &vi_ci;
7362 gp_ci.pInputAssemblyState = &ia_ci;
7363 gp_ci.pViewportState = &vp_state_ci;
7364 gp_ci.pRasterizationState = &rs_ci;
7365 gp_ci.pColorBlendState = &cb_ci;
7366 gp_ci.pDynamicState = &dyn_state_ci;
7367 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7368 gp_ci.layout = pipeline_layout;
7369 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007370
7371 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007372 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007373
7374 VkPipeline pipeline;
7375 VkPipelineCache pipelineCache;
7376
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007377 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007378 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007379 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007380
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007381 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007382
Tobin Ehlisd332f282015-10-02 11:00:56 -06007383 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007384 // First need to successfully create the PSO from above by setting
7385 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007386 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 -07007387
7388 VkViewport vp = {}; // Just need dummy vp to point to
7389 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007390 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007391 ASSERT_VK_SUCCESS(err);
7392 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007393 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007394 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007395 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007396 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007397 Draw(1, 0, 0, 0);
7398
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007399 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007400
7401 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7402 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7403 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7404 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007405 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007406}
7407// Create PSO w/o non-zero scissorCount but no scissor data
7408// Then run second test where dynamic viewportCount doesn't match PSO
7409// viewportCount
7410TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7411 VkResult err;
7412
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007413 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 -07007414
7415 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007416
7417 if (!m_device->phy().features().multiViewport) {
7418 printf("Device does not support multiple viewports/scissors; skipped.\n");
7419 return;
7420 }
7421
Karl Schultz6addd812016-02-02 17:17:23 -07007422 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7423
7424 VkDescriptorPoolSize ds_type_count = {};
7425 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7426 ds_type_count.descriptorCount = 1;
7427
7428 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7429 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7430 ds_pool_ci.maxSets = 1;
7431 ds_pool_ci.poolSizeCount = 1;
7432 ds_pool_ci.pPoolSizes = &ds_type_count;
7433
7434 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007435 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007436 ASSERT_VK_SUCCESS(err);
7437
7438 VkDescriptorSetLayoutBinding dsl_binding = {};
7439 dsl_binding.binding = 0;
7440 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7441 dsl_binding.descriptorCount = 1;
7442 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7443
7444 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7445 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7446 ds_layout_ci.bindingCount = 1;
7447 ds_layout_ci.pBindings = &dsl_binding;
7448
7449 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007450 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007451 ASSERT_VK_SUCCESS(err);
7452
7453 VkDescriptorSet descriptorSet;
7454 VkDescriptorSetAllocateInfo alloc_info = {};
7455 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7456 alloc_info.descriptorSetCount = 1;
7457 alloc_info.descriptorPool = ds_pool;
7458 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007459 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007460 ASSERT_VK_SUCCESS(err);
7461
7462 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7463 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7464 pipeline_layout_ci.setLayoutCount = 1;
7465 pipeline_layout_ci.pSetLayouts = &ds_layout;
7466
7467 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007468 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007469 ASSERT_VK_SUCCESS(err);
7470
7471 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7472 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7473 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007474 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007475 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007476 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007477
7478 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7479 // Set scissor as dynamic to avoid that error
7480 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7481 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7482 dyn_state_ci.dynamicStateCount = 1;
7483 dyn_state_ci.pDynamicStates = &vp_state;
7484
7485 VkPipelineShaderStageCreateInfo shaderStages[2];
7486 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7487
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007488 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7489 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7490 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007491 shaderStages[0] = vs.GetStageCreateInfo();
7492 shaderStages[1] = fs.GetStageCreateInfo();
7493
7494 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7495 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7496 vi_ci.pNext = nullptr;
7497 vi_ci.vertexBindingDescriptionCount = 0;
7498 vi_ci.pVertexBindingDescriptions = nullptr;
7499 vi_ci.vertexAttributeDescriptionCount = 0;
7500 vi_ci.pVertexAttributeDescriptions = nullptr;
7501
7502 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7503 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7504 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7505
7506 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7507 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7508 rs_ci.pNext = nullptr;
7509
Mark Youngc89c6312016-03-31 16:03:20 -06007510 VkPipelineColorBlendAttachmentState att = {};
7511 att.blendEnable = VK_FALSE;
7512 att.colorWriteMask = 0xf;
7513
Karl Schultz6addd812016-02-02 17:17:23 -07007514 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7515 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7516 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007517 cb_ci.attachmentCount = 1;
7518 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007519
7520 VkGraphicsPipelineCreateInfo gp_ci = {};
7521 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7522 gp_ci.stageCount = 2;
7523 gp_ci.pStages = shaderStages;
7524 gp_ci.pVertexInputState = &vi_ci;
7525 gp_ci.pInputAssemblyState = &ia_ci;
7526 gp_ci.pViewportState = &vp_state_ci;
7527 gp_ci.pRasterizationState = &rs_ci;
7528 gp_ci.pColorBlendState = &cb_ci;
7529 gp_ci.pDynamicState = &dyn_state_ci;
7530 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7531 gp_ci.layout = pipeline_layout;
7532 gp_ci.renderPass = renderPass();
7533
7534 VkPipelineCacheCreateInfo pc_ci = {};
7535 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7536
7537 VkPipeline pipeline;
7538 VkPipelineCache pipelineCache;
7539
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007540 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007541 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007542 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007543
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007544 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007545
7546 // Now hit second fail case where we set scissor w/ different count than PSO
7547 // First need to successfully create the PSO from above by setting
7548 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007549 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 -06007550
Tobin Ehlisd332f282015-10-02 11:00:56 -06007551 VkRect2D sc = {}; // Just need dummy vp to point to
7552 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007553 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007554 ASSERT_VK_SUCCESS(err);
7555 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007556 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007557 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007558 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007559 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007560 Draw(1, 0, 0, 0);
7561
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007562 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007563
Chia-I Wuf7458c52015-10-26 21:10:41 +08007564 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7565 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7566 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7567 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007568 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007569}
7570
Mark Young7394fdd2016-03-31 14:56:43 -06007571TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7572 VkResult err;
7573
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007575
7576 ASSERT_NO_FATAL_FAILURE(InitState());
7577 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7578
7579 VkDescriptorPoolSize ds_type_count = {};
7580 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7581 ds_type_count.descriptorCount = 1;
7582
7583 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7584 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7585 ds_pool_ci.maxSets = 1;
7586 ds_pool_ci.poolSizeCount = 1;
7587 ds_pool_ci.pPoolSizes = &ds_type_count;
7588
7589 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007590 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007591 ASSERT_VK_SUCCESS(err);
7592
7593 VkDescriptorSetLayoutBinding dsl_binding = {};
7594 dsl_binding.binding = 0;
7595 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7596 dsl_binding.descriptorCount = 1;
7597 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7598
7599 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7600 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7601 ds_layout_ci.bindingCount = 1;
7602 ds_layout_ci.pBindings = &dsl_binding;
7603
7604 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007605 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007606 ASSERT_VK_SUCCESS(err);
7607
7608 VkDescriptorSet descriptorSet;
7609 VkDescriptorSetAllocateInfo alloc_info = {};
7610 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7611 alloc_info.descriptorSetCount = 1;
7612 alloc_info.descriptorPool = ds_pool;
7613 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007614 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007615 ASSERT_VK_SUCCESS(err);
7616
7617 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7618 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7619 pipeline_layout_ci.setLayoutCount = 1;
7620 pipeline_layout_ci.pSetLayouts = &ds_layout;
7621
7622 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007623 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007624 ASSERT_VK_SUCCESS(err);
7625
7626 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7627 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7628 vp_state_ci.scissorCount = 1;
7629 vp_state_ci.pScissors = NULL;
7630 vp_state_ci.viewportCount = 1;
7631 vp_state_ci.pViewports = NULL;
7632
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007633 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007634 // Set scissor as dynamic to avoid that error
7635 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7636 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7637 dyn_state_ci.dynamicStateCount = 2;
7638 dyn_state_ci.pDynamicStates = dynamic_states;
7639
7640 VkPipelineShaderStageCreateInfo shaderStages[2];
7641 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7642
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007643 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7644 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007645 this); // TODO - We shouldn't need a fragment shader
7646 // but add it to be able to run on more devices
7647 shaderStages[0] = vs.GetStageCreateInfo();
7648 shaderStages[1] = fs.GetStageCreateInfo();
7649
7650 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7651 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7652 vi_ci.pNext = nullptr;
7653 vi_ci.vertexBindingDescriptionCount = 0;
7654 vi_ci.pVertexBindingDescriptions = nullptr;
7655 vi_ci.vertexAttributeDescriptionCount = 0;
7656 vi_ci.pVertexAttributeDescriptions = nullptr;
7657
7658 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7659 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7660 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7661
7662 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7663 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7664 rs_ci.pNext = nullptr;
7665
Mark Young47107952016-05-02 15:59:55 -06007666 // Check too low (line width of -1.0f).
7667 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007668
7669 VkPipelineColorBlendAttachmentState att = {};
7670 att.blendEnable = VK_FALSE;
7671 att.colorWriteMask = 0xf;
7672
7673 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7674 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7675 cb_ci.pNext = nullptr;
7676 cb_ci.attachmentCount = 1;
7677 cb_ci.pAttachments = &att;
7678
7679 VkGraphicsPipelineCreateInfo gp_ci = {};
7680 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7681 gp_ci.stageCount = 2;
7682 gp_ci.pStages = shaderStages;
7683 gp_ci.pVertexInputState = &vi_ci;
7684 gp_ci.pInputAssemblyState = &ia_ci;
7685 gp_ci.pViewportState = &vp_state_ci;
7686 gp_ci.pRasterizationState = &rs_ci;
7687 gp_ci.pColorBlendState = &cb_ci;
7688 gp_ci.pDynamicState = &dyn_state_ci;
7689 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7690 gp_ci.layout = pipeline_layout;
7691 gp_ci.renderPass = renderPass();
7692
7693 VkPipelineCacheCreateInfo pc_ci = {};
7694 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7695
7696 VkPipeline pipeline;
7697 VkPipelineCache pipelineCache;
7698
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007699 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007700 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007701 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007702
7703 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007704 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007705
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007707
7708 // Check too high (line width of 65536.0f).
7709 rs_ci.lineWidth = 65536.0f;
7710
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007711 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007712 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007713 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007714
7715 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007716 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007717
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007719
7720 dyn_state_ci.dynamicStateCount = 3;
7721
7722 rs_ci.lineWidth = 1.0f;
7723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007724 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007725 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007726 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007727 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007728 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007729
7730 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007731 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007732 m_errorMonitor->VerifyFound();
7733
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007735
7736 // Check too high with dynamic setting.
7737 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7738 m_errorMonitor->VerifyFound();
7739 EndCommandBuffer();
7740
7741 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7742 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7743 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7744 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007745 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007746}
7747
Karl Schultz6addd812016-02-02 17:17:23 -07007748TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007749 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7751 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007752
7753 ASSERT_NO_FATAL_FAILURE(InitState());
7754 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007755
Tony Barbourfe3351b2015-07-28 10:17:20 -06007756 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007757 // Don't care about RenderPass handle b/c error should be flagged before
7758 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007759 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007760
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007761 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007762}
7763
Karl Schultz6addd812016-02-02 17:17:23 -07007764TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007765 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7767 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007768
7769 ASSERT_NO_FATAL_FAILURE(InitState());
7770 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007771
Tony Barbourfe3351b2015-07-28 10:17:20 -06007772 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007773 // Just create a dummy Renderpass that's non-NULL so we can get to the
7774 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007775 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007776
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007777 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007778}
7779
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007780TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7781 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7782 "the number of renderPass attachments that use loadOp"
7783 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7784
7785 ASSERT_NO_FATAL_FAILURE(InitState());
7786 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7787
7788 // Create a renderPass with a single attachment that uses loadOp CLEAR
7789 VkAttachmentReference attach = {};
7790 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7791 VkSubpassDescription subpass = {};
7792 subpass.inputAttachmentCount = 1;
7793 subpass.pInputAttachments = &attach;
7794 VkRenderPassCreateInfo rpci = {};
7795 rpci.subpassCount = 1;
7796 rpci.pSubpasses = &subpass;
7797 rpci.attachmentCount = 1;
7798 VkAttachmentDescription attach_desc = {};
7799 attach_desc.format = VK_FORMAT_UNDEFINED;
7800 // Set loadOp to CLEAR
7801 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7802 rpci.pAttachments = &attach_desc;
7803 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7804 VkRenderPass rp;
7805 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7806
7807 VkCommandBufferInheritanceInfo hinfo = {};
7808 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7809 hinfo.renderPass = VK_NULL_HANDLE;
7810 hinfo.subpass = 0;
7811 hinfo.framebuffer = VK_NULL_HANDLE;
7812 hinfo.occlusionQueryEnable = VK_FALSE;
7813 hinfo.queryFlags = 0;
7814 hinfo.pipelineStatistics = 0;
7815 VkCommandBufferBeginInfo info = {};
7816 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7817 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7818 info.pInheritanceInfo = &hinfo;
7819
7820 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7821 VkRenderPassBeginInfo rp_begin = {};
7822 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7823 rp_begin.pNext = NULL;
7824 rp_begin.renderPass = renderPass();
7825 rp_begin.framebuffer = framebuffer();
7826 rp_begin.clearValueCount = 0; // Should be 1
7827
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7829 "there must be at least 1 entries in "
7830 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007831
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007832 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007833
7834 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007835
7836 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007837}
7838
Cody Northrop3bb4d962016-05-09 16:15:57 -06007839TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7840
7841 TEST_DESCRIPTION("End a command buffer with an active render pass");
7842
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7844 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007845
7846 ASSERT_NO_FATAL_FAILURE(InitState());
7847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7848
7849 // The framework's BeginCommandBuffer calls CreateRenderPass
7850 BeginCommandBuffer();
7851
7852 // Call directly into vkEndCommandBuffer instead of the
7853 // the framework's EndCommandBuffer, which inserts a
7854 // vkEndRenderPass
7855 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7856
7857 m_errorMonitor->VerifyFound();
7858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007859 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7860 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007861}
7862
Karl Schultz6addd812016-02-02 17:17:23 -07007863TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007864 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7866 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007867
7868 ASSERT_NO_FATAL_FAILURE(InitState());
7869 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007870
7871 // Renderpass is started here
7872 BeginCommandBuffer();
7873
7874 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007875 vk_testing::Buffer dstBuffer;
7876 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007877
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007878 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007879
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007880 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007881}
7882
Karl Schultz6addd812016-02-02 17:17:23 -07007883TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007884 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7886 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007887
7888 ASSERT_NO_FATAL_FAILURE(InitState());
7889 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007890
7891 // Renderpass is started here
7892 BeginCommandBuffer();
7893
7894 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007895 vk_testing::Buffer dstBuffer;
7896 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007897
Karl Schultz6addd812016-02-02 17:17:23 -07007898 VkDeviceSize dstOffset = 0;
7899 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007900 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007901
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007902 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007903
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007904 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007905}
7906
Karl Schultz6addd812016-02-02 17:17:23 -07007907TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007908 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7910 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007911
7912 ASSERT_NO_FATAL_FAILURE(InitState());
7913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007914
7915 // Renderpass is started here
7916 BeginCommandBuffer();
7917
Michael Lentine0a369f62016-02-03 16:51:46 -06007918 VkClearColorValue clear_color;
7919 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007920 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7921 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7922 const int32_t tex_width = 32;
7923 const int32_t tex_height = 32;
7924 VkImageCreateInfo image_create_info = {};
7925 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7926 image_create_info.pNext = NULL;
7927 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7928 image_create_info.format = tex_format;
7929 image_create_info.extent.width = tex_width;
7930 image_create_info.extent.height = tex_height;
7931 image_create_info.extent.depth = 1;
7932 image_create_info.mipLevels = 1;
7933 image_create_info.arrayLayers = 1;
7934 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7935 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7936 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007937
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007938 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007939 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007940
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007941 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007942
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007943 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007944
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007945 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007946}
7947
Karl Schultz6addd812016-02-02 17:17:23 -07007948TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007949 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7951 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007952
7953 ASSERT_NO_FATAL_FAILURE(InitState());
7954 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007955
7956 // Renderpass is started here
7957 BeginCommandBuffer();
7958
7959 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007960 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007961 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7962 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7963 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7964 image_create_info.extent.width = 64;
7965 image_create_info.extent.height = 64;
7966 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7967 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007968
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007969 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007970 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007971
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007972 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007973
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007974 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7975 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007976
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007977 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007978}
7979
Karl Schultz6addd812016-02-02 17:17:23 -07007980TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007981 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007982 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007983
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
7985 "must be issued inside an active "
7986 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007987
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007988 ASSERT_NO_FATAL_FAILURE(InitState());
7989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007990
7991 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007992 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007993 ASSERT_VK_SUCCESS(err);
7994
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007995 VkClearAttachment color_attachment;
7996 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7997 color_attachment.clearValue.color.float32[0] = 0;
7998 color_attachment.clearValue.color.float32[1] = 0;
7999 color_attachment.clearValue.color.float32[2] = 0;
8000 color_attachment.clearValue.color.float32[3] = 0;
8001 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008002 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008003 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008004
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008005 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008006}
8007
Chris Forbes3b97e932016-09-07 11:29:24 +12008008TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8009 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8010 "called too many times in a renderpass instance");
8011
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8013 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008014
8015 ASSERT_NO_FATAL_FAILURE(InitState());
8016 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8017
8018 BeginCommandBuffer();
8019
8020 // error here.
8021 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8022 m_errorMonitor->VerifyFound();
8023
8024 EndCommandBuffer();
8025}
8026
Chris Forbes6d624702016-09-07 13:57:05 +12008027TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8028 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8029 "called before the final subpass has been reached");
8030
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8032 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008033
8034 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008035 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8036 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008037
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008038 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008039
8040 VkRenderPass rp;
8041 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8042 ASSERT_VK_SUCCESS(err);
8043
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008044 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008045
8046 VkFramebuffer fb;
8047 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8048 ASSERT_VK_SUCCESS(err);
8049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008050 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008051
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008052 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 +12008053
8054 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8055
8056 // Error here.
8057 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8058 m_errorMonitor->VerifyFound();
8059
8060 // Clean up.
8061 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8062 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8063}
8064
Karl Schultz9e66a292016-04-21 15:57:51 -06008065TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8066 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8068 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008069
8070 ASSERT_NO_FATAL_FAILURE(InitState());
8071 BeginCommandBuffer();
8072
8073 VkBufferMemoryBarrier buf_barrier = {};
8074 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8075 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8076 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8077 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8078 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8079 buf_barrier.buffer = VK_NULL_HANDLE;
8080 buf_barrier.offset = 0;
8081 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008082 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8083 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008084
8085 m_errorMonitor->VerifyFound();
8086}
8087
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008088TEST_F(VkLayerTest, InvalidBarriers) {
8089 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8090
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008092
8093 ASSERT_NO_FATAL_FAILURE(InitState());
8094 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8095
8096 VkMemoryBarrier mem_barrier = {};
8097 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8098 mem_barrier.pNext = NULL;
8099 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8100 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8101 BeginCommandBuffer();
8102 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008103 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008104 &mem_barrier, 0, nullptr, 0, nullptr);
8105 m_errorMonitor->VerifyFound();
8106
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008108 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008109 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 -06008110 ASSERT_TRUE(image.initialized());
8111 VkImageMemoryBarrier img_barrier = {};
8112 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8113 img_barrier.pNext = NULL;
8114 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8115 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8116 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8117 // New layout can't be UNDEFINED
8118 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8119 img_barrier.image = image.handle();
8120 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8121 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8122 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8123 img_barrier.subresourceRange.baseArrayLayer = 0;
8124 img_barrier.subresourceRange.baseMipLevel = 0;
8125 img_barrier.subresourceRange.layerCount = 1;
8126 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008127 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8128 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008129 m_errorMonitor->VerifyFound();
8130 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8131
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8133 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008134 // baseArrayLayer + layerCount must be <= image's arrayLayers
8135 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008136 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8137 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008138 m_errorMonitor->VerifyFound();
8139 img_barrier.subresourceRange.baseArrayLayer = 0;
8140
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008142 // baseMipLevel + levelCount must be <= image's mipLevels
8143 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008144 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8145 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008146 m_errorMonitor->VerifyFound();
8147 img_barrier.subresourceRange.baseMipLevel = 0;
8148
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008149 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 -06008150 vk_testing::Buffer buffer;
8151 buffer.init(*m_device, 256);
8152 VkBufferMemoryBarrier buf_barrier = {};
8153 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8154 buf_barrier.pNext = NULL;
8155 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8156 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8157 buf_barrier.buffer = buffer.handle();
8158 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8159 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8160 buf_barrier.offset = 0;
8161 buf_barrier.size = VK_WHOLE_SIZE;
8162 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008163 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8164 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008165 m_errorMonitor->VerifyFound();
8166 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8167
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008169 buf_barrier.offset = 257;
8170 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008171 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8172 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008173 m_errorMonitor->VerifyFound();
8174 buf_barrier.offset = 0;
8175
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008177 buf_barrier.size = 257;
8178 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008179 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8180 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008181 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008182
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008183 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008184 m_errorMonitor->SetDesiredFailureMsg(
8185 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8186 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8187 m_errorMonitor->SetDesiredFailureMsg(
8188 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8189 "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 -06008190 VkDepthStencilObj ds_image(m_device);
8191 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8192 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008193 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8194 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008195 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008196 // Use of COLOR aspect on DS image is error
8197 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008198 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8199 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008200 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008201 // Now test depth-only
8202 VkFormatProperties format_props;
8203
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008204 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8205 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8207 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8209 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008210 VkDepthStencilObj d_image(m_device);
8211 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8212 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008213 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008214 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008215 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008216 // Use of COLOR aspect on depth image is error
8217 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008218 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8219 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008220 m_errorMonitor->VerifyFound();
8221 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008222 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8223 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008224 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8226 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008227 VkDepthStencilObj s_image(m_device);
8228 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8229 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008230 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008231 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008232 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008233 // Use of COLOR aspect on depth image is error
8234 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008235 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8236 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008237 m_errorMonitor->VerifyFound();
8238 }
8239 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8241 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8243 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008244 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008245 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 -06008246 ASSERT_TRUE(c_image.initialized());
8247 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8248 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8249 img_barrier.image = c_image.handle();
8250 // Set aspect to depth (non-color)
8251 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008252 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8253 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008254 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008255}
8256
Tony Barbour18ba25c2016-09-29 13:42:40 -06008257TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8258 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8259
8260 m_errorMonitor->SetDesiredFailureMsg(
8261 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8262 "must have required access bit");
8263 ASSERT_NO_FATAL_FAILURE(InitState());
8264 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008265 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 -06008266 ASSERT_TRUE(image.initialized());
8267
8268 VkImageMemoryBarrier barrier = {};
8269 VkImageSubresourceRange range;
8270 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8271 barrier.srcAccessMask = 0;
8272 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8273 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8274 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8275 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8276 barrier.image = image.handle();
8277 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8278 range.baseMipLevel = 0;
8279 range.levelCount = 1;
8280 range.baseArrayLayer = 0;
8281 range.layerCount = 1;
8282 barrier.subresourceRange = range;
8283 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8284 cmdbuf.BeginCommandBuffer();
8285 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8286 &barrier);
8287 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8288 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8289 barrier.srcAccessMask = 0;
8290 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8291 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8292 &barrier);
8293
8294 m_errorMonitor->VerifyFound();
8295}
8296
Karl Schultz6addd812016-02-02 17:17:23 -07008297TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008298 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008299 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008300
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008302
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008303 ASSERT_NO_FATAL_FAILURE(InitState());
8304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008305 uint32_t qfi = 0;
8306 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008307 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8308 buffCI.size = 1024;
8309 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8310 buffCI.queueFamilyIndexCount = 1;
8311 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008312
8313 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008314 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008315 ASSERT_VK_SUCCESS(err);
8316
8317 BeginCommandBuffer();
8318 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008319 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8320 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008321 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008322 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008323
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008324 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008325
Chia-I Wuf7458c52015-10-26 21:10:41 +08008326 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008327}
8328
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008329TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8330 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8332 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8333 "of the indices specified when the device was created, via the "
8334 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008335
8336 ASSERT_NO_FATAL_FAILURE(InitState());
8337 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8338 VkBufferCreateInfo buffCI = {};
8339 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8340 buffCI.size = 1024;
8341 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8342 buffCI.queueFamilyIndexCount = 1;
8343 // Introduce failure by specifying invalid queue_family_index
8344 uint32_t qfi = 777;
8345 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008346 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008347
8348 VkBuffer ib;
8349 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8350
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008351 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008352 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008353}
8354
Karl Schultz6addd812016-02-02 17:17:23 -07008355TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008356TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008357 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008358
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008359 ASSERT_NO_FATAL_FAILURE(InitState());
8360 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008361
Chris Forbesf29a84f2016-10-06 18:39:28 +13008362 // An empty primary command buffer
8363 VkCommandBufferObj cb(m_device, m_commandPool);
8364 cb.BeginCommandBuffer();
8365 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008366
Chris Forbesf29a84f2016-10-06 18:39:28 +13008367 m_commandBuffer->BeginCommandBuffer();
8368 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8369 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008370
Chris Forbesf29a84f2016-10-06 18:39:28 +13008371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8372 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008373 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008374}
8375
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008376TEST_F(VkLayerTest, DSUsageBitsErrors) {
8377 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8378 "that do not have correct usage bits sets.");
8379 VkResult err;
8380
8381 ASSERT_NO_FATAL_FAILURE(InitState());
8382 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8383 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8384 ds_type_count[i].type = VkDescriptorType(i);
8385 ds_type_count[i].descriptorCount = 1;
8386 }
8387 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8388 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8389 ds_pool_ci.pNext = NULL;
8390 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8391 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8392 ds_pool_ci.pPoolSizes = ds_type_count;
8393
8394 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008395 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008396 ASSERT_VK_SUCCESS(err);
8397
8398 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008399 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008400 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8401 dsl_binding[i].binding = 0;
8402 dsl_binding[i].descriptorType = VkDescriptorType(i);
8403 dsl_binding[i].descriptorCount = 1;
8404 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8405 dsl_binding[i].pImmutableSamplers = NULL;
8406 }
8407
8408 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8409 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8410 ds_layout_ci.pNext = NULL;
8411 ds_layout_ci.bindingCount = 1;
8412 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8413 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8414 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008415 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008416 ASSERT_VK_SUCCESS(err);
8417 }
8418 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8419 VkDescriptorSetAllocateInfo alloc_info = {};
8420 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8421 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8422 alloc_info.descriptorPool = ds_pool;
8423 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008424 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008425 ASSERT_VK_SUCCESS(err);
8426
8427 // Create a buffer & bufferView to be used for invalid updates
8428 VkBufferCreateInfo buff_ci = {};
8429 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8430 // This usage is not valid for any descriptor type
8431 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8432 buff_ci.size = 256;
8433 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8434 VkBuffer buffer;
8435 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8436 ASSERT_VK_SUCCESS(err);
8437
8438 VkBufferViewCreateInfo buff_view_ci = {};
8439 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8440 buff_view_ci.buffer = buffer;
8441 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8442 buff_view_ci.range = VK_WHOLE_SIZE;
8443 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008444 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008445 ASSERT_VK_SUCCESS(err);
8446
8447 // Create an image to be used for invalid updates
8448 VkImageCreateInfo image_ci = {};
8449 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8450 image_ci.imageType = VK_IMAGE_TYPE_2D;
8451 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8452 image_ci.extent.width = 64;
8453 image_ci.extent.height = 64;
8454 image_ci.extent.depth = 1;
8455 image_ci.mipLevels = 1;
8456 image_ci.arrayLayers = 1;
8457 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8458 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8459 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8460 // This usage is not valid for any descriptor type
8461 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8462 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8463 VkImage image;
8464 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8465 ASSERT_VK_SUCCESS(err);
8466 // Bind memory to image
8467 VkMemoryRequirements mem_reqs;
8468 VkDeviceMemory image_mem;
8469 bool pass;
8470 VkMemoryAllocateInfo mem_alloc = {};
8471 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8472 mem_alloc.pNext = NULL;
8473 mem_alloc.allocationSize = 0;
8474 mem_alloc.memoryTypeIndex = 0;
8475 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8476 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008477 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008478 ASSERT_TRUE(pass);
8479 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8480 ASSERT_VK_SUCCESS(err);
8481 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8482 ASSERT_VK_SUCCESS(err);
8483 // Now create view for image
8484 VkImageViewCreateInfo image_view_ci = {};
8485 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8486 image_view_ci.image = image;
8487 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8488 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8489 image_view_ci.subresourceRange.layerCount = 1;
8490 image_view_ci.subresourceRange.baseArrayLayer = 0;
8491 image_view_ci.subresourceRange.levelCount = 1;
8492 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8493 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008494 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008495 ASSERT_VK_SUCCESS(err);
8496
8497 VkDescriptorBufferInfo buff_info = {};
8498 buff_info.buffer = buffer;
8499 VkDescriptorImageInfo img_info = {};
8500 img_info.imageView = image_view;
8501 VkWriteDescriptorSet descriptor_write = {};
8502 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8503 descriptor_write.dstBinding = 0;
8504 descriptor_write.descriptorCount = 1;
8505 descriptor_write.pTexelBufferView = &buff_view;
8506 descriptor_write.pBufferInfo = &buff_info;
8507 descriptor_write.pImageInfo = &img_info;
8508
8509 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008510 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8511 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8512 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8513 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8514 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8515 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8516 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8517 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8518 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8519 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8520 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008521 // Start loop at 1 as SAMPLER desc type has no usage bit error
8522 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8523 descriptor_write.descriptorType = VkDescriptorType(i);
8524 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008526
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008527 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008528
8529 m_errorMonitor->VerifyFound();
8530 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8531 }
8532 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8533 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008534 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008535 vkDestroyImageView(m_device->device(), image_view, NULL);
8536 vkDestroyBuffer(m_device->device(), buffer, NULL);
8537 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008538 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008539 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8540}
8541
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008542TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008543 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8544 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8545 "1. offset value greater than buffer size\n"
8546 "2. range value of 0\n"
8547 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008548 VkResult err;
8549
8550 ASSERT_NO_FATAL_FAILURE(InitState());
8551 VkDescriptorPoolSize ds_type_count = {};
8552 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8553 ds_type_count.descriptorCount = 1;
8554
8555 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8556 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8557 ds_pool_ci.pNext = NULL;
8558 ds_pool_ci.maxSets = 1;
8559 ds_pool_ci.poolSizeCount = 1;
8560 ds_pool_ci.pPoolSizes = &ds_type_count;
8561
8562 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008563 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008564 ASSERT_VK_SUCCESS(err);
8565
8566 // Create layout with single uniform buffer descriptor
8567 VkDescriptorSetLayoutBinding dsl_binding = {};
8568 dsl_binding.binding = 0;
8569 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8570 dsl_binding.descriptorCount = 1;
8571 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8572 dsl_binding.pImmutableSamplers = NULL;
8573
8574 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8575 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8576 ds_layout_ci.pNext = NULL;
8577 ds_layout_ci.bindingCount = 1;
8578 ds_layout_ci.pBindings = &dsl_binding;
8579 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008580 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008581 ASSERT_VK_SUCCESS(err);
8582
8583 VkDescriptorSet descriptor_set = {};
8584 VkDescriptorSetAllocateInfo alloc_info = {};
8585 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8586 alloc_info.descriptorSetCount = 1;
8587 alloc_info.descriptorPool = ds_pool;
8588 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008589 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008590 ASSERT_VK_SUCCESS(err);
8591
8592 // Create a buffer to be used for invalid updates
8593 VkBufferCreateInfo buff_ci = {};
8594 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8595 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8596 buff_ci.size = 256;
8597 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8598 VkBuffer buffer;
8599 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8600 ASSERT_VK_SUCCESS(err);
8601 // Have to bind memory to buffer before descriptor update
8602 VkMemoryAllocateInfo mem_alloc = {};
8603 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8604 mem_alloc.pNext = NULL;
8605 mem_alloc.allocationSize = 256;
8606 mem_alloc.memoryTypeIndex = 0;
8607
8608 VkMemoryRequirements mem_reqs;
8609 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008610 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008611 if (!pass) {
8612 vkDestroyBuffer(m_device->device(), buffer, NULL);
8613 return;
8614 }
8615
8616 VkDeviceMemory mem;
8617 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8618 ASSERT_VK_SUCCESS(err);
8619 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8620 ASSERT_VK_SUCCESS(err);
8621
8622 VkDescriptorBufferInfo buff_info = {};
8623 buff_info.buffer = buffer;
8624 // First make offset 1 larger than buffer size
8625 buff_info.offset = 257;
8626 buff_info.range = VK_WHOLE_SIZE;
8627 VkWriteDescriptorSet descriptor_write = {};
8628 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8629 descriptor_write.dstBinding = 0;
8630 descriptor_write.descriptorCount = 1;
8631 descriptor_write.pTexelBufferView = nullptr;
8632 descriptor_write.pBufferInfo = &buff_info;
8633 descriptor_write.pImageInfo = nullptr;
8634
8635 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8636 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008638
8639 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8640
8641 m_errorMonitor->VerifyFound();
8642 // Now cause error due to range of 0
8643 buff_info.offset = 0;
8644 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8646 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008647
8648 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8649
8650 m_errorMonitor->VerifyFound();
8651 // Now cause error due to range exceeding buffer size - offset
8652 buff_info.offset = 128;
8653 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008654 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 -06008655
8656 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8657
8658 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008659 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008660 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8661 vkDestroyBuffer(m_device->device(), buffer, NULL);
8662 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8663 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8664}
8665
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008666TEST_F(VkLayerTest, DSAspectBitsErrors) {
8667 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8668 // are set, but could expand this test to hit more cases.
8669 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8670 "that do not have correct aspect bits sets.");
8671 VkResult err;
8672
8673 ASSERT_NO_FATAL_FAILURE(InitState());
8674 VkDescriptorPoolSize ds_type_count = {};
8675 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8676 ds_type_count.descriptorCount = 1;
8677
8678 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8679 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8680 ds_pool_ci.pNext = NULL;
8681 ds_pool_ci.maxSets = 5;
8682 ds_pool_ci.poolSizeCount = 1;
8683 ds_pool_ci.pPoolSizes = &ds_type_count;
8684
8685 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008686 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008687 ASSERT_VK_SUCCESS(err);
8688
8689 VkDescriptorSetLayoutBinding dsl_binding = {};
8690 dsl_binding.binding = 0;
8691 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8692 dsl_binding.descriptorCount = 1;
8693 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8694 dsl_binding.pImmutableSamplers = NULL;
8695
8696 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8697 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8698 ds_layout_ci.pNext = NULL;
8699 ds_layout_ci.bindingCount = 1;
8700 ds_layout_ci.pBindings = &dsl_binding;
8701 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008702 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008703 ASSERT_VK_SUCCESS(err);
8704
8705 VkDescriptorSet descriptor_set = {};
8706 VkDescriptorSetAllocateInfo alloc_info = {};
8707 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8708 alloc_info.descriptorSetCount = 1;
8709 alloc_info.descriptorPool = ds_pool;
8710 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008711 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008712 ASSERT_VK_SUCCESS(err);
8713
8714 // Create an image to be used for invalid updates
8715 VkImageCreateInfo image_ci = {};
8716 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8717 image_ci.imageType = VK_IMAGE_TYPE_2D;
8718 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8719 image_ci.extent.width = 64;
8720 image_ci.extent.height = 64;
8721 image_ci.extent.depth = 1;
8722 image_ci.mipLevels = 1;
8723 image_ci.arrayLayers = 1;
8724 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8725 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8726 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8727 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8728 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8729 VkImage image;
8730 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8731 ASSERT_VK_SUCCESS(err);
8732 // Bind memory to image
8733 VkMemoryRequirements mem_reqs;
8734 VkDeviceMemory image_mem;
8735 bool pass;
8736 VkMemoryAllocateInfo mem_alloc = {};
8737 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8738 mem_alloc.pNext = NULL;
8739 mem_alloc.allocationSize = 0;
8740 mem_alloc.memoryTypeIndex = 0;
8741 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8742 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008743 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008744 ASSERT_TRUE(pass);
8745 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8746 ASSERT_VK_SUCCESS(err);
8747 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8748 ASSERT_VK_SUCCESS(err);
8749 // Now create view for image
8750 VkImageViewCreateInfo image_view_ci = {};
8751 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8752 image_view_ci.image = image;
8753 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8754 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8755 image_view_ci.subresourceRange.layerCount = 1;
8756 image_view_ci.subresourceRange.baseArrayLayer = 0;
8757 image_view_ci.subresourceRange.levelCount = 1;
8758 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008759 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008760
8761 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008762 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008763 ASSERT_VK_SUCCESS(err);
8764
8765 VkDescriptorImageInfo img_info = {};
8766 img_info.imageView = image_view;
8767 VkWriteDescriptorSet descriptor_write = {};
8768 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8769 descriptor_write.dstBinding = 0;
8770 descriptor_write.descriptorCount = 1;
8771 descriptor_write.pTexelBufferView = NULL;
8772 descriptor_write.pBufferInfo = NULL;
8773 descriptor_write.pImageInfo = &img_info;
8774 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8775 descriptor_write.dstSet = descriptor_set;
8776 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8777 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008779
8780 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8781
8782 m_errorMonitor->VerifyFound();
8783 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8784 vkDestroyImage(m_device->device(), image, NULL);
8785 vkFreeMemory(m_device->device(), image_mem, NULL);
8786 vkDestroyImageView(m_device->device(), image_view, NULL);
8787 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8788 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8789}
8790
Karl Schultz6addd812016-02-02 17:17:23 -07008791TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008792 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008793 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008794
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8796 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8797 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008798
Tobin Ehlis3b780662015-05-28 12:11:26 -06008799 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008800 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008801 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008802 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8803 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008804
8805 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008806 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8807 ds_pool_ci.pNext = NULL;
8808 ds_pool_ci.maxSets = 1;
8809 ds_pool_ci.poolSizeCount = 1;
8810 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008811
Tobin Ehlis3b780662015-05-28 12:11:26 -06008812 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008813 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008814 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008815 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008816 dsl_binding.binding = 0;
8817 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8818 dsl_binding.descriptorCount = 1;
8819 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8820 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008821
Tony Barboureb254902015-07-15 12:50:33 -06008822 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008823 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8824 ds_layout_ci.pNext = NULL;
8825 ds_layout_ci.bindingCount = 1;
8826 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008827
Tobin Ehlis3b780662015-05-28 12:11:26 -06008828 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008829 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008830 ASSERT_VK_SUCCESS(err);
8831
8832 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008833 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008834 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008835 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008836 alloc_info.descriptorPool = ds_pool;
8837 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008838 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008839 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008840
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008841 VkSamplerCreateInfo sampler_ci = {};
8842 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8843 sampler_ci.pNext = NULL;
8844 sampler_ci.magFilter = VK_FILTER_NEAREST;
8845 sampler_ci.minFilter = VK_FILTER_NEAREST;
8846 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8847 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8848 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8849 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8850 sampler_ci.mipLodBias = 1.0;
8851 sampler_ci.anisotropyEnable = VK_FALSE;
8852 sampler_ci.maxAnisotropy = 1;
8853 sampler_ci.compareEnable = VK_FALSE;
8854 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8855 sampler_ci.minLod = 1.0;
8856 sampler_ci.maxLod = 1.0;
8857 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8858 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8859 VkSampler sampler;
8860 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8861 ASSERT_VK_SUCCESS(err);
8862
8863 VkDescriptorImageInfo info = {};
8864 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008865
8866 VkWriteDescriptorSet descriptor_write;
8867 memset(&descriptor_write, 0, sizeof(descriptor_write));
8868 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008869 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008870 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008871 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008872 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008873 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008874
8875 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8876
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008877 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008878
Chia-I Wuf7458c52015-10-26 21:10:41 +08008879 vkDestroySampler(m_device->device(), sampler, NULL);
8880 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8881 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008882}
8883
Karl Schultz6addd812016-02-02 17:17:23 -07008884TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008885 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008886 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008887
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8889 " binding #0 with 1 total descriptors but update of 1 descriptors "
8890 "starting at binding offset of 0 combined with update array element "
8891 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008892
Tobin Ehlis3b780662015-05-28 12:11:26 -06008893 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008894 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008895 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008896 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8897 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008898
8899 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008900 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8901 ds_pool_ci.pNext = NULL;
8902 ds_pool_ci.maxSets = 1;
8903 ds_pool_ci.poolSizeCount = 1;
8904 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008905
Tobin Ehlis3b780662015-05-28 12:11:26 -06008906 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008907 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008908 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008909
Tony Barboureb254902015-07-15 12:50:33 -06008910 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008911 dsl_binding.binding = 0;
8912 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8913 dsl_binding.descriptorCount = 1;
8914 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8915 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008916
8917 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008918 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8919 ds_layout_ci.pNext = NULL;
8920 ds_layout_ci.bindingCount = 1;
8921 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008922
Tobin Ehlis3b780662015-05-28 12:11:26 -06008923 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008924 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008925 ASSERT_VK_SUCCESS(err);
8926
8927 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008928 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008929 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008930 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008931 alloc_info.descriptorPool = ds_pool;
8932 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008933 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008934 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008935
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008936 // Correctly update descriptor to avoid "NOT_UPDATED" error
8937 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008938 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008939 buff_info.offset = 0;
8940 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008941
8942 VkWriteDescriptorSet descriptor_write;
8943 memset(&descriptor_write, 0, sizeof(descriptor_write));
8944 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008945 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008946 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008947 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008948 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8949 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008950
8951 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8952
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008953 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008954
Chia-I Wuf7458c52015-10-26 21:10:41 +08008955 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8956 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008957}
8958
Karl Schultz6addd812016-02-02 17:17:23 -07008959TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8960 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8961 // index 2
8962 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008963
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008965
Tobin Ehlis3b780662015-05-28 12:11:26 -06008966 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008967 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008968 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008969 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8970 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008971
8972 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008973 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8974 ds_pool_ci.pNext = NULL;
8975 ds_pool_ci.maxSets = 1;
8976 ds_pool_ci.poolSizeCount = 1;
8977 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008978
Tobin Ehlis3b780662015-05-28 12:11:26 -06008979 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008980 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008981 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008982
Tony Barboureb254902015-07-15 12:50:33 -06008983 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008984 dsl_binding.binding = 0;
8985 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8986 dsl_binding.descriptorCount = 1;
8987 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8988 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008989
8990 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008991 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8992 ds_layout_ci.pNext = NULL;
8993 ds_layout_ci.bindingCount = 1;
8994 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008995 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008996 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008997 ASSERT_VK_SUCCESS(err);
8998
8999 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009000 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009001 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009002 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009003 alloc_info.descriptorPool = ds_pool;
9004 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009005 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009006 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009007
Tony Barboureb254902015-07-15 12:50:33 -06009008 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009009 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9010 sampler_ci.pNext = NULL;
9011 sampler_ci.magFilter = VK_FILTER_NEAREST;
9012 sampler_ci.minFilter = VK_FILTER_NEAREST;
9013 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9014 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9015 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9016 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9017 sampler_ci.mipLodBias = 1.0;
9018 sampler_ci.anisotropyEnable = VK_FALSE;
9019 sampler_ci.maxAnisotropy = 1;
9020 sampler_ci.compareEnable = VK_FALSE;
9021 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9022 sampler_ci.minLod = 1.0;
9023 sampler_ci.maxLod = 1.0;
9024 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9025 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009026
Tobin Ehlis3b780662015-05-28 12:11:26 -06009027 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009028 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009029 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009030
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009031 VkDescriptorImageInfo info = {};
9032 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009033
9034 VkWriteDescriptorSet descriptor_write;
9035 memset(&descriptor_write, 0, sizeof(descriptor_write));
9036 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009037 descriptor_write.dstSet = descriptorSet;
9038 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009039 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009040 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009041 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009042 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009043
9044 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9045
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009046 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009047
Chia-I Wuf7458c52015-10-26 21:10:41 +08009048 vkDestroySampler(m_device->device(), sampler, NULL);
9049 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9050 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009051}
9052
Karl Schultz6addd812016-02-02 17:17:23 -07009053TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9054 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9055 // types
9056 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009057
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009058 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 -06009059
Tobin Ehlis3b780662015-05-28 12:11:26 -06009060 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009061
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009062 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009063 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9064 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009065
9066 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009067 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9068 ds_pool_ci.pNext = NULL;
9069 ds_pool_ci.maxSets = 1;
9070 ds_pool_ci.poolSizeCount = 1;
9071 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009072
Tobin Ehlis3b780662015-05-28 12:11:26 -06009073 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009074 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009075 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009076 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009077 dsl_binding.binding = 0;
9078 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9079 dsl_binding.descriptorCount = 1;
9080 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9081 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009082
Tony Barboureb254902015-07-15 12:50:33 -06009083 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009084 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9085 ds_layout_ci.pNext = NULL;
9086 ds_layout_ci.bindingCount = 1;
9087 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009088
Tobin Ehlis3b780662015-05-28 12:11:26 -06009089 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009090 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009091 ASSERT_VK_SUCCESS(err);
9092
9093 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009094 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009095 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009096 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009097 alloc_info.descriptorPool = ds_pool;
9098 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009099 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009100 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009101
Tony Barboureb254902015-07-15 12:50:33 -06009102 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009103 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9104 sampler_ci.pNext = NULL;
9105 sampler_ci.magFilter = VK_FILTER_NEAREST;
9106 sampler_ci.minFilter = VK_FILTER_NEAREST;
9107 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9108 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9109 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9110 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9111 sampler_ci.mipLodBias = 1.0;
9112 sampler_ci.anisotropyEnable = VK_FALSE;
9113 sampler_ci.maxAnisotropy = 1;
9114 sampler_ci.compareEnable = VK_FALSE;
9115 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9116 sampler_ci.minLod = 1.0;
9117 sampler_ci.maxLod = 1.0;
9118 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9119 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009120 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009121 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009122 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009123
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009124 VkDescriptorImageInfo info = {};
9125 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009126
9127 VkWriteDescriptorSet descriptor_write;
9128 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009129 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009130 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009131 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009132 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009133 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009134 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009135
9136 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9137
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009138 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009139
Chia-I Wuf7458c52015-10-26 21:10:41 +08009140 vkDestroySampler(m_device->device(), sampler, NULL);
9141 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9142 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009143}
9144
Karl Schultz6addd812016-02-02 17:17:23 -07009145TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009146 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009147 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009148
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9150 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009151
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009152 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009153 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9154 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009155 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009156 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9157 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009158
9159 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009160 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9161 ds_pool_ci.pNext = NULL;
9162 ds_pool_ci.maxSets = 1;
9163 ds_pool_ci.poolSizeCount = 1;
9164 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009165
9166 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009167 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009168 ASSERT_VK_SUCCESS(err);
9169
9170 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009171 dsl_binding.binding = 0;
9172 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9173 dsl_binding.descriptorCount = 1;
9174 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9175 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009176
9177 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009178 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9179 ds_layout_ci.pNext = NULL;
9180 ds_layout_ci.bindingCount = 1;
9181 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009182 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009183 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009184 ASSERT_VK_SUCCESS(err);
9185
9186 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009187 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009188 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009189 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009190 alloc_info.descriptorPool = ds_pool;
9191 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009192 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009193 ASSERT_VK_SUCCESS(err);
9194
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009195 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009196
9197 VkDescriptorImageInfo descriptor_info;
9198 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9199 descriptor_info.sampler = sampler;
9200
9201 VkWriteDescriptorSet descriptor_write;
9202 memset(&descriptor_write, 0, sizeof(descriptor_write));
9203 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009204 descriptor_write.dstSet = descriptorSet;
9205 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009206 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009207 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9208 descriptor_write.pImageInfo = &descriptor_info;
9209
9210 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9211
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009212 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009213
Chia-I Wuf7458c52015-10-26 21:10:41 +08009214 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9215 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009216}
9217
Karl Schultz6addd812016-02-02 17:17:23 -07009218TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9219 // Create a single combined Image/Sampler descriptor and send it an invalid
9220 // imageView
9221 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9224 "image sampler descriptor failed due "
9225 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009226
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009227 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009228 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009229 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9230 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009231
9232 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009233 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9234 ds_pool_ci.pNext = NULL;
9235 ds_pool_ci.maxSets = 1;
9236 ds_pool_ci.poolSizeCount = 1;
9237 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009238
9239 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009240 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009241 ASSERT_VK_SUCCESS(err);
9242
9243 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009244 dsl_binding.binding = 0;
9245 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9246 dsl_binding.descriptorCount = 1;
9247 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9248 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009249
9250 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009251 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9252 ds_layout_ci.pNext = NULL;
9253 ds_layout_ci.bindingCount = 1;
9254 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009255 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009256 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009257 ASSERT_VK_SUCCESS(err);
9258
9259 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009260 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009261 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009262 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009263 alloc_info.descriptorPool = ds_pool;
9264 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009265 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009266 ASSERT_VK_SUCCESS(err);
9267
9268 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009269 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9270 sampler_ci.pNext = NULL;
9271 sampler_ci.magFilter = VK_FILTER_NEAREST;
9272 sampler_ci.minFilter = VK_FILTER_NEAREST;
9273 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9274 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9275 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9276 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9277 sampler_ci.mipLodBias = 1.0;
9278 sampler_ci.anisotropyEnable = VK_FALSE;
9279 sampler_ci.maxAnisotropy = 1;
9280 sampler_ci.compareEnable = VK_FALSE;
9281 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9282 sampler_ci.minLod = 1.0;
9283 sampler_ci.maxLod = 1.0;
9284 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9285 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009286
9287 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009288 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009289 ASSERT_VK_SUCCESS(err);
9290
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009291 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009292
9293 VkDescriptorImageInfo descriptor_info;
9294 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9295 descriptor_info.sampler = sampler;
9296 descriptor_info.imageView = view;
9297
9298 VkWriteDescriptorSet descriptor_write;
9299 memset(&descriptor_write, 0, sizeof(descriptor_write));
9300 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009301 descriptor_write.dstSet = descriptorSet;
9302 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009303 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009304 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9305 descriptor_write.pImageInfo = &descriptor_info;
9306
9307 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9308
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009309 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009310
Chia-I Wuf7458c52015-10-26 21:10:41 +08009311 vkDestroySampler(m_device->device(), sampler, NULL);
9312 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9313 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009314}
9315
Karl Schultz6addd812016-02-02 17:17:23 -07009316TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9317 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9318 // into the other
9319 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009320
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9322 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9323 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009324
Tobin Ehlis04356f92015-10-27 16:35:27 -06009325 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009326 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009327 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009328 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9329 ds_type_count[0].descriptorCount = 1;
9330 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9331 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009332
9333 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009334 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9335 ds_pool_ci.pNext = NULL;
9336 ds_pool_ci.maxSets = 1;
9337 ds_pool_ci.poolSizeCount = 2;
9338 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009339
9340 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009341 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009342 ASSERT_VK_SUCCESS(err);
9343 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009344 dsl_binding[0].binding = 0;
9345 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9346 dsl_binding[0].descriptorCount = 1;
9347 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9348 dsl_binding[0].pImmutableSamplers = NULL;
9349 dsl_binding[1].binding = 1;
9350 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9351 dsl_binding[1].descriptorCount = 1;
9352 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9353 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009354
9355 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009356 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9357 ds_layout_ci.pNext = NULL;
9358 ds_layout_ci.bindingCount = 2;
9359 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009360
9361 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009362 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009363 ASSERT_VK_SUCCESS(err);
9364
9365 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009366 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009367 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009368 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009369 alloc_info.descriptorPool = ds_pool;
9370 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009371 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009372 ASSERT_VK_SUCCESS(err);
9373
9374 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009375 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9376 sampler_ci.pNext = NULL;
9377 sampler_ci.magFilter = VK_FILTER_NEAREST;
9378 sampler_ci.minFilter = VK_FILTER_NEAREST;
9379 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9380 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9381 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9382 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9383 sampler_ci.mipLodBias = 1.0;
9384 sampler_ci.anisotropyEnable = VK_FALSE;
9385 sampler_ci.maxAnisotropy = 1;
9386 sampler_ci.compareEnable = VK_FALSE;
9387 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9388 sampler_ci.minLod = 1.0;
9389 sampler_ci.maxLod = 1.0;
9390 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9391 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009392
9393 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009394 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009395 ASSERT_VK_SUCCESS(err);
9396
9397 VkDescriptorImageInfo info = {};
9398 info.sampler = sampler;
9399
9400 VkWriteDescriptorSet descriptor_write;
9401 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9402 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009403 descriptor_write.dstSet = descriptorSet;
9404 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009405 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009406 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9407 descriptor_write.pImageInfo = &info;
9408 // This write update should succeed
9409 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9410 // Now perform a copy update that fails due to type mismatch
9411 VkCopyDescriptorSet copy_ds_update;
9412 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9413 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9414 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009415 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009416 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009417 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009418 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009419 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9420
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009421 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009422 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009423 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 -06009424 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9425 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9426 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009427 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009428 copy_ds_update.dstSet = descriptorSet;
9429 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009430 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009431 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9432
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009433 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009434
Tobin Ehlis04356f92015-10-27 16:35:27 -06009435 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9437 "update array offset of 0 and update of "
9438 "5 descriptors oversteps total number "
9439 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009440
Tobin Ehlis04356f92015-10-27 16:35:27 -06009441 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9442 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9443 copy_ds_update.srcSet = descriptorSet;
9444 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009445 copy_ds_update.dstSet = descriptorSet;
9446 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009447 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009448 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9449
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009450 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009451
Chia-I Wuf7458c52015-10-26 21:10:41 +08009452 vkDestroySampler(m_device->device(), sampler, NULL);
9453 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9454 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009455}
9456
Karl Schultz6addd812016-02-02 17:17:23 -07009457TEST_F(VkLayerTest, NumSamplesMismatch) {
9458 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9459 // sampleCount
9460 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009461
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009463
Tobin Ehlis3b780662015-05-28 12:11:26 -06009464 ASSERT_NO_FATAL_FAILURE(InitState());
9465 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009466 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009467 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009468 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009469
9470 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009471 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9472 ds_pool_ci.pNext = NULL;
9473 ds_pool_ci.maxSets = 1;
9474 ds_pool_ci.poolSizeCount = 1;
9475 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009476
Tobin Ehlis3b780662015-05-28 12:11:26 -06009477 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009478 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009479 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009480
Tony Barboureb254902015-07-15 12:50:33 -06009481 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009482 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009483 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009484 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009485 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9486 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009487
Tony Barboureb254902015-07-15 12:50:33 -06009488 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9489 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9490 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009491 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009492 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009493
Tobin Ehlis3b780662015-05-28 12:11:26 -06009494 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009495 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009496 ASSERT_VK_SUCCESS(err);
9497
9498 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009499 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009500 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009501 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009502 alloc_info.descriptorPool = ds_pool;
9503 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009504 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009505 ASSERT_VK_SUCCESS(err);
9506
Tony Barboureb254902015-07-15 12:50:33 -06009507 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009508 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009509 pipe_ms_state_ci.pNext = NULL;
9510 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9511 pipe_ms_state_ci.sampleShadingEnable = 0;
9512 pipe_ms_state_ci.minSampleShading = 1.0;
9513 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009514
Tony Barboureb254902015-07-15 12:50:33 -06009515 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009516 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9517 pipeline_layout_ci.pNext = NULL;
9518 pipeline_layout_ci.setLayoutCount = 1;
9519 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009520
9521 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009522 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009523 ASSERT_VK_SUCCESS(err);
9524
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009525 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9526 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9527 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009528 VkPipelineObj pipe(m_device);
9529 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009530 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009531 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009532 pipe.SetMSAA(&pipe_ms_state_ci);
9533 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009534
Tony Barbourfe3351b2015-07-28 10:17:20 -06009535 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009536 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009537
Mark Young29927482016-05-04 14:38:51 -06009538 // Render triangle (the error should trigger on the attempt to draw).
9539 Draw(3, 1, 0, 0);
9540
9541 // Finalize recording of the command buffer
9542 EndCommandBuffer();
9543
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009544 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009545
Chia-I Wuf7458c52015-10-26 21:10:41 +08009546 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9547 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9548 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009549}
Mark Young29927482016-05-04 14:38:51 -06009550
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009551TEST_F(VkLayerTest, RenderPassIncompatible) {
9552 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9553 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009554 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009555 VkResult err;
9556
9557 ASSERT_NO_FATAL_FAILURE(InitState());
9558 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9559
9560 VkDescriptorSetLayoutBinding dsl_binding = {};
9561 dsl_binding.binding = 0;
9562 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9563 dsl_binding.descriptorCount = 1;
9564 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9565 dsl_binding.pImmutableSamplers = NULL;
9566
9567 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9568 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9569 ds_layout_ci.pNext = NULL;
9570 ds_layout_ci.bindingCount = 1;
9571 ds_layout_ci.pBindings = &dsl_binding;
9572
9573 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009574 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009575 ASSERT_VK_SUCCESS(err);
9576
9577 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9578 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9579 pipeline_layout_ci.pNext = NULL;
9580 pipeline_layout_ci.setLayoutCount = 1;
9581 pipeline_layout_ci.pSetLayouts = &ds_layout;
9582
9583 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009584 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009585 ASSERT_VK_SUCCESS(err);
9586
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009587 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9588 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9589 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009590 // Create a renderpass that will be incompatible with default renderpass
9591 VkAttachmentReference attach = {};
9592 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9593 VkAttachmentReference color_att = {};
9594 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9595 VkSubpassDescription subpass = {};
9596 subpass.inputAttachmentCount = 1;
9597 subpass.pInputAttachments = &attach;
9598 subpass.colorAttachmentCount = 1;
9599 subpass.pColorAttachments = &color_att;
9600 VkRenderPassCreateInfo rpci = {};
9601 rpci.subpassCount = 1;
9602 rpci.pSubpasses = &subpass;
9603 rpci.attachmentCount = 1;
9604 VkAttachmentDescription attach_desc = {};
9605 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009606 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9607 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009608 rpci.pAttachments = &attach_desc;
9609 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9610 VkRenderPass rp;
9611 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9612 VkPipelineObj pipe(m_device);
9613 pipe.AddShader(&vs);
9614 pipe.AddShader(&fs);
9615 pipe.AddColorAttachment();
9616 VkViewport view_port = {};
9617 m_viewports.push_back(view_port);
9618 pipe.SetViewport(m_viewports);
9619 VkRect2D rect = {};
9620 m_scissors.push_back(rect);
9621 pipe.SetScissor(m_scissors);
9622 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9623
9624 VkCommandBufferInheritanceInfo cbii = {};
9625 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9626 cbii.renderPass = rp;
9627 cbii.subpass = 0;
9628 VkCommandBufferBeginInfo cbbi = {};
9629 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9630 cbbi.pInheritanceInfo = &cbii;
9631 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9632 VkRenderPassBeginInfo rpbi = {};
9633 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9634 rpbi.framebuffer = m_framebuffer;
9635 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009636 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9637 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009638
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009640 // Render triangle (the error should trigger on the attempt to draw).
9641 Draw(3, 1, 0, 0);
9642
9643 // Finalize recording of the command buffer
9644 EndCommandBuffer();
9645
9646 m_errorMonitor->VerifyFound();
9647
9648 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9649 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9650 vkDestroyRenderPass(m_device->device(), rp, NULL);
9651}
9652
Mark Youngc89c6312016-03-31 16:03:20 -06009653TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9654 // Create Pipeline where the number of blend attachments doesn't match the
9655 // number of color attachments. In this case, we don't add any color
9656 // blend attachments even though we have a color attachment.
9657 VkResult err;
9658
9659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009660 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009661
9662 ASSERT_NO_FATAL_FAILURE(InitState());
9663 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9664 VkDescriptorPoolSize ds_type_count = {};
9665 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9666 ds_type_count.descriptorCount = 1;
9667
9668 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9669 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9670 ds_pool_ci.pNext = NULL;
9671 ds_pool_ci.maxSets = 1;
9672 ds_pool_ci.poolSizeCount = 1;
9673 ds_pool_ci.pPoolSizes = &ds_type_count;
9674
9675 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009676 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009677 ASSERT_VK_SUCCESS(err);
9678
9679 VkDescriptorSetLayoutBinding dsl_binding = {};
9680 dsl_binding.binding = 0;
9681 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9682 dsl_binding.descriptorCount = 1;
9683 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9684 dsl_binding.pImmutableSamplers = NULL;
9685
9686 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9687 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9688 ds_layout_ci.pNext = NULL;
9689 ds_layout_ci.bindingCount = 1;
9690 ds_layout_ci.pBindings = &dsl_binding;
9691
9692 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009693 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009694 ASSERT_VK_SUCCESS(err);
9695
9696 VkDescriptorSet descriptorSet;
9697 VkDescriptorSetAllocateInfo alloc_info = {};
9698 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9699 alloc_info.descriptorSetCount = 1;
9700 alloc_info.descriptorPool = ds_pool;
9701 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009702 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009703 ASSERT_VK_SUCCESS(err);
9704
9705 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009706 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009707 pipe_ms_state_ci.pNext = NULL;
9708 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9709 pipe_ms_state_ci.sampleShadingEnable = 0;
9710 pipe_ms_state_ci.minSampleShading = 1.0;
9711 pipe_ms_state_ci.pSampleMask = NULL;
9712
9713 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9714 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9715 pipeline_layout_ci.pNext = NULL;
9716 pipeline_layout_ci.setLayoutCount = 1;
9717 pipeline_layout_ci.pSetLayouts = &ds_layout;
9718
9719 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009720 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009721 ASSERT_VK_SUCCESS(err);
9722
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009723 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9724 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9725 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009726 VkPipelineObj pipe(m_device);
9727 pipe.AddShader(&vs);
9728 pipe.AddShader(&fs);
9729 pipe.SetMSAA(&pipe_ms_state_ci);
9730 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9731
9732 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009733 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009734
Mark Young29927482016-05-04 14:38:51 -06009735 // Render triangle (the error should trigger on the attempt to draw).
9736 Draw(3, 1, 0, 0);
9737
9738 // Finalize recording of the command buffer
9739 EndCommandBuffer();
9740
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009741 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009742
9743 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9744 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9745 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9746}
Mark Young29927482016-05-04 14:38:51 -06009747
Mark Muellerd4914412016-06-13 17:52:06 -06009748TEST_F(VkLayerTest, MissingClearAttachment) {
9749 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9750 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009751 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009753 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009754
9755 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9756 m_errorMonitor->VerifyFound();
9757}
9758
Karl Schultz6addd812016-02-02 17:17:23 -07009759TEST_F(VkLayerTest, ClearCmdNoDraw) {
9760 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9761 // to issuing a Draw
9762 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009763
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009765 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009766
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009767 ASSERT_NO_FATAL_FAILURE(InitState());
9768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009769
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009770 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009771 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9772 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009773
9774 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009775 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9776 ds_pool_ci.pNext = NULL;
9777 ds_pool_ci.maxSets = 1;
9778 ds_pool_ci.poolSizeCount = 1;
9779 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009780
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009781 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009782 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009783 ASSERT_VK_SUCCESS(err);
9784
Tony Barboureb254902015-07-15 12:50:33 -06009785 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009786 dsl_binding.binding = 0;
9787 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9788 dsl_binding.descriptorCount = 1;
9789 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9790 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009791
Tony Barboureb254902015-07-15 12:50:33 -06009792 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009793 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9794 ds_layout_ci.pNext = NULL;
9795 ds_layout_ci.bindingCount = 1;
9796 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009797
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009798 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009799 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009800 ASSERT_VK_SUCCESS(err);
9801
9802 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009803 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009804 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009805 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009806 alloc_info.descriptorPool = ds_pool;
9807 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009808 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009809 ASSERT_VK_SUCCESS(err);
9810
Tony Barboureb254902015-07-15 12:50:33 -06009811 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009812 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009813 pipe_ms_state_ci.pNext = NULL;
9814 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9815 pipe_ms_state_ci.sampleShadingEnable = 0;
9816 pipe_ms_state_ci.minSampleShading = 1.0;
9817 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009818
Tony Barboureb254902015-07-15 12:50:33 -06009819 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009820 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9821 pipeline_layout_ci.pNext = NULL;
9822 pipeline_layout_ci.setLayoutCount = 1;
9823 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009824
9825 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009826 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009827 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009828
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009829 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009830 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009831 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009832 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009833
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009834 VkPipelineObj pipe(m_device);
9835 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009836 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009837 pipe.SetMSAA(&pipe_ms_state_ci);
9838 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009839
9840 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009841
Karl Schultz6addd812016-02-02 17:17:23 -07009842 // Main thing we care about for this test is that the VkImage obj we're
9843 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009844 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009845 VkClearAttachment color_attachment;
9846 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9847 color_attachment.clearValue.color.float32[0] = 1.0;
9848 color_attachment.clearValue.color.float32[1] = 1.0;
9849 color_attachment.clearValue.color.float32[2] = 1.0;
9850 color_attachment.clearValue.color.float32[3] = 1.0;
9851 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009852 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009853
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009854 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009855
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009856 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009857
Chia-I Wuf7458c52015-10-26 21:10:41 +08009858 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9859 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9860 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009861}
9862
Karl Schultz6addd812016-02-02 17:17:23 -07009863TEST_F(VkLayerTest, VtxBufferBadIndex) {
9864 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009865
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9867 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009868
Tobin Ehlis502480b2015-06-24 15:53:07 -06009869 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009870 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009872
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009873 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009874 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9875 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009876
9877 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009878 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9879 ds_pool_ci.pNext = NULL;
9880 ds_pool_ci.maxSets = 1;
9881 ds_pool_ci.poolSizeCount = 1;
9882 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009883
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009884 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009885 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009886 ASSERT_VK_SUCCESS(err);
9887
Tony Barboureb254902015-07-15 12:50:33 -06009888 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009889 dsl_binding.binding = 0;
9890 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9891 dsl_binding.descriptorCount = 1;
9892 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9893 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009894
Tony Barboureb254902015-07-15 12:50:33 -06009895 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009896 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9897 ds_layout_ci.pNext = NULL;
9898 ds_layout_ci.bindingCount = 1;
9899 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009900
Tobin Ehlis502480b2015-06-24 15:53:07 -06009901 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009902 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009903 ASSERT_VK_SUCCESS(err);
9904
9905 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009906 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009907 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009908 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009909 alloc_info.descriptorPool = ds_pool;
9910 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009911 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009912 ASSERT_VK_SUCCESS(err);
9913
Tony Barboureb254902015-07-15 12:50:33 -06009914 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009915 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009916 pipe_ms_state_ci.pNext = NULL;
9917 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9918 pipe_ms_state_ci.sampleShadingEnable = 0;
9919 pipe_ms_state_ci.minSampleShading = 1.0;
9920 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009921
Tony Barboureb254902015-07-15 12:50:33 -06009922 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009923 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9924 pipeline_layout_ci.pNext = NULL;
9925 pipeline_layout_ci.setLayoutCount = 1;
9926 pipeline_layout_ci.pSetLayouts = &ds_layout;
9927 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009928
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009929 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009930 ASSERT_VK_SUCCESS(err);
9931
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009932 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9933 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9934 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009935 VkPipelineObj pipe(m_device);
9936 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009937 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009938 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009939 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009940 pipe.SetViewport(m_viewports);
9941 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009942 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009943
9944 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009945 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009946 // Don't care about actual data, just need to get to draw to flag error
9947 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009948 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009949 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009950 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009951
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009952 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009953
Chia-I Wuf7458c52015-10-26 21:10:41 +08009954 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9955 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9956 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009957}
Mark Muellerdfe37552016-07-07 14:47:42 -06009958
Mark Mueller2ee294f2016-08-04 12:59:48 -06009959TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
9960 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
9961 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -06009962 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -06009963
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009964 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
9965 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009966
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009967 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
9968 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009969
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009970 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009971
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -06009973 // The following test fails with recent NVidia drivers.
9974 // By the time core_validation is reached, the NVidia
9975 // driver has sanitized the invalid condition and core_validation
9976 // is not introduced to the failure condition. This is not the case
9977 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009978 // uint32_t count = static_cast<uint32_t>(~0);
9979 // VkPhysicalDevice physical_device;
9980 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
9981 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -06009982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009984 float queue_priority = 0.0;
9985
9986 VkDeviceQueueCreateInfo queue_create_info = {};
9987 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
9988 queue_create_info.queueCount = 1;
9989 queue_create_info.pQueuePriorities = &queue_priority;
9990 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
9991
9992 VkPhysicalDeviceFeatures features = m_device->phy().features();
9993 VkDevice testDevice;
9994 VkDeviceCreateInfo device_create_info = {};
9995 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
9996 device_create_info.queueCreateInfoCount = 1;
9997 device_create_info.pQueueCreateInfos = &queue_create_info;
9998 device_create_info.pEnabledFeatures = &features;
9999 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10000 m_errorMonitor->VerifyFound();
10001
10002 queue_create_info.queueFamilyIndex = 1;
10003
10004 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10005 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10006 for (unsigned i = 0; i < feature_count; i++) {
10007 if (VK_FALSE == feature_array[i]) {
10008 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010010 device_create_info.pEnabledFeatures = &features;
10011 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10012 m_errorMonitor->VerifyFound();
10013 break;
10014 }
10015 }
10016}
10017
10018TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10019 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10020 "End a command buffer with a query still in progress.");
10021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010022 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10023 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10024 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010025
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010026 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010027
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010029
10030 ASSERT_NO_FATAL_FAILURE(InitState());
10031
10032 VkEvent event;
10033 VkEventCreateInfo event_create_info{};
10034 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10035 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10036
Mark Mueller2ee294f2016-08-04 12:59:48 -060010037 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010038 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010039
10040 BeginCommandBuffer();
10041
10042 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010043 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 -060010044 ASSERT_TRUE(image.initialized());
10045 VkImageMemoryBarrier img_barrier = {};
10046 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10047 img_barrier.pNext = NULL;
10048 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10049 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10050 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10051 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10052 img_barrier.image = image.handle();
10053 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010054
10055 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10056 // that layer validation catches the case when it is not.
10057 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010058 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10059 img_barrier.subresourceRange.baseArrayLayer = 0;
10060 img_barrier.subresourceRange.baseMipLevel = 0;
10061 img_barrier.subresourceRange.layerCount = 1;
10062 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010063 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10064 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010065 m_errorMonitor->VerifyFound();
10066
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010068
10069 VkQueryPool query_pool;
10070 VkQueryPoolCreateInfo query_pool_create_info = {};
10071 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10072 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10073 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010074 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010075
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010076 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010077 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10078
10079 vkEndCommandBuffer(m_commandBuffer->handle());
10080 m_errorMonitor->VerifyFound();
10081
10082 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10083 vkDestroyEvent(m_device->device(), event, nullptr);
10084}
10085
Mark Muellerdfe37552016-07-07 14:47:42 -060010086TEST_F(VkLayerTest, VertexBufferInvalid) {
10087 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10088 "delete a buffer twice, use an invalid offset for each "
10089 "buffer type, and attempt to bind a null buffer");
10090
10091 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10092 "using deleted buffer ";
10093 const char *double_destroy_message = "Cannot free buffer 0x";
10094 const char *invalid_offset_message = "vkBindBufferMemory(): "
10095 "memoryOffset is 0x";
10096 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10097 "storage memoryOffset "
10098 "is 0x";
10099 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10100 "texel memoryOffset "
10101 "is 0x";
10102 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10103 "uniform memoryOffset "
10104 "is 0x";
10105 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
10106 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -060010107 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010108
10109 ASSERT_NO_FATAL_FAILURE(InitState());
10110 ASSERT_NO_FATAL_FAILURE(InitViewport());
10111 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10112
10113 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010114 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010115 pipe_ms_state_ci.pNext = NULL;
10116 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10117 pipe_ms_state_ci.sampleShadingEnable = 0;
10118 pipe_ms_state_ci.minSampleShading = 1.0;
10119 pipe_ms_state_ci.pSampleMask = nullptr;
10120
10121 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10122 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10123 VkPipelineLayout pipeline_layout;
10124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010125 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010126 ASSERT_VK_SUCCESS(err);
10127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010128 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10129 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010130 VkPipelineObj pipe(m_device);
10131 pipe.AddShader(&vs);
10132 pipe.AddShader(&fs);
10133 pipe.AddColorAttachment();
10134 pipe.SetMSAA(&pipe_ms_state_ci);
10135 pipe.SetViewport(m_viewports);
10136 pipe.SetScissor(m_scissors);
10137 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10138
10139 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010140 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010141
10142 {
10143 // Create and bind a vertex buffer in a reduced scope, which will cause
10144 // it to be deleted upon leaving this scope
10145 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010146 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010147 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10148 draw_verticies.AddVertexInputToPipe(pipe);
10149 }
10150
10151 Draw(1, 0, 0, 0);
10152
10153 EndCommandBuffer();
10154
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010156 QueueCommandBuffer(false);
10157 m_errorMonitor->VerifyFound();
10158
10159 {
10160 // Create and bind a vertex buffer in a reduced scope, and delete it
10161 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010162 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010164 buffer_test.TestDoubleDestroy();
10165 }
10166 m_errorMonitor->VerifyFound();
10167
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010168 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010169 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10171 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10172 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010173 m_errorMonitor->VerifyFound();
10174 }
10175
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010176 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10177 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010178 // Create and bind a memory buffer with an invalid offset again,
10179 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10181 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10182 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010183 m_errorMonitor->VerifyFound();
10184 }
10185
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010186 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010187 // Create and bind a memory buffer with an invalid offset again, but
10188 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10190 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10191 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010192 m_errorMonitor->VerifyFound();
10193 }
10194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010195 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010196 // Create and bind a memory buffer with an invalid offset again, but
10197 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10199 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10200 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010201 m_errorMonitor->VerifyFound();
10202 }
10203
10204 {
10205 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10207 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10208 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010209 m_errorMonitor->VerifyFound();
10210 }
10211
10212 {
10213 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10215 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10216 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010217 }
10218 m_errorMonitor->VerifyFound();
10219
10220 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10221}
10222
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010223// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10224TEST_F(VkLayerTest, InvalidImageLayout) {
10225 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010226 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10227 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010228 // 3 in ValidateCmdBufImageLayouts
10229 // * -1 Attempt to submit cmd buf w/ deleted image
10230 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10231 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10233 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010234
10235 ASSERT_NO_FATAL_FAILURE(InitState());
10236 // Create src & dst images to use for copy operations
10237 VkImage src_image;
10238 VkImage dst_image;
10239
10240 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10241 const int32_t tex_width = 32;
10242 const int32_t tex_height = 32;
10243
10244 VkImageCreateInfo image_create_info = {};
10245 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10246 image_create_info.pNext = NULL;
10247 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10248 image_create_info.format = tex_format;
10249 image_create_info.extent.width = tex_width;
10250 image_create_info.extent.height = tex_height;
10251 image_create_info.extent.depth = 1;
10252 image_create_info.mipLevels = 1;
10253 image_create_info.arrayLayers = 4;
10254 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10255 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10256 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10257 image_create_info.flags = 0;
10258
10259 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10260 ASSERT_VK_SUCCESS(err);
10261 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10262 ASSERT_VK_SUCCESS(err);
10263
10264 BeginCommandBuffer();
10265 VkImageCopy copyRegion;
10266 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10267 copyRegion.srcSubresource.mipLevel = 0;
10268 copyRegion.srcSubresource.baseArrayLayer = 0;
10269 copyRegion.srcSubresource.layerCount = 1;
10270 copyRegion.srcOffset.x = 0;
10271 copyRegion.srcOffset.y = 0;
10272 copyRegion.srcOffset.z = 0;
10273 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10274 copyRegion.dstSubresource.mipLevel = 0;
10275 copyRegion.dstSubresource.baseArrayLayer = 0;
10276 copyRegion.dstSubresource.layerCount = 1;
10277 copyRegion.dstOffset.x = 0;
10278 copyRegion.dstOffset.y = 0;
10279 copyRegion.dstOffset.z = 0;
10280 copyRegion.extent.width = 1;
10281 copyRegion.extent.height = 1;
10282 copyRegion.extent.depth = 1;
10283 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10284 m_errorMonitor->VerifyFound();
10285 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10287 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10288 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010289 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10290 m_errorMonitor->VerifyFound();
10291 // Final src error is due to bad layout type
10292 m_errorMonitor->SetDesiredFailureMsg(
10293 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10294 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10295 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10296 m_errorMonitor->VerifyFound();
10297 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10299 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010300 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10301 m_errorMonitor->VerifyFound();
10302 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10304 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10305 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010306 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10307 m_errorMonitor->VerifyFound();
10308 m_errorMonitor->SetDesiredFailureMsg(
10309 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10310 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10311 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10312 m_errorMonitor->VerifyFound();
10313 // Now cause error due to bad image layout transition in PipelineBarrier
10314 VkImageMemoryBarrier image_barrier[1] = {};
10315 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10316 image_barrier[0].image = src_image;
10317 image_barrier[0].subresourceRange.layerCount = 2;
10318 image_barrier[0].subresourceRange.levelCount = 2;
10319 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10321 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10322 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10323 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10324 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010325 m_errorMonitor->VerifyFound();
10326
10327 // Finally some layout errors at RenderPass create time
10328 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10329 VkAttachmentReference attach = {};
10330 // perf warning for GENERAL layout w/ non-DS input attachment
10331 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10332 VkSubpassDescription subpass = {};
10333 subpass.inputAttachmentCount = 1;
10334 subpass.pInputAttachments = &attach;
10335 VkRenderPassCreateInfo rpci = {};
10336 rpci.subpassCount = 1;
10337 rpci.pSubpasses = &subpass;
10338 rpci.attachmentCount = 1;
10339 VkAttachmentDescription attach_desc = {};
10340 attach_desc.format = VK_FORMAT_UNDEFINED;
10341 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010342 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010343 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10345 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010346 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10347 m_errorMonitor->VerifyFound();
10348 // error w/ non-general layout
10349 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10350
10351 m_errorMonitor->SetDesiredFailureMsg(
10352 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10353 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10354 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10355 m_errorMonitor->VerifyFound();
10356 subpass.inputAttachmentCount = 0;
10357 subpass.colorAttachmentCount = 1;
10358 subpass.pColorAttachments = &attach;
10359 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10360 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10362 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010363 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10364 m_errorMonitor->VerifyFound();
10365 // error w/ non-color opt or GENERAL layout for color attachment
10366 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10367 m_errorMonitor->SetDesiredFailureMsg(
10368 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10369 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10370 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10371 m_errorMonitor->VerifyFound();
10372 subpass.colorAttachmentCount = 0;
10373 subpass.pDepthStencilAttachment = &attach;
10374 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10375 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10377 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010378 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10379 m_errorMonitor->VerifyFound();
10380 // error w/ non-ds opt or GENERAL layout for color attachment
10381 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10383 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10384 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010385 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10386 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010387 // For this error we need a valid renderpass so create default one
10388 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10389 attach.attachment = 0;
10390 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10391 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10392 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10393 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10394 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10395 // Can't do a CLEAR load on READ_ONLY initialLayout
10396 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10397 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10398 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10400 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10401 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010402 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10403 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010404
10405 vkDestroyImage(m_device->device(), src_image, NULL);
10406 vkDestroyImage(m_device->device(), dst_image, NULL);
10407}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010408
Tobin Ehlise0936662016-10-11 08:10:51 -060010409TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10410 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10411 VkResult err;
10412
10413 ASSERT_NO_FATAL_FAILURE(InitState());
10414
10415 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10416 VkImageTiling tiling;
10417 VkFormatProperties format_properties;
10418 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10419 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10420 tiling = VK_IMAGE_TILING_LINEAR;
10421 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10422 tiling = VK_IMAGE_TILING_OPTIMAL;
10423 } else {
10424 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10425 "skipped.\n");
10426 return;
10427 }
10428
10429 VkDescriptorPoolSize ds_type = {};
10430 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10431 ds_type.descriptorCount = 1;
10432
10433 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10434 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10435 ds_pool_ci.maxSets = 1;
10436 ds_pool_ci.poolSizeCount = 1;
10437 ds_pool_ci.pPoolSizes = &ds_type;
10438 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10439
10440 VkDescriptorPool ds_pool;
10441 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10442 ASSERT_VK_SUCCESS(err);
10443
10444 VkDescriptorSetLayoutBinding dsl_binding = {};
10445 dsl_binding.binding = 0;
10446 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10447 dsl_binding.descriptorCount = 1;
10448 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10449 dsl_binding.pImmutableSamplers = NULL;
10450
10451 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10452 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10453 ds_layout_ci.pNext = NULL;
10454 ds_layout_ci.bindingCount = 1;
10455 ds_layout_ci.pBindings = &dsl_binding;
10456
10457 VkDescriptorSetLayout ds_layout;
10458 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10459 ASSERT_VK_SUCCESS(err);
10460
10461 VkDescriptorSetAllocateInfo alloc_info = {};
10462 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10463 alloc_info.descriptorSetCount = 1;
10464 alloc_info.descriptorPool = ds_pool;
10465 alloc_info.pSetLayouts = &ds_layout;
10466 VkDescriptorSet descriptor_set;
10467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10468 ASSERT_VK_SUCCESS(err);
10469
10470 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10471 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10472 pipeline_layout_ci.pNext = NULL;
10473 pipeline_layout_ci.setLayoutCount = 1;
10474 pipeline_layout_ci.pSetLayouts = &ds_layout;
10475 VkPipelineLayout pipeline_layout;
10476 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10477 ASSERT_VK_SUCCESS(err);
10478
10479 VkImageObj image(m_device);
10480 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10481 ASSERT_TRUE(image.initialized());
10482 VkImageView view = image.targetView(tex_format);
10483
10484 VkDescriptorImageInfo image_info = {};
10485 image_info.imageView = view;
10486 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10487
10488 VkWriteDescriptorSet descriptor_write = {};
10489 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10490 descriptor_write.dstSet = descriptor_set;
10491 descriptor_write.dstBinding = 0;
10492 descriptor_write.descriptorCount = 1;
10493 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10494 descriptor_write.pImageInfo = &image_info;
10495
10496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10497 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10498 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10499 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10500 m_errorMonitor->VerifyFound();
10501
10502 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10503 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10504 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10505 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10506}
10507
Mark Mueller93b938f2016-08-18 10:27:40 -060010508TEST_F(VkLayerTest, SimultaneousUse) {
10509 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10510 "in primary and secondary command buffers.");
10511
10512 ASSERT_NO_FATAL_FAILURE(InitState());
10513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10514
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010515 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010516 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10517 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010518
10519 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010520 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010521 command_buffer_allocate_info.commandPool = m_commandPool;
10522 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10523 command_buffer_allocate_info.commandBufferCount = 1;
10524
10525 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010526 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010527 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10528 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010529 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010530 command_buffer_inheritance_info.renderPass = m_renderPass;
10531 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10532 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010533 command_buffer_begin_info.flags =
10534 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010535 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10536
10537 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010538 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10539 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010540 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010541 vkEndCommandBuffer(secondary_command_buffer);
10542
Mark Mueller93b938f2016-08-18 10:27:40 -060010543 VkSubmitInfo submit_info = {};
10544 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10545 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010546 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010547 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010548
Mark Mueller4042b652016-09-05 22:52:21 -060010549 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010550 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10552 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010553 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010554 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10555 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010556
10557 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010558 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10559
Mark Mueller4042b652016-09-05 22:52:21 -060010560 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010561 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010562 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010563
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10565 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010566 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010567 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10568 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010569}
10570
Mark Mueller917f6bc2016-08-30 10:57:19 -060010571TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10572 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10573 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010574 "Delete objects that are inuse. Call VkQueueSubmit "
10575 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010576
10577 ASSERT_NO_FATAL_FAILURE(InitState());
10578 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10579
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010580 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10581 const char *cannot_delete_event_message = "Cannot delete event 0x";
10582 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10583 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010584
10585 BeginCommandBuffer();
10586
10587 VkEvent event;
10588 VkEventCreateInfo event_create_info = {};
10589 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10590 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010591 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010592
Mark Muellerc8d441e2016-08-23 17:36:00 -060010593 EndCommandBuffer();
10594 vkDestroyEvent(m_device->device(), event, nullptr);
10595
10596 VkSubmitInfo submit_info = {};
10597 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10598 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010599 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010601 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10602 m_errorMonitor->VerifyFound();
10603
10604 m_errorMonitor->SetDesiredFailureMsg(0, "");
10605 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10606
10607 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10608
Mark Mueller917f6bc2016-08-30 10:57:19 -060010609 VkSemaphoreCreateInfo semaphore_create_info = {};
10610 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10611 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010612 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010613 VkFenceCreateInfo fence_create_info = {};
10614 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10615 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010616 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010617
10618 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010619 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010620 descriptor_pool_type_count.descriptorCount = 1;
10621
10622 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10623 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10624 descriptor_pool_create_info.maxSets = 1;
10625 descriptor_pool_create_info.poolSizeCount = 1;
10626 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010627 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010628
10629 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010630 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010631
10632 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010633 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010634 descriptorset_layout_binding.descriptorCount = 1;
10635 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10636
10637 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010638 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010639 descriptorset_layout_create_info.bindingCount = 1;
10640 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10641
10642 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010643 ASSERT_VK_SUCCESS(
10644 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010645
10646 VkDescriptorSet descriptorset;
10647 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010648 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010649 descriptorset_allocate_info.descriptorSetCount = 1;
10650 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10651 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010652 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010653
Mark Mueller4042b652016-09-05 22:52:21 -060010654 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10655
10656 VkDescriptorBufferInfo buffer_info = {};
10657 buffer_info.buffer = buffer_test.GetBuffer();
10658 buffer_info.offset = 0;
10659 buffer_info.range = 1024;
10660
10661 VkWriteDescriptorSet write_descriptor_set = {};
10662 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10663 write_descriptor_set.dstSet = descriptorset;
10664 write_descriptor_set.descriptorCount = 1;
10665 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10666 write_descriptor_set.pBufferInfo = &buffer_info;
10667
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010668 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010669
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010670 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10671 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010672
10673 VkPipelineObj pipe(m_device);
10674 pipe.AddColorAttachment();
10675 pipe.AddShader(&vs);
10676 pipe.AddShader(&fs);
10677
10678 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010679 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010680 pipeline_layout_create_info.setLayoutCount = 1;
10681 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10682
10683 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010684 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010685
10686 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10687
Mark Muellerc8d441e2016-08-23 17:36:00 -060010688 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010689 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010690
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010691 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10692 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10693 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010694
Mark Muellerc8d441e2016-08-23 17:36:00 -060010695 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010696
Mark Mueller917f6bc2016-08-30 10:57:19 -060010697 submit_info.signalSemaphoreCount = 1;
10698 submit_info.pSignalSemaphores = &semaphore;
10699 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010700
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010702 vkDestroyEvent(m_device->device(), event, nullptr);
10703 m_errorMonitor->VerifyFound();
10704
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010706 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10707 m_errorMonitor->VerifyFound();
10708
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010710 vkDestroyFence(m_device->device(), fence, nullptr);
10711 m_errorMonitor->VerifyFound();
10712
Tobin Ehlis122207b2016-09-01 08:50:06 -070010713 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010714 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10715 vkDestroyFence(m_device->device(), fence, nullptr);
10716 vkDestroyEvent(m_device->device(), event, nullptr);
10717 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010718 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010719 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10720}
10721
Tobin Ehlis2adda372016-09-01 08:51:06 -070010722TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10723 TEST_DESCRIPTION("Delete in-use query pool.");
10724
10725 ASSERT_NO_FATAL_FAILURE(InitState());
10726 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10727
10728 VkQueryPool query_pool;
10729 VkQueryPoolCreateInfo query_pool_ci{};
10730 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10731 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10732 query_pool_ci.queryCount = 1;
10733 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10734 BeginCommandBuffer();
10735 // Reset query pool to create binding with cmd buffer
10736 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10737
10738 EndCommandBuffer();
10739
10740 VkSubmitInfo submit_info = {};
10741 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10742 submit_info.commandBufferCount = 1;
10743 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10744 // Submit cmd buffer and then destroy query pool while in-flight
10745 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10746
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010748 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10749 m_errorMonitor->VerifyFound();
10750
10751 vkQueueWaitIdle(m_device->m_queue);
10752 // Now that cmd buffer done we can safely destroy query_pool
10753 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10754}
10755
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010756TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10757 TEST_DESCRIPTION("Delete in-use pipeline.");
10758
10759 ASSERT_NO_FATAL_FAILURE(InitState());
10760 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10761
10762 // Empty pipeline layout used for binding PSO
10763 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10764 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10765 pipeline_layout_ci.setLayoutCount = 0;
10766 pipeline_layout_ci.pSetLayouts = NULL;
10767
10768 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010769 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010770 ASSERT_VK_SUCCESS(err);
10771
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010773 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010774 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10775 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010776 // Store pipeline handle so we can actually delete it before test finishes
10777 VkPipeline delete_this_pipeline;
10778 { // Scope pipeline so it will be auto-deleted
10779 VkPipelineObj pipe(m_device);
10780 pipe.AddShader(&vs);
10781 pipe.AddShader(&fs);
10782 pipe.AddColorAttachment();
10783 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10784 delete_this_pipeline = pipe.handle();
10785
10786 BeginCommandBuffer();
10787 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010788 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010789
10790 EndCommandBuffer();
10791
10792 VkSubmitInfo submit_info = {};
10793 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10794 submit_info.commandBufferCount = 1;
10795 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10796 // Submit cmd buffer and then pipeline destroyed while in-flight
10797 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10798 } // Pipeline deletion triggered here
10799 m_errorMonitor->VerifyFound();
10800 // Make sure queue finished and then actually delete pipeline
10801 vkQueueWaitIdle(m_device->m_queue);
10802 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10803 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10804}
10805
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010806TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10807 TEST_DESCRIPTION("Delete in-use imageView.");
10808
10809 ASSERT_NO_FATAL_FAILURE(InitState());
10810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10811
10812 VkDescriptorPoolSize ds_type_count;
10813 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10814 ds_type_count.descriptorCount = 1;
10815
10816 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10817 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10818 ds_pool_ci.maxSets = 1;
10819 ds_pool_ci.poolSizeCount = 1;
10820 ds_pool_ci.pPoolSizes = &ds_type_count;
10821
10822 VkDescriptorPool ds_pool;
10823 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10824 ASSERT_VK_SUCCESS(err);
10825
10826 VkSamplerCreateInfo sampler_ci = {};
10827 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10828 sampler_ci.pNext = NULL;
10829 sampler_ci.magFilter = VK_FILTER_NEAREST;
10830 sampler_ci.minFilter = VK_FILTER_NEAREST;
10831 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10832 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10833 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10834 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10835 sampler_ci.mipLodBias = 1.0;
10836 sampler_ci.anisotropyEnable = VK_FALSE;
10837 sampler_ci.maxAnisotropy = 1;
10838 sampler_ci.compareEnable = VK_FALSE;
10839 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10840 sampler_ci.minLod = 1.0;
10841 sampler_ci.maxLod = 1.0;
10842 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10843 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10844 VkSampler sampler;
10845
10846 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10847 ASSERT_VK_SUCCESS(err);
10848
10849 VkDescriptorSetLayoutBinding layout_binding;
10850 layout_binding.binding = 0;
10851 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10852 layout_binding.descriptorCount = 1;
10853 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10854 layout_binding.pImmutableSamplers = NULL;
10855
10856 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10857 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10858 ds_layout_ci.bindingCount = 1;
10859 ds_layout_ci.pBindings = &layout_binding;
10860 VkDescriptorSetLayout ds_layout;
10861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10862 ASSERT_VK_SUCCESS(err);
10863
10864 VkDescriptorSetAllocateInfo alloc_info = {};
10865 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10866 alloc_info.descriptorSetCount = 1;
10867 alloc_info.descriptorPool = ds_pool;
10868 alloc_info.pSetLayouts = &ds_layout;
10869 VkDescriptorSet descriptor_set;
10870 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10871 ASSERT_VK_SUCCESS(err);
10872
10873 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10874 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10875 pipeline_layout_ci.pNext = NULL;
10876 pipeline_layout_ci.setLayoutCount = 1;
10877 pipeline_layout_ci.pSetLayouts = &ds_layout;
10878
10879 VkPipelineLayout pipeline_layout;
10880 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10881 ASSERT_VK_SUCCESS(err);
10882
10883 VkImageObj image(m_device);
10884 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
10885 ASSERT_TRUE(image.initialized());
10886
10887 VkImageView view;
10888 VkImageViewCreateInfo ivci = {};
10889 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10890 ivci.image = image.handle();
10891 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10892 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
10893 ivci.subresourceRange.layerCount = 1;
10894 ivci.subresourceRange.baseMipLevel = 0;
10895 ivci.subresourceRange.levelCount = 1;
10896 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10897
10898 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
10899 ASSERT_VK_SUCCESS(err);
10900
10901 VkDescriptorImageInfo image_info{};
10902 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10903 image_info.imageView = view;
10904 image_info.sampler = sampler;
10905
10906 VkWriteDescriptorSet descriptor_write = {};
10907 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10908 descriptor_write.dstSet = descriptor_set;
10909 descriptor_write.dstBinding = 0;
10910 descriptor_write.descriptorCount = 1;
10911 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10912 descriptor_write.pImageInfo = &image_info;
10913
10914 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10915
10916 // Create PSO to use the sampler
10917 char const *vsSource = "#version 450\n"
10918 "\n"
10919 "out gl_PerVertex { \n"
10920 " vec4 gl_Position;\n"
10921 "};\n"
10922 "void main(){\n"
10923 " gl_Position = vec4(1);\n"
10924 "}\n";
10925 char const *fsSource = "#version 450\n"
10926 "\n"
10927 "layout(set=0, binding=0) uniform sampler2D s;\n"
10928 "layout(location=0) out vec4 x;\n"
10929 "void main(){\n"
10930 " x = texture(s, vec2(1));\n"
10931 "}\n";
10932 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10933 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10934 VkPipelineObj pipe(m_device);
10935 pipe.AddShader(&vs);
10936 pipe.AddShader(&fs);
10937 pipe.AddColorAttachment();
10938 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10939
10940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
10941
10942 BeginCommandBuffer();
10943 // Bind pipeline to cmd buffer
10944 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10945 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10946 &descriptor_set, 0, nullptr);
10947 Draw(1, 0, 0, 0);
10948 EndCommandBuffer();
10949 // Submit cmd buffer then destroy sampler
10950 VkSubmitInfo submit_info = {};
10951 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10952 submit_info.commandBufferCount = 1;
10953 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10954 // Submit cmd buffer and then destroy imageView while in-flight
10955 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10956
10957 vkDestroyImageView(m_device->device(), view, nullptr);
10958 m_errorMonitor->VerifyFound();
10959 vkQueueWaitIdle(m_device->m_queue);
10960 // Now we can actually destroy imageView
10961 vkDestroyImageView(m_device->device(), view, NULL);
10962 vkDestroySampler(m_device->device(), sampler, nullptr);
10963 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10964 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10965 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10966}
10967
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060010968TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
10969 TEST_DESCRIPTION("Delete in-use bufferView.");
10970
10971 ASSERT_NO_FATAL_FAILURE(InitState());
10972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10973
10974 VkDescriptorPoolSize ds_type_count;
10975 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10976 ds_type_count.descriptorCount = 1;
10977
10978 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10979 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10980 ds_pool_ci.maxSets = 1;
10981 ds_pool_ci.poolSizeCount = 1;
10982 ds_pool_ci.pPoolSizes = &ds_type_count;
10983
10984 VkDescriptorPool ds_pool;
10985 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10986 ASSERT_VK_SUCCESS(err);
10987
10988 VkDescriptorSetLayoutBinding layout_binding;
10989 layout_binding.binding = 0;
10990 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10991 layout_binding.descriptorCount = 1;
10992 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10993 layout_binding.pImmutableSamplers = NULL;
10994
10995 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10996 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10997 ds_layout_ci.bindingCount = 1;
10998 ds_layout_ci.pBindings = &layout_binding;
10999 VkDescriptorSetLayout ds_layout;
11000 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11001 ASSERT_VK_SUCCESS(err);
11002
11003 VkDescriptorSetAllocateInfo alloc_info = {};
11004 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11005 alloc_info.descriptorSetCount = 1;
11006 alloc_info.descriptorPool = ds_pool;
11007 alloc_info.pSetLayouts = &ds_layout;
11008 VkDescriptorSet descriptor_set;
11009 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11010 ASSERT_VK_SUCCESS(err);
11011
11012 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11013 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11014 pipeline_layout_ci.pNext = NULL;
11015 pipeline_layout_ci.setLayoutCount = 1;
11016 pipeline_layout_ci.pSetLayouts = &ds_layout;
11017
11018 VkPipelineLayout pipeline_layout;
11019 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11020 ASSERT_VK_SUCCESS(err);
11021
11022 VkBuffer buffer;
11023 uint32_t queue_family_index = 0;
11024 VkBufferCreateInfo buffer_create_info = {};
11025 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11026 buffer_create_info.size = 1024;
11027 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11028 buffer_create_info.queueFamilyIndexCount = 1;
11029 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11030
11031 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11032 ASSERT_VK_SUCCESS(err);
11033
11034 VkMemoryRequirements memory_reqs;
11035 VkDeviceMemory buffer_memory;
11036
11037 VkMemoryAllocateInfo memory_info = {};
11038 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11039 memory_info.allocationSize = 0;
11040 memory_info.memoryTypeIndex = 0;
11041
11042 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11043 memory_info.allocationSize = memory_reqs.size;
11044 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11045 ASSERT_TRUE(pass);
11046
11047 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11048 ASSERT_VK_SUCCESS(err);
11049 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11050 ASSERT_VK_SUCCESS(err);
11051
11052 VkBufferView view;
11053 VkBufferViewCreateInfo bvci = {};
11054 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11055 bvci.buffer = buffer;
11056 bvci.format = VK_FORMAT_R8_UNORM;
11057 bvci.range = VK_WHOLE_SIZE;
11058
11059 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11060 ASSERT_VK_SUCCESS(err);
11061
11062 VkWriteDescriptorSet descriptor_write = {};
11063 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11064 descriptor_write.dstSet = descriptor_set;
11065 descriptor_write.dstBinding = 0;
11066 descriptor_write.descriptorCount = 1;
11067 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11068 descriptor_write.pTexelBufferView = &view;
11069
11070 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11071
11072 char const *vsSource = "#version 450\n"
11073 "\n"
11074 "out gl_PerVertex { \n"
11075 " vec4 gl_Position;\n"
11076 "};\n"
11077 "void main(){\n"
11078 " gl_Position = vec4(1);\n"
11079 "}\n";
11080 char const *fsSource = "#version 450\n"
11081 "\n"
11082 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11083 "layout(location=0) out vec4 x;\n"
11084 "void main(){\n"
11085 " x = imageLoad(s, 0);\n"
11086 "}\n";
11087 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11088 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11089 VkPipelineObj pipe(m_device);
11090 pipe.AddShader(&vs);
11091 pipe.AddShader(&fs);
11092 pipe.AddColorAttachment();
11093 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11094
11095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11096
11097 BeginCommandBuffer();
11098 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11099 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11100 VkRect2D scissor = {{0, 0}, {16, 16}};
11101 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11102 // Bind pipeline to cmd buffer
11103 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11104 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11105 &descriptor_set, 0, nullptr);
11106 Draw(1, 0, 0, 0);
11107 EndCommandBuffer();
11108
11109 VkSubmitInfo submit_info = {};
11110 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11111 submit_info.commandBufferCount = 1;
11112 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11113 // Submit cmd buffer and then destroy bufferView while in-flight
11114 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11115
11116 vkDestroyBufferView(m_device->device(), view, nullptr);
11117 m_errorMonitor->VerifyFound();
11118 vkQueueWaitIdle(m_device->m_queue);
11119 // Now we can actually destroy bufferView
11120 vkDestroyBufferView(m_device->device(), view, NULL);
11121 vkDestroyBuffer(m_device->device(), buffer, NULL);
11122 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11123 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11124 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11125 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11126}
11127
Tobin Ehlis209532e2016-09-07 13:52:18 -060011128TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11129 TEST_DESCRIPTION("Delete in-use sampler.");
11130
11131 ASSERT_NO_FATAL_FAILURE(InitState());
11132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11133
11134 VkDescriptorPoolSize ds_type_count;
11135 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11136 ds_type_count.descriptorCount = 1;
11137
11138 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11139 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11140 ds_pool_ci.maxSets = 1;
11141 ds_pool_ci.poolSizeCount = 1;
11142 ds_pool_ci.pPoolSizes = &ds_type_count;
11143
11144 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011145 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011146 ASSERT_VK_SUCCESS(err);
11147
11148 VkSamplerCreateInfo sampler_ci = {};
11149 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11150 sampler_ci.pNext = NULL;
11151 sampler_ci.magFilter = VK_FILTER_NEAREST;
11152 sampler_ci.minFilter = VK_FILTER_NEAREST;
11153 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11154 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11155 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11156 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11157 sampler_ci.mipLodBias = 1.0;
11158 sampler_ci.anisotropyEnable = VK_FALSE;
11159 sampler_ci.maxAnisotropy = 1;
11160 sampler_ci.compareEnable = VK_FALSE;
11161 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11162 sampler_ci.minLod = 1.0;
11163 sampler_ci.maxLod = 1.0;
11164 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11165 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11166 VkSampler sampler;
11167
11168 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11169 ASSERT_VK_SUCCESS(err);
11170
11171 VkDescriptorSetLayoutBinding layout_binding;
11172 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011173 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011174 layout_binding.descriptorCount = 1;
11175 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11176 layout_binding.pImmutableSamplers = NULL;
11177
11178 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11179 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11180 ds_layout_ci.bindingCount = 1;
11181 ds_layout_ci.pBindings = &layout_binding;
11182 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011183 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011184 ASSERT_VK_SUCCESS(err);
11185
11186 VkDescriptorSetAllocateInfo alloc_info = {};
11187 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11188 alloc_info.descriptorSetCount = 1;
11189 alloc_info.descriptorPool = ds_pool;
11190 alloc_info.pSetLayouts = &ds_layout;
11191 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011192 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011193 ASSERT_VK_SUCCESS(err);
11194
11195 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11196 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11197 pipeline_layout_ci.pNext = NULL;
11198 pipeline_layout_ci.setLayoutCount = 1;
11199 pipeline_layout_ci.pSetLayouts = &ds_layout;
11200
11201 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011202 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011203 ASSERT_VK_SUCCESS(err);
11204
11205 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011206 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 -060011207 ASSERT_TRUE(image.initialized());
11208
11209 VkImageView view;
11210 VkImageViewCreateInfo ivci = {};
11211 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11212 ivci.image = image.handle();
11213 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11214 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11215 ivci.subresourceRange.layerCount = 1;
11216 ivci.subresourceRange.baseMipLevel = 0;
11217 ivci.subresourceRange.levelCount = 1;
11218 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11219
11220 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11221 ASSERT_VK_SUCCESS(err);
11222
11223 VkDescriptorImageInfo image_info{};
11224 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11225 image_info.imageView = view;
11226 image_info.sampler = sampler;
11227
11228 VkWriteDescriptorSet descriptor_write = {};
11229 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11230 descriptor_write.dstSet = descriptor_set;
11231 descriptor_write.dstBinding = 0;
11232 descriptor_write.descriptorCount = 1;
11233 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11234 descriptor_write.pImageInfo = &image_info;
11235
11236 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11237
11238 // Create PSO to use the sampler
11239 char const *vsSource = "#version 450\n"
11240 "\n"
11241 "out gl_PerVertex { \n"
11242 " vec4 gl_Position;\n"
11243 "};\n"
11244 "void main(){\n"
11245 " gl_Position = vec4(1);\n"
11246 "}\n";
11247 char const *fsSource = "#version 450\n"
11248 "\n"
11249 "layout(set=0, binding=0) uniform sampler2D s;\n"
11250 "layout(location=0) out vec4 x;\n"
11251 "void main(){\n"
11252 " x = texture(s, vec2(1));\n"
11253 "}\n";
11254 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11255 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11256 VkPipelineObj pipe(m_device);
11257 pipe.AddShader(&vs);
11258 pipe.AddShader(&fs);
11259 pipe.AddColorAttachment();
11260 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11261
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011263
11264 BeginCommandBuffer();
11265 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011266 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11267 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11268 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011269 Draw(1, 0, 0, 0);
11270 EndCommandBuffer();
11271 // Submit cmd buffer then destroy sampler
11272 VkSubmitInfo submit_info = {};
11273 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11274 submit_info.commandBufferCount = 1;
11275 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11276 // Submit cmd buffer and then destroy sampler while in-flight
11277 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11278
11279 vkDestroySampler(m_device->device(), sampler, nullptr);
11280 m_errorMonitor->VerifyFound();
11281 vkQueueWaitIdle(m_device->m_queue);
11282 // Now we can actually destroy sampler
11283 vkDestroySampler(m_device->device(), sampler, nullptr);
11284 vkDestroyImageView(m_device->device(), view, NULL);
11285 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11286 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11287 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11288}
11289
Mark Mueller1cd9f412016-08-25 13:23:52 -060011290TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011291 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011292 "signaled but not waited on by the queue. Wait on a "
11293 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011294
11295 ASSERT_NO_FATAL_FAILURE(InitState());
11296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011298 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11299 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11300 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011301
11302 BeginCommandBuffer();
11303 EndCommandBuffer();
11304
11305 VkSemaphoreCreateInfo semaphore_create_info = {};
11306 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11307 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011308 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011309 VkSubmitInfo submit_info = {};
11310 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11311 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011312 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011313 submit_info.signalSemaphoreCount = 1;
11314 submit_info.pSignalSemaphores = &semaphore;
11315 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11316 m_errorMonitor->SetDesiredFailureMsg(0, "");
11317 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11318 BeginCommandBuffer();
11319 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011321 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11322 m_errorMonitor->VerifyFound();
11323
Mark Mueller1cd9f412016-08-25 13:23:52 -060011324 VkFenceCreateInfo fence_create_info = {};
11325 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11326 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011327 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011330 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11331 m_errorMonitor->VerifyFound();
11332
Mark Mueller4042b652016-09-05 22:52:21 -060011333 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011334 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011335 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11336}
11337
Tobin Ehlis4af23302016-07-19 10:50:30 -060011338TEST_F(VkLayerTest, FramebufferIncompatible) {
11339 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11340 "that does not match the framebuffer for the active "
11341 "renderpass.");
11342 ASSERT_NO_FATAL_FAILURE(InitState());
11343 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11344
11345 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011346 VkAttachmentDescription attachment = {0,
11347 VK_FORMAT_B8G8R8A8_UNORM,
11348 VK_SAMPLE_COUNT_1_BIT,
11349 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11350 VK_ATTACHMENT_STORE_OP_STORE,
11351 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11352 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11353 VK_IMAGE_LAYOUT_UNDEFINED,
11354 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011355
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011356 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011357
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011358 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011359
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011360 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011361
11362 VkRenderPass rp;
11363 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11364 ASSERT_VK_SUCCESS(err);
11365
11366 // A compatible framebuffer.
11367 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011368 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 -060011369 ASSERT_TRUE(image.initialized());
11370
11371 VkImageViewCreateInfo ivci = {
11372 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11373 nullptr,
11374 0,
11375 image.handle(),
11376 VK_IMAGE_VIEW_TYPE_2D,
11377 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011378 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11379 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011380 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11381 };
11382 VkImageView view;
11383 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11384 ASSERT_VK_SUCCESS(err);
11385
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011386 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011387 VkFramebuffer fb;
11388 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11389 ASSERT_VK_SUCCESS(err);
11390
11391 VkCommandBufferAllocateInfo cbai = {};
11392 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11393 cbai.commandPool = m_commandPool;
11394 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11395 cbai.commandBufferCount = 1;
11396
11397 VkCommandBuffer sec_cb;
11398 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11399 ASSERT_VK_SUCCESS(err);
11400 VkCommandBufferBeginInfo cbbi = {};
11401 VkCommandBufferInheritanceInfo cbii = {};
11402 cbii.renderPass = renderPass();
11403 cbii.framebuffer = fb;
11404 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11405 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011406 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 -060011407 cbbi.pInheritanceInfo = &cbii;
11408 vkBeginCommandBuffer(sec_cb, &cbbi);
11409 vkEndCommandBuffer(sec_cb);
11410
Chris Forbes3400bc52016-09-13 18:10:34 +120011411 VkCommandBufferBeginInfo cbbi2 = {
11412 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11413 0, nullptr
11414 };
11415 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11416 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011419 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011420 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11421 m_errorMonitor->VerifyFound();
11422 // Cleanup
11423 vkDestroyImageView(m_device->device(), view, NULL);
11424 vkDestroyRenderPass(m_device->device(), rp, NULL);
11425 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11426}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011427
11428TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11429 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11430 "invalid value. If logicOp is not available, attempt to "
11431 "use it and verify that we see the correct error.");
11432 ASSERT_NO_FATAL_FAILURE(InitState());
11433 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11434
11435 auto features = m_device->phy().features();
11436 // Set the expected error depending on whether or not logicOp available
11437 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11439 "enabled, logicOpEnable must be "
11440 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011441 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011443 }
11444 // Create a pipeline using logicOp
11445 VkResult err;
11446
11447 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11448 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11449
11450 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011451 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011452 ASSERT_VK_SUCCESS(err);
11453
11454 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11455 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11456 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011457 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011458 vp_state_ci.pViewports = &vp;
11459 vp_state_ci.scissorCount = 1;
11460 VkRect2D scissors = {}; // Dummy scissors to point to
11461 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011462
11463 VkPipelineShaderStageCreateInfo shaderStages[2];
11464 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11465
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011466 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11467 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011468 shaderStages[0] = vs.GetStageCreateInfo();
11469 shaderStages[1] = fs.GetStageCreateInfo();
11470
11471 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11472 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11473
11474 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11475 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11476 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11477
11478 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11479 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011480 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011481
11482 VkPipelineColorBlendAttachmentState att = {};
11483 att.blendEnable = VK_FALSE;
11484 att.colorWriteMask = 0xf;
11485
11486 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11487 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11488 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11489 cb_ci.logicOpEnable = VK_TRUE;
11490 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11491 cb_ci.attachmentCount = 1;
11492 cb_ci.pAttachments = &att;
11493
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011494 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11495 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11496 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11497
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011498 VkGraphicsPipelineCreateInfo gp_ci = {};
11499 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11500 gp_ci.stageCount = 2;
11501 gp_ci.pStages = shaderStages;
11502 gp_ci.pVertexInputState = &vi_ci;
11503 gp_ci.pInputAssemblyState = &ia_ci;
11504 gp_ci.pViewportState = &vp_state_ci;
11505 gp_ci.pRasterizationState = &rs_ci;
11506 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011507 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011508 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11509 gp_ci.layout = pipeline_layout;
11510 gp_ci.renderPass = renderPass();
11511
11512 VkPipelineCacheCreateInfo pc_ci = {};
11513 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11514
11515 VkPipeline pipeline;
11516 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011517 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011518 ASSERT_VK_SUCCESS(err);
11519
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011520 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011521 m_errorMonitor->VerifyFound();
11522 if (VK_SUCCESS == err) {
11523 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11524 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011525 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11526 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11527}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011528#endif // DRAW_STATE_TESTS
11529
Tobin Ehlis0788f522015-05-26 16:11:58 -060011530#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011531#if GTEST_IS_THREADSAFE
11532struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011533 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011534 VkEvent event;
11535 bool bailout;
11536};
11537
Karl Schultz6addd812016-02-02 17:17:23 -070011538extern "C" void *AddToCommandBuffer(void *arg) {
11539 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011540
Mike Stroyana6d14942016-07-13 15:10:05 -060011541 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011542 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011543 if (data->bailout) {
11544 break;
11545 }
11546 }
11547 return NULL;
11548}
11549
Karl Schultz6addd812016-02-02 17:17:23 -070011550TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011551 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011552
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011554
Mike Stroyanaccf7692015-05-12 16:00:45 -060011555 ASSERT_NO_FATAL_FAILURE(InitState());
11556 ASSERT_NO_FATAL_FAILURE(InitViewport());
11557 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11558
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011559 // Calls AllocateCommandBuffers
11560 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011561
11562 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011563 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011564
11565 VkEventCreateInfo event_info;
11566 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011567 VkResult err;
11568
11569 memset(&event_info, 0, sizeof(event_info));
11570 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11571
Chia-I Wuf7458c52015-10-26 21:10:41 +080011572 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011573 ASSERT_VK_SUCCESS(err);
11574
Mike Stroyanaccf7692015-05-12 16:00:45 -060011575 err = vkResetEvent(device(), event);
11576 ASSERT_VK_SUCCESS(err);
11577
11578 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011579 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011580 data.event = event;
11581 data.bailout = false;
11582 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011583
11584 // First do some correct operations using multiple threads.
11585 // Add many entries to command buffer from another thread.
11586 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11587 // Make non-conflicting calls from this thread at the same time.
11588 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011589 uint32_t count;
11590 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011591 }
11592 test_platform_thread_join(thread, NULL);
11593
11594 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011595 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011596 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011597 // Add many entries to command buffer from this thread at the same time.
11598 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011599
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011600 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011601 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011602
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011603 m_errorMonitor->SetBailout(NULL);
11604
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011605 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011606
Chia-I Wuf7458c52015-10-26 21:10:41 +080011607 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011608}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011609#endif // GTEST_IS_THREADSAFE
11610#endif // THREADING_TESTS
11611
Chris Forbes9f7ff632015-05-25 11:13:08 +120011612#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011613TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011614 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11615 "with an impossible code size");
11616
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011618
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011619 ASSERT_NO_FATAL_FAILURE(InitState());
11620 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11621
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011622 VkShaderModule module;
11623 VkShaderModuleCreateInfo moduleCreateInfo;
11624 struct icd_spv_header spv;
11625
11626 spv.magic = ICD_SPV_MAGIC;
11627 spv.version = ICD_SPV_VERSION;
11628 spv.gen_magic = 0;
11629
11630 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11631 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011632 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011633 moduleCreateInfo.codeSize = 4;
11634 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011635 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011636
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011637 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011638}
11639
Karl Schultz6addd812016-02-02 17:17:23 -070011640TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011641 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11642 "with a bad magic number");
11643
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011645
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011646 ASSERT_NO_FATAL_FAILURE(InitState());
11647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11648
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011649 VkShaderModule module;
11650 VkShaderModuleCreateInfo moduleCreateInfo;
11651 struct icd_spv_header spv;
11652
11653 spv.magic = ~ICD_SPV_MAGIC;
11654 spv.version = ICD_SPV_VERSION;
11655 spv.gen_magic = 0;
11656
11657 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11658 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011659 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011660 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11661 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011662 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011663
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011664 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011665}
11666
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011667#if 0
11668// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011669TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011671 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011672
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011673 ASSERT_NO_FATAL_FAILURE(InitState());
11674 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11675
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011676 VkShaderModule module;
11677 VkShaderModuleCreateInfo moduleCreateInfo;
11678 struct icd_spv_header spv;
11679
11680 spv.magic = ICD_SPV_MAGIC;
11681 spv.version = ~ICD_SPV_VERSION;
11682 spv.gen_magic = 0;
11683
11684 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11685 moduleCreateInfo.pNext = NULL;
11686
Karl Schultz6addd812016-02-02 17:17:23 -070011687 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011688 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11689 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011690 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011691
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011692 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011693}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011694#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011695
Karl Schultz6addd812016-02-02 17:17:23 -070011696TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011697 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11698 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011700
Chris Forbes9f7ff632015-05-25 11:13:08 +120011701 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011702 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011703
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011704 char const *vsSource = "#version 450\n"
11705 "\n"
11706 "layout(location=0) out float x;\n"
11707 "out gl_PerVertex {\n"
11708 " vec4 gl_Position;\n"
11709 "};\n"
11710 "void main(){\n"
11711 " gl_Position = vec4(1);\n"
11712 " x = 0;\n"
11713 "}\n";
11714 char const *fsSource = "#version 450\n"
11715 "\n"
11716 "layout(location=0) out vec4 color;\n"
11717 "void main(){\n"
11718 " color = vec4(1);\n"
11719 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011720
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011721 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11722 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011723
11724 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011725 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011726 pipe.AddShader(&vs);
11727 pipe.AddShader(&fs);
11728
Chris Forbes9f7ff632015-05-25 11:13:08 +120011729 VkDescriptorSetObj descriptorSet(m_device);
11730 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011731 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011732
Tony Barbour5781e8f2015-08-04 16:23:11 -060011733 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011734
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011735 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011736}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011737
Mark Mueller098c9cb2016-09-08 09:01:57 -060011738TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11739 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11740
11741 ASSERT_NO_FATAL_FAILURE(InitState());
11742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11743
11744 const char *bad_specialization_message =
11745 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11746
11747 char const *vsSource =
11748 "#version 450\n"
11749 "\n"
11750 "out gl_PerVertex {\n"
11751 " vec4 gl_Position;\n"
11752 "};\n"
11753 "void main(){\n"
11754 " gl_Position = vec4(1);\n"
11755 "}\n";
11756
11757 char const *fsSource =
11758 "#version 450\n"
11759 "\n"
11760 "layout (constant_id = 0) const float r = 0.0f;\n"
11761 "layout(location = 0) out vec4 uFragColor;\n"
11762 "void main(){\n"
11763 " uFragColor = vec4(r,1,0,1);\n"
11764 "}\n";
11765
11766 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11767 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11768
11769 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11770 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11771
11772 VkPipelineLayout pipeline_layout;
11773 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11774
11775 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11776 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11777 vp_state_create_info.viewportCount = 1;
11778 VkViewport viewport = {};
11779 vp_state_create_info.pViewports = &viewport;
11780 vp_state_create_info.scissorCount = 1;
11781 VkRect2D scissors = {};
11782 vp_state_create_info.pScissors = &scissors;
11783
11784 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11785
11786 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11787 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11788 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11789 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11790
11791 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11792 vs.GetStageCreateInfo(),
11793 fs.GetStageCreateInfo()
11794 };
11795
11796 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11797 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11798
11799 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11800 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11801 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11802
11803 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11804 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11805 rasterization_state_create_info.pNext = nullptr;
11806 rasterization_state_create_info.lineWidth = 1.0f;
11807 rasterization_state_create_info.rasterizerDiscardEnable = true;
11808
11809 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11810 color_blend_attachment_state.blendEnable = VK_FALSE;
11811 color_blend_attachment_state.colorWriteMask = 0xf;
11812
11813 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11814 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11815 color_blend_state_create_info.attachmentCount = 1;
11816 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11817
11818 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11819 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11820 graphicspipe_create_info.stageCount = 2;
11821 graphicspipe_create_info.pStages = shader_stage_create_info;
11822 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11823 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11824 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11825 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11826 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11827 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11828 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11829 graphicspipe_create_info.layout = pipeline_layout;
11830 graphicspipe_create_info.renderPass = renderPass();
11831
11832 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
11833 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11834
11835 VkPipelineCache pipelineCache;
11836 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
11837
11838 // This structure maps constant ids to data locations.
11839 const VkSpecializationMapEntry entry =
11840 // id, offset, size
11841 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
11842
11843 uint32_t data = 1;
11844
11845 // Set up the info describing spec map and data
11846 const VkSpecializationInfo specialization_info = {
11847 1,
11848 &entry,
11849 1 * sizeof(float),
11850 &data,
11851 };
11852 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
11853
11854 VkPipeline pipeline;
11855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
11856 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
11857 m_errorMonitor->VerifyFound();
11858
11859 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
11860 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11861}
11862
11863TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
11864 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11865
11866 ASSERT_NO_FATAL_FAILURE(InitState());
11867 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11868
11869 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
11870
11871 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
11872 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11873 descriptor_pool_type_count[0].descriptorCount = 1;
11874 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11875 descriptor_pool_type_count[1].descriptorCount = 1;
11876
11877 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11878 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11879 descriptor_pool_create_info.maxSets = 1;
11880 descriptor_pool_create_info.poolSizeCount = 2;
11881 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
11882 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11883
11884 VkDescriptorPool descriptorset_pool;
11885 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11886
11887 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11888 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11889 descriptorset_layout_binding.descriptorCount = 1;
11890 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11891
11892 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11893 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11894 descriptorset_layout_create_info.bindingCount = 1;
11895 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11896
11897 VkDescriptorSetLayout descriptorset_layout;
11898 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
11899
11900 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11901 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11902 descriptorset_allocate_info.descriptorSetCount = 1;
11903 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11904 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11905 VkDescriptorSet descriptorset;
11906 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11907
11908 // Challenge core_validation with a non uniform buffer type.
11909 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
11910
Mark Mueller098c9cb2016-09-08 09:01:57 -060011911 char const *vsSource =
11912 "#version 450\n"
11913 "\n"
11914 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11915 " mat4 mvp;\n"
11916 "} ubuf;\n"
11917 "out gl_PerVertex {\n"
11918 " vec4 gl_Position;\n"
11919 "};\n"
11920 "void main(){\n"
11921 " gl_Position = ubuf.mvp * vec4(1);\n"
11922 "}\n";
11923
11924 char const *fsSource =
11925 "#version 450\n"
11926 "\n"
11927 "layout(location = 0) out vec4 uFragColor;\n"
11928 "void main(){\n"
11929 " uFragColor = vec4(0,1,0,1);\n"
11930 "}\n";
11931
11932 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11933 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11934
11935 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11936 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11937 pipeline_layout_create_info.setLayoutCount = 1;
11938 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11939
11940 VkPipelineLayout pipeline_layout;
11941 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11942
11943 VkPipelineObj pipe(m_device);
11944 pipe.AddColorAttachment();
11945 pipe.AddShader(&vs);
11946 pipe.AddShader(&fs);
11947
11948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
11949 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11950 m_errorMonitor->VerifyFound();
11951
11952 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11953 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11954 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11955}
11956
11957TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
11958 TEST_DESCRIPTION(
11959 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
11960
11961 ASSERT_NO_FATAL_FAILURE(InitState());
11962 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11963
11964 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
11965
11966 VkDescriptorPoolSize descriptor_pool_type_count = {};
11967 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11968 descriptor_pool_type_count.descriptorCount = 1;
11969
11970 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11971 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11972 descriptor_pool_create_info.maxSets = 1;
11973 descriptor_pool_create_info.poolSizeCount = 1;
11974 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
11975 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11976
11977 VkDescriptorPool descriptorset_pool;
11978 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11979
11980 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11981 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11982 descriptorset_layout_binding.descriptorCount = 1;
11983 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
11984 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11985
11986 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11987 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11988 descriptorset_layout_create_info.bindingCount = 1;
11989 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11990
11991 VkDescriptorSetLayout descriptorset_layout;
11992 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
11993 nullptr, &descriptorset_layout));
11994
11995 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11996 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11997 descriptorset_allocate_info.descriptorSetCount = 1;
11998 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11999 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12000 VkDescriptorSet descriptorset;
12001 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12002
12003 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12004
Mark Mueller098c9cb2016-09-08 09:01:57 -060012005 char const *vsSource =
12006 "#version 450\n"
12007 "\n"
12008 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12009 " mat4 mvp;\n"
12010 "} ubuf;\n"
12011 "out gl_PerVertex {\n"
12012 " vec4 gl_Position;\n"
12013 "};\n"
12014 "void main(){\n"
12015 " gl_Position = ubuf.mvp * vec4(1);\n"
12016 "}\n";
12017
12018 char const *fsSource =
12019 "#version 450\n"
12020 "\n"
12021 "layout(location = 0) out vec4 uFragColor;\n"
12022 "void main(){\n"
12023 " uFragColor = vec4(0,1,0,1);\n"
12024 "}\n";
12025
12026 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12027 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12028
12029 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12030 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12031 pipeline_layout_create_info.setLayoutCount = 1;
12032 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12033
12034 VkPipelineLayout pipeline_layout;
12035 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12036
12037 VkPipelineObj pipe(m_device);
12038 pipe.AddColorAttachment();
12039 pipe.AddShader(&vs);
12040 pipe.AddShader(&fs);
12041
12042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12043 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12044 m_errorMonitor->VerifyFound();
12045
12046 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12047 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12048 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12049}
12050
12051TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12052 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12053 "accessible from the current shader stage.");
12054
12055 ASSERT_NO_FATAL_FAILURE(InitState());
12056 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12057
12058 const char *push_constant_not_accessible_message =
12059 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12060
12061 char const *vsSource =
12062 "#version 450\n"
12063 "\n"
12064 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12065 "out gl_PerVertex {\n"
12066 " vec4 gl_Position;\n"
12067 "};\n"
12068 "void main(){\n"
12069 " gl_Position = vec4(consts.x);\n"
12070 "}\n";
12071
12072 char const *fsSource =
12073 "#version 450\n"
12074 "\n"
12075 "layout(location = 0) out vec4 uFragColor;\n"
12076 "void main(){\n"
12077 " uFragColor = vec4(0,1,0,1);\n"
12078 "}\n";
12079
12080 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12081 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12082
12083 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12084 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12085
12086 // Set up a push constant range
12087 VkPushConstantRange push_constant_ranges = {};
12088 // Set to the wrong stage to challenge core_validation
12089 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12090 push_constant_ranges.size = 4;
12091
12092 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12093 pipeline_layout_create_info.pushConstantRangeCount = 1;
12094
12095 VkPipelineLayout pipeline_layout;
12096 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12097
12098 VkPipelineObj pipe(m_device);
12099 pipe.AddColorAttachment();
12100 pipe.AddShader(&vs);
12101 pipe.AddShader(&fs);
12102
12103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12104 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12105 m_errorMonitor->VerifyFound();
12106
12107 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12108}
12109
12110TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12111 TEST_DESCRIPTION(
12112 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12113
12114 ASSERT_NO_FATAL_FAILURE(InitState());
12115 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12116
12117 const char *feature_not_enabled_message =
12118 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12119
12120 // Some awkward steps are required to test with custom device features.
12121 std::vector<const char *> device_extension_names;
12122 auto features = m_device->phy().features();
12123 // Disable support for 64 bit floats
12124 features.shaderFloat64 = false;
12125 // The sacrificial device object
12126 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12127
12128 char const *vsSource = "#version 450\n"
12129 "\n"
12130 "out gl_PerVertex {\n"
12131 " vec4 gl_Position;\n"
12132 "};\n"
12133 "void main(){\n"
12134 " gl_Position = vec4(1);\n"
12135 "}\n";
12136 char const *fsSource = "#version 450\n"
12137 "\n"
12138 "layout(location=0) out vec4 color;\n"
12139 "void main(){\n"
12140 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12141 " color = vec4(green);\n"
12142 "}\n";
12143
12144 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12145 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12146
12147 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012148
12149 VkPipelineObj pipe(&test_device);
12150 pipe.AddColorAttachment();
12151 pipe.AddShader(&vs);
12152 pipe.AddShader(&fs);
12153
12154 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12155 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12156 VkPipelineLayout pipeline_layout;
12157 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12158
12159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12160 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12161 m_errorMonitor->VerifyFound();
12162
12163 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12164}
12165
12166TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12167 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12168
12169 ASSERT_NO_FATAL_FAILURE(InitState());
12170 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12171
12172 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12173
12174 char const *vsSource = "#version 450\n"
12175 "\n"
12176 "out gl_PerVertex {\n"
12177 " vec4 gl_Position;\n"
12178 "};\n"
12179 "layout(xfb_buffer = 1) out;"
12180 "void main(){\n"
12181 " gl_Position = vec4(1);\n"
12182 "}\n";
12183 char const *fsSource = "#version 450\n"
12184 "\n"
12185 "layout(location=0) out vec4 color;\n"
12186 "void main(){\n"
12187 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12188 " color = vec4(green);\n"
12189 "}\n";
12190
12191 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12192 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12193
12194 VkPipelineObj pipe(m_device);
12195 pipe.AddColorAttachment();
12196 pipe.AddShader(&vs);
12197 pipe.AddShader(&fs);
12198
12199 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12200 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12201 VkPipelineLayout pipeline_layout;
12202 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12203
12204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12205 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12206 m_errorMonitor->VerifyFound();
12207
12208 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12209}
12210
Karl Schultz6addd812016-02-02 17:17:23 -070012211TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012212 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12213 "which is not present in the outputs of the previous stage");
12214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012216
Chris Forbes59cb88d2015-05-25 11:13:13 +120012217 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012218 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012219
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012220 char const *vsSource = "#version 450\n"
12221 "\n"
12222 "out gl_PerVertex {\n"
12223 " vec4 gl_Position;\n"
12224 "};\n"
12225 "void main(){\n"
12226 " gl_Position = vec4(1);\n"
12227 "}\n";
12228 char const *fsSource = "#version 450\n"
12229 "\n"
12230 "layout(location=0) in float x;\n"
12231 "layout(location=0) out vec4 color;\n"
12232 "void main(){\n"
12233 " color = vec4(x);\n"
12234 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012235
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012236 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12237 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012238
12239 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012240 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012241 pipe.AddShader(&vs);
12242 pipe.AddShader(&fs);
12243
Chris Forbes59cb88d2015-05-25 11:13:13 +120012244 VkDescriptorSetObj descriptorSet(m_device);
12245 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012246 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012247
Tony Barbour5781e8f2015-08-04 16:23:11 -060012248 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012249
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012250 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012251}
12252
Karl Schultz6addd812016-02-02 17:17:23 -070012253TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012254 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12255 "within an interace block, which is not present in the outputs "
12256 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012258
12259 ASSERT_NO_FATAL_FAILURE(InitState());
12260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12261
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012262 char const *vsSource = "#version 450\n"
12263 "\n"
12264 "out gl_PerVertex {\n"
12265 " vec4 gl_Position;\n"
12266 "};\n"
12267 "void main(){\n"
12268 " gl_Position = vec4(1);\n"
12269 "}\n";
12270 char const *fsSource = "#version 450\n"
12271 "\n"
12272 "in block { layout(location=0) float x; } ins;\n"
12273 "layout(location=0) out vec4 color;\n"
12274 "void main(){\n"
12275 " color = vec4(ins.x);\n"
12276 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012277
12278 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12279 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12280
12281 VkPipelineObj pipe(m_device);
12282 pipe.AddColorAttachment();
12283 pipe.AddShader(&vs);
12284 pipe.AddShader(&fs);
12285
12286 VkDescriptorSetObj descriptorSet(m_device);
12287 descriptorSet.AppendDummy();
12288 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12289
12290 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12291
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012292 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012293}
12294
Karl Schultz6addd812016-02-02 17:17:23 -070012295TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012296 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012297 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12299 "output arr[2] of float32' vs 'ptr to "
12300 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012301
12302 ASSERT_NO_FATAL_FAILURE(InitState());
12303 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12304
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012305 char const *vsSource = "#version 450\n"
12306 "\n"
12307 "layout(location=0) out float x[2];\n"
12308 "out gl_PerVertex {\n"
12309 " vec4 gl_Position;\n"
12310 "};\n"
12311 "void main(){\n"
12312 " x[0] = 0; x[1] = 0;\n"
12313 " gl_Position = vec4(1);\n"
12314 "}\n";
12315 char const *fsSource = "#version 450\n"
12316 "\n"
12317 "layout(location=0) in float x[3];\n"
12318 "layout(location=0) out vec4 color;\n"
12319 "void main(){\n"
12320 " color = vec4(x[0] + x[1] + x[2]);\n"
12321 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012322
12323 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12324 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12325
12326 VkPipelineObj pipe(m_device);
12327 pipe.AddColorAttachment();
12328 pipe.AddShader(&vs);
12329 pipe.AddShader(&fs);
12330
12331 VkDescriptorSetObj descriptorSet(m_device);
12332 descriptorSet.AppendDummy();
12333 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12334
12335 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12336
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012337 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012338}
12339
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012340
Karl Schultz6addd812016-02-02 17:17:23 -070012341TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012342 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012343 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012345
Chris Forbesb56af562015-05-25 11:13:17 +120012346 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012347 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012348
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012349 char const *vsSource = "#version 450\n"
12350 "\n"
12351 "layout(location=0) out int x;\n"
12352 "out gl_PerVertex {\n"
12353 " vec4 gl_Position;\n"
12354 "};\n"
12355 "void main(){\n"
12356 " x = 0;\n"
12357 " gl_Position = vec4(1);\n"
12358 "}\n";
12359 char const *fsSource = "#version 450\n"
12360 "\n"
12361 "layout(location=0) in float x;\n" /* VS writes int */
12362 "layout(location=0) out vec4 color;\n"
12363 "void main(){\n"
12364 " color = vec4(x);\n"
12365 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012366
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012367 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12368 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012369
12370 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012371 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012372 pipe.AddShader(&vs);
12373 pipe.AddShader(&fs);
12374
Chris Forbesb56af562015-05-25 11:13:17 +120012375 VkDescriptorSetObj descriptorSet(m_device);
12376 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012377 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012378
Tony Barbour5781e8f2015-08-04 16:23:11 -060012379 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012380
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012381 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012382}
12383
Karl Schultz6addd812016-02-02 17:17:23 -070012384TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012385 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012386 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012387 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012389
12390 ASSERT_NO_FATAL_FAILURE(InitState());
12391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12392
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012393 char const *vsSource = "#version 450\n"
12394 "\n"
12395 "out block { layout(location=0) int x; } outs;\n"
12396 "out gl_PerVertex {\n"
12397 " vec4 gl_Position;\n"
12398 "};\n"
12399 "void main(){\n"
12400 " outs.x = 0;\n"
12401 " gl_Position = vec4(1);\n"
12402 "}\n";
12403 char const *fsSource = "#version 450\n"
12404 "\n"
12405 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12406 "layout(location=0) out vec4 color;\n"
12407 "void main(){\n"
12408 " color = vec4(ins.x);\n"
12409 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012410
12411 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12412 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12413
12414 VkPipelineObj pipe(m_device);
12415 pipe.AddColorAttachment();
12416 pipe.AddShader(&vs);
12417 pipe.AddShader(&fs);
12418
12419 VkDescriptorSetObj descriptorSet(m_device);
12420 descriptorSet.AppendDummy();
12421 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12422
12423 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12424
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012425 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012426}
12427
12428TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012429 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012430 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012431 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012432 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 +130012433
12434 ASSERT_NO_FATAL_FAILURE(InitState());
12435 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12436
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012437 char const *vsSource = "#version 450\n"
12438 "\n"
12439 "out block { layout(location=1) float x; } outs;\n"
12440 "out gl_PerVertex {\n"
12441 " vec4 gl_Position;\n"
12442 "};\n"
12443 "void main(){\n"
12444 " outs.x = 0;\n"
12445 " gl_Position = vec4(1);\n"
12446 "}\n";
12447 char const *fsSource = "#version 450\n"
12448 "\n"
12449 "in block { layout(location=0) float x; } ins;\n"
12450 "layout(location=0) out vec4 color;\n"
12451 "void main(){\n"
12452 " color = vec4(ins.x);\n"
12453 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012454
12455 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12456 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12457
12458 VkPipelineObj pipe(m_device);
12459 pipe.AddColorAttachment();
12460 pipe.AddShader(&vs);
12461 pipe.AddShader(&fs);
12462
12463 VkDescriptorSetObj descriptorSet(m_device);
12464 descriptorSet.AppendDummy();
12465 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12466
12467 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12468
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012469 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012470}
12471
12472TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012473 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012474 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012475 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012476 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 +130012477
12478 ASSERT_NO_FATAL_FAILURE(InitState());
12479 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12480
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012481 char const *vsSource = "#version 450\n"
12482 "\n"
12483 "out block { layout(location=0, component=0) float x; } outs;\n"
12484 "out gl_PerVertex {\n"
12485 " vec4 gl_Position;\n"
12486 "};\n"
12487 "void main(){\n"
12488 " outs.x = 0;\n"
12489 " gl_Position = vec4(1);\n"
12490 "}\n";
12491 char const *fsSource = "#version 450\n"
12492 "\n"
12493 "in block { layout(location=0, component=1) float x; } ins;\n"
12494 "layout(location=0) out vec4 color;\n"
12495 "void main(){\n"
12496 " color = vec4(ins.x);\n"
12497 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012498
12499 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12500 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12501
12502 VkPipelineObj pipe(m_device);
12503 pipe.AddColorAttachment();
12504 pipe.AddShader(&vs);
12505 pipe.AddShader(&fs);
12506
12507 VkDescriptorSetObj descriptorSet(m_device);
12508 descriptorSet.AppendDummy();
12509 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12510
12511 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12512
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012513 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012514}
12515
Karl Schultz6addd812016-02-02 17:17:23 -070012516TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012517 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12518 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012520
Chris Forbesde136e02015-05-25 11:13:28 +120012521 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012522 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012523
12524 VkVertexInputBindingDescription input_binding;
12525 memset(&input_binding, 0, sizeof(input_binding));
12526
12527 VkVertexInputAttributeDescription input_attrib;
12528 memset(&input_attrib, 0, sizeof(input_attrib));
12529 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12530
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012531 char const *vsSource = "#version 450\n"
12532 "\n"
12533 "out gl_PerVertex {\n"
12534 " vec4 gl_Position;\n"
12535 "};\n"
12536 "void main(){\n"
12537 " gl_Position = vec4(1);\n"
12538 "}\n";
12539 char const *fsSource = "#version 450\n"
12540 "\n"
12541 "layout(location=0) out vec4 color;\n"
12542 "void main(){\n"
12543 " color = vec4(1);\n"
12544 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012545
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012546 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12547 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012548
12549 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012550 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012551 pipe.AddShader(&vs);
12552 pipe.AddShader(&fs);
12553
12554 pipe.AddVertexInputBindings(&input_binding, 1);
12555 pipe.AddVertexInputAttribs(&input_attrib, 1);
12556
Chris Forbesde136e02015-05-25 11:13:28 +120012557 VkDescriptorSetObj descriptorSet(m_device);
12558 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012559 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012560
Tony Barbour5781e8f2015-08-04 16:23:11 -060012561 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012562
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012563 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012564}
12565
Karl Schultz6addd812016-02-02 17:17:23 -070012566TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012567 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12568 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012570
12571 ASSERT_NO_FATAL_FAILURE(InitState());
12572 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12573
12574 VkVertexInputBindingDescription input_binding;
12575 memset(&input_binding, 0, sizeof(input_binding));
12576
12577 VkVertexInputAttributeDescription input_attrib;
12578 memset(&input_attrib, 0, sizeof(input_attrib));
12579 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12580
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012581 char const *vsSource = "#version 450\n"
12582 "\n"
12583 "layout(location=1) in float x;\n"
12584 "out gl_PerVertex {\n"
12585 " vec4 gl_Position;\n"
12586 "};\n"
12587 "void main(){\n"
12588 " gl_Position = vec4(x);\n"
12589 "}\n";
12590 char const *fsSource = "#version 450\n"
12591 "\n"
12592 "layout(location=0) out vec4 color;\n"
12593 "void main(){\n"
12594 " color = vec4(1);\n"
12595 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012596
12597 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12598 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12599
12600 VkPipelineObj pipe(m_device);
12601 pipe.AddColorAttachment();
12602 pipe.AddShader(&vs);
12603 pipe.AddShader(&fs);
12604
12605 pipe.AddVertexInputBindings(&input_binding, 1);
12606 pipe.AddVertexInputAttribs(&input_attrib, 1);
12607
12608 VkDescriptorSetObj descriptorSet(m_device);
12609 descriptorSet.AppendDummy();
12610 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12611
12612 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12613
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012614 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012615}
12616
Karl Schultz6addd812016-02-02 17:17:23 -070012617TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012618 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012619 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012620 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 -060012621
Chris Forbes62e8e502015-05-25 11:13:29 +120012622 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012623 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012624
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012625 char const *vsSource = "#version 450\n"
12626 "\n"
12627 "layout(location=0) in vec4 x;\n" /* not provided */
12628 "out gl_PerVertex {\n"
12629 " vec4 gl_Position;\n"
12630 "};\n"
12631 "void main(){\n"
12632 " gl_Position = x;\n"
12633 "}\n";
12634 char const *fsSource = "#version 450\n"
12635 "\n"
12636 "layout(location=0) out vec4 color;\n"
12637 "void main(){\n"
12638 " color = vec4(1);\n"
12639 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012640
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012641 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12642 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012643
12644 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012645 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012646 pipe.AddShader(&vs);
12647 pipe.AddShader(&fs);
12648
Chris Forbes62e8e502015-05-25 11:13:29 +120012649 VkDescriptorSetObj descriptorSet(m_device);
12650 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012651 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012652
Tony Barbour5781e8f2015-08-04 16:23:11 -060012653 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012654
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012655 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012656}
12657
Karl Schultz6addd812016-02-02 17:17:23 -070012658TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012659 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12660 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012661 "vertex shader input that consumes it");
12662 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 -060012663
Chris Forbesc97d98e2015-05-25 11:13:31 +120012664 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012666
12667 VkVertexInputBindingDescription input_binding;
12668 memset(&input_binding, 0, sizeof(input_binding));
12669
12670 VkVertexInputAttributeDescription input_attrib;
12671 memset(&input_attrib, 0, sizeof(input_attrib));
12672 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12673
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012674 char const *vsSource = "#version 450\n"
12675 "\n"
12676 "layout(location=0) in int x;\n" /* attrib provided float */
12677 "out gl_PerVertex {\n"
12678 " vec4 gl_Position;\n"
12679 "};\n"
12680 "void main(){\n"
12681 " gl_Position = vec4(x);\n"
12682 "}\n";
12683 char const *fsSource = "#version 450\n"
12684 "\n"
12685 "layout(location=0) out vec4 color;\n"
12686 "void main(){\n"
12687 " color = vec4(1);\n"
12688 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012689
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012690 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12691 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012692
12693 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012694 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012695 pipe.AddShader(&vs);
12696 pipe.AddShader(&fs);
12697
12698 pipe.AddVertexInputBindings(&input_binding, 1);
12699 pipe.AddVertexInputAttribs(&input_attrib, 1);
12700
Chris Forbesc97d98e2015-05-25 11:13:31 +120012701 VkDescriptorSetObj descriptorSet(m_device);
12702 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012703 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012704
Tony Barbour5781e8f2015-08-04 16:23:11 -060012705 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012706
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012707 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012708}
12709
Chris Forbesc68b43c2016-04-06 11:18:47 +120012710TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012711 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12712 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12714 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012715
12716 ASSERT_NO_FATAL_FAILURE(InitState());
12717 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12718
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012719 char const *vsSource = "#version 450\n"
12720 "\n"
12721 "out gl_PerVertex {\n"
12722 " vec4 gl_Position;\n"
12723 "};\n"
12724 "void main(){\n"
12725 " gl_Position = vec4(1);\n"
12726 "}\n";
12727 char const *fsSource = "#version 450\n"
12728 "\n"
12729 "layout(location=0) out vec4 color;\n"
12730 "void main(){\n"
12731 " color = vec4(1);\n"
12732 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012733
12734 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12735 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12736
12737 VkPipelineObj pipe(m_device);
12738 pipe.AddColorAttachment();
12739 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012740 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012741 pipe.AddShader(&fs);
12742
12743 VkDescriptorSetObj descriptorSet(m_device);
12744 descriptorSet.AppendDummy();
12745 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12746
12747 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12748
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012749 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012750}
12751
Chris Forbes82ff92a2016-09-09 10:50:24 +120012752TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12754 "No entrypoint found named `foo`");
12755
12756 ASSERT_NO_FATAL_FAILURE(InitState());
12757 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12758
12759 char const *vsSource = "#version 450\n"
12760 "out gl_PerVertex {\n"
12761 " vec4 gl_Position;\n"
12762 "};\n"
12763 "void main(){\n"
12764 " gl_Position = vec4(0);\n"
12765 "}\n";
12766 char const *fsSource = "#version 450\n"
12767 "\n"
12768 "layout(location=0) out vec4 color;\n"
12769 "void main(){\n"
12770 " color = vec4(1);\n"
12771 "}\n";
12772
12773 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12774 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12775
12776 VkPipelineObj pipe(m_device);
12777 pipe.AddColorAttachment();
12778 pipe.AddShader(&vs);
12779 pipe.AddShader(&fs);
12780
12781 VkDescriptorSetObj descriptorSet(m_device);
12782 descriptorSet.AppendDummy();
12783 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12784
12785 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12786
12787 m_errorMonitor->VerifyFound();
12788}
12789
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012790TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12791 m_errorMonitor->SetDesiredFailureMsg(
12792 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12793 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12794 "uses a depth/stencil attachment");
12795
12796 ASSERT_NO_FATAL_FAILURE(InitState());
12797 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12798
12799 char const *vsSource = "#version 450\n"
12800 "void main(){ gl_Position = vec4(0); }\n";
12801 char const *fsSource = "#version 450\n"
12802 "\n"
12803 "layout(location=0) out vec4 color;\n"
12804 "void main(){\n"
12805 " color = vec4(1);\n"
12806 "}\n";
12807
12808 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12809 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12810
12811 VkPipelineObj pipe(m_device);
12812 pipe.AddColorAttachment();
12813 pipe.AddShader(&vs);
12814 pipe.AddShader(&fs);
12815
12816 VkDescriptorSetObj descriptorSet(m_device);
12817 descriptorSet.AppendDummy();
12818 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12819
12820 VkAttachmentDescription attachments[] = {
12821 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12822 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12823 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12824 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12825 },
12826 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12827 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12828 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12829 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12830 },
12831 };
12832 VkAttachmentReference refs[] = {
12833 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
12834 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
12835 };
12836 VkSubpassDescription subpass = {
12837 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
12838 1, &refs[0], nullptr, &refs[1],
12839 0, nullptr
12840 };
12841 VkRenderPassCreateInfo rpci = {
12842 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
12843 0, 2, attachments, 1, &subpass, 0, nullptr
12844 };
12845 VkRenderPass rp;
12846 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12847 ASSERT_VK_SUCCESS(err);
12848
12849 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
12850
12851 m_errorMonitor->VerifyFound();
12852
12853 vkDestroyRenderPass(m_device->device(), rp, nullptr);
12854}
12855
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012856TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012857 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
12858 "the TCS without the patch decoration, but consumed in the TES "
12859 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
12861 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120012862
12863 ASSERT_NO_FATAL_FAILURE(InitState());
12864 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12865
Chris Forbesc1e852d2016-04-04 19:26:42 +120012866 if (!m_device->phy().features().tessellationShader) {
12867 printf("Device does not support tessellation shaders; skipped.\n");
12868 return;
12869 }
12870
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012871 char const *vsSource = "#version 450\n"
12872 "void main(){}\n";
12873 char const *tcsSource = "#version 450\n"
12874 "layout(location=0) out int x[];\n"
12875 "layout(vertices=3) out;\n"
12876 "void main(){\n"
12877 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
12878 " gl_TessLevelInner[0] = 1;\n"
12879 " x[gl_InvocationID] = gl_InvocationID;\n"
12880 "}\n";
12881 char const *tesSource = "#version 450\n"
12882 "layout(triangles, equal_spacing, cw) in;\n"
12883 "layout(location=0) patch in int x;\n"
12884 "out gl_PerVertex { vec4 gl_Position; };\n"
12885 "void main(){\n"
12886 " gl_Position.xyz = gl_TessCoord;\n"
12887 " gl_Position.w = x;\n"
12888 "}\n";
12889 char const *fsSource = "#version 450\n"
12890 "layout(location=0) out vec4 color;\n"
12891 "void main(){\n"
12892 " color = vec4(1);\n"
12893 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120012894
12895 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12896 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
12897 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
12898 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12899
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012900 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
12901 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012902
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012903 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012904
12905 VkPipelineObj pipe(m_device);
12906 pipe.SetInputAssembly(&iasci);
12907 pipe.SetTessellation(&tsci);
12908 pipe.AddColorAttachment();
12909 pipe.AddShader(&vs);
12910 pipe.AddShader(&tcs);
12911 pipe.AddShader(&tes);
12912 pipe.AddShader(&fs);
12913
12914 VkDescriptorSetObj descriptorSet(m_device);
12915 descriptorSet.AppendDummy();
12916 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12917
12918 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12919
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012920 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120012921}
12922
Karl Schultz6addd812016-02-02 17:17:23 -070012923TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012924 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
12925 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12927 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012928
Chris Forbes280ba2c2015-06-12 11:16:41 +120012929 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012930 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012931
12932 /* Two binding descriptions for binding 0 */
12933 VkVertexInputBindingDescription input_bindings[2];
12934 memset(input_bindings, 0, sizeof(input_bindings));
12935
12936 VkVertexInputAttributeDescription input_attrib;
12937 memset(&input_attrib, 0, sizeof(input_attrib));
12938 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12939
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012940 char const *vsSource = "#version 450\n"
12941 "\n"
12942 "layout(location=0) in float x;\n" /* attrib provided float */
12943 "out gl_PerVertex {\n"
12944 " vec4 gl_Position;\n"
12945 "};\n"
12946 "void main(){\n"
12947 " gl_Position = vec4(x);\n"
12948 "}\n";
12949 char const *fsSource = "#version 450\n"
12950 "\n"
12951 "layout(location=0) out vec4 color;\n"
12952 "void main(){\n"
12953 " color = vec4(1);\n"
12954 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120012955
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012956 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12957 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012958
12959 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012960 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012961 pipe.AddShader(&vs);
12962 pipe.AddShader(&fs);
12963
12964 pipe.AddVertexInputBindings(input_bindings, 2);
12965 pipe.AddVertexInputAttribs(&input_attrib, 1);
12966
Chris Forbes280ba2c2015-06-12 11:16:41 +120012967 VkDescriptorSetObj descriptorSet(m_device);
12968 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012969 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012970
Tony Barbour5781e8f2015-08-04 16:23:11 -060012971 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012972
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012973 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012974}
Chris Forbes8f68b562015-05-25 11:13:32 +120012975
Karl Schultz6addd812016-02-02 17:17:23 -070012976TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012977 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012978 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012980
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012981 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012982
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012983 char const *vsSource = "#version 450\n"
12984 "\n"
12985 "out gl_PerVertex {\n"
12986 " vec4 gl_Position;\n"
12987 "};\n"
12988 "void main(){\n"
12989 " gl_Position = vec4(1);\n"
12990 "}\n";
12991 char const *fsSource = "#version 450\n"
12992 "\n"
12993 "void main(){\n"
12994 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012995
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012996 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12997 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012998
12999 VkPipelineObj pipe(m_device);
13000 pipe.AddShader(&vs);
13001 pipe.AddShader(&fs);
13002
Chia-I Wu08accc62015-07-07 11:50:03 +080013003 /* set up CB 0, not written */
13004 pipe.AddColorAttachment();
13005 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013006
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013007 VkDescriptorSetObj descriptorSet(m_device);
13008 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013009 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013010
Tony Barbour5781e8f2015-08-04 16:23:11 -060013011 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013012
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013013 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013014}
13015
Karl Schultz6addd812016-02-02 17:17:23 -070013016TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013017 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013018 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013020 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013021
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013022 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013023
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013024 char const *vsSource = "#version 450\n"
13025 "\n"
13026 "out gl_PerVertex {\n"
13027 " vec4 gl_Position;\n"
13028 "};\n"
13029 "void main(){\n"
13030 " gl_Position = vec4(1);\n"
13031 "}\n";
13032 char const *fsSource = "#version 450\n"
13033 "\n"
13034 "layout(location=0) out vec4 x;\n"
13035 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13036 "void main(){\n"
13037 " x = vec4(1);\n"
13038 " y = vec4(1);\n"
13039 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013040
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013041 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13042 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013043
13044 VkPipelineObj pipe(m_device);
13045 pipe.AddShader(&vs);
13046 pipe.AddShader(&fs);
13047
Chia-I Wu08accc62015-07-07 11:50:03 +080013048 /* set up CB 0, not written */
13049 pipe.AddColorAttachment();
13050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013051 /* FS writes CB 1, but we don't configure it */
13052
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013053 VkDescriptorSetObj descriptorSet(m_device);
13054 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013055 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013056
Tony Barbour5781e8f2015-08-04 16:23:11 -060013057 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013058
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013059 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013060}
13061
Karl Schultz6addd812016-02-02 17:17:23 -070013062TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013063 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013064 "type of an fragment shader output variable, and the format of the corresponding attachment");
13065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013066
Chris Forbesa36d69e2015-05-25 11:13:44 +120013067 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013068
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013069 char const *vsSource = "#version 450\n"
13070 "\n"
13071 "out gl_PerVertex {\n"
13072 " vec4 gl_Position;\n"
13073 "};\n"
13074 "void main(){\n"
13075 " gl_Position = vec4(1);\n"
13076 "}\n";
13077 char const *fsSource = "#version 450\n"
13078 "\n"
13079 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13080 "void main(){\n"
13081 " x = ivec4(1);\n"
13082 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013083
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013084 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13085 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013086
13087 VkPipelineObj pipe(m_device);
13088 pipe.AddShader(&vs);
13089 pipe.AddShader(&fs);
13090
Chia-I Wu08accc62015-07-07 11:50:03 +080013091 /* set up CB 0; type is UNORM by default */
13092 pipe.AddColorAttachment();
13093 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013094
Chris Forbesa36d69e2015-05-25 11:13:44 +120013095 VkDescriptorSetObj descriptorSet(m_device);
13096 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013097 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013098
Tony Barbour5781e8f2015-08-04 16:23:11 -060013099 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013100
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013101 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013102}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013103
Karl Schultz6addd812016-02-02 17:17:23 -070013104TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013105 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13106 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013108
Chris Forbes556c76c2015-08-14 12:04:59 +120013109 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013110
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013111 char const *vsSource = "#version 450\n"
13112 "\n"
13113 "out gl_PerVertex {\n"
13114 " vec4 gl_Position;\n"
13115 "};\n"
13116 "void main(){\n"
13117 " gl_Position = vec4(1);\n"
13118 "}\n";
13119 char const *fsSource = "#version 450\n"
13120 "\n"
13121 "layout(location=0) out vec4 x;\n"
13122 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13123 "void main(){\n"
13124 " x = vec4(bar.y);\n"
13125 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013126
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013127 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13128 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013129
Chris Forbes556c76c2015-08-14 12:04:59 +120013130 VkPipelineObj pipe(m_device);
13131 pipe.AddShader(&vs);
13132 pipe.AddShader(&fs);
13133
13134 /* set up CB 0; type is UNORM by default */
13135 pipe.AddColorAttachment();
13136 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13137
13138 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013139 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013140
13141 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13142
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013143 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013144}
13145
Chris Forbes5c59e902016-02-26 16:56:09 +130013146TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013147 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13148 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013150
13151 ASSERT_NO_FATAL_FAILURE(InitState());
13152
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013153 char const *vsSource = "#version 450\n"
13154 "\n"
13155 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13156 "out gl_PerVertex {\n"
13157 " vec4 gl_Position;\n"
13158 "};\n"
13159 "void main(){\n"
13160 " gl_Position = vec4(consts.x);\n"
13161 "}\n";
13162 char const *fsSource = "#version 450\n"
13163 "\n"
13164 "layout(location=0) out vec4 x;\n"
13165 "void main(){\n"
13166 " x = vec4(1);\n"
13167 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013168
13169 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13170 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13171
13172 VkPipelineObj pipe(m_device);
13173 pipe.AddShader(&vs);
13174 pipe.AddShader(&fs);
13175
13176 /* set up CB 0; type is UNORM by default */
13177 pipe.AddColorAttachment();
13178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13179
13180 VkDescriptorSetObj descriptorSet(m_device);
13181 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13182
13183 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13184
13185 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013186 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013187}
13188
Chris Forbes3fb17902016-08-22 14:57:55 +120013189TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13190 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13191 "which is not included in the subpass description");
13192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13193 "consumes input attachment index 0 but not provided in subpass");
13194
13195 ASSERT_NO_FATAL_FAILURE(InitState());
13196
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013197 char const *vsSource = "#version 450\n"
13198 "\n"
13199 "out gl_PerVertex {\n"
13200 " vec4 gl_Position;\n"
13201 "};\n"
13202 "void main(){\n"
13203 " gl_Position = vec4(1);\n"
13204 "}\n";
13205 char const *fsSource = "#version 450\n"
13206 "\n"
13207 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13208 "layout(location=0) out vec4 color;\n"
13209 "void main() {\n"
13210 " color = subpassLoad(x);\n"
13211 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013212
13213 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13214 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13215
13216 VkPipelineObj pipe(m_device);
13217 pipe.AddShader(&vs);
13218 pipe.AddShader(&fs);
13219 pipe.AddColorAttachment();
13220 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13221
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013222 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13223 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013224 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013225 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013226 ASSERT_VK_SUCCESS(err);
13227
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013228 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013229 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013230 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013231 ASSERT_VK_SUCCESS(err);
13232
13233 // error here.
13234 pipe.CreateVKPipeline(pl, renderPass());
13235
13236 m_errorMonitor->VerifyFound();
13237
13238 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13239 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13240}
13241
Chris Forbes5a9a0472016-08-22 16:02:09 +120013242TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13243 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13244 "with a format having a different fundamental type");
13245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13246 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13247
13248 ASSERT_NO_FATAL_FAILURE(InitState());
13249
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013250 char const *vsSource = "#version 450\n"
13251 "\n"
13252 "out gl_PerVertex {\n"
13253 " vec4 gl_Position;\n"
13254 "};\n"
13255 "void main(){\n"
13256 " gl_Position = vec4(1);\n"
13257 "}\n";
13258 char const *fsSource = "#version 450\n"
13259 "\n"
13260 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13261 "layout(location=0) out vec4 color;\n"
13262 "void main() {\n"
13263 " color = subpassLoad(x);\n"
13264 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013265
13266 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13267 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13268
13269 VkPipelineObj pipe(m_device);
13270 pipe.AddShader(&vs);
13271 pipe.AddShader(&fs);
13272 pipe.AddColorAttachment();
13273 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13274
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013275 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13276 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013277 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013278 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013279 ASSERT_VK_SUCCESS(err);
13280
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013281 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013282 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013283 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013284 ASSERT_VK_SUCCESS(err);
13285
13286 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013287 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13288 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13289 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13290 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13291 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 +120013292 };
13293 VkAttachmentReference color = {
13294 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13295 };
13296 VkAttachmentReference input = {
13297 1, VK_IMAGE_LAYOUT_GENERAL,
13298 };
13299
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013300 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013301
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013302 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013303 VkRenderPass rp;
13304 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13305 ASSERT_VK_SUCCESS(err);
13306
13307 // error here.
13308 pipe.CreateVKPipeline(pl, rp);
13309
13310 m_errorMonitor->VerifyFound();
13311
13312 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13313 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13314 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13315}
13316
Chris Forbes541f7b02016-08-22 15:30:27 +120013317TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13318 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13319 "which is not included in the subpass description -- array case");
13320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13321 "consumes input attachment index 1 but not provided in subpass");
13322
13323 ASSERT_NO_FATAL_FAILURE(InitState());
13324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013325 char const *vsSource = "#version 450\n"
13326 "\n"
13327 "out gl_PerVertex {\n"
13328 " vec4 gl_Position;\n"
13329 "};\n"
13330 "void main(){\n"
13331 " gl_Position = vec4(1);\n"
13332 "}\n";
13333 char const *fsSource = "#version 450\n"
13334 "\n"
13335 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13336 "layout(location=0) out vec4 color;\n"
13337 "void main() {\n"
13338 " color = subpassLoad(xs[1]);\n"
13339 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013340
13341 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13342 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13343
13344 VkPipelineObj pipe(m_device);
13345 pipe.AddShader(&vs);
13346 pipe.AddShader(&fs);
13347 pipe.AddColorAttachment();
13348 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13349
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013350 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13351 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013352 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013353 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013354 ASSERT_VK_SUCCESS(err);
13355
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013356 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013357 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013358 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013359 ASSERT_VK_SUCCESS(err);
13360
13361 // error here.
13362 pipe.CreateVKPipeline(pl, renderPass());
13363
13364 m_errorMonitor->VerifyFound();
13365
13366 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13367 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13368}
13369
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013370TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013371 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13372 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013374
13375 ASSERT_NO_FATAL_FAILURE(InitState());
13376
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013377 char const *csSource = "#version 450\n"
13378 "\n"
13379 "layout(local_size_x=1) in;\n"
13380 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13381 "void main(){\n"
13382 " x = vec4(1);\n"
13383 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013384
13385 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13386
13387 VkDescriptorSetObj descriptorSet(m_device);
13388 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013390 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13391 nullptr,
13392 0,
13393 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13394 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13395 descriptorSet.GetPipelineLayout(),
13396 VK_NULL_HANDLE,
13397 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013398
13399 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013400 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013401
13402 m_errorMonitor->VerifyFound();
13403
13404 if (err == VK_SUCCESS) {
13405 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13406 }
13407}
13408
Chris Forbes22a9b092016-07-19 14:34:05 +120013409TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013410 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13411 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13413 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013414
13415 ASSERT_NO_FATAL_FAILURE(InitState());
13416
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013417 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13418 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013419 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013420 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013421 ASSERT_VK_SUCCESS(err);
13422
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013423 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013424 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013425 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013426 ASSERT_VK_SUCCESS(err);
13427
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013428 char const *csSource = "#version 450\n"
13429 "\n"
13430 "layout(local_size_x=1) in;\n"
13431 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13432 "void main() {\n"
13433 " x.x = 1.0f;\n"
13434 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013435 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13436
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013437 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13438 nullptr,
13439 0,
13440 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13441 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13442 pl,
13443 VK_NULL_HANDLE,
13444 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013445
13446 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013447 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013448
13449 m_errorMonitor->VerifyFound();
13450
13451 if (err == VK_SUCCESS) {
13452 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13453 }
13454
13455 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13456 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13457}
13458
Chris Forbes50020592016-07-27 13:52:41 +120013459TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13460 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13461 "does not match the dimensionality declared in the shader");
13462
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013463 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 +120013464
13465 ASSERT_NO_FATAL_FAILURE(InitState());
13466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13467
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013468 char const *vsSource = "#version 450\n"
13469 "\n"
13470 "out gl_PerVertex { vec4 gl_Position; };\n"
13471 "void main() { gl_Position = vec4(0); }\n";
13472 char const *fsSource = "#version 450\n"
13473 "\n"
13474 "layout(set=0, binding=0) uniform sampler3D s;\n"
13475 "layout(location=0) out vec4 color;\n"
13476 "void main() {\n"
13477 " color = texture(s, vec3(0));\n"
13478 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013479 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13480 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13481
13482 VkPipelineObj pipe(m_device);
13483 pipe.AddShader(&vs);
13484 pipe.AddShader(&fs);
13485 pipe.AddColorAttachment();
13486
13487 VkTextureObj texture(m_device, nullptr);
13488 VkSamplerObj sampler(m_device);
13489
13490 VkDescriptorSetObj descriptorSet(m_device);
13491 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13492 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13493
13494 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13495 ASSERT_VK_SUCCESS(err);
13496
13497 BeginCommandBuffer();
13498
13499 m_commandBuffer->BindPipeline(pipe);
13500 m_commandBuffer->BindDescriptorSet(descriptorSet);
13501
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013502 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013503 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013504 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013505 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13506
13507 // error produced here.
13508 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13509
13510 m_errorMonitor->VerifyFound();
13511
13512 EndCommandBuffer();
13513}
13514
Chris Forbes5533bfc2016-07-27 14:12:34 +120013515TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13516 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13517 "are consumed via singlesample images types in the shader, or vice versa.");
13518
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013520
13521 ASSERT_NO_FATAL_FAILURE(InitState());
13522 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13523
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013524 char const *vsSource = "#version 450\n"
13525 "\n"
13526 "out gl_PerVertex { vec4 gl_Position; };\n"
13527 "void main() { gl_Position = vec4(0); }\n";
13528 char const *fsSource = "#version 450\n"
13529 "\n"
13530 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13531 "layout(location=0) out vec4 color;\n"
13532 "void main() {\n"
13533 " color = texelFetch(s, ivec2(0), 0);\n"
13534 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013535 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13536 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13537
13538 VkPipelineObj pipe(m_device);
13539 pipe.AddShader(&vs);
13540 pipe.AddShader(&fs);
13541 pipe.AddColorAttachment();
13542
13543 VkTextureObj texture(m_device, nullptr);
13544 VkSamplerObj sampler(m_device);
13545
13546 VkDescriptorSetObj descriptorSet(m_device);
13547 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13548 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13549
13550 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13551 ASSERT_VK_SUCCESS(err);
13552
13553 BeginCommandBuffer();
13554
13555 m_commandBuffer->BindPipeline(pipe);
13556 m_commandBuffer->BindDescriptorSet(descriptorSet);
13557
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013558 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013559 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013560 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013561 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13562
13563 // error produced here.
13564 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13565
13566 m_errorMonitor->VerifyFound();
13567
13568 EndCommandBuffer();
13569}
13570
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013571#endif // SHADER_CHECKER_TESTS
13572
13573#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013574TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013576
13577 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013578
13579 // Create an image
13580 VkImage image;
13581
Karl Schultz6addd812016-02-02 17:17:23 -070013582 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13583 const int32_t tex_width = 32;
13584 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013585
13586 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013587 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13588 image_create_info.pNext = NULL;
13589 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13590 image_create_info.format = tex_format;
13591 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013592 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013593 image_create_info.extent.depth = 1;
13594 image_create_info.mipLevels = 1;
13595 image_create_info.arrayLayers = 1;
13596 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13597 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13598 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13599 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013600
13601 // Introduce error by sending down a bogus width extent
13602 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013603 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013604
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013605 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013606}
13607
Mark Youngc48c4c12016-04-11 14:26:49 -060013608TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13610 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013611
13612 ASSERT_NO_FATAL_FAILURE(InitState());
13613
13614 // Create an image
13615 VkImage image;
13616
13617 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13618 const int32_t tex_width = 32;
13619 const int32_t tex_height = 32;
13620
13621 VkImageCreateInfo image_create_info = {};
13622 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13623 image_create_info.pNext = NULL;
13624 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13625 image_create_info.format = tex_format;
13626 image_create_info.extent.width = tex_width;
13627 image_create_info.extent.height = tex_height;
13628 image_create_info.extent.depth = 1;
13629 image_create_info.mipLevels = 1;
13630 image_create_info.arrayLayers = 1;
13631 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13632 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13633 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13634 image_create_info.flags = 0;
13635
13636 // Introduce error by sending down a bogus width extent
13637 image_create_info.extent.width = 0;
13638 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13639
13640 m_errorMonitor->VerifyFound();
13641}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013642#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013643
Tobin Ehliscde08892015-09-22 10:11:37 -060013644#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070013645
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013646TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13647 TEST_DESCRIPTION("Create a render pass with an attachment description "
13648 "format set to VK_FORMAT_UNDEFINED");
13649
13650 ASSERT_NO_FATAL_FAILURE(InitState());
13651 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13652
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013654
13655 VkAttachmentReference color_attach = {};
13656 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13657 color_attach.attachment = 0;
13658 VkSubpassDescription subpass = {};
13659 subpass.colorAttachmentCount = 1;
13660 subpass.pColorAttachments = &color_attach;
13661
13662 VkRenderPassCreateInfo rpci = {};
13663 rpci.subpassCount = 1;
13664 rpci.pSubpasses = &subpass;
13665 rpci.attachmentCount = 1;
13666 VkAttachmentDescription attach_desc = {};
13667 attach_desc.format = VK_FORMAT_UNDEFINED;
13668 rpci.pAttachments = &attach_desc;
13669 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13670 VkRenderPass rp;
13671 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13672
13673 m_errorMonitor->VerifyFound();
13674
13675 if (result == VK_SUCCESS) {
13676 vkDestroyRenderPass(m_device->device(), rp, NULL);
13677 }
13678}
13679
Karl Schultz6addd812016-02-02 17:17:23 -070013680TEST_F(VkLayerTest, InvalidImageView) {
13681 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013682
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013684
Tobin Ehliscde08892015-09-22 10:11:37 -060013685 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013686
Mike Stroyana3082432015-09-25 13:39:21 -060013687 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013688 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013689
Karl Schultz6addd812016-02-02 17:17:23 -070013690 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13691 const int32_t tex_width = 32;
13692 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013693
13694 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013695 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13696 image_create_info.pNext = NULL;
13697 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13698 image_create_info.format = tex_format;
13699 image_create_info.extent.width = tex_width;
13700 image_create_info.extent.height = tex_height;
13701 image_create_info.extent.depth = 1;
13702 image_create_info.mipLevels = 1;
13703 image_create_info.arrayLayers = 1;
13704 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13705 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13706 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13707 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013708
Chia-I Wuf7458c52015-10-26 21:10:41 +080013709 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013710 ASSERT_VK_SUCCESS(err);
13711
13712 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013713 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13714 image_view_create_info.image = image;
13715 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13716 image_view_create_info.format = tex_format;
13717 image_view_create_info.subresourceRange.layerCount = 1;
13718 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13719 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013720 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013721
13722 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013723 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013724
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013725 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013726 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013727}
Mike Stroyana3082432015-09-25 13:39:21 -060013728
Mark Youngd339ba32016-05-30 13:28:35 -060013729TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13730 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013732 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013733
13734 ASSERT_NO_FATAL_FAILURE(InitState());
13735
13736 // Create an image and try to create a view with no memory backing the image
13737 VkImage image;
13738
13739 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13740 const int32_t tex_width = 32;
13741 const int32_t tex_height = 32;
13742
13743 VkImageCreateInfo image_create_info = {};
13744 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13745 image_create_info.pNext = NULL;
13746 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13747 image_create_info.format = tex_format;
13748 image_create_info.extent.width = tex_width;
13749 image_create_info.extent.height = tex_height;
13750 image_create_info.extent.depth = 1;
13751 image_create_info.mipLevels = 1;
13752 image_create_info.arrayLayers = 1;
13753 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13754 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13755 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13756 image_create_info.flags = 0;
13757
13758 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13759 ASSERT_VK_SUCCESS(err);
13760
13761 VkImageViewCreateInfo image_view_create_info = {};
13762 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13763 image_view_create_info.image = image;
13764 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13765 image_view_create_info.format = tex_format;
13766 image_view_create_info.subresourceRange.layerCount = 1;
13767 image_view_create_info.subresourceRange.baseMipLevel = 0;
13768 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013769 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013770
13771 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013772 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013773
13774 m_errorMonitor->VerifyFound();
13775 vkDestroyImage(m_device->device(), image, NULL);
13776 // If last error is success, it still created the view, so delete it.
13777 if (err == VK_SUCCESS) {
13778 vkDestroyImageView(m_device->device(), view, NULL);
13779 }
Mark Youngd339ba32016-05-30 13:28:35 -060013780}
13781
Karl Schultz6addd812016-02-02 17:17:23 -070013782TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013783 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013785 "formats must have ONLY the "
13786 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13788 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013789
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013790 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013791
Karl Schultz6addd812016-02-02 17:17:23 -070013792 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013793 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013794 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013795 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013796
13797 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013798 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013799 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013800 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13801 image_view_create_info.format = tex_format;
13802 image_view_create_info.subresourceRange.baseMipLevel = 0;
13803 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013804 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013805 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013806 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013807
13808 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013809 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013810
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013811 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013812}
13813
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013814TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013815 VkResult err;
13816 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013817
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13819 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013820
Mike Stroyana3082432015-09-25 13:39:21 -060013821 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013822
13823 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013824 VkImage srcImage;
13825 VkImage dstImage;
13826 VkDeviceMemory srcMem;
13827 VkDeviceMemory destMem;
13828 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013829
13830 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013831 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13832 image_create_info.pNext = NULL;
13833 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13834 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13835 image_create_info.extent.width = 32;
13836 image_create_info.extent.height = 32;
13837 image_create_info.extent.depth = 1;
13838 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013839 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070013840 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13841 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13842 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13843 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013844
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013845 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013846 ASSERT_VK_SUCCESS(err);
13847
Mark Lobodzinski867787a2016-10-14 11:49:55 -060013848 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013849 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013850 ASSERT_VK_SUCCESS(err);
13851
13852 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013853 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013854 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13855 memAlloc.pNext = NULL;
13856 memAlloc.allocationSize = 0;
13857 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013858
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060013859 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013860 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013861 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060013862 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013863 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013864 ASSERT_VK_SUCCESS(err);
13865
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013866 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013867 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013868 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013869 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013870 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013871 ASSERT_VK_SUCCESS(err);
13872
13873 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
13874 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013875 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013876 ASSERT_VK_SUCCESS(err);
13877
13878 BeginCommandBuffer();
13879 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013880 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060013881 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060013882 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013883 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060013884 copyRegion.srcOffset.x = 0;
13885 copyRegion.srcOffset.y = 0;
13886 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013887 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013888 copyRegion.dstSubresource.mipLevel = 0;
13889 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013890 // Introduce failure by forcing the dst layerCount to differ from src
13891 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013892 copyRegion.dstOffset.x = 0;
13893 copyRegion.dstOffset.y = 0;
13894 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013895 copyRegion.extent.width = 1;
13896 copyRegion.extent.height = 1;
13897 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013898 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060013899 EndCommandBuffer();
13900
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013901 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060013902
Chia-I Wuf7458c52015-10-26 21:10:41 +080013903 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013904 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080013905 vkFreeMemory(m_device->device(), srcMem, NULL);
13906 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060013907}
13908
Tony Barbourd6673642016-05-05 14:46:39 -060013909TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
13910
13911 TEST_DESCRIPTION("Creating images with unsuported formats ");
13912
13913 ASSERT_NO_FATAL_FAILURE(InitState());
13914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13915 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013916 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 -060013917 VK_IMAGE_TILING_OPTIMAL, 0);
13918 ASSERT_TRUE(image.initialized());
13919
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013920 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
13921 VkImageCreateInfo image_create_info;
13922 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13923 image_create_info.pNext = NULL;
13924 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13925 image_create_info.format = VK_FORMAT_UNDEFINED;
13926 image_create_info.extent.width = 32;
13927 image_create_info.extent.height = 32;
13928 image_create_info.extent.depth = 1;
13929 image_create_info.mipLevels = 1;
13930 image_create_info.arrayLayers = 1;
13931 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13932 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13933 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13934 image_create_info.flags = 0;
13935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13937 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013938
13939 VkImage localImage;
13940 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
13941 m_errorMonitor->VerifyFound();
13942
Tony Barbourd6673642016-05-05 14:46:39 -060013943 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013944 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060013945 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
13946 VkFormat format = static_cast<VkFormat>(f);
13947 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013948 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060013949 unsupported = format;
13950 break;
13951 }
13952 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013953
Tony Barbourd6673642016-05-05 14:46:39 -060013954 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060013955 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060013957
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013958 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060013959 m_errorMonitor->VerifyFound();
13960 }
13961}
13962
13963TEST_F(VkLayerTest, ImageLayerViewTests) {
13964 VkResult ret;
13965 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
13966
13967 ASSERT_NO_FATAL_FAILURE(InitState());
13968
13969 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013970 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 -060013971 VK_IMAGE_TILING_OPTIMAL, 0);
13972 ASSERT_TRUE(image.initialized());
13973
13974 VkImageView imgView;
13975 VkImageViewCreateInfo imgViewInfo = {};
13976 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13977 imgViewInfo.image = image.handle();
13978 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
13979 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13980 imgViewInfo.subresourceRange.layerCount = 1;
13981 imgViewInfo.subresourceRange.baseMipLevel = 0;
13982 imgViewInfo.subresourceRange.levelCount = 1;
13983 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060013986 // View can't have baseMipLevel >= image's mipLevels - Expect
13987 // VIEW_CREATE_ERROR
13988 imgViewInfo.subresourceRange.baseMipLevel = 1;
13989 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13990 m_errorMonitor->VerifyFound();
13991 imgViewInfo.subresourceRange.baseMipLevel = 0;
13992
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060013994 // View can't have baseArrayLayer >= image's arraySize - Expect
13995 // VIEW_CREATE_ERROR
13996 imgViewInfo.subresourceRange.baseArrayLayer = 1;
13997 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13998 m_errorMonitor->VerifyFound();
13999 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14000
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14002 "pCreateInfo->subresourceRange."
14003 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014004 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14005 imgViewInfo.subresourceRange.levelCount = 0;
14006 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14007 m_errorMonitor->VerifyFound();
14008 imgViewInfo.subresourceRange.levelCount = 1;
14009
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14011 "pCreateInfo->subresourceRange."
14012 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014013 m_errorMonitor->SetDesiredFailureMsg(
14014 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14015 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014016 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14017 imgViewInfo.subresourceRange.layerCount = 0;
14018 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14019 m_errorMonitor->VerifyFound();
14020 imgViewInfo.subresourceRange.layerCount = 1;
14021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14024 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14025 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014026 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14027 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14028 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14029 m_errorMonitor->VerifyFound();
14030 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14033 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14034 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014035 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14036 // VIEW_CREATE_ERROR
14037 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14038 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14039 m_errorMonitor->VerifyFound();
14040 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14041
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14043 "differing formats but they must be "
14044 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014045 // TODO: Update framework to easily passing mutable flag into ImageObj init
14046 // For now just allowing image for this one test to not have memory bound
14047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14048 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014049 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14050 // VIEW_CREATE_ERROR
14051 VkImageCreateInfo mutImgInfo = image.create_info();
14052 VkImage mutImage;
14053 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014054 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014055 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14056 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14057 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14058 ASSERT_VK_SUCCESS(ret);
14059 imgViewInfo.image = mutImage;
14060 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14061 m_errorMonitor->VerifyFound();
14062 imgViewInfo.image = image.handle();
14063 vkDestroyImage(m_device->handle(), mutImage, NULL);
14064}
14065
14066TEST_F(VkLayerTest, MiscImageLayerTests) {
14067
14068 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14069
14070 ASSERT_NO_FATAL_FAILURE(InitState());
14071
14072 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014073 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 -060014074 VK_IMAGE_TILING_OPTIMAL, 0);
14075 ASSERT_TRUE(image.initialized());
14076
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060014078 vk_testing::Buffer buffer;
14079 VkMemoryPropertyFlags reqs = 0;
14080 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14081 VkBufferImageCopy region = {};
14082 region.bufferRowLength = 128;
14083 region.bufferImageHeight = 128;
14084 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14085 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
14086 region.imageSubresource.layerCount = 0;
14087 region.imageExtent.height = 4;
14088 region.imageExtent.width = 4;
14089 region.imageExtent.depth = 1;
14090 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014091 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14092 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014093 m_errorMonitor->VerifyFound();
14094 region.imageSubresource.layerCount = 1;
14095
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014096 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14097 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14098 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
14100 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14101 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014102 m_errorMonitor->VerifyFound();
14103
14104 // BufferOffset must be a multiple of 4
14105 // Introduce failure by setting bufferOffset to a value not divisible by 4
14106 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
14108 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14109 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014110 m_errorMonitor->VerifyFound();
14111
14112 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14113 region.bufferOffset = 0;
14114 region.imageExtent.height = 128;
14115 region.imageExtent.width = 128;
14116 // Introduce failure by setting bufferRowLength > 0 but less than width
14117 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14119 "must be zero or greater-than-or-equal-to imageExtent.width");
14120 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14121 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014122 m_errorMonitor->VerifyFound();
14123
14124 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14125 region.bufferRowLength = 128;
14126 // Introduce failure by setting bufferRowHeight > 0 but less than height
14127 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14129 "must be zero or greater-than-or-equal-to imageExtent.height");
14130 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14131 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014132 m_errorMonitor->VerifyFound();
14133
14134 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
14136 "specify only COLOR or DEPTH or "
14137 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060014138 // Expect MISMATCHED_IMAGE_ASPECT
14139 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014140 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14141 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014142 m_errorMonitor->VerifyFound();
14143 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14144
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14146 "If the format of srcImage is a depth, stencil, depth stencil or "
14147 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014148 // Expect INVALID_FILTER
14149 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014150 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 -060014151 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014152 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 -060014153 VkImageBlit blitRegion = {};
14154 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14155 blitRegion.srcSubresource.baseArrayLayer = 0;
14156 blitRegion.srcSubresource.layerCount = 1;
14157 blitRegion.srcSubresource.mipLevel = 0;
14158 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14159 blitRegion.dstSubresource.baseArrayLayer = 0;
14160 blitRegion.dstSubresource.layerCount = 1;
14161 blitRegion.dstSubresource.mipLevel = 0;
14162
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014163 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14164 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014165 m_errorMonitor->VerifyFound();
14166
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014167 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14169 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14170 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014171 m_errorMonitor->VerifyFound();
14172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014174 VkImageMemoryBarrier img_barrier;
14175 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14176 img_barrier.pNext = NULL;
14177 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14178 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14179 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14180 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14181 img_barrier.image = image.handle();
14182 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14183 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14184 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14185 img_barrier.subresourceRange.baseArrayLayer = 0;
14186 img_barrier.subresourceRange.baseMipLevel = 0;
14187 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14188 img_barrier.subresourceRange.layerCount = 0;
14189 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014190 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14191 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014192 m_errorMonitor->VerifyFound();
14193 img_barrier.subresourceRange.layerCount = 1;
14194}
14195
14196TEST_F(VkLayerTest, ImageFormatLimits) {
14197
14198 TEST_DESCRIPTION("Exceed the limits of image format ");
14199
Cody Northropc31a84f2016-08-22 10:41:47 -060014200 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014202 VkImageCreateInfo image_create_info = {};
14203 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14204 image_create_info.pNext = NULL;
14205 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14206 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14207 image_create_info.extent.width = 32;
14208 image_create_info.extent.height = 32;
14209 image_create_info.extent.depth = 1;
14210 image_create_info.mipLevels = 1;
14211 image_create_info.arrayLayers = 1;
14212 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14213 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14214 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14215 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14216 image_create_info.flags = 0;
14217
14218 VkImage nullImg;
14219 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014220 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14221 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014222 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14223 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14224 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14225 m_errorMonitor->VerifyFound();
14226 image_create_info.extent.depth = 1;
14227
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014229 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14230 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14231 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14232 m_errorMonitor->VerifyFound();
14233 image_create_info.mipLevels = 1;
14234
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014236 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14237 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14238 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14239 m_errorMonitor->VerifyFound();
14240 image_create_info.arrayLayers = 1;
14241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014243 int samples = imgFmtProps.sampleCounts >> 1;
14244 image_create_info.samples = (VkSampleCountFlagBits)samples;
14245 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14246 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14247 m_errorMonitor->VerifyFound();
14248 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14249
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14251 "VK_IMAGE_LAYOUT_UNDEFINED or "
14252 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014253 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14254 // Expect INVALID_LAYOUT
14255 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14256 m_errorMonitor->VerifyFound();
14257 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14258}
14259
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014260TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14261
14262 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014264
14265 ASSERT_NO_FATAL_FAILURE(InitState());
14266
14267 VkImageObj src_image(m_device);
14268 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14269 VkImageObj dst_image(m_device);
14270 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14271
14272 BeginCommandBuffer();
14273 VkImageCopy copy_region;
14274 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14275 copy_region.srcSubresource.mipLevel = 0;
14276 copy_region.srcSubresource.baseArrayLayer = 0;
14277 copy_region.srcSubresource.layerCount = 0;
14278 copy_region.srcOffset.x = 0;
14279 copy_region.srcOffset.y = 0;
14280 copy_region.srcOffset.z = 0;
14281 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14282 copy_region.dstSubresource.mipLevel = 0;
14283 copy_region.dstSubresource.baseArrayLayer = 0;
14284 copy_region.dstSubresource.layerCount = 0;
14285 copy_region.dstOffset.x = 0;
14286 copy_region.dstOffset.y = 0;
14287 copy_region.dstOffset.z = 0;
14288 copy_region.extent.width = 64;
14289 copy_region.extent.height = 64;
14290 copy_region.extent.depth = 1;
14291 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14292 &copy_region);
14293 EndCommandBuffer();
14294
14295 m_errorMonitor->VerifyFound();
14296}
14297
14298TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14299
14300 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014302
14303 ASSERT_NO_FATAL_FAILURE(InitState());
14304
14305 VkImageObj src_image(m_device);
14306 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14307 VkImageObj dst_image(m_device);
14308 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14309
14310 BeginCommandBuffer();
14311 VkImageCopy copy_region;
14312 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14313 copy_region.srcSubresource.mipLevel = 0;
14314 copy_region.srcSubresource.baseArrayLayer = 0;
14315 copy_region.srcSubresource.layerCount = 0;
14316 copy_region.srcOffset.x = 0;
14317 copy_region.srcOffset.y = 0;
14318 copy_region.srcOffset.z = 0;
14319 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14320 copy_region.dstSubresource.mipLevel = 0;
14321 copy_region.dstSubresource.baseArrayLayer = 0;
14322 copy_region.dstSubresource.layerCount = 0;
14323 copy_region.dstOffset.x = 0;
14324 copy_region.dstOffset.y = 0;
14325 copy_region.dstOffset.z = 0;
14326 copy_region.extent.width = 64;
14327 copy_region.extent.height = 64;
14328 copy_region.extent.depth = 1;
14329 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14330 &copy_region);
14331 EndCommandBuffer();
14332
14333 m_errorMonitor->VerifyFound();
14334}
14335
Karl Schultz6addd812016-02-02 17:17:23 -070014336TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014337 VkResult err;
14338 bool pass;
14339
14340 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14342 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014343
14344 ASSERT_NO_FATAL_FAILURE(InitState());
14345
14346 // Create two images of different types and try to copy between them
14347 VkImage srcImage;
14348 VkImage dstImage;
14349 VkDeviceMemory srcMem;
14350 VkDeviceMemory destMem;
14351 VkMemoryRequirements memReqs;
14352
14353 VkImageCreateInfo image_create_info = {};
14354 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14355 image_create_info.pNext = NULL;
14356 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14357 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14358 image_create_info.extent.width = 32;
14359 image_create_info.extent.height = 32;
14360 image_create_info.extent.depth = 1;
14361 image_create_info.mipLevels = 1;
14362 image_create_info.arrayLayers = 1;
14363 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14364 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14365 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14366 image_create_info.flags = 0;
14367
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014368 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014369 ASSERT_VK_SUCCESS(err);
14370
14371 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14372 // Introduce failure by creating second image with a different-sized format.
14373 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14374
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014375 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014376 ASSERT_VK_SUCCESS(err);
14377
14378 // Allocate memory
14379 VkMemoryAllocateInfo memAlloc = {};
14380 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14381 memAlloc.pNext = NULL;
14382 memAlloc.allocationSize = 0;
14383 memAlloc.memoryTypeIndex = 0;
14384
14385 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14386 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014387 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014388 ASSERT_TRUE(pass);
14389 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14390 ASSERT_VK_SUCCESS(err);
14391
14392 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14393 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014394 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014395 ASSERT_TRUE(pass);
14396 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14397 ASSERT_VK_SUCCESS(err);
14398
14399 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14400 ASSERT_VK_SUCCESS(err);
14401 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14402 ASSERT_VK_SUCCESS(err);
14403
14404 BeginCommandBuffer();
14405 VkImageCopy copyRegion;
14406 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14407 copyRegion.srcSubresource.mipLevel = 0;
14408 copyRegion.srcSubresource.baseArrayLayer = 0;
14409 copyRegion.srcSubresource.layerCount = 0;
14410 copyRegion.srcOffset.x = 0;
14411 copyRegion.srcOffset.y = 0;
14412 copyRegion.srcOffset.z = 0;
14413 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14414 copyRegion.dstSubresource.mipLevel = 0;
14415 copyRegion.dstSubresource.baseArrayLayer = 0;
14416 copyRegion.dstSubresource.layerCount = 0;
14417 copyRegion.dstOffset.x = 0;
14418 copyRegion.dstOffset.y = 0;
14419 copyRegion.dstOffset.z = 0;
14420 copyRegion.extent.width = 1;
14421 copyRegion.extent.height = 1;
14422 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014423 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014424 EndCommandBuffer();
14425
14426 m_errorMonitor->VerifyFound();
14427
14428 vkDestroyImage(m_device->device(), srcImage, NULL);
14429 vkDestroyImage(m_device->device(), dstImage, NULL);
14430 vkFreeMemory(m_device->device(), srcMem, NULL);
14431 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014432}
14433
Karl Schultz6addd812016-02-02 17:17:23 -070014434TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14435 VkResult err;
14436 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014437
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014438 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14440 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014441
Mike Stroyana3082432015-09-25 13:39:21 -060014442 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014443
14444 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014445 VkImage srcImage;
14446 VkImage dstImage;
14447 VkDeviceMemory srcMem;
14448 VkDeviceMemory destMem;
14449 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014450
14451 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014452 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14453 image_create_info.pNext = NULL;
14454 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14455 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14456 image_create_info.extent.width = 32;
14457 image_create_info.extent.height = 32;
14458 image_create_info.extent.depth = 1;
14459 image_create_info.mipLevels = 1;
14460 image_create_info.arrayLayers = 1;
14461 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14462 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14463 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14464 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014465
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014466 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014467 ASSERT_VK_SUCCESS(err);
14468
Karl Schultzbdb75952016-04-19 11:36:49 -060014469 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14470
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014471 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014472 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014473 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014474 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014475
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014476 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014477 ASSERT_VK_SUCCESS(err);
14478
14479 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014480 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014481 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14482 memAlloc.pNext = NULL;
14483 memAlloc.allocationSize = 0;
14484 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014485
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014486 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014487 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014488 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014489 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014490 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014491 ASSERT_VK_SUCCESS(err);
14492
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014493 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014494 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014495 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014496 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014497 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014498 ASSERT_VK_SUCCESS(err);
14499
14500 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14501 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014502 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014503 ASSERT_VK_SUCCESS(err);
14504
14505 BeginCommandBuffer();
14506 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014507 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014508 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014509 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014510 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014511 copyRegion.srcOffset.x = 0;
14512 copyRegion.srcOffset.y = 0;
14513 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014514 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014515 copyRegion.dstSubresource.mipLevel = 0;
14516 copyRegion.dstSubresource.baseArrayLayer = 0;
14517 copyRegion.dstSubresource.layerCount = 0;
14518 copyRegion.dstOffset.x = 0;
14519 copyRegion.dstOffset.y = 0;
14520 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014521 copyRegion.extent.width = 1;
14522 copyRegion.extent.height = 1;
14523 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014524 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014525 EndCommandBuffer();
14526
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014527 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014528
Chia-I Wuf7458c52015-10-26 21:10:41 +080014529 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014530 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014531 vkFreeMemory(m_device->device(), srcMem, NULL);
14532 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014533}
14534
Karl Schultz6addd812016-02-02 17:17:23 -070014535TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14536 VkResult err;
14537 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014538
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14540 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014541
Mike Stroyana3082432015-09-25 13:39:21 -060014542 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014543
14544 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014545 VkImage srcImage;
14546 VkImage dstImage;
14547 VkDeviceMemory srcMem;
14548 VkDeviceMemory destMem;
14549 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014550
14551 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014552 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14553 image_create_info.pNext = NULL;
14554 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14555 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14556 image_create_info.extent.width = 32;
14557 image_create_info.extent.height = 1;
14558 image_create_info.extent.depth = 1;
14559 image_create_info.mipLevels = 1;
14560 image_create_info.arrayLayers = 1;
14561 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14562 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14563 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14564 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014565
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014566 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014567 ASSERT_VK_SUCCESS(err);
14568
Karl Schultz6addd812016-02-02 17:17:23 -070014569 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014570
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014571 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014572 ASSERT_VK_SUCCESS(err);
14573
14574 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014575 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014576 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14577 memAlloc.pNext = NULL;
14578 memAlloc.allocationSize = 0;
14579 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014580
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014581 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014582 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014583 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014584 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014585 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014586 ASSERT_VK_SUCCESS(err);
14587
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014588 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014589 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014590 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014591 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014592 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014593 ASSERT_VK_SUCCESS(err);
14594
14595 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14596 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014597 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014598 ASSERT_VK_SUCCESS(err);
14599
14600 BeginCommandBuffer();
14601 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014602 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14603 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014604 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014605 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014606 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014607 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014608 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014609 resolveRegion.srcOffset.x = 0;
14610 resolveRegion.srcOffset.y = 0;
14611 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014612 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014613 resolveRegion.dstSubresource.mipLevel = 0;
14614 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014615 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014616 resolveRegion.dstOffset.x = 0;
14617 resolveRegion.dstOffset.y = 0;
14618 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014619 resolveRegion.extent.width = 1;
14620 resolveRegion.extent.height = 1;
14621 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014622 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014623 EndCommandBuffer();
14624
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014625 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014626
Chia-I Wuf7458c52015-10-26 21:10:41 +080014627 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014628 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014629 vkFreeMemory(m_device->device(), srcMem, NULL);
14630 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014631}
14632
Karl Schultz6addd812016-02-02 17:17:23 -070014633TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14634 VkResult err;
14635 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014636
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14638 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014639
Mike Stroyana3082432015-09-25 13:39:21 -060014640 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014641
Chris Forbesa7530692016-05-08 12:35:39 +120014642 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014643 VkImage srcImage;
14644 VkImage dstImage;
14645 VkDeviceMemory srcMem;
14646 VkDeviceMemory destMem;
14647 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014648
14649 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014650 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14651 image_create_info.pNext = NULL;
14652 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14653 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14654 image_create_info.extent.width = 32;
14655 image_create_info.extent.height = 1;
14656 image_create_info.extent.depth = 1;
14657 image_create_info.mipLevels = 1;
14658 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014659 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014660 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14661 // Note: Some implementations expect color attachment usage for any
14662 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014663 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014664 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014665
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014666 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014667 ASSERT_VK_SUCCESS(err);
14668
Karl Schultz6addd812016-02-02 17:17:23 -070014669 // Note: Some implementations expect color attachment usage for any
14670 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014671 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014672
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014673 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014674 ASSERT_VK_SUCCESS(err);
14675
14676 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014677 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014678 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14679 memAlloc.pNext = NULL;
14680 memAlloc.allocationSize = 0;
14681 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014682
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014683 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014684 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014685 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014686 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014687 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014688 ASSERT_VK_SUCCESS(err);
14689
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014690 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014691 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014692 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014693 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014694 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014695 ASSERT_VK_SUCCESS(err);
14696
14697 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14698 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014699 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014700 ASSERT_VK_SUCCESS(err);
14701
14702 BeginCommandBuffer();
14703 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014704 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14705 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014706 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014707 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014708 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014709 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014710 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014711 resolveRegion.srcOffset.x = 0;
14712 resolveRegion.srcOffset.y = 0;
14713 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014714 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014715 resolveRegion.dstSubresource.mipLevel = 0;
14716 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014717 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014718 resolveRegion.dstOffset.x = 0;
14719 resolveRegion.dstOffset.y = 0;
14720 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014721 resolveRegion.extent.width = 1;
14722 resolveRegion.extent.height = 1;
14723 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014724 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014725 EndCommandBuffer();
14726
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014727 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014728
Chia-I Wuf7458c52015-10-26 21:10:41 +080014729 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014730 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014731 vkFreeMemory(m_device->device(), srcMem, NULL);
14732 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014733}
14734
Karl Schultz6addd812016-02-02 17:17:23 -070014735TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14736 VkResult err;
14737 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014738
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14740 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014741
Mike Stroyana3082432015-09-25 13:39:21 -060014742 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014743
14744 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014745 VkImage srcImage;
14746 VkImage dstImage;
14747 VkDeviceMemory srcMem;
14748 VkDeviceMemory destMem;
14749 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014750
14751 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014752 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14753 image_create_info.pNext = NULL;
14754 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14755 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14756 image_create_info.extent.width = 32;
14757 image_create_info.extent.height = 1;
14758 image_create_info.extent.depth = 1;
14759 image_create_info.mipLevels = 1;
14760 image_create_info.arrayLayers = 1;
14761 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14762 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14763 // Note: Some implementations expect color attachment usage for any
14764 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014765 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014766 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014767
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014768 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014769 ASSERT_VK_SUCCESS(err);
14770
Karl Schultz6addd812016-02-02 17:17:23 -070014771 // Set format to something other than source image
14772 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14773 // Note: Some implementations expect color attachment usage for any
14774 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014775 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014776 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014777
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014778 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014779 ASSERT_VK_SUCCESS(err);
14780
14781 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014782 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014783 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14784 memAlloc.pNext = NULL;
14785 memAlloc.allocationSize = 0;
14786 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014787
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014788 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014789 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014790 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014791 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014792 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014793 ASSERT_VK_SUCCESS(err);
14794
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014795 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014796 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014797 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014798 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014799 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014800 ASSERT_VK_SUCCESS(err);
14801
14802 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14803 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014804 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014805 ASSERT_VK_SUCCESS(err);
14806
14807 BeginCommandBuffer();
14808 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014809 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14810 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014811 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014812 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014813 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014814 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014815 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014816 resolveRegion.srcOffset.x = 0;
14817 resolveRegion.srcOffset.y = 0;
14818 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014819 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014820 resolveRegion.dstSubresource.mipLevel = 0;
14821 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014822 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014823 resolveRegion.dstOffset.x = 0;
14824 resolveRegion.dstOffset.y = 0;
14825 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014826 resolveRegion.extent.width = 1;
14827 resolveRegion.extent.height = 1;
14828 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014829 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014830 EndCommandBuffer();
14831
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014832 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014833
Chia-I Wuf7458c52015-10-26 21:10:41 +080014834 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014835 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014836 vkFreeMemory(m_device->device(), srcMem, NULL);
14837 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014838}
14839
Karl Schultz6addd812016-02-02 17:17:23 -070014840TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
14841 VkResult err;
14842 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014843
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14845 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014846
Mike Stroyana3082432015-09-25 13:39:21 -060014847 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014848
14849 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014850 VkImage srcImage;
14851 VkImage dstImage;
14852 VkDeviceMemory srcMem;
14853 VkDeviceMemory destMem;
14854 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014855
14856 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014857 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14858 image_create_info.pNext = NULL;
14859 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14860 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14861 image_create_info.extent.width = 32;
14862 image_create_info.extent.height = 1;
14863 image_create_info.extent.depth = 1;
14864 image_create_info.mipLevels = 1;
14865 image_create_info.arrayLayers = 1;
14866 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14867 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14868 // Note: Some implementations expect color attachment usage for any
14869 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014870 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014871 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014872
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014873 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014874 ASSERT_VK_SUCCESS(err);
14875
Karl Schultz6addd812016-02-02 17:17:23 -070014876 image_create_info.imageType = VK_IMAGE_TYPE_1D;
14877 // Note: Some implementations expect color attachment usage for any
14878 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014879 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014880 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014881
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014882 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014883 ASSERT_VK_SUCCESS(err);
14884
14885 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014886 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014887 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14888 memAlloc.pNext = NULL;
14889 memAlloc.allocationSize = 0;
14890 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014891
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014892 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014893 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014894 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014895 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014896 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014897 ASSERT_VK_SUCCESS(err);
14898
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014899 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014900 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014901 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014902 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014903 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014904 ASSERT_VK_SUCCESS(err);
14905
14906 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14907 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014908 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014909 ASSERT_VK_SUCCESS(err);
14910
14911 BeginCommandBuffer();
14912 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014913 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14914 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014915 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014916 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014917 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014918 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014919 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014920 resolveRegion.srcOffset.x = 0;
14921 resolveRegion.srcOffset.y = 0;
14922 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014923 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014924 resolveRegion.dstSubresource.mipLevel = 0;
14925 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014926 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014927 resolveRegion.dstOffset.x = 0;
14928 resolveRegion.dstOffset.y = 0;
14929 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014930 resolveRegion.extent.width = 1;
14931 resolveRegion.extent.height = 1;
14932 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014933 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014934 EndCommandBuffer();
14935
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014936 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014937
Chia-I Wuf7458c52015-10-26 21:10:41 +080014938 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014939 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014940 vkFreeMemory(m_device->device(), srcMem, NULL);
14941 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014942}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014943
Karl Schultz6addd812016-02-02 17:17:23 -070014944TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014945 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070014946 // to using a DS format, then cause it to hit error due to COLOR_BIT not
14947 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014948 // The image format check comes 2nd in validation so we trigger it first,
14949 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070014950 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014951
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14953 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014954
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014955 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014956
Chia-I Wu1b99bb22015-10-27 19:25:11 +080014957 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014958 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14959 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014960
14961 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014962 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14963 ds_pool_ci.pNext = NULL;
14964 ds_pool_ci.maxSets = 1;
14965 ds_pool_ci.poolSizeCount = 1;
14966 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014967
14968 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014969 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014970 ASSERT_VK_SUCCESS(err);
14971
14972 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014973 dsl_binding.binding = 0;
14974 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14975 dsl_binding.descriptorCount = 1;
14976 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
14977 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014978
14979 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014980 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14981 ds_layout_ci.pNext = NULL;
14982 ds_layout_ci.bindingCount = 1;
14983 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014984 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014985 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014986 ASSERT_VK_SUCCESS(err);
14987
14988 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014989 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080014990 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070014991 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014992 alloc_info.descriptorPool = ds_pool;
14993 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014994 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014995 ASSERT_VK_SUCCESS(err);
14996
Karl Schultz6addd812016-02-02 17:17:23 -070014997 VkImage image_bad;
14998 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014999 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015000 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015001 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015002 const int32_t tex_width = 32;
15003 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015004
15005 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015006 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15007 image_create_info.pNext = NULL;
15008 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15009 image_create_info.format = tex_format_bad;
15010 image_create_info.extent.width = tex_width;
15011 image_create_info.extent.height = tex_height;
15012 image_create_info.extent.depth = 1;
15013 image_create_info.mipLevels = 1;
15014 image_create_info.arrayLayers = 1;
15015 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15016 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015017 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015018 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015020 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015021 ASSERT_VK_SUCCESS(err);
15022 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015023 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15024 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015025 ASSERT_VK_SUCCESS(err);
15026
15027 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015028 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15029 image_view_create_info.image = image_bad;
15030 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15031 image_view_create_info.format = tex_format_bad;
15032 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15033 image_view_create_info.subresourceRange.baseMipLevel = 0;
15034 image_view_create_info.subresourceRange.layerCount = 1;
15035 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015036 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015037
15038 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015039 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015040
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015041 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015042
Chia-I Wuf7458c52015-10-26 21:10:41 +080015043 vkDestroyImage(m_device->device(), image_bad, NULL);
15044 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015045 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15046 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015047}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015048
15049TEST_F(VkLayerTest, ClearImageErrors) {
15050 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15051 "ClearDepthStencilImage with a color image.");
15052
15053 ASSERT_NO_FATAL_FAILURE(InitState());
15054 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15055
15056 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15057 BeginCommandBuffer();
15058 m_commandBuffer->EndRenderPass();
15059
15060 // Color image
15061 VkClearColorValue clear_color;
15062 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15063 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15064 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15065 const int32_t img_width = 32;
15066 const int32_t img_height = 32;
15067 VkImageCreateInfo image_create_info = {};
15068 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15069 image_create_info.pNext = NULL;
15070 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15071 image_create_info.format = color_format;
15072 image_create_info.extent.width = img_width;
15073 image_create_info.extent.height = img_height;
15074 image_create_info.extent.depth = 1;
15075 image_create_info.mipLevels = 1;
15076 image_create_info.arrayLayers = 1;
15077 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15078 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15079 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15080
15081 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015082 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015083
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015084 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015085
15086 // Depth/Stencil image
15087 VkClearDepthStencilValue clear_value = {0};
15088 reqs = 0; // don't need HOST_VISIBLE DS image
15089 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15090 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15091 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15092 ds_image_create_info.extent.width = 64;
15093 ds_image_create_info.extent.height = 64;
15094 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15095 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15096
15097 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015098 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015100 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 -060015101
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015104 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015105 &color_range);
15106
15107 m_errorMonitor->VerifyFound();
15108
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15110 "image created without "
15111 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015112
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015113 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015114 &color_range);
15115
15116 m_errorMonitor->VerifyFound();
15117
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015118 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15120 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015121
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015122 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15123 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015124
15125 m_errorMonitor->VerifyFound();
15126}
Tobin Ehliscde08892015-09-22 10:11:37 -060015127#endif // IMAGE_TESTS
15128
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015129
15130// WSI Enabled Tests
15131//
15132TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15133
15134#if defined(VK_USE_PLATFORM_XCB_KHR)
15135 VkSurfaceKHR surface = VK_NULL_HANDLE;
15136
15137 VkResult err;
15138 bool pass;
15139 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15140 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15141 // uint32_t swapchain_image_count = 0;
15142 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15143 // uint32_t image_index = 0;
15144 // VkPresentInfoKHR present_info = {};
15145
15146 ASSERT_NO_FATAL_FAILURE(InitState());
15147
15148 // Use the create function from one of the VK_KHR_*_surface extension in
15149 // order to create a surface, testing all known errors in the process,
15150 // before successfully creating a surface:
15151 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15153 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15154 pass = (err != VK_SUCCESS);
15155 ASSERT_TRUE(pass);
15156 m_errorMonitor->VerifyFound();
15157
15158 // Next, try to create a surface with the wrong
15159 // VkXcbSurfaceCreateInfoKHR::sType:
15160 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15161 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15163 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15164 pass = (err != VK_SUCCESS);
15165 ASSERT_TRUE(pass);
15166 m_errorMonitor->VerifyFound();
15167
15168 // Create a native window, and then correctly create a surface:
15169 xcb_connection_t *connection;
15170 xcb_screen_t *screen;
15171 xcb_window_t xcb_window;
15172 xcb_intern_atom_reply_t *atom_wm_delete_window;
15173
15174 const xcb_setup_t *setup;
15175 xcb_screen_iterator_t iter;
15176 int scr;
15177 uint32_t value_mask, value_list[32];
15178 int width = 1;
15179 int height = 1;
15180
15181 connection = xcb_connect(NULL, &scr);
15182 ASSERT_TRUE(connection != NULL);
15183 setup = xcb_get_setup(connection);
15184 iter = xcb_setup_roots_iterator(setup);
15185 while (scr-- > 0)
15186 xcb_screen_next(&iter);
15187 screen = iter.data;
15188
15189 xcb_window = xcb_generate_id(connection);
15190
15191 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15192 value_list[0] = screen->black_pixel;
15193 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15194
15195 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15196 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15197
15198 /* Magic code that will send notification when window is destroyed */
15199 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15200 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15201
15202 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15203 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15204 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15205 free(reply);
15206
15207 xcb_map_window(connection, xcb_window);
15208
15209 // Force the x/y coordinates to 100,100 results are identical in consecutive
15210 // runs
15211 const uint32_t coords[] = { 100, 100 };
15212 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15213
15214 // Finally, try to correctly create a surface:
15215 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15216 xcb_create_info.pNext = NULL;
15217 xcb_create_info.flags = 0;
15218 xcb_create_info.connection = connection;
15219 xcb_create_info.window = xcb_window;
15220 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15221 pass = (err == VK_SUCCESS);
15222 ASSERT_TRUE(pass);
15223
15224 // Check if surface supports presentation:
15225
15226 // 1st, do so without having queried the queue families:
15227 VkBool32 supported = false;
15228 // TODO: Get the following error to come out:
15229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15230 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15231 "function");
15232 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15233 pass = (err != VK_SUCCESS);
15234 // ASSERT_TRUE(pass);
15235 // m_errorMonitor->VerifyFound();
15236
15237 // Next, query a queue family index that's too large:
15238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15239 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15240 pass = (err != VK_SUCCESS);
15241 ASSERT_TRUE(pass);
15242 m_errorMonitor->VerifyFound();
15243
15244 // Finally, do so correctly:
15245 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15246 // SUPPORTED
15247 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15248 pass = (err == VK_SUCCESS);
15249 ASSERT_TRUE(pass);
15250
15251 // Before proceeding, try to create a swapchain without having called
15252 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15253 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15254 swapchain_create_info.pNext = NULL;
15255 swapchain_create_info.flags = 0;
15256 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15257 swapchain_create_info.surface = surface;
15258 swapchain_create_info.imageArrayLayers = 1;
15259 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15260 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15262 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15263 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15264 pass = (err != VK_SUCCESS);
15265 ASSERT_TRUE(pass);
15266 m_errorMonitor->VerifyFound();
15267
15268 // Get the surface capabilities:
15269 VkSurfaceCapabilitiesKHR surface_capabilities;
15270
15271 // Do so correctly (only error logged by this entrypoint is if the
15272 // extension isn't enabled):
15273 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15274 pass = (err == VK_SUCCESS);
15275 ASSERT_TRUE(pass);
15276
15277 // Get the surface formats:
15278 uint32_t surface_format_count;
15279
15280 // First, try without a pointer to surface_format_count:
15281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15282 "specified as NULL");
15283 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15284 pass = (err == VK_SUCCESS);
15285 ASSERT_TRUE(pass);
15286 m_errorMonitor->VerifyFound();
15287
15288 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15289 // correctly done a 1st try (to get the count):
15290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15291 surface_format_count = 0;
15292 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15293 pass = (err == VK_SUCCESS);
15294 ASSERT_TRUE(pass);
15295 m_errorMonitor->VerifyFound();
15296
15297 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15298 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15299 pass = (err == VK_SUCCESS);
15300 ASSERT_TRUE(pass);
15301
15302 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15303 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15304
15305 // Next, do a 2nd try with surface_format_count being set too high:
15306 surface_format_count += 5;
15307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15308 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15309 pass = (err == VK_SUCCESS);
15310 ASSERT_TRUE(pass);
15311 m_errorMonitor->VerifyFound();
15312
15313 // Finally, do a correct 1st and 2nd try:
15314 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15315 pass = (err == VK_SUCCESS);
15316 ASSERT_TRUE(pass);
15317 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15318 pass = (err == VK_SUCCESS);
15319 ASSERT_TRUE(pass);
15320
15321 // Get the surface present modes:
15322 uint32_t surface_present_mode_count;
15323
15324 // First, try without a pointer to surface_format_count:
15325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15326 "specified as NULL");
15327
15328 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15329 pass = (err == VK_SUCCESS);
15330 ASSERT_TRUE(pass);
15331 m_errorMonitor->VerifyFound();
15332
15333 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15334 // correctly done a 1st try (to get the count):
15335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15336 surface_present_mode_count = 0;
15337 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15338 (VkPresentModeKHR *)&surface_present_mode_count);
15339 pass = (err == VK_SUCCESS);
15340 ASSERT_TRUE(pass);
15341 m_errorMonitor->VerifyFound();
15342
15343 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15344 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15345 pass = (err == VK_SUCCESS);
15346 ASSERT_TRUE(pass);
15347
15348 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15349 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15350
15351 // Next, do a 2nd try with surface_format_count being set too high:
15352 surface_present_mode_count += 5;
15353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15354 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15355 pass = (err == VK_SUCCESS);
15356 ASSERT_TRUE(pass);
15357 m_errorMonitor->VerifyFound();
15358
15359 // Finally, do a correct 1st and 2nd try:
15360 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15361 pass = (err == VK_SUCCESS);
15362 ASSERT_TRUE(pass);
15363 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15364 pass = (err == VK_SUCCESS);
15365 ASSERT_TRUE(pass);
15366
15367 // Create a swapchain:
15368
15369 // First, try without a pointer to swapchain_create_info:
15370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15371 "specified as NULL");
15372
15373 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15374 pass = (err != VK_SUCCESS);
15375 ASSERT_TRUE(pass);
15376 m_errorMonitor->VerifyFound();
15377
15378 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15379 // sType:
15380 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15382
15383 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15384 pass = (err != VK_SUCCESS);
15385 ASSERT_TRUE(pass);
15386 m_errorMonitor->VerifyFound();
15387
15388 // Next, call with a NULL swapchain pointer:
15389 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15390 swapchain_create_info.pNext = NULL;
15391 swapchain_create_info.flags = 0;
15392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15393 "specified as NULL");
15394
15395 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15396 pass = (err != VK_SUCCESS);
15397 ASSERT_TRUE(pass);
15398 m_errorMonitor->VerifyFound();
15399
15400 // TODO: Enhance swapchain layer so that
15401 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15402
15403 // Next, call with a queue family index that's too large:
15404 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15405 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15406 swapchain_create_info.queueFamilyIndexCount = 2;
15407 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15409 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15410 pass = (err != VK_SUCCESS);
15411 ASSERT_TRUE(pass);
15412 m_errorMonitor->VerifyFound();
15413
15414 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15415 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15416 swapchain_create_info.queueFamilyIndexCount = 1;
15417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15418 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15419 "pCreateInfo->pQueueFamilyIndices).");
15420 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15421 pass = (err != VK_SUCCESS);
15422 ASSERT_TRUE(pass);
15423 m_errorMonitor->VerifyFound();
15424
15425 // Next, call with an invalid imageSharingMode:
15426 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15427 swapchain_create_info.queueFamilyIndexCount = 1;
15428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15429 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15430 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15431 pass = (err != VK_SUCCESS);
15432 ASSERT_TRUE(pass);
15433 m_errorMonitor->VerifyFound();
15434 // Fix for the future:
15435 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15436 // SUPPORTED
15437 swapchain_create_info.queueFamilyIndexCount = 0;
15438 queueFamilyIndex[0] = 0;
15439 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15440
15441 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15442 // Get the images from a swapchain:
15443 // Acquire an image from a swapchain:
15444 // Present an image to a swapchain:
15445 // Destroy the swapchain:
15446
15447 // TODOs:
15448 //
15449 // - Try destroying the device without first destroying the swapchain
15450 //
15451 // - Try destroying the device without first destroying the surface
15452 //
15453 // - Try destroying the surface without first destroying the swapchain
15454
15455 // Destroy the surface:
15456 vkDestroySurfaceKHR(instance(), surface, NULL);
15457
15458 // Tear down the window:
15459 xcb_destroy_window(connection, xcb_window);
15460 xcb_disconnect(connection);
15461
15462#else // VK_USE_PLATFORM_XCB_KHR
15463 return;
15464#endif // VK_USE_PLATFORM_XCB_KHR
15465}
15466
15467//
15468// POSITIVE VALIDATION TESTS
15469//
15470// These tests do not expect to encounter ANY validation errors pass only if this is true
15471
Tobin Ehlise0006882016-11-03 10:14:28 -060015472TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15473 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15474 "by a transition in the primary.");
15475 VkResult err;
15476 m_errorMonitor->ExpectSuccess();
15477 ASSERT_NO_FATAL_FAILURE(InitState());
15478 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15479 // Allocate a secondary and primary cmd buffer
15480 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15481 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15482 command_buffer_allocate_info.commandPool = m_commandPool;
15483 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15484 command_buffer_allocate_info.commandBufferCount = 1;
15485
15486 VkCommandBuffer secondary_command_buffer;
15487 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15488 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15489 VkCommandBuffer primary_command_buffer;
15490 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15491 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15492 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15493 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15494 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15495 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15496 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15497
15498 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15499 ASSERT_VK_SUCCESS(err);
15500 VkImageObj image(m_device);
15501 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15502 ASSERT_TRUE(image.initialized());
15503 VkImageMemoryBarrier img_barrier = {};
15504 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15505 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15506 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15507 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15508 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15509 img_barrier.image = image.handle();
15510 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15511 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15512 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15513 img_barrier.subresourceRange.baseArrayLayer = 0;
15514 img_barrier.subresourceRange.baseMipLevel = 0;
15515 img_barrier.subresourceRange.layerCount = 1;
15516 img_barrier.subresourceRange.levelCount = 1;
15517 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15518 0, nullptr, 1, &img_barrier);
15519 err = vkEndCommandBuffer(secondary_command_buffer);
15520 ASSERT_VK_SUCCESS(err);
15521
15522 // Now update primary cmd buffer to execute secondary and transitions image
15523 command_buffer_begin_info.pInheritanceInfo = nullptr;
15524 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15525 ASSERT_VK_SUCCESS(err);
15526 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15527 VkImageMemoryBarrier img_barrier2 = {};
15528 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15529 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15530 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15531 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15532 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15533 img_barrier2.image = image.handle();
15534 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15535 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15536 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15537 img_barrier2.subresourceRange.baseArrayLayer = 0;
15538 img_barrier2.subresourceRange.baseMipLevel = 0;
15539 img_barrier2.subresourceRange.layerCount = 1;
15540 img_barrier2.subresourceRange.levelCount = 1;
15541 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15542 nullptr, 1, &img_barrier2);
15543 err = vkEndCommandBuffer(primary_command_buffer);
15544 ASSERT_VK_SUCCESS(err);
15545 VkSubmitInfo submit_info = {};
15546 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15547 submit_info.commandBufferCount = 1;
15548 submit_info.pCommandBuffers = &primary_command_buffer;
15549 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15550 ASSERT_VK_SUCCESS(err);
15551 m_errorMonitor->VerifyNotFound();
15552 err = vkDeviceWaitIdle(m_device->device());
15553 ASSERT_VK_SUCCESS(err);
15554 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15555 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15556}
15557
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015558// This is a positive test. No failures are expected.
15559TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15560 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15561 "is ignoring VkWriteDescriptorSet members that are not "
15562 "related to the descriptor type specified by "
15563 "VkWriteDescriptorSet::descriptorType. Correct "
15564 "validation behavior will result in the test running to "
15565 "completion without validation errors.");
15566
15567 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15568
15569 ASSERT_NO_FATAL_FAILURE(InitState());
15570
15571 // Image Case
15572 {
15573 m_errorMonitor->ExpectSuccess();
15574
15575 VkImage image;
15576 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15577 const int32_t tex_width = 32;
15578 const int32_t tex_height = 32;
15579 VkImageCreateInfo image_create_info = {};
15580 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15581 image_create_info.pNext = NULL;
15582 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15583 image_create_info.format = tex_format;
15584 image_create_info.extent.width = tex_width;
15585 image_create_info.extent.height = tex_height;
15586 image_create_info.extent.depth = 1;
15587 image_create_info.mipLevels = 1;
15588 image_create_info.arrayLayers = 1;
15589 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15590 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15591 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15592 image_create_info.flags = 0;
15593 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15594 ASSERT_VK_SUCCESS(err);
15595
15596 VkMemoryRequirements memory_reqs;
15597 VkDeviceMemory image_memory;
15598 bool pass;
15599 VkMemoryAllocateInfo memory_info = {};
15600 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15601 memory_info.pNext = NULL;
15602 memory_info.allocationSize = 0;
15603 memory_info.memoryTypeIndex = 0;
15604 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15605 memory_info.allocationSize = memory_reqs.size;
15606 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15607 ASSERT_TRUE(pass);
15608 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15609 ASSERT_VK_SUCCESS(err);
15610 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15611 ASSERT_VK_SUCCESS(err);
15612
15613 VkImageViewCreateInfo image_view_create_info = {};
15614 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15615 image_view_create_info.image = image;
15616 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15617 image_view_create_info.format = tex_format;
15618 image_view_create_info.subresourceRange.layerCount = 1;
15619 image_view_create_info.subresourceRange.baseMipLevel = 0;
15620 image_view_create_info.subresourceRange.levelCount = 1;
15621 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15622
15623 VkImageView view;
15624 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15625 ASSERT_VK_SUCCESS(err);
15626
15627 VkDescriptorPoolSize ds_type_count = {};
15628 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15629 ds_type_count.descriptorCount = 1;
15630
15631 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15632 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15633 ds_pool_ci.pNext = NULL;
15634 ds_pool_ci.maxSets = 1;
15635 ds_pool_ci.poolSizeCount = 1;
15636 ds_pool_ci.pPoolSizes = &ds_type_count;
15637
15638 VkDescriptorPool ds_pool;
15639 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15640 ASSERT_VK_SUCCESS(err);
15641
15642 VkDescriptorSetLayoutBinding dsl_binding = {};
15643 dsl_binding.binding = 0;
15644 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15645 dsl_binding.descriptorCount = 1;
15646 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15647 dsl_binding.pImmutableSamplers = NULL;
15648
15649 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15650 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15651 ds_layout_ci.pNext = NULL;
15652 ds_layout_ci.bindingCount = 1;
15653 ds_layout_ci.pBindings = &dsl_binding;
15654 VkDescriptorSetLayout ds_layout;
15655 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15656 ASSERT_VK_SUCCESS(err);
15657
15658 VkDescriptorSet descriptor_set;
15659 VkDescriptorSetAllocateInfo alloc_info = {};
15660 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15661 alloc_info.descriptorSetCount = 1;
15662 alloc_info.descriptorPool = ds_pool;
15663 alloc_info.pSetLayouts = &ds_layout;
15664 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15665 ASSERT_VK_SUCCESS(err);
15666
15667 VkDescriptorImageInfo image_info = {};
15668 image_info.imageView = view;
15669 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15670
15671 VkWriteDescriptorSet descriptor_write;
15672 memset(&descriptor_write, 0, sizeof(descriptor_write));
15673 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15674 descriptor_write.dstSet = descriptor_set;
15675 descriptor_write.dstBinding = 0;
15676 descriptor_write.descriptorCount = 1;
15677 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15678 descriptor_write.pImageInfo = &image_info;
15679
15680 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15681 // be
15682 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15683 // This will most likely produce a crash if the parameter_validation
15684 // layer
15685 // does not correctly ignore pBufferInfo.
15686 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15687 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15688
15689 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15690
15691 m_errorMonitor->VerifyNotFound();
15692
15693 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15694 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15695 vkDestroyImageView(m_device->device(), view, NULL);
15696 vkDestroyImage(m_device->device(), image, NULL);
15697 vkFreeMemory(m_device->device(), image_memory, NULL);
15698 }
15699
15700 // Buffer Case
15701 {
15702 m_errorMonitor->ExpectSuccess();
15703
15704 VkBuffer buffer;
15705 uint32_t queue_family_index = 0;
15706 VkBufferCreateInfo buffer_create_info = {};
15707 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15708 buffer_create_info.size = 1024;
15709 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15710 buffer_create_info.queueFamilyIndexCount = 1;
15711 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15712
15713 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15714 ASSERT_VK_SUCCESS(err);
15715
15716 VkMemoryRequirements memory_reqs;
15717 VkDeviceMemory buffer_memory;
15718 bool pass;
15719 VkMemoryAllocateInfo memory_info = {};
15720 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15721 memory_info.pNext = NULL;
15722 memory_info.allocationSize = 0;
15723 memory_info.memoryTypeIndex = 0;
15724
15725 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15726 memory_info.allocationSize = memory_reqs.size;
15727 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15728 ASSERT_TRUE(pass);
15729
15730 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15731 ASSERT_VK_SUCCESS(err);
15732 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15733 ASSERT_VK_SUCCESS(err);
15734
15735 VkDescriptorPoolSize ds_type_count = {};
15736 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15737 ds_type_count.descriptorCount = 1;
15738
15739 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15740 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15741 ds_pool_ci.pNext = NULL;
15742 ds_pool_ci.maxSets = 1;
15743 ds_pool_ci.poolSizeCount = 1;
15744 ds_pool_ci.pPoolSizes = &ds_type_count;
15745
15746 VkDescriptorPool ds_pool;
15747 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15748 ASSERT_VK_SUCCESS(err);
15749
15750 VkDescriptorSetLayoutBinding dsl_binding = {};
15751 dsl_binding.binding = 0;
15752 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15753 dsl_binding.descriptorCount = 1;
15754 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15755 dsl_binding.pImmutableSamplers = NULL;
15756
15757 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15758 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15759 ds_layout_ci.pNext = NULL;
15760 ds_layout_ci.bindingCount = 1;
15761 ds_layout_ci.pBindings = &dsl_binding;
15762 VkDescriptorSetLayout ds_layout;
15763 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15764 ASSERT_VK_SUCCESS(err);
15765
15766 VkDescriptorSet descriptor_set;
15767 VkDescriptorSetAllocateInfo alloc_info = {};
15768 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15769 alloc_info.descriptorSetCount = 1;
15770 alloc_info.descriptorPool = ds_pool;
15771 alloc_info.pSetLayouts = &ds_layout;
15772 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15773 ASSERT_VK_SUCCESS(err);
15774
15775 VkDescriptorBufferInfo buffer_info = {};
15776 buffer_info.buffer = buffer;
15777 buffer_info.offset = 0;
15778 buffer_info.range = 1024;
15779
15780 VkWriteDescriptorSet descriptor_write;
15781 memset(&descriptor_write, 0, sizeof(descriptor_write));
15782 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15783 descriptor_write.dstSet = descriptor_set;
15784 descriptor_write.dstBinding = 0;
15785 descriptor_write.descriptorCount = 1;
15786 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15787 descriptor_write.pBufferInfo = &buffer_info;
15788
15789 // Set pImageInfo and pTexelBufferView to invalid values, which should
15790 // be
15791 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15792 // This will most likely produce a crash if the parameter_validation
15793 // layer
15794 // does not correctly ignore pImageInfo.
15795 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15796 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15797
15798 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15799
15800 m_errorMonitor->VerifyNotFound();
15801
15802 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15803 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15804 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15805 vkDestroyBuffer(m_device->device(), buffer, NULL);
15806 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15807 }
15808
15809 // Texel Buffer Case
15810 {
15811 m_errorMonitor->ExpectSuccess();
15812
15813 VkBuffer buffer;
15814 uint32_t queue_family_index = 0;
15815 VkBufferCreateInfo buffer_create_info = {};
15816 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15817 buffer_create_info.size = 1024;
15818 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15819 buffer_create_info.queueFamilyIndexCount = 1;
15820 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15821
15822 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15823 ASSERT_VK_SUCCESS(err);
15824
15825 VkMemoryRequirements memory_reqs;
15826 VkDeviceMemory buffer_memory;
15827 bool pass;
15828 VkMemoryAllocateInfo memory_info = {};
15829 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15830 memory_info.pNext = NULL;
15831 memory_info.allocationSize = 0;
15832 memory_info.memoryTypeIndex = 0;
15833
15834 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15835 memory_info.allocationSize = memory_reqs.size;
15836 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15837 ASSERT_TRUE(pass);
15838
15839 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15840 ASSERT_VK_SUCCESS(err);
15841 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15842 ASSERT_VK_SUCCESS(err);
15843
15844 VkBufferViewCreateInfo buff_view_ci = {};
15845 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
15846 buff_view_ci.buffer = buffer;
15847 buff_view_ci.format = VK_FORMAT_R8_UNORM;
15848 buff_view_ci.range = VK_WHOLE_SIZE;
15849 VkBufferView buffer_view;
15850 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
15851
15852 VkDescriptorPoolSize ds_type_count = {};
15853 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15854 ds_type_count.descriptorCount = 1;
15855
15856 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15857 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15858 ds_pool_ci.pNext = NULL;
15859 ds_pool_ci.maxSets = 1;
15860 ds_pool_ci.poolSizeCount = 1;
15861 ds_pool_ci.pPoolSizes = &ds_type_count;
15862
15863 VkDescriptorPool ds_pool;
15864 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15865 ASSERT_VK_SUCCESS(err);
15866
15867 VkDescriptorSetLayoutBinding dsl_binding = {};
15868 dsl_binding.binding = 0;
15869 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15870 dsl_binding.descriptorCount = 1;
15871 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15872 dsl_binding.pImmutableSamplers = NULL;
15873
15874 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15875 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15876 ds_layout_ci.pNext = NULL;
15877 ds_layout_ci.bindingCount = 1;
15878 ds_layout_ci.pBindings = &dsl_binding;
15879 VkDescriptorSetLayout ds_layout;
15880 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15881 ASSERT_VK_SUCCESS(err);
15882
15883 VkDescriptorSet descriptor_set;
15884 VkDescriptorSetAllocateInfo alloc_info = {};
15885 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15886 alloc_info.descriptorSetCount = 1;
15887 alloc_info.descriptorPool = ds_pool;
15888 alloc_info.pSetLayouts = &ds_layout;
15889 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15890 ASSERT_VK_SUCCESS(err);
15891
15892 VkWriteDescriptorSet descriptor_write;
15893 memset(&descriptor_write, 0, sizeof(descriptor_write));
15894 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15895 descriptor_write.dstSet = descriptor_set;
15896 descriptor_write.dstBinding = 0;
15897 descriptor_write.descriptorCount = 1;
15898 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15899 descriptor_write.pTexelBufferView = &buffer_view;
15900
15901 // Set pImageInfo and pBufferInfo to invalid values, which should be
15902 // ignored for descriptorType ==
15903 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
15904 // This will most likely produce a crash if the parameter_validation
15905 // layer
15906 // does not correctly ignore pImageInfo and pBufferInfo.
15907 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15908 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15909
15910 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15911
15912 m_errorMonitor->VerifyNotFound();
15913
15914 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15915 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15916 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15917 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
15918 vkDestroyBuffer(m_device->device(), buffer, NULL);
15919 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15920 }
15921}
15922
Tobin Ehlisf7428442016-10-25 07:58:24 -060015923TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
15924 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
15925
15926 ASSERT_NO_FATAL_FAILURE(InitState());
15927 // Create layout where two binding #s are "1"
15928 static const uint32_t NUM_BINDINGS = 3;
15929 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15930 dsl_binding[0].binding = 1;
15931 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15932 dsl_binding[0].descriptorCount = 1;
15933 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15934 dsl_binding[0].pImmutableSamplers = NULL;
15935 dsl_binding[1].binding = 0;
15936 dsl_binding[1].descriptorCount = 1;
15937 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15938 dsl_binding[1].descriptorCount = 1;
15939 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15940 dsl_binding[1].pImmutableSamplers = NULL;
15941 dsl_binding[2].binding = 1; // Duplicate binding should cause error
15942 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15943 dsl_binding[2].descriptorCount = 1;
15944 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15945 dsl_binding[2].pImmutableSamplers = NULL;
15946
15947 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15948 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15949 ds_layout_ci.pNext = NULL;
15950 ds_layout_ci.bindingCount = NUM_BINDINGS;
15951 ds_layout_ci.pBindings = dsl_binding;
15952 VkDescriptorSetLayout ds_layout;
15953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
15954 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15955 m_errorMonitor->VerifyFound();
15956}
15957
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060015958TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015959 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
15960
15961 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015962
15963 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015964
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060015965 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
15966
15967 {
15968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
15969 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
15970 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15971 m_errorMonitor->VerifyFound();
15972 }
15973
15974 {
15975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
15976 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
15977 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15978 m_errorMonitor->VerifyFound();
15979 }
15980
15981 {
15982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
15983 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
15984 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15985 m_errorMonitor->VerifyFound();
15986 }
15987
15988 {
15989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
15990 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
15991 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15992 m_errorMonitor->VerifyFound();
15993 }
15994
15995 {
15996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
15997 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
15998 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15999 m_errorMonitor->VerifyFound();
16000 }
16001
16002 {
16003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16004 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16005 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16006 m_errorMonitor->VerifyFound();
16007 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016008
16009 {
16010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16011 VkRect2D scissor = {{-1, 0}, {16, 16}};
16012 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16013 m_errorMonitor->VerifyFound();
16014 }
16015
16016 {
16017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16018 VkRect2D scissor = {{0, -2}, {16, 16}};
16019 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16020 m_errorMonitor->VerifyFound();
16021 }
16022
16023 {
16024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16025 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16026 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16027 m_errorMonitor->VerifyFound();
16028 }
16029
16030 {
16031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16032 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16033 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16034 m_errorMonitor->VerifyFound();
16035 }
16036
16037 EndCommandBuffer();
16038}
16039
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016040// This is a positive test. No failures are expected.
16041TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16042 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16043 VkResult err;
16044
16045 ASSERT_NO_FATAL_FAILURE(InitState());
16046 m_errorMonitor->ExpectSuccess();
16047 VkDescriptorPoolSize ds_type_count = {};
16048 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16049 ds_type_count.descriptorCount = 2;
16050
16051 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16052 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16053 ds_pool_ci.pNext = NULL;
16054 ds_pool_ci.maxSets = 1;
16055 ds_pool_ci.poolSizeCount = 1;
16056 ds_pool_ci.pPoolSizes = &ds_type_count;
16057
16058 VkDescriptorPool ds_pool;
16059 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16060 ASSERT_VK_SUCCESS(err);
16061
16062 // Create layout with two uniform buffer descriptors w/ empty binding between them
16063 static const uint32_t NUM_BINDINGS = 3;
16064 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16065 dsl_binding[0].binding = 0;
16066 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16067 dsl_binding[0].descriptorCount = 1;
16068 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16069 dsl_binding[0].pImmutableSamplers = NULL;
16070 dsl_binding[1].binding = 1;
16071 dsl_binding[1].descriptorCount = 0; // empty binding
16072 dsl_binding[2].binding = 2;
16073 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16074 dsl_binding[2].descriptorCount = 1;
16075 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16076 dsl_binding[2].pImmutableSamplers = NULL;
16077
16078 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16079 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16080 ds_layout_ci.pNext = NULL;
16081 ds_layout_ci.bindingCount = NUM_BINDINGS;
16082 ds_layout_ci.pBindings = dsl_binding;
16083 VkDescriptorSetLayout ds_layout;
16084 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16085 ASSERT_VK_SUCCESS(err);
16086
16087 VkDescriptorSet descriptor_set = {};
16088 VkDescriptorSetAllocateInfo alloc_info = {};
16089 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16090 alloc_info.descriptorSetCount = 1;
16091 alloc_info.descriptorPool = ds_pool;
16092 alloc_info.pSetLayouts = &ds_layout;
16093 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16094 ASSERT_VK_SUCCESS(err);
16095
16096 // Create a buffer to be used for update
16097 VkBufferCreateInfo buff_ci = {};
16098 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16099 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16100 buff_ci.size = 256;
16101 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16102 VkBuffer buffer;
16103 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16104 ASSERT_VK_SUCCESS(err);
16105 // Have to bind memory to buffer before descriptor update
16106 VkMemoryAllocateInfo mem_alloc = {};
16107 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16108 mem_alloc.pNext = NULL;
16109 mem_alloc.allocationSize = 512; // one allocation for both buffers
16110 mem_alloc.memoryTypeIndex = 0;
16111
16112 VkMemoryRequirements mem_reqs;
16113 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16114 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16115 if (!pass) {
16116 vkDestroyBuffer(m_device->device(), buffer, NULL);
16117 return;
16118 }
16119
16120 VkDeviceMemory mem;
16121 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16122 ASSERT_VK_SUCCESS(err);
16123 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16124 ASSERT_VK_SUCCESS(err);
16125
16126 // Only update the descriptor at binding 2
16127 VkDescriptorBufferInfo buff_info = {};
16128 buff_info.buffer = buffer;
16129 buff_info.offset = 0;
16130 buff_info.range = VK_WHOLE_SIZE;
16131 VkWriteDescriptorSet descriptor_write = {};
16132 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16133 descriptor_write.dstBinding = 2;
16134 descriptor_write.descriptorCount = 1;
16135 descriptor_write.pTexelBufferView = nullptr;
16136 descriptor_write.pBufferInfo = &buff_info;
16137 descriptor_write.pImageInfo = nullptr;
16138 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16139 descriptor_write.dstSet = descriptor_set;
16140
16141 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16142
16143 m_errorMonitor->VerifyNotFound();
16144 // Cleanup
16145 vkFreeMemory(m_device->device(), mem, NULL);
16146 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16147 vkDestroyBuffer(m_device->device(), buffer, NULL);
16148 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16149}
16150
16151// This is a positive test. No failures are expected.
16152TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16153 VkResult err;
16154 bool pass;
16155
16156 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16157 "the buffer, create an image, and bind the same memory to "
16158 "it");
16159
16160 m_errorMonitor->ExpectSuccess();
16161
16162 ASSERT_NO_FATAL_FAILURE(InitState());
16163
16164 VkBuffer buffer;
16165 VkImage image;
16166 VkDeviceMemory mem;
16167 VkMemoryRequirements mem_reqs;
16168
16169 VkBufferCreateInfo buf_info = {};
16170 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16171 buf_info.pNext = NULL;
16172 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16173 buf_info.size = 256;
16174 buf_info.queueFamilyIndexCount = 0;
16175 buf_info.pQueueFamilyIndices = NULL;
16176 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16177 buf_info.flags = 0;
16178 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16179 ASSERT_VK_SUCCESS(err);
16180
16181 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16182
16183 VkMemoryAllocateInfo alloc_info = {};
16184 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16185 alloc_info.pNext = NULL;
16186 alloc_info.memoryTypeIndex = 0;
16187
16188 // Ensure memory is big enough for both bindings
16189 alloc_info.allocationSize = 0x10000;
16190
16191 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16192 if (!pass) {
16193 vkDestroyBuffer(m_device->device(), buffer, NULL);
16194 return;
16195 }
16196
16197 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16198 ASSERT_VK_SUCCESS(err);
16199
16200 uint8_t *pData;
16201 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16202 ASSERT_VK_SUCCESS(err);
16203
16204 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16205
16206 vkUnmapMemory(m_device->device(), mem);
16207
16208 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16209 ASSERT_VK_SUCCESS(err);
16210
16211 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16212 // memory. In fact, it was never used by the GPU.
16213 // Just be be sure, wait for idle.
16214 vkDestroyBuffer(m_device->device(), buffer, NULL);
16215 vkDeviceWaitIdle(m_device->device());
16216
16217 VkImageCreateInfo image_create_info = {};
16218 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16219 image_create_info.pNext = NULL;
16220 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16221 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16222 image_create_info.extent.width = 64;
16223 image_create_info.extent.height = 64;
16224 image_create_info.extent.depth = 1;
16225 image_create_info.mipLevels = 1;
16226 image_create_info.arrayLayers = 1;
16227 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16228 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16229 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16230 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16231 image_create_info.queueFamilyIndexCount = 0;
16232 image_create_info.pQueueFamilyIndices = NULL;
16233 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16234 image_create_info.flags = 0;
16235
16236 VkMemoryAllocateInfo mem_alloc = {};
16237 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16238 mem_alloc.pNext = NULL;
16239 mem_alloc.allocationSize = 0;
16240 mem_alloc.memoryTypeIndex = 0;
16241
16242 /* Create a mappable image. It will be the texture if linear images are ok
16243 * to be textures or it will be the staging image if they are not.
16244 */
16245 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16246 ASSERT_VK_SUCCESS(err);
16247
16248 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16249
16250 mem_alloc.allocationSize = mem_reqs.size;
16251
16252 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16253 if (!pass) {
16254 vkDestroyImage(m_device->device(), image, NULL);
16255 return;
16256 }
16257
16258 // VALIDATION FAILURE:
16259 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16260 ASSERT_VK_SUCCESS(err);
16261
16262 m_errorMonitor->VerifyNotFound();
16263
16264 vkFreeMemory(m_device->device(), mem, NULL);
16265 vkDestroyBuffer(m_device->device(), buffer, NULL);
16266 vkDestroyImage(m_device->device(), image, NULL);
16267}
16268
Tobin Ehlis953e8392016-11-17 10:54:13 -070016269TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16270 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16271 // We previously had a bug where dynamic offset of inactive bindings was still being used
16272 VkResult err;
16273 m_errorMonitor->ExpectSuccess();
16274
16275 ASSERT_NO_FATAL_FAILURE(InitState());
16276 ASSERT_NO_FATAL_FAILURE(InitViewport());
16277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16278
16279 VkDescriptorPoolSize ds_type_count = {};
16280 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16281 ds_type_count.descriptorCount = 3;
16282
16283 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16284 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16285 ds_pool_ci.pNext = NULL;
16286 ds_pool_ci.maxSets = 1;
16287 ds_pool_ci.poolSizeCount = 1;
16288 ds_pool_ci.pPoolSizes = &ds_type_count;
16289
16290 VkDescriptorPool ds_pool;
16291 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16292 ASSERT_VK_SUCCESS(err);
16293
16294 const uint32_t BINDING_COUNT = 3;
16295 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
16296 dsl_binding[0].binding = 0;
16297 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16298 dsl_binding[0].descriptorCount = 1;
16299 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16300 dsl_binding[0].pImmutableSamplers = NULL;
16301 dsl_binding[1].binding = 1;
16302 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16303 dsl_binding[1].descriptorCount = 1;
16304 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16305 dsl_binding[1].pImmutableSamplers = NULL;
16306 dsl_binding[2].binding = 2;
16307 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16308 dsl_binding[2].descriptorCount = 1;
16309 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16310 dsl_binding[2].pImmutableSamplers = NULL;
16311
16312 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16313 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16314 ds_layout_ci.pNext = NULL;
16315 ds_layout_ci.bindingCount = BINDING_COUNT;
16316 ds_layout_ci.pBindings = dsl_binding;
16317 VkDescriptorSetLayout ds_layout;
16318 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16319 ASSERT_VK_SUCCESS(err);
16320
16321 VkDescriptorSet descriptor_set;
16322 VkDescriptorSetAllocateInfo alloc_info = {};
16323 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16324 alloc_info.descriptorSetCount = 1;
16325 alloc_info.descriptorPool = ds_pool;
16326 alloc_info.pSetLayouts = &ds_layout;
16327 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16328 ASSERT_VK_SUCCESS(err);
16329
16330 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16331 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16332 pipeline_layout_ci.pNext = NULL;
16333 pipeline_layout_ci.setLayoutCount = 1;
16334 pipeline_layout_ci.pSetLayouts = &ds_layout;
16335
16336 VkPipelineLayout pipeline_layout;
16337 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16338 ASSERT_VK_SUCCESS(err);
16339
16340 // Create two buffers to update the descriptors with
16341 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16342 uint32_t qfi = 0;
16343 VkBufferCreateInfo buffCI = {};
16344 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16345 buffCI.size = 2048;
16346 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16347 buffCI.queueFamilyIndexCount = 1;
16348 buffCI.pQueueFamilyIndices = &qfi;
16349
16350 VkBuffer dyub1;
16351 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16352 ASSERT_VK_SUCCESS(err);
16353 // buffer2
16354 buffCI.size = 1024;
16355 VkBuffer dyub2;
16356 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16357 ASSERT_VK_SUCCESS(err);
16358 // Allocate memory and bind to buffers
16359 VkMemoryAllocateInfo mem_alloc[2] = {};
16360 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16361 mem_alloc[0].pNext = NULL;
16362 mem_alloc[0].memoryTypeIndex = 0;
16363 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16364 mem_alloc[1].pNext = NULL;
16365 mem_alloc[1].memoryTypeIndex = 0;
16366
16367 VkMemoryRequirements mem_reqs1;
16368 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16369 VkMemoryRequirements mem_reqs2;
16370 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16371 mem_alloc[0].allocationSize = mem_reqs1.size;
16372 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16373 mem_alloc[1].allocationSize = mem_reqs2.size;
16374 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16375 if (!pass) {
16376 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16377 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16378 return;
16379 }
16380
16381 VkDeviceMemory mem1;
16382 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16383 ASSERT_VK_SUCCESS(err);
16384 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
16385 ASSERT_VK_SUCCESS(err);
16386 VkDeviceMemory mem2;
16387 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
16388 ASSERT_VK_SUCCESS(err);
16389 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
16390 ASSERT_VK_SUCCESS(err);
16391 // Update descriptors
16392 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
16393 buff_info[0].buffer = dyub1;
16394 buff_info[0].offset = 0;
16395 buff_info[0].range = 256;
16396 buff_info[1].buffer = dyub1;
16397 buff_info[1].offset = 256;
16398 buff_info[1].range = 512;
16399 buff_info[2].buffer = dyub2;
16400 buff_info[2].offset = 0;
16401 buff_info[2].range = 512;
16402
16403 VkWriteDescriptorSet descriptor_write;
16404 memset(&descriptor_write, 0, sizeof(descriptor_write));
16405 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16406 descriptor_write.dstSet = descriptor_set;
16407 descriptor_write.dstBinding = 0;
16408 descriptor_write.descriptorCount = BINDING_COUNT;
16409 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16410 descriptor_write.pBufferInfo = buff_info;
16411
16412 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16413
16414 BeginCommandBuffer();
16415
16416 // Create PSO to be used for draw-time errors below
16417 char const *vsSource = "#version 450\n"
16418 "\n"
16419 "out gl_PerVertex { \n"
16420 " vec4 gl_Position;\n"
16421 "};\n"
16422 "void main(){\n"
16423 " gl_Position = vec4(1);\n"
16424 "}\n";
16425 char const *fsSource = "#version 450\n"
16426 "\n"
16427 "layout(location=0) out vec4 x;\n"
16428 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
16429 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
16430 "void main(){\n"
16431 " x = vec4(bar1.y) + vec4(bar2.y);\n"
16432 "}\n";
16433 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16434 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16435 VkPipelineObj pipe(m_device);
16436 pipe.SetViewport(m_viewports);
16437 pipe.SetScissor(m_scissors);
16438 pipe.AddShader(&vs);
16439 pipe.AddShader(&fs);
16440 pipe.AddColorAttachment();
16441 pipe.CreateVKPipeline(pipeline_layout, renderPass());
16442
16443 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
16444 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
16445 // we used to have a bug in this case.
16446 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
16447 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
16448 &descriptor_set, BINDING_COUNT, dyn_off);
16449 Draw(1, 0, 0, 0);
16450 m_errorMonitor->VerifyNotFound();
16451
16452 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16453 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16454 vkFreeMemory(m_device->device(), mem1, NULL);
16455 vkFreeMemory(m_device->device(), mem2, NULL);
16456
16457 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
16458 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16459 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16460}
16461
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016462TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16463
16464 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16465 "mapping while using VK_WHOLE_SIZE does not cause access "
16466 "violations");
16467 VkResult err;
16468 uint8_t *pData;
16469 ASSERT_NO_FATAL_FAILURE(InitState());
16470
16471 VkDeviceMemory mem;
16472 VkMemoryRequirements mem_reqs;
16473 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
16474 VkMemoryAllocateInfo alloc_info = {};
16475 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16476 alloc_info.pNext = NULL;
16477 alloc_info.memoryTypeIndex = 0;
16478
16479 static const VkDeviceSize allocation_size = 0x1000;
16480 alloc_info.allocationSize = allocation_size;
16481
16482 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16483 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16484 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16485 if (!pass) {
16486 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16487 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16488 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16489 if (!pass) {
16490 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16491 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16492 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16493 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16494 if (!pass) {
16495 return;
16496 }
16497 }
16498 }
16499
16500 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16501 ASSERT_VK_SUCCESS(err);
16502
16503 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16504 // mapped range
16505 m_errorMonitor->ExpectSuccess();
16506 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16507 ASSERT_VK_SUCCESS(err);
16508 VkMappedMemoryRange mmr = {};
16509 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16510 mmr.memory = mem;
16511 mmr.offset = 0;
16512 mmr.size = VK_WHOLE_SIZE;
16513 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16514 ASSERT_VK_SUCCESS(err);
16515 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16516 ASSERT_VK_SUCCESS(err);
16517 m_errorMonitor->VerifyNotFound();
16518 vkUnmapMemory(m_device->device(), mem);
16519
16520 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16521 // mapped range
16522 m_errorMonitor->ExpectSuccess();
16523 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16524 ASSERT_VK_SUCCESS(err);
16525 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16526 mmr.memory = mem;
16527 mmr.offset = 13;
16528 mmr.size = VK_WHOLE_SIZE;
16529 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16530 ASSERT_VK_SUCCESS(err);
16531 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16532 ASSERT_VK_SUCCESS(err);
16533 m_errorMonitor->VerifyNotFound();
16534 vkUnmapMemory(m_device->device(), mem);
16535
16536 // Map with prime offset and size
16537 // Flush/Invalidate subrange of mapped area with prime offset and size
16538 m_errorMonitor->ExpectSuccess();
16539 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16540 ASSERT_VK_SUCCESS(err);
16541 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16542 mmr.memory = mem;
16543 mmr.offset = allocation_size - 107;
16544 mmr.size = 61;
16545 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16546 ASSERT_VK_SUCCESS(err);
16547 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16548 ASSERT_VK_SUCCESS(err);
16549 m_errorMonitor->VerifyNotFound();
16550 vkUnmapMemory(m_device->device(), mem);
16551
16552 // Map without offset and flush WHOLE_SIZE with two separate offsets
16553 m_errorMonitor->ExpectSuccess();
16554 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16555 ASSERT_VK_SUCCESS(err);
16556 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16557 mmr.memory = mem;
16558 mmr.offset = allocation_size - 100;
16559 mmr.size = VK_WHOLE_SIZE;
16560 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16561 ASSERT_VK_SUCCESS(err);
16562 mmr.offset = allocation_size - 200;
16563 mmr.size = VK_WHOLE_SIZE;
16564 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16565 ASSERT_VK_SUCCESS(err);
16566 m_errorMonitor->VerifyNotFound();
16567 vkUnmapMemory(m_device->device(), mem);
16568
16569 vkFreeMemory(m_device->device(), mem, NULL);
16570}
16571
16572// This is a positive test. We used to expect error in this case but spec now allows it
16573TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16574 m_errorMonitor->ExpectSuccess();
16575 vk_testing::Fence testFence;
16576 VkFenceCreateInfo fenceInfo = {};
16577 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16578 fenceInfo.pNext = NULL;
16579
16580 ASSERT_NO_FATAL_FAILURE(InitState());
16581 testFence.init(*m_device, fenceInfo);
16582 VkFence fences[1] = { testFence.handle() };
16583 VkResult result = vkResetFences(m_device->device(), 1, fences);
16584 ASSERT_VK_SUCCESS(result);
16585
16586 m_errorMonitor->VerifyNotFound();
16587}
16588
16589TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16590 m_errorMonitor->ExpectSuccess();
16591
16592 ASSERT_NO_FATAL_FAILURE(InitState());
16593 VkResult err;
16594
16595 // Record (empty!) command buffer that can be submitted multiple times
16596 // simultaneously.
16597 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16598 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16599 m_commandBuffer->BeginCommandBuffer(&cbbi);
16600 m_commandBuffer->EndCommandBuffer();
16601
16602 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16603 VkFence fence;
16604 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16605 ASSERT_VK_SUCCESS(err);
16606
16607 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16608 VkSemaphore s1, s2;
16609 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16610 ASSERT_VK_SUCCESS(err);
16611 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16612 ASSERT_VK_SUCCESS(err);
16613
16614 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16615 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16616 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16617 ASSERT_VK_SUCCESS(err);
16618
16619 // Submit CB again, signaling s2.
16620 si.pSignalSemaphores = &s2;
16621 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16622 ASSERT_VK_SUCCESS(err);
16623
16624 // Wait for fence.
16625 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16626 ASSERT_VK_SUCCESS(err);
16627
16628 // CB is still in flight from second submission, but semaphore s1 is no
16629 // longer in flight. delete it.
16630 vkDestroySemaphore(m_device->device(), s1, nullptr);
16631
16632 m_errorMonitor->VerifyNotFound();
16633
16634 // Force device idle and clean up remaining objects
16635 vkDeviceWaitIdle(m_device->device());
16636 vkDestroySemaphore(m_device->device(), s2, nullptr);
16637 vkDestroyFence(m_device->device(), fence, nullptr);
16638}
16639
16640TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16641 m_errorMonitor->ExpectSuccess();
16642
16643 ASSERT_NO_FATAL_FAILURE(InitState());
16644 VkResult err;
16645
16646 // A fence created signaled
16647 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16648 VkFence f1;
16649 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16650 ASSERT_VK_SUCCESS(err);
16651
16652 // A fence created not
16653 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16654 VkFence f2;
16655 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16656 ASSERT_VK_SUCCESS(err);
16657
16658 // Submit the unsignaled fence
16659 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16660 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16661
16662 // Wait on both fences, with signaled first.
16663 VkFence fences[] = { f1, f2 };
16664 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16665
16666 // Should have both retired!
16667 vkDestroyFence(m_device->device(), f1, nullptr);
16668 vkDestroyFence(m_device->device(), f2, nullptr);
16669
16670 m_errorMonitor->VerifyNotFound();
16671}
16672
16673TEST_F(VkPositiveLayerTest, ValidUsage) {
16674 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16675 "doesn't generate validation errors");
16676
16677 ASSERT_NO_FATAL_FAILURE(InitState());
16678
16679 m_errorMonitor->ExpectSuccess();
16680 // Verify that we can create a view with usage INPUT_ATTACHMENT
16681 VkImageObj image(m_device);
16682 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16683 ASSERT_TRUE(image.initialized());
16684 VkImageView imageView;
16685 VkImageViewCreateInfo ivci = {};
16686 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16687 ivci.image = image.handle();
16688 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16689 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16690 ivci.subresourceRange.layerCount = 1;
16691 ivci.subresourceRange.baseMipLevel = 0;
16692 ivci.subresourceRange.levelCount = 1;
16693 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16694
16695 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16696 m_errorMonitor->VerifyNotFound();
16697 vkDestroyImageView(m_device->device(), imageView, NULL);
16698}
16699
16700// This is a positive test. No failures are expected.
16701TEST_F(VkPositiveLayerTest, BindSparse) {
16702 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16703 "and then free the memory");
16704
16705 ASSERT_NO_FATAL_FAILURE(InitState());
16706
16707 auto index = m_device->graphics_queue_node_index_;
16708 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16709 return;
16710
16711 m_errorMonitor->ExpectSuccess();
16712
16713 VkImage image;
16714 VkImageCreateInfo image_create_info = {};
16715 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16716 image_create_info.pNext = NULL;
16717 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16718 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16719 image_create_info.extent.width = 64;
16720 image_create_info.extent.height = 64;
16721 image_create_info.extent.depth = 1;
16722 image_create_info.mipLevels = 1;
16723 image_create_info.arrayLayers = 1;
16724 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16725 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16726 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16727 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16728 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16729 ASSERT_VK_SUCCESS(err);
16730
16731 VkMemoryRequirements memory_reqs;
16732 VkDeviceMemory memory_one, memory_two;
16733 bool pass;
16734 VkMemoryAllocateInfo memory_info = {};
16735 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16736 memory_info.pNext = NULL;
16737 memory_info.allocationSize = 0;
16738 memory_info.memoryTypeIndex = 0;
16739 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16740 // Find an image big enough to allow sparse mapping of 2 memory regions
16741 // Increase the image size until it is at least twice the
16742 // size of the required alignment, to ensure we can bind both
16743 // allocated memory blocks to the image on aligned offsets.
16744 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16745 vkDestroyImage(m_device->device(), image, nullptr);
16746 image_create_info.extent.width *= 2;
16747 image_create_info.extent.height *= 2;
16748 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16749 ASSERT_VK_SUCCESS(err);
16750 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16751 }
16752 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16753 // at the end of the first
16754 memory_info.allocationSize = memory_reqs.alignment;
16755 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16756 ASSERT_TRUE(pass);
16757 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16758 ASSERT_VK_SUCCESS(err);
16759 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16760 ASSERT_VK_SUCCESS(err);
16761 VkSparseMemoryBind binds[2];
16762 binds[0].flags = 0;
16763 binds[0].memory = memory_one;
16764 binds[0].memoryOffset = 0;
16765 binds[0].resourceOffset = 0;
16766 binds[0].size = memory_info.allocationSize;
16767 binds[1].flags = 0;
16768 binds[1].memory = memory_two;
16769 binds[1].memoryOffset = 0;
16770 binds[1].resourceOffset = memory_info.allocationSize;
16771 binds[1].size = memory_info.allocationSize;
16772
16773 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16774 opaqueBindInfo.image = image;
16775 opaqueBindInfo.bindCount = 2;
16776 opaqueBindInfo.pBinds = binds;
16777
16778 VkFence fence = VK_NULL_HANDLE;
16779 VkBindSparseInfo bindSparseInfo = {};
16780 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16781 bindSparseInfo.imageOpaqueBindCount = 1;
16782 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16783
16784 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16785 vkQueueWaitIdle(m_device->m_queue);
16786 vkDestroyImage(m_device->device(), image, NULL);
16787 vkFreeMemory(m_device->device(), memory_one, NULL);
16788 vkFreeMemory(m_device->device(), memory_two, NULL);
16789 m_errorMonitor->VerifyNotFound();
16790}
16791
16792TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16793 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16794 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16795 "the command buffer has prior knowledge of that "
16796 "attachment's layout.");
16797
16798 m_errorMonitor->ExpectSuccess();
16799
16800 ASSERT_NO_FATAL_FAILURE(InitState());
16801
16802 // A renderpass with one color attachment.
16803 VkAttachmentDescription attachment = { 0,
16804 VK_FORMAT_R8G8B8A8_UNORM,
16805 VK_SAMPLE_COUNT_1_BIT,
16806 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16807 VK_ATTACHMENT_STORE_OP_STORE,
16808 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16809 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16810 VK_IMAGE_LAYOUT_UNDEFINED,
16811 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16812
16813 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16814
16815 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16816
16817 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16818
16819 VkRenderPass rp;
16820 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16821 ASSERT_VK_SUCCESS(err);
16822
16823 // A compatible framebuffer.
16824 VkImageObj image(m_device);
16825 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16826 ASSERT_TRUE(image.initialized());
16827
16828 VkImageViewCreateInfo ivci = {
16829 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16830 nullptr,
16831 0,
16832 image.handle(),
16833 VK_IMAGE_VIEW_TYPE_2D,
16834 VK_FORMAT_R8G8B8A8_UNORM,
16835 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16836 VK_COMPONENT_SWIZZLE_IDENTITY },
16837 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16838 };
16839 VkImageView view;
16840 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16841 ASSERT_VK_SUCCESS(err);
16842
16843 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16844 VkFramebuffer fb;
16845 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16846 ASSERT_VK_SUCCESS(err);
16847
16848 // Record a single command buffer which uses this renderpass twice. The
16849 // bug is triggered at the beginning of the second renderpass, when the
16850 // command buffer already has a layout recorded for the attachment.
16851 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16852 BeginCommandBuffer();
16853 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16854 vkCmdEndRenderPass(m_commandBuffer->handle());
16855 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16856
16857 m_errorMonitor->VerifyNotFound();
16858
16859 vkCmdEndRenderPass(m_commandBuffer->handle());
16860 EndCommandBuffer();
16861
16862 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16863 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16864 vkDestroyImageView(m_device->device(), view, nullptr);
16865}
16866
16867TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
16868 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
16869 "command buffer, bind them together, then destroy "
16870 "command pool and framebuffer and verify there are no "
16871 "errors.");
16872
16873 m_errorMonitor->ExpectSuccess();
16874
16875 ASSERT_NO_FATAL_FAILURE(InitState());
16876
16877 // A renderpass with one color attachment.
16878 VkAttachmentDescription attachment = { 0,
16879 VK_FORMAT_R8G8B8A8_UNORM,
16880 VK_SAMPLE_COUNT_1_BIT,
16881 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16882 VK_ATTACHMENT_STORE_OP_STORE,
16883 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16884 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16885 VK_IMAGE_LAYOUT_UNDEFINED,
16886 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16887
16888 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16889
16890 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16891
16892 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16893
16894 VkRenderPass rp;
16895 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16896 ASSERT_VK_SUCCESS(err);
16897
16898 // A compatible framebuffer.
16899 VkImageObj image(m_device);
16900 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16901 ASSERT_TRUE(image.initialized());
16902
16903 VkImageViewCreateInfo ivci = {
16904 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16905 nullptr,
16906 0,
16907 image.handle(),
16908 VK_IMAGE_VIEW_TYPE_2D,
16909 VK_FORMAT_R8G8B8A8_UNORM,
16910 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16911 VK_COMPONENT_SWIZZLE_IDENTITY },
16912 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16913 };
16914 VkImageView view;
16915 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16916 ASSERT_VK_SUCCESS(err);
16917
16918 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16919 VkFramebuffer fb;
16920 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16921 ASSERT_VK_SUCCESS(err);
16922
16923 // Explicitly create a command buffer to bind the FB to so that we can then
16924 // destroy the command pool in order to implicitly free command buffer
16925 VkCommandPool command_pool;
16926 VkCommandPoolCreateInfo pool_create_info{};
16927 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16928 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16929 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16930 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16931
16932 VkCommandBuffer command_buffer;
16933 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16934 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16935 command_buffer_allocate_info.commandPool = command_pool;
16936 command_buffer_allocate_info.commandBufferCount = 1;
16937 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16938 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16939
16940 // Begin our cmd buffer with renderpass using our framebuffer
16941 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16942 VkCommandBufferBeginInfo begin_info{};
16943 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16944 vkBeginCommandBuffer(command_buffer, &begin_info);
16945
16946 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16947 vkCmdEndRenderPass(command_buffer);
16948 vkEndCommandBuffer(command_buffer);
16949 vkDestroyImageView(m_device->device(), view, nullptr);
16950 // Destroy command pool to implicitly free command buffer
16951 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16952 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16953 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16954 m_errorMonitor->VerifyNotFound();
16955}
16956
16957TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
16958 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
16959 "transitions for the first subpass");
16960
16961 m_errorMonitor->ExpectSuccess();
16962
16963 ASSERT_NO_FATAL_FAILURE(InitState());
16964
16965 // A renderpass with one color attachment.
16966 VkAttachmentDescription attachment = { 0,
16967 VK_FORMAT_R8G8B8A8_UNORM,
16968 VK_SAMPLE_COUNT_1_BIT,
16969 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16970 VK_ATTACHMENT_STORE_OP_STORE,
16971 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16972 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16973 VK_IMAGE_LAYOUT_UNDEFINED,
16974 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16975
16976 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16977
16978 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16979
16980 VkSubpassDependency dep = { 0,
16981 0,
16982 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16983 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16984 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16985 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16986 VK_DEPENDENCY_BY_REGION_BIT };
16987
16988 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16989
16990 VkResult err;
16991 VkRenderPass rp;
16992 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16993 ASSERT_VK_SUCCESS(err);
16994
16995 // A compatible framebuffer.
16996 VkImageObj image(m_device);
16997 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16998 ASSERT_TRUE(image.initialized());
16999
17000 VkImageViewCreateInfo ivci = {
17001 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17002 nullptr,
17003 0,
17004 image.handle(),
17005 VK_IMAGE_VIEW_TYPE_2D,
17006 VK_FORMAT_R8G8B8A8_UNORM,
17007 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17008 VK_COMPONENT_SWIZZLE_IDENTITY },
17009 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17010 };
17011 VkImageView view;
17012 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17013 ASSERT_VK_SUCCESS(err);
17014
17015 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17016 VkFramebuffer fb;
17017 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17018 ASSERT_VK_SUCCESS(err);
17019
17020 // Record a single command buffer which issues a pipeline barrier w/
17021 // image memory barrier for the attachment. This detects the previously
17022 // missing tracking of the subpass layout by throwing a validation error
17023 // if it doesn't occur.
17024 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17025 BeginCommandBuffer();
17026 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17027
17028 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17029 nullptr,
17030 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17031 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17032 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17033 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17034 VK_QUEUE_FAMILY_IGNORED,
17035 VK_QUEUE_FAMILY_IGNORED,
17036 image.handle(),
17037 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17038 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17039 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17040 &imb);
17041
17042 vkCmdEndRenderPass(m_commandBuffer->handle());
17043 m_errorMonitor->VerifyNotFound();
17044 EndCommandBuffer();
17045
17046 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17047 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17048 vkDestroyImageView(m_device->device(), view, nullptr);
17049}
17050
17051TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17052 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17053 "is used as a depth/stencil framebuffer attachment, the "
17054 "aspectMask is ignored and both depth and stencil image "
17055 "subresources are used.");
17056
17057 VkFormatProperties format_properties;
17058 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17059 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17060 return;
17061 }
17062
17063 m_errorMonitor->ExpectSuccess();
17064
17065 ASSERT_NO_FATAL_FAILURE(InitState());
17066
17067 VkAttachmentDescription attachment = { 0,
17068 VK_FORMAT_D32_SFLOAT_S8_UINT,
17069 VK_SAMPLE_COUNT_1_BIT,
17070 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17071 VK_ATTACHMENT_STORE_OP_STORE,
17072 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17073 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17074 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17075 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17076
17077 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17078
17079 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17080
17081 VkSubpassDependency dep = { 0,
17082 0,
17083 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17084 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17085 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17086 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17087 VK_DEPENDENCY_BY_REGION_BIT};
17088
17089 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17090
17091 VkResult err;
17092 VkRenderPass rp;
17093 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17094 ASSERT_VK_SUCCESS(err);
17095
17096 VkImageObj image(m_device);
17097 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17098 0x26, // usage
17099 VK_IMAGE_TILING_OPTIMAL, 0);
17100 ASSERT_TRUE(image.initialized());
17101 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17102
17103 VkImageViewCreateInfo ivci = {
17104 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17105 nullptr,
17106 0,
17107 image.handle(),
17108 VK_IMAGE_VIEW_TYPE_2D,
17109 VK_FORMAT_D32_SFLOAT_S8_UINT,
17110 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17111 { 0x2, 0, 1, 0, 1 },
17112 };
17113 VkImageView view;
17114 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17115 ASSERT_VK_SUCCESS(err);
17116
17117 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17118 VkFramebuffer fb;
17119 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17120 ASSERT_VK_SUCCESS(err);
17121
17122 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17123 BeginCommandBuffer();
17124 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17125
17126 VkImageMemoryBarrier imb = {};
17127 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17128 imb.pNext = nullptr;
17129 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17130 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17131 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17132 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17133 imb.srcQueueFamilyIndex = 0;
17134 imb.dstQueueFamilyIndex = 0;
17135 imb.image = image.handle();
17136 imb.subresourceRange.aspectMask = 0x6;
17137 imb.subresourceRange.baseMipLevel = 0;
17138 imb.subresourceRange.levelCount = 0x1;
17139 imb.subresourceRange.baseArrayLayer = 0;
17140 imb.subresourceRange.layerCount = 0x1;
17141
17142 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17143 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17144 &imb);
17145
17146 vkCmdEndRenderPass(m_commandBuffer->handle());
17147 EndCommandBuffer();
17148 QueueCommandBuffer(false);
17149 m_errorMonitor->VerifyNotFound();
17150
17151 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17152 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17153 vkDestroyImageView(m_device->device(), view, nullptr);
17154}
17155
17156TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17157 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17158 "errors, when an attachment reference is "
17159 "VK_ATTACHMENT_UNUSED");
17160
17161 m_errorMonitor->ExpectSuccess();
17162
17163 ASSERT_NO_FATAL_FAILURE(InitState());
17164
17165 // A renderpass with no attachments
17166 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17167
17168 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17169
17170 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17171
17172 VkRenderPass rp;
17173 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17174 ASSERT_VK_SUCCESS(err);
17175
17176 // A compatible framebuffer.
17177 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17178 VkFramebuffer fb;
17179 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17180 ASSERT_VK_SUCCESS(err);
17181
17182 // Record a command buffer which just begins and ends the renderpass. The
17183 // bug manifests in BeginRenderPass.
17184 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17185 BeginCommandBuffer();
17186 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17187 vkCmdEndRenderPass(m_commandBuffer->handle());
17188 m_errorMonitor->VerifyNotFound();
17189 EndCommandBuffer();
17190
17191 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17192 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17193}
17194
17195// This is a positive test. No errors are expected.
17196TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17197 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17198 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17199 VkResult result = VK_SUCCESS;
17200 VkImageFormatProperties formatProps;
17201 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17202 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17203 &formatProps);
17204 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17205 return;
17206 }
17207
17208 ASSERT_NO_FATAL_FAILURE(InitState());
17209 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17210 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17211 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17212 VkAttachmentDescription att = {};
17213 VkAttachmentReference ref = {};
17214 att.format = depth_stencil_fmt;
17215 att.samples = VK_SAMPLE_COUNT_1_BIT;
17216 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17217 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17218 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17219 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17220 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17221 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17222
17223 VkClearValue clear;
17224 clear.depthStencil.depth = 1.0;
17225 clear.depthStencil.stencil = 0;
17226 ref.attachment = 0;
17227 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17228
17229 VkSubpassDescription subpass = {};
17230 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17231 subpass.flags = 0;
17232 subpass.inputAttachmentCount = 0;
17233 subpass.pInputAttachments = NULL;
17234 subpass.colorAttachmentCount = 0;
17235 subpass.pColorAttachments = NULL;
17236 subpass.pResolveAttachments = NULL;
17237 subpass.pDepthStencilAttachment = &ref;
17238 subpass.preserveAttachmentCount = 0;
17239 subpass.pPreserveAttachments = NULL;
17240
17241 VkRenderPass rp;
17242 VkRenderPassCreateInfo rp_info = {};
17243 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17244 rp_info.attachmentCount = 1;
17245 rp_info.pAttachments = &att;
17246 rp_info.subpassCount = 1;
17247 rp_info.pSubpasses = &subpass;
17248 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17249 ASSERT_VK_SUCCESS(result);
17250
17251 VkImageView *depthView = m_depthStencil->BindInfo();
17252 VkFramebufferCreateInfo fb_info = {};
17253 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17254 fb_info.pNext = NULL;
17255 fb_info.renderPass = rp;
17256 fb_info.attachmentCount = 1;
17257 fb_info.pAttachments = depthView;
17258 fb_info.width = 100;
17259 fb_info.height = 100;
17260 fb_info.layers = 1;
17261 VkFramebuffer fb;
17262 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17263 ASSERT_VK_SUCCESS(result);
17264
17265 VkRenderPassBeginInfo rpbinfo = {};
17266 rpbinfo.clearValueCount = 1;
17267 rpbinfo.pClearValues = &clear;
17268 rpbinfo.pNext = NULL;
17269 rpbinfo.renderPass = rp;
17270 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17271 rpbinfo.renderArea.extent.width = 100;
17272 rpbinfo.renderArea.extent.height = 100;
17273 rpbinfo.renderArea.offset.x = 0;
17274 rpbinfo.renderArea.offset.y = 0;
17275 rpbinfo.framebuffer = fb;
17276
17277 VkFence fence = {};
17278 VkFenceCreateInfo fence_ci = {};
17279 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17280 fence_ci.pNext = nullptr;
17281 fence_ci.flags = 0;
17282 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17283 ASSERT_VK_SUCCESS(result);
17284
17285 m_commandBuffer->BeginCommandBuffer();
17286 m_commandBuffer->BeginRenderPass(rpbinfo);
17287 m_commandBuffer->EndRenderPass();
17288 m_commandBuffer->EndCommandBuffer();
17289 m_commandBuffer->QueueCommandBuffer(fence);
17290
17291 VkImageObj destImage(m_device);
17292 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17293 VK_IMAGE_TILING_OPTIMAL, 0);
17294 VkImageMemoryBarrier barrier = {};
17295 VkImageSubresourceRange range;
17296 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17297 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17298 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17299 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17300 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17301 barrier.image = m_depthStencil->handle();
17302 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17303 range.baseMipLevel = 0;
17304 range.levelCount = 1;
17305 range.baseArrayLayer = 0;
17306 range.layerCount = 1;
17307 barrier.subresourceRange = range;
17308 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17309 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17310 cmdbuf.BeginCommandBuffer();
17311 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17312 &barrier);
17313 barrier.srcAccessMask = 0;
17314 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17315 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17316 barrier.image = destImage.handle();
17317 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17318 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17319 &barrier);
17320 VkImageCopy cregion;
17321 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17322 cregion.srcSubresource.mipLevel = 0;
17323 cregion.srcSubresource.baseArrayLayer = 0;
17324 cregion.srcSubresource.layerCount = 1;
17325 cregion.srcOffset.x = 0;
17326 cregion.srcOffset.y = 0;
17327 cregion.srcOffset.z = 0;
17328 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17329 cregion.dstSubresource.mipLevel = 0;
17330 cregion.dstSubresource.baseArrayLayer = 0;
17331 cregion.dstSubresource.layerCount = 1;
17332 cregion.dstOffset.x = 0;
17333 cregion.dstOffset.y = 0;
17334 cregion.dstOffset.z = 0;
17335 cregion.extent.width = 100;
17336 cregion.extent.height = 100;
17337 cregion.extent.depth = 1;
17338 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17339 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17340 cmdbuf.EndCommandBuffer();
17341
17342 VkSubmitInfo submit_info;
17343 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17344 submit_info.pNext = NULL;
17345 submit_info.waitSemaphoreCount = 0;
17346 submit_info.pWaitSemaphores = NULL;
17347 submit_info.pWaitDstStageMask = NULL;
17348 submit_info.commandBufferCount = 1;
17349 submit_info.pCommandBuffers = &cmdbuf.handle();
17350 submit_info.signalSemaphoreCount = 0;
17351 submit_info.pSignalSemaphores = NULL;
17352
17353 m_errorMonitor->ExpectSuccess();
17354 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17355 m_errorMonitor->VerifyNotFound();
17356
17357 vkQueueWaitIdle(m_device->m_queue);
17358 vkDestroyFence(m_device->device(), fence, nullptr);
17359 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17360 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17361}
17362
17363// This is a positive test. No errors should be generated.
17364TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17365 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17366
17367 m_errorMonitor->ExpectSuccess();
17368 ASSERT_NO_FATAL_FAILURE(InitState());
17369
17370 VkEvent event;
17371 VkEventCreateInfo event_create_info{};
17372 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17373 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17374
17375 VkCommandPool command_pool;
17376 VkCommandPoolCreateInfo pool_create_info{};
17377 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17378 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17379 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17380 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17381
17382 VkCommandBuffer command_buffer;
17383 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17384 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17385 command_buffer_allocate_info.commandPool = command_pool;
17386 command_buffer_allocate_info.commandBufferCount = 1;
17387 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17388 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17389
17390 VkQueue queue = VK_NULL_HANDLE;
17391 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17392
17393 {
17394 VkCommandBufferBeginInfo begin_info{};
17395 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17396 vkBeginCommandBuffer(command_buffer, &begin_info);
17397
17398 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17399 nullptr, 0, nullptr);
17400 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17401 vkEndCommandBuffer(command_buffer);
17402 }
17403 {
17404 VkSubmitInfo submit_info{};
17405 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17406 submit_info.commandBufferCount = 1;
17407 submit_info.pCommandBuffers = &command_buffer;
17408 submit_info.signalSemaphoreCount = 0;
17409 submit_info.pSignalSemaphores = nullptr;
17410 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17411 }
17412 { vkSetEvent(m_device->device(), event); }
17413
17414 vkQueueWaitIdle(queue);
17415
17416 vkDestroyEvent(m_device->device(), event, nullptr);
17417 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17418 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17419
17420 m_errorMonitor->VerifyNotFound();
17421}
17422// This is a positive test. No errors should be generated.
17423TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17424 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17425
17426 ASSERT_NO_FATAL_FAILURE(InitState());
17427 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17428 return;
17429
17430 m_errorMonitor->ExpectSuccess();
17431
17432 VkQueryPool query_pool;
17433 VkQueryPoolCreateInfo query_pool_create_info{};
17434 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17435 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17436 query_pool_create_info.queryCount = 1;
17437 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17438
17439 VkCommandPool command_pool;
17440 VkCommandPoolCreateInfo pool_create_info{};
17441 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17442 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17443 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17444 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17445
17446 VkCommandBuffer command_buffer;
17447 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17448 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17449 command_buffer_allocate_info.commandPool = command_pool;
17450 command_buffer_allocate_info.commandBufferCount = 1;
17451 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17452 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17453
17454 VkCommandBuffer secondary_command_buffer;
17455 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17456 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17457
17458 VkQueue queue = VK_NULL_HANDLE;
17459 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17460
17461 uint32_t qfi = 0;
17462 VkBufferCreateInfo buff_create_info = {};
17463 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17464 buff_create_info.size = 1024;
17465 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17466 buff_create_info.queueFamilyIndexCount = 1;
17467 buff_create_info.pQueueFamilyIndices = &qfi;
17468
17469 VkResult err;
17470 VkBuffer buffer;
17471 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17472 ASSERT_VK_SUCCESS(err);
17473 VkMemoryAllocateInfo mem_alloc = {};
17474 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17475 mem_alloc.pNext = NULL;
17476 mem_alloc.allocationSize = 1024;
17477 mem_alloc.memoryTypeIndex = 0;
17478
17479 VkMemoryRequirements memReqs;
17480 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17481 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17482 if (!pass) {
17483 vkDestroyBuffer(m_device->device(), buffer, NULL);
17484 return;
17485 }
17486
17487 VkDeviceMemory mem;
17488 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17489 ASSERT_VK_SUCCESS(err);
17490 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17491 ASSERT_VK_SUCCESS(err);
17492
17493 VkCommandBufferInheritanceInfo hinfo = {};
17494 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17495 hinfo.renderPass = VK_NULL_HANDLE;
17496 hinfo.subpass = 0;
17497 hinfo.framebuffer = VK_NULL_HANDLE;
17498 hinfo.occlusionQueryEnable = VK_FALSE;
17499 hinfo.queryFlags = 0;
17500 hinfo.pipelineStatistics = 0;
17501
17502 {
17503 VkCommandBufferBeginInfo begin_info{};
17504 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17505 begin_info.pInheritanceInfo = &hinfo;
17506 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17507
17508 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17509 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17510
17511 vkEndCommandBuffer(secondary_command_buffer);
17512
17513 begin_info.pInheritanceInfo = nullptr;
17514 vkBeginCommandBuffer(command_buffer, &begin_info);
17515
17516 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17517 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17518
17519 vkEndCommandBuffer(command_buffer);
17520 }
17521 {
17522 VkSubmitInfo submit_info{};
17523 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17524 submit_info.commandBufferCount = 1;
17525 submit_info.pCommandBuffers = &command_buffer;
17526 submit_info.signalSemaphoreCount = 0;
17527 submit_info.pSignalSemaphores = nullptr;
17528 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17529 }
17530
17531 vkQueueWaitIdle(queue);
17532
17533 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17534 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17535 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17536 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17537 vkDestroyBuffer(m_device->device(), buffer, NULL);
17538 vkFreeMemory(m_device->device(), mem, NULL);
17539
17540 m_errorMonitor->VerifyNotFound();
17541}
17542
17543// This is a positive test. No errors should be generated.
17544TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17545 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17546
17547 ASSERT_NO_FATAL_FAILURE(InitState());
17548 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17549 return;
17550
17551 m_errorMonitor->ExpectSuccess();
17552
17553 VkQueryPool query_pool;
17554 VkQueryPoolCreateInfo query_pool_create_info{};
17555 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17556 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17557 query_pool_create_info.queryCount = 1;
17558 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17559
17560 VkCommandPool command_pool;
17561 VkCommandPoolCreateInfo pool_create_info{};
17562 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17563 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17564 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17565 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17566
17567 VkCommandBuffer command_buffer[2];
17568 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17569 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17570 command_buffer_allocate_info.commandPool = command_pool;
17571 command_buffer_allocate_info.commandBufferCount = 2;
17572 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17573 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17574
17575 VkQueue queue = VK_NULL_HANDLE;
17576 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17577
17578 uint32_t qfi = 0;
17579 VkBufferCreateInfo buff_create_info = {};
17580 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17581 buff_create_info.size = 1024;
17582 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17583 buff_create_info.queueFamilyIndexCount = 1;
17584 buff_create_info.pQueueFamilyIndices = &qfi;
17585
17586 VkResult err;
17587 VkBuffer buffer;
17588 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17589 ASSERT_VK_SUCCESS(err);
17590 VkMemoryAllocateInfo mem_alloc = {};
17591 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17592 mem_alloc.pNext = NULL;
17593 mem_alloc.allocationSize = 1024;
17594 mem_alloc.memoryTypeIndex = 0;
17595
17596 VkMemoryRequirements memReqs;
17597 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17598 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17599 if (!pass) {
17600 vkDestroyBuffer(m_device->device(), buffer, NULL);
17601 return;
17602 }
17603
17604 VkDeviceMemory mem;
17605 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17606 ASSERT_VK_SUCCESS(err);
17607 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17608 ASSERT_VK_SUCCESS(err);
17609
17610 {
17611 VkCommandBufferBeginInfo begin_info{};
17612 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17613 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17614
17615 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17616 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17617
17618 vkEndCommandBuffer(command_buffer[0]);
17619
17620 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17621
17622 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17623
17624 vkEndCommandBuffer(command_buffer[1]);
17625 }
17626 {
17627 VkSubmitInfo submit_info{};
17628 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17629 submit_info.commandBufferCount = 2;
17630 submit_info.pCommandBuffers = command_buffer;
17631 submit_info.signalSemaphoreCount = 0;
17632 submit_info.pSignalSemaphores = nullptr;
17633 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17634 }
17635
17636 vkQueueWaitIdle(queue);
17637
17638 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17639 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17640 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17641 vkDestroyBuffer(m_device->device(), buffer, NULL);
17642 vkFreeMemory(m_device->device(), mem, NULL);
17643
17644 m_errorMonitor->VerifyNotFound();
17645}
17646
Tony Barbourc46924f2016-11-04 11:49:52 -060017647TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017648 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17649
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017650 ASSERT_NO_FATAL_FAILURE(InitState());
17651 VkEvent event;
17652 VkEventCreateInfo event_create_info{};
17653 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17654 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17655
17656 VkCommandPool command_pool;
17657 VkCommandPoolCreateInfo pool_create_info{};
17658 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17659 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17660 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17661 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17662
17663 VkCommandBuffer command_buffer;
17664 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17665 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17666 command_buffer_allocate_info.commandPool = command_pool;
17667 command_buffer_allocate_info.commandBufferCount = 1;
17668 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17669 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17670
17671 VkQueue queue = VK_NULL_HANDLE;
17672 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17673
17674 {
17675 VkCommandBufferBeginInfo begin_info{};
17676 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17677 vkBeginCommandBuffer(command_buffer, &begin_info);
17678
17679 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017680 vkEndCommandBuffer(command_buffer);
17681 }
17682 {
17683 VkSubmitInfo submit_info{};
17684 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17685 submit_info.commandBufferCount = 1;
17686 submit_info.pCommandBuffers = &command_buffer;
17687 submit_info.signalSemaphoreCount = 0;
17688 submit_info.pSignalSemaphores = nullptr;
17689 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17690 }
17691 {
17692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17693 "command buffer.");
17694 vkSetEvent(m_device->device(), event);
17695 m_errorMonitor->VerifyFound();
17696 }
17697
17698 vkQueueWaitIdle(queue);
17699
17700 vkDestroyEvent(m_device->device(), event, nullptr);
17701 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17702 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17703}
17704
17705// This is a positive test. No errors should be generated.
17706TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17707 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17708 "run through a Submit & WaitForFences cycle 3 times. This "
17709 "previously revealed a bug so running this positive test "
17710 "to prevent a regression.");
17711 m_errorMonitor->ExpectSuccess();
17712
17713 ASSERT_NO_FATAL_FAILURE(InitState());
17714 VkQueue queue = VK_NULL_HANDLE;
17715 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17716
17717 static const uint32_t NUM_OBJECTS = 2;
17718 static const uint32_t NUM_FRAMES = 3;
17719 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17720 VkFence fences[NUM_OBJECTS] = {};
17721
17722 VkCommandPool cmd_pool;
17723 VkCommandPoolCreateInfo cmd_pool_ci = {};
17724 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17725 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17726 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17727 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17728 ASSERT_VK_SUCCESS(err);
17729
17730 VkCommandBufferAllocateInfo cmd_buf_info = {};
17731 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17732 cmd_buf_info.commandPool = cmd_pool;
17733 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17734 cmd_buf_info.commandBufferCount = 1;
17735
17736 VkFenceCreateInfo fence_ci = {};
17737 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17738 fence_ci.pNext = nullptr;
17739 fence_ci.flags = 0;
17740
17741 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17742 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17743 ASSERT_VK_SUCCESS(err);
17744 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17745 ASSERT_VK_SUCCESS(err);
17746 }
17747
17748 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17749 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17750 // Create empty cmd buffer
17751 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17752 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17753
17754 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17755 ASSERT_VK_SUCCESS(err);
17756 err = vkEndCommandBuffer(cmd_buffers[obj]);
17757 ASSERT_VK_SUCCESS(err);
17758
17759 VkSubmitInfo submit_info = {};
17760 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17761 submit_info.commandBufferCount = 1;
17762 submit_info.pCommandBuffers = &cmd_buffers[obj];
17763 // Submit cmd buffer and wait for fence
17764 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17765 ASSERT_VK_SUCCESS(err);
17766 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17767 ASSERT_VK_SUCCESS(err);
17768 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17769 ASSERT_VK_SUCCESS(err);
17770 }
17771 }
17772 m_errorMonitor->VerifyNotFound();
17773 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17774 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17775 vkDestroyFence(m_device->device(), fences[i], nullptr);
17776 }
17777}
17778// This is a positive test. No errors should be generated.
17779TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17780
17781 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17782 "submitted on separate queues followed by a QueueWaitIdle.");
17783
17784 ASSERT_NO_FATAL_FAILURE(InitState());
17785 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17786 return;
17787
17788 m_errorMonitor->ExpectSuccess();
17789
17790 VkSemaphore semaphore;
17791 VkSemaphoreCreateInfo semaphore_create_info{};
17792 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17793 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17794
17795 VkCommandPool command_pool;
17796 VkCommandPoolCreateInfo pool_create_info{};
17797 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17798 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17799 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17800 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17801
17802 VkCommandBuffer command_buffer[2];
17803 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17804 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17805 command_buffer_allocate_info.commandPool = command_pool;
17806 command_buffer_allocate_info.commandBufferCount = 2;
17807 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17808 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17809
17810 VkQueue queue = VK_NULL_HANDLE;
17811 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17812
17813 {
17814 VkCommandBufferBeginInfo begin_info{};
17815 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17816 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17817
17818 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17819 nullptr, 0, nullptr, 0, nullptr);
17820
17821 VkViewport viewport{};
17822 viewport.maxDepth = 1.0f;
17823 viewport.minDepth = 0.0f;
17824 viewport.width = 512;
17825 viewport.height = 512;
17826 viewport.x = 0;
17827 viewport.y = 0;
17828 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17829 vkEndCommandBuffer(command_buffer[0]);
17830 }
17831 {
17832 VkCommandBufferBeginInfo begin_info{};
17833 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17834 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17835
17836 VkViewport viewport{};
17837 viewport.maxDepth = 1.0f;
17838 viewport.minDepth = 0.0f;
17839 viewport.width = 512;
17840 viewport.height = 512;
17841 viewport.x = 0;
17842 viewport.y = 0;
17843 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17844 vkEndCommandBuffer(command_buffer[1]);
17845 }
17846 {
17847 VkSubmitInfo submit_info{};
17848 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17849 submit_info.commandBufferCount = 1;
17850 submit_info.pCommandBuffers = &command_buffer[0];
17851 submit_info.signalSemaphoreCount = 1;
17852 submit_info.pSignalSemaphores = &semaphore;
17853 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17854 }
17855 {
17856 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17857 VkSubmitInfo submit_info{};
17858 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17859 submit_info.commandBufferCount = 1;
17860 submit_info.pCommandBuffers = &command_buffer[1];
17861 submit_info.waitSemaphoreCount = 1;
17862 submit_info.pWaitSemaphores = &semaphore;
17863 submit_info.pWaitDstStageMask = flags;
17864 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17865 }
17866
17867 vkQueueWaitIdle(m_device->m_queue);
17868
17869 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17870 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17871 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17872
17873 m_errorMonitor->VerifyNotFound();
17874}
17875
17876// This is a positive test. No errors should be generated.
17877TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
17878
17879 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17880 "submitted on separate queues, the second having a fence"
17881 "followed by a QueueWaitIdle.");
17882
17883 ASSERT_NO_FATAL_FAILURE(InitState());
17884 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17885 return;
17886
17887 m_errorMonitor->ExpectSuccess();
17888
17889 VkFence fence;
17890 VkFenceCreateInfo fence_create_info{};
17891 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17892 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17893
17894 VkSemaphore semaphore;
17895 VkSemaphoreCreateInfo semaphore_create_info{};
17896 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17897 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17898
17899 VkCommandPool command_pool;
17900 VkCommandPoolCreateInfo pool_create_info{};
17901 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17902 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17903 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17904 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17905
17906 VkCommandBuffer command_buffer[2];
17907 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17908 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17909 command_buffer_allocate_info.commandPool = command_pool;
17910 command_buffer_allocate_info.commandBufferCount = 2;
17911 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17912 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17913
17914 VkQueue queue = VK_NULL_HANDLE;
17915 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17916
17917 {
17918 VkCommandBufferBeginInfo begin_info{};
17919 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17920 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17921
17922 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17923 nullptr, 0, nullptr, 0, nullptr);
17924
17925 VkViewport viewport{};
17926 viewport.maxDepth = 1.0f;
17927 viewport.minDepth = 0.0f;
17928 viewport.width = 512;
17929 viewport.height = 512;
17930 viewport.x = 0;
17931 viewport.y = 0;
17932 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17933 vkEndCommandBuffer(command_buffer[0]);
17934 }
17935 {
17936 VkCommandBufferBeginInfo begin_info{};
17937 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17938 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17939
17940 VkViewport viewport{};
17941 viewport.maxDepth = 1.0f;
17942 viewport.minDepth = 0.0f;
17943 viewport.width = 512;
17944 viewport.height = 512;
17945 viewport.x = 0;
17946 viewport.y = 0;
17947 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17948 vkEndCommandBuffer(command_buffer[1]);
17949 }
17950 {
17951 VkSubmitInfo submit_info{};
17952 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17953 submit_info.commandBufferCount = 1;
17954 submit_info.pCommandBuffers = &command_buffer[0];
17955 submit_info.signalSemaphoreCount = 1;
17956 submit_info.pSignalSemaphores = &semaphore;
17957 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17958 }
17959 {
17960 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17961 VkSubmitInfo submit_info{};
17962 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17963 submit_info.commandBufferCount = 1;
17964 submit_info.pCommandBuffers = &command_buffer[1];
17965 submit_info.waitSemaphoreCount = 1;
17966 submit_info.pWaitSemaphores = &semaphore;
17967 submit_info.pWaitDstStageMask = flags;
17968 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17969 }
17970
17971 vkQueueWaitIdle(m_device->m_queue);
17972
17973 vkDestroyFence(m_device->device(), fence, nullptr);
17974 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17975 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17976 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17977
17978 m_errorMonitor->VerifyNotFound();
17979}
17980
17981// This is a positive test. No errors should be generated.
17982TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
17983
17984 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17985 "submitted on separate queues, the second having a fence"
17986 "followed by two consecutive WaitForFences calls on the same fence.");
17987
17988 ASSERT_NO_FATAL_FAILURE(InitState());
17989 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17990 return;
17991
17992 m_errorMonitor->ExpectSuccess();
17993
17994 VkFence fence;
17995 VkFenceCreateInfo fence_create_info{};
17996 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17997 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17998
17999 VkSemaphore semaphore;
18000 VkSemaphoreCreateInfo semaphore_create_info{};
18001 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18002 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18003
18004 VkCommandPool command_pool;
18005 VkCommandPoolCreateInfo pool_create_info{};
18006 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18007 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18008 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18009 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18010
18011 VkCommandBuffer command_buffer[2];
18012 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18013 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18014 command_buffer_allocate_info.commandPool = command_pool;
18015 command_buffer_allocate_info.commandBufferCount = 2;
18016 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18017 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18018
18019 VkQueue queue = VK_NULL_HANDLE;
18020 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18021
18022 {
18023 VkCommandBufferBeginInfo begin_info{};
18024 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18025 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18026
18027 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18028 nullptr, 0, nullptr, 0, nullptr);
18029
18030 VkViewport viewport{};
18031 viewport.maxDepth = 1.0f;
18032 viewport.minDepth = 0.0f;
18033 viewport.width = 512;
18034 viewport.height = 512;
18035 viewport.x = 0;
18036 viewport.y = 0;
18037 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18038 vkEndCommandBuffer(command_buffer[0]);
18039 }
18040 {
18041 VkCommandBufferBeginInfo begin_info{};
18042 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18043 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18044
18045 VkViewport viewport{};
18046 viewport.maxDepth = 1.0f;
18047 viewport.minDepth = 0.0f;
18048 viewport.width = 512;
18049 viewport.height = 512;
18050 viewport.x = 0;
18051 viewport.y = 0;
18052 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18053 vkEndCommandBuffer(command_buffer[1]);
18054 }
18055 {
18056 VkSubmitInfo submit_info{};
18057 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18058 submit_info.commandBufferCount = 1;
18059 submit_info.pCommandBuffers = &command_buffer[0];
18060 submit_info.signalSemaphoreCount = 1;
18061 submit_info.pSignalSemaphores = &semaphore;
18062 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18063 }
18064 {
18065 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18066 VkSubmitInfo submit_info{};
18067 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18068 submit_info.commandBufferCount = 1;
18069 submit_info.pCommandBuffers = &command_buffer[1];
18070 submit_info.waitSemaphoreCount = 1;
18071 submit_info.pWaitSemaphores = &semaphore;
18072 submit_info.pWaitDstStageMask = flags;
18073 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18074 }
18075
18076 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18077 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18078
18079 vkDestroyFence(m_device->device(), fence, nullptr);
18080 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18081 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18082 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18083
18084 m_errorMonitor->VerifyNotFound();
18085}
18086
18087TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18088
18089 ASSERT_NO_FATAL_FAILURE(InitState());
18090 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18091 printf("Test requires two queues, skipping\n");
18092 return;
18093 }
18094
18095 VkResult err;
18096
18097 m_errorMonitor->ExpectSuccess();
18098
18099 VkQueue q0 = m_device->m_queue;
18100 VkQueue q1 = nullptr;
18101 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18102 ASSERT_NE(q1, nullptr);
18103
18104 // An (empty) command buffer. We must have work in the first submission --
18105 // the layer treats unfenced work differently from fenced work.
18106 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18107 VkCommandPool pool;
18108 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18109 ASSERT_VK_SUCCESS(err);
18110 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18111 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18112 VkCommandBuffer cb;
18113 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18114 ASSERT_VK_SUCCESS(err);
18115 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18116 err = vkBeginCommandBuffer(cb, &cbbi);
18117 ASSERT_VK_SUCCESS(err);
18118 err = vkEndCommandBuffer(cb);
18119 ASSERT_VK_SUCCESS(err);
18120
18121 // A semaphore
18122 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18123 VkSemaphore s;
18124 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18125 ASSERT_VK_SUCCESS(err);
18126
18127 // First submission, to q0
18128 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18129
18130 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18131 ASSERT_VK_SUCCESS(err);
18132
18133 // Second submission, to q1, waiting on s
18134 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18135 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18136
18137 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18138 ASSERT_VK_SUCCESS(err);
18139
18140 // Wait for q0 idle
18141 err = vkQueueWaitIdle(q0);
18142 ASSERT_VK_SUCCESS(err);
18143
18144 // Command buffer should have been completed (it was on q0); reset the pool.
18145 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18146
18147 m_errorMonitor->VerifyNotFound();
18148
18149 // Force device completely idle and clean up resources
18150 vkDeviceWaitIdle(m_device->device());
18151 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18152 vkDestroySemaphore(m_device->device(), s, nullptr);
18153}
18154
18155// This is a positive test. No errors should be generated.
18156TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18157
18158 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18159 "submitted on separate queues, the second having a fence, "
18160 "followed by a WaitForFences call.");
18161
18162 ASSERT_NO_FATAL_FAILURE(InitState());
18163 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18164 return;
18165
18166 m_errorMonitor->ExpectSuccess();
18167
18168 ASSERT_NO_FATAL_FAILURE(InitState());
18169 VkFence fence;
18170 VkFenceCreateInfo fence_create_info{};
18171 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18172 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18173
18174 VkSemaphore semaphore;
18175 VkSemaphoreCreateInfo semaphore_create_info{};
18176 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18177 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18178
18179 VkCommandPool command_pool;
18180 VkCommandPoolCreateInfo pool_create_info{};
18181 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18182 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18183 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18184 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18185
18186 VkCommandBuffer command_buffer[2];
18187 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18188 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18189 command_buffer_allocate_info.commandPool = command_pool;
18190 command_buffer_allocate_info.commandBufferCount = 2;
18191 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18192 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18193
18194 VkQueue queue = VK_NULL_HANDLE;
18195 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18196
18197 {
18198 VkCommandBufferBeginInfo begin_info{};
18199 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18200 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18201
18202 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18203 nullptr, 0, nullptr, 0, nullptr);
18204
18205 VkViewport viewport{};
18206 viewport.maxDepth = 1.0f;
18207 viewport.minDepth = 0.0f;
18208 viewport.width = 512;
18209 viewport.height = 512;
18210 viewport.x = 0;
18211 viewport.y = 0;
18212 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18213 vkEndCommandBuffer(command_buffer[0]);
18214 }
18215 {
18216 VkCommandBufferBeginInfo begin_info{};
18217 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18218 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18219
18220 VkViewport viewport{};
18221 viewport.maxDepth = 1.0f;
18222 viewport.minDepth = 0.0f;
18223 viewport.width = 512;
18224 viewport.height = 512;
18225 viewport.x = 0;
18226 viewport.y = 0;
18227 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18228 vkEndCommandBuffer(command_buffer[1]);
18229 }
18230 {
18231 VkSubmitInfo submit_info{};
18232 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18233 submit_info.commandBufferCount = 1;
18234 submit_info.pCommandBuffers = &command_buffer[0];
18235 submit_info.signalSemaphoreCount = 1;
18236 submit_info.pSignalSemaphores = &semaphore;
18237 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18238 }
18239 {
18240 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18241 VkSubmitInfo submit_info{};
18242 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18243 submit_info.commandBufferCount = 1;
18244 submit_info.pCommandBuffers = &command_buffer[1];
18245 submit_info.waitSemaphoreCount = 1;
18246 submit_info.pWaitSemaphores = &semaphore;
18247 submit_info.pWaitDstStageMask = flags;
18248 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18249 }
18250
18251 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18252
18253 vkDestroyFence(m_device->device(), fence, nullptr);
18254 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18255 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18256 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18257
18258 m_errorMonitor->VerifyNotFound();
18259}
18260
18261// This is a positive test. No errors should be generated.
18262TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18263
18264 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18265 "on the same queue, sharing a signal/wait semaphore, the "
18266 "second having a fence, "
18267 "followed by a WaitForFences call.");
18268
18269 m_errorMonitor->ExpectSuccess();
18270
18271 ASSERT_NO_FATAL_FAILURE(InitState());
18272 VkFence fence;
18273 VkFenceCreateInfo fence_create_info{};
18274 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18275 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18276
18277 VkSemaphore semaphore;
18278 VkSemaphoreCreateInfo semaphore_create_info{};
18279 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18280 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18281
18282 VkCommandPool command_pool;
18283 VkCommandPoolCreateInfo pool_create_info{};
18284 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18285 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18286 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18287 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18288
18289 VkCommandBuffer command_buffer[2];
18290 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18291 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18292 command_buffer_allocate_info.commandPool = command_pool;
18293 command_buffer_allocate_info.commandBufferCount = 2;
18294 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18295 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18296
18297 {
18298 VkCommandBufferBeginInfo begin_info{};
18299 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18300 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18301
18302 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18303 nullptr, 0, nullptr, 0, nullptr);
18304
18305 VkViewport viewport{};
18306 viewport.maxDepth = 1.0f;
18307 viewport.minDepth = 0.0f;
18308 viewport.width = 512;
18309 viewport.height = 512;
18310 viewport.x = 0;
18311 viewport.y = 0;
18312 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18313 vkEndCommandBuffer(command_buffer[0]);
18314 }
18315 {
18316 VkCommandBufferBeginInfo begin_info{};
18317 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18318 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18319
18320 VkViewport viewport{};
18321 viewport.maxDepth = 1.0f;
18322 viewport.minDepth = 0.0f;
18323 viewport.width = 512;
18324 viewport.height = 512;
18325 viewport.x = 0;
18326 viewport.y = 0;
18327 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18328 vkEndCommandBuffer(command_buffer[1]);
18329 }
18330 {
18331 VkSubmitInfo submit_info{};
18332 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18333 submit_info.commandBufferCount = 1;
18334 submit_info.pCommandBuffers = &command_buffer[0];
18335 submit_info.signalSemaphoreCount = 1;
18336 submit_info.pSignalSemaphores = &semaphore;
18337 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18338 }
18339 {
18340 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18341 VkSubmitInfo submit_info{};
18342 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18343 submit_info.commandBufferCount = 1;
18344 submit_info.pCommandBuffers = &command_buffer[1];
18345 submit_info.waitSemaphoreCount = 1;
18346 submit_info.pWaitSemaphores = &semaphore;
18347 submit_info.pWaitDstStageMask = flags;
18348 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18349 }
18350
18351 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18352
18353 vkDestroyFence(m_device->device(), fence, nullptr);
18354 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18355 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18356 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18357
18358 m_errorMonitor->VerifyNotFound();
18359}
18360
18361// This is a positive test. No errors should be generated.
18362TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18363
18364 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18365 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18366 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18367
18368 m_errorMonitor->ExpectSuccess();
18369
18370 ASSERT_NO_FATAL_FAILURE(InitState());
18371 VkFence fence;
18372 VkFenceCreateInfo fence_create_info{};
18373 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18374 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18375
18376 VkCommandPool command_pool;
18377 VkCommandPoolCreateInfo pool_create_info{};
18378 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18379 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18380 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18381 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18382
18383 VkCommandBuffer command_buffer[2];
18384 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18385 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18386 command_buffer_allocate_info.commandPool = command_pool;
18387 command_buffer_allocate_info.commandBufferCount = 2;
18388 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18389 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18390
18391 {
18392 VkCommandBufferBeginInfo begin_info{};
18393 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18394 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18395
18396 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18397 nullptr, 0, nullptr, 0, nullptr);
18398
18399 VkViewport viewport{};
18400 viewport.maxDepth = 1.0f;
18401 viewport.minDepth = 0.0f;
18402 viewport.width = 512;
18403 viewport.height = 512;
18404 viewport.x = 0;
18405 viewport.y = 0;
18406 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18407 vkEndCommandBuffer(command_buffer[0]);
18408 }
18409 {
18410 VkCommandBufferBeginInfo begin_info{};
18411 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18412 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18413
18414 VkViewport viewport{};
18415 viewport.maxDepth = 1.0f;
18416 viewport.minDepth = 0.0f;
18417 viewport.width = 512;
18418 viewport.height = 512;
18419 viewport.x = 0;
18420 viewport.y = 0;
18421 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18422 vkEndCommandBuffer(command_buffer[1]);
18423 }
18424 {
18425 VkSubmitInfo submit_info{};
18426 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18427 submit_info.commandBufferCount = 1;
18428 submit_info.pCommandBuffers = &command_buffer[0];
18429 submit_info.signalSemaphoreCount = 0;
18430 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18431 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18432 }
18433 {
18434 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18435 VkSubmitInfo submit_info{};
18436 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18437 submit_info.commandBufferCount = 1;
18438 submit_info.pCommandBuffers = &command_buffer[1];
18439 submit_info.waitSemaphoreCount = 0;
18440 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18441 submit_info.pWaitDstStageMask = flags;
18442 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18443 }
18444
18445 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18446
18447 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18448 ASSERT_VK_SUCCESS(err);
18449
18450 vkDestroyFence(m_device->device(), fence, nullptr);
18451 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18452 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18453
18454 m_errorMonitor->VerifyNotFound();
18455}
18456
18457// This is a positive test. No errors should be generated.
18458TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18459
18460 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18461 "on the same queue, the second having a fence, followed "
18462 "by a WaitForFences call.");
18463
18464 m_errorMonitor->ExpectSuccess();
18465
18466 ASSERT_NO_FATAL_FAILURE(InitState());
18467 VkFence fence;
18468 VkFenceCreateInfo fence_create_info{};
18469 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18470 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18471
18472 VkCommandPool command_pool;
18473 VkCommandPoolCreateInfo pool_create_info{};
18474 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18475 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18476 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18477 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18478
18479 VkCommandBuffer command_buffer[2];
18480 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18481 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18482 command_buffer_allocate_info.commandPool = command_pool;
18483 command_buffer_allocate_info.commandBufferCount = 2;
18484 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18485 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18486
18487 {
18488 VkCommandBufferBeginInfo begin_info{};
18489 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18490 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18491
18492 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18493 nullptr, 0, nullptr, 0, nullptr);
18494
18495 VkViewport viewport{};
18496 viewport.maxDepth = 1.0f;
18497 viewport.minDepth = 0.0f;
18498 viewport.width = 512;
18499 viewport.height = 512;
18500 viewport.x = 0;
18501 viewport.y = 0;
18502 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18503 vkEndCommandBuffer(command_buffer[0]);
18504 }
18505 {
18506 VkCommandBufferBeginInfo begin_info{};
18507 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18508 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18509
18510 VkViewport viewport{};
18511 viewport.maxDepth = 1.0f;
18512 viewport.minDepth = 0.0f;
18513 viewport.width = 512;
18514 viewport.height = 512;
18515 viewport.x = 0;
18516 viewport.y = 0;
18517 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18518 vkEndCommandBuffer(command_buffer[1]);
18519 }
18520 {
18521 VkSubmitInfo submit_info{};
18522 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18523 submit_info.commandBufferCount = 1;
18524 submit_info.pCommandBuffers = &command_buffer[0];
18525 submit_info.signalSemaphoreCount = 0;
18526 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18527 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18528 }
18529 {
18530 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18531 VkSubmitInfo submit_info{};
18532 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18533 submit_info.commandBufferCount = 1;
18534 submit_info.pCommandBuffers = &command_buffer[1];
18535 submit_info.waitSemaphoreCount = 0;
18536 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18537 submit_info.pWaitDstStageMask = flags;
18538 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18539 }
18540
18541 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18542
18543 vkDestroyFence(m_device->device(), fence, nullptr);
18544 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18545 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18546
18547 m_errorMonitor->VerifyNotFound();
18548}
18549
18550// This is a positive test. No errors should be generated.
18551TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18552
18553 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18554 "QueueSubmit call followed by a WaitForFences call.");
18555 ASSERT_NO_FATAL_FAILURE(InitState());
18556
18557 m_errorMonitor->ExpectSuccess();
18558
18559 VkFence fence;
18560 VkFenceCreateInfo fence_create_info{};
18561 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18562 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18563
18564 VkSemaphore semaphore;
18565 VkSemaphoreCreateInfo semaphore_create_info{};
18566 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18567 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18568
18569 VkCommandPool command_pool;
18570 VkCommandPoolCreateInfo pool_create_info{};
18571 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18572 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18573 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18574 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18575
18576 VkCommandBuffer command_buffer[2];
18577 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18578 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18579 command_buffer_allocate_info.commandPool = command_pool;
18580 command_buffer_allocate_info.commandBufferCount = 2;
18581 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18582 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18583
18584 {
18585 VkCommandBufferBeginInfo begin_info{};
18586 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18587 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18588
18589 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18590 nullptr, 0, nullptr, 0, nullptr);
18591
18592 VkViewport viewport{};
18593 viewport.maxDepth = 1.0f;
18594 viewport.minDepth = 0.0f;
18595 viewport.width = 512;
18596 viewport.height = 512;
18597 viewport.x = 0;
18598 viewport.y = 0;
18599 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18600 vkEndCommandBuffer(command_buffer[0]);
18601 }
18602 {
18603 VkCommandBufferBeginInfo begin_info{};
18604 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18605 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18606
18607 VkViewport viewport{};
18608 viewport.maxDepth = 1.0f;
18609 viewport.minDepth = 0.0f;
18610 viewport.width = 512;
18611 viewport.height = 512;
18612 viewport.x = 0;
18613 viewport.y = 0;
18614 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18615 vkEndCommandBuffer(command_buffer[1]);
18616 }
18617 {
18618 VkSubmitInfo submit_info[2];
18619 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18620
18621 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18622 submit_info[0].pNext = NULL;
18623 submit_info[0].commandBufferCount = 1;
18624 submit_info[0].pCommandBuffers = &command_buffer[0];
18625 submit_info[0].signalSemaphoreCount = 1;
18626 submit_info[0].pSignalSemaphores = &semaphore;
18627 submit_info[0].waitSemaphoreCount = 0;
18628 submit_info[0].pWaitSemaphores = NULL;
18629 submit_info[0].pWaitDstStageMask = 0;
18630
18631 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18632 submit_info[1].pNext = NULL;
18633 submit_info[1].commandBufferCount = 1;
18634 submit_info[1].pCommandBuffers = &command_buffer[1];
18635 submit_info[1].waitSemaphoreCount = 1;
18636 submit_info[1].pWaitSemaphores = &semaphore;
18637 submit_info[1].pWaitDstStageMask = flags;
18638 submit_info[1].signalSemaphoreCount = 0;
18639 submit_info[1].pSignalSemaphores = NULL;
18640 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18641 }
18642
18643 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18644
18645 vkDestroyFence(m_device->device(), fence, nullptr);
18646 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18647 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18648 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18649
18650 m_errorMonitor->VerifyNotFound();
18651}
18652
18653TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18654 m_errorMonitor->ExpectSuccess();
18655
18656 ASSERT_NO_FATAL_FAILURE(InitState());
18657 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18658
18659 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18660 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18661
18662 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18663 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18664 m_errorMonitor->VerifyNotFound();
18665 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18666 m_errorMonitor->VerifyNotFound();
18667 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18668 m_errorMonitor->VerifyNotFound();
18669
18670 m_commandBuffer->EndCommandBuffer();
18671 m_errorMonitor->VerifyNotFound();
18672}
18673
18674TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18675 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18676 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18677 "has a valid layout, and a second subpass then uses a "
18678 "valid *READ_ONLY* layout.");
18679 m_errorMonitor->ExpectSuccess();
18680 ASSERT_NO_FATAL_FAILURE(InitState());
18681
18682 VkAttachmentReference attach[2] = {};
18683 attach[0].attachment = 0;
18684 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18685 attach[1].attachment = 0;
18686 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18687 VkSubpassDescription subpasses[2] = {};
18688 // First subpass clears DS attach on load
18689 subpasses[0].pDepthStencilAttachment = &attach[0];
18690 // 2nd subpass reads in DS as input attachment
18691 subpasses[1].inputAttachmentCount = 1;
18692 subpasses[1].pInputAttachments = &attach[1];
18693 VkAttachmentDescription attach_desc = {};
18694 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18695 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18696 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18697 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18698 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18699 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18700 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18701 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18702 VkRenderPassCreateInfo rpci = {};
18703 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18704 rpci.attachmentCount = 1;
18705 rpci.pAttachments = &attach_desc;
18706 rpci.subpassCount = 2;
18707 rpci.pSubpasses = subpasses;
18708
18709 // Now create RenderPass and verify no errors
18710 VkRenderPass rp;
18711 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18712 m_errorMonitor->VerifyNotFound();
18713
18714 vkDestroyRenderPass(m_device->device(), rp, NULL);
18715}
18716
18717TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18718 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18719 "as vertex attributes");
18720 m_errorMonitor->ExpectSuccess();
18721
18722 ASSERT_NO_FATAL_FAILURE(InitState());
18723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18724
18725 VkVertexInputBindingDescription input_binding;
18726 memset(&input_binding, 0, sizeof(input_binding));
18727
18728 VkVertexInputAttributeDescription input_attribs[2];
18729 memset(input_attribs, 0, sizeof(input_attribs));
18730
18731 for (int i = 0; i < 2; i++) {
18732 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18733 input_attribs[i].location = i;
18734 }
18735
18736 char const *vsSource = "#version 450\n"
18737 "\n"
18738 "layout(location=0) in mat2x4 x;\n"
18739 "out gl_PerVertex {\n"
18740 " vec4 gl_Position;\n"
18741 "};\n"
18742 "void main(){\n"
18743 " gl_Position = x[0] + x[1];\n"
18744 "}\n";
18745 char const *fsSource = "#version 450\n"
18746 "\n"
18747 "layout(location=0) out vec4 color;\n"
18748 "void main(){\n"
18749 " color = vec4(1);\n"
18750 "}\n";
18751
18752 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18753 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18754
18755 VkPipelineObj pipe(m_device);
18756 pipe.AddColorAttachment();
18757 pipe.AddShader(&vs);
18758 pipe.AddShader(&fs);
18759
18760 pipe.AddVertexInputBindings(&input_binding, 1);
18761 pipe.AddVertexInputAttribs(input_attribs, 2);
18762
18763 VkDescriptorSetObj descriptorSet(m_device);
18764 descriptorSet.AppendDummy();
18765 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18766
18767 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18768
18769 /* expect success */
18770 m_errorMonitor->VerifyNotFound();
18771}
18772
18773TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18774 m_errorMonitor->ExpectSuccess();
18775
18776 ASSERT_NO_FATAL_FAILURE(InitState());
18777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18778
18779 VkVertexInputBindingDescription input_binding;
18780 memset(&input_binding, 0, sizeof(input_binding));
18781
18782 VkVertexInputAttributeDescription input_attribs[2];
18783 memset(input_attribs, 0, sizeof(input_attribs));
18784
18785 for (int i = 0; i < 2; i++) {
18786 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18787 input_attribs[i].location = i;
18788 }
18789
18790 char const *vsSource = "#version 450\n"
18791 "\n"
18792 "layout(location=0) in vec4 x[2];\n"
18793 "out gl_PerVertex {\n"
18794 " vec4 gl_Position;\n"
18795 "};\n"
18796 "void main(){\n"
18797 " gl_Position = x[0] + x[1];\n"
18798 "}\n";
18799 char const *fsSource = "#version 450\n"
18800 "\n"
18801 "layout(location=0) out vec4 color;\n"
18802 "void main(){\n"
18803 " color = vec4(1);\n"
18804 "}\n";
18805
18806 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18807 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18808
18809 VkPipelineObj pipe(m_device);
18810 pipe.AddColorAttachment();
18811 pipe.AddShader(&vs);
18812 pipe.AddShader(&fs);
18813
18814 pipe.AddVertexInputBindings(&input_binding, 1);
18815 pipe.AddVertexInputAttribs(input_attribs, 2);
18816
18817 VkDescriptorSetObj descriptorSet(m_device);
18818 descriptorSet.AppendDummy();
18819 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18820
18821 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18822
18823 m_errorMonitor->VerifyNotFound();
18824}
18825
18826TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18827 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18828 "through multiple vertex shader inputs, each consuming a different "
18829 "subset of the components.");
18830 m_errorMonitor->ExpectSuccess();
18831
18832 ASSERT_NO_FATAL_FAILURE(InitState());
18833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18834
18835 VkVertexInputBindingDescription input_binding;
18836 memset(&input_binding, 0, sizeof(input_binding));
18837
18838 VkVertexInputAttributeDescription input_attribs[3];
18839 memset(input_attribs, 0, sizeof(input_attribs));
18840
18841 for (int i = 0; i < 3; i++) {
18842 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18843 input_attribs[i].location = i;
18844 }
18845
18846 char const *vsSource = "#version 450\n"
18847 "\n"
18848 "layout(location=0) in vec4 x;\n"
18849 "layout(location=1) in vec3 y1;\n"
18850 "layout(location=1, component=3) in float y2;\n"
18851 "layout(location=2) in vec4 z;\n"
18852 "out gl_PerVertex {\n"
18853 " vec4 gl_Position;\n"
18854 "};\n"
18855 "void main(){\n"
18856 " gl_Position = x + vec4(y1, y2) + z;\n"
18857 "}\n";
18858 char const *fsSource = "#version 450\n"
18859 "\n"
18860 "layout(location=0) out vec4 color;\n"
18861 "void main(){\n"
18862 " color = vec4(1);\n"
18863 "}\n";
18864
18865 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18866 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18867
18868 VkPipelineObj pipe(m_device);
18869 pipe.AddColorAttachment();
18870 pipe.AddShader(&vs);
18871 pipe.AddShader(&fs);
18872
18873 pipe.AddVertexInputBindings(&input_binding, 1);
18874 pipe.AddVertexInputAttribs(input_attribs, 3);
18875
18876 VkDescriptorSetObj descriptorSet(m_device);
18877 descriptorSet.AppendDummy();
18878 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18879
18880 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18881
18882 m_errorMonitor->VerifyNotFound();
18883}
18884
18885TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
18886 m_errorMonitor->ExpectSuccess();
18887
18888 ASSERT_NO_FATAL_FAILURE(InitState());
18889 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18890
18891 char const *vsSource = "#version 450\n"
18892 "out gl_PerVertex {\n"
18893 " vec4 gl_Position;\n"
18894 "};\n"
18895 "void main(){\n"
18896 " gl_Position = vec4(0);\n"
18897 "}\n";
18898 char const *fsSource = "#version 450\n"
18899 "\n"
18900 "layout(location=0) out vec4 color;\n"
18901 "void main(){\n"
18902 " color = vec4(1);\n"
18903 "}\n";
18904
18905 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18906 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18907
18908 VkPipelineObj pipe(m_device);
18909 pipe.AddColorAttachment();
18910 pipe.AddShader(&vs);
18911 pipe.AddShader(&fs);
18912
18913 VkDescriptorSetObj descriptorSet(m_device);
18914 descriptorSet.AppendDummy();
18915 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18916
18917 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18918
18919 m_errorMonitor->VerifyNotFound();
18920}
18921
18922TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
18923 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
18924 "set out in 14.1.3: fundamental type must match, and producer side must "
18925 "have at least as many components");
18926 m_errorMonitor->ExpectSuccess();
18927
18928 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
18929
18930 ASSERT_NO_FATAL_FAILURE(InitState());
18931 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18932
18933 char const *vsSource = "#version 450\n"
18934 "out gl_PerVertex {\n"
18935 " vec4 gl_Position;\n"
18936 "};\n"
18937 "layout(location=0) out vec3 x;\n"
18938 "layout(location=1) out ivec3 y;\n"
18939 "layout(location=2) out vec3 z;\n"
18940 "void main(){\n"
18941 " gl_Position = vec4(0);\n"
18942 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
18943 "}\n";
18944 char const *fsSource = "#version 450\n"
18945 "\n"
18946 "layout(location=0) out vec4 color;\n"
18947 "layout(location=0) in float x;\n"
18948 "layout(location=1) flat in int y;\n"
18949 "layout(location=2) in vec2 z;\n"
18950 "void main(){\n"
18951 " color = vec4(1 + x + y + z.x);\n"
18952 "}\n";
18953
18954 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18955 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18956
18957 VkPipelineObj pipe(m_device);
18958 pipe.AddColorAttachment();
18959 pipe.AddShader(&vs);
18960 pipe.AddShader(&fs);
18961
18962 VkDescriptorSetObj descriptorSet(m_device);
18963 descriptorSet.AppendDummy();
18964 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18965
18966 VkResult err = VK_SUCCESS;
18967 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18968 ASSERT_VK_SUCCESS(err);
18969
18970 m_errorMonitor->VerifyNotFound();
18971}
18972
18973TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
18974 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
18975 "passed between the TCS and TES stages");
18976 m_errorMonitor->ExpectSuccess();
18977
18978 ASSERT_NO_FATAL_FAILURE(InitState());
18979 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18980
18981 if (!m_device->phy().features().tessellationShader) {
18982 printf("Device does not support tessellation shaders; skipped.\n");
18983 return;
18984 }
18985
18986 char const *vsSource = "#version 450\n"
18987 "void main(){}\n";
18988 char const *tcsSource = "#version 450\n"
18989 "layout(location=0) out int x[];\n"
18990 "layout(vertices=3) out;\n"
18991 "void main(){\n"
18992 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
18993 " gl_TessLevelInner[0] = 1;\n"
18994 " x[gl_InvocationID] = gl_InvocationID;\n"
18995 "}\n";
18996 char const *tesSource = "#version 450\n"
18997 "layout(triangles, equal_spacing, cw) in;\n"
18998 "layout(location=0) in int x[];\n"
18999 "out gl_PerVertex { vec4 gl_Position; };\n"
19000 "void main(){\n"
19001 " gl_Position.xyz = gl_TessCoord;\n"
19002 " gl_Position.w = x[0] + x[1] + x[2];\n"
19003 "}\n";
19004 char const *fsSource = "#version 450\n"
19005 "layout(location=0) out vec4 color;\n"
19006 "void main(){\n"
19007 " color = vec4(1);\n"
19008 "}\n";
19009
19010 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19011 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19012 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19013 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19014
19015 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19016 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19017
19018 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19019
19020 VkPipelineObj pipe(m_device);
19021 pipe.SetInputAssembly(&iasci);
19022 pipe.SetTessellation(&tsci);
19023 pipe.AddColorAttachment();
19024 pipe.AddShader(&vs);
19025 pipe.AddShader(&tcs);
19026 pipe.AddShader(&tes);
19027 pipe.AddShader(&fs);
19028
19029 VkDescriptorSetObj descriptorSet(m_device);
19030 descriptorSet.AppendDummy();
19031 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19032
19033 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19034
19035 m_errorMonitor->VerifyNotFound();
19036}
19037
19038TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19039 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19040 "interface block passed into the geometry shader. This "
19041 "is interesting because the 'extra' array level is not "
19042 "present on the member type, but on the block instance.");
19043 m_errorMonitor->ExpectSuccess();
19044
19045 ASSERT_NO_FATAL_FAILURE(InitState());
19046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19047
19048 if (!m_device->phy().features().geometryShader) {
19049 printf("Device does not support geometry shaders; skipped.\n");
19050 return;
19051 }
19052
19053 char const *vsSource = "#version 450\n"
19054 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19055 "void main(){\n"
19056 " vs_out.x = vec4(1);\n"
19057 "}\n";
19058 char const *gsSource = "#version 450\n"
19059 "layout(triangles) in;\n"
19060 "layout(triangle_strip, max_vertices=3) out;\n"
19061 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19062 "out gl_PerVertex { vec4 gl_Position; };\n"
19063 "void main() {\n"
19064 " gl_Position = gs_in[0].x;\n"
19065 " EmitVertex();\n"
19066 "}\n";
19067 char const *fsSource = "#version 450\n"
19068 "layout(location=0) out vec4 color;\n"
19069 "void main(){\n"
19070 " color = vec4(1);\n"
19071 "}\n";
19072
19073 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19074 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19075 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19076
19077 VkPipelineObj pipe(m_device);
19078 pipe.AddColorAttachment();
19079 pipe.AddShader(&vs);
19080 pipe.AddShader(&gs);
19081 pipe.AddShader(&fs);
19082
19083 VkDescriptorSetObj descriptorSet(m_device);
19084 descriptorSet.AppendDummy();
19085 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19086
19087 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19088
19089 m_errorMonitor->VerifyNotFound();
19090}
19091
19092TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19093 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19094 "attributes. This is interesting because they consume multiple "
19095 "locations.");
19096 m_errorMonitor->ExpectSuccess();
19097
19098 ASSERT_NO_FATAL_FAILURE(InitState());
19099 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19100
19101 if (!m_device->phy().features().shaderFloat64) {
19102 printf("Device does not support 64bit vertex attributes; skipped.\n");
19103 return;
19104 }
19105
19106 VkVertexInputBindingDescription input_bindings[1];
19107 memset(input_bindings, 0, sizeof(input_bindings));
19108
19109 VkVertexInputAttributeDescription input_attribs[4];
19110 memset(input_attribs, 0, sizeof(input_attribs));
19111 input_attribs[0].location = 0;
19112 input_attribs[0].offset = 0;
19113 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19114 input_attribs[1].location = 2;
19115 input_attribs[1].offset = 32;
19116 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19117 input_attribs[2].location = 4;
19118 input_attribs[2].offset = 64;
19119 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19120 input_attribs[3].location = 6;
19121 input_attribs[3].offset = 96;
19122 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19123
19124 char const *vsSource = "#version 450\n"
19125 "\n"
19126 "layout(location=0) in dmat4 x;\n"
19127 "out gl_PerVertex {\n"
19128 " vec4 gl_Position;\n"
19129 "};\n"
19130 "void main(){\n"
19131 " gl_Position = vec4(x[0][0]);\n"
19132 "}\n";
19133 char const *fsSource = "#version 450\n"
19134 "\n"
19135 "layout(location=0) out vec4 color;\n"
19136 "void main(){\n"
19137 " color = vec4(1);\n"
19138 "}\n";
19139
19140 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19141 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19142
19143 VkPipelineObj pipe(m_device);
19144 pipe.AddColorAttachment();
19145 pipe.AddShader(&vs);
19146 pipe.AddShader(&fs);
19147
19148 pipe.AddVertexInputBindings(input_bindings, 1);
19149 pipe.AddVertexInputAttribs(input_attribs, 4);
19150
19151 VkDescriptorSetObj descriptorSet(m_device);
19152 descriptorSet.AppendDummy();
19153 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19154
19155 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19156
19157 m_errorMonitor->VerifyNotFound();
19158}
19159
19160TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19161 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19162 m_errorMonitor->ExpectSuccess();
19163
19164 ASSERT_NO_FATAL_FAILURE(InitState());
19165
19166 char const *vsSource = "#version 450\n"
19167 "\n"
19168 "out gl_PerVertex {\n"
19169 " vec4 gl_Position;\n"
19170 "};\n"
19171 "void main(){\n"
19172 " gl_Position = vec4(1);\n"
19173 "}\n";
19174 char const *fsSource = "#version 450\n"
19175 "\n"
19176 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19177 "layout(location=0) out vec4 color;\n"
19178 "void main() {\n"
19179 " color = subpassLoad(x);\n"
19180 "}\n";
19181
19182 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19183 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19184
19185 VkPipelineObj pipe(m_device);
19186 pipe.AddShader(&vs);
19187 pipe.AddShader(&fs);
19188 pipe.AddColorAttachment();
19189 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19190
19191 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19192 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19193 VkDescriptorSetLayout dsl;
19194 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19195 ASSERT_VK_SUCCESS(err);
19196
19197 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19198 VkPipelineLayout pl;
19199 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19200 ASSERT_VK_SUCCESS(err);
19201
19202 VkAttachmentDescription descs[2] = {
19203 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19204 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19205 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19206 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19207 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19208 };
19209 VkAttachmentReference color = {
19210 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19211 };
19212 VkAttachmentReference input = {
19213 1, VK_IMAGE_LAYOUT_GENERAL,
19214 };
19215
19216 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19217
19218 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19219 VkRenderPass rp;
19220 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19221 ASSERT_VK_SUCCESS(err);
19222
19223 // should be OK. would go wrong here if it's going to...
19224 pipe.CreateVKPipeline(pl, rp);
19225
19226 m_errorMonitor->VerifyNotFound();
19227
19228 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19229 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19230 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19231}
19232
19233TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19234 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19235 "descriptor-backed resource which is not provided, but the shader does not "
19236 "statically use it. This is interesting because it requires compute pipelines "
19237 "to have a proper descriptor use walk, which they didn't for some time.");
19238 m_errorMonitor->ExpectSuccess();
19239
19240 ASSERT_NO_FATAL_FAILURE(InitState());
19241
19242 char const *csSource = "#version 450\n"
19243 "\n"
19244 "layout(local_size_x=1) in;\n"
19245 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19246 "void main(){\n"
19247 " // x is not used.\n"
19248 "}\n";
19249
19250 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19251
19252 VkDescriptorSetObj descriptorSet(m_device);
19253 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19254
19255 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19256 nullptr,
19257 0,
19258 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19259 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19260 descriptorSet.GetPipelineLayout(),
19261 VK_NULL_HANDLE,
19262 -1 };
19263
19264 VkPipeline pipe;
19265 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19266
19267 m_errorMonitor->VerifyNotFound();
19268
19269 if (err == VK_SUCCESS) {
19270 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19271 }
19272}
19273
19274TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19275 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19276 "sampler portion of a combined image + sampler");
19277 m_errorMonitor->ExpectSuccess();
19278
19279 ASSERT_NO_FATAL_FAILURE(InitState());
19280
19281 VkDescriptorSetLayoutBinding bindings[] = {
19282 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19283 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19284 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19285 };
19286 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19287 VkDescriptorSetLayout dsl;
19288 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19289 ASSERT_VK_SUCCESS(err);
19290
19291 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19292 VkPipelineLayout pl;
19293 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19294 ASSERT_VK_SUCCESS(err);
19295
19296 char const *csSource = "#version 450\n"
19297 "\n"
19298 "layout(local_size_x=1) in;\n"
19299 "layout(set=0, binding=0) uniform sampler s;\n"
19300 "layout(set=0, binding=1) uniform texture2D t;\n"
19301 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19302 "void main() {\n"
19303 " x = texture(sampler2D(t, s), vec2(0));\n"
19304 "}\n";
19305 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19306
19307 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19308 nullptr,
19309 0,
19310 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19311 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19312 pl,
19313 VK_NULL_HANDLE,
19314 -1 };
19315
19316 VkPipeline pipe;
19317 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19318
19319 m_errorMonitor->VerifyNotFound();
19320
19321 if (err == VK_SUCCESS) {
19322 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19323 }
19324
19325 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19326 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19327}
19328
19329TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19330 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19331 "image portion of a combined image + sampler");
19332 m_errorMonitor->ExpectSuccess();
19333
19334 ASSERT_NO_FATAL_FAILURE(InitState());
19335
19336 VkDescriptorSetLayoutBinding bindings[] = {
19337 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19338 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19339 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19340 };
19341 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19342 VkDescriptorSetLayout dsl;
19343 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19344 ASSERT_VK_SUCCESS(err);
19345
19346 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19347 VkPipelineLayout pl;
19348 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19349 ASSERT_VK_SUCCESS(err);
19350
19351 char const *csSource = "#version 450\n"
19352 "\n"
19353 "layout(local_size_x=1) in;\n"
19354 "layout(set=0, binding=0) uniform texture2D t;\n"
19355 "layout(set=0, binding=1) uniform sampler s;\n"
19356 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19357 "void main() {\n"
19358 " x = texture(sampler2D(t, s), vec2(0));\n"
19359 "}\n";
19360 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19361
19362 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19363 nullptr,
19364 0,
19365 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19366 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19367 pl,
19368 VK_NULL_HANDLE,
19369 -1 };
19370
19371 VkPipeline pipe;
19372 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19373
19374 m_errorMonitor->VerifyNotFound();
19375
19376 if (err == VK_SUCCESS) {
19377 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19378 }
19379
19380 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19381 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19382}
19383
19384TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19385 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19386 "both the sampler and the image of a combined image+sampler "
19387 "but via separate variables");
19388 m_errorMonitor->ExpectSuccess();
19389
19390 ASSERT_NO_FATAL_FAILURE(InitState());
19391
19392 VkDescriptorSetLayoutBinding bindings[] = {
19393 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19394 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19395 };
19396 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19397 VkDescriptorSetLayout dsl;
19398 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19399 ASSERT_VK_SUCCESS(err);
19400
19401 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19402 VkPipelineLayout pl;
19403 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19404 ASSERT_VK_SUCCESS(err);
19405
19406 char const *csSource = "#version 450\n"
19407 "\n"
19408 "layout(local_size_x=1) in;\n"
19409 "layout(set=0, binding=0) uniform texture2D t;\n"
19410 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19411 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19412 "void main() {\n"
19413 " x = texture(sampler2D(t, s), vec2(0));\n"
19414 "}\n";
19415 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19416
19417 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19418 nullptr,
19419 0,
19420 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19421 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19422 pl,
19423 VK_NULL_HANDLE,
19424 -1 };
19425
19426 VkPipeline pipe;
19427 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19428
19429 m_errorMonitor->VerifyNotFound();
19430
19431 if (err == VK_SUCCESS) {
19432 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19433 }
19434
19435 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19436 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19437}
19438
19439TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19440 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19441
19442 ASSERT_NO_FATAL_FAILURE(InitState());
19443
19444 // Positive test to check parameter_validation and unique_objects support
19445 // for NV_dedicated_allocation
19446 uint32_t extension_count = 0;
19447 bool supports_nv_dedicated_allocation = false;
19448 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19449 ASSERT_VK_SUCCESS(err);
19450
19451 if (extension_count > 0) {
19452 std::vector<VkExtensionProperties> available_extensions(extension_count);
19453
19454 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19455 ASSERT_VK_SUCCESS(err);
19456
19457 for (const auto &extension_props : available_extensions) {
19458 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19459 supports_nv_dedicated_allocation = true;
19460 }
19461 }
19462 }
19463
19464 if (supports_nv_dedicated_allocation) {
19465 m_errorMonitor->ExpectSuccess();
19466
19467 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19468 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19469 dedicated_buffer_create_info.pNext = nullptr;
19470 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19471
19472 uint32_t queue_family_index = 0;
19473 VkBufferCreateInfo buffer_create_info = {};
19474 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19475 buffer_create_info.pNext = &dedicated_buffer_create_info;
19476 buffer_create_info.size = 1024;
19477 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19478 buffer_create_info.queueFamilyIndexCount = 1;
19479 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19480
19481 VkBuffer buffer;
19482 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19483 ASSERT_VK_SUCCESS(err);
19484
19485 VkMemoryRequirements memory_reqs;
19486 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19487
19488 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19489 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19490 dedicated_memory_info.pNext = nullptr;
19491 dedicated_memory_info.buffer = buffer;
19492 dedicated_memory_info.image = VK_NULL_HANDLE;
19493
19494 VkMemoryAllocateInfo memory_info = {};
19495 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19496 memory_info.pNext = &dedicated_memory_info;
19497 memory_info.allocationSize = memory_reqs.size;
19498
19499 bool pass;
19500 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19501 ASSERT_TRUE(pass);
19502
19503 VkDeviceMemory buffer_memory;
19504 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19505 ASSERT_VK_SUCCESS(err);
19506
19507 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19508 ASSERT_VK_SUCCESS(err);
19509
19510 vkDestroyBuffer(m_device->device(), buffer, NULL);
19511 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19512
19513 m_errorMonitor->VerifyNotFound();
19514 }
19515}
19516
19517TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19518 VkResult err;
19519
19520 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19521
19522 ASSERT_NO_FATAL_FAILURE(InitState());
19523 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19524
19525 std::vector<const char *> device_extension_names;
19526 auto features = m_device->phy().features();
19527 // Artificially disable support for non-solid fill modes
19528 features.fillModeNonSolid = false;
19529 // The sacrificial device object
19530 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19531
19532 VkRenderpassObj render_pass(&test_device);
19533
19534 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19535 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19536 pipeline_layout_ci.setLayoutCount = 0;
19537 pipeline_layout_ci.pSetLayouts = NULL;
19538
19539 VkPipelineLayout pipeline_layout;
19540 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19541 ASSERT_VK_SUCCESS(err);
19542
19543 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19544 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19545 rs_ci.pNext = nullptr;
19546 rs_ci.lineWidth = 1.0f;
19547 rs_ci.rasterizerDiscardEnable = true;
19548
19549 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19550 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19551
19552 // Set polygonMode=FILL. No error is expected
19553 m_errorMonitor->ExpectSuccess();
19554 {
19555 VkPipelineObj pipe(&test_device);
19556 pipe.AddShader(&vs);
19557 pipe.AddShader(&fs);
19558 pipe.AddColorAttachment();
19559 // Set polygonMode to a good value
19560 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19561 pipe.SetRasterization(&rs_ci);
19562 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19563 }
19564 m_errorMonitor->VerifyNotFound();
19565
19566 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19567}
19568
19569TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19570 VkResult err;
19571 ASSERT_NO_FATAL_FAILURE(InitState());
19572 ASSERT_NO_FATAL_FAILURE(InitViewport());
19573 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19574
19575 VkPipelineLayout pipeline_layout;
19576 VkPushConstantRange pc_range = {};
19577 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19578 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19579 pipeline_layout_ci.pushConstantRangeCount = 1;
19580 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19581
19582 //
19583 // Check for invalid push constant ranges in pipeline layouts.
19584 //
19585 struct PipelineLayoutTestCase {
19586 VkPushConstantRange const range;
19587 char const *msg;
19588 };
19589
19590 // Check for overlapping ranges
19591 const uint32_t ranges_per_test = 5;
19592 struct OverlappingRangeTestCase {
19593 VkPushConstantRange const ranges[ranges_per_test];
19594 char const *msg;
19595 };
19596
19597 // Run some positive tests to make sure overlap checking in the layer is OK
19598 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19599 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19600 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19601 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19602 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19603 "" },
19604 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19605 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19606 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19607 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19608 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19609 "" } } };
19610 for (const auto &iter : overlapping_range_tests_pos) {
19611 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19612 m_errorMonitor->ExpectSuccess();
19613 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19614 m_errorMonitor->VerifyNotFound();
19615 if (VK_SUCCESS == err) {
19616 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19617 }
19618 }
19619
19620 //
19621 // CmdPushConstants tests
19622 //
19623 const uint8_t dummy_values[100] = {};
19624
19625 BeginCommandBuffer();
19626
19627 // positive overlapping range tests with cmd
19628 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19629 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19630 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19631 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19632 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19633 } };
19634
19635 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19636 const VkPushConstantRange pc_range4[] = {
19637 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19638 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19639 };
19640
19641 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19642 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19643 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19644 ASSERT_VK_SUCCESS(err);
19645 for (const auto &iter : cmd_overlap_tests_pos) {
19646 m_errorMonitor->ExpectSuccess();
19647 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19648 iter.range.size, dummy_values);
19649 m_errorMonitor->VerifyNotFound();
19650 }
19651 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19652
19653 EndCommandBuffer();
19654}
19655
19656
19657
19658
19659
19660
19661
19662#if 0 // A few devices have issues with this test so disabling for now
19663TEST_F(VkPositiveLayerTest, LongFenceChain)
19664{
19665 m_errorMonitor->ExpectSuccess();
19666
19667 ASSERT_NO_FATAL_FAILURE(InitState());
19668 VkResult err;
19669
19670 std::vector<VkFence> fences;
19671
19672 const int chainLength = 32768;
19673
19674 for (int i = 0; i < chainLength; i++) {
19675 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19676 VkFence fence;
19677 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19678 ASSERT_VK_SUCCESS(err);
19679
19680 fences.push_back(fence);
19681
19682 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19683 0, nullptr, 0, nullptr };
19684 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19685 ASSERT_VK_SUCCESS(err);
19686
19687 }
19688
19689 // BOOM, stack overflow.
19690 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19691
19692 for (auto fence : fences)
19693 vkDestroyFence(m_device->device(), fence, nullptr);
19694
19695 m_errorMonitor->VerifyNotFound();
19696}
19697#endif
19698
19699
Cody Northrop1242dfd2016-07-13 17:24:59 -060019700#if defined(ANDROID) && defined(VALIDATION_APK)
19701static bool initialized = false;
19702static bool active = false;
19703
19704// Convert Intents to argv
19705// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019706std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019707 std::vector<std::string> args;
19708 JavaVM &vm = *app.activity->vm;
19709 JNIEnv *p_env;
19710 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19711 return args;
19712
19713 JNIEnv &env = *p_env;
19714 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019715 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019716 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019717 jmethodID get_string_extra_method =
19718 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019719 jvalue get_string_extra_args;
19720 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019721 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019722
19723 std::string args_str;
19724 if (extra_str) {
19725 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19726 args_str = extra_utf;
19727 env.ReleaseStringUTFChars(extra_str, extra_utf);
19728 env.DeleteLocalRef(extra_str);
19729 }
19730
19731 env.DeleteLocalRef(get_string_extra_args.l);
19732 env.DeleteLocalRef(intent);
19733 vm.DetachCurrentThread();
19734
19735 // split args_str
19736 std::stringstream ss(args_str);
19737 std::string arg;
19738 while (std::getline(ss, arg, ' ')) {
19739 if (!arg.empty())
19740 args.push_back(arg);
19741 }
19742
19743 return args;
19744}
19745
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019746static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019747
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019748static void processCommand(struct android_app *app, int32_t cmd) {
19749 switch (cmd) {
19750 case APP_CMD_INIT_WINDOW: {
19751 if (app->window) {
19752 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019753 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019754 break;
19755 }
19756 case APP_CMD_GAINED_FOCUS: {
19757 active = true;
19758 break;
19759 }
19760 case APP_CMD_LOST_FOCUS: {
19761 active = false;
19762 break;
19763 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019764 }
19765}
19766
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019767void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019768 app_dummy();
19769
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019770 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019771
19772 int vulkanSupport = InitVulkan();
19773 if (vulkanSupport == 0) {
19774 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19775 return;
19776 }
19777
19778 app->onAppCmd = processCommand;
19779 app->onInputEvent = processInput;
19780
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019781 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019782 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019783 struct android_poll_source *source;
19784 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019785 if (source) {
19786 source->process(app, source);
19787 }
19788
19789 if (app->destroyRequested != 0) {
19790 VkTestFramework::Finish();
19791 return;
19792 }
19793 }
19794
19795 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019796 // Use the following key to send arguments to gtest, i.e.
19797 // --es args "--gtest_filter=-VkLayerTest.foo"
19798 const char key[] = "args";
19799 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019800
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019801 std::string filter = "";
19802 if (args.size() > 0) {
19803 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19804 filter += args[0];
19805 } else {
19806 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19807 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019808
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019809 int argc = 2;
19810 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19811 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019812
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019813 // Route output to files until we can override the gtest output
19814 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19815 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019816
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019817 ::testing::InitGoogleTest(&argc, argv);
19818 VkTestFramework::InitArgs(&argc, argv);
19819 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019820
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019821 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019822
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019823 if (result != 0) {
19824 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19825 } else {
19826 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19827 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019828
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019829 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019830
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019831 fclose(stdout);
19832 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019833
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019834 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019835
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019836 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019837 }
19838 }
19839}
19840#endif
19841
Tony Barbour300a6082015-04-07 13:44:53 -060019842int main(int argc, char **argv) {
19843 int result;
19844
Cody Northrop8e54a402016-03-08 22:25:52 -070019845#ifdef ANDROID
19846 int vulkanSupport = InitVulkan();
19847 if (vulkanSupport == 0)
19848 return 1;
19849#endif
19850
Tony Barbour300a6082015-04-07 13:44:53 -060019851 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060019852 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060019853
19854 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
19855
19856 result = RUN_ALL_TESTS();
19857
Tony Barbour6918cd52015-04-09 12:58:51 -060019858 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060019859 return result;
19860}