blob: b2e7499bd2167cff64379e5df04c79cb0564e3c6 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060037#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060038#include "vkrenderframework.h"
39#include <limits.h>
40#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060041
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042#define GLM_FORCE_RADIANS
43#include "glm/glm.hpp"
44#include <glm/gtc/matrix_transform.hpp>
45
Dustin Gravesffa90fa2016-05-06 11:20:38 -060046#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060047#define MEM_TRACKER_TESTS 1
48#define OBJ_TRACKER_TESTS 1
49#define DRAW_STATE_TESTS 1
50#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120051#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060052#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060053#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060054
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055//--------------------------------------------------------------------------------------
56// Mesh and VertexFormat Data
57//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070058struct Vertex {
59 float posX, posY, posZ, posW; // Position data
60 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061};
62
Karl Schultz6addd812016-02-02 17:17:23 -070063#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050064
65typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070066 BsoFailNone = 0x00000000,
67 BsoFailLineWidth = 0x00000001,
68 BsoFailDepthBias = 0x00000002,
69 BsoFailViewport = 0x00000004,
70 BsoFailScissor = 0x00000008,
71 BsoFailBlend = 0x00000010,
72 BsoFailDepthBounds = 0x00000020,
73 BsoFailStencilReadMask = 0x00000040,
74 BsoFailStencilWriteMask = 0x00000080,
75 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060076 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060077 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050085};
86
Mark Lobodzinskice751c62016-09-08 10:45:35 -060087static const char bindStateVertShaderText[] = "#version 450\n"
88 "vec2 vertices[3];\n"
89 "out gl_PerVertex {\n"
90 " vec4 gl_Position;\n"
91 "};\n"
92 "void main() {\n"
93 " vertices[0] = vec2(-1.0, -1.0);\n"
94 " vertices[1] = vec2( 1.0, -1.0);\n"
95 " vertices[2] = vec2( 0.0, 1.0);\n"
96 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
97 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060099static const char bindStateFragShaderText[] = "#version 450\n"
100 "\n"
101 "layout(location = 0) out vec4 uFragColor;\n"
102 "void main(){\n"
103 " uFragColor = vec4(0,1,0,1);\n"
104 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500105
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600106static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
107 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
108 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600109
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600110// ErrorMonitor Usage:
111//
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600112// Call SetDesiredFailureMsg with: a string to be compared against all
113// encountered log messages, or a validation error enum identifying
114// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
115// will match all log messages. logMsg will return true for skipCall
116// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117//
118// Call DesiredMsgFound to determine if the desired failure message
119// was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600120class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700121 public:
122 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600123 test_platform_thread_create_mutex(&m_mutex);
124 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200125 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700126 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600127 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600128 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129
Dustin Graves48458142016-04-29 16:11:55 -0600130 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
131
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600132 // ErrorMonitor will look for an error message containing the specified string
Karl Schultz6addd812016-02-02 17:17:23 -0700133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600134 // Also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600136 m_failure_message_strings.clear();
137 // If we are looking for a matching string, ignore any IDs
138 m_desired_message_ids.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600139 m_otherMsgs.clear();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600140 m_desired_message_strings.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700141 m_msgFound = VK_FALSE;
142 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600143 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600144 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600145
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600146 // ErrorMonitor will look for a message ID matching the specified one
147 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
148 // Also discard all collected messages to this point
149 test_platform_thread_lock_mutex(&m_mutex);
150 m_failure_message_strings.clear();
151 // If we are looking for IDs don't look for strings
152 m_desired_message_strings.clear();
153 m_otherMsgs.clear();
154 m_desired_message_ids.insert(msg_id);
155 m_msgFound = VK_FALSE;
156 m_msgFlags = msgFlags;
157 test_platform_thread_unlock_mutex(&m_mutex);
158 }
159
160 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600162 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600163 if (m_bailout != NULL) {
164 *m_bailout = true;
165 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600167 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600168
169 for (auto desired_msg : m_desired_message_strings) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600170 if (desired_msg.length() == 0) {
171 // An empty desired_msg string "" indicates a positive test - not expecting an error.
172 // Return true to avoid calling layers/driver with this error.
173 // And don't erase the "" string, so it remains if another error is found.
174 result = VK_TRUE;
175 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600176 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600177 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600178 m_msgFound = VK_TRUE;
179 result = VK_TRUE;
180 // We only want one match for each expected error so remove from set here
181 // Since we're about the break the loop it's ok to remove from set we're iterating over
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600182 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600183 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186 for (auto desired_id : m_desired_message_ids) {
187 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
188 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
189 // Return true to avoid calling layers/driver with this error.
190 result = VK_TRUE;
191 } else if (desired_id == message_code) {
192 // Double-check that the string matches the error enum
193 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
194 found_expected = true;
195 result = VK_TRUE;
196 m_msgFound = VK_TRUE;
197 m_desired_message_ids.erase(desired_id);
198 break;
199 } else {
200 // Treat this message as a regular unexpected error, but print a warning jic
201 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
202 errorString.c_str(), desired_id, validation_error_map[desired_id]);
203 }
204 }
205 }
206
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600207 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200208 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600209 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600210 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600211 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600212 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600213 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600214
Karl Schultz6addd812016-02-02 17:17:23 -0700215 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600216
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600217 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
218
Karl Schultz6addd812016-02-02 17:17:23 -0700219 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600220
Karl Schultz6addd812016-02-02 17:17:23 -0700221 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600222
Karl Schultz6addd812016-02-02 17:17:23 -0700223 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600224 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600225 if (otherMsgs.size()) {
226 cout << "Other error messages logged for this test were:" << endl;
227 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
228 cout << " " << *iter << endl;
229 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600230 }
231 }
232
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600233 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200234
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600235 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
236 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
237 m_msgFlags = message_flag_mask;
238 // Match ANY message matching specified type
239 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200240 }
241
242 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600243 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200244 if (!DesiredMsgFound()) {
245 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600246 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600247 FAIL() << "Did not receive expected error '" << desired_msg << "'";
248 }
Tony Barbour59b42282016-11-03 13:31:28 -0600249 for (auto desired_id : m_desired_message_ids) {
250 FAIL() << "Did not receive expected error '" << desired_id << "'";
251 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200252 }
253 }
254
255 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600256 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200257 if (DesiredMsgFound()) {
258 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600259 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600260 FAIL() << "Expected to succeed but got error: " << msg;
261 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262 }
263 }
264
Karl Schultz6addd812016-02-02 17:17:23 -0700265 private:
266 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600267 std::unordered_set<uint32_t>m_desired_message_ids;
268 std::unordered_set<string> m_desired_message_strings;
269 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700270 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600271 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700272 bool *m_bailout;
273 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600274};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500275
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600276static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
277 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
278 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600279 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
280 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600281 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600282 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600283 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600284}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500285
Karl Schultz6addd812016-02-02 17:17:23 -0700286class VkLayerTest : public VkRenderFramework {
287 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800288 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
289 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600290 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
291 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700292 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
294 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700295 }
Tony Barbour300a6082015-04-07 13:44:53 -0600296
Tony Barbourfe3351b2015-07-28 10:17:20 -0600297 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600298 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800299 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600300 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
301 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700302 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700304 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600305 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700306 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600307 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
308 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
309 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700310 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
311 }
312 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
313 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
314 }
315
316 protected:
317 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600318 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600319
320 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600321 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600322 std::vector<const char *> instance_extension_names;
323 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600324
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700325 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600326 /*
327 * Since CreateDbgMsgCallback is an instance level extension call
328 * any extension / layer that utilizes that feature also needs
329 * to be enabled at create instance time.
330 */
Karl Schultz6addd812016-02-02 17:17:23 -0700331 // Use Threading layer first to protect others from
332 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700333 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600334 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800335 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700336 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800337 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600338 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700339 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600340
Ian Elliott2c1daf52016-05-12 09:41:46 -0600341 if (m_enableWSI) {
342 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
343 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
344#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
345#if defined(VK_USE_PLATFORM_ANDROID_KHR)
346 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
347#endif // VK_USE_PLATFORM_ANDROID_KHR
348#if defined(VK_USE_PLATFORM_MIR_KHR)
349 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_MIR_KHR
351#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
352 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
353#endif // VK_USE_PLATFORM_WAYLAND_KHR
354#if defined(VK_USE_PLATFORM_WIN32_KHR)
355 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_WIN32_KHR
357#endif // NEED_TO_TEST_THIS_ON_PLATFORM
358#if defined(VK_USE_PLATFORM_XCB_KHR)
359 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
360#elif defined(VK_USE_PLATFORM_XLIB_KHR)
361 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
362#endif // VK_USE_PLATFORM_XLIB_KHR
363 }
364
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600365 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600366 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800367 this->app_info.pApplicationName = "layer_tests";
368 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600369 this->app_info.pEngineName = "unittest";
370 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600371 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600372
Tony Barbour15524c32015-04-29 17:34:29 -0600373 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600374 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600375 }
376
377 virtual void TearDown() {
378 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600379 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600380 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600381 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600382
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600383 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600384};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500385
Karl Schultz6addd812016-02-02 17:17:23 -0700386VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600387 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600388
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800389 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600390
391 /*
392 * For render test all drawing happens in a single render pass
393 * on a single command buffer.
394 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200395 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800396 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600397 }
398
399 return result;
400}
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600403 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600404
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200405 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800406 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200407 }
Tony Barbour300a6082015-04-07 13:44:53 -0600408
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600410
411 return result;
412}
413
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600414void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500415 // Create identity matrix
416 int i;
417 struct vktriangle_vs_uniform data;
418
419 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700420 glm::mat4 View = glm::mat4(1.0f);
421 glm::mat4 Model = glm::mat4(1.0f);
422 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700424 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425
426 memcpy(&data.mvp, &MVP[0][0], matrixSize);
427
Karl Schultz6addd812016-02-02 17:17:23 -0700428 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600429 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500430 };
431
Karl Schultz6addd812016-02-02 17:17:23 -0700432 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 data.position[i][0] = tri_data[i].posX;
434 data.position[i][1] = tri_data[i].posY;
435 data.position[i][2] = tri_data[i].posZ;
436 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700437 data.color[i][0] = tri_data[i].r;
438 data.color[i][1] = tri_data[i].g;
439 data.color[i][2] = tri_data[i].b;
440 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500441 }
442
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 ASSERT_NO_FATAL_FAILURE(InitViewport());
444
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200445 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
446 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Karl Schultz6addd812016-02-02 17:17:23 -0700448 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600449 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
451 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800452 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 pipelineobj.AddShader(&vs);
454 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 if (failMask & BsoFailLineWidth) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600457 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600458 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600459 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
460 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600461 }
462 if (failMask & BsoFailDepthBias) {
463 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600464 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600465 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600466 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600467 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600468 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600469 }
Karl Schultz6addd812016-02-02 17:17:23 -0700470 // Viewport and scissors must stay in synch or other errors will occur than
471 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 if (failMask & BsoFailViewport) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
474 }
475 if (failMask & BsoFailScissor) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
477 }
478 if (failMask & BsoFailBlend) {
479 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600480 VkPipelineColorBlendAttachmentState att_state = {};
481 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
482 att_state.blendEnable = VK_TRUE;
483 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600484 }
485 if (failMask & BsoFailDepthBounds) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
487 }
488 if (failMask & BsoFailStencilReadMask) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
490 }
491 if (failMask & BsoFailStencilWriteMask) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
493 }
494 if (failMask & BsoFailStencilReference) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
496 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500497
498 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600499 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600502 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
Tony Barbourfe3351b2015-07-28 10:17:20 -0600504 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500505
506 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600507 if (failMask & BsoFailIndexBuffer) {
508 // Use DrawIndexed w/o an index buffer bound
509 DrawIndexed(3, 1, 0, 0, 0);
510 } else {
511 Draw(3, 1, 0, 0);
512 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500513
Mark Muellerd4914412016-06-13 17:52:06 -0600514 if (failMask & BsoFailCmdClearAttachments) {
515 VkClearAttachment color_attachment = {};
516 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
517 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
518 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
519
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600520 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600521 }
522
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500523 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600524 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500525
Tony Barbourfe3351b2015-07-28 10:17:20 -0600526 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500527}
528
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600529void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
530 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500531 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500533 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600534 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500535 }
536
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800537 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700538 // Make sure depthWriteEnable is set so that Depth fail test will work
539 // correctly
540 // Make sure stencilTestEnable is set so that Stencil fail test will work
541 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600542 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800543 stencil.failOp = VK_STENCIL_OP_KEEP;
544 stencil.passOp = VK_STENCIL_OP_KEEP;
545 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
546 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600547
548 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
549 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600550 ds_ci.pNext = NULL;
551 ds_ci.depthTestEnable = VK_FALSE;
552 ds_ci.depthWriteEnable = VK_TRUE;
553 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
554 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600555 if (failMask & BsoFailDepthBounds) {
556 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600557 ds_ci.maxDepthBounds = 0.0f;
558 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600559 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600560 ds_ci.stencilTestEnable = VK_TRUE;
561 ds_ci.front = stencil;
562 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600563
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600564 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600565 pipelineobj.SetViewport(m_viewports);
566 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800567 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600568 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600569 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800570 commandBuffer->BindPipeline(pipelineobj);
571 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500572}
573
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600574class VkPositiveLayerTest : public VkLayerTest {
575 public:
576 protected:
577};
578
Ian Elliott2c1daf52016-05-12 09:41:46 -0600579class VkWsiEnabledLayerTest : public VkLayerTest {
580 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 protected:
582 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600583};
584
Mark Muellerdfe37552016-07-07 14:47:42 -0600585class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600586 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600587 enum eTestEnFlags {
588 eDoubleDelete,
589 eInvalidDeviceOffset,
590 eInvalidMemoryOffset,
591 eBindNullBuffer,
592 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600593 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600594 };
595
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600596 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600597
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
599 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600600 return true;
601 }
602 VkDeviceSize offset_limit = 0;
603 if (eInvalidMemoryOffset == aTestFlag) {
604 VkBuffer vulkanBuffer;
605 VkBufferCreateInfo buffer_create_info = {};
606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
607 buffer_create_info.size = 32;
608 buffer_create_info.usage = aBufferUsage;
609
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600610 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600611 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600614 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
615 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
617 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600618 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600620 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600622 }
623 if (eOffsetAlignment < offset_limit) {
624 return true;
625 }
626 return false;
627 }
628
629 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
631 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
633 if (eBindNullBuffer == aTestFlag) {
634 VulkanMemory = 0;
635 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
636 } else {
637 VkBufferCreateInfo buffer_create_info = {};
638 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
639 buffer_create_info.size = 32;
640 buffer_create_info.usage = aBufferUsage;
641
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600643
644 CreateCurrent = true;
645
646 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600647 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600648
649 VkMemoryAllocateInfo memory_allocate_info = {};
650 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
651 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
653 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600654 if (!pass) {
655 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
656 return;
657 }
658
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600659 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600660 AllocateCurrent = true;
661 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
663 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 BoundCurrent = true;
665
666 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
667 }
668 }
669
670 ~VkBufferTest() {
671 if (CreateCurrent) {
672 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
673 }
674 if (AllocateCurrent) {
675 if (InvalidDeleteEn) {
676 union {
677 VkDeviceMemory device_memory;
678 unsigned long long index_access;
679 } bad_index;
680
681 bad_index.device_memory = VulkanMemory;
682 bad_index.index_access++;
683
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600684 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600685 }
686 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
687 }
688 }
689
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600690 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600691
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600692 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600693
694 void TestDoubleDestroy() {
695 // Destroy the buffer but leave the flag set, which will cause
696 // the buffer to be destroyed again in the destructor.
697 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600701 bool AllocateCurrent;
702 bool BoundCurrent;
703 bool CreateCurrent;
704 bool InvalidDeleteEn;
705
706 VkBuffer VulkanBuffer;
707 VkDevice VulkanDevice;
708 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600709};
710
711class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600712 public:
713 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600714 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600716 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600717 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
718 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 BindIdGenerator++; // NB: This can wrap w/misuse
720
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600721 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
722 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
725 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
726 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
727 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
728 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600729
730 unsigned i = 0;
731 do {
732 VertexInputAttributeDescription[i].binding = BindId;
733 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
735 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600736 i++;
737 } while (AttributeCount < i);
738
739 i = 0;
740 do {
741 VertexInputBindingDescription[i].binding = BindId;
742 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600743 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600744 i++;
745 } while (BindingCount < i);
746 }
747
748 ~VkVerticesObj() {
749 if (VertexInputAttributeDescription) {
750 delete[] VertexInputAttributeDescription;
751 }
752 if (VertexInputBindingDescription) {
753 delete[] VertexInputBindingDescription;
754 }
755 }
756
757 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
759 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600760 return true;
761 }
762
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600763 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600764 VkDeviceSize *offsetList;
765 unsigned offsetCount;
766
767 if (aOffsetCount) {
768 offsetList = aOffsetList;
769 offsetCount = aOffsetCount;
770 } else {
771 offsetList = new VkDeviceSize[1]();
772 offsetCount = 1;
773 }
774
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600775 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600776 BoundCurrent = true;
777
778 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600779 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600780 }
781 }
782
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600783 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600784 static uint32_t BindIdGenerator;
785
786 bool BoundCurrent;
787 unsigned AttributeCount;
788 unsigned BindingCount;
789 uint32_t BindId;
790
791 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
792 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
793 VkVertexInputBindingDescription *VertexInputBindingDescription;
794 VkConstantBufferObj VulkanMemoryBuffer;
795};
796
797uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500798// ********************************************************************************************************************
799// ********************************************************************************************************************
800// ********************************************************************************************************************
801// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600802#if PARAMETER_VALIDATION_TESTS
803TEST_F(VkLayerTest, RequiredParameter) {
804 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
805 "pointer, array, and array count parameters");
806
807 ASSERT_NO_FATAL_FAILURE(InitState());
808
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600810 // Specify NULL for a pointer to a handle
811 // Expected to trigger an error with
812 // parameter_validation::validate_required_pointer
813 vkGetPhysicalDeviceFeatures(gpu(), NULL);
814 m_errorMonitor->VerifyFound();
815
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
817 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600818 // Specify NULL for pointer to array count
819 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600820 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600821 m_errorMonitor->VerifyFound();
822
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 // Specify 0 for a required array count
825 // Expected to trigger an error with parameter_validation::validate_array
826 VkViewport view_port = {};
827 m_commandBuffer->SetViewport(0, 0, &view_port);
828 m_errorMonitor->VerifyFound();
829
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for a required array
832 // Expected to trigger an error with parameter_validation::validate_array
833 m_commandBuffer->SetViewport(0, 1, NULL);
834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify VK_NULL_HANDLE for a required handle
838 // Expected to trigger an error with
839 // parameter_validation::validate_required_handle
840 vkUnmapMemory(device(), VK_NULL_HANDLE);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
844 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600845 // Specify VK_NULL_HANDLE for a required handle array entry
846 // Expected to trigger an error with
847 // parameter_validation::validate_required_handle_array
848 VkFence fence = VK_NULL_HANDLE;
849 vkResetFences(device(), 1, &fence);
850 m_errorMonitor->VerifyFound();
851
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600853 // Specify NULL for a required struct pointer
854 // Expected to trigger an error with
855 // parameter_validation::validate_struct_type
856 VkDeviceMemory memory = VK_NULL_HANDLE;
857 vkAllocateMemory(device(), NULL, NULL, &memory);
858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600861 // Specify 0 for a required VkFlags parameter
862 // Expected to trigger an error with parameter_validation::validate_flags
863 m_commandBuffer->SetStencilReference(0, 0);
864 m_errorMonitor->VerifyFound();
865
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600867 // Specify 0 for a required VkFlags array entry
868 // Expected to trigger an error with
869 // parameter_validation::validate_flags_array
870 VkSemaphore semaphore = VK_NULL_HANDLE;
871 VkPipelineStageFlags stageFlags = 0;
872 VkSubmitInfo submitInfo = {};
873 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
874 submitInfo.waitSemaphoreCount = 1;
875 submitInfo.pWaitSemaphores = &semaphore;
876 submitInfo.pWaitDstStageMask = &stageFlags;
877 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
878 m_errorMonitor->VerifyFound();
879}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600880
Dustin Gravesfce74c02016-05-10 11:42:58 -0600881TEST_F(VkLayerTest, ReservedParameter) {
882 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
883
884 ASSERT_NO_FATAL_FAILURE(InitState());
885
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600887 // Specify 0 for a reserved VkFlags parameter
888 // Expected to trigger an error with
889 // parameter_validation::validate_reserved_flags
890 VkEvent event_handle = VK_NULL_HANDLE;
891 VkEventCreateInfo event_info = {};
892 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
893 event_info.flags = 1;
894 vkCreateEvent(device(), &event_info, NULL, &event_handle);
895 m_errorMonitor->VerifyFound();
896}
897
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600898TEST_F(VkLayerTest, InvalidStructSType) {
899 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
900 "structure's sType field");
901
902 ASSERT_NO_FATAL_FAILURE(InitState());
903
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600905 // Zero struct memory, effectively setting sType to
906 // VK_STRUCTURE_TYPE_APPLICATION_INFO
907 // Expected to trigger an error with
908 // parameter_validation::validate_struct_type
909 VkMemoryAllocateInfo alloc_info = {};
910 VkDeviceMemory memory = VK_NULL_HANDLE;
911 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
912 m_errorMonitor->VerifyFound();
913
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915 // Zero struct memory, effectively setting sType to
916 // VK_STRUCTURE_TYPE_APPLICATION_INFO
917 // Expected to trigger an error with
918 // parameter_validation::validate_struct_type_array
919 VkSubmitInfo submit_info = {};
920 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
921 m_errorMonitor->VerifyFound();
922}
923
924TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600925 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600926
927 ASSERT_NO_FATAL_FAILURE(InitState());
928
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600930 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600931 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600932 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600933 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600934 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600935 // Zero-initialization will provide the correct sType
936 VkApplicationInfo app_info = {};
937 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
938 event_alloc_info.pNext = &app_info;
939 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
940 m_errorMonitor->VerifyFound();
941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
943 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
945 // a function that has allowed pNext structure types and specify
946 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600947 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600948 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600949 VkMemoryAllocateInfo memory_alloc_info = {};
950 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
951 memory_alloc_info.pNext = &app_info;
952 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600953 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600954}
Dustin Graves5d33d532016-05-09 16:21:12 -0600955
956TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600957 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600958
959 ASSERT_NO_FATAL_FAILURE(InitState());
960
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
962 "range of the core VkFormat "
963 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600964 // Specify an invalid VkFormat value
965 // Expected to trigger an error with
966 // parameter_validation::validate_ranged_enum
967 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600968 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600969 m_errorMonitor->VerifyFound();
970
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 // Specify an invalid VkFlags bitmask value
973 // Expected to trigger an error with parameter_validation::validate_flags
974 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600975 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
976 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600977 m_errorMonitor->VerifyFound();
978
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 // Specify an invalid VkFlags array entry
981 // Expected to trigger an error with
982 // parameter_validation::validate_flags_array
983 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600984 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600985 VkSubmitInfo submit_info = {};
986 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
987 submit_info.waitSemaphoreCount = 1;
988 submit_info.pWaitSemaphores = &semaphore;
989 submit_info.pWaitDstStageMask = &stage_flags;
990 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
991 m_errorMonitor->VerifyFound();
992
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 // Specify an invalid VkBool32 value
995 // Expected to trigger a warning with
996 // parameter_validation::validate_bool32
997 VkSampler sampler = VK_NULL_HANDLE;
998 VkSamplerCreateInfo sampler_info = {};
999 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1000 sampler_info.pNext = NULL;
1001 sampler_info.magFilter = VK_FILTER_NEAREST;
1002 sampler_info.minFilter = VK_FILTER_NEAREST;
1003 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1004 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1005 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1006 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1007 sampler_info.mipLodBias = 1.0;
1008 sampler_info.maxAnisotropy = 1;
1009 sampler_info.compareEnable = VK_FALSE;
1010 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1011 sampler_info.minLod = 1.0;
1012 sampler_info.maxLod = 1.0;
1013 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1014 sampler_info.unnormalizedCoordinates = VK_FALSE;
1015 // Not VK_TRUE or VK_FALSE
1016 sampler_info.anisotropyEnable = 3;
1017 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1018 m_errorMonitor->VerifyFound();
1019}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001020
1021TEST_F(VkLayerTest, FailedReturnValue) {
1022 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1023
1024 ASSERT_NO_FATAL_FAILURE(InitState());
1025
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001026 // Find an unsupported image format
1027 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1028 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1029 VkFormat format = static_cast<VkFormat>(f);
1030 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001031 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001032 unsupported = format;
1033 break;
1034 }
1035 }
1036
1037 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1039 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001040 // Specify an unsupported VkFormat value to generate a
1041 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1042 // Expected to trigger a warning from
1043 // parameter_validation::validate_result
1044 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001045 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1046 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1048 m_errorMonitor->VerifyFound();
1049 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001050}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001051
1052TEST_F(VkLayerTest, UpdateBufferAlignment) {
1053 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001054 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001055
1056 ASSERT_NO_FATAL_FAILURE(InitState());
1057
1058 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1059 vk_testing::Buffer buffer;
1060 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1061
1062 BeginCommandBuffer();
1063 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1066 m_errorMonitor->VerifyFound();
1067
1068 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1071 m_errorMonitor->VerifyFound();
1072
1073 // Introduce failure by using dataSize that is < 0
1074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001075 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1077 m_errorMonitor->VerifyFound();
1078
1079 // Introduce failure by using dataSize that is > 65536
1080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001081 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001082 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1083 m_errorMonitor->VerifyFound();
1084
1085 EndCommandBuffer();
1086}
1087
1088TEST_F(VkLayerTest, FillBufferAlignment) {
1089 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1090
1091 ASSERT_NO_FATAL_FAILURE(InitState());
1092
1093 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1094 vk_testing::Buffer buffer;
1095 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1096
1097 BeginCommandBuffer();
1098
1099 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1102 m_errorMonitor->VerifyFound();
1103
1104 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001106 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1107 m_errorMonitor->VerifyFound();
1108
1109 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001111 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1112 m_errorMonitor->VerifyFound();
1113
1114 EndCommandBuffer();
1115}
Dustin Graves40f35822016-06-23 11:12:53 -06001116
Cortd889ff92016-07-27 09:51:27 -07001117TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1118 VkResult err;
1119
1120 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001121 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001122
1123 ASSERT_NO_FATAL_FAILURE(InitState());
1124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1125
1126 std::vector<const char *> device_extension_names;
1127 auto features = m_device->phy().features();
1128 // Artificially disable support for non-solid fill modes
1129 features.fillModeNonSolid = false;
1130 // The sacrificial device object
1131 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1132
1133 VkRenderpassObj render_pass(&test_device);
1134
1135 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1136 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1137 pipeline_layout_ci.setLayoutCount = 0;
1138 pipeline_layout_ci.pSetLayouts = NULL;
1139
1140 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001141 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001142 ASSERT_VK_SUCCESS(err);
1143
1144 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1145 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1146 rs_ci.pNext = nullptr;
1147 rs_ci.lineWidth = 1.0f;
1148 rs_ci.rasterizerDiscardEnable = true;
1149
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001150 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1151 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001152
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001153 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1155 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001156 {
1157 VkPipelineObj pipe(&test_device);
1158 pipe.AddShader(&vs);
1159 pipe.AddShader(&fs);
1160 pipe.AddColorAttachment();
1161 // Introduce failure by setting unsupported polygon mode
1162 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1163 pipe.SetRasterization(&rs_ci);
1164 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1165 }
1166 m_errorMonitor->VerifyFound();
1167
1168 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1170 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001171 {
1172 VkPipelineObj pipe(&test_device);
1173 pipe.AddShader(&vs);
1174 pipe.AddShader(&fs);
1175 pipe.AddColorAttachment();
1176 // Introduce failure by setting unsupported polygon mode
1177 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1178 pipe.SetRasterization(&rs_ci);
1179 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1180 }
1181 m_errorMonitor->VerifyFound();
1182
Cortd889ff92016-07-27 09:51:27 -07001183 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1184}
1185
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001186#endif // PARAMETER_VALIDATION_TESTS
1187
Tobin Ehlis0788f522015-05-26 16:11:58 -06001188#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001189#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001190TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001191{
1192 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001193 VkFenceCreateInfo fenceInfo = {};
1194 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1195 fenceInfo.pNext = NULL;
1196 fenceInfo.flags = 0;
1197
Mike Weiblencce7ec72016-10-17 19:33:05 -06001198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001199
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001200 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001201
1202 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1203 vk_testing::Buffer buffer;
1204 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001205
Tony Barbourfe3351b2015-07-28 10:17:20 -06001206 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001207 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001208 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001209
1210 testFence.init(*m_device, fenceInfo);
1211
1212 // Bypass framework since it does the waits automatically
1213 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001214 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001215 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1216 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001217 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001218 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001219 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001220 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001221 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001222 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001223 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001224
1225 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001226 ASSERT_VK_SUCCESS( err );
1227
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001229 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001230
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001231 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232}
1233
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001235{
1236 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001237 VkFenceCreateInfo fenceInfo = {};
1238 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1239 fenceInfo.pNext = NULL;
1240 fenceInfo.flags = 0;
1241
Mike Weiblencce7ec72016-10-17 19:33:05 -06001242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001243
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001244 ASSERT_NO_FATAL_FAILURE(InitState());
1245 ASSERT_NO_FATAL_FAILURE(InitViewport());
1246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1247
Tony Barbourfe3351b2015-07-28 10:17:20 -06001248 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001249 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001250 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251
1252 testFence.init(*m_device, fenceInfo);
1253
1254 // Bypass framework since it does the waits automatically
1255 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001256 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001257 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1258 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001259 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001260 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001261 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001262 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001263 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001264 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001265 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001266
1267 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001268 ASSERT_VK_SUCCESS( err );
1269
Jon Ashburnf19916e2016-01-11 13:12:43 -07001270 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001271 VkCommandBufferBeginInfo info = {};
1272 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1273 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001274 info.renderPass = VK_NULL_HANDLE;
1275 info.subpass = 0;
1276 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001277 info.occlusionQueryEnable = VK_FALSE;
1278 info.queryFlags = 0;
1279 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001280
1281 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001282 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001283
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001284 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001285}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001286#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001287
Tobin Ehlisf11be982016-05-11 13:52:53 -06001288TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1289 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1290 "buffer and image to memory such that they will alias.");
1291 VkResult err;
1292 bool pass;
1293 ASSERT_NO_FATAL_FAILURE(InitState());
1294
Tobin Ehlis077ded32016-05-12 17:39:13 -06001295 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001296 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001297 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001298 VkDeviceMemory mem; // buffer will be bound first
1299 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001300 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001301
1302 VkBufferCreateInfo buf_info = {};
1303 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1304 buf_info.pNext = NULL;
1305 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1306 buf_info.size = 256;
1307 buf_info.queueFamilyIndexCount = 0;
1308 buf_info.pQueueFamilyIndices = NULL;
1309 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1310 buf_info.flags = 0;
1311 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1312 ASSERT_VK_SUCCESS(err);
1313
Tobin Ehlis077ded32016-05-12 17:39:13 -06001314 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001315
1316 VkImageCreateInfo image_create_info = {};
1317 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1318 image_create_info.pNext = NULL;
1319 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1320 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1321 image_create_info.extent.width = 64;
1322 image_create_info.extent.height = 64;
1323 image_create_info.extent.depth = 1;
1324 image_create_info.mipLevels = 1;
1325 image_create_info.arrayLayers = 1;
1326 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001327 // Image tiling must be optimal to trigger error when aliasing linear buffer
1328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001329 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1330 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1331 image_create_info.queueFamilyIndexCount = 0;
1332 image_create_info.pQueueFamilyIndices = NULL;
1333 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1334 image_create_info.flags = 0;
1335
Tobin Ehlisf11be982016-05-11 13:52:53 -06001336 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1337 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001338 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1339 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001340
Tobin Ehlis077ded32016-05-12 17:39:13 -06001341 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1342
1343 VkMemoryAllocateInfo alloc_info = {};
1344 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1345 alloc_info.pNext = NULL;
1346 alloc_info.memoryTypeIndex = 0;
1347 // Ensure memory is big enough for both bindings
1348 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001349 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1350 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001351 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001352 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001353 vkDestroyImage(m_device->device(), image, NULL);
1354 return;
1355 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001356 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1357 ASSERT_VK_SUCCESS(err);
1358 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1359 ASSERT_VK_SUCCESS(err);
1360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001362 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001363 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1364 m_errorMonitor->VerifyFound();
1365
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001366 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001367 // aliasing buffer2
1368 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1369 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001370 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1371 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001372 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001373 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001375 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001376 m_errorMonitor->VerifyFound();
1377
1378 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001379 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001380 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001381 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001382 vkFreeMemory(m_device->device(), mem, NULL);
1383 vkFreeMemory(m_device->device(), mem_img, NULL);
1384}
1385
Tobin Ehlis35372522016-05-12 08:32:31 -06001386TEST_F(VkLayerTest, InvalidMemoryMapping) {
1387 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1388 VkResult err;
1389 bool pass;
1390 ASSERT_NO_FATAL_FAILURE(InitState());
1391
1392 VkBuffer buffer;
1393 VkDeviceMemory mem;
1394 VkMemoryRequirements mem_reqs;
1395
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001396 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1397
Tobin Ehlis35372522016-05-12 08:32:31 -06001398 VkBufferCreateInfo buf_info = {};
1399 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1400 buf_info.pNext = NULL;
1401 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1402 buf_info.size = 256;
1403 buf_info.queueFamilyIndexCount = 0;
1404 buf_info.pQueueFamilyIndices = NULL;
1405 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1406 buf_info.flags = 0;
1407 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1408 ASSERT_VK_SUCCESS(err);
1409
1410 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1411 VkMemoryAllocateInfo alloc_info = {};
1412 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1413 alloc_info.pNext = NULL;
1414 alloc_info.memoryTypeIndex = 0;
1415
1416 // Ensure memory is big enough for both bindings
1417 static const VkDeviceSize allocation_size = 0x10000;
1418 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001419 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001420 if (!pass) {
1421 vkDestroyBuffer(m_device->device(), buffer, NULL);
1422 return;
1423 }
1424 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1425 ASSERT_VK_SUCCESS(err);
1426
1427 uint8_t *pData;
1428 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001430 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1431 m_errorMonitor->VerifyFound();
1432 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001433 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001434 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1436 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1437 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001438 m_errorMonitor->VerifyFound();
1439
1440 // Unmap the memory to avoid re-map error
1441 vkUnmapMemory(m_device->device(), mem);
1442 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1444 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1445 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001446 m_errorMonitor->VerifyFound();
1447 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1449 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001450 m_errorMonitor->VerifyFound();
1451 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001453 vkUnmapMemory(m_device->device(), mem);
1454 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001455
Tobin Ehlis35372522016-05-12 08:32:31 -06001456 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001457 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001458 ASSERT_VK_SUCCESS(err);
1459 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001460 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001461 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001462 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001464 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1465 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001466
Tobin Ehlis35372522016-05-12 08:32:31 -06001467 // Now flush range that oversteps mapped range
1468 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001469 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001470 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001471 mmr.offset = atom_size;
1472 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1474 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1475 m_errorMonitor->VerifyFound();
1476
1477 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1478 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001479 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001480 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001481 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001482 mmr.size = VK_WHOLE_SIZE;
1483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001484 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1485 m_errorMonitor->VerifyFound();
1486
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001487 // Some platforms have an atomsize of 1 which makes the test meaningless
1488 if (atom_size > 3) {
1489 // Now with an offset NOT a multiple of the device limit
1490 vkUnmapMemory(m_device->device(), mem);
1491 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1492 ASSERT_VK_SUCCESS(err);
1493 mmr.offset = 3; // Not a multiple of atom_size
1494 mmr.size = VK_WHOLE_SIZE;
1495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1496 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1497 m_errorMonitor->VerifyFound();
1498
1499 // Now with a size NOT a multiple of the device limit
1500 vkUnmapMemory(m_device->device(), mem);
1501 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1502 ASSERT_VK_SUCCESS(err);
1503 mmr.offset = atom_size;
1504 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1506 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1507 m_errorMonitor->VerifyFound();
1508 }
1509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001510 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1511 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001512 if (!pass) {
1513 vkFreeMemory(m_device->device(), mem, NULL);
1514 vkDestroyBuffer(m_device->device(), buffer, NULL);
1515 return;
1516 }
1517 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1518 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1519
1520 vkDestroyBuffer(m_device->device(), buffer, NULL);
1521 vkFreeMemory(m_device->device(), mem, NULL);
1522}
1523
Chris Forbes09368e42016-10-13 11:59:22 +13001524#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001525TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1526 VkResult err;
1527 bool pass;
1528
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001529 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1530 // following declaration (which is temporarily being moved below):
1531 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001532 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001533 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001534 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001535 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001536 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001537 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001538
1539 ASSERT_NO_FATAL_FAILURE(InitState());
1540
Ian Elliott3f06ce52016-04-29 14:46:21 -06001541#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1542#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1543 // Use the functions from the VK_KHR_android_surface extension without
1544 // enabling that extension:
1545
1546 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001547 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1549 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001550 pass = (err != VK_SUCCESS);
1551 ASSERT_TRUE(pass);
1552 m_errorMonitor->VerifyFound();
1553#endif // VK_USE_PLATFORM_ANDROID_KHR
1554
Ian Elliott3f06ce52016-04-29 14:46:21 -06001555#if defined(VK_USE_PLATFORM_MIR_KHR)
1556 // Use the functions from the VK_KHR_mir_surface extension without enabling
1557 // that extension:
1558
1559 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001560 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001562 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1563 pass = (err != VK_SUCCESS);
1564 ASSERT_TRUE(pass);
1565 m_errorMonitor->VerifyFound();
1566
1567 // Tell whether an mir_connection supports presentation:
1568 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1570 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001571 m_errorMonitor->VerifyFound();
1572#endif // VK_USE_PLATFORM_MIR_KHR
1573
Ian Elliott3f06ce52016-04-29 14:46:21 -06001574#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1575 // Use the functions from the VK_KHR_wayland_surface extension without
1576 // enabling that extension:
1577
1578 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001579 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1581 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001582 pass = (err != VK_SUCCESS);
1583 ASSERT_TRUE(pass);
1584 m_errorMonitor->VerifyFound();
1585
1586 // Tell whether an wayland_display supports presentation:
1587 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1589 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001590 m_errorMonitor->VerifyFound();
1591#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001592#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001593
Ian Elliott3f06ce52016-04-29 14:46:21 -06001594#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001595 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1596 // TO NON-LINUX PLATFORMS:
1597 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001598 // Use the functions from the VK_KHR_win32_surface extension without
1599 // enabling that extension:
1600
1601 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001602 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1604 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001605 pass = (err != VK_SUCCESS);
1606 ASSERT_TRUE(pass);
1607 m_errorMonitor->VerifyFound();
1608
1609 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001611 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001612 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001613// Set this (for now, until all platforms are supported and tested):
1614#define NEED_TO_TEST_THIS_ON_PLATFORM
1615#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001616#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001617 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1618 // TO NON-LINUX PLATFORMS:
1619 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001620#endif
1621#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001622 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1623 // that extension:
1624
1625 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001626 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001628 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1629 pass = (err != VK_SUCCESS);
1630 ASSERT_TRUE(pass);
1631 m_errorMonitor->VerifyFound();
1632
1633 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001634 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001635 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1637 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001638 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001639// Set this (for now, until all platforms are supported and tested):
1640#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001641#endif // VK_USE_PLATFORM_XCB_KHR
1642
Ian Elliott12630812016-04-29 14:35:43 -06001643#if defined(VK_USE_PLATFORM_XLIB_KHR)
1644 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1645 // that extension:
1646
1647 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001648 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001650 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1651 pass = (err != VK_SUCCESS);
1652 ASSERT_TRUE(pass);
1653 m_errorMonitor->VerifyFound();
1654
1655 // Tell whether an Xlib VisualID supports presentation:
1656 Display *dpy = NULL;
1657 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001659 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1660 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001661// Set this (for now, until all platforms are supported and tested):
1662#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001663#endif // VK_USE_PLATFORM_XLIB_KHR
1664
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001665// Use the functions from the VK_KHR_surface extension without enabling
1666// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001667
Ian Elliott489eec02016-05-05 14:12:44 -06001668#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001669 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001671 vkDestroySurfaceKHR(instance(), surface, NULL);
1672 m_errorMonitor->VerifyFound();
1673
1674 // Check if surface supports presentation:
1675 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001677 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1678 pass = (err != VK_SUCCESS);
1679 ASSERT_TRUE(pass);
1680 m_errorMonitor->VerifyFound();
1681
1682 // Check surface capabilities:
1683 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1685 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001686 pass = (err != VK_SUCCESS);
1687 ASSERT_TRUE(pass);
1688 m_errorMonitor->VerifyFound();
1689
1690 // Check surface formats:
1691 uint32_t format_count = 0;
1692 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1694 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001695 pass = (err != VK_SUCCESS);
1696 ASSERT_TRUE(pass);
1697 m_errorMonitor->VerifyFound();
1698
1699 // Check surface present modes:
1700 uint32_t present_mode_count = 0;
1701 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1703 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001704 pass = (err != VK_SUCCESS);
1705 ASSERT_TRUE(pass);
1706 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001707#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001708
Ian Elliott1c32c772016-04-28 14:47:13 -06001709 // Use the functions from the VK_KHR_swapchain extension without enabling
1710 // that extension:
1711
1712 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001714 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1715 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001716 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001717 pass = (err != VK_SUCCESS);
1718 ASSERT_TRUE(pass);
1719 m_errorMonitor->VerifyFound();
1720
1721 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1723 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001724 pass = (err != VK_SUCCESS);
1725 ASSERT_TRUE(pass);
1726 m_errorMonitor->VerifyFound();
1727
Chris Forbeseb7d5502016-09-13 18:19:21 +12001728 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1729 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1730 VkFence fence;
1731 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1732
Ian Elliott1c32c772016-04-28 14:47:13 -06001733 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001735 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001736 pass = (err != VK_SUCCESS);
1737 ASSERT_TRUE(pass);
1738 m_errorMonitor->VerifyFound();
1739
Chris Forbeseb7d5502016-09-13 18:19:21 +12001740 vkDestroyFence(m_device->device(), fence, nullptr);
1741
Ian Elliott1c32c772016-04-28 14:47:13 -06001742 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001743 //
1744 // NOTE: Currently can't test this because a real swapchain is needed (as
1745 // opposed to the fake one we created) in order for the layer to lookup the
1746 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001747
1748 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001750 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1751 m_errorMonitor->VerifyFound();
1752}
Chris Forbes09368e42016-10-13 11:59:22 +13001753#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001754
Karl Schultz6addd812016-02-02 17:17:23 -07001755TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1756 VkResult err;
1757 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001758
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1760 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001761
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001762 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001763
1764 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001765 VkImage image;
1766 VkDeviceMemory mem;
1767 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001768
Karl Schultz6addd812016-02-02 17:17:23 -07001769 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1770 const int32_t tex_width = 32;
1771 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001772
Tony Barboureb254902015-07-15 12:50:33 -06001773 VkImageCreateInfo image_create_info = {};
1774 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001775 image_create_info.pNext = NULL;
1776 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1777 image_create_info.format = tex_format;
1778 image_create_info.extent.width = tex_width;
1779 image_create_info.extent.height = tex_height;
1780 image_create_info.extent.depth = 1;
1781 image_create_info.mipLevels = 1;
1782 image_create_info.arrayLayers = 1;
1783 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1784 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1785 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1786 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001787 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001788
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001789 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001790 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001791 mem_alloc.pNext = NULL;
1792 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001793
Chia-I Wuf7458c52015-10-26 21:10:41 +08001794 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001795 ASSERT_VK_SUCCESS(err);
1796
Karl Schultz6addd812016-02-02 17:17:23 -07001797 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001798
Mark Lobodzinski23065352015-05-29 09:32:35 -05001799 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001800
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001801 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Karl Schultz6addd812016-02-02 17:17:23 -07001802 if (!pass) { // If we can't find any unmappable memory this test doesn't
1803 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001804 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001805 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001806 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001807
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001808 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001809 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001810 ASSERT_VK_SUCCESS(err);
1811
1812 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001813 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001814 ASSERT_VK_SUCCESS(err);
1815
1816 // Map memory as if to initialize the image
1817 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001818 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001819
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001820 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001821
Chia-I Wuf7458c52015-10-26 21:10:41 +08001822 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001823 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001824}
1825
Karl Schultz6addd812016-02-02 17:17:23 -07001826TEST_F(VkLayerTest, RebindMemory) {
1827 VkResult err;
1828 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001829
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001831
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001832 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001833
1834 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001835 VkImage image;
1836 VkDeviceMemory mem1;
1837 VkDeviceMemory mem2;
1838 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001839
Karl Schultz6addd812016-02-02 17:17:23 -07001840 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1841 const int32_t tex_width = 32;
1842 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001843
Tony Barboureb254902015-07-15 12:50:33 -06001844 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001845 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1846 image_create_info.pNext = NULL;
1847 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1848 image_create_info.format = tex_format;
1849 image_create_info.extent.width = tex_width;
1850 image_create_info.extent.height = tex_height;
1851 image_create_info.extent.depth = 1;
1852 image_create_info.mipLevels = 1;
1853 image_create_info.arrayLayers = 1;
1854 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1855 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1856 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1857 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001858
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001859 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001860 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1861 mem_alloc.pNext = NULL;
1862 mem_alloc.allocationSize = 0;
1863 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001864
Karl Schultz6addd812016-02-02 17:17:23 -07001865 // Introduce failure, do NOT set memProps to
1866 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001867 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001868 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001869 ASSERT_VK_SUCCESS(err);
1870
Karl Schultz6addd812016-02-02 17:17:23 -07001871 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001872
1873 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001874 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001875 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001876
1877 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001878 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001879 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001880 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001881 ASSERT_VK_SUCCESS(err);
1882
1883 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001884 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001885 ASSERT_VK_SUCCESS(err);
1886
Karl Schultz6addd812016-02-02 17:17:23 -07001887 // Introduce validation failure, try to bind a different memory object to
1888 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001889 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001890
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001891 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001892
Chia-I Wuf7458c52015-10-26 21:10:41 +08001893 vkDestroyImage(m_device->device(), image, NULL);
1894 vkFreeMemory(m_device->device(), mem1, NULL);
1895 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001896}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001897
Karl Schultz6addd812016-02-02 17:17:23 -07001898TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001899 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001900
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1902 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001903
1904 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001905 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1906 fenceInfo.pNext = NULL;
1907 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001908
Tony Barbour300a6082015-04-07 13:44:53 -06001909 ASSERT_NO_FATAL_FAILURE(InitState());
1910 ASSERT_NO_FATAL_FAILURE(InitViewport());
1911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1912
Tony Barbourfe3351b2015-07-28 10:17:20 -06001913 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001914 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001915 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001916
1917 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001918
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001919 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001920 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1921 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001922 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001923 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001924 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001925 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001926 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001927 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001928 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001929
1930 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001931 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001932
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001933 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001934}
Chris Forbes4e44c912016-06-16 10:20:00 +12001935
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001936TEST_F(VkLayerTest, InvalidUsageBits) {
1937 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1938 "Initialize buffer with wrong usage then perform copy expecting errors "
1939 "from both the image and the buffer (2 calls)");
1940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001941
1942 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001943 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001944 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001945 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001946 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001947
Tony Barbourf92621a2016-05-02 14:28:12 -06001948 VkImageView dsv;
1949 VkImageViewCreateInfo dsvci = {};
1950 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1951 dsvci.image = image.handle();
1952 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1953 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1954 dsvci.subresourceRange.layerCount = 1;
1955 dsvci.subresourceRange.baseMipLevel = 0;
1956 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001957 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001958
Tony Barbourf92621a2016-05-02 14:28:12 -06001959 // Create a view with depth / stencil aspect for image with different usage
1960 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001961
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001962 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001963
1964 // Initialize buffer with TRANSFER_DST usage
1965 vk_testing::Buffer buffer;
1966 VkMemoryPropertyFlags reqs = 0;
1967 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1968 VkBufferImageCopy region = {};
1969 region.bufferRowLength = 128;
1970 region.bufferImageHeight = 128;
1971 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1972 region.imageSubresource.layerCount = 1;
1973 region.imageExtent.height = 16;
1974 region.imageExtent.width = 16;
1975 region.imageExtent.depth = 1;
1976
Tony Barbourf92621a2016-05-02 14:28:12 -06001977 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1978 // TRANSFER_DST
1979 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001980
Chris Forbesda581202016-10-06 18:25:26 +13001981 // two separate errors from this call:
1982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1984
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001985 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1986 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001987 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001988}
Tony Barbour75d79f02016-08-30 09:39:07 -06001989
Tony Barbour75d79f02016-08-30 09:39:07 -06001990
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001991#endif // MEM_TRACKER_TESTS
1992
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001993#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001994
1995TEST_F(VkLayerTest, LeakAnObject) {
1996 VkResult err;
1997
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001998 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001999
2000 // Note that we have to create a new device since destroying the
2001 // framework's device causes Teardown() to fail and just calling Teardown
2002 // will destroy the errorMonitor.
2003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002005
2006 ASSERT_NO_FATAL_FAILURE(InitState());
2007
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002008 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002009 std::vector<VkDeviceQueueCreateInfo> queue_info;
2010 queue_info.reserve(queue_props.size());
2011 std::vector<std::vector<float>> queue_priorities;
2012 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2013 VkDeviceQueueCreateInfo qi = {};
2014 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2015 qi.pNext = NULL;
2016 qi.queueFamilyIndex = i;
2017 qi.queueCount = queue_props[i].queueCount;
2018 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2019 qi.pQueuePriorities = queue_priorities[i].data();
2020 queue_info.push_back(qi);
2021 }
2022
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002023 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002024
2025 // The sacrificial device object
2026 VkDevice testDevice;
2027 VkDeviceCreateInfo device_create_info = {};
2028 auto features = m_device->phy().features();
2029 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2030 device_create_info.pNext = NULL;
2031 device_create_info.queueCreateInfoCount = queue_info.size();
2032 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002033 device_create_info.enabledLayerCount = 0;
2034 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002035 device_create_info.pEnabledFeatures = &features;
2036 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2037 ASSERT_VK_SUCCESS(err);
2038
2039 VkFence fence;
2040 VkFenceCreateInfo fence_create_info = {};
2041 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2042 fence_create_info.pNext = NULL;
2043 fence_create_info.flags = 0;
2044 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2045 ASSERT_VK_SUCCESS(err);
2046
2047 // Induce failure by not calling vkDestroyFence
2048 vkDestroyDevice(testDevice, NULL);
2049 m_errorMonitor->VerifyFound();
2050}
2051
2052TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2053
2054 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2055 "attempt to delete them from another.");
2056
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002058
Cody Northropc31a84f2016-08-22 10:41:47 -06002059 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002060 VkCommandPool command_pool_one;
2061 VkCommandPool command_pool_two;
2062
2063 VkCommandPoolCreateInfo pool_create_info{};
2064 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2065 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2066 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2067
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002068 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002069
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002070 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002071
2072 VkCommandBuffer command_buffer[9];
2073 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002074 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002075 command_buffer_allocate_info.commandPool = command_pool_one;
2076 command_buffer_allocate_info.commandBufferCount = 9;
2077 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002078 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002079
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002080 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002081
2082 m_errorMonitor->VerifyFound();
2083
2084 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2085 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2086}
2087
2088TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2089 VkResult err;
2090
2091 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002092 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002093
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002095
2096 ASSERT_NO_FATAL_FAILURE(InitState());
2097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2098
2099 VkDescriptorPoolSize ds_type_count = {};
2100 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2101 ds_type_count.descriptorCount = 1;
2102
2103 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2104 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2105 ds_pool_ci.pNext = NULL;
2106 ds_pool_ci.flags = 0;
2107 ds_pool_ci.maxSets = 1;
2108 ds_pool_ci.poolSizeCount = 1;
2109 ds_pool_ci.pPoolSizes = &ds_type_count;
2110
2111 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002112 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002113 ASSERT_VK_SUCCESS(err);
2114
2115 // Create a second descriptor pool
2116 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002117 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002118 ASSERT_VK_SUCCESS(err);
2119
2120 VkDescriptorSetLayoutBinding dsl_binding = {};
2121 dsl_binding.binding = 0;
2122 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2123 dsl_binding.descriptorCount = 1;
2124 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2125 dsl_binding.pImmutableSamplers = NULL;
2126
2127 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2128 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2129 ds_layout_ci.pNext = NULL;
2130 ds_layout_ci.bindingCount = 1;
2131 ds_layout_ci.pBindings = &dsl_binding;
2132
2133 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002134 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002135 ASSERT_VK_SUCCESS(err);
2136
2137 VkDescriptorSet descriptorSet;
2138 VkDescriptorSetAllocateInfo alloc_info = {};
2139 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2140 alloc_info.descriptorSetCount = 1;
2141 alloc_info.descriptorPool = ds_pool_one;
2142 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002143 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002144 ASSERT_VK_SUCCESS(err);
2145
2146 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2147
2148 m_errorMonitor->VerifyFound();
2149
2150 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2151 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2152 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2153}
2154
2155TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002157
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002158 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002159
2160 ASSERT_NO_FATAL_FAILURE(InitState());
2161
2162 // Pass bogus handle into GetImageMemoryRequirements
2163 VkMemoryRequirements mem_reqs;
2164 uint64_t fakeImageHandle = 0xCADECADE;
2165 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2166
2167 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2168
2169 m_errorMonitor->VerifyFound();
2170}
2171
Karl Schultz6addd812016-02-02 17:17:23 -07002172TEST_F(VkLayerTest, PipelineNotBound) {
2173 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002174
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002175 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002176
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002178
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002179 ASSERT_NO_FATAL_FAILURE(InitState());
2180 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002181
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002182 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002183 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2184 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002185
2186 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002187 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2188 ds_pool_ci.pNext = NULL;
2189 ds_pool_ci.maxSets = 1;
2190 ds_pool_ci.poolSizeCount = 1;
2191 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002192
2193 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002194 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002195 ASSERT_VK_SUCCESS(err);
2196
2197 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002198 dsl_binding.binding = 0;
2199 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2200 dsl_binding.descriptorCount = 1;
2201 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2202 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002203
2204 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002205 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2206 ds_layout_ci.pNext = NULL;
2207 ds_layout_ci.bindingCount = 1;
2208 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002209
2210 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002211 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002212 ASSERT_VK_SUCCESS(err);
2213
2214 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002215 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002216 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002217 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002218 alloc_info.descriptorPool = ds_pool;
2219 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002220 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002221 ASSERT_VK_SUCCESS(err);
2222
2223 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002224 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2225 pipeline_layout_ci.pNext = NULL;
2226 pipeline_layout_ci.setLayoutCount = 1;
2227 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002228
2229 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002230 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002231 ASSERT_VK_SUCCESS(err);
2232
Mark Youngad779052016-01-06 14:26:04 -07002233 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002234
2235 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002236 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002237
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002238 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002239
Chia-I Wuf7458c52015-10-26 21:10:41 +08002240 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2241 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2242 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002243}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002244
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002245TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2246 VkResult err;
2247
2248 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2249 "during bind[Buffer|Image]Memory time");
2250
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002251 ASSERT_NO_FATAL_FAILURE(InitState());
2252
2253 // Create an image, allocate memory, set a bad typeIndex and then try to
2254 // bind it
2255 VkImage image;
2256 VkDeviceMemory mem;
2257 VkMemoryRequirements mem_reqs;
2258 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2259 const int32_t tex_width = 32;
2260 const int32_t tex_height = 32;
2261
2262 VkImageCreateInfo image_create_info = {};
2263 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2264 image_create_info.pNext = NULL;
2265 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2266 image_create_info.format = tex_format;
2267 image_create_info.extent.width = tex_width;
2268 image_create_info.extent.height = tex_height;
2269 image_create_info.extent.depth = 1;
2270 image_create_info.mipLevels = 1;
2271 image_create_info.arrayLayers = 1;
2272 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2273 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2274 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2275 image_create_info.flags = 0;
2276
2277 VkMemoryAllocateInfo mem_alloc = {};
2278 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2279 mem_alloc.pNext = NULL;
2280 mem_alloc.allocationSize = 0;
2281 mem_alloc.memoryTypeIndex = 0;
2282
2283 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2284 ASSERT_VK_SUCCESS(err);
2285
2286 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2287 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002288
2289 // Introduce Failure, select invalid TypeIndex
2290 VkPhysicalDeviceMemoryProperties memory_info;
2291
2292 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2293 unsigned int i;
2294 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2295 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2296 mem_alloc.memoryTypeIndex = i;
2297 break;
2298 }
2299 }
2300 if (i >= memory_info.memoryTypeCount) {
2301 printf("No invalid memory type index could be found; skipped.\n");
2302 vkDestroyImage(m_device->device(), image, NULL);
2303 return;
2304 }
2305
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002307
2308 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2309 ASSERT_VK_SUCCESS(err);
2310
2311 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2312 (void)err;
2313
2314 m_errorMonitor->VerifyFound();
2315
2316 vkDestroyImage(m_device->device(), image, NULL);
2317 vkFreeMemory(m_device->device(), mem, NULL);
2318}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002319
Karl Schultz6addd812016-02-02 17:17:23 -07002320TEST_F(VkLayerTest, BindInvalidMemory) {
2321 VkResult err;
2322 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002323
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002325
Tobin Ehlisec598302015-09-15 15:02:17 -06002326 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002327
2328 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002329 VkImage image;
2330 VkDeviceMemory mem;
2331 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002332
Karl Schultz6addd812016-02-02 17:17:23 -07002333 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2334 const int32_t tex_width = 32;
2335 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002336
2337 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002338 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2339 image_create_info.pNext = NULL;
2340 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2341 image_create_info.format = tex_format;
2342 image_create_info.extent.width = tex_width;
2343 image_create_info.extent.height = tex_height;
2344 image_create_info.extent.depth = 1;
2345 image_create_info.mipLevels = 1;
2346 image_create_info.arrayLayers = 1;
2347 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2348 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2349 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2350 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002351
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002352 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002353 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2354 mem_alloc.pNext = NULL;
2355 mem_alloc.allocationSize = 0;
2356 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002357
Chia-I Wuf7458c52015-10-26 21:10:41 +08002358 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002359 ASSERT_VK_SUCCESS(err);
2360
Karl Schultz6addd812016-02-02 17:17:23 -07002361 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002362
2363 mem_alloc.allocationSize = mem_reqs.size;
2364
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002365 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002366 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002367
2368 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002369 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002370 ASSERT_VK_SUCCESS(err);
2371
2372 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002373 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002374
2375 // Try to bind free memory that has been freed
2376 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2377 // This may very well return an error.
2378 (void)err;
2379
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002380 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002381
Chia-I Wuf7458c52015-10-26 21:10:41 +08002382 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002383}
2384
Karl Schultz6addd812016-02-02 17:17:23 -07002385TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2386 VkResult err;
2387 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002388
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002390
Tobin Ehlisec598302015-09-15 15:02:17 -06002391 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002392
Karl Schultz6addd812016-02-02 17:17:23 -07002393 // Create an image object, allocate memory, destroy the object and then try
2394 // to bind it
2395 VkImage image;
2396 VkDeviceMemory mem;
2397 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002398
Karl Schultz6addd812016-02-02 17:17:23 -07002399 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2400 const int32_t tex_width = 32;
2401 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002402
2403 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002404 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2405 image_create_info.pNext = NULL;
2406 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2407 image_create_info.format = tex_format;
2408 image_create_info.extent.width = tex_width;
2409 image_create_info.extent.height = tex_height;
2410 image_create_info.extent.depth = 1;
2411 image_create_info.mipLevels = 1;
2412 image_create_info.arrayLayers = 1;
2413 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2414 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2415 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2416 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002417
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002418 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002419 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2420 mem_alloc.pNext = NULL;
2421 mem_alloc.allocationSize = 0;
2422 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002423
Chia-I Wuf7458c52015-10-26 21:10:41 +08002424 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002425 ASSERT_VK_SUCCESS(err);
2426
Karl Schultz6addd812016-02-02 17:17:23 -07002427 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002428
2429 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002430 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002431 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002432
2433 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002434 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002435 ASSERT_VK_SUCCESS(err);
2436
2437 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002438 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002439 ASSERT_VK_SUCCESS(err);
2440
2441 // Now Try to bind memory to this destroyed object
2442 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2443 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002444 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002445
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002446 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002447
Chia-I Wuf7458c52015-10-26 21:10:41 +08002448 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002449}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002450
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002451#endif // OBJ_TRACKER_TESTS
2452
Tobin Ehlis0788f522015-05-26 16:11:58 -06002453#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002454
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002455TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2456 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2457
2458 ASSERT_NO_FATAL_FAILURE(InitState());
2459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2460
2461 VkVertexInputBindingDescription input_binding;
2462 memset(&input_binding, 0, sizeof(input_binding));
2463
2464 VkVertexInputAttributeDescription input_attribs;
2465 memset(&input_attribs, 0, sizeof(input_attribs));
2466
2467 // Pick a really bad format for this purpose and make sure it should fail
2468 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2469 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2470 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2471 printf("Format unsuitable for test; skipped.\n");
2472 return;
2473 }
2474
2475 input_attribs.location = 0;
2476 char const *vsSource = "#version 450\n"
2477 "\n"
2478 "out gl_PerVertex {\n"
2479 " vec4 gl_Position;\n"
2480 "};\n"
2481 "void main(){\n"
2482 " gl_Position = vec4(1);\n"
2483 "}\n";
2484 char const *fsSource = "#version 450\n"
2485 "\n"
2486 "layout(location=0) out vec4 color;\n"
2487 "void main(){\n"
2488 " color = vec4(1);\n"
2489 "}\n";
2490
2491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2492 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2493 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2494
2495 VkPipelineObj pipe(m_device);
2496 pipe.AddColorAttachment();
2497 pipe.AddShader(&vs);
2498 pipe.AddShader(&fs);
2499
2500 pipe.AddVertexInputBindings(&input_binding, 1);
2501 pipe.AddVertexInputAttribs(&input_attribs, 1);
2502
2503 VkDescriptorSetObj descriptorSet(m_device);
2504 descriptorSet.AppendDummy();
2505 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2506
2507 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2508
2509 m_errorMonitor->VerifyFound();
2510}
2511
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002512TEST_F(VkLayerTest, ImageSampleCounts) {
2513
2514 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2515 "validation errors.");
2516 ASSERT_NO_FATAL_FAILURE(InitState());
2517
2518 VkMemoryPropertyFlags reqs = 0;
2519 VkImageCreateInfo image_create_info = {};
2520 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2521 image_create_info.pNext = NULL;
2522 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2523 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2524 image_create_info.extent.width = 256;
2525 image_create_info.extent.height = 256;
2526 image_create_info.extent.depth = 1;
2527 image_create_info.mipLevels = 1;
2528 image_create_info.arrayLayers = 1;
2529 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2530 image_create_info.flags = 0;
2531
2532 VkImageBlit blit_region = {};
2533 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2534 blit_region.srcSubresource.baseArrayLayer = 0;
2535 blit_region.srcSubresource.layerCount = 1;
2536 blit_region.srcSubresource.mipLevel = 0;
2537 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2538 blit_region.dstSubresource.baseArrayLayer = 0;
2539 blit_region.dstSubresource.layerCount = 1;
2540 blit_region.dstSubresource.mipLevel = 0;
2541
2542 // Create two images, the source with sampleCount = 2, and attempt to blit
2543 // between them
2544 {
2545 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002546 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002547 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002548 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002549 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002550 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002551 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002552 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002553 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2555 "of VK_SAMPLE_COUNT_2_BIT but "
2556 "must be VK_SAMPLE_COUNT_1_BIT");
2557 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2558 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002559 m_errorMonitor->VerifyFound();
2560 m_commandBuffer->EndCommandBuffer();
2561 }
2562
2563 // Create two images, the dest with sampleCount = 4, and attempt to blit
2564 // between them
2565 {
2566 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002567 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002568 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002569 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002570 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002571 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002572 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002573 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002574 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2576 "of VK_SAMPLE_COUNT_4_BIT but "
2577 "must be VK_SAMPLE_COUNT_1_BIT");
2578 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2579 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002580 m_errorMonitor->VerifyFound();
2581 m_commandBuffer->EndCommandBuffer();
2582 }
2583
2584 VkBufferImageCopy copy_region = {};
2585 copy_region.bufferRowLength = 128;
2586 copy_region.bufferImageHeight = 128;
2587 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2588 copy_region.imageSubresource.layerCount = 1;
2589 copy_region.imageExtent.height = 64;
2590 copy_region.imageExtent.width = 64;
2591 copy_region.imageExtent.depth = 1;
2592
2593 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2594 // buffer to image
2595 {
2596 vk_testing::Buffer src_buffer;
2597 VkMemoryPropertyFlags reqs = 0;
2598 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2599 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002600 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002601 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002602 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002603 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2605 "of VK_SAMPLE_COUNT_8_BIT but "
2606 "must be VK_SAMPLE_COUNT_1_BIT");
2607 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2608 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002609 m_errorMonitor->VerifyFound();
2610 m_commandBuffer->EndCommandBuffer();
2611 }
2612
2613 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2614 // image to buffer
2615 {
2616 vk_testing::Buffer dst_buffer;
2617 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2618 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002619 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002620 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002621 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002622 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2624 "of VK_SAMPLE_COUNT_2_BIT but "
2625 "must be VK_SAMPLE_COUNT_1_BIT");
2626 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002627 dst_buffer.handle(), 1, &copy_region);
2628 m_errorMonitor->VerifyFound();
2629 m_commandBuffer->EndCommandBuffer();
2630 }
2631}
2632
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002633TEST_F(VkLayerTest, BlitImageFormats) {
2634
2635 // Image blit with mismatched formats
2636 const char * expected_message =
2637 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2638 " the other one must also have signed/unsigned integer format";
2639
2640 ASSERT_NO_FATAL_FAILURE(InitState());
2641
2642 VkImageObj src_image(m_device);
2643 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2644 VkImageObj dst_image(m_device);
2645 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2646 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002647 dst_image2.init(64, 64, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002648
2649 VkImageBlit blitRegion = {};
2650 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2651 blitRegion.srcSubresource.baseArrayLayer = 0;
2652 blitRegion.srcSubresource.layerCount = 1;
2653 blitRegion.srcSubresource.mipLevel = 0;
2654 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2655 blitRegion.dstSubresource.baseArrayLayer = 0;
2656 blitRegion.dstSubresource.layerCount = 1;
2657 blitRegion.dstSubresource.mipLevel = 0;
2658
2659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2660
2661 // Unsigned int vs not an int
2662 BeginCommandBuffer();
2663 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2664 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2665
2666 m_errorMonitor->VerifyFound();
2667
2668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2669
2670 // Unsigned int vs signed int
2671 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2672 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2673
2674 m_errorMonitor->VerifyFound();
2675
2676 EndCommandBuffer();
2677}
2678
2679
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002680TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2681 VkResult err;
2682 bool pass;
2683
2684 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2685 ASSERT_NO_FATAL_FAILURE(InitState());
2686
2687 // If w/d/h granularity is 1, test is not meaningful
2688 // TODO: When virtual device limits are available, create a set of limits for this test that
2689 // will always have a granularity of > 1 for w, h, and d
2690 auto index = m_device->graphics_queue_node_index_;
2691 auto queue_family_properties = m_device->phy().queue_properties();
2692
2693 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2694 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2695 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2696 return;
2697 }
2698
2699 // Create two images of different types and try to copy between them
2700 VkImage srcImage;
2701 VkImage dstImage;
2702 VkDeviceMemory srcMem;
2703 VkDeviceMemory destMem;
2704 VkMemoryRequirements memReqs;
2705
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002706 VkImageCreateInfo image_create_info = {};
2707 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2708 image_create_info.pNext = NULL;
2709 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2710 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2711 image_create_info.extent.width = 32;
2712 image_create_info.extent.height = 32;
2713 image_create_info.extent.depth = 1;
2714 image_create_info.mipLevels = 1;
2715 image_create_info.arrayLayers = 4;
2716 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2717 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2718 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2719 image_create_info.flags = 0;
2720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002721 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002722 ASSERT_VK_SUCCESS(err);
2723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002724 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002725 ASSERT_VK_SUCCESS(err);
2726
2727 // Allocate memory
2728 VkMemoryAllocateInfo memAlloc = {};
2729 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2730 memAlloc.pNext = NULL;
2731 memAlloc.allocationSize = 0;
2732 memAlloc.memoryTypeIndex = 0;
2733
2734 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2735 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002736 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002737 ASSERT_TRUE(pass);
2738 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2739 ASSERT_VK_SUCCESS(err);
2740
2741 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2742 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002743 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002744 ASSERT_VK_SUCCESS(err);
2745 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2746 ASSERT_VK_SUCCESS(err);
2747
2748 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2749 ASSERT_VK_SUCCESS(err);
2750 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2751 ASSERT_VK_SUCCESS(err);
2752
2753 BeginCommandBuffer();
2754 VkImageCopy copyRegion;
2755 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2756 copyRegion.srcSubresource.mipLevel = 0;
2757 copyRegion.srcSubresource.baseArrayLayer = 0;
2758 copyRegion.srcSubresource.layerCount = 1;
2759 copyRegion.srcOffset.x = 0;
2760 copyRegion.srcOffset.y = 0;
2761 copyRegion.srcOffset.z = 0;
2762 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2763 copyRegion.dstSubresource.mipLevel = 0;
2764 copyRegion.dstSubresource.baseArrayLayer = 0;
2765 copyRegion.dstSubresource.layerCount = 1;
2766 copyRegion.dstOffset.x = 0;
2767 copyRegion.dstOffset.y = 0;
2768 copyRegion.dstOffset.z = 0;
2769 copyRegion.extent.width = 1;
2770 copyRegion.extent.height = 1;
2771 copyRegion.extent.depth = 1;
2772
2773 // Introduce failure by setting srcOffset to a bad granularity value
2774 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2776 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002777 m_errorMonitor->VerifyFound();
2778
2779 // Introduce failure by setting extent to a bad granularity value
2780 copyRegion.srcOffset.y = 0;
2781 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2783 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002784 m_errorMonitor->VerifyFound();
2785
2786 // Now do some buffer/image copies
2787 vk_testing::Buffer buffer;
2788 VkMemoryPropertyFlags reqs = 0;
2789 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2790 VkBufferImageCopy region = {};
2791 region.bufferOffset = 0;
2792 region.bufferRowLength = 3;
2793 region.bufferImageHeight = 128;
2794 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2795 region.imageSubresource.layerCount = 1;
2796 region.imageExtent.height = 16;
2797 region.imageExtent.width = 16;
2798 region.imageExtent.depth = 1;
2799 region.imageOffset.x = 0;
2800 region.imageOffset.y = 0;
2801 region.imageOffset.z = 0;
2802
2803 // Introduce failure by setting bufferRowLength to a bad granularity value
2804 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2806 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2807 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002808 m_errorMonitor->VerifyFound();
2809 region.bufferRowLength = 128;
2810
2811 // Introduce failure by setting bufferOffset to a bad granularity value
2812 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2814 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2815 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002816 m_errorMonitor->VerifyFound();
2817 region.bufferOffset = 0;
2818
2819 // Introduce failure by setting bufferImageHeight to a bad granularity value
2820 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2822 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2823 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002824 m_errorMonitor->VerifyFound();
2825 region.bufferImageHeight = 128;
2826
2827 // Introduce failure by setting imageExtent to a bad granularity value
2828 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2830 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2831 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002832 m_errorMonitor->VerifyFound();
2833 region.imageExtent.width = 16;
2834
2835 // Introduce failure by setting imageOffset to a bad granularity value
2836 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2838 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2839 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002840 m_errorMonitor->VerifyFound();
2841
2842 EndCommandBuffer();
2843
2844 vkDestroyImage(m_device->device(), srcImage, NULL);
2845 vkDestroyImage(m_device->device(), dstImage, NULL);
2846 vkFreeMemory(m_device->device(), srcMem, NULL);
2847 vkFreeMemory(m_device->device(), destMem, NULL);
2848}
2849
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002850TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002851 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2852 "attempt to submit them on a queue created in a different "
2853 "queue family.");
2854
Cody Northropc31a84f2016-08-22 10:41:47 -06002855 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002856 // This test is meaningless unless we have multiple queue families
2857 auto queue_family_properties = m_device->phy().queue_properties();
2858 if (queue_family_properties.size() < 2) {
2859 return;
2860 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002862 // Get safe index of another queue family
2863 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2864 ASSERT_NO_FATAL_FAILURE(InitState());
2865 // Create a second queue using a different queue family
2866 VkQueue other_queue;
2867 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2868
2869 // Record an empty cmd buffer
2870 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2871 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2872 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2873 vkEndCommandBuffer(m_commandBuffer->handle());
2874
2875 // And submit on the wrong queue
2876 VkSubmitInfo submit_info = {};
2877 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2878 submit_info.commandBufferCount = 1;
2879 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002880 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002881
2882 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002883}
2884
Chris Forbes4c24a922016-11-16 08:59:10 +13002885TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2886 ASSERT_NO_FATAL_FAILURE(InitState());
2887
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002888 // There are no attachments, but refer to attachment 0.
2889 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002890 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002891 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2892 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002893 };
2894
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002895 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2896 nullptr,
2897 0,
2898 0,
2899 nullptr,
2900 1,
2901 subpasses,
2902 0,
2903 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002904 VkRenderPass rp;
2905
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002906 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002908 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002909 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2910 m_errorMonitor->VerifyFound();
2911}
2912
Chris Forbesa58c4522016-09-28 15:19:39 +13002913TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2914 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2915 ASSERT_NO_FATAL_FAILURE(InitState());
2916
2917 // A renderpass with two subpasses, both writing the same attachment.
2918 VkAttachmentDescription attach[] = {
2919 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2920 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2921 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2922 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2923 },
2924 };
2925 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2926 VkSubpassDescription subpasses[] = {
2927 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2928 1, &ref, nullptr, nullptr, 0, nullptr },
2929 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2930 1, &ref, nullptr, nullptr, 0, nullptr },
2931 };
2932 VkSubpassDependency dep = {
2933 0, 1,
2934 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2935 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2936 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2937 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2938 VK_DEPENDENCY_BY_REGION_BIT
2939 };
2940 VkRenderPassCreateInfo rpci = {
2941 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2942 0, 1, attach, 2, subpasses, 1, &dep
2943 };
2944 VkRenderPass rp;
2945 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2946 ASSERT_VK_SUCCESS(err);
2947
2948 VkImageObj image(m_device);
2949 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2950 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2951 VK_IMAGE_TILING_OPTIMAL, 0);
2952 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2953
2954 VkFramebufferCreateInfo fbci = {
2955 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2956 0, rp, 1, &imageView, 32, 32, 1
2957 };
2958 VkFramebuffer fb;
2959 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2960 ASSERT_VK_SUCCESS(err);
2961
2962 char const *vsSource =
2963 "#version 450\n"
2964 "void main() { gl_Position = vec4(1); }\n";
2965 char const *fsSource =
2966 "#version 450\n"
2967 "layout(location=0) out vec4 color;\n"
2968 "void main() { color = vec4(1); }\n";
2969
2970 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2971 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2972 VkPipelineObj pipe(m_device);
2973 pipe.AddColorAttachment();
2974 pipe.AddShader(&vs);
2975 pipe.AddShader(&fs);
2976 VkViewport view_port = {};
2977 m_viewports.push_back(view_port);
2978 pipe.SetViewport(m_viewports);
2979 VkRect2D rect = {};
2980 m_scissors.push_back(rect);
2981 pipe.SetScissor(m_scissors);
2982
2983 VkPipelineLayoutCreateInfo plci = {
2984 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2985 0, 0, nullptr, 0, nullptr
2986 };
2987 VkPipelineLayout pl;
2988 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2989 ASSERT_VK_SUCCESS(err);
2990 pipe.CreateVKPipeline(pl, rp);
2991
2992 BeginCommandBuffer();
2993
2994 VkRenderPassBeginInfo rpbi = {
2995 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2996 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
2997 };
2998
2999 // subtest 1: bind in the wrong subpass
3000 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3001 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3003 "built for subpass 0 but used in subpass 1");
3004 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3005 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3006 m_errorMonitor->VerifyFound();
3007
3008 vkCmdEndRenderPass(m_commandBuffer->handle());
3009
3010 // subtest 2: bind in correct subpass, then transition to next subpass
3011 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3012 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3013 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3015 "built for subpass 0 but used in subpass 1");
3016 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3017 m_errorMonitor->VerifyFound();
3018
3019 vkCmdEndRenderPass(m_commandBuffer->handle());
3020
3021 EndCommandBuffer();
3022
3023 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3024 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3025 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3026}
3027
Tony Barbour4e919972016-08-09 13:27:40 -06003028TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3029 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3030 "with extent outside of framebuffer");
3031 ASSERT_NO_FATAL_FAILURE(InitState());
3032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3035 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003036
3037 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3038 m_renderPassBeginInfo.renderArea.extent.width = 257;
3039 m_renderPassBeginInfo.renderArea.extent.height = 257;
3040 BeginCommandBuffer();
3041 m_errorMonitor->VerifyFound();
3042}
3043
3044TEST_F(VkLayerTest, DisabledIndependentBlend) {
3045 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3046 "blend and then specifying different blend states for two "
3047 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003048 VkPhysicalDeviceFeatures features = {};
3049 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003050 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003051
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3053 "Invalid Pipeline CreateInfo: If independent blend feature not "
3054 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003055
Cody Northropc31a84f2016-08-22 10:41:47 -06003056 VkDescriptorSetObj descriptorSet(m_device);
3057 descriptorSet.AppendDummy();
3058 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003059
Cody Northropc31a84f2016-08-22 10:41:47 -06003060 VkPipelineObj pipeline(m_device);
3061 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003062 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003063 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003064
Cody Northropc31a84f2016-08-22 10:41:47 -06003065 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3066 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3067 att_state1.blendEnable = VK_TRUE;
3068 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3069 att_state2.blendEnable = VK_FALSE;
3070 pipeline.AddColorAttachment(0, &att_state1);
3071 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003072 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003073 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003074}
3075
3076TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3077 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3078 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003079 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003080
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3082 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003083
3084 // Create a renderPass with a single color attachment
3085 VkAttachmentReference attach = {};
3086 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3087 VkSubpassDescription subpass = {};
3088 VkRenderPassCreateInfo rpci = {};
3089 rpci.subpassCount = 1;
3090 rpci.pSubpasses = &subpass;
3091 rpci.attachmentCount = 1;
3092 VkAttachmentDescription attach_desc = {};
3093 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3094 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3095 rpci.pAttachments = &attach_desc;
3096 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3097 VkRenderPass rp;
3098 subpass.pDepthStencilAttachment = &attach;
3099 subpass.pColorAttachments = NULL;
3100 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3101 m_errorMonitor->VerifyFound();
3102}
3103
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003104TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3105 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3106 "attachment reference of VK_ATTACHMENT_UNUSED");
3107
3108 ASSERT_NO_FATAL_FAILURE(InitState());
3109 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3110
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003112
3113 VkAttachmentReference color_attach = {};
3114 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3115 color_attach.attachment = 0;
3116 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3117 VkSubpassDescription subpass = {};
3118 subpass.colorAttachmentCount = 1;
3119 subpass.pColorAttachments = &color_attach;
3120 subpass.preserveAttachmentCount = 1;
3121 subpass.pPreserveAttachments = &preserve_attachment;
3122
3123 VkRenderPassCreateInfo rpci = {};
3124 rpci.subpassCount = 1;
3125 rpci.pSubpasses = &subpass;
3126 rpci.attachmentCount = 1;
3127 VkAttachmentDescription attach_desc = {};
3128 attach_desc.format = VK_FORMAT_UNDEFINED;
3129 rpci.pAttachments = &attach_desc;
3130 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3131 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003132 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003133
3134 m_errorMonitor->VerifyFound();
3135
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003136 if (result == VK_SUCCESS) {
3137 vkDestroyRenderPass(m_device->device(), rp, NULL);
3138 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003139}
3140
Chris Forbesc5389742016-06-29 11:49:23 +12003141TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003142 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3143 "when the source of a subpass multisample resolve "
3144 "does not have multiple samples.");
3145
Chris Forbesc5389742016-06-29 11:49:23 +12003146 ASSERT_NO_FATAL_FAILURE(InitState());
3147
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3149 "Subpass 0 requests multisample resolve from attachment 0 which has "
3150 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003151
3152 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003153 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3154 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3155 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3156 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3157 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3158 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003159 };
3160
3161 VkAttachmentReference color = {
3162 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3163 };
3164
3165 VkAttachmentReference resolve = {
3166 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3167 };
3168
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003169 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003170
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003171 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003172
3173 VkRenderPass rp;
3174 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3175
3176 m_errorMonitor->VerifyFound();
3177
3178 if (err == VK_SUCCESS)
3179 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3180}
3181
3182TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003183 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3184 "when a subpass multisample resolve operation is "
3185 "requested, and the destination of that resolve has "
3186 "multiple samples.");
3187
Chris Forbesc5389742016-06-29 11:49:23 +12003188 ASSERT_NO_FATAL_FAILURE(InitState());
3189
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3191 "Subpass 0 requests multisample resolve into attachment 1, which "
3192 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003193
3194 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003195 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3196 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3197 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3198 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3199 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3200 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003201 };
3202
3203 VkAttachmentReference color = {
3204 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3205 };
3206
3207 VkAttachmentReference resolve = {
3208 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3209 };
3210
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003211 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003212
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003213 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003214
3215 VkRenderPass rp;
3216 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3217
3218 m_errorMonitor->VerifyFound();
3219
3220 if (err == VK_SUCCESS)
3221 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3222}
3223
Chris Forbes3f128ef2016-06-29 14:58:53 +12003224TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003225 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3226 "when the color and depth attachments used by a subpass "
3227 "have inconsistent sample counts");
3228
Chris Forbes3f128ef2016-06-29 14:58:53 +12003229 ASSERT_NO_FATAL_FAILURE(InitState());
3230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3232 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003233
3234 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003235 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3236 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3237 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3238 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3239 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3240 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003241 };
3242
3243 VkAttachmentReference color[] = {
3244 {
3245 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3246 },
3247 {
3248 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3249 },
3250 };
3251
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003252 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003253
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003254 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003255
3256 VkRenderPass rp;
3257 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3258
3259 m_errorMonitor->VerifyFound();
3260
3261 if (err == VK_SUCCESS)
3262 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3263}
3264
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003265TEST_F(VkLayerTest, FramebufferCreateErrors) {
3266 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003267 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003268 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003269 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3270 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3271 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3272 " 6. Framebuffer attachment where dimensions don't match\n"
3273 " 7. Framebuffer attachment w/o identity swizzle\n"
3274 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003275
3276 ASSERT_NO_FATAL_FAILURE(InitState());
3277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3278
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3280 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3281 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003282
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003283 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003284 VkAttachmentReference attach = {};
3285 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3286 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003287 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003288 VkRenderPassCreateInfo rpci = {};
3289 rpci.subpassCount = 1;
3290 rpci.pSubpasses = &subpass;
3291 rpci.attachmentCount = 1;
3292 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003293 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003294 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003295 rpci.pAttachments = &attach_desc;
3296 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3297 VkRenderPass rp;
3298 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3299 ASSERT_VK_SUCCESS(err);
3300
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003301 VkImageView ivs[2];
3302 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3303 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003304 VkFramebufferCreateInfo fb_info = {};
3305 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3306 fb_info.pNext = NULL;
3307 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003308 // Set mis-matching attachmentCount
3309 fb_info.attachmentCount = 2;
3310 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003311 fb_info.width = 100;
3312 fb_info.height = 100;
3313 fb_info.layers = 1;
3314
3315 VkFramebuffer fb;
3316 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3317
3318 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003319 if (err == VK_SUCCESS) {
3320 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3321 }
3322 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003323
3324 // Create a renderPass with a depth-stencil attachment created with
3325 // IMAGE_USAGE_COLOR_ATTACHMENT
3326 // Add our color attachment to pDepthStencilAttachment
3327 subpass.pDepthStencilAttachment = &attach;
3328 subpass.pColorAttachments = NULL;
3329 VkRenderPass rp_ds;
3330 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3331 ASSERT_VK_SUCCESS(err);
3332 // Set correct attachment count, but attachment has COLOR usage bit set
3333 fb_info.attachmentCount = 1;
3334 fb_info.renderPass = rp_ds;
3335
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003337 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3338
3339 m_errorMonitor->VerifyFound();
3340 if (err == VK_SUCCESS) {
3341 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3342 }
3343 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003344
3345 // Create new renderpass with alternate attachment format from fb
3346 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3347 subpass.pDepthStencilAttachment = NULL;
3348 subpass.pColorAttachments = &attach;
3349 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3350 ASSERT_VK_SUCCESS(err);
3351
3352 // Cause error due to mis-matched formats between rp & fb
3353 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3354 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3356 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003357 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3358
3359 m_errorMonitor->VerifyFound();
3360 if (err == VK_SUCCESS) {
3361 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3362 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003363 vkDestroyRenderPass(m_device->device(), rp, NULL);
3364
3365 // Create new renderpass with alternate sample count from fb
3366 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3367 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3368 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3369 ASSERT_VK_SUCCESS(err);
3370
3371 // Cause error due to mis-matched sample count between rp & fb
3372 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3374 "that do not match the "
3375 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003376 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3377
3378 m_errorMonitor->VerifyFound();
3379 if (err == VK_SUCCESS) {
3380 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3381 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003382
3383 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003384
3385 // Create a custom imageView with non-1 mip levels
3386 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003387 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003388 ASSERT_TRUE(image.initialized());
3389
3390 VkImageView view;
3391 VkImageViewCreateInfo ivci = {};
3392 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3393 ivci.image = image.handle();
3394 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3395 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3396 ivci.subresourceRange.layerCount = 1;
3397 ivci.subresourceRange.baseMipLevel = 0;
3398 // Set level count 2 (only 1 is allowed for FB attachment)
3399 ivci.subresourceRange.levelCount = 2;
3400 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3401 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3402 ASSERT_VK_SUCCESS(err);
3403 // Re-create renderpass to have matching sample count
3404 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3405 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3406 ASSERT_VK_SUCCESS(err);
3407
3408 fb_info.renderPass = rp;
3409 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003411 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3412
3413 m_errorMonitor->VerifyFound();
3414 if (err == VK_SUCCESS) {
3415 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3416 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003417 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003418 // Update view to original color buffer and grow FB dimensions too big
3419 fb_info.pAttachments = ivs;
3420 fb_info.height = 1024;
3421 fb_info.width = 1024;
3422 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3424 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003425 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3426
3427 m_errorMonitor->VerifyFound();
3428 if (err == VK_SUCCESS) {
3429 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3430 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003431 // Create view attachment with non-identity swizzle
3432 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3433 ivci.image = image.handle();
3434 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3435 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3436 ivci.subresourceRange.layerCount = 1;
3437 ivci.subresourceRange.baseMipLevel = 0;
3438 ivci.subresourceRange.levelCount = 1;
3439 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3440 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3441 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3442 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3443 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3444 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3445 ASSERT_VK_SUCCESS(err);
3446
3447 fb_info.pAttachments = &view;
3448 fb_info.height = 100;
3449 fb_info.width = 100;
3450 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3452 "framebuffer attachments must have "
3453 "been created with the identity "
3454 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003455 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3456
3457 m_errorMonitor->VerifyFound();
3458 if (err == VK_SUCCESS) {
3459 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3460 }
3461 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003462 // Request fb that exceeds max dimensions
3463 // reset attachment to color attachment
3464 fb_info.pAttachments = ivs;
3465 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3466 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3467 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3469 "dimensions exceed physical device "
3470 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003471 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3472
3473 m_errorMonitor->VerifyFound();
3474 if (err == VK_SUCCESS) {
3475 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3476 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003477
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003478 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003479}
3480
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003481TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003482 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3483 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003484
Cody Northropc31a84f2016-08-22 10:41:47 -06003485 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003486 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3488 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003489 m_errorMonitor->VerifyFound();
3490}
3491
3492TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003493 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3494 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003495
Cody Northropc31a84f2016-08-22 10:41:47 -06003496 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003497 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3499 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003500 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003501}
3502
3503TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003504 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3505 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003506
Cody Northropc31a84f2016-08-22 10:41:47 -06003507 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003508 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003510 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003511 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003512}
3513
3514TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003515 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3516 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003517
Cody Northropc31a84f2016-08-22 10:41:47 -06003518 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003519 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003521 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003522 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003523}
3524
Cortd713fe82016-07-27 09:51:27 -07003525TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003526 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3527 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003528
3529 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003530 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3532 "Dynamic blend constants state not set for this command buffer");
3533 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003534 m_errorMonitor->VerifyFound();
3535}
3536
3537TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003538 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3539 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003540
3541 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003542 if (!m_device->phy().features().depthBounds) {
3543 printf("Device does not support depthBounds test; skipped.\n");
3544 return;
3545 }
3546 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3548 "Dynamic depth bounds state not set for this command buffer");
3549 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003550 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003551}
3552
3553TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003554 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3555 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003556
3557 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003558 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3560 "Dynamic stencil read mask state not set for this command buffer");
3561 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003562 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003563}
3564
3565TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003566 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3567 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003568
3569 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003570 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3572 "Dynamic stencil write mask state not set for this command buffer");
3573 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003574 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003575}
3576
3577TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003578 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3579 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003580
3581 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003582 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3584 "Dynamic stencil reference state not set for this command buffer");
3585 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003586 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003587}
3588
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003589TEST_F(VkLayerTest, IndexBufferNotBound) {
3590 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003591
3592 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3594 "Index buffer object not bound to this command buffer when Indexed ");
3595 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003596 m_errorMonitor->VerifyFound();
3597}
3598
Karl Schultz6addd812016-02-02 17:17:23 -07003599TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3601 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3602 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003603
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003604 ASSERT_NO_FATAL_FAILURE(InitState());
3605 ASSERT_NO_FATAL_FAILURE(InitViewport());
3606 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3607
Karl Schultz6addd812016-02-02 17:17:23 -07003608 // We luck out b/c by default the framework creates CB w/ the
3609 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003610 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003611 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003612 EndCommandBuffer();
3613
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003614 // Bypass framework since it does the waits automatically
3615 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003616 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003617 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3618 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003619 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003620 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003621 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003622 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003623 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003624 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003625 submit_info.pSignalSemaphores = NULL;
3626
Chris Forbes40028e22016-06-13 09:59:34 +12003627 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003628 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003629 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003630
Karl Schultz6addd812016-02-02 17:17:23 -07003631 // Cause validation error by re-submitting cmd buffer that should only be
3632 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003633 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003634 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003635
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003636 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003637}
3638
Karl Schultz6addd812016-02-02 17:17:23 -07003639TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003640 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003641 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003642
3643 ASSERT_NO_FATAL_FAILURE(InitState());
3644 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003645
Karl Schultz6addd812016-02-02 17:17:23 -07003646 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3647 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003648 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003649 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003650 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003651
3652 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003653 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3654 ds_pool_ci.pNext = NULL;
3655 ds_pool_ci.flags = 0;
3656 ds_pool_ci.maxSets = 1;
3657 ds_pool_ci.poolSizeCount = 1;
3658 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003659
3660 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003661 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003662 ASSERT_VK_SUCCESS(err);
3663
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003664 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3665 dsl_binding_samp.binding = 0;
3666 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3667 dsl_binding_samp.descriptorCount = 1;
3668 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3669 dsl_binding_samp.pImmutableSamplers = NULL;
3670
3671 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3672 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3673 ds_layout_ci.pNext = NULL;
3674 ds_layout_ci.bindingCount = 1;
3675 ds_layout_ci.pBindings = &dsl_binding_samp;
3676
3677 VkDescriptorSetLayout ds_layout_samp;
3678 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3679 ASSERT_VK_SUCCESS(err);
3680
3681 // Try to allocate 2 sets when pool only has 1 set
3682 VkDescriptorSet descriptor_sets[2];
3683 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3684 VkDescriptorSetAllocateInfo alloc_info = {};
3685 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3686 alloc_info.descriptorSetCount = 2;
3687 alloc_info.descriptorPool = ds_pool;
3688 alloc_info.pSetLayouts = set_layouts;
3689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3690 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3691 m_errorMonitor->VerifyFound();
3692
3693 alloc_info.descriptorSetCount = 1;
3694 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003695 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003696 dsl_binding.binding = 0;
3697 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3698 dsl_binding.descriptorCount = 1;
3699 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3700 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003701
Karl Schultz6addd812016-02-02 17:17:23 -07003702 ds_layout_ci.bindingCount = 1;
3703 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003704
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003705 VkDescriptorSetLayout ds_layout_ub;
3706 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003707 ASSERT_VK_SUCCESS(err);
3708
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003709 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003710 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003711 alloc_info.pSetLayouts = &ds_layout_ub;
3712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3713 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003714
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003715 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003716
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003717 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003718 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003719}
3720
Karl Schultz6addd812016-02-02 17:17:23 -07003721TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3722 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3725 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3726 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003727
Tobin Ehlise735c692015-10-08 13:13:50 -06003728 ASSERT_NO_FATAL_FAILURE(InitState());
3729 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003730
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003731 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003732 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3733 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003734
3735 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003736 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3737 ds_pool_ci.pNext = NULL;
3738 ds_pool_ci.maxSets = 1;
3739 ds_pool_ci.poolSizeCount = 1;
3740 ds_pool_ci.flags = 0;
3741 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3742 // app can only call vkResetDescriptorPool on this pool.;
3743 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003744
3745 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003746 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003747 ASSERT_VK_SUCCESS(err);
3748
3749 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003750 dsl_binding.binding = 0;
3751 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3752 dsl_binding.descriptorCount = 1;
3753 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3754 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003755
3756 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003757 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3758 ds_layout_ci.pNext = NULL;
3759 ds_layout_ci.bindingCount = 1;
3760 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003761
3762 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003763 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003764 ASSERT_VK_SUCCESS(err);
3765
3766 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003767 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003768 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003769 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003770 alloc_info.descriptorPool = ds_pool;
3771 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003772 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003773 ASSERT_VK_SUCCESS(err);
3774
3775 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003776 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003777
Chia-I Wuf7458c52015-10-26 21:10:41 +08003778 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3779 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003780}
3781
Karl Schultz6addd812016-02-02 17:17:23 -07003782TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003783 // Attempt to clear Descriptor Pool with bad object.
3784 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003785
3786 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003788 uint64_t fake_pool_handle = 0xbaad6001;
3789 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3790 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003791 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003792}
3793
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003794TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003795 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3796 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003797 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003798 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003799
3800 uint64_t fake_set_handle = 0xbaad6001;
3801 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003802 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003804
3805 ASSERT_NO_FATAL_FAILURE(InitState());
3806
3807 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3808 layout_bindings[0].binding = 0;
3809 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3810 layout_bindings[0].descriptorCount = 1;
3811 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3812 layout_bindings[0].pImmutableSamplers = NULL;
3813
3814 VkDescriptorSetLayout descriptor_set_layout;
3815 VkDescriptorSetLayoutCreateInfo dslci = {};
3816 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3817 dslci.pNext = NULL;
3818 dslci.bindingCount = 1;
3819 dslci.pBindings = layout_bindings;
3820 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003821 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003822
3823 VkPipelineLayout pipeline_layout;
3824 VkPipelineLayoutCreateInfo plci = {};
3825 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3826 plci.pNext = NULL;
3827 plci.setLayoutCount = 1;
3828 plci.pSetLayouts = &descriptor_set_layout;
3829 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003830 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003831
3832 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003833 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3834 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003835 m_errorMonitor->VerifyFound();
3836 EndCommandBuffer();
3837 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3838 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003839}
3840
Karl Schultz6addd812016-02-02 17:17:23 -07003841TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003842 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3843 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003844 uint64_t fake_layout_handle = 0xbaad6001;
3845 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003847 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003848 VkPipelineLayout pipeline_layout;
3849 VkPipelineLayoutCreateInfo plci = {};
3850 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3851 plci.pNext = NULL;
3852 plci.setLayoutCount = 1;
3853 plci.pSetLayouts = &bad_layout;
3854 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3855
3856 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003857}
3858
Mark Muellerd4914412016-06-13 17:52:06 -06003859TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3860 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3861 "1) A uniform buffer update must have a valid buffer index."
3862 "2) When using an array of descriptors in a single WriteDescriptor,"
3863 " the descriptor types and stageflags must all be the same."
3864 "3) Immutable Sampler state must match across descriptors");
3865
3866 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003867 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3868 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3869 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3870 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3871 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003872
Mark Muellerd4914412016-06-13 17:52:06 -06003873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3874
3875 ASSERT_NO_FATAL_FAILURE(InitState());
3876 VkDescriptorPoolSize ds_type_count[4] = {};
3877 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3878 ds_type_count[0].descriptorCount = 1;
3879 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3880 ds_type_count[1].descriptorCount = 1;
3881 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3882 ds_type_count[2].descriptorCount = 1;
3883 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3884 ds_type_count[3].descriptorCount = 1;
3885
3886 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3887 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3888 ds_pool_ci.maxSets = 1;
3889 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3890 ds_pool_ci.pPoolSizes = ds_type_count;
3891
3892 VkDescriptorPool ds_pool;
3893 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3894 ASSERT_VK_SUCCESS(err);
3895
Mark Muellerb9896722016-06-16 09:54:29 -06003896 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003897 layout_binding[0].binding = 0;
3898 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3899 layout_binding[0].descriptorCount = 1;
3900 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3901 layout_binding[0].pImmutableSamplers = NULL;
3902
3903 layout_binding[1].binding = 1;
3904 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3905 layout_binding[1].descriptorCount = 1;
3906 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3907 layout_binding[1].pImmutableSamplers = NULL;
3908
3909 VkSamplerCreateInfo sampler_ci = {};
3910 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3911 sampler_ci.pNext = NULL;
3912 sampler_ci.magFilter = VK_FILTER_NEAREST;
3913 sampler_ci.minFilter = VK_FILTER_NEAREST;
3914 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3915 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3916 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3917 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3918 sampler_ci.mipLodBias = 1.0;
3919 sampler_ci.anisotropyEnable = VK_FALSE;
3920 sampler_ci.maxAnisotropy = 1;
3921 sampler_ci.compareEnable = VK_FALSE;
3922 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3923 sampler_ci.minLod = 1.0;
3924 sampler_ci.maxLod = 1.0;
3925 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3926 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3927 VkSampler sampler;
3928
3929 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3930 ASSERT_VK_SUCCESS(err);
3931
3932 layout_binding[2].binding = 2;
3933 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3934 layout_binding[2].descriptorCount = 1;
3935 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3936 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3937
Mark Muellerd4914412016-06-13 17:52:06 -06003938 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3939 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3940 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3941 ds_layout_ci.pBindings = layout_binding;
3942 VkDescriptorSetLayout ds_layout;
3943 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3944 ASSERT_VK_SUCCESS(err);
3945
3946 VkDescriptorSetAllocateInfo alloc_info = {};
3947 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3948 alloc_info.descriptorSetCount = 1;
3949 alloc_info.descriptorPool = ds_pool;
3950 alloc_info.pSetLayouts = &ds_layout;
3951 VkDescriptorSet descriptorSet;
3952 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3953 ASSERT_VK_SUCCESS(err);
3954
3955 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3956 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3957 pipeline_layout_ci.pNext = NULL;
3958 pipeline_layout_ci.setLayoutCount = 1;
3959 pipeline_layout_ci.pSetLayouts = &ds_layout;
3960
3961 VkPipelineLayout pipeline_layout;
3962 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3963 ASSERT_VK_SUCCESS(err);
3964
Mark Mueller5c838ce2016-06-16 09:54:29 -06003965 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003966 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3967 descriptor_write.dstSet = descriptorSet;
3968 descriptor_write.dstBinding = 0;
3969 descriptor_write.descriptorCount = 1;
3970 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3971
Mark Mueller5c838ce2016-06-16 09:54:29 -06003972 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003973 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3974 m_errorMonitor->VerifyFound();
3975
3976 // Create a buffer to update the descriptor with
3977 uint32_t qfi = 0;
3978 VkBufferCreateInfo buffCI = {};
3979 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3980 buffCI.size = 1024;
3981 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3982 buffCI.queueFamilyIndexCount = 1;
3983 buffCI.pQueueFamilyIndices = &qfi;
3984
3985 VkBuffer dyub;
3986 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3987 ASSERT_VK_SUCCESS(err);
3988 VkDescriptorBufferInfo buffInfo = {};
3989 buffInfo.buffer = dyub;
3990 buffInfo.offset = 0;
3991 buffInfo.range = 1024;
3992
3993 descriptor_write.pBufferInfo = &buffInfo;
3994 descriptor_write.descriptorCount = 2;
3995
Mark Mueller5c838ce2016-06-16 09:54:29 -06003996 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3998 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3999 m_errorMonitor->VerifyFound();
4000
Mark Mueller5c838ce2016-06-16 09:54:29 -06004001 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4002 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004003 descriptor_write.dstBinding = 1;
4004 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004005
Mark Mueller5c838ce2016-06-16 09:54:29 -06004006 // Make pImageInfo index non-null to avoid complaints of it missing
4007 VkDescriptorImageInfo imageInfo = {};
4008 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4009 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4011 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4012 m_errorMonitor->VerifyFound();
4013
Mark Muellerd4914412016-06-13 17:52:06 -06004014 vkDestroyBuffer(m_device->device(), dyub, NULL);
4015 vkDestroySampler(m_device->device(), sampler, NULL);
4016 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4017 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4018 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4019}
4020
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004021TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4022 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4023 "due to a buffer dependency being destroyed.");
4024 ASSERT_NO_FATAL_FAILURE(InitState());
4025
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004026 VkBuffer buffer;
4027 VkDeviceMemory mem;
4028 VkMemoryRequirements mem_reqs;
4029
4030 VkBufferCreateInfo buf_info = {};
4031 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004032 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004033 buf_info.size = 256;
4034 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4035 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4036 ASSERT_VK_SUCCESS(err);
4037
4038 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4039
4040 VkMemoryAllocateInfo alloc_info = {};
4041 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4042 alloc_info.allocationSize = 256;
4043 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004044 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 -06004045 if (!pass) {
4046 vkDestroyBuffer(m_device->device(), buffer, NULL);
4047 return;
4048 }
4049 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4050 ASSERT_VK_SUCCESS(err);
4051
4052 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4053 ASSERT_VK_SUCCESS(err);
4054
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004055 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004056 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004057 m_commandBuffer->EndCommandBuffer();
4058
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004060 // Destroy buffer dependency prior to submit to cause ERROR
4061 vkDestroyBuffer(m_device->device(), buffer, NULL);
4062
4063 VkSubmitInfo submit_info = {};
4064 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4065 submit_info.commandBufferCount = 1;
4066 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4067 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4068
4069 m_errorMonitor->VerifyFound();
4070 vkFreeMemory(m_device->handle(), mem, NULL);
4071}
4072
Tobin Ehlisea413442016-09-28 10:23:59 -06004073TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4074 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4075
4076 ASSERT_NO_FATAL_FAILURE(InitState());
4077 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4078
4079 VkDescriptorPoolSize ds_type_count;
4080 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4081 ds_type_count.descriptorCount = 1;
4082
4083 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4084 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4085 ds_pool_ci.maxSets = 1;
4086 ds_pool_ci.poolSizeCount = 1;
4087 ds_pool_ci.pPoolSizes = &ds_type_count;
4088
4089 VkDescriptorPool ds_pool;
4090 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4091 ASSERT_VK_SUCCESS(err);
4092
4093 VkDescriptorSetLayoutBinding layout_binding;
4094 layout_binding.binding = 0;
4095 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4096 layout_binding.descriptorCount = 1;
4097 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4098 layout_binding.pImmutableSamplers = NULL;
4099
4100 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4101 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4102 ds_layout_ci.bindingCount = 1;
4103 ds_layout_ci.pBindings = &layout_binding;
4104 VkDescriptorSetLayout ds_layout;
4105 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4106 ASSERT_VK_SUCCESS(err);
4107
4108 VkDescriptorSetAllocateInfo alloc_info = {};
4109 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4110 alloc_info.descriptorSetCount = 1;
4111 alloc_info.descriptorPool = ds_pool;
4112 alloc_info.pSetLayouts = &ds_layout;
4113 VkDescriptorSet descriptor_set;
4114 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4115 ASSERT_VK_SUCCESS(err);
4116
4117 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4118 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4119 pipeline_layout_ci.pNext = NULL;
4120 pipeline_layout_ci.setLayoutCount = 1;
4121 pipeline_layout_ci.pSetLayouts = &ds_layout;
4122
4123 VkPipelineLayout pipeline_layout;
4124 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4125 ASSERT_VK_SUCCESS(err);
4126
4127 VkBuffer buffer;
4128 uint32_t queue_family_index = 0;
4129 VkBufferCreateInfo buffer_create_info = {};
4130 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4131 buffer_create_info.size = 1024;
4132 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4133 buffer_create_info.queueFamilyIndexCount = 1;
4134 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4135
4136 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4137 ASSERT_VK_SUCCESS(err);
4138
4139 VkMemoryRequirements memory_reqs;
4140 VkDeviceMemory buffer_memory;
4141
4142 VkMemoryAllocateInfo memory_info = {};
4143 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4144 memory_info.allocationSize = 0;
4145 memory_info.memoryTypeIndex = 0;
4146
4147 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4148 memory_info.allocationSize = memory_reqs.size;
4149 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4150 ASSERT_TRUE(pass);
4151
4152 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4153 ASSERT_VK_SUCCESS(err);
4154 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4155 ASSERT_VK_SUCCESS(err);
4156
4157 VkBufferView view;
4158 VkBufferViewCreateInfo bvci = {};
4159 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4160 bvci.buffer = buffer;
4161 bvci.format = VK_FORMAT_R8_UNORM;
4162 bvci.range = VK_WHOLE_SIZE;
4163
4164 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4165 ASSERT_VK_SUCCESS(err);
4166
4167 VkWriteDescriptorSet descriptor_write = {};
4168 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4169 descriptor_write.dstSet = descriptor_set;
4170 descriptor_write.dstBinding = 0;
4171 descriptor_write.descriptorCount = 1;
4172 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4173 descriptor_write.pTexelBufferView = &view;
4174
4175 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4176
4177 char const *vsSource = "#version 450\n"
4178 "\n"
4179 "out gl_PerVertex { \n"
4180 " vec4 gl_Position;\n"
4181 "};\n"
4182 "void main(){\n"
4183 " gl_Position = vec4(1);\n"
4184 "}\n";
4185 char const *fsSource = "#version 450\n"
4186 "\n"
4187 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4188 "layout(location=0) out vec4 x;\n"
4189 "void main(){\n"
4190 " x = imageLoad(s, 0);\n"
4191 "}\n";
4192 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4193 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4194 VkPipelineObj pipe(m_device);
4195 pipe.AddShader(&vs);
4196 pipe.AddShader(&fs);
4197 pipe.AddColorAttachment();
4198 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4199
4200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4202
4203 BeginCommandBuffer();
4204 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4205 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4206 VkRect2D scissor = {{0, 0}, {16, 16}};
4207 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4208 // Bind pipeline to cmd buffer
4209 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4210 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4211 &descriptor_set, 0, nullptr);
4212 Draw(1, 0, 0, 0);
4213 EndCommandBuffer();
4214
4215 // Delete BufferView in order to invalidate cmd buffer
4216 vkDestroyBufferView(m_device->device(), view, NULL);
4217 // Now attempt submit of cmd buffer
4218 VkSubmitInfo submit_info = {};
4219 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4220 submit_info.commandBufferCount = 1;
4221 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4222 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4223 m_errorMonitor->VerifyFound();
4224
4225 // Clean-up
4226 vkDestroyBuffer(m_device->device(), buffer, NULL);
4227 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4228 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4229 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4230 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4231}
4232
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004233TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4234 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4235 "due to an image dependency being destroyed.");
4236 ASSERT_NO_FATAL_FAILURE(InitState());
4237
4238 VkImage image;
4239 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4240 VkImageCreateInfo image_create_info = {};
4241 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4242 image_create_info.pNext = NULL;
4243 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4244 image_create_info.format = tex_format;
4245 image_create_info.extent.width = 32;
4246 image_create_info.extent.height = 32;
4247 image_create_info.extent.depth = 1;
4248 image_create_info.mipLevels = 1;
4249 image_create_info.arrayLayers = 1;
4250 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4251 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004252 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004253 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004254 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004255 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004256 // Have to bind memory to image before recording cmd in cmd buffer using it
4257 VkMemoryRequirements mem_reqs;
4258 VkDeviceMemory image_mem;
4259 bool pass;
4260 VkMemoryAllocateInfo mem_alloc = {};
4261 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4262 mem_alloc.pNext = NULL;
4263 mem_alloc.memoryTypeIndex = 0;
4264 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4265 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004266 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004267 ASSERT_TRUE(pass);
4268 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4269 ASSERT_VK_SUCCESS(err);
4270 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4271 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004272
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004273 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004274 VkClearColorValue ccv;
4275 ccv.float32[0] = 1.0f;
4276 ccv.float32[1] = 1.0f;
4277 ccv.float32[2] = 1.0f;
4278 ccv.float32[3] = 1.0f;
4279 VkImageSubresourceRange isr = {};
4280 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004281 isr.baseArrayLayer = 0;
4282 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004283 isr.layerCount = 1;
4284 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004285 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004286 m_commandBuffer->EndCommandBuffer();
4287
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004289 // Destroy image dependency prior to submit to cause ERROR
4290 vkDestroyImage(m_device->device(), image, NULL);
4291
4292 VkSubmitInfo submit_info = {};
4293 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4294 submit_info.commandBufferCount = 1;
4295 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4296 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4297
4298 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004299 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004300}
4301
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004302TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4303 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4304 "due to a framebuffer image dependency being destroyed.");
4305 VkFormatProperties format_properties;
4306 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004307 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4308 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004309 return;
4310 }
4311
4312 ASSERT_NO_FATAL_FAILURE(InitState());
4313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4314
4315 VkImageCreateInfo image_ci = {};
4316 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4317 image_ci.pNext = NULL;
4318 image_ci.imageType = VK_IMAGE_TYPE_2D;
4319 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4320 image_ci.extent.width = 32;
4321 image_ci.extent.height = 32;
4322 image_ci.extent.depth = 1;
4323 image_ci.mipLevels = 1;
4324 image_ci.arrayLayers = 1;
4325 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4326 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004327 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004328 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4329 image_ci.flags = 0;
4330 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004331 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004332
4333 VkMemoryRequirements memory_reqs;
4334 VkDeviceMemory image_memory;
4335 bool pass;
4336 VkMemoryAllocateInfo memory_info = {};
4337 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4338 memory_info.pNext = NULL;
4339 memory_info.allocationSize = 0;
4340 memory_info.memoryTypeIndex = 0;
4341 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4342 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004343 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004344 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004345 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004346 ASSERT_VK_SUCCESS(err);
4347 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4348 ASSERT_VK_SUCCESS(err);
4349
4350 VkImageViewCreateInfo ivci = {
4351 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4352 nullptr,
4353 0,
4354 image,
4355 VK_IMAGE_VIEW_TYPE_2D,
4356 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004357 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004358 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4359 };
4360 VkImageView view;
4361 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4362 ASSERT_VK_SUCCESS(err);
4363
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004364 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004365 VkFramebuffer fb;
4366 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4367 ASSERT_VK_SUCCESS(err);
4368
4369 // Just use default renderpass with our framebuffer
4370 m_renderPassBeginInfo.framebuffer = fb;
4371 // Create Null cmd buffer for submit
4372 BeginCommandBuffer();
4373 EndCommandBuffer();
4374 // Destroy image attached to framebuffer to invalidate cmd buffer
4375 vkDestroyImage(m_device->device(), image, NULL);
4376 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004378 QueueCommandBuffer(false);
4379 m_errorMonitor->VerifyFound();
4380
4381 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4382 vkDestroyImageView(m_device->device(), view, nullptr);
4383 vkFreeMemory(m_device->device(), image_memory, nullptr);
4384}
4385
Tobin Ehlisb329f992016-10-12 13:20:29 -06004386TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4387 TEST_DESCRIPTION("Delete in-use framebuffer.");
4388 VkFormatProperties format_properties;
4389 VkResult err = VK_SUCCESS;
4390 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4391
4392 ASSERT_NO_FATAL_FAILURE(InitState());
4393 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4394
4395 VkImageObj image(m_device);
4396 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4397 ASSERT_TRUE(image.initialized());
4398 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4399
4400 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4401 VkFramebuffer fb;
4402 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4403 ASSERT_VK_SUCCESS(err);
4404
4405 // Just use default renderpass with our framebuffer
4406 m_renderPassBeginInfo.framebuffer = fb;
4407 // Create Null cmd buffer for submit
4408 BeginCommandBuffer();
4409 EndCommandBuffer();
4410 // Submit cmd buffer to put it in-flight
4411 VkSubmitInfo submit_info = {};
4412 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4413 submit_info.commandBufferCount = 1;
4414 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4415 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4416 // Destroy framebuffer while in-flight
4417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4418 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4419 m_errorMonitor->VerifyFound();
4420 // Wait for queue to complete so we can safely destroy everything
4421 vkQueueWaitIdle(m_device->m_queue);
4422 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4423}
4424
Tobin Ehlis88becd72016-09-21 14:33:41 -06004425TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4426 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4427 VkFormatProperties format_properties;
4428 VkResult err = VK_SUCCESS;
4429 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004430
4431 ASSERT_NO_FATAL_FAILURE(InitState());
4432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4433
4434 VkImageCreateInfo image_ci = {};
4435 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4436 image_ci.pNext = NULL;
4437 image_ci.imageType = VK_IMAGE_TYPE_2D;
4438 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4439 image_ci.extent.width = 256;
4440 image_ci.extent.height = 256;
4441 image_ci.extent.depth = 1;
4442 image_ci.mipLevels = 1;
4443 image_ci.arrayLayers = 1;
4444 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4445 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004446 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004447 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4448 image_ci.flags = 0;
4449 VkImage image;
4450 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4451
4452 VkMemoryRequirements memory_reqs;
4453 VkDeviceMemory image_memory;
4454 bool pass;
4455 VkMemoryAllocateInfo memory_info = {};
4456 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4457 memory_info.pNext = NULL;
4458 memory_info.allocationSize = 0;
4459 memory_info.memoryTypeIndex = 0;
4460 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4461 memory_info.allocationSize = memory_reqs.size;
4462 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4463 ASSERT_TRUE(pass);
4464 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4465 ASSERT_VK_SUCCESS(err);
4466 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4467 ASSERT_VK_SUCCESS(err);
4468
4469 VkImageViewCreateInfo ivci = {
4470 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4471 nullptr,
4472 0,
4473 image,
4474 VK_IMAGE_VIEW_TYPE_2D,
4475 VK_FORMAT_B8G8R8A8_UNORM,
4476 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4477 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4478 };
4479 VkImageView view;
4480 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4481 ASSERT_VK_SUCCESS(err);
4482
4483 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4484 VkFramebuffer fb;
4485 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4486 ASSERT_VK_SUCCESS(err);
4487
4488 // Just use default renderpass with our framebuffer
4489 m_renderPassBeginInfo.framebuffer = fb;
4490 // Create Null cmd buffer for submit
4491 BeginCommandBuffer();
4492 EndCommandBuffer();
4493 // Submit cmd buffer to put it (and attached imageView) in-flight
4494 VkSubmitInfo submit_info = {};
4495 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4496 submit_info.commandBufferCount = 1;
4497 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4498 // Submit cmd buffer to put framebuffer and children in-flight
4499 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4500 // Destroy image attached to framebuffer while in-flight
4501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4502 vkDestroyImage(m_device->device(), image, NULL);
4503 m_errorMonitor->VerifyFound();
4504 // Wait for queue to complete so we can safely destroy image and other objects
4505 vkQueueWaitIdle(m_device->m_queue);
4506 vkDestroyImage(m_device->device(), image, NULL);
4507 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4508 vkDestroyImageView(m_device->device(), view, nullptr);
4509 vkFreeMemory(m_device->device(), image_memory, nullptr);
4510}
4511
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004512TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4513 TEST_DESCRIPTION("Delete in-use renderPass.");
4514
4515 ASSERT_NO_FATAL_FAILURE(InitState());
4516 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4517
4518 // Create simple renderpass
4519 VkAttachmentReference attach = {};
4520 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4521 VkSubpassDescription subpass = {};
4522 subpass.pColorAttachments = &attach;
4523 VkRenderPassCreateInfo rpci = {};
4524 rpci.subpassCount = 1;
4525 rpci.pSubpasses = &subpass;
4526 rpci.attachmentCount = 1;
4527 VkAttachmentDescription attach_desc = {};
4528 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4529 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4530 rpci.pAttachments = &attach_desc;
4531 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4532 VkRenderPass rp;
4533 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4534 ASSERT_VK_SUCCESS(err);
4535
4536 // Create a pipeline that uses the given renderpass
4537 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4538 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4539
4540 VkPipelineLayout pipeline_layout;
4541 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4542 ASSERT_VK_SUCCESS(err);
4543
4544 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4545 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4546 vp_state_ci.viewportCount = 1;
4547 VkViewport vp = {}; // Just need dummy vp to point to
4548 vp_state_ci.pViewports = &vp;
4549 vp_state_ci.scissorCount = 1;
4550 VkRect2D scissors = {}; // Dummy scissors to point to
4551 vp_state_ci.pScissors = &scissors;
4552
4553 VkPipelineShaderStageCreateInfo shaderStages[2];
4554 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4555
4556 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4557 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4558 // but add it to be able to run on more devices
4559 shaderStages[0] = vs.GetStageCreateInfo();
4560 shaderStages[1] = fs.GetStageCreateInfo();
4561
4562 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4563 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4564
4565 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4566 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4567 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4568
4569 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4570 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4571 rs_ci.rasterizerDiscardEnable = true;
4572 rs_ci.lineWidth = 1.0f;
4573
4574 VkPipelineColorBlendAttachmentState att = {};
4575 att.blendEnable = VK_FALSE;
4576 att.colorWriteMask = 0xf;
4577
4578 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4579 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4580 cb_ci.attachmentCount = 1;
4581 cb_ci.pAttachments = &att;
4582
4583 VkGraphicsPipelineCreateInfo gp_ci = {};
4584 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4585 gp_ci.stageCount = 2;
4586 gp_ci.pStages = shaderStages;
4587 gp_ci.pVertexInputState = &vi_ci;
4588 gp_ci.pInputAssemblyState = &ia_ci;
4589 gp_ci.pViewportState = &vp_state_ci;
4590 gp_ci.pRasterizationState = &rs_ci;
4591 gp_ci.pColorBlendState = &cb_ci;
4592 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4593 gp_ci.layout = pipeline_layout;
4594 gp_ci.renderPass = rp;
4595
4596 VkPipelineCacheCreateInfo pc_ci = {};
4597 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4598
4599 VkPipeline pipeline;
4600 VkPipelineCache pipe_cache;
4601 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4602 ASSERT_VK_SUCCESS(err);
4603
4604 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4605 ASSERT_VK_SUCCESS(err);
4606 // Bind pipeline to cmd buffer, will also bind renderpass
4607 m_commandBuffer->BeginCommandBuffer();
4608 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4609 m_commandBuffer->EndCommandBuffer();
4610
4611 VkSubmitInfo submit_info = {};
4612 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4613 submit_info.commandBufferCount = 1;
4614 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4615 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4616
4617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4618 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4619 m_errorMonitor->VerifyFound();
4620
4621 // Wait for queue to complete so we can safely destroy everything
4622 vkQueueWaitIdle(m_device->m_queue);
4623 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4624 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4625 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4626 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4627}
4628
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004629TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004630 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004631 ASSERT_NO_FATAL_FAILURE(InitState());
4632
4633 VkImage image;
4634 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4635 VkImageCreateInfo image_create_info = {};
4636 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4637 image_create_info.pNext = NULL;
4638 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4639 image_create_info.format = tex_format;
4640 image_create_info.extent.width = 32;
4641 image_create_info.extent.height = 32;
4642 image_create_info.extent.depth = 1;
4643 image_create_info.mipLevels = 1;
4644 image_create_info.arrayLayers = 1;
4645 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4646 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004647 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004648 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004649 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004650 ASSERT_VK_SUCCESS(err);
4651 // Have to bind memory to image before recording cmd in cmd buffer using it
4652 VkMemoryRequirements mem_reqs;
4653 VkDeviceMemory image_mem;
4654 bool pass;
4655 VkMemoryAllocateInfo mem_alloc = {};
4656 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4657 mem_alloc.pNext = NULL;
4658 mem_alloc.memoryTypeIndex = 0;
4659 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4660 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004661 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004662 ASSERT_TRUE(pass);
4663 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4664 ASSERT_VK_SUCCESS(err);
4665
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004666 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004668 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004669
4670 m_commandBuffer->BeginCommandBuffer();
4671 VkClearColorValue ccv;
4672 ccv.float32[0] = 1.0f;
4673 ccv.float32[1] = 1.0f;
4674 ccv.float32[2] = 1.0f;
4675 ccv.float32[3] = 1.0f;
4676 VkImageSubresourceRange isr = {};
4677 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4678 isr.baseArrayLayer = 0;
4679 isr.baseMipLevel = 0;
4680 isr.layerCount = 1;
4681 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004682 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004683 m_commandBuffer->EndCommandBuffer();
4684
4685 m_errorMonitor->VerifyFound();
4686 vkDestroyImage(m_device->device(), image, NULL);
4687 vkFreeMemory(m_device->device(), image_mem, nullptr);
4688}
4689
4690TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004691 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004692 ASSERT_NO_FATAL_FAILURE(InitState());
4693
4694 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004695 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 -06004696 VK_IMAGE_TILING_OPTIMAL, 0);
4697 ASSERT_TRUE(image.initialized());
4698
4699 VkBuffer buffer;
4700 VkDeviceMemory mem;
4701 VkMemoryRequirements mem_reqs;
4702
4703 VkBufferCreateInfo buf_info = {};
4704 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004705 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004706 buf_info.size = 256;
4707 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4708 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4709 ASSERT_VK_SUCCESS(err);
4710
4711 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4712
4713 VkMemoryAllocateInfo alloc_info = {};
4714 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4715 alloc_info.allocationSize = 256;
4716 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004717 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 -06004718 if (!pass) {
4719 vkDestroyBuffer(m_device->device(), buffer, NULL);
4720 return;
4721 }
4722 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4723 ASSERT_VK_SUCCESS(err);
4724
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004725 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004727 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004728 VkBufferImageCopy region = {};
4729 region.bufferRowLength = 128;
4730 region.bufferImageHeight = 128;
4731 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4732
4733 region.imageSubresource.layerCount = 1;
4734 region.imageExtent.height = 4;
4735 region.imageExtent.width = 4;
4736 region.imageExtent.depth = 1;
4737 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004738 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4739 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004740 m_commandBuffer->EndCommandBuffer();
4741
4742 m_errorMonitor->VerifyFound();
4743
4744 vkDestroyBuffer(m_device->device(), buffer, NULL);
4745 vkFreeMemory(m_device->handle(), mem, NULL);
4746}
4747
Tobin Ehlis85940f52016-07-07 16:57:21 -06004748TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4749 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4750 "due to an event dependency being destroyed.");
4751 ASSERT_NO_FATAL_FAILURE(InitState());
4752
4753 VkEvent event;
4754 VkEventCreateInfo evci = {};
4755 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4756 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4757 ASSERT_VK_SUCCESS(result);
4758
4759 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004760 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004761 m_commandBuffer->EndCommandBuffer();
4762
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004764 // Destroy event dependency prior to submit to cause ERROR
4765 vkDestroyEvent(m_device->device(), event, NULL);
4766
4767 VkSubmitInfo submit_info = {};
4768 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4769 submit_info.commandBufferCount = 1;
4770 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4771 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4772
4773 m_errorMonitor->VerifyFound();
4774}
4775
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004776TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4777 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4778 "due to a query pool dependency being destroyed.");
4779 ASSERT_NO_FATAL_FAILURE(InitState());
4780
4781 VkQueryPool query_pool;
4782 VkQueryPoolCreateInfo qpci{};
4783 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4784 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4785 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004786 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004787 ASSERT_VK_SUCCESS(result);
4788
4789 m_commandBuffer->BeginCommandBuffer();
4790 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4791 m_commandBuffer->EndCommandBuffer();
4792
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004794 // Destroy query pool dependency prior to submit to cause ERROR
4795 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4796
4797 VkSubmitInfo submit_info = {};
4798 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4799 submit_info.commandBufferCount = 1;
4800 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4801 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4802
4803 m_errorMonitor->VerifyFound();
4804}
4805
Tobin Ehlis24130d92016-07-08 15:50:53 -06004806TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4807 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4808 "due to a pipeline dependency being destroyed.");
4809 ASSERT_NO_FATAL_FAILURE(InitState());
4810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4811
4812 VkResult err;
4813
4814 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4815 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4816
4817 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004818 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004819 ASSERT_VK_SUCCESS(err);
4820
4821 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4822 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4823 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004824 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004825 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004826 vp_state_ci.scissorCount = 1;
4827 VkRect2D scissors = {}; // Dummy scissors to point to
4828 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004829
4830 VkPipelineShaderStageCreateInfo shaderStages[2];
4831 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4832
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004833 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4834 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4835 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004836 shaderStages[0] = vs.GetStageCreateInfo();
4837 shaderStages[1] = fs.GetStageCreateInfo();
4838
4839 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4840 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4841
4842 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4843 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4844 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4845
4846 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4847 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004848 rs_ci.rasterizerDiscardEnable = true;
4849 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004850
4851 VkPipelineColorBlendAttachmentState att = {};
4852 att.blendEnable = VK_FALSE;
4853 att.colorWriteMask = 0xf;
4854
4855 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4856 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4857 cb_ci.attachmentCount = 1;
4858 cb_ci.pAttachments = &att;
4859
4860 VkGraphicsPipelineCreateInfo gp_ci = {};
4861 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4862 gp_ci.stageCount = 2;
4863 gp_ci.pStages = shaderStages;
4864 gp_ci.pVertexInputState = &vi_ci;
4865 gp_ci.pInputAssemblyState = &ia_ci;
4866 gp_ci.pViewportState = &vp_state_ci;
4867 gp_ci.pRasterizationState = &rs_ci;
4868 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004869 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4870 gp_ci.layout = pipeline_layout;
4871 gp_ci.renderPass = renderPass();
4872
4873 VkPipelineCacheCreateInfo pc_ci = {};
4874 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4875
4876 VkPipeline pipeline;
4877 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004878 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004879 ASSERT_VK_SUCCESS(err);
4880
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004881 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004882 ASSERT_VK_SUCCESS(err);
4883
4884 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004885 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004886 m_commandBuffer->EndCommandBuffer();
4887 // Now destroy pipeline in order to cause error when submitting
4888 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4889
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004891
4892 VkSubmitInfo submit_info = {};
4893 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4894 submit_info.commandBufferCount = 1;
4895 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4896 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4897
4898 m_errorMonitor->VerifyFound();
4899 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4900 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4901}
4902
Tobin Ehlis31289162016-08-17 14:57:58 -06004903TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4904 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4905 "due to a bound descriptor set with a buffer dependency "
4906 "being destroyed.");
4907 ASSERT_NO_FATAL_FAILURE(InitState());
4908 ASSERT_NO_FATAL_FAILURE(InitViewport());
4909 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4910
4911 VkDescriptorPoolSize ds_type_count = {};
4912 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4913 ds_type_count.descriptorCount = 1;
4914
4915 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4916 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4917 ds_pool_ci.pNext = NULL;
4918 ds_pool_ci.maxSets = 1;
4919 ds_pool_ci.poolSizeCount = 1;
4920 ds_pool_ci.pPoolSizes = &ds_type_count;
4921
4922 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004923 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004924 ASSERT_VK_SUCCESS(err);
4925
4926 VkDescriptorSetLayoutBinding dsl_binding = {};
4927 dsl_binding.binding = 0;
4928 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4929 dsl_binding.descriptorCount = 1;
4930 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4931 dsl_binding.pImmutableSamplers = NULL;
4932
4933 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4934 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4935 ds_layout_ci.pNext = NULL;
4936 ds_layout_ci.bindingCount = 1;
4937 ds_layout_ci.pBindings = &dsl_binding;
4938 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004939 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004940 ASSERT_VK_SUCCESS(err);
4941
4942 VkDescriptorSet descriptorSet;
4943 VkDescriptorSetAllocateInfo alloc_info = {};
4944 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4945 alloc_info.descriptorSetCount = 1;
4946 alloc_info.descriptorPool = ds_pool;
4947 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004948 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004949 ASSERT_VK_SUCCESS(err);
4950
4951 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4952 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4953 pipeline_layout_ci.pNext = NULL;
4954 pipeline_layout_ci.setLayoutCount = 1;
4955 pipeline_layout_ci.pSetLayouts = &ds_layout;
4956
4957 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004958 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004959 ASSERT_VK_SUCCESS(err);
4960
4961 // Create a buffer to update the descriptor with
4962 uint32_t qfi = 0;
4963 VkBufferCreateInfo buffCI = {};
4964 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4965 buffCI.size = 1024;
4966 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4967 buffCI.queueFamilyIndexCount = 1;
4968 buffCI.pQueueFamilyIndices = &qfi;
4969
4970 VkBuffer buffer;
4971 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4972 ASSERT_VK_SUCCESS(err);
4973 // Allocate memory and bind to buffer so we can make it to the appropriate
4974 // error
4975 VkMemoryAllocateInfo mem_alloc = {};
4976 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4977 mem_alloc.pNext = NULL;
4978 mem_alloc.allocationSize = 1024;
4979 mem_alloc.memoryTypeIndex = 0;
4980
4981 VkMemoryRequirements memReqs;
4982 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004983 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004984 if (!pass) {
4985 vkDestroyBuffer(m_device->device(), buffer, NULL);
4986 return;
4987 }
4988
4989 VkDeviceMemory mem;
4990 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4991 ASSERT_VK_SUCCESS(err);
4992 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4993 ASSERT_VK_SUCCESS(err);
4994 // Correctly update descriptor to avoid "NOT_UPDATED" error
4995 VkDescriptorBufferInfo buffInfo = {};
4996 buffInfo.buffer = buffer;
4997 buffInfo.offset = 0;
4998 buffInfo.range = 1024;
4999
5000 VkWriteDescriptorSet descriptor_write;
5001 memset(&descriptor_write, 0, sizeof(descriptor_write));
5002 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5003 descriptor_write.dstSet = descriptorSet;
5004 descriptor_write.dstBinding = 0;
5005 descriptor_write.descriptorCount = 1;
5006 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5007 descriptor_write.pBufferInfo = &buffInfo;
5008
5009 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5010
5011 // Create PSO to be used for draw-time errors below
5012 char const *vsSource = "#version 450\n"
5013 "\n"
5014 "out gl_PerVertex { \n"
5015 " vec4 gl_Position;\n"
5016 "};\n"
5017 "void main(){\n"
5018 " gl_Position = vec4(1);\n"
5019 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005020 char const *fsSource = "#version 450\n"
5021 "\n"
5022 "layout(location=0) out vec4 x;\n"
5023 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5024 "void main(){\n"
5025 " x = vec4(bar.y);\n"
5026 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005027 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5028 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5029 VkPipelineObj pipe(m_device);
5030 pipe.AddShader(&vs);
5031 pipe.AddShader(&fs);
5032 pipe.AddColorAttachment();
5033 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5034
5035 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005036 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5037 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5038 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005039 Draw(1, 0, 0, 0);
5040 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005042 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5043 vkDestroyBuffer(m_device->device(), buffer, NULL);
5044 // Attempt to submit cmd buffer
5045 VkSubmitInfo submit_info = {};
5046 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5047 submit_info.commandBufferCount = 1;
5048 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5049 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5050 m_errorMonitor->VerifyFound();
5051 // Cleanup
5052 vkFreeMemory(m_device->device(), mem, NULL);
5053
5054 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5055 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5056 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5057}
5058
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005059TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5060 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5061 "due to a bound descriptor sets with a combined image "
5062 "sampler having their image, sampler, and descriptor set "
5063 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005064 "submit associated cmd buffers. Attempt to destroy a "
5065 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005066 ASSERT_NO_FATAL_FAILURE(InitState());
5067 ASSERT_NO_FATAL_FAILURE(InitViewport());
5068 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5069
5070 VkDescriptorPoolSize ds_type_count = {};
5071 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5072 ds_type_count.descriptorCount = 1;
5073
5074 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5075 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5076 ds_pool_ci.pNext = NULL;
5077 ds_pool_ci.maxSets = 1;
5078 ds_pool_ci.poolSizeCount = 1;
5079 ds_pool_ci.pPoolSizes = &ds_type_count;
5080
5081 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005082 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005083 ASSERT_VK_SUCCESS(err);
5084
5085 VkDescriptorSetLayoutBinding dsl_binding = {};
5086 dsl_binding.binding = 0;
5087 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5088 dsl_binding.descriptorCount = 1;
5089 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5090 dsl_binding.pImmutableSamplers = NULL;
5091
5092 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5093 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5094 ds_layout_ci.pNext = NULL;
5095 ds_layout_ci.bindingCount = 1;
5096 ds_layout_ci.pBindings = &dsl_binding;
5097 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005098 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005099 ASSERT_VK_SUCCESS(err);
5100
5101 VkDescriptorSet descriptorSet;
5102 VkDescriptorSetAllocateInfo alloc_info = {};
5103 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5104 alloc_info.descriptorSetCount = 1;
5105 alloc_info.descriptorPool = ds_pool;
5106 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005107 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005108 ASSERT_VK_SUCCESS(err);
5109
5110 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5111 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5112 pipeline_layout_ci.pNext = NULL;
5113 pipeline_layout_ci.setLayoutCount = 1;
5114 pipeline_layout_ci.pSetLayouts = &ds_layout;
5115
5116 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005117 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005118 ASSERT_VK_SUCCESS(err);
5119
5120 // Create images to update the descriptor with
5121 VkImage image;
5122 VkImage image2;
5123 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5124 const int32_t tex_width = 32;
5125 const int32_t tex_height = 32;
5126 VkImageCreateInfo image_create_info = {};
5127 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5128 image_create_info.pNext = NULL;
5129 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5130 image_create_info.format = tex_format;
5131 image_create_info.extent.width = tex_width;
5132 image_create_info.extent.height = tex_height;
5133 image_create_info.extent.depth = 1;
5134 image_create_info.mipLevels = 1;
5135 image_create_info.arrayLayers = 1;
5136 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5137 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5138 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5139 image_create_info.flags = 0;
5140 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5141 ASSERT_VK_SUCCESS(err);
5142 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5143 ASSERT_VK_SUCCESS(err);
5144
5145 VkMemoryRequirements memory_reqs;
5146 VkDeviceMemory image_memory;
5147 bool pass;
5148 VkMemoryAllocateInfo memory_info = {};
5149 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5150 memory_info.pNext = NULL;
5151 memory_info.allocationSize = 0;
5152 memory_info.memoryTypeIndex = 0;
5153 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5154 // Allocate enough memory for both images
5155 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005156 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005157 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005158 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005159 ASSERT_VK_SUCCESS(err);
5160 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5161 ASSERT_VK_SUCCESS(err);
5162 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005163 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005164 ASSERT_VK_SUCCESS(err);
5165
5166 VkImageViewCreateInfo image_view_create_info = {};
5167 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5168 image_view_create_info.image = image;
5169 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5170 image_view_create_info.format = tex_format;
5171 image_view_create_info.subresourceRange.layerCount = 1;
5172 image_view_create_info.subresourceRange.baseMipLevel = 0;
5173 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005174 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005175
5176 VkImageView view;
5177 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005178 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005179 ASSERT_VK_SUCCESS(err);
5180 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005181 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005182 ASSERT_VK_SUCCESS(err);
5183 // Create Samplers
5184 VkSamplerCreateInfo sampler_ci = {};
5185 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5186 sampler_ci.pNext = NULL;
5187 sampler_ci.magFilter = VK_FILTER_NEAREST;
5188 sampler_ci.minFilter = VK_FILTER_NEAREST;
5189 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5190 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5191 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5192 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5193 sampler_ci.mipLodBias = 1.0;
5194 sampler_ci.anisotropyEnable = VK_FALSE;
5195 sampler_ci.maxAnisotropy = 1;
5196 sampler_ci.compareEnable = VK_FALSE;
5197 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5198 sampler_ci.minLod = 1.0;
5199 sampler_ci.maxLod = 1.0;
5200 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5201 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5202 VkSampler sampler;
5203 VkSampler sampler2;
5204 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5205 ASSERT_VK_SUCCESS(err);
5206 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5207 ASSERT_VK_SUCCESS(err);
5208 // Update descriptor with image and sampler
5209 VkDescriptorImageInfo img_info = {};
5210 img_info.sampler = sampler;
5211 img_info.imageView = view;
5212 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5213
5214 VkWriteDescriptorSet descriptor_write;
5215 memset(&descriptor_write, 0, sizeof(descriptor_write));
5216 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5217 descriptor_write.dstSet = descriptorSet;
5218 descriptor_write.dstBinding = 0;
5219 descriptor_write.descriptorCount = 1;
5220 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5221 descriptor_write.pImageInfo = &img_info;
5222
5223 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5224
5225 // Create PSO to be used for draw-time errors below
5226 char const *vsSource = "#version 450\n"
5227 "\n"
5228 "out gl_PerVertex { \n"
5229 " vec4 gl_Position;\n"
5230 "};\n"
5231 "void main(){\n"
5232 " gl_Position = vec4(1);\n"
5233 "}\n";
5234 char const *fsSource = "#version 450\n"
5235 "\n"
5236 "layout(set=0, binding=0) uniform sampler2D s;\n"
5237 "layout(location=0) out vec4 x;\n"
5238 "void main(){\n"
5239 " x = texture(s, vec2(1));\n"
5240 "}\n";
5241 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5242 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5243 VkPipelineObj pipe(m_device);
5244 pipe.AddShader(&vs);
5245 pipe.AddShader(&fs);
5246 pipe.AddColorAttachment();
5247 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5248
5249 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005251 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005252 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5253 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5254 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005255 Draw(1, 0, 0, 0);
5256 EndCommandBuffer();
5257 // Destroy sampler invalidates the cmd buffer, causing error on submit
5258 vkDestroySampler(m_device->device(), sampler, NULL);
5259 // Attempt to submit cmd buffer
5260 VkSubmitInfo submit_info = {};
5261 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5262 submit_info.commandBufferCount = 1;
5263 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5264 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5265 m_errorMonitor->VerifyFound();
5266 // Now re-update descriptor with valid sampler and delete image
5267 img_info.sampler = sampler2;
5268 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005270 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005271 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5272 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5273 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005274 Draw(1, 0, 0, 0);
5275 EndCommandBuffer();
5276 // Destroy image invalidates the cmd buffer, causing error on submit
5277 vkDestroyImage(m_device->device(), image, NULL);
5278 // Attempt to submit cmd buffer
5279 submit_info = {};
5280 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5281 submit_info.commandBufferCount = 1;
5282 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5283 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5284 m_errorMonitor->VerifyFound();
5285 // Now update descriptor to be valid, but then free descriptor
5286 img_info.imageView = view2;
5287 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005289 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005290 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5291 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5292 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005293 Draw(1, 0, 0, 0);
5294 EndCommandBuffer();
5295 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005297 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005298 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005299 // Attempt to submit cmd buffer
5300 submit_info = {};
5301 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5302 submit_info.commandBufferCount = 1;
5303 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5304 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5305 m_errorMonitor->VerifyFound();
5306 // Cleanup
5307 vkFreeMemory(m_device->device(), image_memory, NULL);
5308 vkDestroySampler(m_device->device(), sampler2, NULL);
5309 vkDestroyImage(m_device->device(), image2, NULL);
5310 vkDestroyImageView(m_device->device(), view, NULL);
5311 vkDestroyImageView(m_device->device(), view2, NULL);
5312 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5313 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5314 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5315}
5316
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005317TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5318 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5319 ASSERT_NO_FATAL_FAILURE(InitState());
5320 ASSERT_NO_FATAL_FAILURE(InitViewport());
5321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5322
5323 VkDescriptorPoolSize ds_type_count = {};
5324 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5325 ds_type_count.descriptorCount = 1;
5326
5327 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5328 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5329 ds_pool_ci.pNext = NULL;
5330 ds_pool_ci.maxSets = 1;
5331 ds_pool_ci.poolSizeCount = 1;
5332 ds_pool_ci.pPoolSizes = &ds_type_count;
5333
5334 VkDescriptorPool ds_pool;
5335 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5336 ASSERT_VK_SUCCESS(err);
5337
5338 VkDescriptorSetLayoutBinding dsl_binding = {};
5339 dsl_binding.binding = 0;
5340 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5341 dsl_binding.descriptorCount = 1;
5342 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5343 dsl_binding.pImmutableSamplers = NULL;
5344
5345 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5346 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5347 ds_layout_ci.pNext = NULL;
5348 ds_layout_ci.bindingCount = 1;
5349 ds_layout_ci.pBindings = &dsl_binding;
5350 VkDescriptorSetLayout ds_layout;
5351 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5352 ASSERT_VK_SUCCESS(err);
5353
5354 VkDescriptorSet descriptor_set;
5355 VkDescriptorSetAllocateInfo alloc_info = {};
5356 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5357 alloc_info.descriptorSetCount = 1;
5358 alloc_info.descriptorPool = ds_pool;
5359 alloc_info.pSetLayouts = &ds_layout;
5360 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5361 ASSERT_VK_SUCCESS(err);
5362
5363 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5364 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5365 pipeline_layout_ci.pNext = NULL;
5366 pipeline_layout_ci.setLayoutCount = 1;
5367 pipeline_layout_ci.pSetLayouts = &ds_layout;
5368
5369 VkPipelineLayout pipeline_layout;
5370 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5371 ASSERT_VK_SUCCESS(err);
5372
5373 // Create image to update the descriptor with
5374 VkImageObj image(m_device);
5375 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5376 ASSERT_TRUE(image.initialized());
5377
5378 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5379 // Create Sampler
5380 VkSamplerCreateInfo sampler_ci = {};
5381 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5382 sampler_ci.pNext = NULL;
5383 sampler_ci.magFilter = VK_FILTER_NEAREST;
5384 sampler_ci.minFilter = VK_FILTER_NEAREST;
5385 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5386 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5387 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5388 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5389 sampler_ci.mipLodBias = 1.0;
5390 sampler_ci.anisotropyEnable = VK_FALSE;
5391 sampler_ci.maxAnisotropy = 1;
5392 sampler_ci.compareEnable = VK_FALSE;
5393 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5394 sampler_ci.minLod = 1.0;
5395 sampler_ci.maxLod = 1.0;
5396 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5397 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5398 VkSampler sampler;
5399 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5400 ASSERT_VK_SUCCESS(err);
5401 // Update descriptor with image and sampler
5402 VkDescriptorImageInfo img_info = {};
5403 img_info.sampler = sampler;
5404 img_info.imageView = view;
5405 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5406
5407 VkWriteDescriptorSet descriptor_write;
5408 memset(&descriptor_write, 0, sizeof(descriptor_write));
5409 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5410 descriptor_write.dstSet = descriptor_set;
5411 descriptor_write.dstBinding = 0;
5412 descriptor_write.descriptorCount = 1;
5413 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5414 descriptor_write.pImageInfo = &img_info;
5415
5416 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5417
5418 // Create PSO to be used for draw-time errors below
5419 char const *vsSource = "#version 450\n"
5420 "\n"
5421 "out gl_PerVertex { \n"
5422 " vec4 gl_Position;\n"
5423 "};\n"
5424 "void main(){\n"
5425 " gl_Position = vec4(1);\n"
5426 "}\n";
5427 char const *fsSource = "#version 450\n"
5428 "\n"
5429 "layout(set=0, binding=0) uniform sampler2D s;\n"
5430 "layout(location=0) out vec4 x;\n"
5431 "void main(){\n"
5432 " x = texture(s, vec2(1));\n"
5433 "}\n";
5434 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5435 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5436 VkPipelineObj pipe(m_device);
5437 pipe.AddShader(&vs);
5438 pipe.AddShader(&fs);
5439 pipe.AddColorAttachment();
5440 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5441
5442 BeginCommandBuffer();
5443 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5444 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5445 &descriptor_set, 0, NULL);
5446 Draw(1, 0, 0, 0);
5447 EndCommandBuffer();
5448 // Submit cmd buffer to put pool in-flight
5449 VkSubmitInfo submit_info = {};
5450 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5451 submit_info.commandBufferCount = 1;
5452 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5453 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5454 // Destroy pool while in-flight, causing error
5455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5456 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5457 m_errorMonitor->VerifyFound();
5458 vkQueueWaitIdle(m_device->m_queue);
5459 // Cleanup
5460 vkDestroySampler(m_device->device(), sampler, NULL);
5461 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5462 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5463 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5464}
5465
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005466TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5467 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5468 ASSERT_NO_FATAL_FAILURE(InitState());
5469 ASSERT_NO_FATAL_FAILURE(InitViewport());
5470 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5471
5472 VkDescriptorPoolSize ds_type_count = {};
5473 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5474 ds_type_count.descriptorCount = 1;
5475
5476 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5477 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5478 ds_pool_ci.pNext = NULL;
5479 ds_pool_ci.maxSets = 1;
5480 ds_pool_ci.poolSizeCount = 1;
5481 ds_pool_ci.pPoolSizes = &ds_type_count;
5482
5483 VkDescriptorPool ds_pool;
5484 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5485 ASSERT_VK_SUCCESS(err);
5486
5487 VkDescriptorSetLayoutBinding dsl_binding = {};
5488 dsl_binding.binding = 0;
5489 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5490 dsl_binding.descriptorCount = 1;
5491 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5492 dsl_binding.pImmutableSamplers = NULL;
5493
5494 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5495 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5496 ds_layout_ci.pNext = NULL;
5497 ds_layout_ci.bindingCount = 1;
5498 ds_layout_ci.pBindings = &dsl_binding;
5499 VkDescriptorSetLayout ds_layout;
5500 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5501 ASSERT_VK_SUCCESS(err);
5502
5503 VkDescriptorSet descriptorSet;
5504 VkDescriptorSetAllocateInfo alloc_info = {};
5505 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5506 alloc_info.descriptorSetCount = 1;
5507 alloc_info.descriptorPool = ds_pool;
5508 alloc_info.pSetLayouts = &ds_layout;
5509 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5510 ASSERT_VK_SUCCESS(err);
5511
5512 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5513 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5514 pipeline_layout_ci.pNext = NULL;
5515 pipeline_layout_ci.setLayoutCount = 1;
5516 pipeline_layout_ci.pSetLayouts = &ds_layout;
5517
5518 VkPipelineLayout pipeline_layout;
5519 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5520 ASSERT_VK_SUCCESS(err);
5521
5522 // Create images to update the descriptor with
5523 VkImage image;
5524 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5525 const int32_t tex_width = 32;
5526 const int32_t tex_height = 32;
5527 VkImageCreateInfo image_create_info = {};
5528 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5529 image_create_info.pNext = NULL;
5530 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5531 image_create_info.format = tex_format;
5532 image_create_info.extent.width = tex_width;
5533 image_create_info.extent.height = tex_height;
5534 image_create_info.extent.depth = 1;
5535 image_create_info.mipLevels = 1;
5536 image_create_info.arrayLayers = 1;
5537 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5538 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5539 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5540 image_create_info.flags = 0;
5541 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5542 ASSERT_VK_SUCCESS(err);
5543 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5544 VkMemoryRequirements memory_reqs;
5545 VkDeviceMemory image_memory;
5546 bool pass;
5547 VkMemoryAllocateInfo memory_info = {};
5548 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5549 memory_info.pNext = NULL;
5550 memory_info.allocationSize = 0;
5551 memory_info.memoryTypeIndex = 0;
5552 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5553 // Allocate enough memory for image
5554 memory_info.allocationSize = memory_reqs.size;
5555 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5556 ASSERT_TRUE(pass);
5557 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5558 ASSERT_VK_SUCCESS(err);
5559 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5560 ASSERT_VK_SUCCESS(err);
5561
5562 VkImageViewCreateInfo image_view_create_info = {};
5563 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5564 image_view_create_info.image = image;
5565 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5566 image_view_create_info.format = tex_format;
5567 image_view_create_info.subresourceRange.layerCount = 1;
5568 image_view_create_info.subresourceRange.baseMipLevel = 0;
5569 image_view_create_info.subresourceRange.levelCount = 1;
5570 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5571
5572 VkImageView view;
5573 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5574 ASSERT_VK_SUCCESS(err);
5575 // Create Samplers
5576 VkSamplerCreateInfo sampler_ci = {};
5577 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5578 sampler_ci.pNext = NULL;
5579 sampler_ci.magFilter = VK_FILTER_NEAREST;
5580 sampler_ci.minFilter = VK_FILTER_NEAREST;
5581 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5582 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5583 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5584 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5585 sampler_ci.mipLodBias = 1.0;
5586 sampler_ci.anisotropyEnable = VK_FALSE;
5587 sampler_ci.maxAnisotropy = 1;
5588 sampler_ci.compareEnable = VK_FALSE;
5589 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5590 sampler_ci.minLod = 1.0;
5591 sampler_ci.maxLod = 1.0;
5592 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5593 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5594 VkSampler sampler;
5595 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5596 ASSERT_VK_SUCCESS(err);
5597 // Update descriptor with image and sampler
5598 VkDescriptorImageInfo img_info = {};
5599 img_info.sampler = sampler;
5600 img_info.imageView = view;
5601 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5602
5603 VkWriteDescriptorSet descriptor_write;
5604 memset(&descriptor_write, 0, sizeof(descriptor_write));
5605 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5606 descriptor_write.dstSet = descriptorSet;
5607 descriptor_write.dstBinding = 0;
5608 descriptor_write.descriptorCount = 1;
5609 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5610 descriptor_write.pImageInfo = &img_info;
5611 // Break memory binding and attempt update
5612 vkFreeMemory(m_device->device(), image_memory, nullptr);
5613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005614 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5616 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5617 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5618 m_errorMonitor->VerifyFound();
5619 // Cleanup
5620 vkDestroyImage(m_device->device(), image, NULL);
5621 vkDestroySampler(m_device->device(), sampler, NULL);
5622 vkDestroyImageView(m_device->device(), view, NULL);
5623 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5624 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5625 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5626}
5627
Karl Schultz6addd812016-02-02 17:17:23 -07005628TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005629 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5630 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005631 // Create a valid cmd buffer
5632 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005633 uint64_t fake_pipeline_handle = 0xbaad6001;
5634 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005635 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005636 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5637
5638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005639 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005640 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005641 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005642
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005643 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005644 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 -06005645 Draw(1, 0, 0, 0);
5646 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005647
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005648 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005649 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 +12005650 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005651 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5652 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005653}
5654
Karl Schultz6addd812016-02-02 17:17:23 -07005655TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005656 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005657 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005658
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005660
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005661 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005662 ASSERT_NO_FATAL_FAILURE(InitViewport());
5663 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005664 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005665 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5666 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005667
5668 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005669 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5670 ds_pool_ci.pNext = NULL;
5671 ds_pool_ci.maxSets = 1;
5672 ds_pool_ci.poolSizeCount = 1;
5673 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005674
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005675 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005676 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005677 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005678
Tony Barboureb254902015-07-15 12:50:33 -06005679 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005680 dsl_binding.binding = 0;
5681 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5682 dsl_binding.descriptorCount = 1;
5683 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5684 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005685
Tony Barboureb254902015-07-15 12:50:33 -06005686 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005687 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5688 ds_layout_ci.pNext = NULL;
5689 ds_layout_ci.bindingCount = 1;
5690 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005691 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005692 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005693 ASSERT_VK_SUCCESS(err);
5694
5695 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005696 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005697 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005698 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005699 alloc_info.descriptorPool = ds_pool;
5700 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005701 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005702 ASSERT_VK_SUCCESS(err);
5703
Tony Barboureb254902015-07-15 12:50:33 -06005704 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005705 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5706 pipeline_layout_ci.pNext = NULL;
5707 pipeline_layout_ci.setLayoutCount = 1;
5708 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005709
5710 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005711 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005712 ASSERT_VK_SUCCESS(err);
5713
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005714 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005715 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005716 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005717 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005718
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005719 VkPipelineObj pipe(m_device);
5720 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005721 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005722 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005723 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005724
5725 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005726 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5727 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5728 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005729
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005730 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005731
Chia-I Wuf7458c52015-10-26 21:10:41 +08005732 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5733 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5734 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005735}
5736
Karl Schultz6addd812016-02-02 17:17:23 -07005737TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005738 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005739 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005740
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5742 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005743
5744 ASSERT_NO_FATAL_FAILURE(InitState());
5745 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005746 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5747 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005748
5749 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005750 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5751 ds_pool_ci.pNext = NULL;
5752 ds_pool_ci.maxSets = 1;
5753 ds_pool_ci.poolSizeCount = 1;
5754 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005755
5756 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005757 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005758 ASSERT_VK_SUCCESS(err);
5759
5760 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005761 dsl_binding.binding = 0;
5762 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5763 dsl_binding.descriptorCount = 1;
5764 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5765 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005766
5767 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005768 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5769 ds_layout_ci.pNext = NULL;
5770 ds_layout_ci.bindingCount = 1;
5771 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005772 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005773 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005774 ASSERT_VK_SUCCESS(err);
5775
5776 VkDescriptorSet descriptorSet;
5777 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005778 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005779 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005780 alloc_info.descriptorPool = ds_pool;
5781 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005782 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005783 ASSERT_VK_SUCCESS(err);
5784
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005785 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005786 VkWriteDescriptorSet descriptor_write;
5787 memset(&descriptor_write, 0, sizeof(descriptor_write));
5788 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5789 descriptor_write.dstSet = descriptorSet;
5790 descriptor_write.dstBinding = 0;
5791 descriptor_write.descriptorCount = 1;
5792 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5793 descriptor_write.pTexelBufferView = &view;
5794
5795 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5796
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005797 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005798
5799 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5800 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5801}
5802
Mark Youngd339ba32016-05-30 13:28:35 -06005803TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005804 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 -06005805
5806 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005808 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005809
5810 ASSERT_NO_FATAL_FAILURE(InitState());
5811
5812 // Create a buffer with no bound memory and then attempt to create
5813 // a buffer view.
5814 VkBufferCreateInfo buff_ci = {};
5815 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005816 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005817 buff_ci.size = 256;
5818 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5819 VkBuffer buffer;
5820 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5821 ASSERT_VK_SUCCESS(err);
5822
5823 VkBufferViewCreateInfo buff_view_ci = {};
5824 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5825 buff_view_ci.buffer = buffer;
5826 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5827 buff_view_ci.range = VK_WHOLE_SIZE;
5828 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005829 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005830
5831 m_errorMonitor->VerifyFound();
5832 vkDestroyBuffer(m_device->device(), buffer, NULL);
5833 // If last error is success, it still created the view, so delete it.
5834 if (err == VK_SUCCESS) {
5835 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5836 }
5837}
5838
Karl Schultz6addd812016-02-02 17:17:23 -07005839TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5840 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5841 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005842 // 1. No dynamicOffset supplied
5843 // 2. Too many dynamicOffsets supplied
5844 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005845 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5847 "0 dynamicOffsets are left in "
5848 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005849
5850 ASSERT_NO_FATAL_FAILURE(InitState());
5851 ASSERT_NO_FATAL_FAILURE(InitViewport());
5852 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5853
5854 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005855 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5856 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005857
5858 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005859 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5860 ds_pool_ci.pNext = NULL;
5861 ds_pool_ci.maxSets = 1;
5862 ds_pool_ci.poolSizeCount = 1;
5863 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005864
5865 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005866 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005867 ASSERT_VK_SUCCESS(err);
5868
5869 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005870 dsl_binding.binding = 0;
5871 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5872 dsl_binding.descriptorCount = 1;
5873 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5874 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005875
5876 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005877 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5878 ds_layout_ci.pNext = NULL;
5879 ds_layout_ci.bindingCount = 1;
5880 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005881 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005882 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005883 ASSERT_VK_SUCCESS(err);
5884
5885 VkDescriptorSet descriptorSet;
5886 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005887 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005888 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005889 alloc_info.descriptorPool = ds_pool;
5890 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005891 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005892 ASSERT_VK_SUCCESS(err);
5893
5894 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005895 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5896 pipeline_layout_ci.pNext = NULL;
5897 pipeline_layout_ci.setLayoutCount = 1;
5898 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005899
5900 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005901 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005902 ASSERT_VK_SUCCESS(err);
5903
5904 // Create a buffer to update the descriptor with
5905 uint32_t qfi = 0;
5906 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005907 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5908 buffCI.size = 1024;
5909 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5910 buffCI.queueFamilyIndexCount = 1;
5911 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005912
5913 VkBuffer dyub;
5914 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5915 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005916 // Allocate memory and bind to buffer so we can make it to the appropriate
5917 // error
5918 VkMemoryAllocateInfo mem_alloc = {};
5919 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5920 mem_alloc.pNext = NULL;
5921 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005922 mem_alloc.memoryTypeIndex = 0;
5923
5924 VkMemoryRequirements memReqs;
5925 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005926 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005927 if (!pass) {
5928 vkDestroyBuffer(m_device->device(), dyub, NULL);
5929 return;
5930 }
5931
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005932 VkDeviceMemory mem;
5933 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5934 ASSERT_VK_SUCCESS(err);
5935 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5936 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005937 // Correctly update descriptor to avoid "NOT_UPDATED" error
5938 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005939 buffInfo.buffer = dyub;
5940 buffInfo.offset = 0;
5941 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005942
5943 VkWriteDescriptorSet descriptor_write;
5944 memset(&descriptor_write, 0, sizeof(descriptor_write));
5945 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5946 descriptor_write.dstSet = descriptorSet;
5947 descriptor_write.dstBinding = 0;
5948 descriptor_write.descriptorCount = 1;
5949 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5950 descriptor_write.pBufferInfo = &buffInfo;
5951
5952 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5953
5954 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005955 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5956 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005957 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005958 uint32_t pDynOff[2] = {512, 756};
5959 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5961 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5962 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5963 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005964 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005965 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5967 "offset 0 and range 1024 that "
5968 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005969 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005970 char const *vsSource = "#version 450\n"
5971 "\n"
5972 "out gl_PerVertex { \n"
5973 " vec4 gl_Position;\n"
5974 "};\n"
5975 "void main(){\n"
5976 " gl_Position = vec4(1);\n"
5977 "}\n";
5978 char const *fsSource = "#version 450\n"
5979 "\n"
5980 "layout(location=0) out vec4 x;\n"
5981 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5982 "void main(){\n"
5983 " x = vec4(bar.y);\n"
5984 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005985 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5986 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5987 VkPipelineObj pipe(m_device);
5988 pipe.AddShader(&vs);
5989 pipe.AddShader(&fs);
5990 pipe.AddColorAttachment();
5991 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5992
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005993 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005994 // This update should succeed, but offset size of 512 will overstep buffer
5995 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005996 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5997 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005998 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005999 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006000
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006001 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006002 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006003
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006004 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006005 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006006 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6007}
6008
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006009TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6010 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6011 "that doesn't have memory bound");
6012 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006014 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6016 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006017
6018 ASSERT_NO_FATAL_FAILURE(InitState());
6019 ASSERT_NO_FATAL_FAILURE(InitViewport());
6020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6021
6022 VkDescriptorPoolSize ds_type_count = {};
6023 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6024 ds_type_count.descriptorCount = 1;
6025
6026 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6027 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6028 ds_pool_ci.pNext = NULL;
6029 ds_pool_ci.maxSets = 1;
6030 ds_pool_ci.poolSizeCount = 1;
6031 ds_pool_ci.pPoolSizes = &ds_type_count;
6032
6033 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006034 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006035 ASSERT_VK_SUCCESS(err);
6036
6037 VkDescriptorSetLayoutBinding dsl_binding = {};
6038 dsl_binding.binding = 0;
6039 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6040 dsl_binding.descriptorCount = 1;
6041 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6042 dsl_binding.pImmutableSamplers = NULL;
6043
6044 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6045 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6046 ds_layout_ci.pNext = NULL;
6047 ds_layout_ci.bindingCount = 1;
6048 ds_layout_ci.pBindings = &dsl_binding;
6049 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006050 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006051 ASSERT_VK_SUCCESS(err);
6052
6053 VkDescriptorSet descriptorSet;
6054 VkDescriptorSetAllocateInfo alloc_info = {};
6055 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6056 alloc_info.descriptorSetCount = 1;
6057 alloc_info.descriptorPool = ds_pool;
6058 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006059 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006060 ASSERT_VK_SUCCESS(err);
6061
6062 // Create a buffer to update the descriptor with
6063 uint32_t qfi = 0;
6064 VkBufferCreateInfo buffCI = {};
6065 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6066 buffCI.size = 1024;
6067 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6068 buffCI.queueFamilyIndexCount = 1;
6069 buffCI.pQueueFamilyIndices = &qfi;
6070
6071 VkBuffer dyub;
6072 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6073 ASSERT_VK_SUCCESS(err);
6074
6075 // Attempt to update descriptor without binding memory to it
6076 VkDescriptorBufferInfo buffInfo = {};
6077 buffInfo.buffer = dyub;
6078 buffInfo.offset = 0;
6079 buffInfo.range = 1024;
6080
6081 VkWriteDescriptorSet descriptor_write;
6082 memset(&descriptor_write, 0, sizeof(descriptor_write));
6083 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6084 descriptor_write.dstSet = descriptorSet;
6085 descriptor_write.dstBinding = 0;
6086 descriptor_write.descriptorCount = 1;
6087 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6088 descriptor_write.pBufferInfo = &buffInfo;
6089
6090 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6091 m_errorMonitor->VerifyFound();
6092
6093 vkDestroyBuffer(m_device->device(), dyub, NULL);
6094 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6095 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6096}
6097
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006098TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006099 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006100 ASSERT_NO_FATAL_FAILURE(InitState());
6101 ASSERT_NO_FATAL_FAILURE(InitViewport());
6102 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6103
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006104 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006105 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006106 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6107 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6108 pipeline_layout_ci.pushConstantRangeCount = 1;
6109 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6110
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006111 //
6112 // Check for invalid push constant ranges in pipeline layouts.
6113 //
6114 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006115 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006116 char const *msg;
6117 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006118
Karl Schultzc81037d2016-05-12 08:11:23 -06006119 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6120 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6121 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6122 "vkCreatePipelineLayout() call has push constants index 0 with "
6123 "size 0."},
6124 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6125 "vkCreatePipelineLayout() call has push constants index 0 with "
6126 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006127 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006128 "vkCreatePipelineLayout() call has push constants index 0 with "
6129 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006130 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006131 "vkCreatePipelineLayout() call has push constants index 0 with "
6132 "size 0."},
6133 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6134 "vkCreatePipelineLayout() call has push constants index 0 with "
6135 "offset 1. Offset must"},
6136 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6137 "vkCreatePipelineLayout() call has push constants index 0 "
6138 "with offset "},
6139 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6140 "vkCreatePipelineLayout() call has push constants "
6141 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006142 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006143 "vkCreatePipelineLayout() call has push constants index 0 "
6144 "with offset "},
6145 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6146 "vkCreatePipelineLayout() call has push "
6147 "constants index 0 with offset "},
6148 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6149 "vkCreatePipelineLayout() call has push "
6150 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006151 }};
6152
6153 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006154 for (const auto &iter : range_tests) {
6155 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6157 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006158 m_errorMonitor->VerifyFound();
6159 if (VK_SUCCESS == err) {
6160 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6161 }
6162 }
6163
6164 // Check for invalid stage flag
6165 pc_range.offset = 0;
6166 pc_range.size = 16;
6167 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006168 m_errorMonitor->SetDesiredFailureMsg(
6169 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6170 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006171 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006172 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006173 if (VK_SUCCESS == err) {
6174 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6175 }
6176
6177 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006178 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006179 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006180 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006181 char const *msg;
6182 };
6183
Karl Schultzc81037d2016-05-12 08:11:23 -06006184 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006185 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6186 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6187 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6188 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6189 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006190 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006191 {
6192 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6193 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6194 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6195 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6196 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006197 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006198 },
6199 {
6200 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6201 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6202 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6203 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6204 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006205 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006206 },
6207 {
6208 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6209 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6210 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6211 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6212 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006213 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006214 },
6215 {
6216 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6217 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6218 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6219 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6220 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006221 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006222 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006223
Karl Schultzc81037d2016-05-12 08:11:23 -06006224 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006225 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006226 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6228 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006229 m_errorMonitor->VerifyFound();
6230 if (VK_SUCCESS == err) {
6231 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6232 }
6233 }
6234
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006235 //
6236 // CmdPushConstants tests
6237 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006238 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006239
6240 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006241 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6242 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006243 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6244 "vkCmdPushConstants() call has push constants with size 1. Size "
6245 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006246 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006247 "vkCmdPushConstants() call has push constants with size 1. Size "
6248 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006249 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006250 "vkCmdPushConstants() call has push constants with offset 1. "
6251 "Offset must be a multiple of 4."},
6252 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6253 "vkCmdPushConstants() call has push constants with offset 1. "
6254 "Offset must be a multiple of 4."},
6255 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6256 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6257 "0x1 not within flag-matching ranges in pipeline layout"},
6258 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6259 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6260 "0x1 not within flag-matching ranges in pipeline layout"},
6261 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6262 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6263 "0x1 not within flag-matching ranges in pipeline layout"},
6264 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6265 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6266 "0x1 not within flag-matching ranges in pipeline layout"},
6267 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6268 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6269 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006270 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006271 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6272 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006273 }};
6274
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006275 BeginCommandBuffer();
6276
6277 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006278 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006279 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006280 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006281 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006282 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006283 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006284 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006285 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6287 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006288 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006289 m_errorMonitor->VerifyFound();
6290 }
6291
6292 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006294 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006295 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006296 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006297
Karl Schultzc81037d2016-05-12 08:11:23 -06006298 // overlapping range tests with cmd
6299 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6300 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6301 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6302 "0x1 not within flag-matching ranges in pipeline layout"},
6303 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6304 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6305 "0x1 not within flag-matching ranges in pipeline layout"},
6306 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6307 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6308 "0x1 not within flag-matching ranges in pipeline layout"},
6309 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006310 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006311 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006312 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6313 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006314 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006315 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006316 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006317 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006318 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006319 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6321 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006322 iter.range.size, dummy_values);
6323 m_errorMonitor->VerifyFound();
6324 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006325 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6326
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006327 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006328}
6329
Karl Schultz6addd812016-02-02 17:17:23 -07006330TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006331 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006332 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006333
6334 ASSERT_NO_FATAL_FAILURE(InitState());
6335 ASSERT_NO_FATAL_FAILURE(InitViewport());
6336 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6337
Mike Stroyanb8a61002016-06-20 16:00:28 -06006338 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6339 VkImageTiling tiling;
6340 VkFormatProperties format_properties;
6341 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006342 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006343 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006344 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006345 tiling = VK_IMAGE_TILING_OPTIMAL;
6346 } else {
6347 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6348 "skipped.\n");
6349 return;
6350 }
6351
Tobin Ehlis559c6382015-11-05 09:52:49 -07006352 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6353 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006354 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6355 ds_type_count[0].descriptorCount = 10;
6356 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6357 ds_type_count[1].descriptorCount = 2;
6358 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6359 ds_type_count[2].descriptorCount = 2;
6360 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6361 ds_type_count[3].descriptorCount = 5;
6362 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6363 // type
6364 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6365 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6366 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006367
6368 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006369 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6370 ds_pool_ci.pNext = NULL;
6371 ds_pool_ci.maxSets = 5;
6372 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6373 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006374
6375 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006376 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006377 ASSERT_VK_SUCCESS(err);
6378
6379 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6380 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006381 dsl_binding[0].binding = 0;
6382 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6383 dsl_binding[0].descriptorCount = 5;
6384 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6385 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006386
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006387 // Create layout identical to set0 layout but w/ different stageFlags
6388 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006389 dsl_fs_stage_only.binding = 0;
6390 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6391 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006392 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6393 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006394 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006395 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006396 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6397 ds_layout_ci.pNext = NULL;
6398 ds_layout_ci.bindingCount = 1;
6399 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006400 static const uint32_t NUM_LAYOUTS = 4;
6401 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006402 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006403 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6404 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006405 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006406 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006407 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006408 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006409 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006410 dsl_binding[0].binding = 0;
6411 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006412 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006413 dsl_binding[1].binding = 1;
6414 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6415 dsl_binding[1].descriptorCount = 2;
6416 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6417 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006418 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006419 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006420 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006421 ASSERT_VK_SUCCESS(err);
6422 dsl_binding[0].binding = 0;
6423 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006424 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006425 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006426 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006427 ASSERT_VK_SUCCESS(err);
6428 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006429 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006430 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006431 ASSERT_VK_SUCCESS(err);
6432
6433 static const uint32_t NUM_SETS = 4;
6434 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6435 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006436 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006437 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006438 alloc_info.descriptorPool = ds_pool;
6439 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006440 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006441 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006442 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006443 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006444 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006445 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006446 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006447
6448 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006449 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6450 pipeline_layout_ci.pNext = NULL;
6451 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6452 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006453
6454 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006455 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006456 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006457 // Create pipelineLayout with only one setLayout
6458 pipeline_layout_ci.setLayoutCount = 1;
6459 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006460 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006461 ASSERT_VK_SUCCESS(err);
6462 // Create pipelineLayout with 2 descriptor setLayout at index 0
6463 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6464 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006465 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006466 ASSERT_VK_SUCCESS(err);
6467 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6468 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6469 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006470 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006471 ASSERT_VK_SUCCESS(err);
6472 // Create pipelineLayout with UB type, but stageFlags for FS only
6473 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6474 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006475 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006476 ASSERT_VK_SUCCESS(err);
6477 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6478 VkDescriptorSetLayout pl_bad_s0[2] = {};
6479 pl_bad_s0[0] = ds_layout_fs_only;
6480 pl_bad_s0[1] = ds_layout[1];
6481 pipeline_layout_ci.setLayoutCount = 2;
6482 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6483 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006484 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006485 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006486
6487 // Create a buffer to update the descriptor with
6488 uint32_t qfi = 0;
6489 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006490 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6491 buffCI.size = 1024;
6492 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6493 buffCI.queueFamilyIndexCount = 1;
6494 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006495
6496 VkBuffer dyub;
6497 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6498 ASSERT_VK_SUCCESS(err);
6499 // Correctly update descriptor to avoid "NOT_UPDATED" error
6500 static const uint32_t NUM_BUFFS = 5;
6501 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006502 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006503 buffInfo[i].buffer = dyub;
6504 buffInfo[i].offset = 0;
6505 buffInfo[i].range = 1024;
6506 }
Karl Schultz6addd812016-02-02 17:17:23 -07006507 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006508 const int32_t tex_width = 32;
6509 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006510 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006511 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6512 image_create_info.pNext = NULL;
6513 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6514 image_create_info.format = tex_format;
6515 image_create_info.extent.width = tex_width;
6516 image_create_info.extent.height = tex_height;
6517 image_create_info.extent.depth = 1;
6518 image_create_info.mipLevels = 1;
6519 image_create_info.arrayLayers = 1;
6520 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006521 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006522 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006523 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006524 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6525 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006526
Karl Schultz6addd812016-02-02 17:17:23 -07006527 VkMemoryRequirements memReqs;
6528 VkDeviceMemory imageMem;
6529 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006530 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006531 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6532 memAlloc.pNext = NULL;
6533 memAlloc.allocationSize = 0;
6534 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006535 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6536 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006537 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006538 ASSERT_TRUE(pass);
6539 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6540 ASSERT_VK_SUCCESS(err);
6541 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6542 ASSERT_VK_SUCCESS(err);
6543
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006544 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006545 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6546 image_view_create_info.image = image;
6547 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6548 image_view_create_info.format = tex_format;
6549 image_view_create_info.subresourceRange.layerCount = 1;
6550 image_view_create_info.subresourceRange.baseMipLevel = 0;
6551 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006552 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006553
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006554 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006555 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006556 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006557 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006558 imageInfo[0].imageView = view;
6559 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6560 imageInfo[1].imageView = view;
6561 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006562 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006563 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006564 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006565 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006566
6567 static const uint32_t NUM_SET_UPDATES = 3;
6568 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6569 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6570 descriptor_write[0].dstSet = descriptorSet[0];
6571 descriptor_write[0].dstBinding = 0;
6572 descriptor_write[0].descriptorCount = 5;
6573 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6574 descriptor_write[0].pBufferInfo = buffInfo;
6575 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6576 descriptor_write[1].dstSet = descriptorSet[1];
6577 descriptor_write[1].dstBinding = 0;
6578 descriptor_write[1].descriptorCount = 2;
6579 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6580 descriptor_write[1].pImageInfo = imageInfo;
6581 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6582 descriptor_write[2].dstSet = descriptorSet[1];
6583 descriptor_write[2].dstBinding = 1;
6584 descriptor_write[2].descriptorCount = 2;
6585 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006586 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006587
6588 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006589
Tobin Ehlis88452832015-12-03 09:40:56 -07006590 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006591 char const *vsSource = "#version 450\n"
6592 "\n"
6593 "out gl_PerVertex {\n"
6594 " vec4 gl_Position;\n"
6595 "};\n"
6596 "void main(){\n"
6597 " gl_Position = vec4(1);\n"
6598 "}\n";
6599 char const *fsSource = "#version 450\n"
6600 "\n"
6601 "layout(location=0) out vec4 x;\n"
6602 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6603 "void main(){\n"
6604 " x = vec4(bar.y);\n"
6605 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006606 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6607 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006608 VkPipelineObj pipe(m_device);
6609 pipe.AddShader(&vs);
6610 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006611 pipe.AddColorAttachment();
6612 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006613
6614 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006615
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006616 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006617 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6618 // of PSO
6619 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6620 // cmd_pipeline.c
6621 // due to the fact that cmd_alloc_dset_data() has not been called in
6622 // cmd_bind_graphics_pipeline()
6623 // TODO : Want to cause various binding incompatibility issues here to test
6624 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006625 // First cause various verify_layout_compatibility() fails
6626 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006627 // verify_set_layout_compatibility fail cases:
6628 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6630 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6631 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006632 m_errorMonitor->VerifyFound();
6633
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006634 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6636 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6637 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006638 m_errorMonitor->VerifyFound();
6639
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006640 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006641 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6642 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6644 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6645 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006646 m_errorMonitor->VerifyFound();
6647
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006648 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6649 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6651 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6652 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006653 m_errorMonitor->VerifyFound();
6654
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006655 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6656 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6658 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6659 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6660 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006661 m_errorMonitor->VerifyFound();
6662
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006663 // Cause INFO messages due to disturbing previously bound Sets
6664 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006665 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6666 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006667 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6669 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6670 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006671 m_errorMonitor->VerifyFound();
6672
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006673 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6674 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006675 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6677 "any subsequent sets were disturbed ");
6678 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6679 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006680 m_errorMonitor->VerifyFound();
6681
Tobin Ehlis10fad692016-07-07 12:00:36 -06006682 // Now that we're done actively using the pipelineLayout that gfx pipeline
6683 // was created with, we should be able to delete it. Do that now to verify
6684 // that validation obeys pipelineLayout lifetime
6685 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6686
Tobin Ehlis88452832015-12-03 09:40:56 -07006687 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006688 // 1. Error due to not binding required set (we actually use same code as
6689 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006690 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6691 &descriptorSet[0], 0, NULL);
6692 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6693 &descriptorSet[1], 0, NULL);
6694 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 -07006695 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006696 m_errorMonitor->VerifyFound();
6697
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006698 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006699 // 2. Error due to bound set not being compatible with PSO's
6700 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006701 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6702 &descriptorSet[0], 0, NULL);
6703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006704 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006705 m_errorMonitor->VerifyFound();
6706
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006707 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006708 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006709 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6710 }
6711 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006712 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006713 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6714 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006715 vkFreeMemory(m_device->device(), imageMem, NULL);
6716 vkDestroyImage(m_device->device(), image, NULL);
6717 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006718}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006719
Karl Schultz6addd812016-02-02 17:17:23 -07006720TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006721
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6723 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006724
6725 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006726 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006727 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006728 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006729
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006730 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006731}
6732
Karl Schultz6addd812016-02-02 17:17:23 -07006733TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6734 VkResult err;
6735 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006736
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006738
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006739 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006740
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006741 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006742 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006743 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006744 cmd.commandPool = m_commandPool;
6745 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006746 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006747
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006748 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006749 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006750
6751 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006752 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006753 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006754 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006755 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006756 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 -07006757 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006758
6759 // The error should be caught by validation of the BeginCommandBuffer call
6760 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6761
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006762 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006763 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006764}
6765
Karl Schultz6addd812016-02-02 17:17:23 -07006766TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006767 // Cause error due to Begin while recording CB
6768 // Then cause 2 errors for attempting to reset CB w/o having
6769 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6770 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006772
6773 ASSERT_NO_FATAL_FAILURE(InitState());
6774
6775 // Calls AllocateCommandBuffers
6776 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6777
Karl Schultz6addd812016-02-02 17:17:23 -07006778 // Force the failure by setting the Renderpass and Framebuffer fields with
6779 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006780 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006781 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006782 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6783 cmd_buf_info.pNext = NULL;
6784 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006785 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006786
6787 // Begin CB to transition to recording state
6788 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6789 // Can't re-begin. This should trigger error
6790 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006791 m_errorMonitor->VerifyFound();
6792
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006794 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6795 // Reset attempt will trigger error due to incorrect CommandPool state
6796 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006797 m_errorMonitor->VerifyFound();
6798
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006800 // Transition CB to RECORDED state
6801 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6802 // Now attempting to Begin will implicitly reset, which triggers error
6803 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006804 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006805}
6806
Karl Schultz6addd812016-02-02 17:17:23 -07006807TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006808 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006809 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006810
Mike Weiblencce7ec72016-10-17 19:33:05 -06006811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006812
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006813 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006815
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006816 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006817 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6818 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006819
6820 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006821 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6822 ds_pool_ci.pNext = NULL;
6823 ds_pool_ci.maxSets = 1;
6824 ds_pool_ci.poolSizeCount = 1;
6825 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006826
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006827 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006828 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006829 ASSERT_VK_SUCCESS(err);
6830
Tony Barboureb254902015-07-15 12:50:33 -06006831 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006832 dsl_binding.binding = 0;
6833 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6834 dsl_binding.descriptorCount = 1;
6835 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6836 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006837
Tony Barboureb254902015-07-15 12:50:33 -06006838 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006839 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6840 ds_layout_ci.pNext = NULL;
6841 ds_layout_ci.bindingCount = 1;
6842 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006843
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006844 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006845 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006846 ASSERT_VK_SUCCESS(err);
6847
6848 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006849 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006850 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006851 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006852 alloc_info.descriptorPool = ds_pool;
6853 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006854 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006855 ASSERT_VK_SUCCESS(err);
6856
Tony Barboureb254902015-07-15 12:50:33 -06006857 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006858 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6859 pipeline_layout_ci.setLayoutCount = 1;
6860 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006861
6862 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006863 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006864 ASSERT_VK_SUCCESS(err);
6865
Tobin Ehlise68360f2015-10-01 11:15:13 -06006866 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006867 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006868
6869 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006870 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6871 vp_state_ci.scissorCount = 1;
6872 vp_state_ci.pScissors = &sc;
6873 vp_state_ci.viewportCount = 1;
6874 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006875
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006876 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6877 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6878 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6879 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6880 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6881 rs_state_ci.depthClampEnable = VK_FALSE;
6882 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6883 rs_state_ci.depthBiasEnable = VK_FALSE;
6884
Tony Barboureb254902015-07-15 12:50:33 -06006885 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006886 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6887 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006888 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006889 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6890 gp_ci.layout = pipeline_layout;
6891 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006892
6893 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006894 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6895 pc_ci.initialDataSize = 0;
6896 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006897
6898 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006899 VkPipelineCache pipelineCache;
6900
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006901 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006902 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006903 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006904
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006905 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006906
Chia-I Wuf7458c52015-10-26 21:10:41 +08006907 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6908 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6909 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6910 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006911}
Tobin Ehlis912df022015-09-17 08:46:18 -06006912/*// TODO : This test should be good, but needs Tess support in compiler to run
6913TEST_F(VkLayerTest, InvalidPatchControlPoints)
6914{
6915 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006916 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006917
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006919 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6920primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006921
Tobin Ehlis912df022015-09-17 08:46:18 -06006922 ASSERT_NO_FATAL_FAILURE(InitState());
6923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006924
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006925 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006926 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006927 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006928
6929 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6930 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6931 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006932 ds_pool_ci.poolSizeCount = 1;
6933 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006934
6935 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006936 err = vkCreateDescriptorPool(m_device->device(),
6937VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006938 ASSERT_VK_SUCCESS(err);
6939
6940 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006941 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006942 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006943 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006944 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6945 dsl_binding.pImmutableSamplers = NULL;
6946
6947 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006948 ds_layout_ci.sType =
6949VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006950 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006951 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006952 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006953
6954 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006955 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6956&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006957 ASSERT_VK_SUCCESS(err);
6958
6959 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006960 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6961VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006962 ASSERT_VK_SUCCESS(err);
6963
6964 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006965 pipeline_layout_ci.sType =
6966VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006967 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006968 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006969 pipeline_layout_ci.pSetLayouts = &ds_layout;
6970
6971 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006972 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6973&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006974 ASSERT_VK_SUCCESS(err);
6975
6976 VkPipelineShaderStageCreateInfo shaderStages[3];
6977 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6978
Karl Schultz6addd812016-02-02 17:17:23 -07006979 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6980this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006981 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006982 VkShaderObj
6983tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6984this);
6985 VkShaderObj
6986te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6987this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006988
Karl Schultz6addd812016-02-02 17:17:23 -07006989 shaderStages[0].sType =
6990VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006991 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006992 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006993 shaderStages[1].sType =
6994VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006995 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006996 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006997 shaderStages[2].sType =
6998VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006999 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007000 shaderStages[2].shader = te.handle();
7001
7002 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007003 iaCI.sType =
7004VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007005 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007006
7007 VkPipelineTessellationStateCreateInfo tsCI = {};
7008 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7009 tsCI.patchControlPoints = 0; // This will cause an error
7010
7011 VkGraphicsPipelineCreateInfo gp_ci = {};
7012 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7013 gp_ci.pNext = NULL;
7014 gp_ci.stageCount = 3;
7015 gp_ci.pStages = shaderStages;
7016 gp_ci.pVertexInputState = NULL;
7017 gp_ci.pInputAssemblyState = &iaCI;
7018 gp_ci.pTessellationState = &tsCI;
7019 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007020 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007021 gp_ci.pMultisampleState = NULL;
7022 gp_ci.pDepthStencilState = NULL;
7023 gp_ci.pColorBlendState = NULL;
7024 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7025 gp_ci.layout = pipeline_layout;
7026 gp_ci.renderPass = renderPass();
7027
7028 VkPipelineCacheCreateInfo pc_ci = {};
7029 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7030 pc_ci.pNext = NULL;
7031 pc_ci.initialSize = 0;
7032 pc_ci.initialData = 0;
7033 pc_ci.maxSize = 0;
7034
7035 VkPipeline pipeline;
7036 VkPipelineCache pipelineCache;
7037
Karl Schultz6addd812016-02-02 17:17:23 -07007038 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7039&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007040 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007041 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7042&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007043
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007044 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007045
Chia-I Wuf7458c52015-10-26 21:10:41 +08007046 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7047 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7048 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7049 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007050}
7051*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06007052// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07007053TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007054 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007055
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7057 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007058
Tobin Ehlise68360f2015-10-01 11:15:13 -06007059 ASSERT_NO_FATAL_FAILURE(InitState());
7060 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007061
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007062 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007063 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7064 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007065
7066 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007067 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7068 ds_pool_ci.maxSets = 1;
7069 ds_pool_ci.poolSizeCount = 1;
7070 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007071
7072 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007073 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007074 ASSERT_VK_SUCCESS(err);
7075
7076 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007077 dsl_binding.binding = 0;
7078 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7079 dsl_binding.descriptorCount = 1;
7080 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007081
7082 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007083 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7084 ds_layout_ci.bindingCount = 1;
7085 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007086
7087 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007088 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007089 ASSERT_VK_SUCCESS(err);
7090
7091 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007092 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007093 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007094 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007095 alloc_info.descriptorPool = ds_pool;
7096 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007097 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007098 ASSERT_VK_SUCCESS(err);
7099
7100 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007101 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7102 pipeline_layout_ci.setLayoutCount = 1;
7103 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007104
7105 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007106 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007107 ASSERT_VK_SUCCESS(err);
7108
7109 VkViewport vp = {}; // Just need dummy vp to point to
7110
7111 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007112 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7113 vp_state_ci.scissorCount = 0;
7114 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7115 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007116
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007117 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7118 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7119 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7120 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7121 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7122 rs_state_ci.depthClampEnable = VK_FALSE;
7123 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7124 rs_state_ci.depthBiasEnable = VK_FALSE;
7125
Cody Northropeb3a6c12015-10-05 14:44:45 -06007126 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007127 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007129 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7130 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7131 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007132 shaderStages[0] = vs.GetStageCreateInfo();
7133 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007134
7135 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007136 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7137 gp_ci.stageCount = 2;
7138 gp_ci.pStages = shaderStages;
7139 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007140 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007141 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7142 gp_ci.layout = pipeline_layout;
7143 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007144
7145 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007146 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007147
7148 VkPipeline pipeline;
7149 VkPipelineCache pipelineCache;
7150
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007151 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007152 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007153 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007154
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007155 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007156
Chia-I Wuf7458c52015-10-26 21:10:41 +08007157 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7158 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7159 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7160 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007161}
Karl Schultz6addd812016-02-02 17:17:23 -07007162// Don't set viewport state in PSO. This is an error b/c we always need this
7163// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007164// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007165TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007166 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007167 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007168
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007170
Tobin Ehlise68360f2015-10-01 11:15:13 -06007171 ASSERT_NO_FATAL_FAILURE(InitState());
7172 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007173
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007174 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007175 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7176 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007177
7178 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007179 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7180 ds_pool_ci.maxSets = 1;
7181 ds_pool_ci.poolSizeCount = 1;
7182 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007183
7184 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007185 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007186 ASSERT_VK_SUCCESS(err);
7187
7188 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007189 dsl_binding.binding = 0;
7190 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7191 dsl_binding.descriptorCount = 1;
7192 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007193
7194 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007195 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7196 ds_layout_ci.bindingCount = 1;
7197 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007198
7199 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007200 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007201 ASSERT_VK_SUCCESS(err);
7202
7203 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007204 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007205 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007206 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007207 alloc_info.descriptorPool = ds_pool;
7208 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007209 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007210 ASSERT_VK_SUCCESS(err);
7211
7212 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007213 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7214 pipeline_layout_ci.setLayoutCount = 1;
7215 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007216
7217 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007218 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007219 ASSERT_VK_SUCCESS(err);
7220
7221 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7222 // Set scissor as dynamic to avoid second error
7223 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007224 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7225 dyn_state_ci.dynamicStateCount = 1;
7226 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007227
Cody Northropeb3a6c12015-10-05 14:44:45 -06007228 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007229 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007231 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7232 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7233 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007234 shaderStages[0] = vs.GetStageCreateInfo();
7235 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007236
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007237 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7238 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7239 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7240 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7241 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7242 rs_state_ci.depthClampEnable = VK_FALSE;
7243 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7244 rs_state_ci.depthBiasEnable = VK_FALSE;
7245
Tobin Ehlise68360f2015-10-01 11:15:13 -06007246 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007247 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7248 gp_ci.stageCount = 2;
7249 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007250 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007251 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7252 // should cause validation error
7253 gp_ci.pDynamicState = &dyn_state_ci;
7254 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7255 gp_ci.layout = pipeline_layout;
7256 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007257
7258 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007259 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007260
7261 VkPipeline pipeline;
7262 VkPipelineCache pipelineCache;
7263
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007264 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007265 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007266 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007267
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007268 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007269
Chia-I Wuf7458c52015-10-26 21:10:41 +08007270 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7271 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7272 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7273 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007274}
7275// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007276// Then run second test where dynamic scissor count doesn't match PSO scissor
7277// count
7278TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7279 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007280
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7282 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007283
Tobin Ehlise68360f2015-10-01 11:15:13 -06007284 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007285
7286 if (!m_device->phy().features().multiViewport) {
7287 printf("Device does not support multiple viewports/scissors; skipped.\n");
7288 return;
7289 }
7290
Tobin Ehlise68360f2015-10-01 11:15:13 -06007291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007292
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007293 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007294 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7295 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007296
7297 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007298 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7299 ds_pool_ci.maxSets = 1;
7300 ds_pool_ci.poolSizeCount = 1;
7301 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007302
7303 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007304 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007305 ASSERT_VK_SUCCESS(err);
7306
7307 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007308 dsl_binding.binding = 0;
7309 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7310 dsl_binding.descriptorCount = 1;
7311 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007312
7313 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007314 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7315 ds_layout_ci.bindingCount = 1;
7316 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007317
7318 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007319 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007320 ASSERT_VK_SUCCESS(err);
7321
7322 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007323 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007324 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007325 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007326 alloc_info.descriptorPool = ds_pool;
7327 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007328 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007329 ASSERT_VK_SUCCESS(err);
7330
7331 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007332 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7333 pipeline_layout_ci.setLayoutCount = 1;
7334 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007335
7336 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007337 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007338 ASSERT_VK_SUCCESS(err);
7339
7340 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007341 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7342 vp_state_ci.viewportCount = 1;
7343 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7344 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007345 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007346
7347 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7348 // Set scissor as dynamic to avoid that error
7349 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007350 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7351 dyn_state_ci.dynamicStateCount = 1;
7352 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007353
Cody Northropeb3a6c12015-10-05 14:44:45 -06007354 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007355 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007356
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007357 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7358 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7359 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007360 shaderStages[0] = vs.GetStageCreateInfo();
7361 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007362
Cody Northropf6622dc2015-10-06 10:33:21 -06007363 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7364 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7365 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007366 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007367 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007368 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007369 vi_ci.pVertexAttributeDescriptions = nullptr;
7370
7371 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7372 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7373 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7374
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007375 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007376 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007377 rs_ci.pNext = nullptr;
7378
Mark Youngc89c6312016-03-31 16:03:20 -06007379 VkPipelineColorBlendAttachmentState att = {};
7380 att.blendEnable = VK_FALSE;
7381 att.colorWriteMask = 0xf;
7382
Cody Northropf6622dc2015-10-06 10:33:21 -06007383 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7384 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7385 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007386 cb_ci.attachmentCount = 1;
7387 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007388
Tobin Ehlise68360f2015-10-01 11:15:13 -06007389 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007390 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7391 gp_ci.stageCount = 2;
7392 gp_ci.pStages = shaderStages;
7393 gp_ci.pVertexInputState = &vi_ci;
7394 gp_ci.pInputAssemblyState = &ia_ci;
7395 gp_ci.pViewportState = &vp_state_ci;
7396 gp_ci.pRasterizationState = &rs_ci;
7397 gp_ci.pColorBlendState = &cb_ci;
7398 gp_ci.pDynamicState = &dyn_state_ci;
7399 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7400 gp_ci.layout = pipeline_layout;
7401 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007402
7403 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007404 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007405
7406 VkPipeline pipeline;
7407 VkPipelineCache pipelineCache;
7408
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007409 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007410 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007411 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007412
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007413 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007414
Tobin Ehlisd332f282015-10-02 11:00:56 -06007415 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007416 // First need to successfully create the PSO from above by setting
7417 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007418 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 -07007419
7420 VkViewport vp = {}; // Just need dummy vp to point to
7421 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007422 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007423 ASSERT_VK_SUCCESS(err);
7424 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007425 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007426 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007427 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007428 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007429 Draw(1, 0, 0, 0);
7430
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007431 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007432
7433 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7434 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7435 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7436 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007437 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007438}
7439// Create PSO w/o non-zero scissorCount but no scissor data
7440// Then run second test where dynamic viewportCount doesn't match PSO
7441// viewportCount
7442TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7443 VkResult err;
7444
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007445 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 -07007446
7447 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007448
7449 if (!m_device->phy().features().multiViewport) {
7450 printf("Device does not support multiple viewports/scissors; skipped.\n");
7451 return;
7452 }
7453
Karl Schultz6addd812016-02-02 17:17:23 -07007454 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7455
7456 VkDescriptorPoolSize ds_type_count = {};
7457 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7458 ds_type_count.descriptorCount = 1;
7459
7460 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7461 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7462 ds_pool_ci.maxSets = 1;
7463 ds_pool_ci.poolSizeCount = 1;
7464 ds_pool_ci.pPoolSizes = &ds_type_count;
7465
7466 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007467 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007468 ASSERT_VK_SUCCESS(err);
7469
7470 VkDescriptorSetLayoutBinding dsl_binding = {};
7471 dsl_binding.binding = 0;
7472 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7473 dsl_binding.descriptorCount = 1;
7474 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7475
7476 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7477 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7478 ds_layout_ci.bindingCount = 1;
7479 ds_layout_ci.pBindings = &dsl_binding;
7480
7481 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007482 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007483 ASSERT_VK_SUCCESS(err);
7484
7485 VkDescriptorSet descriptorSet;
7486 VkDescriptorSetAllocateInfo alloc_info = {};
7487 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7488 alloc_info.descriptorSetCount = 1;
7489 alloc_info.descriptorPool = ds_pool;
7490 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007491 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007492 ASSERT_VK_SUCCESS(err);
7493
7494 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7495 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7496 pipeline_layout_ci.setLayoutCount = 1;
7497 pipeline_layout_ci.pSetLayouts = &ds_layout;
7498
7499 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007500 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007501 ASSERT_VK_SUCCESS(err);
7502
7503 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7504 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7505 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007506 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007507 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007508 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007509
7510 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7511 // Set scissor as dynamic to avoid that error
7512 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7513 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7514 dyn_state_ci.dynamicStateCount = 1;
7515 dyn_state_ci.pDynamicStates = &vp_state;
7516
7517 VkPipelineShaderStageCreateInfo shaderStages[2];
7518 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7519
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007520 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7521 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7522 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007523 shaderStages[0] = vs.GetStageCreateInfo();
7524 shaderStages[1] = fs.GetStageCreateInfo();
7525
7526 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7527 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7528 vi_ci.pNext = nullptr;
7529 vi_ci.vertexBindingDescriptionCount = 0;
7530 vi_ci.pVertexBindingDescriptions = nullptr;
7531 vi_ci.vertexAttributeDescriptionCount = 0;
7532 vi_ci.pVertexAttributeDescriptions = nullptr;
7533
7534 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7535 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7536 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7537
7538 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7539 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7540 rs_ci.pNext = nullptr;
7541
Mark Youngc89c6312016-03-31 16:03:20 -06007542 VkPipelineColorBlendAttachmentState att = {};
7543 att.blendEnable = VK_FALSE;
7544 att.colorWriteMask = 0xf;
7545
Karl Schultz6addd812016-02-02 17:17:23 -07007546 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7547 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7548 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007549 cb_ci.attachmentCount = 1;
7550 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007551
7552 VkGraphicsPipelineCreateInfo gp_ci = {};
7553 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7554 gp_ci.stageCount = 2;
7555 gp_ci.pStages = shaderStages;
7556 gp_ci.pVertexInputState = &vi_ci;
7557 gp_ci.pInputAssemblyState = &ia_ci;
7558 gp_ci.pViewportState = &vp_state_ci;
7559 gp_ci.pRasterizationState = &rs_ci;
7560 gp_ci.pColorBlendState = &cb_ci;
7561 gp_ci.pDynamicState = &dyn_state_ci;
7562 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7563 gp_ci.layout = pipeline_layout;
7564 gp_ci.renderPass = renderPass();
7565
7566 VkPipelineCacheCreateInfo pc_ci = {};
7567 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7568
7569 VkPipeline pipeline;
7570 VkPipelineCache pipelineCache;
7571
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007572 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007573 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007574 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007575
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007576 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007577
7578 // Now hit second fail case where we set scissor w/ different count than PSO
7579 // First need to successfully create the PSO from above by setting
7580 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007581 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 -06007582
Tobin Ehlisd332f282015-10-02 11:00:56 -06007583 VkRect2D sc = {}; // Just need dummy vp to point to
7584 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007585 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007586 ASSERT_VK_SUCCESS(err);
7587 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007588 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007589 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007590 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007591 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007592 Draw(1, 0, 0, 0);
7593
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007594 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007595
Chia-I Wuf7458c52015-10-26 21:10:41 +08007596 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7597 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7598 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7599 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007600 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007601}
7602
Mark Young7394fdd2016-03-31 14:56:43 -06007603TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7604 VkResult err;
7605
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007607
7608 ASSERT_NO_FATAL_FAILURE(InitState());
7609 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7610
7611 VkDescriptorPoolSize ds_type_count = {};
7612 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7613 ds_type_count.descriptorCount = 1;
7614
7615 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7616 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7617 ds_pool_ci.maxSets = 1;
7618 ds_pool_ci.poolSizeCount = 1;
7619 ds_pool_ci.pPoolSizes = &ds_type_count;
7620
7621 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007622 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007623 ASSERT_VK_SUCCESS(err);
7624
7625 VkDescriptorSetLayoutBinding dsl_binding = {};
7626 dsl_binding.binding = 0;
7627 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7628 dsl_binding.descriptorCount = 1;
7629 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7630
7631 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7632 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7633 ds_layout_ci.bindingCount = 1;
7634 ds_layout_ci.pBindings = &dsl_binding;
7635
7636 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007637 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007638 ASSERT_VK_SUCCESS(err);
7639
7640 VkDescriptorSet descriptorSet;
7641 VkDescriptorSetAllocateInfo alloc_info = {};
7642 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7643 alloc_info.descriptorSetCount = 1;
7644 alloc_info.descriptorPool = ds_pool;
7645 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007646 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007647 ASSERT_VK_SUCCESS(err);
7648
7649 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7650 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7651 pipeline_layout_ci.setLayoutCount = 1;
7652 pipeline_layout_ci.pSetLayouts = &ds_layout;
7653
7654 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007655 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007656 ASSERT_VK_SUCCESS(err);
7657
7658 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7659 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7660 vp_state_ci.scissorCount = 1;
7661 vp_state_ci.pScissors = NULL;
7662 vp_state_ci.viewportCount = 1;
7663 vp_state_ci.pViewports = NULL;
7664
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007665 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007666 // Set scissor as dynamic to avoid that error
7667 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7668 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7669 dyn_state_ci.dynamicStateCount = 2;
7670 dyn_state_ci.pDynamicStates = dynamic_states;
7671
7672 VkPipelineShaderStageCreateInfo shaderStages[2];
7673 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7674
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007675 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7676 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007677 this); // TODO - We shouldn't need a fragment shader
7678 // but add it to be able to run on more devices
7679 shaderStages[0] = vs.GetStageCreateInfo();
7680 shaderStages[1] = fs.GetStageCreateInfo();
7681
7682 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7683 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7684 vi_ci.pNext = nullptr;
7685 vi_ci.vertexBindingDescriptionCount = 0;
7686 vi_ci.pVertexBindingDescriptions = nullptr;
7687 vi_ci.vertexAttributeDescriptionCount = 0;
7688 vi_ci.pVertexAttributeDescriptions = nullptr;
7689
7690 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7691 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7692 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7693
7694 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7695 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7696 rs_ci.pNext = nullptr;
7697
Mark Young47107952016-05-02 15:59:55 -06007698 // Check too low (line width of -1.0f).
7699 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007700
7701 VkPipelineColorBlendAttachmentState att = {};
7702 att.blendEnable = VK_FALSE;
7703 att.colorWriteMask = 0xf;
7704
7705 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7706 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7707 cb_ci.pNext = nullptr;
7708 cb_ci.attachmentCount = 1;
7709 cb_ci.pAttachments = &att;
7710
7711 VkGraphicsPipelineCreateInfo gp_ci = {};
7712 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7713 gp_ci.stageCount = 2;
7714 gp_ci.pStages = shaderStages;
7715 gp_ci.pVertexInputState = &vi_ci;
7716 gp_ci.pInputAssemblyState = &ia_ci;
7717 gp_ci.pViewportState = &vp_state_ci;
7718 gp_ci.pRasterizationState = &rs_ci;
7719 gp_ci.pColorBlendState = &cb_ci;
7720 gp_ci.pDynamicState = &dyn_state_ci;
7721 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7722 gp_ci.layout = pipeline_layout;
7723 gp_ci.renderPass = renderPass();
7724
7725 VkPipelineCacheCreateInfo pc_ci = {};
7726 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7727
7728 VkPipeline pipeline;
7729 VkPipelineCache pipelineCache;
7730
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007731 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007732 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007733 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007734
7735 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007736 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007737
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007739
7740 // Check too high (line width of 65536.0f).
7741 rs_ci.lineWidth = 65536.0f;
7742
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007743 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007744 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007745 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007746
7747 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007748 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007749
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007751
7752 dyn_state_ci.dynamicStateCount = 3;
7753
7754 rs_ci.lineWidth = 1.0f;
7755
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007756 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007757 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007758 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007759 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007760 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007761
7762 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007763 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007764 m_errorMonitor->VerifyFound();
7765
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007767
7768 // Check too high with dynamic setting.
7769 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7770 m_errorMonitor->VerifyFound();
7771 EndCommandBuffer();
7772
7773 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7774 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7775 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7776 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007777 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007778}
7779
Karl Schultz6addd812016-02-02 17:17:23 -07007780TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007781 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7783 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007784
7785 ASSERT_NO_FATAL_FAILURE(InitState());
7786 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007787
Tony Barbourfe3351b2015-07-28 10:17:20 -06007788 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007789 // Don't care about RenderPass handle b/c error should be flagged before
7790 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007791 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007792
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007793 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007794}
7795
Karl Schultz6addd812016-02-02 17:17:23 -07007796TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007797 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7799 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007800
7801 ASSERT_NO_FATAL_FAILURE(InitState());
7802 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007803
Tony Barbourfe3351b2015-07-28 10:17:20 -06007804 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007805 // Just create a dummy Renderpass that's non-NULL so we can get to the
7806 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007807 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007808
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007809 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007810}
7811
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007812TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7813 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7814 "the number of renderPass attachments that use loadOp"
7815 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7816
7817 ASSERT_NO_FATAL_FAILURE(InitState());
7818 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7819
7820 // Create a renderPass with a single attachment that uses loadOp CLEAR
7821 VkAttachmentReference attach = {};
7822 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7823 VkSubpassDescription subpass = {};
7824 subpass.inputAttachmentCount = 1;
7825 subpass.pInputAttachments = &attach;
7826 VkRenderPassCreateInfo rpci = {};
7827 rpci.subpassCount = 1;
7828 rpci.pSubpasses = &subpass;
7829 rpci.attachmentCount = 1;
7830 VkAttachmentDescription attach_desc = {};
7831 attach_desc.format = VK_FORMAT_UNDEFINED;
7832 // Set loadOp to CLEAR
7833 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7834 rpci.pAttachments = &attach_desc;
7835 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7836 VkRenderPass rp;
7837 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7838
7839 VkCommandBufferInheritanceInfo hinfo = {};
7840 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7841 hinfo.renderPass = VK_NULL_HANDLE;
7842 hinfo.subpass = 0;
7843 hinfo.framebuffer = VK_NULL_HANDLE;
7844 hinfo.occlusionQueryEnable = VK_FALSE;
7845 hinfo.queryFlags = 0;
7846 hinfo.pipelineStatistics = 0;
7847 VkCommandBufferBeginInfo info = {};
7848 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7849 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7850 info.pInheritanceInfo = &hinfo;
7851
7852 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7853 VkRenderPassBeginInfo rp_begin = {};
7854 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7855 rp_begin.pNext = NULL;
7856 rp_begin.renderPass = renderPass();
7857 rp_begin.framebuffer = framebuffer();
7858 rp_begin.clearValueCount = 0; // Should be 1
7859
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7861 "there must be at least 1 entries in "
7862 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007863
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007864 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007865
7866 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007867
7868 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007869}
7870
Cody Northrop3bb4d962016-05-09 16:15:57 -06007871TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7872
7873 TEST_DESCRIPTION("End a command buffer with an active render pass");
7874
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7876 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007877
7878 ASSERT_NO_FATAL_FAILURE(InitState());
7879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7880
7881 // The framework's BeginCommandBuffer calls CreateRenderPass
7882 BeginCommandBuffer();
7883
7884 // Call directly into vkEndCommandBuffer instead of the
7885 // the framework's EndCommandBuffer, which inserts a
7886 // vkEndRenderPass
7887 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7888
7889 m_errorMonitor->VerifyFound();
7890
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007891 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7892 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007893}
7894
Karl Schultz6addd812016-02-02 17:17:23 -07007895TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007896 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7898 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007899
7900 ASSERT_NO_FATAL_FAILURE(InitState());
7901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007902
7903 // Renderpass is started here
7904 BeginCommandBuffer();
7905
7906 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007907 vk_testing::Buffer dstBuffer;
7908 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007909
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007910 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007911
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007912 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007913}
7914
Karl Schultz6addd812016-02-02 17:17:23 -07007915TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007916 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7918 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007919
7920 ASSERT_NO_FATAL_FAILURE(InitState());
7921 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007922
7923 // Renderpass is started here
7924 BeginCommandBuffer();
7925
7926 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007927 vk_testing::Buffer dstBuffer;
7928 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007929
Karl Schultz6addd812016-02-02 17:17:23 -07007930 VkDeviceSize dstOffset = 0;
7931 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007932 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007934 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007935
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007936 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007937}
7938
Karl Schultz6addd812016-02-02 17:17:23 -07007939TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007940 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7942 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007943
7944 ASSERT_NO_FATAL_FAILURE(InitState());
7945 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007946
7947 // Renderpass is started here
7948 BeginCommandBuffer();
7949
Michael Lentine0a369f62016-02-03 16:51:46 -06007950 VkClearColorValue clear_color;
7951 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007952 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7953 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7954 const int32_t tex_width = 32;
7955 const int32_t tex_height = 32;
7956 VkImageCreateInfo image_create_info = {};
7957 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7958 image_create_info.pNext = NULL;
7959 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7960 image_create_info.format = tex_format;
7961 image_create_info.extent.width = tex_width;
7962 image_create_info.extent.height = tex_height;
7963 image_create_info.extent.depth = 1;
7964 image_create_info.mipLevels = 1;
7965 image_create_info.arrayLayers = 1;
7966 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7967 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7968 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007969
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007970 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007971 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007972
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007973 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007974
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007975 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 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, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007981 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7983 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007984
7985 ASSERT_NO_FATAL_FAILURE(InitState());
7986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007987
7988 // Renderpass is started here
7989 BeginCommandBuffer();
7990
7991 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007992 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007993 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7994 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7995 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7996 image_create_info.extent.width = 64;
7997 image_create_info.extent.height = 64;
7998 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7999 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008000
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008001 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008002 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008004 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008005
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008006 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8007 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008008
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008009 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008010}
8011
Karl Schultz6addd812016-02-02 17:17:23 -07008012TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008013 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008014 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008015
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8017 "must be issued inside an active "
8018 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008019
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008020 ASSERT_NO_FATAL_FAILURE(InitState());
8021 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008022
8023 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008024 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008025 ASSERT_VK_SUCCESS(err);
8026
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008027 VkClearAttachment color_attachment;
8028 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8029 color_attachment.clearValue.color.float32[0] = 0;
8030 color_attachment.clearValue.color.float32[1] = 0;
8031 color_attachment.clearValue.color.float32[2] = 0;
8032 color_attachment.clearValue.color.float32[3] = 0;
8033 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008034 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008035 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008036
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008037 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008038}
8039
Chris Forbes3b97e932016-09-07 11:29:24 +12008040TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8041 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8042 "called too many times in a renderpass instance");
8043
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8045 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008046
8047 ASSERT_NO_FATAL_FAILURE(InitState());
8048 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8049
8050 BeginCommandBuffer();
8051
8052 // error here.
8053 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8054 m_errorMonitor->VerifyFound();
8055
8056 EndCommandBuffer();
8057}
8058
Chris Forbes6d624702016-09-07 13:57:05 +12008059TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8060 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8061 "called before the final subpass has been reached");
8062
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8064 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008065
8066 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008067 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8068 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008069
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008070 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008071
8072 VkRenderPass rp;
8073 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8074 ASSERT_VK_SUCCESS(err);
8075
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008076 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008077
8078 VkFramebuffer fb;
8079 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8080 ASSERT_VK_SUCCESS(err);
8081
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008082 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008083
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008084 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 +12008085
8086 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8087
8088 // Error here.
8089 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8090 m_errorMonitor->VerifyFound();
8091
8092 // Clean up.
8093 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8094 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8095}
8096
Karl Schultz9e66a292016-04-21 15:57:51 -06008097TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8098 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8100 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008101
8102 ASSERT_NO_FATAL_FAILURE(InitState());
8103 BeginCommandBuffer();
8104
8105 VkBufferMemoryBarrier buf_barrier = {};
8106 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8107 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8108 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8109 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8110 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8111 buf_barrier.buffer = VK_NULL_HANDLE;
8112 buf_barrier.offset = 0;
8113 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008114 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8115 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008116
8117 m_errorMonitor->VerifyFound();
8118}
8119
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008120TEST_F(VkLayerTest, InvalidBarriers) {
8121 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8122
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008124
8125 ASSERT_NO_FATAL_FAILURE(InitState());
8126 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8127
8128 VkMemoryBarrier mem_barrier = {};
8129 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8130 mem_barrier.pNext = NULL;
8131 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8132 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8133 BeginCommandBuffer();
8134 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008135 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008136 &mem_barrier, 0, nullptr, 0, nullptr);
8137 m_errorMonitor->VerifyFound();
8138
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008140 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008141 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 -06008142 ASSERT_TRUE(image.initialized());
8143 VkImageMemoryBarrier img_barrier = {};
8144 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8145 img_barrier.pNext = NULL;
8146 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8147 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8148 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8149 // New layout can't be UNDEFINED
8150 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8151 img_barrier.image = image.handle();
8152 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8153 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8154 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8155 img_barrier.subresourceRange.baseArrayLayer = 0;
8156 img_barrier.subresourceRange.baseMipLevel = 0;
8157 img_barrier.subresourceRange.layerCount = 1;
8158 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008159 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8160 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008161 m_errorMonitor->VerifyFound();
8162 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8163
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8165 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008166 // baseArrayLayer + layerCount must be <= image's arrayLayers
8167 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008168 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8169 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008170 m_errorMonitor->VerifyFound();
8171 img_barrier.subresourceRange.baseArrayLayer = 0;
8172
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008174 // baseMipLevel + levelCount must be <= image's mipLevels
8175 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008176 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8177 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008178 m_errorMonitor->VerifyFound();
8179 img_barrier.subresourceRange.baseMipLevel = 0;
8180
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008181 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 -06008182 vk_testing::Buffer buffer;
8183 buffer.init(*m_device, 256);
8184 VkBufferMemoryBarrier buf_barrier = {};
8185 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8186 buf_barrier.pNext = NULL;
8187 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8188 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8189 buf_barrier.buffer = buffer.handle();
8190 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8191 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8192 buf_barrier.offset = 0;
8193 buf_barrier.size = VK_WHOLE_SIZE;
8194 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008195 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8196 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008197 m_errorMonitor->VerifyFound();
8198 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8199
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008201 buf_barrier.offset = 257;
8202 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008203 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8204 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008205 m_errorMonitor->VerifyFound();
8206 buf_barrier.offset = 0;
8207
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008209 buf_barrier.size = 257;
8210 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008211 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8212 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008213 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008214
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008215 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008216 m_errorMonitor->SetDesiredFailureMsg(
8217 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8218 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8219 m_errorMonitor->SetDesiredFailureMsg(
8220 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8221 "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 -06008222 VkDepthStencilObj ds_image(m_device);
8223 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8224 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008225 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8226 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008227 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008228 // Use of COLOR aspect on DS image is error
8229 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008230 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8231 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008232 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008233 // Now test depth-only
8234 VkFormatProperties format_props;
8235
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008236 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8237 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8239 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8241 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008242 VkDepthStencilObj d_image(m_device);
8243 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8244 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008245 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008246 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008247 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008248 // Use of COLOR aspect on depth image is error
8249 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008250 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8251 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008252 m_errorMonitor->VerifyFound();
8253 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008254 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8255 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008256 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8258 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008259 VkDepthStencilObj s_image(m_device);
8260 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8261 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008262 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008263 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008264 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008265 // Use of COLOR aspect on depth image is error
8266 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008267 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8268 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008269 m_errorMonitor->VerifyFound();
8270 }
8271 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8273 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8275 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008276 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008277 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 -06008278 ASSERT_TRUE(c_image.initialized());
8279 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8280 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8281 img_barrier.image = c_image.handle();
8282 // Set aspect to depth (non-color)
8283 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008284 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8285 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008286 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008287}
8288
Tony Barbour18ba25c2016-09-29 13:42:40 -06008289TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8290 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8291
8292 m_errorMonitor->SetDesiredFailureMsg(
8293 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8294 "must have required access bit");
8295 ASSERT_NO_FATAL_FAILURE(InitState());
8296 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008297 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 -06008298 ASSERT_TRUE(image.initialized());
8299
8300 VkImageMemoryBarrier barrier = {};
8301 VkImageSubresourceRange range;
8302 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8303 barrier.srcAccessMask = 0;
8304 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8305 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8306 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8307 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8308 barrier.image = image.handle();
8309 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8310 range.baseMipLevel = 0;
8311 range.levelCount = 1;
8312 range.baseArrayLayer = 0;
8313 range.layerCount = 1;
8314 barrier.subresourceRange = range;
8315 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8316 cmdbuf.BeginCommandBuffer();
8317 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8318 &barrier);
8319 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8320 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8321 barrier.srcAccessMask = 0;
8322 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8323 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8324 &barrier);
8325
8326 m_errorMonitor->VerifyFound();
8327}
8328
Karl Schultz6addd812016-02-02 17:17:23 -07008329TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008330 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008331 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008332
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008334
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008335 ASSERT_NO_FATAL_FAILURE(InitState());
8336 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008337 uint32_t qfi = 0;
8338 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008339 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 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008344
8345 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008346 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008347 ASSERT_VK_SUCCESS(err);
8348
8349 BeginCommandBuffer();
8350 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008351 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8352 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008353 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008354 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008355
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008356 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008357
Chia-I Wuf7458c52015-10-26 21:10:41 +08008358 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008359}
8360
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008361TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8362 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8364 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8365 "of the indices specified when the device was created, via the "
8366 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008367
8368 ASSERT_NO_FATAL_FAILURE(InitState());
8369 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8370 VkBufferCreateInfo buffCI = {};
8371 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8372 buffCI.size = 1024;
8373 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8374 buffCI.queueFamilyIndexCount = 1;
8375 // Introduce failure by specifying invalid queue_family_index
8376 uint32_t qfi = 777;
8377 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008378 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008379
8380 VkBuffer ib;
8381 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8382
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008383 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008384 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008385}
8386
Karl Schultz6addd812016-02-02 17:17:23 -07008387TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008388TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008389 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008390
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008391 ASSERT_NO_FATAL_FAILURE(InitState());
8392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008393
Chris Forbesf29a84f2016-10-06 18:39:28 +13008394 // An empty primary command buffer
8395 VkCommandBufferObj cb(m_device, m_commandPool);
8396 cb.BeginCommandBuffer();
8397 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008398
Chris Forbesf29a84f2016-10-06 18:39:28 +13008399 m_commandBuffer->BeginCommandBuffer();
8400 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8401 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008402
Chris Forbesf29a84f2016-10-06 18:39:28 +13008403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8404 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008405 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008406}
8407
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008408TEST_F(VkLayerTest, DSUsageBitsErrors) {
8409 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8410 "that do not have correct usage bits sets.");
8411 VkResult err;
8412
8413 ASSERT_NO_FATAL_FAILURE(InitState());
8414 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8415 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8416 ds_type_count[i].type = VkDescriptorType(i);
8417 ds_type_count[i].descriptorCount = 1;
8418 }
8419 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8420 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8421 ds_pool_ci.pNext = NULL;
8422 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8423 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8424 ds_pool_ci.pPoolSizes = ds_type_count;
8425
8426 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008427 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008428 ASSERT_VK_SUCCESS(err);
8429
8430 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008431 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008432 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8433 dsl_binding[i].binding = 0;
8434 dsl_binding[i].descriptorType = VkDescriptorType(i);
8435 dsl_binding[i].descriptorCount = 1;
8436 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8437 dsl_binding[i].pImmutableSamplers = NULL;
8438 }
8439
8440 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8441 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8442 ds_layout_ci.pNext = NULL;
8443 ds_layout_ci.bindingCount = 1;
8444 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8445 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8446 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008447 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008448 ASSERT_VK_SUCCESS(err);
8449 }
8450 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8451 VkDescriptorSetAllocateInfo alloc_info = {};
8452 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8453 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8454 alloc_info.descriptorPool = ds_pool;
8455 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008456 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008457 ASSERT_VK_SUCCESS(err);
8458
8459 // Create a buffer & bufferView to be used for invalid updates
8460 VkBufferCreateInfo buff_ci = {};
8461 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8462 // This usage is not valid for any descriptor type
8463 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8464 buff_ci.size = 256;
8465 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8466 VkBuffer buffer;
8467 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8468 ASSERT_VK_SUCCESS(err);
8469
8470 VkBufferViewCreateInfo buff_view_ci = {};
8471 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8472 buff_view_ci.buffer = buffer;
8473 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8474 buff_view_ci.range = VK_WHOLE_SIZE;
8475 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008476 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008477 ASSERT_VK_SUCCESS(err);
8478
8479 // Create an image to be used for invalid updates
8480 VkImageCreateInfo image_ci = {};
8481 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8482 image_ci.imageType = VK_IMAGE_TYPE_2D;
8483 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8484 image_ci.extent.width = 64;
8485 image_ci.extent.height = 64;
8486 image_ci.extent.depth = 1;
8487 image_ci.mipLevels = 1;
8488 image_ci.arrayLayers = 1;
8489 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8490 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8491 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8492 // This usage is not valid for any descriptor type
8493 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8494 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8495 VkImage image;
8496 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8497 ASSERT_VK_SUCCESS(err);
8498 // Bind memory to image
8499 VkMemoryRequirements mem_reqs;
8500 VkDeviceMemory image_mem;
8501 bool pass;
8502 VkMemoryAllocateInfo mem_alloc = {};
8503 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8504 mem_alloc.pNext = NULL;
8505 mem_alloc.allocationSize = 0;
8506 mem_alloc.memoryTypeIndex = 0;
8507 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8508 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008509 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008510 ASSERT_TRUE(pass);
8511 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8512 ASSERT_VK_SUCCESS(err);
8513 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8514 ASSERT_VK_SUCCESS(err);
8515 // Now create view for image
8516 VkImageViewCreateInfo image_view_ci = {};
8517 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8518 image_view_ci.image = image;
8519 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8520 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8521 image_view_ci.subresourceRange.layerCount = 1;
8522 image_view_ci.subresourceRange.baseArrayLayer = 0;
8523 image_view_ci.subresourceRange.levelCount = 1;
8524 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8525 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008526 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008527 ASSERT_VK_SUCCESS(err);
8528
8529 VkDescriptorBufferInfo buff_info = {};
8530 buff_info.buffer = buffer;
8531 VkDescriptorImageInfo img_info = {};
8532 img_info.imageView = image_view;
8533 VkWriteDescriptorSet descriptor_write = {};
8534 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8535 descriptor_write.dstBinding = 0;
8536 descriptor_write.descriptorCount = 1;
8537 descriptor_write.pTexelBufferView = &buff_view;
8538 descriptor_write.pBufferInfo = &buff_info;
8539 descriptor_write.pImageInfo = &img_info;
8540
8541 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008542 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8543 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8544 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8545 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8546 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8547 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8548 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8549 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8550 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8551 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8552 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008553 // Start loop at 1 as SAMPLER desc type has no usage bit error
8554 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8555 descriptor_write.descriptorType = VkDescriptorType(i);
8556 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008558
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008559 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008560
8561 m_errorMonitor->VerifyFound();
8562 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8563 }
8564 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8565 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008566 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008567 vkDestroyImageView(m_device->device(), image_view, NULL);
8568 vkDestroyBuffer(m_device->device(), buffer, NULL);
8569 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008570 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008571 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8572}
8573
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008574TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008575 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8576 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8577 "1. offset value greater than buffer size\n"
8578 "2. range value of 0\n"
8579 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008580 VkResult err;
8581
8582 ASSERT_NO_FATAL_FAILURE(InitState());
8583 VkDescriptorPoolSize ds_type_count = {};
8584 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8585 ds_type_count.descriptorCount = 1;
8586
8587 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8588 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8589 ds_pool_ci.pNext = NULL;
8590 ds_pool_ci.maxSets = 1;
8591 ds_pool_ci.poolSizeCount = 1;
8592 ds_pool_ci.pPoolSizes = &ds_type_count;
8593
8594 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008595 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008596 ASSERT_VK_SUCCESS(err);
8597
8598 // Create layout with single uniform buffer descriptor
8599 VkDescriptorSetLayoutBinding dsl_binding = {};
8600 dsl_binding.binding = 0;
8601 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8602 dsl_binding.descriptorCount = 1;
8603 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8604 dsl_binding.pImmutableSamplers = NULL;
8605
8606 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8607 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8608 ds_layout_ci.pNext = NULL;
8609 ds_layout_ci.bindingCount = 1;
8610 ds_layout_ci.pBindings = &dsl_binding;
8611 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008612 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008613 ASSERT_VK_SUCCESS(err);
8614
8615 VkDescriptorSet descriptor_set = {};
8616 VkDescriptorSetAllocateInfo alloc_info = {};
8617 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8618 alloc_info.descriptorSetCount = 1;
8619 alloc_info.descriptorPool = ds_pool;
8620 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008621 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008622 ASSERT_VK_SUCCESS(err);
8623
8624 // Create a buffer to be used for invalid updates
8625 VkBufferCreateInfo buff_ci = {};
8626 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8627 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8628 buff_ci.size = 256;
8629 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8630 VkBuffer buffer;
8631 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8632 ASSERT_VK_SUCCESS(err);
8633 // Have to bind memory to buffer before descriptor update
8634 VkMemoryAllocateInfo mem_alloc = {};
8635 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8636 mem_alloc.pNext = NULL;
8637 mem_alloc.allocationSize = 256;
8638 mem_alloc.memoryTypeIndex = 0;
8639
8640 VkMemoryRequirements mem_reqs;
8641 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008642 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008643 if (!pass) {
8644 vkDestroyBuffer(m_device->device(), buffer, NULL);
8645 return;
8646 }
8647
8648 VkDeviceMemory mem;
8649 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8650 ASSERT_VK_SUCCESS(err);
8651 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8652 ASSERT_VK_SUCCESS(err);
8653
8654 VkDescriptorBufferInfo buff_info = {};
8655 buff_info.buffer = buffer;
8656 // First make offset 1 larger than buffer size
8657 buff_info.offset = 257;
8658 buff_info.range = VK_WHOLE_SIZE;
8659 VkWriteDescriptorSet descriptor_write = {};
8660 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8661 descriptor_write.dstBinding = 0;
8662 descriptor_write.descriptorCount = 1;
8663 descriptor_write.pTexelBufferView = nullptr;
8664 descriptor_write.pBufferInfo = &buff_info;
8665 descriptor_write.pImageInfo = nullptr;
8666
8667 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8668 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008670
8671 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8672
8673 m_errorMonitor->VerifyFound();
8674 // Now cause error due to range of 0
8675 buff_info.offset = 0;
8676 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8678 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008679
8680 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8681
8682 m_errorMonitor->VerifyFound();
8683 // Now cause error due to range exceeding buffer size - offset
8684 buff_info.offset = 128;
8685 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008686 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 -06008687
8688 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8689
8690 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008691 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008692 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8693 vkDestroyBuffer(m_device->device(), buffer, NULL);
8694 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8695 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8696}
8697
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008698TEST_F(VkLayerTest, DSAspectBitsErrors) {
8699 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8700 // are set, but could expand this test to hit more cases.
8701 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8702 "that do not have correct aspect bits sets.");
8703 VkResult err;
8704
8705 ASSERT_NO_FATAL_FAILURE(InitState());
8706 VkDescriptorPoolSize ds_type_count = {};
8707 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8708 ds_type_count.descriptorCount = 1;
8709
8710 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8711 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8712 ds_pool_ci.pNext = NULL;
8713 ds_pool_ci.maxSets = 5;
8714 ds_pool_ci.poolSizeCount = 1;
8715 ds_pool_ci.pPoolSizes = &ds_type_count;
8716
8717 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008718 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008719 ASSERT_VK_SUCCESS(err);
8720
8721 VkDescriptorSetLayoutBinding dsl_binding = {};
8722 dsl_binding.binding = 0;
8723 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8724 dsl_binding.descriptorCount = 1;
8725 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8726 dsl_binding.pImmutableSamplers = NULL;
8727
8728 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8729 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8730 ds_layout_ci.pNext = NULL;
8731 ds_layout_ci.bindingCount = 1;
8732 ds_layout_ci.pBindings = &dsl_binding;
8733 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008734 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008735 ASSERT_VK_SUCCESS(err);
8736
8737 VkDescriptorSet descriptor_set = {};
8738 VkDescriptorSetAllocateInfo alloc_info = {};
8739 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8740 alloc_info.descriptorSetCount = 1;
8741 alloc_info.descriptorPool = ds_pool;
8742 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008743 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008744 ASSERT_VK_SUCCESS(err);
8745
8746 // Create an image to be used for invalid updates
8747 VkImageCreateInfo image_ci = {};
8748 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8749 image_ci.imageType = VK_IMAGE_TYPE_2D;
8750 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8751 image_ci.extent.width = 64;
8752 image_ci.extent.height = 64;
8753 image_ci.extent.depth = 1;
8754 image_ci.mipLevels = 1;
8755 image_ci.arrayLayers = 1;
8756 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8757 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8758 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8759 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8760 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8761 VkImage image;
8762 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8763 ASSERT_VK_SUCCESS(err);
8764 // Bind memory to image
8765 VkMemoryRequirements mem_reqs;
8766 VkDeviceMemory image_mem;
8767 bool pass;
8768 VkMemoryAllocateInfo mem_alloc = {};
8769 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8770 mem_alloc.pNext = NULL;
8771 mem_alloc.allocationSize = 0;
8772 mem_alloc.memoryTypeIndex = 0;
8773 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8774 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008775 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008776 ASSERT_TRUE(pass);
8777 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8778 ASSERT_VK_SUCCESS(err);
8779 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8780 ASSERT_VK_SUCCESS(err);
8781 // Now create view for image
8782 VkImageViewCreateInfo image_view_ci = {};
8783 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8784 image_view_ci.image = image;
8785 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8786 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8787 image_view_ci.subresourceRange.layerCount = 1;
8788 image_view_ci.subresourceRange.baseArrayLayer = 0;
8789 image_view_ci.subresourceRange.levelCount = 1;
8790 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008791 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008792
8793 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008794 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008795 ASSERT_VK_SUCCESS(err);
8796
8797 VkDescriptorImageInfo img_info = {};
8798 img_info.imageView = image_view;
8799 VkWriteDescriptorSet descriptor_write = {};
8800 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8801 descriptor_write.dstBinding = 0;
8802 descriptor_write.descriptorCount = 1;
8803 descriptor_write.pTexelBufferView = NULL;
8804 descriptor_write.pBufferInfo = NULL;
8805 descriptor_write.pImageInfo = &img_info;
8806 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8807 descriptor_write.dstSet = descriptor_set;
8808 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8809 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008811
8812 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8813
8814 m_errorMonitor->VerifyFound();
8815 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8816 vkDestroyImage(m_device->device(), image, NULL);
8817 vkFreeMemory(m_device->device(), image_mem, NULL);
8818 vkDestroyImageView(m_device->device(), image_view, NULL);
8819 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8820 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8821}
8822
Karl Schultz6addd812016-02-02 17:17:23 -07008823TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008824 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008825 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008826
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8828 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8829 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008830
Tobin Ehlis3b780662015-05-28 12:11:26 -06008831 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008832 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008833 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008834 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8835 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008836
8837 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008838 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8839 ds_pool_ci.pNext = NULL;
8840 ds_pool_ci.maxSets = 1;
8841 ds_pool_ci.poolSizeCount = 1;
8842 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008843
Tobin Ehlis3b780662015-05-28 12:11:26 -06008844 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008845 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008846 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008847 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008848 dsl_binding.binding = 0;
8849 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8850 dsl_binding.descriptorCount = 1;
8851 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8852 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008853
Tony Barboureb254902015-07-15 12:50:33 -06008854 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008855 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8856 ds_layout_ci.pNext = NULL;
8857 ds_layout_ci.bindingCount = 1;
8858 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008859
Tobin Ehlis3b780662015-05-28 12:11:26 -06008860 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008862 ASSERT_VK_SUCCESS(err);
8863
8864 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008865 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008866 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008867 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008868 alloc_info.descriptorPool = ds_pool;
8869 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008870 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008871 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008872
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008873 VkSamplerCreateInfo sampler_ci = {};
8874 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8875 sampler_ci.pNext = NULL;
8876 sampler_ci.magFilter = VK_FILTER_NEAREST;
8877 sampler_ci.minFilter = VK_FILTER_NEAREST;
8878 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8879 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8880 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8881 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8882 sampler_ci.mipLodBias = 1.0;
8883 sampler_ci.anisotropyEnable = VK_FALSE;
8884 sampler_ci.maxAnisotropy = 1;
8885 sampler_ci.compareEnable = VK_FALSE;
8886 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8887 sampler_ci.minLod = 1.0;
8888 sampler_ci.maxLod = 1.0;
8889 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8890 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8891 VkSampler sampler;
8892 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8893 ASSERT_VK_SUCCESS(err);
8894
8895 VkDescriptorImageInfo info = {};
8896 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008897
8898 VkWriteDescriptorSet descriptor_write;
8899 memset(&descriptor_write, 0, sizeof(descriptor_write));
8900 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008901 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008902 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008903 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008904 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008905 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008906
8907 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8908
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008909 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008910
Chia-I Wuf7458c52015-10-26 21:10:41 +08008911 vkDestroySampler(m_device->device(), sampler, NULL);
8912 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8913 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008914}
8915
Karl Schultz6addd812016-02-02 17:17:23 -07008916TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008917 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008918 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008919
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8921 " binding #0 with 1 total descriptors but update of 1 descriptors "
8922 "starting at binding offset of 0 combined with update array element "
8923 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008924
Tobin Ehlis3b780662015-05-28 12:11:26 -06008925 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008926 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008927 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008928 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8929 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008930
8931 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008932 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8933 ds_pool_ci.pNext = NULL;
8934 ds_pool_ci.maxSets = 1;
8935 ds_pool_ci.poolSizeCount = 1;
8936 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008937
Tobin Ehlis3b780662015-05-28 12:11:26 -06008938 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008939 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008940 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008941
Tony Barboureb254902015-07-15 12:50:33 -06008942 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008943 dsl_binding.binding = 0;
8944 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8945 dsl_binding.descriptorCount = 1;
8946 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8947 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008948
8949 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008950 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8951 ds_layout_ci.pNext = NULL;
8952 ds_layout_ci.bindingCount = 1;
8953 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008954
Tobin Ehlis3b780662015-05-28 12:11:26 -06008955 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008956 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008957 ASSERT_VK_SUCCESS(err);
8958
8959 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008960 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008961 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008962 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008963 alloc_info.descriptorPool = ds_pool;
8964 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008965 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008966 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008967
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008968 // Correctly update descriptor to avoid "NOT_UPDATED" error
8969 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008970 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008971 buff_info.offset = 0;
8972 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008973
8974 VkWriteDescriptorSet descriptor_write;
8975 memset(&descriptor_write, 0, sizeof(descriptor_write));
8976 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008977 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008978 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008979 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008980 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8981 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008982
8983 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8984
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008985 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008986
Chia-I Wuf7458c52015-10-26 21:10:41 +08008987 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8988 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008989}
8990
Karl Schultz6addd812016-02-02 17:17:23 -07008991TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07008992 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07008993 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008994
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07008995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008996
Tobin Ehlis3b780662015-05-28 12:11:26 -06008997 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008998 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008999 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009000 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9001 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009002
9003 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009004 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9005 ds_pool_ci.pNext = NULL;
9006 ds_pool_ci.maxSets = 1;
9007 ds_pool_ci.poolSizeCount = 1;
9008 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009009
Tobin Ehlis3b780662015-05-28 12:11:26 -06009010 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009011 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009012 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009013
Tony Barboureb254902015-07-15 12:50:33 -06009014 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009015 dsl_binding.binding = 0;
9016 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9017 dsl_binding.descriptorCount = 1;
9018 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9019 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009020
9021 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009022 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9023 ds_layout_ci.pNext = NULL;
9024 ds_layout_ci.bindingCount = 1;
9025 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009026 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009027 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009028 ASSERT_VK_SUCCESS(err);
9029
9030 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009031 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009032 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009033 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009034 alloc_info.descriptorPool = ds_pool;
9035 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009036 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009037 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009038
Tony Barboureb254902015-07-15 12:50:33 -06009039 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009040 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9041 sampler_ci.pNext = NULL;
9042 sampler_ci.magFilter = VK_FILTER_NEAREST;
9043 sampler_ci.minFilter = VK_FILTER_NEAREST;
9044 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9045 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9046 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9047 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9048 sampler_ci.mipLodBias = 1.0;
9049 sampler_ci.anisotropyEnable = VK_FALSE;
9050 sampler_ci.maxAnisotropy = 1;
9051 sampler_ci.compareEnable = VK_FALSE;
9052 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9053 sampler_ci.minLod = 1.0;
9054 sampler_ci.maxLod = 1.0;
9055 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9056 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009057
Tobin Ehlis3b780662015-05-28 12:11:26 -06009058 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009059 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009060 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009061
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009062 VkDescriptorImageInfo info = {};
9063 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009064
9065 VkWriteDescriptorSet descriptor_write;
9066 memset(&descriptor_write, 0, sizeof(descriptor_write));
9067 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009068 descriptor_write.dstSet = descriptorSet;
9069 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009070 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009071 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009072 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009073 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009074
9075 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9076
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009077 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009078
Chia-I Wuf7458c52015-10-26 21:10:41 +08009079 vkDestroySampler(m_device->device(), sampler, NULL);
9080 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9081 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009082}
9083
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009084TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9085 // Create layout w/ empty binding and attempt to update it
9086 VkResult err;
9087
9088 ASSERT_NO_FATAL_FAILURE(InitState());
9089
9090 VkDescriptorPoolSize ds_type_count = {};
9091 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9092 ds_type_count.descriptorCount = 1;
9093
9094 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9095 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9096 ds_pool_ci.pNext = NULL;
9097 ds_pool_ci.maxSets = 1;
9098 ds_pool_ci.poolSizeCount = 1;
9099 ds_pool_ci.pPoolSizes = &ds_type_count;
9100
9101 VkDescriptorPool ds_pool;
9102 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9103 ASSERT_VK_SUCCESS(err);
9104
9105 VkDescriptorSetLayoutBinding dsl_binding = {};
9106 dsl_binding.binding = 0;
9107 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9108 dsl_binding.descriptorCount = 0;
9109 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9110 dsl_binding.pImmutableSamplers = NULL;
9111
9112 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9113 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9114 ds_layout_ci.pNext = NULL;
9115 ds_layout_ci.bindingCount = 1;
9116 ds_layout_ci.pBindings = &dsl_binding;
9117 VkDescriptorSetLayout ds_layout;
9118 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9119 ASSERT_VK_SUCCESS(err);
9120
9121 VkDescriptorSet descriptor_set;
9122 VkDescriptorSetAllocateInfo alloc_info = {};
9123 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9124 alloc_info.descriptorSetCount = 1;
9125 alloc_info.descriptorPool = ds_pool;
9126 alloc_info.pSetLayouts = &ds_layout;
9127 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9128 ASSERT_VK_SUCCESS(err);
9129
9130 VkSamplerCreateInfo sampler_ci = {};
9131 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9132 sampler_ci.magFilter = VK_FILTER_NEAREST;
9133 sampler_ci.minFilter = VK_FILTER_NEAREST;
9134 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9135 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9136 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9137 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9138 sampler_ci.mipLodBias = 1.0;
9139 sampler_ci.maxAnisotropy = 1;
9140 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9141 sampler_ci.minLod = 1.0;
9142 sampler_ci.maxLod = 1.0;
9143 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9144
9145 VkSampler sampler;
9146 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9147 ASSERT_VK_SUCCESS(err);
9148
9149 VkDescriptorImageInfo info = {};
9150 info.sampler = sampler;
9151
9152 VkWriteDescriptorSet descriptor_write;
9153 memset(&descriptor_write, 0, sizeof(descriptor_write));
9154 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9155 descriptor_write.dstSet = descriptor_set;
9156 descriptor_write.dstBinding = 0;
9157 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9158 // This is the wrong type, but empty binding error will be flagged first
9159 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9160 descriptor_write.pImageInfo = &info;
9161
9162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9163 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9164 m_errorMonitor->VerifyFound();
9165
9166 vkDestroySampler(m_device->device(), sampler, NULL);
9167 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9168 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9169}
9170
Karl Schultz6addd812016-02-02 17:17:23 -07009171TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9172 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9173 // types
9174 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009175
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009176 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 -06009177
Tobin Ehlis3b780662015-05-28 12:11:26 -06009178 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009179
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009180 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009181 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9182 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009183
9184 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009185 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9186 ds_pool_ci.pNext = NULL;
9187 ds_pool_ci.maxSets = 1;
9188 ds_pool_ci.poolSizeCount = 1;
9189 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009190
Tobin Ehlis3b780662015-05-28 12:11:26 -06009191 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009192 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009193 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009194 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009195 dsl_binding.binding = 0;
9196 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9197 dsl_binding.descriptorCount = 1;
9198 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9199 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009200
Tony Barboureb254902015-07-15 12:50:33 -06009201 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009202 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9203 ds_layout_ci.pNext = NULL;
9204 ds_layout_ci.bindingCount = 1;
9205 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009206
Tobin Ehlis3b780662015-05-28 12:11:26 -06009207 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009208 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009209 ASSERT_VK_SUCCESS(err);
9210
9211 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009212 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009213 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009214 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009215 alloc_info.descriptorPool = ds_pool;
9216 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009217 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009218 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009219
Tony Barboureb254902015-07-15 12:50:33 -06009220 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009221 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9222 sampler_ci.pNext = NULL;
9223 sampler_ci.magFilter = VK_FILTER_NEAREST;
9224 sampler_ci.minFilter = VK_FILTER_NEAREST;
9225 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9226 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9227 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9228 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9229 sampler_ci.mipLodBias = 1.0;
9230 sampler_ci.anisotropyEnable = VK_FALSE;
9231 sampler_ci.maxAnisotropy = 1;
9232 sampler_ci.compareEnable = VK_FALSE;
9233 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9234 sampler_ci.minLod = 1.0;
9235 sampler_ci.maxLod = 1.0;
9236 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9237 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009238 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009239 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009240 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009241
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009242 VkDescriptorImageInfo info = {};
9243 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009244
9245 VkWriteDescriptorSet descriptor_write;
9246 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009247 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009248 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009249 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009250 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009251 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009252 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009253
9254 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9255
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009256 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009257
Chia-I Wuf7458c52015-10-26 21:10:41 +08009258 vkDestroySampler(m_device->device(), sampler, NULL);
9259 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9260 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009261}
9262
Karl Schultz6addd812016-02-02 17:17:23 -07009263TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009264 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009265 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009266
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9268 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009269
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009270 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009271 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9272 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009273 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009274 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9275 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009276
9277 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009278 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9279 ds_pool_ci.pNext = NULL;
9280 ds_pool_ci.maxSets = 1;
9281 ds_pool_ci.poolSizeCount = 1;
9282 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009283
9284 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009285 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009286 ASSERT_VK_SUCCESS(err);
9287
9288 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009289 dsl_binding.binding = 0;
9290 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9291 dsl_binding.descriptorCount = 1;
9292 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9293 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009294
9295 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009296 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9297 ds_layout_ci.pNext = NULL;
9298 ds_layout_ci.bindingCount = 1;
9299 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009300 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009301 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009302 ASSERT_VK_SUCCESS(err);
9303
9304 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009305 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009306 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009307 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009308 alloc_info.descriptorPool = ds_pool;
9309 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009310 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009311 ASSERT_VK_SUCCESS(err);
9312
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009313 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009314
9315 VkDescriptorImageInfo descriptor_info;
9316 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9317 descriptor_info.sampler = sampler;
9318
9319 VkWriteDescriptorSet descriptor_write;
9320 memset(&descriptor_write, 0, sizeof(descriptor_write));
9321 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009322 descriptor_write.dstSet = descriptorSet;
9323 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009324 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009325 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9326 descriptor_write.pImageInfo = &descriptor_info;
9327
9328 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9329
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009330 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009331
Chia-I Wuf7458c52015-10-26 21:10:41 +08009332 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9333 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009334}
9335
Karl Schultz6addd812016-02-02 17:17:23 -07009336TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9337 // Create a single combined Image/Sampler descriptor and send it an invalid
9338 // imageView
9339 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009340
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9342 "image sampler descriptor failed due "
9343 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009344
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009345 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009346 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009347 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9348 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009349
9350 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009351 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9352 ds_pool_ci.pNext = NULL;
9353 ds_pool_ci.maxSets = 1;
9354 ds_pool_ci.poolSizeCount = 1;
9355 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009356
9357 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009358 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009359 ASSERT_VK_SUCCESS(err);
9360
9361 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009362 dsl_binding.binding = 0;
9363 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9364 dsl_binding.descriptorCount = 1;
9365 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9366 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009367
9368 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009369 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9370 ds_layout_ci.pNext = NULL;
9371 ds_layout_ci.bindingCount = 1;
9372 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009373 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009374 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009375 ASSERT_VK_SUCCESS(err);
9376
9377 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009378 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009379 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009380 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009381 alloc_info.descriptorPool = ds_pool;
9382 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009383 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009384 ASSERT_VK_SUCCESS(err);
9385
9386 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009387 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9388 sampler_ci.pNext = NULL;
9389 sampler_ci.magFilter = VK_FILTER_NEAREST;
9390 sampler_ci.minFilter = VK_FILTER_NEAREST;
9391 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9392 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9393 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9394 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9395 sampler_ci.mipLodBias = 1.0;
9396 sampler_ci.anisotropyEnable = VK_FALSE;
9397 sampler_ci.maxAnisotropy = 1;
9398 sampler_ci.compareEnable = VK_FALSE;
9399 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9400 sampler_ci.minLod = 1.0;
9401 sampler_ci.maxLod = 1.0;
9402 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9403 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009404
9405 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009406 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009407 ASSERT_VK_SUCCESS(err);
9408
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009409 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009410
9411 VkDescriptorImageInfo descriptor_info;
9412 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9413 descriptor_info.sampler = sampler;
9414 descriptor_info.imageView = view;
9415
9416 VkWriteDescriptorSet descriptor_write;
9417 memset(&descriptor_write, 0, sizeof(descriptor_write));
9418 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009419 descriptor_write.dstSet = descriptorSet;
9420 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009421 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009422 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9423 descriptor_write.pImageInfo = &descriptor_info;
9424
9425 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9426
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009427 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009428
Chia-I Wuf7458c52015-10-26 21:10:41 +08009429 vkDestroySampler(m_device->device(), sampler, NULL);
9430 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9431 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009432}
9433
Karl Schultz6addd812016-02-02 17:17:23 -07009434TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9435 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9436 // into the other
9437 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009438
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9440 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9441 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009442
Tobin Ehlis04356f92015-10-27 16:35:27 -06009443 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009444 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009445 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009446 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9447 ds_type_count[0].descriptorCount = 1;
9448 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9449 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009450
9451 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009452 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9453 ds_pool_ci.pNext = NULL;
9454 ds_pool_ci.maxSets = 1;
9455 ds_pool_ci.poolSizeCount = 2;
9456 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009457
9458 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009459 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009460 ASSERT_VK_SUCCESS(err);
9461 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009462 dsl_binding[0].binding = 0;
9463 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9464 dsl_binding[0].descriptorCount = 1;
9465 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9466 dsl_binding[0].pImmutableSamplers = NULL;
9467 dsl_binding[1].binding = 1;
9468 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9469 dsl_binding[1].descriptorCount = 1;
9470 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9471 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009472
9473 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009474 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9475 ds_layout_ci.pNext = NULL;
9476 ds_layout_ci.bindingCount = 2;
9477 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009478
9479 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009480 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009481 ASSERT_VK_SUCCESS(err);
9482
9483 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009484 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009485 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009486 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009487 alloc_info.descriptorPool = ds_pool;
9488 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009489 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009490 ASSERT_VK_SUCCESS(err);
9491
9492 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009493 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9494 sampler_ci.pNext = NULL;
9495 sampler_ci.magFilter = VK_FILTER_NEAREST;
9496 sampler_ci.minFilter = VK_FILTER_NEAREST;
9497 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9498 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9499 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9500 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9501 sampler_ci.mipLodBias = 1.0;
9502 sampler_ci.anisotropyEnable = VK_FALSE;
9503 sampler_ci.maxAnisotropy = 1;
9504 sampler_ci.compareEnable = VK_FALSE;
9505 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9506 sampler_ci.minLod = 1.0;
9507 sampler_ci.maxLod = 1.0;
9508 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9509 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009510
9511 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009512 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009513 ASSERT_VK_SUCCESS(err);
9514
9515 VkDescriptorImageInfo info = {};
9516 info.sampler = sampler;
9517
9518 VkWriteDescriptorSet descriptor_write;
9519 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9520 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009521 descriptor_write.dstSet = descriptorSet;
9522 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009523 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009524 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9525 descriptor_write.pImageInfo = &info;
9526 // This write update should succeed
9527 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9528 // Now perform a copy update that fails due to type mismatch
9529 VkCopyDescriptorSet copy_ds_update;
9530 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9531 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9532 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009533 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009534 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009535 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009536 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009537 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9538
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009539 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009540 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009541 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 -06009542 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9543 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9544 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009545 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009546 copy_ds_update.dstSet = descriptorSet;
9547 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009548 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009549 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9550
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009551 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009552
Tobin Ehlis04356f92015-10-27 16:35:27 -06009553 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9555 "update array offset of 0 and update of "
9556 "5 descriptors oversteps total number "
9557 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009558
Tobin Ehlis04356f92015-10-27 16:35:27 -06009559 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9560 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9561 copy_ds_update.srcSet = descriptorSet;
9562 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009563 copy_ds_update.dstSet = descriptorSet;
9564 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009565 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009566 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9567
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009568 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009569
Chia-I Wuf7458c52015-10-26 21:10:41 +08009570 vkDestroySampler(m_device->device(), sampler, NULL);
9571 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9572 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009573}
9574
Karl Schultz6addd812016-02-02 17:17:23 -07009575TEST_F(VkLayerTest, NumSamplesMismatch) {
9576 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9577 // sampleCount
9578 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009579
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009581
Tobin Ehlis3b780662015-05-28 12:11:26 -06009582 ASSERT_NO_FATAL_FAILURE(InitState());
9583 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009584 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009585 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009586 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009587
9588 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009589 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9590 ds_pool_ci.pNext = NULL;
9591 ds_pool_ci.maxSets = 1;
9592 ds_pool_ci.poolSizeCount = 1;
9593 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009594
Tobin Ehlis3b780662015-05-28 12:11:26 -06009595 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009596 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009597 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009598
Tony Barboureb254902015-07-15 12:50:33 -06009599 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009600 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009601 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009602 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009603 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9604 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009605
Tony Barboureb254902015-07-15 12:50:33 -06009606 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9607 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9608 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009609 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009610 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009611
Tobin Ehlis3b780662015-05-28 12:11:26 -06009612 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009613 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009614 ASSERT_VK_SUCCESS(err);
9615
9616 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009617 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009618 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009619 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009620 alloc_info.descriptorPool = ds_pool;
9621 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009622 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009623 ASSERT_VK_SUCCESS(err);
9624
Tony Barboureb254902015-07-15 12:50:33 -06009625 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009626 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009627 pipe_ms_state_ci.pNext = NULL;
9628 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9629 pipe_ms_state_ci.sampleShadingEnable = 0;
9630 pipe_ms_state_ci.minSampleShading = 1.0;
9631 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009632
Tony Barboureb254902015-07-15 12:50:33 -06009633 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009634 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9635 pipeline_layout_ci.pNext = NULL;
9636 pipeline_layout_ci.setLayoutCount = 1;
9637 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009638
9639 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009640 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009641 ASSERT_VK_SUCCESS(err);
9642
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009643 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9644 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9645 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009646 VkPipelineObj pipe(m_device);
9647 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009648 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009649 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009650 pipe.SetMSAA(&pipe_ms_state_ci);
9651 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009652
Tony Barbourfe3351b2015-07-28 10:17:20 -06009653 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009654 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009655
Mark Young29927482016-05-04 14:38:51 -06009656 // Render triangle (the error should trigger on the attempt to draw).
9657 Draw(3, 1, 0, 0);
9658
9659 // Finalize recording of the command buffer
9660 EndCommandBuffer();
9661
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009662 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009663
Chia-I Wuf7458c52015-10-26 21:10:41 +08009664 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9665 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9666 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009667}
Mark Young29927482016-05-04 14:38:51 -06009668
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009669TEST_F(VkLayerTest, RenderPassIncompatible) {
9670 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9671 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009672 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009673 VkResult err;
9674
9675 ASSERT_NO_FATAL_FAILURE(InitState());
9676 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9677
9678 VkDescriptorSetLayoutBinding dsl_binding = {};
9679 dsl_binding.binding = 0;
9680 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9681 dsl_binding.descriptorCount = 1;
9682 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9683 dsl_binding.pImmutableSamplers = NULL;
9684
9685 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9686 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9687 ds_layout_ci.pNext = NULL;
9688 ds_layout_ci.bindingCount = 1;
9689 ds_layout_ci.pBindings = &dsl_binding;
9690
9691 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009692 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009693 ASSERT_VK_SUCCESS(err);
9694
9695 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9696 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9697 pipeline_layout_ci.pNext = NULL;
9698 pipeline_layout_ci.setLayoutCount = 1;
9699 pipeline_layout_ci.pSetLayouts = &ds_layout;
9700
9701 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009702 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009703 ASSERT_VK_SUCCESS(err);
9704
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009705 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9706 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9707 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009708 // Create a renderpass that will be incompatible with default renderpass
9709 VkAttachmentReference attach = {};
9710 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9711 VkAttachmentReference color_att = {};
9712 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9713 VkSubpassDescription subpass = {};
9714 subpass.inputAttachmentCount = 1;
9715 subpass.pInputAttachments = &attach;
9716 subpass.colorAttachmentCount = 1;
9717 subpass.pColorAttachments = &color_att;
9718 VkRenderPassCreateInfo rpci = {};
9719 rpci.subpassCount = 1;
9720 rpci.pSubpasses = &subpass;
9721 rpci.attachmentCount = 1;
9722 VkAttachmentDescription attach_desc = {};
9723 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009724 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9725 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009726 rpci.pAttachments = &attach_desc;
9727 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9728 VkRenderPass rp;
9729 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9730 VkPipelineObj pipe(m_device);
9731 pipe.AddShader(&vs);
9732 pipe.AddShader(&fs);
9733 pipe.AddColorAttachment();
9734 VkViewport view_port = {};
9735 m_viewports.push_back(view_port);
9736 pipe.SetViewport(m_viewports);
9737 VkRect2D rect = {};
9738 m_scissors.push_back(rect);
9739 pipe.SetScissor(m_scissors);
9740 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9741
9742 VkCommandBufferInheritanceInfo cbii = {};
9743 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9744 cbii.renderPass = rp;
9745 cbii.subpass = 0;
9746 VkCommandBufferBeginInfo cbbi = {};
9747 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9748 cbbi.pInheritanceInfo = &cbii;
9749 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9750 VkRenderPassBeginInfo rpbi = {};
9751 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9752 rpbi.framebuffer = m_framebuffer;
9753 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009754 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9755 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009756
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009758 // Render triangle (the error should trigger on the attempt to draw).
9759 Draw(3, 1, 0, 0);
9760
9761 // Finalize recording of the command buffer
9762 EndCommandBuffer();
9763
9764 m_errorMonitor->VerifyFound();
9765
9766 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9767 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9768 vkDestroyRenderPass(m_device->device(), rp, NULL);
9769}
9770
Mark Youngc89c6312016-03-31 16:03:20 -06009771TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9772 // Create Pipeline where the number of blend attachments doesn't match the
9773 // number of color attachments. In this case, we don't add any color
9774 // blend attachments even though we have a color attachment.
9775 VkResult err;
9776
9777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009778 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009779
9780 ASSERT_NO_FATAL_FAILURE(InitState());
9781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9782 VkDescriptorPoolSize ds_type_count = {};
9783 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9784 ds_type_count.descriptorCount = 1;
9785
9786 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9787 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9788 ds_pool_ci.pNext = NULL;
9789 ds_pool_ci.maxSets = 1;
9790 ds_pool_ci.poolSizeCount = 1;
9791 ds_pool_ci.pPoolSizes = &ds_type_count;
9792
9793 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009794 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009795 ASSERT_VK_SUCCESS(err);
9796
9797 VkDescriptorSetLayoutBinding dsl_binding = {};
9798 dsl_binding.binding = 0;
9799 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9800 dsl_binding.descriptorCount = 1;
9801 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9802 dsl_binding.pImmutableSamplers = NULL;
9803
9804 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9805 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9806 ds_layout_ci.pNext = NULL;
9807 ds_layout_ci.bindingCount = 1;
9808 ds_layout_ci.pBindings = &dsl_binding;
9809
9810 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009811 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009812 ASSERT_VK_SUCCESS(err);
9813
9814 VkDescriptorSet descriptorSet;
9815 VkDescriptorSetAllocateInfo alloc_info = {};
9816 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9817 alloc_info.descriptorSetCount = 1;
9818 alloc_info.descriptorPool = ds_pool;
9819 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009820 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009821 ASSERT_VK_SUCCESS(err);
9822
9823 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009824 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009825 pipe_ms_state_ci.pNext = NULL;
9826 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9827 pipe_ms_state_ci.sampleShadingEnable = 0;
9828 pipe_ms_state_ci.minSampleShading = 1.0;
9829 pipe_ms_state_ci.pSampleMask = NULL;
9830
9831 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9832 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9833 pipeline_layout_ci.pNext = NULL;
9834 pipeline_layout_ci.setLayoutCount = 1;
9835 pipeline_layout_ci.pSetLayouts = &ds_layout;
9836
9837 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009838 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009839 ASSERT_VK_SUCCESS(err);
9840
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009841 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9842 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9843 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009844 VkPipelineObj pipe(m_device);
9845 pipe.AddShader(&vs);
9846 pipe.AddShader(&fs);
9847 pipe.SetMSAA(&pipe_ms_state_ci);
9848 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9849
9850 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009851 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009852
Mark Young29927482016-05-04 14:38:51 -06009853 // Render triangle (the error should trigger on the attempt to draw).
9854 Draw(3, 1, 0, 0);
9855
9856 // Finalize recording of the command buffer
9857 EndCommandBuffer();
9858
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009859 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009860
9861 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9862 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9863 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9864}
Mark Young29927482016-05-04 14:38:51 -06009865
Mark Muellerd4914412016-06-13 17:52:06 -06009866TEST_F(VkLayerTest, MissingClearAttachment) {
9867 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9868 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009869 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009871 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009872
9873 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9874 m_errorMonitor->VerifyFound();
9875}
9876
Karl Schultz6addd812016-02-02 17:17:23 -07009877TEST_F(VkLayerTest, ClearCmdNoDraw) {
9878 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9879 // to issuing a Draw
9880 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009881
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009883 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009884
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009885 ASSERT_NO_FATAL_FAILURE(InitState());
9886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009887
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009888 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009889 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9890 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009891
9892 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009893 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9894 ds_pool_ci.pNext = NULL;
9895 ds_pool_ci.maxSets = 1;
9896 ds_pool_ci.poolSizeCount = 1;
9897 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009898
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009899 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009900 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009901 ASSERT_VK_SUCCESS(err);
9902
Tony Barboureb254902015-07-15 12:50:33 -06009903 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009904 dsl_binding.binding = 0;
9905 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9906 dsl_binding.descriptorCount = 1;
9907 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9908 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009909
Tony Barboureb254902015-07-15 12:50:33 -06009910 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009911 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9912 ds_layout_ci.pNext = NULL;
9913 ds_layout_ci.bindingCount = 1;
9914 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009915
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009916 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009917 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009918 ASSERT_VK_SUCCESS(err);
9919
9920 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009921 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009922 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009923 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009924 alloc_info.descriptorPool = ds_pool;
9925 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009926 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009927 ASSERT_VK_SUCCESS(err);
9928
Tony Barboureb254902015-07-15 12:50:33 -06009929 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009930 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009931 pipe_ms_state_ci.pNext = NULL;
9932 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9933 pipe_ms_state_ci.sampleShadingEnable = 0;
9934 pipe_ms_state_ci.minSampleShading = 1.0;
9935 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009936
Tony Barboureb254902015-07-15 12:50:33 -06009937 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009938 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9939 pipeline_layout_ci.pNext = NULL;
9940 pipeline_layout_ci.setLayoutCount = 1;
9941 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009942
9943 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009944 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009945 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009946
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009947 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009948 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009949 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009950 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009951
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009952 VkPipelineObj pipe(m_device);
9953 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009954 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009955 pipe.SetMSAA(&pipe_ms_state_ci);
9956 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009957
9958 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009959
Karl Schultz6addd812016-02-02 17:17:23 -07009960 // Main thing we care about for this test is that the VkImage obj we're
9961 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009962 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009963 VkClearAttachment color_attachment;
9964 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9965 color_attachment.clearValue.color.float32[0] = 1.0;
9966 color_attachment.clearValue.color.float32[1] = 1.0;
9967 color_attachment.clearValue.color.float32[2] = 1.0;
9968 color_attachment.clearValue.color.float32[3] = 1.0;
9969 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009970 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009971
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009972 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009973
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009974 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009975
Chia-I Wuf7458c52015-10-26 21:10:41 +08009976 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9977 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9978 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009979}
9980
Karl Schultz6addd812016-02-02 17:17:23 -07009981TEST_F(VkLayerTest, VtxBufferBadIndex) {
9982 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009983
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9985 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009986
Tobin Ehlis502480b2015-06-24 15:53:07 -06009987 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009988 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009990
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009991 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009992 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9993 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009994
9995 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009996 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9997 ds_pool_ci.pNext = NULL;
9998 ds_pool_ci.maxSets = 1;
9999 ds_pool_ci.poolSizeCount = 1;
10000 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010001
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010002 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010003 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010004 ASSERT_VK_SUCCESS(err);
10005
Tony Barboureb254902015-07-15 12:50:33 -060010006 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010007 dsl_binding.binding = 0;
10008 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10009 dsl_binding.descriptorCount = 1;
10010 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10011 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010012
Tony Barboureb254902015-07-15 12:50:33 -060010013 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010014 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10015 ds_layout_ci.pNext = NULL;
10016 ds_layout_ci.bindingCount = 1;
10017 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010018
Tobin Ehlis502480b2015-06-24 15:53:07 -060010019 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010020 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010021 ASSERT_VK_SUCCESS(err);
10022
10023 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010024 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010025 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010026 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010027 alloc_info.descriptorPool = ds_pool;
10028 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010029 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010030 ASSERT_VK_SUCCESS(err);
10031
Tony Barboureb254902015-07-15 12:50:33 -060010032 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010033 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010034 pipe_ms_state_ci.pNext = NULL;
10035 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10036 pipe_ms_state_ci.sampleShadingEnable = 0;
10037 pipe_ms_state_ci.minSampleShading = 1.0;
10038 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010039
Tony Barboureb254902015-07-15 12:50:33 -060010040 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010041 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10042 pipeline_layout_ci.pNext = NULL;
10043 pipeline_layout_ci.setLayoutCount = 1;
10044 pipeline_layout_ci.pSetLayouts = &ds_layout;
10045 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010047 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010048 ASSERT_VK_SUCCESS(err);
10049
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010050 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10051 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10052 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010053 VkPipelineObj pipe(m_device);
10054 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010055 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010056 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010057 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010058 pipe.SetViewport(m_viewports);
10059 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010060 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010061
10062 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010063 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010064 // Don't care about actual data, just need to get to draw to flag error
10065 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010066 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010067 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010068 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010069
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010070 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010071
Chia-I Wuf7458c52015-10-26 21:10:41 +080010072 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10073 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10074 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010075}
Mark Muellerdfe37552016-07-07 14:47:42 -060010076
Mark Mueller2ee294f2016-08-04 12:59:48 -060010077TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10078 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10079 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010080 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010081
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010082 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10083 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010084
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010085 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10086 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010087
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010088 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010089
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010091 // The following test fails with recent NVidia drivers.
10092 // By the time core_validation is reached, the NVidia
10093 // driver has sanitized the invalid condition and core_validation
10094 // is not introduced to the failure condition. This is not the case
10095 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010096 // uint32_t count = static_cast<uint32_t>(~0);
10097 // VkPhysicalDevice physical_device;
10098 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10099 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010100
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010102 float queue_priority = 0.0;
10103
10104 VkDeviceQueueCreateInfo queue_create_info = {};
10105 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10106 queue_create_info.queueCount = 1;
10107 queue_create_info.pQueuePriorities = &queue_priority;
10108 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10109
10110 VkPhysicalDeviceFeatures features = m_device->phy().features();
10111 VkDevice testDevice;
10112 VkDeviceCreateInfo device_create_info = {};
10113 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10114 device_create_info.queueCreateInfoCount = 1;
10115 device_create_info.pQueueCreateInfos = &queue_create_info;
10116 device_create_info.pEnabledFeatures = &features;
10117 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10118 m_errorMonitor->VerifyFound();
10119
10120 queue_create_info.queueFamilyIndex = 1;
10121
10122 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10123 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10124 for (unsigned i = 0; i < feature_count; i++) {
10125 if (VK_FALSE == feature_array[i]) {
10126 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010128 device_create_info.pEnabledFeatures = &features;
10129 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10130 m_errorMonitor->VerifyFound();
10131 break;
10132 }
10133 }
10134}
10135
Tobin Ehlis16edf082016-11-21 12:33:49 -070010136TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10137 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10138
10139 ASSERT_NO_FATAL_FAILURE(InitState());
10140
10141 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10142 std::vector<VkDeviceQueueCreateInfo> queue_info;
10143 queue_info.reserve(queue_props.size());
10144 std::vector<std::vector<float>> queue_priorities;
10145 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10146 VkDeviceQueueCreateInfo qi{};
10147 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10148 qi.queueFamilyIndex = i;
10149 qi.queueCount = queue_props[i].queueCount;
10150 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10151 qi.pQueuePriorities = queue_priorities[i].data();
10152 queue_info.push_back(qi);
10153 }
10154
10155 std::vector<const char *> device_extension_names;
10156
10157 VkDevice local_device;
10158 VkDeviceCreateInfo device_create_info = {};
10159 auto features = m_device->phy().features();
10160 // Intentionally disable pipeline stats
10161 features.pipelineStatisticsQuery = VK_FALSE;
10162 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10163 device_create_info.pNext = NULL;
10164 device_create_info.queueCreateInfoCount = queue_info.size();
10165 device_create_info.pQueueCreateInfos = queue_info.data();
10166 device_create_info.enabledLayerCount = 0;
10167 device_create_info.ppEnabledLayerNames = NULL;
10168 device_create_info.pEnabledFeatures = &features;
10169 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10170 ASSERT_VK_SUCCESS(err);
10171
10172 VkQueryPoolCreateInfo qpci{};
10173 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10174 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10175 qpci.queryCount = 1;
10176 VkQueryPool query_pool;
10177
10178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10179 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10180 m_errorMonitor->VerifyFound();
10181
10182 vkDestroyDevice(local_device, nullptr);
10183}
10184
Mark Mueller2ee294f2016-08-04 12:59:48 -060010185TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10186 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10187 "End a command buffer with a query still in progress.");
10188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010189 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10190 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10191 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010192
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010193 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010196
10197 ASSERT_NO_FATAL_FAILURE(InitState());
10198
10199 VkEvent event;
10200 VkEventCreateInfo event_create_info{};
10201 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10202 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10203
Mark Mueller2ee294f2016-08-04 12:59:48 -060010204 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010205 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010206
10207 BeginCommandBuffer();
10208
10209 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010210 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 -060010211 ASSERT_TRUE(image.initialized());
10212 VkImageMemoryBarrier img_barrier = {};
10213 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10214 img_barrier.pNext = NULL;
10215 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10216 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10217 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10218 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10219 img_barrier.image = image.handle();
10220 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010221
10222 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10223 // that layer validation catches the case when it is not.
10224 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010225 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10226 img_barrier.subresourceRange.baseArrayLayer = 0;
10227 img_barrier.subresourceRange.baseMipLevel = 0;
10228 img_barrier.subresourceRange.layerCount = 1;
10229 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010230 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10231 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010232 m_errorMonitor->VerifyFound();
10233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010235
10236 VkQueryPool query_pool;
10237 VkQueryPoolCreateInfo query_pool_create_info = {};
10238 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10239 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10240 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010241 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010243 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010244 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10245
10246 vkEndCommandBuffer(m_commandBuffer->handle());
10247 m_errorMonitor->VerifyFound();
10248
10249 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10250 vkDestroyEvent(m_device->device(), event, nullptr);
10251}
10252
Mark Muellerdfe37552016-07-07 14:47:42 -060010253TEST_F(VkLayerTest, VertexBufferInvalid) {
10254 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10255 "delete a buffer twice, use an invalid offset for each "
10256 "buffer type, and attempt to bind a null buffer");
10257
10258 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10259 "using deleted buffer ";
10260 const char *double_destroy_message = "Cannot free buffer 0x";
10261 const char *invalid_offset_message = "vkBindBufferMemory(): "
10262 "memoryOffset is 0x";
10263 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10264 "storage memoryOffset "
10265 "is 0x";
10266 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10267 "texel memoryOffset "
10268 "is 0x";
10269 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10270 "uniform memoryOffset "
10271 "is 0x";
10272 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
10273 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -060010274 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010275
10276 ASSERT_NO_FATAL_FAILURE(InitState());
10277 ASSERT_NO_FATAL_FAILURE(InitViewport());
10278 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10279
10280 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010281 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010282 pipe_ms_state_ci.pNext = NULL;
10283 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10284 pipe_ms_state_ci.sampleShadingEnable = 0;
10285 pipe_ms_state_ci.minSampleShading = 1.0;
10286 pipe_ms_state_ci.pSampleMask = nullptr;
10287
10288 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10289 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10290 VkPipelineLayout pipeline_layout;
10291
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010292 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010293 ASSERT_VK_SUCCESS(err);
10294
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010295 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10296 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010297 VkPipelineObj pipe(m_device);
10298 pipe.AddShader(&vs);
10299 pipe.AddShader(&fs);
10300 pipe.AddColorAttachment();
10301 pipe.SetMSAA(&pipe_ms_state_ci);
10302 pipe.SetViewport(m_viewports);
10303 pipe.SetScissor(m_scissors);
10304 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10305
10306 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010307 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010308
10309 {
10310 // Create and bind a vertex buffer in a reduced scope, which will cause
10311 // it to be deleted upon leaving this scope
10312 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010313 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010314 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10315 draw_verticies.AddVertexInputToPipe(pipe);
10316 }
10317
10318 Draw(1, 0, 0, 0);
10319
10320 EndCommandBuffer();
10321
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010323 QueueCommandBuffer(false);
10324 m_errorMonitor->VerifyFound();
10325
10326 {
10327 // Create and bind a vertex buffer in a reduced scope, and delete it
10328 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010329 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010331 buffer_test.TestDoubleDestroy();
10332 }
10333 m_errorMonitor->VerifyFound();
10334
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010335 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010336 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10338 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10339 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010340 m_errorMonitor->VerifyFound();
10341 }
10342
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010343 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10344 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010345 // Create and bind a memory buffer with an invalid offset again,
10346 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10348 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10349 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010350 m_errorMonitor->VerifyFound();
10351 }
10352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010353 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010354 // Create and bind a memory buffer with an invalid offset again, but
10355 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10357 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10358 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010359 m_errorMonitor->VerifyFound();
10360 }
10361
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010362 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010363 // Create and bind a memory buffer with an invalid offset again, but
10364 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10366 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10367 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010368 m_errorMonitor->VerifyFound();
10369 }
10370
10371 {
10372 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10374 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10375 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010376 m_errorMonitor->VerifyFound();
10377 }
10378
10379 {
10380 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10382 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10383 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010384 }
10385 m_errorMonitor->VerifyFound();
10386
10387 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10388}
10389
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010390// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10391TEST_F(VkLayerTest, InvalidImageLayout) {
10392 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010393 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10394 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010395 // 3 in ValidateCmdBufImageLayouts
10396 // * -1 Attempt to submit cmd buf w/ deleted image
10397 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10398 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10400 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010401
10402 ASSERT_NO_FATAL_FAILURE(InitState());
10403 // Create src & dst images to use for copy operations
10404 VkImage src_image;
10405 VkImage dst_image;
10406
10407 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10408 const int32_t tex_width = 32;
10409 const int32_t tex_height = 32;
10410
10411 VkImageCreateInfo image_create_info = {};
10412 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10413 image_create_info.pNext = NULL;
10414 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10415 image_create_info.format = tex_format;
10416 image_create_info.extent.width = tex_width;
10417 image_create_info.extent.height = tex_height;
10418 image_create_info.extent.depth = 1;
10419 image_create_info.mipLevels = 1;
10420 image_create_info.arrayLayers = 4;
10421 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10422 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10423 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10424 image_create_info.flags = 0;
10425
10426 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10427 ASSERT_VK_SUCCESS(err);
10428 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10429 ASSERT_VK_SUCCESS(err);
10430
10431 BeginCommandBuffer();
10432 VkImageCopy copyRegion;
10433 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10434 copyRegion.srcSubresource.mipLevel = 0;
10435 copyRegion.srcSubresource.baseArrayLayer = 0;
10436 copyRegion.srcSubresource.layerCount = 1;
10437 copyRegion.srcOffset.x = 0;
10438 copyRegion.srcOffset.y = 0;
10439 copyRegion.srcOffset.z = 0;
10440 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10441 copyRegion.dstSubresource.mipLevel = 0;
10442 copyRegion.dstSubresource.baseArrayLayer = 0;
10443 copyRegion.dstSubresource.layerCount = 1;
10444 copyRegion.dstOffset.x = 0;
10445 copyRegion.dstOffset.y = 0;
10446 copyRegion.dstOffset.z = 0;
10447 copyRegion.extent.width = 1;
10448 copyRegion.extent.height = 1;
10449 copyRegion.extent.depth = 1;
10450 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10451 m_errorMonitor->VerifyFound();
10452 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10454 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10455 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010456 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10457 m_errorMonitor->VerifyFound();
10458 // Final src error is due to bad layout type
10459 m_errorMonitor->SetDesiredFailureMsg(
10460 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10461 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10462 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10463 m_errorMonitor->VerifyFound();
10464 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10466 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010467 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10468 m_errorMonitor->VerifyFound();
10469 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10471 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10472 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010473 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10474 m_errorMonitor->VerifyFound();
10475 m_errorMonitor->SetDesiredFailureMsg(
10476 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10477 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10478 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10479 m_errorMonitor->VerifyFound();
10480 // Now cause error due to bad image layout transition in PipelineBarrier
10481 VkImageMemoryBarrier image_barrier[1] = {};
10482 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10483 image_barrier[0].image = src_image;
10484 image_barrier[0].subresourceRange.layerCount = 2;
10485 image_barrier[0].subresourceRange.levelCount = 2;
10486 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10488 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10489 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10490 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10491 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010492 m_errorMonitor->VerifyFound();
10493
10494 // Finally some layout errors at RenderPass create time
10495 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10496 VkAttachmentReference attach = {};
10497 // perf warning for GENERAL layout w/ non-DS input attachment
10498 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10499 VkSubpassDescription subpass = {};
10500 subpass.inputAttachmentCount = 1;
10501 subpass.pInputAttachments = &attach;
10502 VkRenderPassCreateInfo rpci = {};
10503 rpci.subpassCount = 1;
10504 rpci.pSubpasses = &subpass;
10505 rpci.attachmentCount = 1;
10506 VkAttachmentDescription attach_desc = {};
10507 attach_desc.format = VK_FORMAT_UNDEFINED;
10508 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010509 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010510 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10512 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010513 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10514 m_errorMonitor->VerifyFound();
10515 // error w/ non-general layout
10516 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10517
10518 m_errorMonitor->SetDesiredFailureMsg(
10519 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10520 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10521 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10522 m_errorMonitor->VerifyFound();
10523 subpass.inputAttachmentCount = 0;
10524 subpass.colorAttachmentCount = 1;
10525 subpass.pColorAttachments = &attach;
10526 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10527 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10529 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010530 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10531 m_errorMonitor->VerifyFound();
10532 // error w/ non-color opt or GENERAL layout for color attachment
10533 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10534 m_errorMonitor->SetDesiredFailureMsg(
10535 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10536 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10537 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10538 m_errorMonitor->VerifyFound();
10539 subpass.colorAttachmentCount = 0;
10540 subpass.pDepthStencilAttachment = &attach;
10541 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10542 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10544 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010545 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10546 m_errorMonitor->VerifyFound();
10547 // error w/ non-ds opt or GENERAL layout for color attachment
10548 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10550 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10551 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010552 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10553 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010554 // For this error we need a valid renderpass so create default one
10555 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10556 attach.attachment = 0;
10557 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10558 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10559 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10560 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10561 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10562 // Can't do a CLEAR load on READ_ONLY initialLayout
10563 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10564 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10565 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10567 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10568 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010569 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10570 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010571
10572 vkDestroyImage(m_device->device(), src_image, NULL);
10573 vkDestroyImage(m_device->device(), dst_image, NULL);
10574}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010575
Tobin Ehlise0936662016-10-11 08:10:51 -060010576TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10577 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10578 VkResult err;
10579
10580 ASSERT_NO_FATAL_FAILURE(InitState());
10581
10582 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10583 VkImageTiling tiling;
10584 VkFormatProperties format_properties;
10585 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10586 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10587 tiling = VK_IMAGE_TILING_LINEAR;
10588 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10589 tiling = VK_IMAGE_TILING_OPTIMAL;
10590 } else {
10591 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10592 "skipped.\n");
10593 return;
10594 }
10595
10596 VkDescriptorPoolSize ds_type = {};
10597 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10598 ds_type.descriptorCount = 1;
10599
10600 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10601 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10602 ds_pool_ci.maxSets = 1;
10603 ds_pool_ci.poolSizeCount = 1;
10604 ds_pool_ci.pPoolSizes = &ds_type;
10605 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10606
10607 VkDescriptorPool ds_pool;
10608 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10609 ASSERT_VK_SUCCESS(err);
10610
10611 VkDescriptorSetLayoutBinding dsl_binding = {};
10612 dsl_binding.binding = 0;
10613 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10614 dsl_binding.descriptorCount = 1;
10615 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10616 dsl_binding.pImmutableSamplers = NULL;
10617
10618 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10619 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10620 ds_layout_ci.pNext = NULL;
10621 ds_layout_ci.bindingCount = 1;
10622 ds_layout_ci.pBindings = &dsl_binding;
10623
10624 VkDescriptorSetLayout ds_layout;
10625 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10626 ASSERT_VK_SUCCESS(err);
10627
10628 VkDescriptorSetAllocateInfo alloc_info = {};
10629 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10630 alloc_info.descriptorSetCount = 1;
10631 alloc_info.descriptorPool = ds_pool;
10632 alloc_info.pSetLayouts = &ds_layout;
10633 VkDescriptorSet descriptor_set;
10634 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10635 ASSERT_VK_SUCCESS(err);
10636
10637 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10638 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10639 pipeline_layout_ci.pNext = NULL;
10640 pipeline_layout_ci.setLayoutCount = 1;
10641 pipeline_layout_ci.pSetLayouts = &ds_layout;
10642 VkPipelineLayout pipeline_layout;
10643 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10644 ASSERT_VK_SUCCESS(err);
10645
10646 VkImageObj image(m_device);
10647 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10648 ASSERT_TRUE(image.initialized());
10649 VkImageView view = image.targetView(tex_format);
10650
10651 VkDescriptorImageInfo image_info = {};
10652 image_info.imageView = view;
10653 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10654
10655 VkWriteDescriptorSet descriptor_write = {};
10656 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10657 descriptor_write.dstSet = descriptor_set;
10658 descriptor_write.dstBinding = 0;
10659 descriptor_write.descriptorCount = 1;
10660 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10661 descriptor_write.pImageInfo = &image_info;
10662
10663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10664 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10665 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10666 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10667 m_errorMonitor->VerifyFound();
10668
10669 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10670 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10671 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10672 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10673}
10674
Mark Mueller93b938f2016-08-18 10:27:40 -060010675TEST_F(VkLayerTest, SimultaneousUse) {
10676 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10677 "in primary and secondary command buffers.");
10678
10679 ASSERT_NO_FATAL_FAILURE(InitState());
10680 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10681
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010682 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010683 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10684 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010685
10686 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010687 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010688 command_buffer_allocate_info.commandPool = m_commandPool;
10689 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10690 command_buffer_allocate_info.commandBufferCount = 1;
10691
10692 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010693 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010694 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10695 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010696 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010697 command_buffer_inheritance_info.renderPass = m_renderPass;
10698 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10699 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010700 command_buffer_begin_info.flags =
10701 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010702 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10703
10704 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010705 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10706 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010707 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010708 vkEndCommandBuffer(secondary_command_buffer);
10709
Mark Mueller93b938f2016-08-18 10:27:40 -060010710 VkSubmitInfo submit_info = {};
10711 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10712 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010713 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010714 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010715
Mark Mueller4042b652016-09-05 22:52:21 -060010716 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010717 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10719 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010720 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010721 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10722 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010723
10724 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010725 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10726
Mark Mueller4042b652016-09-05 22:52:21 -060010727 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010728 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010729 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010730
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10732 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010733 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010734 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10735 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010736}
10737
Mark Mueller917f6bc2016-08-30 10:57:19 -060010738TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10739 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10740 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010741 "Delete objects that are inuse. Call VkQueueSubmit "
10742 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010743
10744 ASSERT_NO_FATAL_FAILURE(InitState());
10745 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10746
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010747 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10748 const char *cannot_delete_event_message = "Cannot delete event 0x";
10749 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10750 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010751
10752 BeginCommandBuffer();
10753
10754 VkEvent event;
10755 VkEventCreateInfo event_create_info = {};
10756 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10757 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010758 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010759
Mark Muellerc8d441e2016-08-23 17:36:00 -060010760 EndCommandBuffer();
10761 vkDestroyEvent(m_device->device(), event, nullptr);
10762
10763 VkSubmitInfo submit_info = {};
10764 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10765 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010766 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010768 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10769 m_errorMonitor->VerifyFound();
10770
10771 m_errorMonitor->SetDesiredFailureMsg(0, "");
10772 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10773
10774 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10775
Mark Mueller917f6bc2016-08-30 10:57:19 -060010776 VkSemaphoreCreateInfo semaphore_create_info = {};
10777 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10778 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010779 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010780 VkFenceCreateInfo fence_create_info = {};
10781 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10782 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010783 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010784
10785 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010786 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010787 descriptor_pool_type_count.descriptorCount = 1;
10788
10789 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10790 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10791 descriptor_pool_create_info.maxSets = 1;
10792 descriptor_pool_create_info.poolSizeCount = 1;
10793 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010794 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010795
10796 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010797 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010798
10799 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010800 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010801 descriptorset_layout_binding.descriptorCount = 1;
10802 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10803
10804 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010805 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010806 descriptorset_layout_create_info.bindingCount = 1;
10807 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10808
10809 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010810 ASSERT_VK_SUCCESS(
10811 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010812
10813 VkDescriptorSet descriptorset;
10814 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010815 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010816 descriptorset_allocate_info.descriptorSetCount = 1;
10817 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10818 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010819 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010820
Mark Mueller4042b652016-09-05 22:52:21 -060010821 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10822
10823 VkDescriptorBufferInfo buffer_info = {};
10824 buffer_info.buffer = buffer_test.GetBuffer();
10825 buffer_info.offset = 0;
10826 buffer_info.range = 1024;
10827
10828 VkWriteDescriptorSet write_descriptor_set = {};
10829 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10830 write_descriptor_set.dstSet = descriptorset;
10831 write_descriptor_set.descriptorCount = 1;
10832 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10833 write_descriptor_set.pBufferInfo = &buffer_info;
10834
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010835 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010836
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010837 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10838 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010839
10840 VkPipelineObj pipe(m_device);
10841 pipe.AddColorAttachment();
10842 pipe.AddShader(&vs);
10843 pipe.AddShader(&fs);
10844
10845 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010846 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010847 pipeline_layout_create_info.setLayoutCount = 1;
10848 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10849
10850 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010851 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010852
10853 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10854
Mark Muellerc8d441e2016-08-23 17:36:00 -060010855 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010856 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010857
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010858 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10859 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10860 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010861
Mark Muellerc8d441e2016-08-23 17:36:00 -060010862 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010863
Mark Mueller917f6bc2016-08-30 10:57:19 -060010864 submit_info.signalSemaphoreCount = 1;
10865 submit_info.pSignalSemaphores = &semaphore;
10866 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010867
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010869 vkDestroyEvent(m_device->device(), event, nullptr);
10870 m_errorMonitor->VerifyFound();
10871
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010873 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10874 m_errorMonitor->VerifyFound();
10875
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010877 vkDestroyFence(m_device->device(), fence, nullptr);
10878 m_errorMonitor->VerifyFound();
10879
Tobin Ehlis122207b2016-09-01 08:50:06 -070010880 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010881 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10882 vkDestroyFence(m_device->device(), fence, nullptr);
10883 vkDestroyEvent(m_device->device(), event, nullptr);
10884 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010885 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010886 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10887}
10888
Tobin Ehlis2adda372016-09-01 08:51:06 -070010889TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10890 TEST_DESCRIPTION("Delete in-use query pool.");
10891
10892 ASSERT_NO_FATAL_FAILURE(InitState());
10893 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10894
10895 VkQueryPool query_pool;
10896 VkQueryPoolCreateInfo query_pool_ci{};
10897 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10898 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10899 query_pool_ci.queryCount = 1;
10900 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10901 BeginCommandBuffer();
10902 // Reset query pool to create binding with cmd buffer
10903 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10904
10905 EndCommandBuffer();
10906
10907 VkSubmitInfo submit_info = {};
10908 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10909 submit_info.commandBufferCount = 1;
10910 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10911 // Submit cmd buffer and then destroy query pool while in-flight
10912 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10913
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010915 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10916 m_errorMonitor->VerifyFound();
10917
10918 vkQueueWaitIdle(m_device->m_queue);
10919 // Now that cmd buffer done we can safely destroy query_pool
10920 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10921}
10922
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010923TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10924 TEST_DESCRIPTION("Delete in-use pipeline.");
10925
10926 ASSERT_NO_FATAL_FAILURE(InitState());
10927 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10928
10929 // Empty pipeline layout used for binding PSO
10930 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10931 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10932 pipeline_layout_ci.setLayoutCount = 0;
10933 pipeline_layout_ci.pSetLayouts = NULL;
10934
10935 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010936 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010937 ASSERT_VK_SUCCESS(err);
10938
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010940 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010941 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10942 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010943 // Store pipeline handle so we can actually delete it before test finishes
10944 VkPipeline delete_this_pipeline;
10945 { // Scope pipeline so it will be auto-deleted
10946 VkPipelineObj pipe(m_device);
10947 pipe.AddShader(&vs);
10948 pipe.AddShader(&fs);
10949 pipe.AddColorAttachment();
10950 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10951 delete_this_pipeline = pipe.handle();
10952
10953 BeginCommandBuffer();
10954 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010955 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010956
10957 EndCommandBuffer();
10958
10959 VkSubmitInfo submit_info = {};
10960 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10961 submit_info.commandBufferCount = 1;
10962 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10963 // Submit cmd buffer and then pipeline destroyed while in-flight
10964 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10965 } // Pipeline deletion triggered here
10966 m_errorMonitor->VerifyFound();
10967 // Make sure queue finished and then actually delete pipeline
10968 vkQueueWaitIdle(m_device->m_queue);
10969 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10970 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10971}
10972
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010973TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10974 TEST_DESCRIPTION("Delete in-use imageView.");
10975
10976 ASSERT_NO_FATAL_FAILURE(InitState());
10977 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10978
10979 VkDescriptorPoolSize ds_type_count;
10980 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10981 ds_type_count.descriptorCount = 1;
10982
10983 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10984 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10985 ds_pool_ci.maxSets = 1;
10986 ds_pool_ci.poolSizeCount = 1;
10987 ds_pool_ci.pPoolSizes = &ds_type_count;
10988
10989 VkDescriptorPool ds_pool;
10990 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10991 ASSERT_VK_SUCCESS(err);
10992
10993 VkSamplerCreateInfo sampler_ci = {};
10994 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10995 sampler_ci.pNext = NULL;
10996 sampler_ci.magFilter = VK_FILTER_NEAREST;
10997 sampler_ci.minFilter = VK_FILTER_NEAREST;
10998 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10999 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11000 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11001 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11002 sampler_ci.mipLodBias = 1.0;
11003 sampler_ci.anisotropyEnable = VK_FALSE;
11004 sampler_ci.maxAnisotropy = 1;
11005 sampler_ci.compareEnable = VK_FALSE;
11006 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11007 sampler_ci.minLod = 1.0;
11008 sampler_ci.maxLod = 1.0;
11009 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11010 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11011 VkSampler sampler;
11012
11013 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11014 ASSERT_VK_SUCCESS(err);
11015
11016 VkDescriptorSetLayoutBinding layout_binding;
11017 layout_binding.binding = 0;
11018 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11019 layout_binding.descriptorCount = 1;
11020 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11021 layout_binding.pImmutableSamplers = NULL;
11022
11023 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11024 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11025 ds_layout_ci.bindingCount = 1;
11026 ds_layout_ci.pBindings = &layout_binding;
11027 VkDescriptorSetLayout ds_layout;
11028 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11029 ASSERT_VK_SUCCESS(err);
11030
11031 VkDescriptorSetAllocateInfo alloc_info = {};
11032 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11033 alloc_info.descriptorSetCount = 1;
11034 alloc_info.descriptorPool = ds_pool;
11035 alloc_info.pSetLayouts = &ds_layout;
11036 VkDescriptorSet descriptor_set;
11037 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11038 ASSERT_VK_SUCCESS(err);
11039
11040 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11041 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11042 pipeline_layout_ci.pNext = NULL;
11043 pipeline_layout_ci.setLayoutCount = 1;
11044 pipeline_layout_ci.pSetLayouts = &ds_layout;
11045
11046 VkPipelineLayout pipeline_layout;
11047 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11048 ASSERT_VK_SUCCESS(err);
11049
11050 VkImageObj image(m_device);
11051 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11052 ASSERT_TRUE(image.initialized());
11053
11054 VkImageView view;
11055 VkImageViewCreateInfo ivci = {};
11056 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11057 ivci.image = image.handle();
11058 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11059 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11060 ivci.subresourceRange.layerCount = 1;
11061 ivci.subresourceRange.baseMipLevel = 0;
11062 ivci.subresourceRange.levelCount = 1;
11063 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11064
11065 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11066 ASSERT_VK_SUCCESS(err);
11067
11068 VkDescriptorImageInfo image_info{};
11069 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11070 image_info.imageView = view;
11071 image_info.sampler = sampler;
11072
11073 VkWriteDescriptorSet descriptor_write = {};
11074 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11075 descriptor_write.dstSet = descriptor_set;
11076 descriptor_write.dstBinding = 0;
11077 descriptor_write.descriptorCount = 1;
11078 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11079 descriptor_write.pImageInfo = &image_info;
11080
11081 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11082
11083 // Create PSO to use the sampler
11084 char const *vsSource = "#version 450\n"
11085 "\n"
11086 "out gl_PerVertex { \n"
11087 " vec4 gl_Position;\n"
11088 "};\n"
11089 "void main(){\n"
11090 " gl_Position = vec4(1);\n"
11091 "}\n";
11092 char const *fsSource = "#version 450\n"
11093 "\n"
11094 "layout(set=0, binding=0) uniform sampler2D s;\n"
11095 "layout(location=0) out vec4 x;\n"
11096 "void main(){\n"
11097 " x = texture(s, vec2(1));\n"
11098 "}\n";
11099 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11100 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11101 VkPipelineObj pipe(m_device);
11102 pipe.AddShader(&vs);
11103 pipe.AddShader(&fs);
11104 pipe.AddColorAttachment();
11105 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11106
11107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
11108
11109 BeginCommandBuffer();
11110 // Bind pipeline to cmd buffer
11111 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11112 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11113 &descriptor_set, 0, nullptr);
11114 Draw(1, 0, 0, 0);
11115 EndCommandBuffer();
11116 // Submit cmd buffer then destroy sampler
11117 VkSubmitInfo submit_info = {};
11118 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11119 submit_info.commandBufferCount = 1;
11120 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11121 // Submit cmd buffer and then destroy imageView while in-flight
11122 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11123
11124 vkDestroyImageView(m_device->device(), view, nullptr);
11125 m_errorMonitor->VerifyFound();
11126 vkQueueWaitIdle(m_device->m_queue);
11127 // Now we can actually destroy imageView
11128 vkDestroyImageView(m_device->device(), view, NULL);
11129 vkDestroySampler(m_device->device(), sampler, nullptr);
11130 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11131 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11132 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11133}
11134
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011135TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11136 TEST_DESCRIPTION("Delete in-use bufferView.");
11137
11138 ASSERT_NO_FATAL_FAILURE(InitState());
11139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11140
11141 VkDescriptorPoolSize ds_type_count;
11142 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11143 ds_type_count.descriptorCount = 1;
11144
11145 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11146 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11147 ds_pool_ci.maxSets = 1;
11148 ds_pool_ci.poolSizeCount = 1;
11149 ds_pool_ci.pPoolSizes = &ds_type_count;
11150
11151 VkDescriptorPool ds_pool;
11152 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11153 ASSERT_VK_SUCCESS(err);
11154
11155 VkDescriptorSetLayoutBinding layout_binding;
11156 layout_binding.binding = 0;
11157 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11158 layout_binding.descriptorCount = 1;
11159 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11160 layout_binding.pImmutableSamplers = NULL;
11161
11162 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11163 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11164 ds_layout_ci.bindingCount = 1;
11165 ds_layout_ci.pBindings = &layout_binding;
11166 VkDescriptorSetLayout ds_layout;
11167 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11168 ASSERT_VK_SUCCESS(err);
11169
11170 VkDescriptorSetAllocateInfo alloc_info = {};
11171 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11172 alloc_info.descriptorSetCount = 1;
11173 alloc_info.descriptorPool = ds_pool;
11174 alloc_info.pSetLayouts = &ds_layout;
11175 VkDescriptorSet descriptor_set;
11176 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11177 ASSERT_VK_SUCCESS(err);
11178
11179 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11180 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11181 pipeline_layout_ci.pNext = NULL;
11182 pipeline_layout_ci.setLayoutCount = 1;
11183 pipeline_layout_ci.pSetLayouts = &ds_layout;
11184
11185 VkPipelineLayout pipeline_layout;
11186 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11187 ASSERT_VK_SUCCESS(err);
11188
11189 VkBuffer buffer;
11190 uint32_t queue_family_index = 0;
11191 VkBufferCreateInfo buffer_create_info = {};
11192 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11193 buffer_create_info.size = 1024;
11194 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11195 buffer_create_info.queueFamilyIndexCount = 1;
11196 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11197
11198 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11199 ASSERT_VK_SUCCESS(err);
11200
11201 VkMemoryRequirements memory_reqs;
11202 VkDeviceMemory buffer_memory;
11203
11204 VkMemoryAllocateInfo memory_info = {};
11205 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11206 memory_info.allocationSize = 0;
11207 memory_info.memoryTypeIndex = 0;
11208
11209 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11210 memory_info.allocationSize = memory_reqs.size;
11211 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11212 ASSERT_TRUE(pass);
11213
11214 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11215 ASSERT_VK_SUCCESS(err);
11216 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11217 ASSERT_VK_SUCCESS(err);
11218
11219 VkBufferView view;
11220 VkBufferViewCreateInfo bvci = {};
11221 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11222 bvci.buffer = buffer;
11223 bvci.format = VK_FORMAT_R8_UNORM;
11224 bvci.range = VK_WHOLE_SIZE;
11225
11226 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11227 ASSERT_VK_SUCCESS(err);
11228
11229 VkWriteDescriptorSet descriptor_write = {};
11230 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11231 descriptor_write.dstSet = descriptor_set;
11232 descriptor_write.dstBinding = 0;
11233 descriptor_write.descriptorCount = 1;
11234 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11235 descriptor_write.pTexelBufferView = &view;
11236
11237 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11238
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, r8) uniform imageBuffer s;\n"
11250 "layout(location=0) out vec4 x;\n"
11251 "void main(){\n"
11252 " x = imageLoad(s, 0);\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
11262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11263
11264 BeginCommandBuffer();
11265 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11266 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11267 VkRect2D scissor = {{0, 0}, {16, 16}};
11268 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11269 // Bind pipeline to cmd buffer
11270 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11271 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11272 &descriptor_set, 0, nullptr);
11273 Draw(1, 0, 0, 0);
11274 EndCommandBuffer();
11275
11276 VkSubmitInfo submit_info = {};
11277 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11278 submit_info.commandBufferCount = 1;
11279 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11280 // Submit cmd buffer and then destroy bufferView while in-flight
11281 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11282
11283 vkDestroyBufferView(m_device->device(), view, nullptr);
11284 m_errorMonitor->VerifyFound();
11285 vkQueueWaitIdle(m_device->m_queue);
11286 // Now we can actually destroy bufferView
11287 vkDestroyBufferView(m_device->device(), view, NULL);
11288 vkDestroyBuffer(m_device->device(), buffer, NULL);
11289 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11290 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11291 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11292 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11293}
11294
Tobin Ehlis209532e2016-09-07 13:52:18 -060011295TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11296 TEST_DESCRIPTION("Delete in-use sampler.");
11297
11298 ASSERT_NO_FATAL_FAILURE(InitState());
11299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11300
11301 VkDescriptorPoolSize ds_type_count;
11302 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11303 ds_type_count.descriptorCount = 1;
11304
11305 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11306 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11307 ds_pool_ci.maxSets = 1;
11308 ds_pool_ci.poolSizeCount = 1;
11309 ds_pool_ci.pPoolSizes = &ds_type_count;
11310
11311 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011312 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011313 ASSERT_VK_SUCCESS(err);
11314
11315 VkSamplerCreateInfo sampler_ci = {};
11316 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11317 sampler_ci.pNext = NULL;
11318 sampler_ci.magFilter = VK_FILTER_NEAREST;
11319 sampler_ci.minFilter = VK_FILTER_NEAREST;
11320 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11321 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11322 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11323 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11324 sampler_ci.mipLodBias = 1.0;
11325 sampler_ci.anisotropyEnable = VK_FALSE;
11326 sampler_ci.maxAnisotropy = 1;
11327 sampler_ci.compareEnable = VK_FALSE;
11328 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11329 sampler_ci.minLod = 1.0;
11330 sampler_ci.maxLod = 1.0;
11331 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11332 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11333 VkSampler sampler;
11334
11335 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11336 ASSERT_VK_SUCCESS(err);
11337
11338 VkDescriptorSetLayoutBinding layout_binding;
11339 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011340 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011341 layout_binding.descriptorCount = 1;
11342 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11343 layout_binding.pImmutableSamplers = NULL;
11344
11345 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11346 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11347 ds_layout_ci.bindingCount = 1;
11348 ds_layout_ci.pBindings = &layout_binding;
11349 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011350 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011351 ASSERT_VK_SUCCESS(err);
11352
11353 VkDescriptorSetAllocateInfo alloc_info = {};
11354 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11355 alloc_info.descriptorSetCount = 1;
11356 alloc_info.descriptorPool = ds_pool;
11357 alloc_info.pSetLayouts = &ds_layout;
11358 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011359 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011360 ASSERT_VK_SUCCESS(err);
11361
11362 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11363 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11364 pipeline_layout_ci.pNext = NULL;
11365 pipeline_layout_ci.setLayoutCount = 1;
11366 pipeline_layout_ci.pSetLayouts = &ds_layout;
11367
11368 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011369 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011370 ASSERT_VK_SUCCESS(err);
11371
11372 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011373 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 -060011374 ASSERT_TRUE(image.initialized());
11375
11376 VkImageView view;
11377 VkImageViewCreateInfo ivci = {};
11378 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11379 ivci.image = image.handle();
11380 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11381 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11382 ivci.subresourceRange.layerCount = 1;
11383 ivci.subresourceRange.baseMipLevel = 0;
11384 ivci.subresourceRange.levelCount = 1;
11385 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11386
11387 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11388 ASSERT_VK_SUCCESS(err);
11389
11390 VkDescriptorImageInfo image_info{};
11391 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11392 image_info.imageView = view;
11393 image_info.sampler = sampler;
11394
11395 VkWriteDescriptorSet descriptor_write = {};
11396 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11397 descriptor_write.dstSet = descriptor_set;
11398 descriptor_write.dstBinding = 0;
11399 descriptor_write.descriptorCount = 1;
11400 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11401 descriptor_write.pImageInfo = &image_info;
11402
11403 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11404
11405 // Create PSO to use the sampler
11406 char const *vsSource = "#version 450\n"
11407 "\n"
11408 "out gl_PerVertex { \n"
11409 " vec4 gl_Position;\n"
11410 "};\n"
11411 "void main(){\n"
11412 " gl_Position = vec4(1);\n"
11413 "}\n";
11414 char const *fsSource = "#version 450\n"
11415 "\n"
11416 "layout(set=0, binding=0) uniform sampler2D s;\n"
11417 "layout(location=0) out vec4 x;\n"
11418 "void main(){\n"
11419 " x = texture(s, vec2(1));\n"
11420 "}\n";
11421 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11422 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11423 VkPipelineObj pipe(m_device);
11424 pipe.AddShader(&vs);
11425 pipe.AddShader(&fs);
11426 pipe.AddColorAttachment();
11427 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11428
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011430
11431 BeginCommandBuffer();
11432 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011433 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11434 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11435 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011436 Draw(1, 0, 0, 0);
11437 EndCommandBuffer();
11438 // Submit cmd buffer then destroy sampler
11439 VkSubmitInfo submit_info = {};
11440 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11441 submit_info.commandBufferCount = 1;
11442 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11443 // Submit cmd buffer and then destroy sampler while in-flight
11444 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11445
11446 vkDestroySampler(m_device->device(), sampler, nullptr);
11447 m_errorMonitor->VerifyFound();
11448 vkQueueWaitIdle(m_device->m_queue);
11449 // Now we can actually destroy sampler
11450 vkDestroySampler(m_device->device(), sampler, nullptr);
11451 vkDestroyImageView(m_device->device(), view, NULL);
11452 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11453 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11454 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11455}
11456
Mark Mueller1cd9f412016-08-25 13:23:52 -060011457TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011458 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011459 "signaled but not waited on by the queue. Wait on a "
11460 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011461
11462 ASSERT_NO_FATAL_FAILURE(InitState());
11463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11464
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011465 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11466 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11467 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011468
11469 BeginCommandBuffer();
11470 EndCommandBuffer();
11471
11472 VkSemaphoreCreateInfo semaphore_create_info = {};
11473 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11474 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011475 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011476 VkSubmitInfo submit_info = {};
11477 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11478 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011479 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011480 submit_info.signalSemaphoreCount = 1;
11481 submit_info.pSignalSemaphores = &semaphore;
11482 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11483 m_errorMonitor->SetDesiredFailureMsg(0, "");
11484 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11485 BeginCommandBuffer();
11486 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011488 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11489 m_errorMonitor->VerifyFound();
11490
Mark Mueller1cd9f412016-08-25 13:23:52 -060011491 VkFenceCreateInfo fence_create_info = {};
11492 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11493 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011494 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011495
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011497 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11498 m_errorMonitor->VerifyFound();
11499
Mark Mueller4042b652016-09-05 22:52:21 -060011500 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011501 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011502 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11503}
11504
Tobin Ehlis4af23302016-07-19 10:50:30 -060011505TEST_F(VkLayerTest, FramebufferIncompatible) {
11506 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11507 "that does not match the framebuffer for the active "
11508 "renderpass.");
11509 ASSERT_NO_FATAL_FAILURE(InitState());
11510 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11511
11512 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011513 VkAttachmentDescription attachment = {0,
11514 VK_FORMAT_B8G8R8A8_UNORM,
11515 VK_SAMPLE_COUNT_1_BIT,
11516 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11517 VK_ATTACHMENT_STORE_OP_STORE,
11518 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11519 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11520 VK_IMAGE_LAYOUT_UNDEFINED,
11521 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011522
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011523 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011524
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011525 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011526
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011527 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011528
11529 VkRenderPass rp;
11530 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11531 ASSERT_VK_SUCCESS(err);
11532
11533 // A compatible framebuffer.
11534 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011535 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 -060011536 ASSERT_TRUE(image.initialized());
11537
11538 VkImageViewCreateInfo ivci = {
11539 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11540 nullptr,
11541 0,
11542 image.handle(),
11543 VK_IMAGE_VIEW_TYPE_2D,
11544 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011545 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11546 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011547 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11548 };
11549 VkImageView view;
11550 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11551 ASSERT_VK_SUCCESS(err);
11552
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011553 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011554 VkFramebuffer fb;
11555 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11556 ASSERT_VK_SUCCESS(err);
11557
11558 VkCommandBufferAllocateInfo cbai = {};
11559 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11560 cbai.commandPool = m_commandPool;
11561 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11562 cbai.commandBufferCount = 1;
11563
11564 VkCommandBuffer sec_cb;
11565 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11566 ASSERT_VK_SUCCESS(err);
11567 VkCommandBufferBeginInfo cbbi = {};
11568 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130011569 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060011570 cbii.renderPass = renderPass();
11571 cbii.framebuffer = fb;
11572 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11573 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011574 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 -060011575 cbbi.pInheritanceInfo = &cbii;
11576 vkBeginCommandBuffer(sec_cb, &cbbi);
11577 vkEndCommandBuffer(sec_cb);
11578
Chris Forbes3400bc52016-09-13 18:10:34 +120011579 VkCommandBufferBeginInfo cbbi2 = {
11580 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11581 0, nullptr
11582 };
11583 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11584 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011585
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011587 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011588 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11589 m_errorMonitor->VerifyFound();
11590 // Cleanup
11591 vkDestroyImageView(m_device->device(), view, NULL);
11592 vkDestroyRenderPass(m_device->device(), rp, NULL);
11593 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11594}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011595
11596TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11597 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11598 "invalid value. If logicOp is not available, attempt to "
11599 "use it and verify that we see the correct error.");
11600 ASSERT_NO_FATAL_FAILURE(InitState());
11601 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11602
11603 auto features = m_device->phy().features();
11604 // Set the expected error depending on whether or not logicOp available
11605 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11607 "enabled, logicOpEnable must be "
11608 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011609 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011611 }
11612 // Create a pipeline using logicOp
11613 VkResult err;
11614
11615 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11616 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11617
11618 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011619 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011620 ASSERT_VK_SUCCESS(err);
11621
11622 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11623 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11624 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011625 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011626 vp_state_ci.pViewports = &vp;
11627 vp_state_ci.scissorCount = 1;
11628 VkRect2D scissors = {}; // Dummy scissors to point to
11629 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011630
11631 VkPipelineShaderStageCreateInfo shaderStages[2];
11632 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11633
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011634 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11635 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011636 shaderStages[0] = vs.GetStageCreateInfo();
11637 shaderStages[1] = fs.GetStageCreateInfo();
11638
11639 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11640 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11641
11642 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11643 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11644 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11645
11646 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11647 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011648 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011649
11650 VkPipelineColorBlendAttachmentState att = {};
11651 att.blendEnable = VK_FALSE;
11652 att.colorWriteMask = 0xf;
11653
11654 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11655 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11656 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11657 cb_ci.logicOpEnable = VK_TRUE;
11658 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11659 cb_ci.attachmentCount = 1;
11660 cb_ci.pAttachments = &att;
11661
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011662 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11663 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11664 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11665
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011666 VkGraphicsPipelineCreateInfo gp_ci = {};
11667 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11668 gp_ci.stageCount = 2;
11669 gp_ci.pStages = shaderStages;
11670 gp_ci.pVertexInputState = &vi_ci;
11671 gp_ci.pInputAssemblyState = &ia_ci;
11672 gp_ci.pViewportState = &vp_state_ci;
11673 gp_ci.pRasterizationState = &rs_ci;
11674 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011675 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011676 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11677 gp_ci.layout = pipeline_layout;
11678 gp_ci.renderPass = renderPass();
11679
11680 VkPipelineCacheCreateInfo pc_ci = {};
11681 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11682
11683 VkPipeline pipeline;
11684 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011685 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011686 ASSERT_VK_SUCCESS(err);
11687
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011688 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011689 m_errorMonitor->VerifyFound();
11690 if (VK_SUCCESS == err) {
11691 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11692 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011693 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11694 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11695}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011696#endif // DRAW_STATE_TESTS
11697
Tobin Ehlis0788f522015-05-26 16:11:58 -060011698#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011699#if GTEST_IS_THREADSAFE
11700struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011701 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011702 VkEvent event;
11703 bool bailout;
11704};
11705
Karl Schultz6addd812016-02-02 17:17:23 -070011706extern "C" void *AddToCommandBuffer(void *arg) {
11707 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011708
Mike Stroyana6d14942016-07-13 15:10:05 -060011709 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011710 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011711 if (data->bailout) {
11712 break;
11713 }
11714 }
11715 return NULL;
11716}
11717
Karl Schultz6addd812016-02-02 17:17:23 -070011718TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011719 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011720
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011722
Mike Stroyanaccf7692015-05-12 16:00:45 -060011723 ASSERT_NO_FATAL_FAILURE(InitState());
11724 ASSERT_NO_FATAL_FAILURE(InitViewport());
11725 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11726
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011727 // Calls AllocateCommandBuffers
11728 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011729
11730 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011731 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011732
11733 VkEventCreateInfo event_info;
11734 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011735 VkResult err;
11736
11737 memset(&event_info, 0, sizeof(event_info));
11738 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11739
Chia-I Wuf7458c52015-10-26 21:10:41 +080011740 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011741 ASSERT_VK_SUCCESS(err);
11742
Mike Stroyanaccf7692015-05-12 16:00:45 -060011743 err = vkResetEvent(device(), event);
11744 ASSERT_VK_SUCCESS(err);
11745
11746 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011747 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011748 data.event = event;
11749 data.bailout = false;
11750 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011751
11752 // First do some correct operations using multiple threads.
11753 // Add many entries to command buffer from another thread.
11754 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11755 // Make non-conflicting calls from this thread at the same time.
11756 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011757 uint32_t count;
11758 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011759 }
11760 test_platform_thread_join(thread, NULL);
11761
11762 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011763 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011764 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011765 // Add many entries to command buffer from this thread at the same time.
11766 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011767
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011768 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011769 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011770
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011771 m_errorMonitor->SetBailout(NULL);
11772
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011773 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011774
Chia-I Wuf7458c52015-10-26 21:10:41 +080011775 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011776}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011777#endif // GTEST_IS_THREADSAFE
11778#endif // THREADING_TESTS
11779
Chris Forbes9f7ff632015-05-25 11:13:08 +120011780#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011781TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011782 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11783 "with an impossible code size");
11784
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011786
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011787 ASSERT_NO_FATAL_FAILURE(InitState());
11788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11789
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011790 VkShaderModule module;
11791 VkShaderModuleCreateInfo moduleCreateInfo;
11792 struct icd_spv_header spv;
11793
11794 spv.magic = ICD_SPV_MAGIC;
11795 spv.version = ICD_SPV_VERSION;
11796 spv.gen_magic = 0;
11797
11798 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11799 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011800 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011801 moduleCreateInfo.codeSize = 4;
11802 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011803 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011804
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011805 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011806}
11807
Karl Schultz6addd812016-02-02 17:17:23 -070011808TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011809 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11810 "with a bad magic number");
11811
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011813
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011814 ASSERT_NO_FATAL_FAILURE(InitState());
11815 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11816
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011817 VkShaderModule module;
11818 VkShaderModuleCreateInfo moduleCreateInfo;
11819 struct icd_spv_header spv;
11820
11821 spv.magic = ~ICD_SPV_MAGIC;
11822 spv.version = ICD_SPV_VERSION;
11823 spv.gen_magic = 0;
11824
11825 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11826 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011827 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011828 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11829 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011830 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011831
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011832 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011833}
11834
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011835#if 0
11836// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011837TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011839 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011840
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011841 ASSERT_NO_FATAL_FAILURE(InitState());
11842 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11843
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011844 VkShaderModule module;
11845 VkShaderModuleCreateInfo moduleCreateInfo;
11846 struct icd_spv_header spv;
11847
11848 spv.magic = ICD_SPV_MAGIC;
11849 spv.version = ~ICD_SPV_VERSION;
11850 spv.gen_magic = 0;
11851
11852 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11853 moduleCreateInfo.pNext = NULL;
11854
Karl Schultz6addd812016-02-02 17:17:23 -070011855 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011856 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11857 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011858 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011859
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011860 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011861}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011862#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011863
Karl Schultz6addd812016-02-02 17:17:23 -070011864TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011865 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11866 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011868
Chris Forbes9f7ff632015-05-25 11:13:08 +120011869 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011870 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011871
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011872 char const *vsSource = "#version 450\n"
11873 "\n"
11874 "layout(location=0) out float x;\n"
11875 "out gl_PerVertex {\n"
11876 " vec4 gl_Position;\n"
11877 "};\n"
11878 "void main(){\n"
11879 " gl_Position = vec4(1);\n"
11880 " x = 0;\n"
11881 "}\n";
11882 char const *fsSource = "#version 450\n"
11883 "\n"
11884 "layout(location=0) out vec4 color;\n"
11885 "void main(){\n"
11886 " color = vec4(1);\n"
11887 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011888
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011889 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11890 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011891
11892 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011893 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011894 pipe.AddShader(&vs);
11895 pipe.AddShader(&fs);
11896
Chris Forbes9f7ff632015-05-25 11:13:08 +120011897 VkDescriptorSetObj descriptorSet(m_device);
11898 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011899 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011900
Tony Barbour5781e8f2015-08-04 16:23:11 -060011901 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011902
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011903 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011904}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011905
Mark Mueller098c9cb2016-09-08 09:01:57 -060011906TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11907 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11908
11909 ASSERT_NO_FATAL_FAILURE(InitState());
11910 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11911
11912 const char *bad_specialization_message =
11913 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11914
11915 char const *vsSource =
11916 "#version 450\n"
11917 "\n"
11918 "out gl_PerVertex {\n"
11919 " vec4 gl_Position;\n"
11920 "};\n"
11921 "void main(){\n"
11922 " gl_Position = vec4(1);\n"
11923 "}\n";
11924
11925 char const *fsSource =
11926 "#version 450\n"
11927 "\n"
11928 "layout (constant_id = 0) const float r = 0.0f;\n"
11929 "layout(location = 0) out vec4 uFragColor;\n"
11930 "void main(){\n"
11931 " uFragColor = vec4(r,1,0,1);\n"
11932 "}\n";
11933
11934 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11935 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11936
11937 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11938 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11939
11940 VkPipelineLayout pipeline_layout;
11941 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11942
11943 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11944 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11945 vp_state_create_info.viewportCount = 1;
11946 VkViewport viewport = {};
11947 vp_state_create_info.pViewports = &viewport;
11948 vp_state_create_info.scissorCount = 1;
11949 VkRect2D scissors = {};
11950 vp_state_create_info.pScissors = &scissors;
11951
11952 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11953
11954 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11955 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11956 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11957 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11958
11959 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11960 vs.GetStageCreateInfo(),
11961 fs.GetStageCreateInfo()
11962 };
11963
11964 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11965 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11966
11967 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11968 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11969 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11970
11971 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11972 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11973 rasterization_state_create_info.pNext = nullptr;
11974 rasterization_state_create_info.lineWidth = 1.0f;
11975 rasterization_state_create_info.rasterizerDiscardEnable = true;
11976
11977 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11978 color_blend_attachment_state.blendEnable = VK_FALSE;
11979 color_blend_attachment_state.colorWriteMask = 0xf;
11980
11981 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11982 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11983 color_blend_state_create_info.attachmentCount = 1;
11984 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11985
11986 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11987 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11988 graphicspipe_create_info.stageCount = 2;
11989 graphicspipe_create_info.pStages = shader_stage_create_info;
11990 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11991 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11992 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11993 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11994 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11995 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11996 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11997 graphicspipe_create_info.layout = pipeline_layout;
11998 graphicspipe_create_info.renderPass = renderPass();
11999
12000 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12001 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12002
12003 VkPipelineCache pipelineCache;
12004 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12005
12006 // This structure maps constant ids to data locations.
12007 const VkSpecializationMapEntry entry =
12008 // id, offset, size
12009 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12010
12011 uint32_t data = 1;
12012
12013 // Set up the info describing spec map and data
12014 const VkSpecializationInfo specialization_info = {
12015 1,
12016 &entry,
12017 1 * sizeof(float),
12018 &data,
12019 };
12020 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12021
12022 VkPipeline pipeline;
12023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12024 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12025 m_errorMonitor->VerifyFound();
12026
12027 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12028 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12029}
12030
12031TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12032 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12033
12034 ASSERT_NO_FATAL_FAILURE(InitState());
12035 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12036
12037 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12038
12039 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12040 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12041 descriptor_pool_type_count[0].descriptorCount = 1;
12042 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12043 descriptor_pool_type_count[1].descriptorCount = 1;
12044
12045 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12046 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12047 descriptor_pool_create_info.maxSets = 1;
12048 descriptor_pool_create_info.poolSizeCount = 2;
12049 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12050 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12051
12052 VkDescriptorPool descriptorset_pool;
12053 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12054
12055 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12056 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12057 descriptorset_layout_binding.descriptorCount = 1;
12058 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12059
12060 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12061 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12062 descriptorset_layout_create_info.bindingCount = 1;
12063 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12064
12065 VkDescriptorSetLayout descriptorset_layout;
12066 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12067
12068 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12069 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12070 descriptorset_allocate_info.descriptorSetCount = 1;
12071 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12072 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12073 VkDescriptorSet descriptorset;
12074 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12075
12076 // Challenge core_validation with a non uniform buffer type.
12077 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12078
Mark Mueller098c9cb2016-09-08 09:01:57 -060012079 char const *vsSource =
12080 "#version 450\n"
12081 "\n"
12082 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12083 " mat4 mvp;\n"
12084 "} ubuf;\n"
12085 "out gl_PerVertex {\n"
12086 " vec4 gl_Position;\n"
12087 "};\n"
12088 "void main(){\n"
12089 " gl_Position = ubuf.mvp * vec4(1);\n"
12090 "}\n";
12091
12092 char const *fsSource =
12093 "#version 450\n"
12094 "\n"
12095 "layout(location = 0) out vec4 uFragColor;\n"
12096 "void main(){\n"
12097 " uFragColor = vec4(0,1,0,1);\n"
12098 "}\n";
12099
12100 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12101 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12102
12103 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12104 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12105 pipeline_layout_create_info.setLayoutCount = 1;
12106 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12107
12108 VkPipelineLayout pipeline_layout;
12109 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12110
12111 VkPipelineObj pipe(m_device);
12112 pipe.AddColorAttachment();
12113 pipe.AddShader(&vs);
12114 pipe.AddShader(&fs);
12115
12116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12117 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12118 m_errorMonitor->VerifyFound();
12119
12120 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12121 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12122 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12123}
12124
12125TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12126 TEST_DESCRIPTION(
12127 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12128
12129 ASSERT_NO_FATAL_FAILURE(InitState());
12130 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12131
12132 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12133
12134 VkDescriptorPoolSize descriptor_pool_type_count = {};
12135 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12136 descriptor_pool_type_count.descriptorCount = 1;
12137
12138 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12139 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12140 descriptor_pool_create_info.maxSets = 1;
12141 descriptor_pool_create_info.poolSizeCount = 1;
12142 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12143 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12144
12145 VkDescriptorPool descriptorset_pool;
12146 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12147
12148 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12149 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12150 descriptorset_layout_binding.descriptorCount = 1;
12151 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12152 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12153
12154 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12155 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12156 descriptorset_layout_create_info.bindingCount = 1;
12157 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12158
12159 VkDescriptorSetLayout descriptorset_layout;
12160 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12161 nullptr, &descriptorset_layout));
12162
12163 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12164 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12165 descriptorset_allocate_info.descriptorSetCount = 1;
12166 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12167 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12168 VkDescriptorSet descriptorset;
12169 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12170
12171 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12172
Mark Mueller098c9cb2016-09-08 09:01:57 -060012173 char const *vsSource =
12174 "#version 450\n"
12175 "\n"
12176 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12177 " mat4 mvp;\n"
12178 "} ubuf;\n"
12179 "out gl_PerVertex {\n"
12180 " vec4 gl_Position;\n"
12181 "};\n"
12182 "void main(){\n"
12183 " gl_Position = ubuf.mvp * vec4(1);\n"
12184 "}\n";
12185
12186 char const *fsSource =
12187 "#version 450\n"
12188 "\n"
12189 "layout(location = 0) out vec4 uFragColor;\n"
12190 "void main(){\n"
12191 " uFragColor = vec4(0,1,0,1);\n"
12192 "}\n";
12193
12194 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12195 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12196
12197 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12198 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12199 pipeline_layout_create_info.setLayoutCount = 1;
12200 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12201
12202 VkPipelineLayout pipeline_layout;
12203 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12204
12205 VkPipelineObj pipe(m_device);
12206 pipe.AddColorAttachment();
12207 pipe.AddShader(&vs);
12208 pipe.AddShader(&fs);
12209
12210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12211 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12212 m_errorMonitor->VerifyFound();
12213
12214 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12215 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12216 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12217}
12218
12219TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12220 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12221 "accessible from the current shader stage.");
12222
12223 ASSERT_NO_FATAL_FAILURE(InitState());
12224 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12225
12226 const char *push_constant_not_accessible_message =
12227 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12228
12229 char const *vsSource =
12230 "#version 450\n"
12231 "\n"
12232 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12233 "out gl_PerVertex {\n"
12234 " vec4 gl_Position;\n"
12235 "};\n"
12236 "void main(){\n"
12237 " gl_Position = vec4(consts.x);\n"
12238 "}\n";
12239
12240 char const *fsSource =
12241 "#version 450\n"
12242 "\n"
12243 "layout(location = 0) out vec4 uFragColor;\n"
12244 "void main(){\n"
12245 " uFragColor = vec4(0,1,0,1);\n"
12246 "}\n";
12247
12248 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12249 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12250
12251 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12252 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12253
12254 // Set up a push constant range
12255 VkPushConstantRange push_constant_ranges = {};
12256 // Set to the wrong stage to challenge core_validation
12257 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12258 push_constant_ranges.size = 4;
12259
12260 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12261 pipeline_layout_create_info.pushConstantRangeCount = 1;
12262
12263 VkPipelineLayout pipeline_layout;
12264 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12265
12266 VkPipelineObj pipe(m_device);
12267 pipe.AddColorAttachment();
12268 pipe.AddShader(&vs);
12269 pipe.AddShader(&fs);
12270
12271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12272 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12273 m_errorMonitor->VerifyFound();
12274
12275 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12276}
12277
12278TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12279 TEST_DESCRIPTION(
12280 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12281
12282 ASSERT_NO_FATAL_FAILURE(InitState());
12283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12284
12285 const char *feature_not_enabled_message =
12286 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12287
12288 // Some awkward steps are required to test with custom device features.
12289 std::vector<const char *> device_extension_names;
12290 auto features = m_device->phy().features();
12291 // Disable support for 64 bit floats
12292 features.shaderFloat64 = false;
12293 // The sacrificial device object
12294 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12295
12296 char const *vsSource = "#version 450\n"
12297 "\n"
12298 "out gl_PerVertex {\n"
12299 " vec4 gl_Position;\n"
12300 "};\n"
12301 "void main(){\n"
12302 " gl_Position = vec4(1);\n"
12303 "}\n";
12304 char const *fsSource = "#version 450\n"
12305 "\n"
12306 "layout(location=0) out vec4 color;\n"
12307 "void main(){\n"
12308 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12309 " color = vec4(green);\n"
12310 "}\n";
12311
12312 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12313 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12314
12315 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012316
12317 VkPipelineObj pipe(&test_device);
12318 pipe.AddColorAttachment();
12319 pipe.AddShader(&vs);
12320 pipe.AddShader(&fs);
12321
12322 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12323 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12324 VkPipelineLayout pipeline_layout;
12325 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12326
12327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12328 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12329 m_errorMonitor->VerifyFound();
12330
12331 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12332}
12333
12334TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12335 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12336
12337 ASSERT_NO_FATAL_FAILURE(InitState());
12338 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12339
12340 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12341
12342 char const *vsSource = "#version 450\n"
12343 "\n"
12344 "out gl_PerVertex {\n"
12345 " vec4 gl_Position;\n"
12346 "};\n"
12347 "layout(xfb_buffer = 1) out;"
12348 "void main(){\n"
12349 " gl_Position = vec4(1);\n"
12350 "}\n";
12351 char const *fsSource = "#version 450\n"
12352 "\n"
12353 "layout(location=0) out vec4 color;\n"
12354 "void main(){\n"
12355 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12356 " color = vec4(green);\n"
12357 "}\n";
12358
12359 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12360 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12361
12362 VkPipelineObj pipe(m_device);
12363 pipe.AddColorAttachment();
12364 pipe.AddShader(&vs);
12365 pipe.AddShader(&fs);
12366
12367 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12368 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12369 VkPipelineLayout pipeline_layout;
12370 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12371
12372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12373 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12374 m_errorMonitor->VerifyFound();
12375
12376 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12377}
12378
Karl Schultz6addd812016-02-02 17:17:23 -070012379TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012380 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12381 "which is not present in the outputs of the previous stage");
12382
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012384
Chris Forbes59cb88d2015-05-25 11:13:13 +120012385 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012388 char const *vsSource = "#version 450\n"
12389 "\n"
12390 "out gl_PerVertex {\n"
12391 " vec4 gl_Position;\n"
12392 "};\n"
12393 "void main(){\n"
12394 " gl_Position = vec4(1);\n"
12395 "}\n";
12396 char const *fsSource = "#version 450\n"
12397 "\n"
12398 "layout(location=0) in float x;\n"
12399 "layout(location=0) out vec4 color;\n"
12400 "void main(){\n"
12401 " color = vec4(x);\n"
12402 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012403
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012404 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12405 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012406
12407 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012408 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012409 pipe.AddShader(&vs);
12410 pipe.AddShader(&fs);
12411
Chris Forbes59cb88d2015-05-25 11:13:13 +120012412 VkDescriptorSetObj descriptorSet(m_device);
12413 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012414 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012415
Tony Barbour5781e8f2015-08-04 16:23:11 -060012416 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012417
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012418 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012419}
12420
Karl Schultz6addd812016-02-02 17:17:23 -070012421TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012422 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12423 "within an interace block, which is not present in the outputs "
12424 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012426
12427 ASSERT_NO_FATAL_FAILURE(InitState());
12428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12429
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012430 char const *vsSource = "#version 450\n"
12431 "\n"
12432 "out gl_PerVertex {\n"
12433 " vec4 gl_Position;\n"
12434 "};\n"
12435 "void main(){\n"
12436 " gl_Position = vec4(1);\n"
12437 "}\n";
12438 char const *fsSource = "#version 450\n"
12439 "\n"
12440 "in block { layout(location=0) float x; } ins;\n"
12441 "layout(location=0) out vec4 color;\n"
12442 "void main(){\n"
12443 " color = vec4(ins.x);\n"
12444 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012445
12446 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12447 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12448
12449 VkPipelineObj pipe(m_device);
12450 pipe.AddColorAttachment();
12451 pipe.AddShader(&vs);
12452 pipe.AddShader(&fs);
12453
12454 VkDescriptorSetObj descriptorSet(m_device);
12455 descriptorSet.AppendDummy();
12456 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12457
12458 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12459
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012460 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012461}
12462
Karl Schultz6addd812016-02-02 17:17:23 -070012463TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012464 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012465 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12467 "output arr[2] of float32' vs 'ptr to "
12468 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012469
12470 ASSERT_NO_FATAL_FAILURE(InitState());
12471 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12472
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012473 char const *vsSource = "#version 450\n"
12474 "\n"
12475 "layout(location=0) out float x[2];\n"
12476 "out gl_PerVertex {\n"
12477 " vec4 gl_Position;\n"
12478 "};\n"
12479 "void main(){\n"
12480 " x[0] = 0; x[1] = 0;\n"
12481 " gl_Position = vec4(1);\n"
12482 "}\n";
12483 char const *fsSource = "#version 450\n"
12484 "\n"
12485 "layout(location=0) in float x[3];\n"
12486 "layout(location=0) out vec4 color;\n"
12487 "void main(){\n"
12488 " color = vec4(x[0] + x[1] + x[2]);\n"
12489 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012490
12491 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12492 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12493
12494 VkPipelineObj pipe(m_device);
12495 pipe.AddColorAttachment();
12496 pipe.AddShader(&vs);
12497 pipe.AddShader(&fs);
12498
12499 VkDescriptorSetObj descriptorSet(m_device);
12500 descriptorSet.AppendDummy();
12501 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12502
12503 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12504
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012505 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012506}
12507
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012508
Karl Schultz6addd812016-02-02 17:17:23 -070012509TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012510 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012511 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012513
Chris Forbesb56af562015-05-25 11:13:17 +120012514 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012516
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012517 char const *vsSource = "#version 450\n"
12518 "\n"
12519 "layout(location=0) out int x;\n"
12520 "out gl_PerVertex {\n"
12521 " vec4 gl_Position;\n"
12522 "};\n"
12523 "void main(){\n"
12524 " x = 0;\n"
12525 " gl_Position = vec4(1);\n"
12526 "}\n";
12527 char const *fsSource = "#version 450\n"
12528 "\n"
12529 "layout(location=0) in float x;\n" /* VS writes int */
12530 "layout(location=0) out vec4 color;\n"
12531 "void main(){\n"
12532 " color = vec4(x);\n"
12533 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012534
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012535 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12536 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012537
12538 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012539 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012540 pipe.AddShader(&vs);
12541 pipe.AddShader(&fs);
12542
Chris Forbesb56af562015-05-25 11:13:17 +120012543 VkDescriptorSetObj descriptorSet(m_device);
12544 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012545 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012546
Tony Barbour5781e8f2015-08-04 16:23:11 -060012547 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012548
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012549 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012550}
12551
Karl Schultz6addd812016-02-02 17:17:23 -070012552TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012553 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012554 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012555 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012557
12558 ASSERT_NO_FATAL_FAILURE(InitState());
12559 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12560
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012561 char const *vsSource = "#version 450\n"
12562 "\n"
12563 "out block { layout(location=0) int x; } outs;\n"
12564 "out gl_PerVertex {\n"
12565 " vec4 gl_Position;\n"
12566 "};\n"
12567 "void main(){\n"
12568 " outs.x = 0;\n"
12569 " gl_Position = vec4(1);\n"
12570 "}\n";
12571 char const *fsSource = "#version 450\n"
12572 "\n"
12573 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12574 "layout(location=0) out vec4 color;\n"
12575 "void main(){\n"
12576 " color = vec4(ins.x);\n"
12577 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012578
12579 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12580 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12581
12582 VkPipelineObj pipe(m_device);
12583 pipe.AddColorAttachment();
12584 pipe.AddShader(&vs);
12585 pipe.AddShader(&fs);
12586
12587 VkDescriptorSetObj descriptorSet(m_device);
12588 descriptorSet.AppendDummy();
12589 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12590
12591 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12592
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012593 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012594}
12595
12596TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012597 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012598 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012599 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012600 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 +130012601
12602 ASSERT_NO_FATAL_FAILURE(InitState());
12603 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12604
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012605 char const *vsSource = "#version 450\n"
12606 "\n"
12607 "out block { layout(location=1) float x; } outs;\n"
12608 "out gl_PerVertex {\n"
12609 " vec4 gl_Position;\n"
12610 "};\n"
12611 "void main(){\n"
12612 " outs.x = 0;\n"
12613 " gl_Position = vec4(1);\n"
12614 "}\n";
12615 char const *fsSource = "#version 450\n"
12616 "\n"
12617 "in block { layout(location=0) float x; } ins;\n"
12618 "layout(location=0) out vec4 color;\n"
12619 "void main(){\n"
12620 " color = vec4(ins.x);\n"
12621 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012622
12623 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12624 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12625
12626 VkPipelineObj pipe(m_device);
12627 pipe.AddColorAttachment();
12628 pipe.AddShader(&vs);
12629 pipe.AddShader(&fs);
12630
12631 VkDescriptorSetObj descriptorSet(m_device);
12632 descriptorSet.AppendDummy();
12633 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12634
12635 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12636
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012637 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012638}
12639
12640TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012641 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012642 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012643 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012644 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 +130012645
12646 ASSERT_NO_FATAL_FAILURE(InitState());
12647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12648
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012649 char const *vsSource = "#version 450\n"
12650 "\n"
12651 "out block { layout(location=0, component=0) float x; } outs;\n"
12652 "out gl_PerVertex {\n"
12653 " vec4 gl_Position;\n"
12654 "};\n"
12655 "void main(){\n"
12656 " outs.x = 0;\n"
12657 " gl_Position = vec4(1);\n"
12658 "}\n";
12659 char const *fsSource = "#version 450\n"
12660 "\n"
12661 "in block { layout(location=0, component=1) float x; } ins;\n"
12662 "layout(location=0) out vec4 color;\n"
12663 "void main(){\n"
12664 " color = vec4(ins.x);\n"
12665 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012666
12667 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12668 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12669
12670 VkPipelineObj pipe(m_device);
12671 pipe.AddColorAttachment();
12672 pipe.AddShader(&vs);
12673 pipe.AddShader(&fs);
12674
12675 VkDescriptorSetObj descriptorSet(m_device);
12676 descriptorSet.AppendDummy();
12677 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12678
12679 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12680
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012681 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012682}
12683
Karl Schultz6addd812016-02-02 17:17:23 -070012684TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012685 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12686 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012688
Chris Forbesde136e02015-05-25 11:13:28 +120012689 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012690 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012691
12692 VkVertexInputBindingDescription input_binding;
12693 memset(&input_binding, 0, sizeof(input_binding));
12694
12695 VkVertexInputAttributeDescription input_attrib;
12696 memset(&input_attrib, 0, sizeof(input_attrib));
12697 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12698
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012699 char const *vsSource = "#version 450\n"
12700 "\n"
12701 "out gl_PerVertex {\n"
12702 " vec4 gl_Position;\n"
12703 "};\n"
12704 "void main(){\n"
12705 " gl_Position = vec4(1);\n"
12706 "}\n";
12707 char const *fsSource = "#version 450\n"
12708 "\n"
12709 "layout(location=0) out vec4 color;\n"
12710 "void main(){\n"
12711 " color = vec4(1);\n"
12712 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012713
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012714 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12715 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012716
12717 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012718 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012719 pipe.AddShader(&vs);
12720 pipe.AddShader(&fs);
12721
12722 pipe.AddVertexInputBindings(&input_binding, 1);
12723 pipe.AddVertexInputAttribs(&input_attrib, 1);
12724
Chris Forbesde136e02015-05-25 11:13:28 +120012725 VkDescriptorSetObj descriptorSet(m_device);
12726 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012727 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012728
Tony Barbour5781e8f2015-08-04 16:23:11 -060012729 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012730
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012731 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012732}
12733
Karl Schultz6addd812016-02-02 17:17:23 -070012734TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012735 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12736 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012738
12739 ASSERT_NO_FATAL_FAILURE(InitState());
12740 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12741
12742 VkVertexInputBindingDescription input_binding;
12743 memset(&input_binding, 0, sizeof(input_binding));
12744
12745 VkVertexInputAttributeDescription input_attrib;
12746 memset(&input_attrib, 0, sizeof(input_attrib));
12747 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12748
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012749 char const *vsSource = "#version 450\n"
12750 "\n"
12751 "layout(location=1) in float x;\n"
12752 "out gl_PerVertex {\n"
12753 " vec4 gl_Position;\n"
12754 "};\n"
12755 "void main(){\n"
12756 " gl_Position = vec4(x);\n"
12757 "}\n";
12758 char const *fsSource = "#version 450\n"
12759 "\n"
12760 "layout(location=0) out vec4 color;\n"
12761 "void main(){\n"
12762 " color = vec4(1);\n"
12763 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012764
12765 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12766 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12767
12768 VkPipelineObj pipe(m_device);
12769 pipe.AddColorAttachment();
12770 pipe.AddShader(&vs);
12771 pipe.AddShader(&fs);
12772
12773 pipe.AddVertexInputBindings(&input_binding, 1);
12774 pipe.AddVertexInputAttribs(&input_attrib, 1);
12775
12776 VkDescriptorSetObj descriptorSet(m_device);
12777 descriptorSet.AppendDummy();
12778 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12779
12780 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12781
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012782 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012783}
12784
Karl Schultz6addd812016-02-02 17:17:23 -070012785TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012786 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012787 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012788 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 -060012789
Chris Forbes62e8e502015-05-25 11:13:29 +120012790 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012792
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012793 char const *vsSource = "#version 450\n"
12794 "\n"
12795 "layout(location=0) in vec4 x;\n" /* not provided */
12796 "out gl_PerVertex {\n"
12797 " vec4 gl_Position;\n"
12798 "};\n"
12799 "void main(){\n"
12800 " gl_Position = x;\n"
12801 "}\n";
12802 char const *fsSource = "#version 450\n"
12803 "\n"
12804 "layout(location=0) out vec4 color;\n"
12805 "void main(){\n"
12806 " color = vec4(1);\n"
12807 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012808
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012809 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12810 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012811
12812 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012813 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012814 pipe.AddShader(&vs);
12815 pipe.AddShader(&fs);
12816
Chris Forbes62e8e502015-05-25 11:13:29 +120012817 VkDescriptorSetObj descriptorSet(m_device);
12818 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012819 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012820
Tony Barbour5781e8f2015-08-04 16:23:11 -060012821 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012822
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012823 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012824}
12825
Karl Schultz6addd812016-02-02 17:17:23 -070012826TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012827 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12828 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012829 "vertex shader input that consumes it");
12830 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 -060012831
Chris Forbesc97d98e2015-05-25 11:13:31 +120012832 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012834
12835 VkVertexInputBindingDescription input_binding;
12836 memset(&input_binding, 0, sizeof(input_binding));
12837
12838 VkVertexInputAttributeDescription input_attrib;
12839 memset(&input_attrib, 0, sizeof(input_attrib));
12840 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12841
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012842 char const *vsSource = "#version 450\n"
12843 "\n"
12844 "layout(location=0) in int x;\n" /* attrib provided float */
12845 "out gl_PerVertex {\n"
12846 " vec4 gl_Position;\n"
12847 "};\n"
12848 "void main(){\n"
12849 " gl_Position = vec4(x);\n"
12850 "}\n";
12851 char const *fsSource = "#version 450\n"
12852 "\n"
12853 "layout(location=0) out vec4 color;\n"
12854 "void main(){\n"
12855 " color = vec4(1);\n"
12856 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012857
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012858 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12859 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012860
12861 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012862 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012863 pipe.AddShader(&vs);
12864 pipe.AddShader(&fs);
12865
12866 pipe.AddVertexInputBindings(&input_binding, 1);
12867 pipe.AddVertexInputAttribs(&input_attrib, 1);
12868
Chris Forbesc97d98e2015-05-25 11:13:31 +120012869 VkDescriptorSetObj descriptorSet(m_device);
12870 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012871 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012872
Tony Barbour5781e8f2015-08-04 16:23:11 -060012873 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012874
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012875 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012876}
12877
Chris Forbesc68b43c2016-04-06 11:18:47 +120012878TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012879 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12880 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12882 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012883
12884 ASSERT_NO_FATAL_FAILURE(InitState());
12885 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12886
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012887 char const *vsSource = "#version 450\n"
12888 "\n"
12889 "out gl_PerVertex {\n"
12890 " vec4 gl_Position;\n"
12891 "};\n"
12892 "void main(){\n"
12893 " gl_Position = vec4(1);\n"
12894 "}\n";
12895 char const *fsSource = "#version 450\n"
12896 "\n"
12897 "layout(location=0) out vec4 color;\n"
12898 "void main(){\n"
12899 " color = vec4(1);\n"
12900 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012901
12902 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12903 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12904
12905 VkPipelineObj pipe(m_device);
12906 pipe.AddColorAttachment();
12907 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012908 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012909 pipe.AddShader(&fs);
12910
12911 VkDescriptorSetObj descriptorSet(m_device);
12912 descriptorSet.AppendDummy();
12913 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12914
12915 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12916
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012917 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012918}
12919
Chris Forbes82ff92a2016-09-09 10:50:24 +120012920TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12922 "No entrypoint found named `foo`");
12923
12924 ASSERT_NO_FATAL_FAILURE(InitState());
12925 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12926
12927 char const *vsSource = "#version 450\n"
12928 "out gl_PerVertex {\n"
12929 " vec4 gl_Position;\n"
12930 "};\n"
12931 "void main(){\n"
12932 " gl_Position = vec4(0);\n"
12933 "}\n";
12934 char const *fsSource = "#version 450\n"
12935 "\n"
12936 "layout(location=0) out vec4 color;\n"
12937 "void main(){\n"
12938 " color = vec4(1);\n"
12939 "}\n";
12940
12941 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12942 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12943
12944 VkPipelineObj pipe(m_device);
12945 pipe.AddColorAttachment();
12946 pipe.AddShader(&vs);
12947 pipe.AddShader(&fs);
12948
12949 VkDescriptorSetObj descriptorSet(m_device);
12950 descriptorSet.AppendDummy();
12951 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12952
12953 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12954
12955 m_errorMonitor->VerifyFound();
12956}
12957
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012958TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12959 m_errorMonitor->SetDesiredFailureMsg(
12960 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12961 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12962 "uses a depth/stencil attachment");
12963
12964 ASSERT_NO_FATAL_FAILURE(InitState());
12965 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12966
12967 char const *vsSource = "#version 450\n"
12968 "void main(){ gl_Position = vec4(0); }\n";
12969 char const *fsSource = "#version 450\n"
12970 "\n"
12971 "layout(location=0) out vec4 color;\n"
12972 "void main(){\n"
12973 " color = vec4(1);\n"
12974 "}\n";
12975
12976 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12977 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12978
12979 VkPipelineObj pipe(m_device);
12980 pipe.AddColorAttachment();
12981 pipe.AddShader(&vs);
12982 pipe.AddShader(&fs);
12983
12984 VkDescriptorSetObj descriptorSet(m_device);
12985 descriptorSet.AppendDummy();
12986 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12987
12988 VkAttachmentDescription attachments[] = {
12989 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12990 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12991 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12992 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12993 },
12994 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12995 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12996 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12997 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12998 },
12999 };
13000 VkAttachmentReference refs[] = {
13001 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13002 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13003 };
13004 VkSubpassDescription subpass = {
13005 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13006 1, &refs[0], nullptr, &refs[1],
13007 0, nullptr
13008 };
13009 VkRenderPassCreateInfo rpci = {
13010 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13011 0, 2, attachments, 1, &subpass, 0, nullptr
13012 };
13013 VkRenderPass rp;
13014 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13015 ASSERT_VK_SUCCESS(err);
13016
13017 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13018
13019 m_errorMonitor->VerifyFound();
13020
13021 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13022}
13023
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013024TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013025 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13026 "the TCS without the patch decoration, but consumed in the TES "
13027 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13029 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013030
13031 ASSERT_NO_FATAL_FAILURE(InitState());
13032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13033
Chris Forbesc1e852d2016-04-04 19:26:42 +120013034 if (!m_device->phy().features().tessellationShader) {
13035 printf("Device does not support tessellation shaders; skipped.\n");
13036 return;
13037 }
13038
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013039 char const *vsSource = "#version 450\n"
13040 "void main(){}\n";
13041 char const *tcsSource = "#version 450\n"
13042 "layout(location=0) out int x[];\n"
13043 "layout(vertices=3) out;\n"
13044 "void main(){\n"
13045 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13046 " gl_TessLevelInner[0] = 1;\n"
13047 " x[gl_InvocationID] = gl_InvocationID;\n"
13048 "}\n";
13049 char const *tesSource = "#version 450\n"
13050 "layout(triangles, equal_spacing, cw) in;\n"
13051 "layout(location=0) patch in int x;\n"
13052 "out gl_PerVertex { vec4 gl_Position; };\n"
13053 "void main(){\n"
13054 " gl_Position.xyz = gl_TessCoord;\n"
13055 " gl_Position.w = x;\n"
13056 "}\n";
13057 char const *fsSource = "#version 450\n"
13058 "layout(location=0) out vec4 color;\n"
13059 "void main(){\n"
13060 " color = vec4(1);\n"
13061 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013062
13063 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13064 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13065 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13066 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13067
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013068 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13069 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013070
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013071 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013072
13073 VkPipelineObj pipe(m_device);
13074 pipe.SetInputAssembly(&iasci);
13075 pipe.SetTessellation(&tsci);
13076 pipe.AddColorAttachment();
13077 pipe.AddShader(&vs);
13078 pipe.AddShader(&tcs);
13079 pipe.AddShader(&tes);
13080 pipe.AddShader(&fs);
13081
13082 VkDescriptorSetObj descriptorSet(m_device);
13083 descriptorSet.AppendDummy();
13084 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13085
13086 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13087
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013088 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013089}
13090
Karl Schultz6addd812016-02-02 17:17:23 -070013091TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013092 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13093 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13095 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013096
Chris Forbes280ba2c2015-06-12 11:16:41 +120013097 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013098 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013099
13100 /* Two binding descriptions for binding 0 */
13101 VkVertexInputBindingDescription input_bindings[2];
13102 memset(input_bindings, 0, sizeof(input_bindings));
13103
13104 VkVertexInputAttributeDescription input_attrib;
13105 memset(&input_attrib, 0, sizeof(input_attrib));
13106 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013108 char const *vsSource = "#version 450\n"
13109 "\n"
13110 "layout(location=0) in float x;\n" /* attrib provided float */
13111 "out gl_PerVertex {\n"
13112 " vec4 gl_Position;\n"
13113 "};\n"
13114 "void main(){\n"
13115 " gl_Position = vec4(x);\n"
13116 "}\n";
13117 char const *fsSource = "#version 450\n"
13118 "\n"
13119 "layout(location=0) out vec4 color;\n"
13120 "void main(){\n"
13121 " color = vec4(1);\n"
13122 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013123
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013124 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13125 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013126
13127 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013128 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013129 pipe.AddShader(&vs);
13130 pipe.AddShader(&fs);
13131
13132 pipe.AddVertexInputBindings(input_bindings, 2);
13133 pipe.AddVertexInputAttribs(&input_attrib, 1);
13134
Chris Forbes280ba2c2015-06-12 11:16:41 +120013135 VkDescriptorSetObj descriptorSet(m_device);
13136 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013137 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013138
Tony Barbour5781e8f2015-08-04 16:23:11 -060013139 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013140
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013141 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013142}
Chris Forbes8f68b562015-05-25 11:13:32 +120013143
Karl Schultz6addd812016-02-02 17:17:23 -070013144TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013145 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013146 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013148
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013149 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013150
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013151 char const *vsSource = "#version 450\n"
13152 "\n"
13153 "out gl_PerVertex {\n"
13154 " vec4 gl_Position;\n"
13155 "};\n"
13156 "void main(){\n"
13157 " gl_Position = vec4(1);\n"
13158 "}\n";
13159 char const *fsSource = "#version 450\n"
13160 "\n"
13161 "void main(){\n"
13162 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013163
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013164 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13165 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013166
13167 VkPipelineObj pipe(m_device);
13168 pipe.AddShader(&vs);
13169 pipe.AddShader(&fs);
13170
Chia-I Wu08accc62015-07-07 11:50:03 +080013171 /* set up CB 0, not written */
13172 pipe.AddColorAttachment();
13173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013174
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013175 VkDescriptorSetObj descriptorSet(m_device);
13176 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013177 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013178
Tony Barbour5781e8f2015-08-04 16:23:11 -060013179 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013180
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013181 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013182}
13183
Karl Schultz6addd812016-02-02 17:17:23 -070013184TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013185 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013186 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013188 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013189
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013190 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013191
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013192 char const *vsSource = "#version 450\n"
13193 "\n"
13194 "out gl_PerVertex {\n"
13195 " vec4 gl_Position;\n"
13196 "};\n"
13197 "void main(){\n"
13198 " gl_Position = vec4(1);\n"
13199 "}\n";
13200 char const *fsSource = "#version 450\n"
13201 "\n"
13202 "layout(location=0) out vec4 x;\n"
13203 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13204 "void main(){\n"
13205 " x = vec4(1);\n"
13206 " y = vec4(1);\n"
13207 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013208
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013209 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13210 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013211
13212 VkPipelineObj pipe(m_device);
13213 pipe.AddShader(&vs);
13214 pipe.AddShader(&fs);
13215
Chia-I Wu08accc62015-07-07 11:50:03 +080013216 /* set up CB 0, not written */
13217 pipe.AddColorAttachment();
13218 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013219 /* FS writes CB 1, but we don't configure it */
13220
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013221 VkDescriptorSetObj descriptorSet(m_device);
13222 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013223 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013224
Tony Barbour5781e8f2015-08-04 16:23:11 -060013225 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013226
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013227 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013228}
13229
Karl Schultz6addd812016-02-02 17:17:23 -070013230TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013231 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013232 "type of an fragment shader output variable, and the format of the corresponding attachment");
13233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013234
Chris Forbesa36d69e2015-05-25 11:13:44 +120013235 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013236
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013237 char const *vsSource = "#version 450\n"
13238 "\n"
13239 "out gl_PerVertex {\n"
13240 " vec4 gl_Position;\n"
13241 "};\n"
13242 "void main(){\n"
13243 " gl_Position = vec4(1);\n"
13244 "}\n";
13245 char const *fsSource = "#version 450\n"
13246 "\n"
13247 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13248 "void main(){\n"
13249 " x = ivec4(1);\n"
13250 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013251
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013252 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13253 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013254
13255 VkPipelineObj pipe(m_device);
13256 pipe.AddShader(&vs);
13257 pipe.AddShader(&fs);
13258
Chia-I Wu08accc62015-07-07 11:50:03 +080013259 /* set up CB 0; type is UNORM by default */
13260 pipe.AddColorAttachment();
13261 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013262
Chris Forbesa36d69e2015-05-25 11:13:44 +120013263 VkDescriptorSetObj descriptorSet(m_device);
13264 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013265 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013266
Tony Barbour5781e8f2015-08-04 16:23:11 -060013267 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013268
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013269 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013270}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013271
Karl Schultz6addd812016-02-02 17:17:23 -070013272TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013273 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13274 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013276
Chris Forbes556c76c2015-08-14 12:04:59 +120013277 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013278
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013279 char const *vsSource = "#version 450\n"
13280 "\n"
13281 "out gl_PerVertex {\n"
13282 " vec4 gl_Position;\n"
13283 "};\n"
13284 "void main(){\n"
13285 " gl_Position = vec4(1);\n"
13286 "}\n";
13287 char const *fsSource = "#version 450\n"
13288 "\n"
13289 "layout(location=0) out vec4 x;\n"
13290 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13291 "void main(){\n"
13292 " x = vec4(bar.y);\n"
13293 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013294
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013295 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13296 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013297
Chris Forbes556c76c2015-08-14 12:04:59 +120013298 VkPipelineObj pipe(m_device);
13299 pipe.AddShader(&vs);
13300 pipe.AddShader(&fs);
13301
13302 /* set up CB 0; type is UNORM by default */
13303 pipe.AddColorAttachment();
13304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13305
13306 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013307 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013308
13309 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13310
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013311 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013312}
13313
Chris Forbes5c59e902016-02-26 16:56:09 +130013314TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013315 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13316 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013318
13319 ASSERT_NO_FATAL_FAILURE(InitState());
13320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013321 char const *vsSource = "#version 450\n"
13322 "\n"
13323 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13324 "out gl_PerVertex {\n"
13325 " vec4 gl_Position;\n"
13326 "};\n"
13327 "void main(){\n"
13328 " gl_Position = vec4(consts.x);\n"
13329 "}\n";
13330 char const *fsSource = "#version 450\n"
13331 "\n"
13332 "layout(location=0) out vec4 x;\n"
13333 "void main(){\n"
13334 " x = vec4(1);\n"
13335 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013336
13337 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13338 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13339
13340 VkPipelineObj pipe(m_device);
13341 pipe.AddShader(&vs);
13342 pipe.AddShader(&fs);
13343
13344 /* set up CB 0; type is UNORM by default */
13345 pipe.AddColorAttachment();
13346 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13347
13348 VkDescriptorSetObj descriptorSet(m_device);
13349 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13350
13351 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13352
13353 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013354 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013355}
13356
Chris Forbes3fb17902016-08-22 14:57:55 +120013357TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13358 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13359 "which is not included in the subpass description");
13360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13361 "consumes input attachment index 0 but not provided in subpass");
13362
13363 ASSERT_NO_FATAL_FAILURE(InitState());
13364
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013365 char const *vsSource = "#version 450\n"
13366 "\n"
13367 "out gl_PerVertex {\n"
13368 " vec4 gl_Position;\n"
13369 "};\n"
13370 "void main(){\n"
13371 " gl_Position = vec4(1);\n"
13372 "}\n";
13373 char const *fsSource = "#version 450\n"
13374 "\n"
13375 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13376 "layout(location=0) out vec4 color;\n"
13377 "void main() {\n"
13378 " color = subpassLoad(x);\n"
13379 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013380
13381 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13382 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13383
13384 VkPipelineObj pipe(m_device);
13385 pipe.AddShader(&vs);
13386 pipe.AddShader(&fs);
13387 pipe.AddColorAttachment();
13388 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013390 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13391 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013392 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013393 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013394 ASSERT_VK_SUCCESS(err);
13395
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013396 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013397 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013398 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013399 ASSERT_VK_SUCCESS(err);
13400
13401 // error here.
13402 pipe.CreateVKPipeline(pl, renderPass());
13403
13404 m_errorMonitor->VerifyFound();
13405
13406 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13407 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13408}
13409
Chris Forbes5a9a0472016-08-22 16:02:09 +120013410TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13411 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13412 "with a format having a different fundamental type");
13413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13414 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13415
13416 ASSERT_NO_FATAL_FAILURE(InitState());
13417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013418 char const *vsSource = "#version 450\n"
13419 "\n"
13420 "out gl_PerVertex {\n"
13421 " vec4 gl_Position;\n"
13422 "};\n"
13423 "void main(){\n"
13424 " gl_Position = vec4(1);\n"
13425 "}\n";
13426 char const *fsSource = "#version 450\n"
13427 "\n"
13428 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13429 "layout(location=0) out vec4 color;\n"
13430 "void main() {\n"
13431 " color = subpassLoad(x);\n"
13432 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013433
13434 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13435 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13436
13437 VkPipelineObj pipe(m_device);
13438 pipe.AddShader(&vs);
13439 pipe.AddShader(&fs);
13440 pipe.AddColorAttachment();
13441 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013443 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13444 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013445 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013446 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013447 ASSERT_VK_SUCCESS(err);
13448
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013449 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013450 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013451 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013452 ASSERT_VK_SUCCESS(err);
13453
13454 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013455 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13456 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13457 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13458 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13459 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 +120013460 };
13461 VkAttachmentReference color = {
13462 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13463 };
13464 VkAttachmentReference input = {
13465 1, VK_IMAGE_LAYOUT_GENERAL,
13466 };
13467
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013468 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013469
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013470 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013471 VkRenderPass rp;
13472 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13473 ASSERT_VK_SUCCESS(err);
13474
13475 // error here.
13476 pipe.CreateVKPipeline(pl, rp);
13477
13478 m_errorMonitor->VerifyFound();
13479
13480 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13481 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13482 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13483}
13484
Chris Forbes541f7b02016-08-22 15:30:27 +120013485TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13486 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13487 "which is not included in the subpass description -- array case");
13488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13489 "consumes input attachment index 1 but not provided in subpass");
13490
13491 ASSERT_NO_FATAL_FAILURE(InitState());
13492
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013493 char const *vsSource = "#version 450\n"
13494 "\n"
13495 "out gl_PerVertex {\n"
13496 " vec4 gl_Position;\n"
13497 "};\n"
13498 "void main(){\n"
13499 " gl_Position = vec4(1);\n"
13500 "}\n";
13501 char const *fsSource = "#version 450\n"
13502 "\n"
13503 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13504 "layout(location=0) out vec4 color;\n"
13505 "void main() {\n"
13506 " color = subpassLoad(xs[1]);\n"
13507 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013508
13509 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13510 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13511
13512 VkPipelineObj pipe(m_device);
13513 pipe.AddShader(&vs);
13514 pipe.AddShader(&fs);
13515 pipe.AddColorAttachment();
13516 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13517
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013518 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13519 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013520 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013521 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013522 ASSERT_VK_SUCCESS(err);
13523
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013524 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013525 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013526 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013527 ASSERT_VK_SUCCESS(err);
13528
13529 // error here.
13530 pipe.CreateVKPipeline(pl, renderPass());
13531
13532 m_errorMonitor->VerifyFound();
13533
13534 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13535 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13536}
13537
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013538TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013539 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13540 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013542
13543 ASSERT_NO_FATAL_FAILURE(InitState());
13544
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013545 char const *csSource = "#version 450\n"
13546 "\n"
13547 "layout(local_size_x=1) in;\n"
13548 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13549 "void main(){\n"
13550 " x = vec4(1);\n"
13551 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013552
13553 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13554
13555 VkDescriptorSetObj descriptorSet(m_device);
13556 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13557
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013558 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13559 nullptr,
13560 0,
13561 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13562 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13563 descriptorSet.GetPipelineLayout(),
13564 VK_NULL_HANDLE,
13565 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013566
13567 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013568 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013569
13570 m_errorMonitor->VerifyFound();
13571
13572 if (err == VK_SUCCESS) {
13573 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13574 }
13575}
13576
Chris Forbes22a9b092016-07-19 14:34:05 +120013577TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013578 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13579 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13581 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013582
13583 ASSERT_NO_FATAL_FAILURE(InitState());
13584
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013585 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13586 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013587 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013588 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013589 ASSERT_VK_SUCCESS(err);
13590
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013591 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013592 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013593 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013594 ASSERT_VK_SUCCESS(err);
13595
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013596 char const *csSource = "#version 450\n"
13597 "\n"
13598 "layout(local_size_x=1) in;\n"
13599 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13600 "void main() {\n"
13601 " x.x = 1.0f;\n"
13602 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013603 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13604
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013605 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13606 nullptr,
13607 0,
13608 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13609 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13610 pl,
13611 VK_NULL_HANDLE,
13612 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013613
13614 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013615 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013616
13617 m_errorMonitor->VerifyFound();
13618
13619 if (err == VK_SUCCESS) {
13620 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13621 }
13622
13623 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13624 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13625}
13626
Chris Forbes50020592016-07-27 13:52:41 +120013627TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13628 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13629 "does not match the dimensionality declared in the shader");
13630
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013631 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 +120013632
13633 ASSERT_NO_FATAL_FAILURE(InitState());
13634 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13635
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013636 char const *vsSource = "#version 450\n"
13637 "\n"
13638 "out gl_PerVertex { vec4 gl_Position; };\n"
13639 "void main() { gl_Position = vec4(0); }\n";
13640 char const *fsSource = "#version 450\n"
13641 "\n"
13642 "layout(set=0, binding=0) uniform sampler3D s;\n"
13643 "layout(location=0) out vec4 color;\n"
13644 "void main() {\n"
13645 " color = texture(s, vec3(0));\n"
13646 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013647 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13648 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13649
13650 VkPipelineObj pipe(m_device);
13651 pipe.AddShader(&vs);
13652 pipe.AddShader(&fs);
13653 pipe.AddColorAttachment();
13654
13655 VkTextureObj texture(m_device, nullptr);
13656 VkSamplerObj sampler(m_device);
13657
13658 VkDescriptorSetObj descriptorSet(m_device);
13659 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13660 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13661
13662 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13663 ASSERT_VK_SUCCESS(err);
13664
13665 BeginCommandBuffer();
13666
13667 m_commandBuffer->BindPipeline(pipe);
13668 m_commandBuffer->BindDescriptorSet(descriptorSet);
13669
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013670 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013671 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013672 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013673 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13674
13675 // error produced here.
13676 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13677
13678 m_errorMonitor->VerifyFound();
13679
13680 EndCommandBuffer();
13681}
13682
Chris Forbes5533bfc2016-07-27 14:12:34 +120013683TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13684 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13685 "are consumed via singlesample images types in the shader, or vice versa.");
13686
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013688
13689 ASSERT_NO_FATAL_FAILURE(InitState());
13690 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13691
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013692 char const *vsSource = "#version 450\n"
13693 "\n"
13694 "out gl_PerVertex { vec4 gl_Position; };\n"
13695 "void main() { gl_Position = vec4(0); }\n";
13696 char const *fsSource = "#version 450\n"
13697 "\n"
13698 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13699 "layout(location=0) out vec4 color;\n"
13700 "void main() {\n"
13701 " color = texelFetch(s, ivec2(0), 0);\n"
13702 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013703 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13704 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13705
13706 VkPipelineObj pipe(m_device);
13707 pipe.AddShader(&vs);
13708 pipe.AddShader(&fs);
13709 pipe.AddColorAttachment();
13710
13711 VkTextureObj texture(m_device, nullptr);
13712 VkSamplerObj sampler(m_device);
13713
13714 VkDescriptorSetObj descriptorSet(m_device);
13715 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13716 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13717
13718 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13719 ASSERT_VK_SUCCESS(err);
13720
13721 BeginCommandBuffer();
13722
13723 m_commandBuffer->BindPipeline(pipe);
13724 m_commandBuffer->BindDescriptorSet(descriptorSet);
13725
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013726 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013727 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013728 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013729 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13730
13731 // error produced here.
13732 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13733
13734 m_errorMonitor->VerifyFound();
13735
13736 EndCommandBuffer();
13737}
13738
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013739#endif // SHADER_CHECKER_TESTS
13740
13741#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013742TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013744
13745 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013746
13747 // Create an image
13748 VkImage image;
13749
Karl Schultz6addd812016-02-02 17:17:23 -070013750 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13751 const int32_t tex_width = 32;
13752 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013753
13754 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013755 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13756 image_create_info.pNext = NULL;
13757 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13758 image_create_info.format = tex_format;
13759 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013760 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013761 image_create_info.extent.depth = 1;
13762 image_create_info.mipLevels = 1;
13763 image_create_info.arrayLayers = 1;
13764 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13765 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13766 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13767 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013768
13769 // Introduce error by sending down a bogus width extent
13770 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013771 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013772
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013773 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013774}
13775
Mark Youngc48c4c12016-04-11 14:26:49 -060013776TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13778 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013779
13780 ASSERT_NO_FATAL_FAILURE(InitState());
13781
13782 // Create an image
13783 VkImage image;
13784
13785 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13786 const int32_t tex_width = 32;
13787 const int32_t tex_height = 32;
13788
13789 VkImageCreateInfo image_create_info = {};
13790 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13791 image_create_info.pNext = NULL;
13792 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13793 image_create_info.format = tex_format;
13794 image_create_info.extent.width = tex_width;
13795 image_create_info.extent.height = tex_height;
13796 image_create_info.extent.depth = 1;
13797 image_create_info.mipLevels = 1;
13798 image_create_info.arrayLayers = 1;
13799 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13800 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13801 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13802 image_create_info.flags = 0;
13803
13804 // Introduce error by sending down a bogus width extent
13805 image_create_info.extent.width = 0;
13806 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13807
13808 m_errorMonitor->VerifyFound();
13809}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013810#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013811
Tobin Ehliscde08892015-09-22 10:11:37 -060013812#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070013813
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013814TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13815 TEST_DESCRIPTION("Create a render pass with an attachment description "
13816 "format set to VK_FORMAT_UNDEFINED");
13817
13818 ASSERT_NO_FATAL_FAILURE(InitState());
13819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13820
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013822
13823 VkAttachmentReference color_attach = {};
13824 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13825 color_attach.attachment = 0;
13826 VkSubpassDescription subpass = {};
13827 subpass.colorAttachmentCount = 1;
13828 subpass.pColorAttachments = &color_attach;
13829
13830 VkRenderPassCreateInfo rpci = {};
13831 rpci.subpassCount = 1;
13832 rpci.pSubpasses = &subpass;
13833 rpci.attachmentCount = 1;
13834 VkAttachmentDescription attach_desc = {};
13835 attach_desc.format = VK_FORMAT_UNDEFINED;
13836 rpci.pAttachments = &attach_desc;
13837 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13838 VkRenderPass rp;
13839 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13840
13841 m_errorMonitor->VerifyFound();
13842
13843 if (result == VK_SUCCESS) {
13844 vkDestroyRenderPass(m_device->device(), rp, NULL);
13845 }
13846}
13847
Karl Schultz6addd812016-02-02 17:17:23 -070013848TEST_F(VkLayerTest, InvalidImageView) {
13849 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013850
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013852
Tobin Ehliscde08892015-09-22 10:11:37 -060013853 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013854
Mike Stroyana3082432015-09-25 13:39:21 -060013855 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013856 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013857
Karl Schultz6addd812016-02-02 17:17:23 -070013858 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13859 const int32_t tex_width = 32;
13860 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013861
13862 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013863 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13864 image_create_info.pNext = NULL;
13865 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13866 image_create_info.format = tex_format;
13867 image_create_info.extent.width = tex_width;
13868 image_create_info.extent.height = tex_height;
13869 image_create_info.extent.depth = 1;
13870 image_create_info.mipLevels = 1;
13871 image_create_info.arrayLayers = 1;
13872 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13873 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13874 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13875 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013876
Chia-I Wuf7458c52015-10-26 21:10:41 +080013877 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013878 ASSERT_VK_SUCCESS(err);
13879
13880 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130013881 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070013882 image_view_create_info.image = image;
13883 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13884 image_view_create_info.format = tex_format;
13885 image_view_create_info.subresourceRange.layerCount = 1;
13886 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13887 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013888 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013889
13890 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013891 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013892
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013893 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013894 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013895}
Mike Stroyana3082432015-09-25 13:39:21 -060013896
Mark Youngd339ba32016-05-30 13:28:35 -060013897TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13898 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013900 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013901
13902 ASSERT_NO_FATAL_FAILURE(InitState());
13903
13904 // Create an image and try to create a view with no memory backing the image
13905 VkImage image;
13906
13907 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13908 const int32_t tex_width = 32;
13909 const int32_t tex_height = 32;
13910
13911 VkImageCreateInfo image_create_info = {};
13912 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13913 image_create_info.pNext = NULL;
13914 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13915 image_create_info.format = tex_format;
13916 image_create_info.extent.width = tex_width;
13917 image_create_info.extent.height = tex_height;
13918 image_create_info.extent.depth = 1;
13919 image_create_info.mipLevels = 1;
13920 image_create_info.arrayLayers = 1;
13921 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13922 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13923 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13924 image_create_info.flags = 0;
13925
13926 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13927 ASSERT_VK_SUCCESS(err);
13928
13929 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130013930 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060013931 image_view_create_info.image = image;
13932 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13933 image_view_create_info.format = tex_format;
13934 image_view_create_info.subresourceRange.layerCount = 1;
13935 image_view_create_info.subresourceRange.baseMipLevel = 0;
13936 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013937 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013938
13939 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013940 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013941
13942 m_errorMonitor->VerifyFound();
13943 vkDestroyImage(m_device->device(), image, NULL);
13944 // If last error is success, it still created the view, so delete it.
13945 if (err == VK_SUCCESS) {
13946 vkDestroyImageView(m_device->device(), view, NULL);
13947 }
Mark Youngd339ba32016-05-30 13:28:35 -060013948}
13949
Karl Schultz6addd812016-02-02 17:17:23 -070013950TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013951 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013953 "formats must have ONLY the "
13954 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13956 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013957
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013958 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013959
Karl Schultz6addd812016-02-02 17:17:23 -070013960 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013961 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013962 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013963 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013964
13965 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013966 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013967 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013968 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13969 image_view_create_info.format = tex_format;
13970 image_view_create_info.subresourceRange.baseMipLevel = 0;
13971 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013972 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013973 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013974 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013975
13976 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013977 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013978
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013979 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013980}
13981
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013982TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013983 VkResult err;
13984 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013985
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13987 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013988
Mike Stroyana3082432015-09-25 13:39:21 -060013989 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013990
13991 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013992 VkImage srcImage;
13993 VkImage dstImage;
13994 VkDeviceMemory srcMem;
13995 VkDeviceMemory destMem;
13996 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013997
13998 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013999 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14000 image_create_info.pNext = NULL;
14001 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14002 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14003 image_create_info.extent.width = 32;
14004 image_create_info.extent.height = 32;
14005 image_create_info.extent.depth = 1;
14006 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014007 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014008 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14009 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14010 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14011 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014012
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014013 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014014 ASSERT_VK_SUCCESS(err);
14015
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014016 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014017 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014018 ASSERT_VK_SUCCESS(err);
14019
14020 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014021 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014022 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14023 memAlloc.pNext = NULL;
14024 memAlloc.allocationSize = 0;
14025 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014026
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014027 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014028 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014029 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014030 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014031 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014032 ASSERT_VK_SUCCESS(err);
14033
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014034 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014035 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014036 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014037 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014038 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014039 ASSERT_VK_SUCCESS(err);
14040
14041 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14042 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014043 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014044 ASSERT_VK_SUCCESS(err);
14045
14046 BeginCommandBuffer();
14047 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014048 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014049 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014050 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014051 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014052 copyRegion.srcOffset.x = 0;
14053 copyRegion.srcOffset.y = 0;
14054 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014055 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014056 copyRegion.dstSubresource.mipLevel = 0;
14057 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014058 // Introduce failure by forcing the dst layerCount to differ from src
14059 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014060 copyRegion.dstOffset.x = 0;
14061 copyRegion.dstOffset.y = 0;
14062 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014063 copyRegion.extent.width = 1;
14064 copyRegion.extent.height = 1;
14065 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014066 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014067 EndCommandBuffer();
14068
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014069 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014070
Chia-I Wuf7458c52015-10-26 21:10:41 +080014071 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014072 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014073 vkFreeMemory(m_device->device(), srcMem, NULL);
14074 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014075}
14076
Tony Barbourd6673642016-05-05 14:46:39 -060014077TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14078
14079 TEST_DESCRIPTION("Creating images with unsuported formats ");
14080
14081 ASSERT_NO_FATAL_FAILURE(InitState());
14082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14083 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014084 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 -060014085 VK_IMAGE_TILING_OPTIMAL, 0);
14086 ASSERT_TRUE(image.initialized());
14087
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014088 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014089 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014090 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014091 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14092 image_create_info.format = VK_FORMAT_UNDEFINED;
14093 image_create_info.extent.width = 32;
14094 image_create_info.extent.height = 32;
14095 image_create_info.extent.depth = 1;
14096 image_create_info.mipLevels = 1;
14097 image_create_info.arrayLayers = 1;
14098 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14099 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14100 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014101
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14103 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014104
14105 VkImage localImage;
14106 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14107 m_errorMonitor->VerifyFound();
14108
Tony Barbourd6673642016-05-05 14:46:39 -060014109 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014110 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014111 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14112 VkFormat format = static_cast<VkFormat>(f);
14113 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014114 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014115 unsupported = format;
14116 break;
14117 }
14118 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014119
Tony Barbourd6673642016-05-05 14:46:39 -060014120 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014121 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014123
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014124 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014125 m_errorMonitor->VerifyFound();
14126 }
14127}
14128
14129TEST_F(VkLayerTest, ImageLayerViewTests) {
14130 VkResult ret;
14131 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14132
14133 ASSERT_NO_FATAL_FAILURE(InitState());
14134
14135 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014136 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 -060014137 VK_IMAGE_TILING_OPTIMAL, 0);
14138 ASSERT_TRUE(image.initialized());
14139
14140 VkImageView imgView;
14141 VkImageViewCreateInfo imgViewInfo = {};
14142 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14143 imgViewInfo.image = image.handle();
14144 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14145 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14146 imgViewInfo.subresourceRange.layerCount = 1;
14147 imgViewInfo.subresourceRange.baseMipLevel = 0;
14148 imgViewInfo.subresourceRange.levelCount = 1;
14149 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14150
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060014152 // View can't have baseMipLevel >= image's mipLevels - Expect
14153 // VIEW_CREATE_ERROR
14154 imgViewInfo.subresourceRange.baseMipLevel = 1;
14155 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14156 m_errorMonitor->VerifyFound();
14157 imgViewInfo.subresourceRange.baseMipLevel = 0;
14158
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014160 // View can't have baseArrayLayer >= image's arraySize - Expect
14161 // VIEW_CREATE_ERROR
14162 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14163 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14164 m_errorMonitor->VerifyFound();
14165 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14166
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14168 "pCreateInfo->subresourceRange."
14169 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014170 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14171 imgViewInfo.subresourceRange.levelCount = 0;
14172 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14173 m_errorMonitor->VerifyFound();
14174 imgViewInfo.subresourceRange.levelCount = 1;
14175
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14177 "pCreateInfo->subresourceRange."
14178 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014179 m_errorMonitor->SetDesiredFailureMsg(
14180 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14181 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014182 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14183 imgViewInfo.subresourceRange.layerCount = 0;
14184 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14185 m_errorMonitor->VerifyFound();
14186 imgViewInfo.subresourceRange.layerCount = 1;
14187
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14190 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14191 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014192 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14193 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14194 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14195 m_errorMonitor->VerifyFound();
14196 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14197
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14199 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14200 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014201 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14202 // VIEW_CREATE_ERROR
14203 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14204 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14205 m_errorMonitor->VerifyFound();
14206 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14209 "differing formats but they must be "
14210 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014211 // TODO: Update framework to easily passing mutable flag into ImageObj init
14212 // For now just allowing image for this one test to not have memory bound
14213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14214 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014215 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14216 // VIEW_CREATE_ERROR
14217 VkImageCreateInfo mutImgInfo = image.create_info();
14218 VkImage mutImage;
14219 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014220 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014221 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14222 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14223 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14224 ASSERT_VK_SUCCESS(ret);
14225 imgViewInfo.image = mutImage;
14226 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14227 m_errorMonitor->VerifyFound();
14228 imgViewInfo.image = image.handle();
14229 vkDestroyImage(m_device->handle(), mutImage, NULL);
14230}
14231
14232TEST_F(VkLayerTest, MiscImageLayerTests) {
14233
14234 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14235
14236 ASSERT_NO_FATAL_FAILURE(InitState());
14237
14238 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014239 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 -060014240 VK_IMAGE_TILING_OPTIMAL, 0);
14241 ASSERT_TRUE(image.initialized());
14242
Tony Barbourd6673642016-05-05 14:46:39 -060014243 vk_testing::Buffer buffer;
14244 VkMemoryPropertyFlags reqs = 0;
14245 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14246 VkBufferImageCopy region = {};
14247 region.bufferRowLength = 128;
14248 region.bufferImageHeight = 128;
14249 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14250 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014251 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014252 region.imageExtent.height = 4;
14253 region.imageExtent.width = 4;
14254 region.imageExtent.depth = 1;
14255 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014256
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014257 // Image must have offset.z of 0 and extent.depth of 1
14258 // Introduce failure by setting imageExtent.depth to 0
14259 region.imageExtent.depth = 0;
14260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14261 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14262 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14263 m_errorMonitor->VerifyFound();
14264
14265 region.imageExtent.depth = 1;
14266
14267 // Image must have offset.z of 0 and extent.depth of 1
14268 // Introduce failure by setting imageOffset.z to 4
14269 region.imageOffset.z = 4;
14270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14271 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14272 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14273 m_errorMonitor->VerifyFound();
14274
14275 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014276 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14277 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14278 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014280 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14281 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014282 m_errorMonitor->VerifyFound();
14283
14284 // BufferOffset must be a multiple of 4
14285 // Introduce failure by setting bufferOffset to a value not divisible by 4
14286 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014288 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14289 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014290 m_errorMonitor->VerifyFound();
14291
14292 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14293 region.bufferOffset = 0;
14294 region.imageExtent.height = 128;
14295 region.imageExtent.width = 128;
14296 // Introduce failure by setting bufferRowLength > 0 but less than width
14297 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014299 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14300 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014301 m_errorMonitor->VerifyFound();
14302
14303 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14304 region.bufferRowLength = 128;
14305 // Introduce failure by setting bufferRowHeight > 0 but less than height
14306 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014308 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14309 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014310 m_errorMonitor->VerifyFound();
14311
14312 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14314 "If the format of srcImage is a depth, stencil, depth stencil or "
14315 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014316 // Expect INVALID_FILTER
14317 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014318 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 -060014319 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014320 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 -060014321 VkImageBlit blitRegion = {};
14322 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14323 blitRegion.srcSubresource.baseArrayLayer = 0;
14324 blitRegion.srcSubresource.layerCount = 1;
14325 blitRegion.srcSubresource.mipLevel = 0;
14326 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14327 blitRegion.dstSubresource.baseArrayLayer = 0;
14328 blitRegion.dstSubresource.layerCount = 1;
14329 blitRegion.dstSubresource.mipLevel = 0;
14330
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014331 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14332 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014333 m_errorMonitor->VerifyFound();
14334
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014335 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14337 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14338 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014339 m_errorMonitor->VerifyFound();
14340
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014342 VkImageMemoryBarrier img_barrier;
14343 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14344 img_barrier.pNext = NULL;
14345 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14346 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14347 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14348 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14349 img_barrier.image = image.handle();
14350 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14351 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14352 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14353 img_barrier.subresourceRange.baseArrayLayer = 0;
14354 img_barrier.subresourceRange.baseMipLevel = 0;
14355 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14356 img_barrier.subresourceRange.layerCount = 0;
14357 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014358 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14359 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014360 m_errorMonitor->VerifyFound();
14361 img_barrier.subresourceRange.layerCount = 1;
14362}
14363
14364TEST_F(VkLayerTest, ImageFormatLimits) {
14365
14366 TEST_DESCRIPTION("Exceed the limits of image format ");
14367
Cody Northropc31a84f2016-08-22 10:41:47 -060014368 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014370 VkImageCreateInfo image_create_info = {};
14371 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14372 image_create_info.pNext = NULL;
14373 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14374 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14375 image_create_info.extent.width = 32;
14376 image_create_info.extent.height = 32;
14377 image_create_info.extent.depth = 1;
14378 image_create_info.mipLevels = 1;
14379 image_create_info.arrayLayers = 1;
14380 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14381 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14382 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14383 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14384 image_create_info.flags = 0;
14385
14386 VkImage nullImg;
14387 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014388 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14389 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014390 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14391 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14392 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14393 m_errorMonitor->VerifyFound();
14394 image_create_info.extent.depth = 1;
14395
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014397 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14398 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14399 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14400 m_errorMonitor->VerifyFound();
14401 image_create_info.mipLevels = 1;
14402
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014404 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14405 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14406 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14407 m_errorMonitor->VerifyFound();
14408 image_create_info.arrayLayers = 1;
14409
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014411 int samples = imgFmtProps.sampleCounts >> 1;
14412 image_create_info.samples = (VkSampleCountFlagBits)samples;
14413 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14414 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14415 m_errorMonitor->VerifyFound();
14416 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14419 "VK_IMAGE_LAYOUT_UNDEFINED or "
14420 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014421 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14422 // Expect INVALID_LAYOUT
14423 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14424 m_errorMonitor->VerifyFound();
14425 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14426}
14427
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014428TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14429
14430 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014432
14433 ASSERT_NO_FATAL_FAILURE(InitState());
14434
14435 VkImageObj src_image(m_device);
14436 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14437 VkImageObj dst_image(m_device);
14438 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14439
14440 BeginCommandBuffer();
14441 VkImageCopy copy_region;
14442 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14443 copy_region.srcSubresource.mipLevel = 0;
14444 copy_region.srcSubresource.baseArrayLayer = 0;
14445 copy_region.srcSubresource.layerCount = 0;
14446 copy_region.srcOffset.x = 0;
14447 copy_region.srcOffset.y = 0;
14448 copy_region.srcOffset.z = 0;
14449 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14450 copy_region.dstSubresource.mipLevel = 0;
14451 copy_region.dstSubresource.baseArrayLayer = 0;
14452 copy_region.dstSubresource.layerCount = 0;
14453 copy_region.dstOffset.x = 0;
14454 copy_region.dstOffset.y = 0;
14455 copy_region.dstOffset.z = 0;
14456 copy_region.extent.width = 64;
14457 copy_region.extent.height = 64;
14458 copy_region.extent.depth = 1;
14459 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14460 &copy_region);
14461 EndCommandBuffer();
14462
14463 m_errorMonitor->VerifyFound();
14464}
14465
14466TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14467
14468 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014470
14471 ASSERT_NO_FATAL_FAILURE(InitState());
14472
14473 VkImageObj src_image(m_device);
14474 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14475 VkImageObj dst_image(m_device);
14476 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14477
14478 BeginCommandBuffer();
14479 VkImageCopy copy_region;
14480 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14481 copy_region.srcSubresource.mipLevel = 0;
14482 copy_region.srcSubresource.baseArrayLayer = 0;
14483 copy_region.srcSubresource.layerCount = 0;
14484 copy_region.srcOffset.x = 0;
14485 copy_region.srcOffset.y = 0;
14486 copy_region.srcOffset.z = 0;
14487 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14488 copy_region.dstSubresource.mipLevel = 0;
14489 copy_region.dstSubresource.baseArrayLayer = 0;
14490 copy_region.dstSubresource.layerCount = 0;
14491 copy_region.dstOffset.x = 0;
14492 copy_region.dstOffset.y = 0;
14493 copy_region.dstOffset.z = 0;
14494 copy_region.extent.width = 64;
14495 copy_region.extent.height = 64;
14496 copy_region.extent.depth = 1;
14497 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14498 &copy_region);
14499 EndCommandBuffer();
14500
14501 m_errorMonitor->VerifyFound();
14502}
14503
Karl Schultz6addd812016-02-02 17:17:23 -070014504TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014505 VkResult err;
14506 bool pass;
14507
14508 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14510 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014511
14512 ASSERT_NO_FATAL_FAILURE(InitState());
14513
14514 // Create two images of different types and try to copy between them
14515 VkImage srcImage;
14516 VkImage dstImage;
14517 VkDeviceMemory srcMem;
14518 VkDeviceMemory destMem;
14519 VkMemoryRequirements memReqs;
14520
14521 VkImageCreateInfo image_create_info = {};
14522 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14523 image_create_info.pNext = NULL;
14524 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14525 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14526 image_create_info.extent.width = 32;
14527 image_create_info.extent.height = 32;
14528 image_create_info.extent.depth = 1;
14529 image_create_info.mipLevels = 1;
14530 image_create_info.arrayLayers = 1;
14531 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14532 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14533 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14534 image_create_info.flags = 0;
14535
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014536 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014537 ASSERT_VK_SUCCESS(err);
14538
14539 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14540 // Introduce failure by creating second image with a different-sized format.
14541 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14542
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014543 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014544 ASSERT_VK_SUCCESS(err);
14545
14546 // Allocate memory
14547 VkMemoryAllocateInfo memAlloc = {};
14548 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14549 memAlloc.pNext = NULL;
14550 memAlloc.allocationSize = 0;
14551 memAlloc.memoryTypeIndex = 0;
14552
14553 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14554 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014555 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014556 ASSERT_TRUE(pass);
14557 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14558 ASSERT_VK_SUCCESS(err);
14559
14560 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14561 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014562 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014563 ASSERT_TRUE(pass);
14564 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14565 ASSERT_VK_SUCCESS(err);
14566
14567 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14568 ASSERT_VK_SUCCESS(err);
14569 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14570 ASSERT_VK_SUCCESS(err);
14571
14572 BeginCommandBuffer();
14573 VkImageCopy copyRegion;
14574 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14575 copyRegion.srcSubresource.mipLevel = 0;
14576 copyRegion.srcSubresource.baseArrayLayer = 0;
14577 copyRegion.srcSubresource.layerCount = 0;
14578 copyRegion.srcOffset.x = 0;
14579 copyRegion.srcOffset.y = 0;
14580 copyRegion.srcOffset.z = 0;
14581 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14582 copyRegion.dstSubresource.mipLevel = 0;
14583 copyRegion.dstSubresource.baseArrayLayer = 0;
14584 copyRegion.dstSubresource.layerCount = 0;
14585 copyRegion.dstOffset.x = 0;
14586 copyRegion.dstOffset.y = 0;
14587 copyRegion.dstOffset.z = 0;
14588 copyRegion.extent.width = 1;
14589 copyRegion.extent.height = 1;
14590 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014591 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014592 EndCommandBuffer();
14593
14594 m_errorMonitor->VerifyFound();
14595
14596 vkDestroyImage(m_device->device(), srcImage, NULL);
14597 vkDestroyImage(m_device->device(), dstImage, NULL);
14598 vkFreeMemory(m_device->device(), srcMem, NULL);
14599 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014600}
14601
Karl Schultz6addd812016-02-02 17:17:23 -070014602TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14603 VkResult err;
14604 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014605
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014606 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14608 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014609
Mike Stroyana3082432015-09-25 13:39:21 -060014610 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014611
14612 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014613 VkImage srcImage;
14614 VkImage dstImage;
14615 VkDeviceMemory srcMem;
14616 VkDeviceMemory destMem;
14617 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014618
14619 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014620 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14621 image_create_info.pNext = NULL;
14622 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14623 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14624 image_create_info.extent.width = 32;
14625 image_create_info.extent.height = 32;
14626 image_create_info.extent.depth = 1;
14627 image_create_info.mipLevels = 1;
14628 image_create_info.arrayLayers = 1;
14629 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14630 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14631 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14632 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014633
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014634 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014635 ASSERT_VK_SUCCESS(err);
14636
Karl Schultzbdb75952016-04-19 11:36:49 -060014637 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14638
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014639 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014640 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014641 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014642 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014643
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014644 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014645 ASSERT_VK_SUCCESS(err);
14646
14647 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014648 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014649 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14650 memAlloc.pNext = NULL;
14651 memAlloc.allocationSize = 0;
14652 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014653
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014654 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014655 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014656 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014657 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014658 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014659 ASSERT_VK_SUCCESS(err);
14660
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014661 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014662 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014663 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014664 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014665 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014666 ASSERT_VK_SUCCESS(err);
14667
14668 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14669 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014670 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014671 ASSERT_VK_SUCCESS(err);
14672
14673 BeginCommandBuffer();
14674 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014675 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014676 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014677 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014678 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014679 copyRegion.srcOffset.x = 0;
14680 copyRegion.srcOffset.y = 0;
14681 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014682 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014683 copyRegion.dstSubresource.mipLevel = 0;
14684 copyRegion.dstSubresource.baseArrayLayer = 0;
14685 copyRegion.dstSubresource.layerCount = 0;
14686 copyRegion.dstOffset.x = 0;
14687 copyRegion.dstOffset.y = 0;
14688 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014689 copyRegion.extent.width = 1;
14690 copyRegion.extent.height = 1;
14691 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014692 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014693 EndCommandBuffer();
14694
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014695 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014696
Chia-I Wuf7458c52015-10-26 21:10:41 +080014697 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014698 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014699 vkFreeMemory(m_device->device(), srcMem, NULL);
14700 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014701}
14702
Karl Schultz6addd812016-02-02 17:17:23 -070014703TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14704 VkResult err;
14705 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014706
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14708 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014709
Mike Stroyana3082432015-09-25 13:39:21 -060014710 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014711
14712 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014713 VkImage srcImage;
14714 VkImage dstImage;
14715 VkDeviceMemory srcMem;
14716 VkDeviceMemory destMem;
14717 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014718
14719 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014720 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14721 image_create_info.pNext = NULL;
14722 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14723 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14724 image_create_info.extent.width = 32;
14725 image_create_info.extent.height = 1;
14726 image_create_info.extent.depth = 1;
14727 image_create_info.mipLevels = 1;
14728 image_create_info.arrayLayers = 1;
14729 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14730 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14731 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14732 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014733
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014734 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014735 ASSERT_VK_SUCCESS(err);
14736
Karl Schultz6addd812016-02-02 17:17:23 -070014737 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014738
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014739 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014740 ASSERT_VK_SUCCESS(err);
14741
14742 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014743 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014744 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14745 memAlloc.pNext = NULL;
14746 memAlloc.allocationSize = 0;
14747 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014748
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014749 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014750 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014751 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014752 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014753 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014754 ASSERT_VK_SUCCESS(err);
14755
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014756 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014757 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014758 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014759 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014760 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014761 ASSERT_VK_SUCCESS(err);
14762
14763 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14764 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014765 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014766 ASSERT_VK_SUCCESS(err);
14767
14768 BeginCommandBuffer();
14769 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014770 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14771 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014772 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014773 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014774 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014775 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014776 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014777 resolveRegion.srcOffset.x = 0;
14778 resolveRegion.srcOffset.y = 0;
14779 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014780 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014781 resolveRegion.dstSubresource.mipLevel = 0;
14782 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014783 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014784 resolveRegion.dstOffset.x = 0;
14785 resolveRegion.dstOffset.y = 0;
14786 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014787 resolveRegion.extent.width = 1;
14788 resolveRegion.extent.height = 1;
14789 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014790 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014791 EndCommandBuffer();
14792
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014793 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014794
Chia-I Wuf7458c52015-10-26 21:10:41 +080014795 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014796 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014797 vkFreeMemory(m_device->device(), srcMem, NULL);
14798 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014799}
14800
Karl Schultz6addd812016-02-02 17:17:23 -070014801TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14802 VkResult err;
14803 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014804
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14806 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014807
Mike Stroyana3082432015-09-25 13:39:21 -060014808 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014809
Chris Forbesa7530692016-05-08 12:35:39 +120014810 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014811 VkImage srcImage;
14812 VkImage dstImage;
14813 VkDeviceMemory srcMem;
14814 VkDeviceMemory destMem;
14815 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014816
14817 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014818 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14819 image_create_info.pNext = NULL;
14820 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14821 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14822 image_create_info.extent.width = 32;
14823 image_create_info.extent.height = 1;
14824 image_create_info.extent.depth = 1;
14825 image_create_info.mipLevels = 1;
14826 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014827 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014828 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14829 // Note: Some implementations expect color attachment usage for any
14830 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014831 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014832 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014833
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014834 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014835 ASSERT_VK_SUCCESS(err);
14836
Karl Schultz6addd812016-02-02 17:17:23 -070014837 // Note: Some implementations expect color attachment usage for any
14838 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014839 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014840
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014841 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014842 ASSERT_VK_SUCCESS(err);
14843
14844 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014845 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014846 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14847 memAlloc.pNext = NULL;
14848 memAlloc.allocationSize = 0;
14849 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014850
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014851 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014852 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014853 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014854 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014855 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014856 ASSERT_VK_SUCCESS(err);
14857
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014858 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014859 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014860 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014861 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014862 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014863 ASSERT_VK_SUCCESS(err);
14864
14865 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14866 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014867 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014868 ASSERT_VK_SUCCESS(err);
14869
14870 BeginCommandBuffer();
14871 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014872 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14873 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014874 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014875 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014876 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014877 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014878 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014879 resolveRegion.srcOffset.x = 0;
14880 resolveRegion.srcOffset.y = 0;
14881 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014882 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014883 resolveRegion.dstSubresource.mipLevel = 0;
14884 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014885 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014886 resolveRegion.dstOffset.x = 0;
14887 resolveRegion.dstOffset.y = 0;
14888 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014889 resolveRegion.extent.width = 1;
14890 resolveRegion.extent.height = 1;
14891 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014892 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014893 EndCommandBuffer();
14894
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014895 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014896
Chia-I Wuf7458c52015-10-26 21:10:41 +080014897 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014898 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014899 vkFreeMemory(m_device->device(), srcMem, NULL);
14900 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014901}
14902
Karl Schultz6addd812016-02-02 17:17:23 -070014903TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14904 VkResult err;
14905 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014906
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14908 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014909
Mike Stroyana3082432015-09-25 13:39:21 -060014910 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014911
14912 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014913 VkImage srcImage;
14914 VkImage dstImage;
14915 VkDeviceMemory srcMem;
14916 VkDeviceMemory destMem;
14917 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014918
14919 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014920 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14921 image_create_info.pNext = NULL;
14922 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14923 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14924 image_create_info.extent.width = 32;
14925 image_create_info.extent.height = 1;
14926 image_create_info.extent.depth = 1;
14927 image_create_info.mipLevels = 1;
14928 image_create_info.arrayLayers = 1;
14929 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14930 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14931 // Note: Some implementations expect color attachment usage for any
14932 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014933 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014934 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014936 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014937 ASSERT_VK_SUCCESS(err);
14938
Karl Schultz6addd812016-02-02 17:17:23 -070014939 // Set format to something other than source image
14940 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14941 // Note: Some implementations expect color attachment usage for any
14942 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014943 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014944 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014945
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014946 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014947 ASSERT_VK_SUCCESS(err);
14948
14949 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014950 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014951 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14952 memAlloc.pNext = NULL;
14953 memAlloc.allocationSize = 0;
14954 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014955
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014956 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014957 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014958 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014959 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014960 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014961 ASSERT_VK_SUCCESS(err);
14962
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014963 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014964 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014965 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014966 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014967 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014968 ASSERT_VK_SUCCESS(err);
14969
14970 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14971 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014972 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014973 ASSERT_VK_SUCCESS(err);
14974
14975 BeginCommandBuffer();
14976 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014977 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14978 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014979 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014980 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014981 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014982 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014983 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014984 resolveRegion.srcOffset.x = 0;
14985 resolveRegion.srcOffset.y = 0;
14986 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014987 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014988 resolveRegion.dstSubresource.mipLevel = 0;
14989 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014990 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014991 resolveRegion.dstOffset.x = 0;
14992 resolveRegion.dstOffset.y = 0;
14993 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014994 resolveRegion.extent.width = 1;
14995 resolveRegion.extent.height = 1;
14996 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014997 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014998 EndCommandBuffer();
14999
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015000 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015001
Chia-I Wuf7458c52015-10-26 21:10:41 +080015002 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015003 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015004 vkFreeMemory(m_device->device(), srcMem, NULL);
15005 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015006}
15007
Karl Schultz6addd812016-02-02 17:17:23 -070015008TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15009 VkResult err;
15010 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15013 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015014
Mike Stroyana3082432015-09-25 13:39:21 -060015015 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015016
15017 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015018 VkImage srcImage;
15019 VkImage dstImage;
15020 VkDeviceMemory srcMem;
15021 VkDeviceMemory destMem;
15022 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015023
15024 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015025 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15026 image_create_info.pNext = NULL;
15027 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15028 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15029 image_create_info.extent.width = 32;
15030 image_create_info.extent.height = 1;
15031 image_create_info.extent.depth = 1;
15032 image_create_info.mipLevels = 1;
15033 image_create_info.arrayLayers = 1;
15034 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15035 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15036 // Note: Some implementations expect color attachment usage for any
15037 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015038 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015039 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015041 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015042 ASSERT_VK_SUCCESS(err);
15043
Karl Schultz6addd812016-02-02 17:17:23 -070015044 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15045 // Note: Some implementations expect color attachment usage for any
15046 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015047 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015048 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015049
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015050 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015051 ASSERT_VK_SUCCESS(err);
15052
15053 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015054 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015055 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15056 memAlloc.pNext = NULL;
15057 memAlloc.allocationSize = 0;
15058 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015059
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015060 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015061 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015062 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015063 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015064 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015065 ASSERT_VK_SUCCESS(err);
15066
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015067 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015068 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015069 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015070 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015071 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015072 ASSERT_VK_SUCCESS(err);
15073
15074 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15075 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015076 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015077 ASSERT_VK_SUCCESS(err);
15078
15079 BeginCommandBuffer();
15080 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015081 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15082 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015083 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015084 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015085 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015086 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015087 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015088 resolveRegion.srcOffset.x = 0;
15089 resolveRegion.srcOffset.y = 0;
15090 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015091 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015092 resolveRegion.dstSubresource.mipLevel = 0;
15093 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015094 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015095 resolveRegion.dstOffset.x = 0;
15096 resolveRegion.dstOffset.y = 0;
15097 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015098 resolveRegion.extent.width = 1;
15099 resolveRegion.extent.height = 1;
15100 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015101 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015102 EndCommandBuffer();
15103
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015104 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015105
Chia-I Wuf7458c52015-10-26 21:10:41 +080015106 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015107 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015108 vkFreeMemory(m_device->device(), srcMem, NULL);
15109 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015110}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015111
Karl Schultz6addd812016-02-02 17:17:23 -070015112TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015113 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015114 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15115 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015116 // The image format check comes 2nd in validation so we trigger it first,
15117 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015118 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015119
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15121 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015122
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015123 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015124
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015125 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015126 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15127 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015128
15129 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015130 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15131 ds_pool_ci.pNext = NULL;
15132 ds_pool_ci.maxSets = 1;
15133 ds_pool_ci.poolSizeCount = 1;
15134 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015135
15136 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015137 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015138 ASSERT_VK_SUCCESS(err);
15139
15140 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015141 dsl_binding.binding = 0;
15142 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15143 dsl_binding.descriptorCount = 1;
15144 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15145 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015146
15147 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015148 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15149 ds_layout_ci.pNext = NULL;
15150 ds_layout_ci.bindingCount = 1;
15151 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015152 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015153 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015154 ASSERT_VK_SUCCESS(err);
15155
15156 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015157 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015158 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015159 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015160 alloc_info.descriptorPool = ds_pool;
15161 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015162 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015163 ASSERT_VK_SUCCESS(err);
15164
Karl Schultz6addd812016-02-02 17:17:23 -070015165 VkImage image_bad;
15166 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015167 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015168 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015169 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015170 const int32_t tex_width = 32;
15171 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015172
15173 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015174 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15175 image_create_info.pNext = NULL;
15176 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15177 image_create_info.format = tex_format_bad;
15178 image_create_info.extent.width = tex_width;
15179 image_create_info.extent.height = tex_height;
15180 image_create_info.extent.depth = 1;
15181 image_create_info.mipLevels = 1;
15182 image_create_info.arrayLayers = 1;
15183 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15184 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015185 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015186 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015187
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015188 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015189 ASSERT_VK_SUCCESS(err);
15190 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015191 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15192 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015193 ASSERT_VK_SUCCESS(err);
15194
15195 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015196 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015197 image_view_create_info.image = image_bad;
15198 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15199 image_view_create_info.format = tex_format_bad;
15200 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15201 image_view_create_info.subresourceRange.baseMipLevel = 0;
15202 image_view_create_info.subresourceRange.layerCount = 1;
15203 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015204 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015205
15206 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015207 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015208
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015209 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015210
Chia-I Wuf7458c52015-10-26 21:10:41 +080015211 vkDestroyImage(m_device->device(), image_bad, NULL);
15212 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015213 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15214 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015215}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015216
15217TEST_F(VkLayerTest, ClearImageErrors) {
15218 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15219 "ClearDepthStencilImage with a color image.");
15220
15221 ASSERT_NO_FATAL_FAILURE(InitState());
15222 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15223
15224 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15225 BeginCommandBuffer();
15226 m_commandBuffer->EndRenderPass();
15227
15228 // Color image
15229 VkClearColorValue clear_color;
15230 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15231 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15232 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15233 const int32_t img_width = 32;
15234 const int32_t img_height = 32;
15235 VkImageCreateInfo image_create_info = {};
15236 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15237 image_create_info.pNext = NULL;
15238 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15239 image_create_info.format = color_format;
15240 image_create_info.extent.width = img_width;
15241 image_create_info.extent.height = img_height;
15242 image_create_info.extent.depth = 1;
15243 image_create_info.mipLevels = 1;
15244 image_create_info.arrayLayers = 1;
15245 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15246 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15247 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15248
15249 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015250 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015251
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015252 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015253
15254 // Depth/Stencil image
15255 VkClearDepthStencilValue clear_value = {0};
15256 reqs = 0; // don't need HOST_VISIBLE DS image
15257 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15258 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15259 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15260 ds_image_create_info.extent.width = 64;
15261 ds_image_create_info.extent.height = 64;
15262 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15263 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15264
15265 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015266 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015267
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015268 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 -060015269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015272 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015273 &color_range);
15274
15275 m_errorMonitor->VerifyFound();
15276
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15278 "image created without "
15279 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015280
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015281 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015282 &color_range);
15283
15284 m_errorMonitor->VerifyFound();
15285
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015286 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15288 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015289
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015290 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15291 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015292
15293 m_errorMonitor->VerifyFound();
15294}
Tobin Ehliscde08892015-09-22 10:11:37 -060015295#endif // IMAGE_TESTS
15296
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015297
15298// WSI Enabled Tests
15299//
Chris Forbes09368e42016-10-13 11:59:22 +130015300#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015301TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15302
15303#if defined(VK_USE_PLATFORM_XCB_KHR)
15304 VkSurfaceKHR surface = VK_NULL_HANDLE;
15305
15306 VkResult err;
15307 bool pass;
15308 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15309 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15310 // uint32_t swapchain_image_count = 0;
15311 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15312 // uint32_t image_index = 0;
15313 // VkPresentInfoKHR present_info = {};
15314
15315 ASSERT_NO_FATAL_FAILURE(InitState());
15316
15317 // Use the create function from one of the VK_KHR_*_surface extension in
15318 // order to create a surface, testing all known errors in the process,
15319 // before successfully creating a surface:
15320 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15322 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15323 pass = (err != VK_SUCCESS);
15324 ASSERT_TRUE(pass);
15325 m_errorMonitor->VerifyFound();
15326
15327 // Next, try to create a surface with the wrong
15328 // VkXcbSurfaceCreateInfoKHR::sType:
15329 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15330 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15332 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15333 pass = (err != VK_SUCCESS);
15334 ASSERT_TRUE(pass);
15335 m_errorMonitor->VerifyFound();
15336
15337 // Create a native window, and then correctly create a surface:
15338 xcb_connection_t *connection;
15339 xcb_screen_t *screen;
15340 xcb_window_t xcb_window;
15341 xcb_intern_atom_reply_t *atom_wm_delete_window;
15342
15343 const xcb_setup_t *setup;
15344 xcb_screen_iterator_t iter;
15345 int scr;
15346 uint32_t value_mask, value_list[32];
15347 int width = 1;
15348 int height = 1;
15349
15350 connection = xcb_connect(NULL, &scr);
15351 ASSERT_TRUE(connection != NULL);
15352 setup = xcb_get_setup(connection);
15353 iter = xcb_setup_roots_iterator(setup);
15354 while (scr-- > 0)
15355 xcb_screen_next(&iter);
15356 screen = iter.data;
15357
15358 xcb_window = xcb_generate_id(connection);
15359
15360 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15361 value_list[0] = screen->black_pixel;
15362 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15363
15364 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15365 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15366
15367 /* Magic code that will send notification when window is destroyed */
15368 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15369 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15370
15371 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15372 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15373 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15374 free(reply);
15375
15376 xcb_map_window(connection, xcb_window);
15377
15378 // Force the x/y coordinates to 100,100 results are identical in consecutive
15379 // runs
15380 const uint32_t coords[] = { 100, 100 };
15381 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15382
15383 // Finally, try to correctly create a surface:
15384 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15385 xcb_create_info.pNext = NULL;
15386 xcb_create_info.flags = 0;
15387 xcb_create_info.connection = connection;
15388 xcb_create_info.window = xcb_window;
15389 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15390 pass = (err == VK_SUCCESS);
15391 ASSERT_TRUE(pass);
15392
15393 // Check if surface supports presentation:
15394
15395 // 1st, do so without having queried the queue families:
15396 VkBool32 supported = false;
15397 // TODO: Get the following error to come out:
15398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15399 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15400 "function");
15401 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15402 pass = (err != VK_SUCCESS);
15403 // ASSERT_TRUE(pass);
15404 // m_errorMonitor->VerifyFound();
15405
15406 // Next, query a queue family index that's too large:
15407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15408 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15409 pass = (err != VK_SUCCESS);
15410 ASSERT_TRUE(pass);
15411 m_errorMonitor->VerifyFound();
15412
15413 // Finally, do so correctly:
15414 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15415 // SUPPORTED
15416 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15417 pass = (err == VK_SUCCESS);
15418 ASSERT_TRUE(pass);
15419
15420 // Before proceeding, try to create a swapchain without having called
15421 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15422 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15423 swapchain_create_info.pNext = NULL;
15424 swapchain_create_info.flags = 0;
15425 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15426 swapchain_create_info.surface = surface;
15427 swapchain_create_info.imageArrayLayers = 1;
15428 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15429 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15431 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15432 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15433 pass = (err != VK_SUCCESS);
15434 ASSERT_TRUE(pass);
15435 m_errorMonitor->VerifyFound();
15436
15437 // Get the surface capabilities:
15438 VkSurfaceCapabilitiesKHR surface_capabilities;
15439
15440 // Do so correctly (only error logged by this entrypoint is if the
15441 // extension isn't enabled):
15442 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15443 pass = (err == VK_SUCCESS);
15444 ASSERT_TRUE(pass);
15445
15446 // Get the surface formats:
15447 uint32_t surface_format_count;
15448
15449 // First, try without a pointer to surface_format_count:
15450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15451 "specified as NULL");
15452 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15453 pass = (err == VK_SUCCESS);
15454 ASSERT_TRUE(pass);
15455 m_errorMonitor->VerifyFound();
15456
15457 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15458 // correctly done a 1st try (to get the count):
15459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15460 surface_format_count = 0;
15461 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15462 pass = (err == VK_SUCCESS);
15463 ASSERT_TRUE(pass);
15464 m_errorMonitor->VerifyFound();
15465
15466 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15467 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15468 pass = (err == VK_SUCCESS);
15469 ASSERT_TRUE(pass);
15470
15471 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15472 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15473
15474 // Next, do a 2nd try with surface_format_count being set too high:
15475 surface_format_count += 5;
15476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15477 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15478 pass = (err == VK_SUCCESS);
15479 ASSERT_TRUE(pass);
15480 m_errorMonitor->VerifyFound();
15481
15482 // Finally, do a correct 1st and 2nd try:
15483 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15484 pass = (err == VK_SUCCESS);
15485 ASSERT_TRUE(pass);
15486 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15487 pass = (err == VK_SUCCESS);
15488 ASSERT_TRUE(pass);
15489
15490 // Get the surface present modes:
15491 uint32_t surface_present_mode_count;
15492
15493 // First, try without a pointer to surface_format_count:
15494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15495 "specified as NULL");
15496
15497 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15498 pass = (err == VK_SUCCESS);
15499 ASSERT_TRUE(pass);
15500 m_errorMonitor->VerifyFound();
15501
15502 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15503 // correctly done a 1st try (to get the count):
15504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15505 surface_present_mode_count = 0;
15506 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15507 (VkPresentModeKHR *)&surface_present_mode_count);
15508 pass = (err == VK_SUCCESS);
15509 ASSERT_TRUE(pass);
15510 m_errorMonitor->VerifyFound();
15511
15512 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15513 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15514 pass = (err == VK_SUCCESS);
15515 ASSERT_TRUE(pass);
15516
15517 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15518 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15519
15520 // Next, do a 2nd try with surface_format_count being set too high:
15521 surface_present_mode_count += 5;
15522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15523 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15524 pass = (err == VK_SUCCESS);
15525 ASSERT_TRUE(pass);
15526 m_errorMonitor->VerifyFound();
15527
15528 // Finally, do a correct 1st and 2nd try:
15529 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15530 pass = (err == VK_SUCCESS);
15531 ASSERT_TRUE(pass);
15532 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15533 pass = (err == VK_SUCCESS);
15534 ASSERT_TRUE(pass);
15535
15536 // Create a swapchain:
15537
15538 // First, try without a pointer to swapchain_create_info:
15539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15540 "specified as NULL");
15541
15542 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15543 pass = (err != VK_SUCCESS);
15544 ASSERT_TRUE(pass);
15545 m_errorMonitor->VerifyFound();
15546
15547 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15548 // sType:
15549 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15551
15552 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15553 pass = (err != VK_SUCCESS);
15554 ASSERT_TRUE(pass);
15555 m_errorMonitor->VerifyFound();
15556
15557 // Next, call with a NULL swapchain pointer:
15558 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15559 swapchain_create_info.pNext = NULL;
15560 swapchain_create_info.flags = 0;
15561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15562 "specified as NULL");
15563
15564 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15565 pass = (err != VK_SUCCESS);
15566 ASSERT_TRUE(pass);
15567 m_errorMonitor->VerifyFound();
15568
15569 // TODO: Enhance swapchain layer so that
15570 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15571
15572 // Next, call with a queue family index that's too large:
15573 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15574 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15575 swapchain_create_info.queueFamilyIndexCount = 2;
15576 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15578 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15579 pass = (err != VK_SUCCESS);
15580 ASSERT_TRUE(pass);
15581 m_errorMonitor->VerifyFound();
15582
15583 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15584 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15585 swapchain_create_info.queueFamilyIndexCount = 1;
15586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15587 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15588 "pCreateInfo->pQueueFamilyIndices).");
15589 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15590 pass = (err != VK_SUCCESS);
15591 ASSERT_TRUE(pass);
15592 m_errorMonitor->VerifyFound();
15593
15594 // Next, call with an invalid imageSharingMode:
15595 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15596 swapchain_create_info.queueFamilyIndexCount = 1;
15597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15598 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15599 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15600 pass = (err != VK_SUCCESS);
15601 ASSERT_TRUE(pass);
15602 m_errorMonitor->VerifyFound();
15603 // Fix for the future:
15604 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15605 // SUPPORTED
15606 swapchain_create_info.queueFamilyIndexCount = 0;
15607 queueFamilyIndex[0] = 0;
15608 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15609
15610 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15611 // Get the images from a swapchain:
15612 // Acquire an image from a swapchain:
15613 // Present an image to a swapchain:
15614 // Destroy the swapchain:
15615
15616 // TODOs:
15617 //
15618 // - Try destroying the device without first destroying the swapchain
15619 //
15620 // - Try destroying the device without first destroying the surface
15621 //
15622 // - Try destroying the surface without first destroying the swapchain
15623
15624 // Destroy the surface:
15625 vkDestroySurfaceKHR(instance(), surface, NULL);
15626
15627 // Tear down the window:
15628 xcb_destroy_window(connection, xcb_window);
15629 xcb_disconnect(connection);
15630
15631#else // VK_USE_PLATFORM_XCB_KHR
15632 return;
15633#endif // VK_USE_PLATFORM_XCB_KHR
15634}
Chris Forbes09368e42016-10-13 11:59:22 +130015635#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015636
15637//
15638// POSITIVE VALIDATION TESTS
15639//
15640// These tests do not expect to encounter ANY validation errors pass only if this is true
15641
Tobin Ehlise0006882016-11-03 10:14:28 -060015642TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15643 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15644 "by a transition in the primary.");
15645 VkResult err;
15646 m_errorMonitor->ExpectSuccess();
15647 ASSERT_NO_FATAL_FAILURE(InitState());
15648 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15649 // Allocate a secondary and primary cmd buffer
15650 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15651 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15652 command_buffer_allocate_info.commandPool = m_commandPool;
15653 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15654 command_buffer_allocate_info.commandBufferCount = 1;
15655
15656 VkCommandBuffer secondary_command_buffer;
15657 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15658 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15659 VkCommandBuffer primary_command_buffer;
15660 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15661 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15662 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15663 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15664 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15665 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15666 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15667
15668 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15669 ASSERT_VK_SUCCESS(err);
15670 VkImageObj image(m_device);
15671 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15672 ASSERT_TRUE(image.initialized());
15673 VkImageMemoryBarrier img_barrier = {};
15674 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15675 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15676 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15677 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15678 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15679 img_barrier.image = image.handle();
15680 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15681 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15682 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15683 img_barrier.subresourceRange.baseArrayLayer = 0;
15684 img_barrier.subresourceRange.baseMipLevel = 0;
15685 img_barrier.subresourceRange.layerCount = 1;
15686 img_barrier.subresourceRange.levelCount = 1;
15687 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15688 0, nullptr, 1, &img_barrier);
15689 err = vkEndCommandBuffer(secondary_command_buffer);
15690 ASSERT_VK_SUCCESS(err);
15691
15692 // Now update primary cmd buffer to execute secondary and transitions image
15693 command_buffer_begin_info.pInheritanceInfo = nullptr;
15694 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15695 ASSERT_VK_SUCCESS(err);
15696 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15697 VkImageMemoryBarrier img_barrier2 = {};
15698 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15699 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15700 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15701 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15702 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15703 img_barrier2.image = image.handle();
15704 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15705 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15706 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15707 img_barrier2.subresourceRange.baseArrayLayer = 0;
15708 img_barrier2.subresourceRange.baseMipLevel = 0;
15709 img_barrier2.subresourceRange.layerCount = 1;
15710 img_barrier2.subresourceRange.levelCount = 1;
15711 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15712 nullptr, 1, &img_barrier2);
15713 err = vkEndCommandBuffer(primary_command_buffer);
15714 ASSERT_VK_SUCCESS(err);
15715 VkSubmitInfo submit_info = {};
15716 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15717 submit_info.commandBufferCount = 1;
15718 submit_info.pCommandBuffers = &primary_command_buffer;
15719 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15720 ASSERT_VK_SUCCESS(err);
15721 m_errorMonitor->VerifyNotFound();
15722 err = vkDeviceWaitIdle(m_device->device());
15723 ASSERT_VK_SUCCESS(err);
15724 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15725 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15726}
15727
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015728// This is a positive test. No failures are expected.
15729TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15730 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15731 "is ignoring VkWriteDescriptorSet members that are not "
15732 "related to the descriptor type specified by "
15733 "VkWriteDescriptorSet::descriptorType. Correct "
15734 "validation behavior will result in the test running to "
15735 "completion without validation errors.");
15736
15737 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15738
15739 ASSERT_NO_FATAL_FAILURE(InitState());
15740
15741 // Image Case
15742 {
15743 m_errorMonitor->ExpectSuccess();
15744
15745 VkImage image;
15746 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15747 const int32_t tex_width = 32;
15748 const int32_t tex_height = 32;
15749 VkImageCreateInfo image_create_info = {};
15750 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15751 image_create_info.pNext = NULL;
15752 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15753 image_create_info.format = tex_format;
15754 image_create_info.extent.width = tex_width;
15755 image_create_info.extent.height = tex_height;
15756 image_create_info.extent.depth = 1;
15757 image_create_info.mipLevels = 1;
15758 image_create_info.arrayLayers = 1;
15759 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15760 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15761 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15762 image_create_info.flags = 0;
15763 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15764 ASSERT_VK_SUCCESS(err);
15765
15766 VkMemoryRequirements memory_reqs;
15767 VkDeviceMemory image_memory;
15768 bool pass;
15769 VkMemoryAllocateInfo memory_info = {};
15770 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15771 memory_info.pNext = NULL;
15772 memory_info.allocationSize = 0;
15773 memory_info.memoryTypeIndex = 0;
15774 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15775 memory_info.allocationSize = memory_reqs.size;
15776 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15777 ASSERT_TRUE(pass);
15778 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15779 ASSERT_VK_SUCCESS(err);
15780 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15781 ASSERT_VK_SUCCESS(err);
15782
15783 VkImageViewCreateInfo image_view_create_info = {};
15784 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15785 image_view_create_info.image = image;
15786 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15787 image_view_create_info.format = tex_format;
15788 image_view_create_info.subresourceRange.layerCount = 1;
15789 image_view_create_info.subresourceRange.baseMipLevel = 0;
15790 image_view_create_info.subresourceRange.levelCount = 1;
15791 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15792
15793 VkImageView view;
15794 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15795 ASSERT_VK_SUCCESS(err);
15796
15797 VkDescriptorPoolSize ds_type_count = {};
15798 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15799 ds_type_count.descriptorCount = 1;
15800
15801 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15802 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15803 ds_pool_ci.pNext = NULL;
15804 ds_pool_ci.maxSets = 1;
15805 ds_pool_ci.poolSizeCount = 1;
15806 ds_pool_ci.pPoolSizes = &ds_type_count;
15807
15808 VkDescriptorPool ds_pool;
15809 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15810 ASSERT_VK_SUCCESS(err);
15811
15812 VkDescriptorSetLayoutBinding dsl_binding = {};
15813 dsl_binding.binding = 0;
15814 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15815 dsl_binding.descriptorCount = 1;
15816 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15817 dsl_binding.pImmutableSamplers = NULL;
15818
15819 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15820 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15821 ds_layout_ci.pNext = NULL;
15822 ds_layout_ci.bindingCount = 1;
15823 ds_layout_ci.pBindings = &dsl_binding;
15824 VkDescriptorSetLayout ds_layout;
15825 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15826 ASSERT_VK_SUCCESS(err);
15827
15828 VkDescriptorSet descriptor_set;
15829 VkDescriptorSetAllocateInfo alloc_info = {};
15830 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15831 alloc_info.descriptorSetCount = 1;
15832 alloc_info.descriptorPool = ds_pool;
15833 alloc_info.pSetLayouts = &ds_layout;
15834 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15835 ASSERT_VK_SUCCESS(err);
15836
15837 VkDescriptorImageInfo image_info = {};
15838 image_info.imageView = view;
15839 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15840
15841 VkWriteDescriptorSet descriptor_write;
15842 memset(&descriptor_write, 0, sizeof(descriptor_write));
15843 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15844 descriptor_write.dstSet = descriptor_set;
15845 descriptor_write.dstBinding = 0;
15846 descriptor_write.descriptorCount = 1;
15847 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15848 descriptor_write.pImageInfo = &image_info;
15849
15850 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15851 // be
15852 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15853 // This will most likely produce a crash if the parameter_validation
15854 // layer
15855 // does not correctly ignore pBufferInfo.
15856 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15857 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15858
15859 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15860
15861 m_errorMonitor->VerifyNotFound();
15862
15863 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15864 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15865 vkDestroyImageView(m_device->device(), view, NULL);
15866 vkDestroyImage(m_device->device(), image, NULL);
15867 vkFreeMemory(m_device->device(), image_memory, NULL);
15868 }
15869
15870 // Buffer Case
15871 {
15872 m_errorMonitor->ExpectSuccess();
15873
15874 VkBuffer buffer;
15875 uint32_t queue_family_index = 0;
15876 VkBufferCreateInfo buffer_create_info = {};
15877 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15878 buffer_create_info.size = 1024;
15879 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15880 buffer_create_info.queueFamilyIndexCount = 1;
15881 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15882
15883 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15884 ASSERT_VK_SUCCESS(err);
15885
15886 VkMemoryRequirements memory_reqs;
15887 VkDeviceMemory buffer_memory;
15888 bool pass;
15889 VkMemoryAllocateInfo memory_info = {};
15890 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15891 memory_info.pNext = NULL;
15892 memory_info.allocationSize = 0;
15893 memory_info.memoryTypeIndex = 0;
15894
15895 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15896 memory_info.allocationSize = memory_reqs.size;
15897 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15898 ASSERT_TRUE(pass);
15899
15900 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15901 ASSERT_VK_SUCCESS(err);
15902 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15903 ASSERT_VK_SUCCESS(err);
15904
15905 VkDescriptorPoolSize ds_type_count = {};
15906 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15907 ds_type_count.descriptorCount = 1;
15908
15909 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15910 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15911 ds_pool_ci.pNext = NULL;
15912 ds_pool_ci.maxSets = 1;
15913 ds_pool_ci.poolSizeCount = 1;
15914 ds_pool_ci.pPoolSizes = &ds_type_count;
15915
15916 VkDescriptorPool ds_pool;
15917 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15918 ASSERT_VK_SUCCESS(err);
15919
15920 VkDescriptorSetLayoutBinding dsl_binding = {};
15921 dsl_binding.binding = 0;
15922 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15923 dsl_binding.descriptorCount = 1;
15924 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15925 dsl_binding.pImmutableSamplers = NULL;
15926
15927 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15928 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15929 ds_layout_ci.pNext = NULL;
15930 ds_layout_ci.bindingCount = 1;
15931 ds_layout_ci.pBindings = &dsl_binding;
15932 VkDescriptorSetLayout ds_layout;
15933 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15934 ASSERT_VK_SUCCESS(err);
15935
15936 VkDescriptorSet descriptor_set;
15937 VkDescriptorSetAllocateInfo alloc_info = {};
15938 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15939 alloc_info.descriptorSetCount = 1;
15940 alloc_info.descriptorPool = ds_pool;
15941 alloc_info.pSetLayouts = &ds_layout;
15942 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15943 ASSERT_VK_SUCCESS(err);
15944
15945 VkDescriptorBufferInfo buffer_info = {};
15946 buffer_info.buffer = buffer;
15947 buffer_info.offset = 0;
15948 buffer_info.range = 1024;
15949
15950 VkWriteDescriptorSet descriptor_write;
15951 memset(&descriptor_write, 0, sizeof(descriptor_write));
15952 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15953 descriptor_write.dstSet = descriptor_set;
15954 descriptor_write.dstBinding = 0;
15955 descriptor_write.descriptorCount = 1;
15956 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15957 descriptor_write.pBufferInfo = &buffer_info;
15958
15959 // Set pImageInfo and pTexelBufferView to invalid values, which should
15960 // be
15961 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15962 // This will most likely produce a crash if the parameter_validation
15963 // layer
15964 // does not correctly ignore pImageInfo.
15965 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15966 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15967
15968 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15969
15970 m_errorMonitor->VerifyNotFound();
15971
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015972 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15973 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15974 vkDestroyBuffer(m_device->device(), buffer, NULL);
15975 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15976 }
15977
15978 // Texel Buffer Case
15979 {
15980 m_errorMonitor->ExpectSuccess();
15981
15982 VkBuffer buffer;
15983 uint32_t queue_family_index = 0;
15984 VkBufferCreateInfo buffer_create_info = {};
15985 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15986 buffer_create_info.size = 1024;
15987 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15988 buffer_create_info.queueFamilyIndexCount = 1;
15989 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15990
15991 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15992 ASSERT_VK_SUCCESS(err);
15993
15994 VkMemoryRequirements memory_reqs;
15995 VkDeviceMemory buffer_memory;
15996 bool pass;
15997 VkMemoryAllocateInfo memory_info = {};
15998 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15999 memory_info.pNext = NULL;
16000 memory_info.allocationSize = 0;
16001 memory_info.memoryTypeIndex = 0;
16002
16003 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16004 memory_info.allocationSize = memory_reqs.size;
16005 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16006 ASSERT_TRUE(pass);
16007
16008 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16009 ASSERT_VK_SUCCESS(err);
16010 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16011 ASSERT_VK_SUCCESS(err);
16012
16013 VkBufferViewCreateInfo buff_view_ci = {};
16014 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16015 buff_view_ci.buffer = buffer;
16016 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16017 buff_view_ci.range = VK_WHOLE_SIZE;
16018 VkBufferView buffer_view;
16019 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16020
16021 VkDescriptorPoolSize ds_type_count = {};
16022 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16023 ds_type_count.descriptorCount = 1;
16024
16025 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16026 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16027 ds_pool_ci.pNext = NULL;
16028 ds_pool_ci.maxSets = 1;
16029 ds_pool_ci.poolSizeCount = 1;
16030 ds_pool_ci.pPoolSizes = &ds_type_count;
16031
16032 VkDescriptorPool ds_pool;
16033 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16034 ASSERT_VK_SUCCESS(err);
16035
16036 VkDescriptorSetLayoutBinding dsl_binding = {};
16037 dsl_binding.binding = 0;
16038 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16039 dsl_binding.descriptorCount = 1;
16040 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16041 dsl_binding.pImmutableSamplers = NULL;
16042
16043 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16044 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16045 ds_layout_ci.pNext = NULL;
16046 ds_layout_ci.bindingCount = 1;
16047 ds_layout_ci.pBindings = &dsl_binding;
16048 VkDescriptorSetLayout ds_layout;
16049 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16050 ASSERT_VK_SUCCESS(err);
16051
16052 VkDescriptorSet descriptor_set;
16053 VkDescriptorSetAllocateInfo alloc_info = {};
16054 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16055 alloc_info.descriptorSetCount = 1;
16056 alloc_info.descriptorPool = ds_pool;
16057 alloc_info.pSetLayouts = &ds_layout;
16058 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16059 ASSERT_VK_SUCCESS(err);
16060
16061 VkWriteDescriptorSet descriptor_write;
16062 memset(&descriptor_write, 0, sizeof(descriptor_write));
16063 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16064 descriptor_write.dstSet = descriptor_set;
16065 descriptor_write.dstBinding = 0;
16066 descriptor_write.descriptorCount = 1;
16067 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16068 descriptor_write.pTexelBufferView = &buffer_view;
16069
16070 // Set pImageInfo and pBufferInfo to invalid values, which should be
16071 // ignored for descriptorType ==
16072 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16073 // This will most likely produce a crash if the parameter_validation
16074 // layer
16075 // does not correctly ignore pImageInfo and pBufferInfo.
16076 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16077 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16078
16079 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16080
16081 m_errorMonitor->VerifyNotFound();
16082
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016083 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16084 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16085 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16086 vkDestroyBuffer(m_device->device(), buffer, NULL);
16087 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16088 }
16089}
16090
Tobin Ehlisf7428442016-10-25 07:58:24 -060016091TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16092 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16093
16094 ASSERT_NO_FATAL_FAILURE(InitState());
16095 // Create layout where two binding #s are "1"
16096 static const uint32_t NUM_BINDINGS = 3;
16097 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16098 dsl_binding[0].binding = 1;
16099 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16100 dsl_binding[0].descriptorCount = 1;
16101 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16102 dsl_binding[0].pImmutableSamplers = NULL;
16103 dsl_binding[1].binding = 0;
16104 dsl_binding[1].descriptorCount = 1;
16105 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16106 dsl_binding[1].descriptorCount = 1;
16107 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16108 dsl_binding[1].pImmutableSamplers = NULL;
16109 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16110 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16111 dsl_binding[2].descriptorCount = 1;
16112 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16113 dsl_binding[2].pImmutableSamplers = NULL;
16114
16115 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16116 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16117 ds_layout_ci.pNext = NULL;
16118 ds_layout_ci.bindingCount = NUM_BINDINGS;
16119 ds_layout_ci.pBindings = dsl_binding;
16120 VkDescriptorSetLayout ds_layout;
16121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16122 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16123 m_errorMonitor->VerifyFound();
16124}
16125
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016126TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016127 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16128
16129 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016130
16131 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016132
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016133 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16134
16135 {
16136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16137 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16138 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16139 m_errorMonitor->VerifyFound();
16140 }
16141
16142 {
16143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16144 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16145 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16146 m_errorMonitor->VerifyFound();
16147 }
16148
16149 {
16150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16151 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16152 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16153 m_errorMonitor->VerifyFound();
16154 }
16155
16156 {
16157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16158 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16159 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16160 m_errorMonitor->VerifyFound();
16161 }
16162
16163 {
16164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16165 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16166 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16167 m_errorMonitor->VerifyFound();
16168 }
16169
16170 {
16171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16172 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16173 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16174 m_errorMonitor->VerifyFound();
16175 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016176
16177 {
16178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16179 VkRect2D scissor = {{-1, 0}, {16, 16}};
16180 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16181 m_errorMonitor->VerifyFound();
16182 }
16183
16184 {
16185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16186 VkRect2D scissor = {{0, -2}, {16, 16}};
16187 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16188 m_errorMonitor->VerifyFound();
16189 }
16190
16191 {
16192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16193 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16194 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16195 m_errorMonitor->VerifyFound();
16196 }
16197
16198 {
16199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16200 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16201 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16202 m_errorMonitor->VerifyFound();
16203 }
16204
16205 EndCommandBuffer();
16206}
16207
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016208// This is a positive test. No failures are expected.
16209TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16210 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16211 VkResult err;
16212
16213 ASSERT_NO_FATAL_FAILURE(InitState());
16214 m_errorMonitor->ExpectSuccess();
16215 VkDescriptorPoolSize ds_type_count = {};
16216 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16217 ds_type_count.descriptorCount = 2;
16218
16219 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16220 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16221 ds_pool_ci.pNext = NULL;
16222 ds_pool_ci.maxSets = 1;
16223 ds_pool_ci.poolSizeCount = 1;
16224 ds_pool_ci.pPoolSizes = &ds_type_count;
16225
16226 VkDescriptorPool ds_pool;
16227 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16228 ASSERT_VK_SUCCESS(err);
16229
16230 // Create layout with two uniform buffer descriptors w/ empty binding between them
16231 static const uint32_t NUM_BINDINGS = 3;
16232 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16233 dsl_binding[0].binding = 0;
16234 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16235 dsl_binding[0].descriptorCount = 1;
16236 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16237 dsl_binding[0].pImmutableSamplers = NULL;
16238 dsl_binding[1].binding = 1;
16239 dsl_binding[1].descriptorCount = 0; // empty binding
16240 dsl_binding[2].binding = 2;
16241 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16242 dsl_binding[2].descriptorCount = 1;
16243 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16244 dsl_binding[2].pImmutableSamplers = NULL;
16245
16246 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16247 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16248 ds_layout_ci.pNext = NULL;
16249 ds_layout_ci.bindingCount = NUM_BINDINGS;
16250 ds_layout_ci.pBindings = dsl_binding;
16251 VkDescriptorSetLayout ds_layout;
16252 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16253 ASSERT_VK_SUCCESS(err);
16254
16255 VkDescriptorSet descriptor_set = {};
16256 VkDescriptorSetAllocateInfo alloc_info = {};
16257 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16258 alloc_info.descriptorSetCount = 1;
16259 alloc_info.descriptorPool = ds_pool;
16260 alloc_info.pSetLayouts = &ds_layout;
16261 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16262 ASSERT_VK_SUCCESS(err);
16263
16264 // Create a buffer to be used for update
16265 VkBufferCreateInfo buff_ci = {};
16266 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16267 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16268 buff_ci.size = 256;
16269 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16270 VkBuffer buffer;
16271 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16272 ASSERT_VK_SUCCESS(err);
16273 // Have to bind memory to buffer before descriptor update
16274 VkMemoryAllocateInfo mem_alloc = {};
16275 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16276 mem_alloc.pNext = NULL;
16277 mem_alloc.allocationSize = 512; // one allocation for both buffers
16278 mem_alloc.memoryTypeIndex = 0;
16279
16280 VkMemoryRequirements mem_reqs;
16281 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16282 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16283 if (!pass) {
16284 vkDestroyBuffer(m_device->device(), buffer, NULL);
16285 return;
16286 }
16287
16288 VkDeviceMemory mem;
16289 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16290 ASSERT_VK_SUCCESS(err);
16291 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16292 ASSERT_VK_SUCCESS(err);
16293
16294 // Only update the descriptor at binding 2
16295 VkDescriptorBufferInfo buff_info = {};
16296 buff_info.buffer = buffer;
16297 buff_info.offset = 0;
16298 buff_info.range = VK_WHOLE_SIZE;
16299 VkWriteDescriptorSet descriptor_write = {};
16300 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16301 descriptor_write.dstBinding = 2;
16302 descriptor_write.descriptorCount = 1;
16303 descriptor_write.pTexelBufferView = nullptr;
16304 descriptor_write.pBufferInfo = &buff_info;
16305 descriptor_write.pImageInfo = nullptr;
16306 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16307 descriptor_write.dstSet = descriptor_set;
16308
16309 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16310
16311 m_errorMonitor->VerifyNotFound();
16312 // Cleanup
16313 vkFreeMemory(m_device->device(), mem, NULL);
16314 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16315 vkDestroyBuffer(m_device->device(), buffer, NULL);
16316 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16317}
16318
16319// This is a positive test. No failures are expected.
16320TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16321 VkResult err;
16322 bool pass;
16323
16324 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16325 "the buffer, create an image, and bind the same memory to "
16326 "it");
16327
16328 m_errorMonitor->ExpectSuccess();
16329
16330 ASSERT_NO_FATAL_FAILURE(InitState());
16331
16332 VkBuffer buffer;
16333 VkImage image;
16334 VkDeviceMemory mem;
16335 VkMemoryRequirements mem_reqs;
16336
16337 VkBufferCreateInfo buf_info = {};
16338 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16339 buf_info.pNext = NULL;
16340 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16341 buf_info.size = 256;
16342 buf_info.queueFamilyIndexCount = 0;
16343 buf_info.pQueueFamilyIndices = NULL;
16344 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16345 buf_info.flags = 0;
16346 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16347 ASSERT_VK_SUCCESS(err);
16348
16349 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16350
16351 VkMemoryAllocateInfo alloc_info = {};
16352 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16353 alloc_info.pNext = NULL;
16354 alloc_info.memoryTypeIndex = 0;
16355
16356 // Ensure memory is big enough for both bindings
16357 alloc_info.allocationSize = 0x10000;
16358
16359 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16360 if (!pass) {
16361 vkDestroyBuffer(m_device->device(), buffer, NULL);
16362 return;
16363 }
16364
16365 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16366 ASSERT_VK_SUCCESS(err);
16367
16368 uint8_t *pData;
16369 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16370 ASSERT_VK_SUCCESS(err);
16371
16372 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16373
16374 vkUnmapMemory(m_device->device(), mem);
16375
16376 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16377 ASSERT_VK_SUCCESS(err);
16378
16379 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16380 // memory. In fact, it was never used by the GPU.
16381 // Just be be sure, wait for idle.
16382 vkDestroyBuffer(m_device->device(), buffer, NULL);
16383 vkDeviceWaitIdle(m_device->device());
16384
16385 VkImageCreateInfo image_create_info = {};
16386 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16387 image_create_info.pNext = NULL;
16388 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16389 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16390 image_create_info.extent.width = 64;
16391 image_create_info.extent.height = 64;
16392 image_create_info.extent.depth = 1;
16393 image_create_info.mipLevels = 1;
16394 image_create_info.arrayLayers = 1;
16395 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16396 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16397 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16398 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16399 image_create_info.queueFamilyIndexCount = 0;
16400 image_create_info.pQueueFamilyIndices = NULL;
16401 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16402 image_create_info.flags = 0;
16403
16404 VkMemoryAllocateInfo mem_alloc = {};
16405 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16406 mem_alloc.pNext = NULL;
16407 mem_alloc.allocationSize = 0;
16408 mem_alloc.memoryTypeIndex = 0;
16409
16410 /* Create a mappable image. It will be the texture if linear images are ok
16411 * to be textures or it will be the staging image if they are not.
16412 */
16413 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16414 ASSERT_VK_SUCCESS(err);
16415
16416 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16417
16418 mem_alloc.allocationSize = mem_reqs.size;
16419
16420 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16421 if (!pass) {
16422 vkDestroyImage(m_device->device(), image, NULL);
16423 return;
16424 }
16425
16426 // VALIDATION FAILURE:
16427 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16428 ASSERT_VK_SUCCESS(err);
16429
16430 m_errorMonitor->VerifyNotFound();
16431
16432 vkFreeMemory(m_device->device(), mem, NULL);
16433 vkDestroyBuffer(m_device->device(), buffer, NULL);
16434 vkDestroyImage(m_device->device(), image, NULL);
16435}
16436
Tobin Ehlis953e8392016-11-17 10:54:13 -070016437TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16438 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16439 // We previously had a bug where dynamic offset of inactive bindings was still being used
16440 VkResult err;
16441 m_errorMonitor->ExpectSuccess();
16442
16443 ASSERT_NO_FATAL_FAILURE(InitState());
16444 ASSERT_NO_FATAL_FAILURE(InitViewport());
16445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16446
16447 VkDescriptorPoolSize ds_type_count = {};
16448 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16449 ds_type_count.descriptorCount = 3;
16450
16451 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16452 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16453 ds_pool_ci.pNext = NULL;
16454 ds_pool_ci.maxSets = 1;
16455 ds_pool_ci.poolSizeCount = 1;
16456 ds_pool_ci.pPoolSizes = &ds_type_count;
16457
16458 VkDescriptorPool ds_pool;
16459 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16460 ASSERT_VK_SUCCESS(err);
16461
16462 const uint32_t BINDING_COUNT = 3;
16463 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
16464 dsl_binding[0].binding = 0;
16465 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16466 dsl_binding[0].descriptorCount = 1;
16467 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16468 dsl_binding[0].pImmutableSamplers = NULL;
16469 dsl_binding[1].binding = 1;
16470 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16471 dsl_binding[1].descriptorCount = 1;
16472 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16473 dsl_binding[1].pImmutableSamplers = NULL;
16474 dsl_binding[2].binding = 2;
16475 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16476 dsl_binding[2].descriptorCount = 1;
16477 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16478 dsl_binding[2].pImmutableSamplers = NULL;
16479
16480 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16481 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16482 ds_layout_ci.pNext = NULL;
16483 ds_layout_ci.bindingCount = BINDING_COUNT;
16484 ds_layout_ci.pBindings = dsl_binding;
16485 VkDescriptorSetLayout ds_layout;
16486 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16487 ASSERT_VK_SUCCESS(err);
16488
16489 VkDescriptorSet descriptor_set;
16490 VkDescriptorSetAllocateInfo alloc_info = {};
16491 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16492 alloc_info.descriptorSetCount = 1;
16493 alloc_info.descriptorPool = ds_pool;
16494 alloc_info.pSetLayouts = &ds_layout;
16495 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16496 ASSERT_VK_SUCCESS(err);
16497
16498 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16499 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16500 pipeline_layout_ci.pNext = NULL;
16501 pipeline_layout_ci.setLayoutCount = 1;
16502 pipeline_layout_ci.pSetLayouts = &ds_layout;
16503
16504 VkPipelineLayout pipeline_layout;
16505 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16506 ASSERT_VK_SUCCESS(err);
16507
16508 // Create two buffers to update the descriptors with
16509 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16510 uint32_t qfi = 0;
16511 VkBufferCreateInfo buffCI = {};
16512 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16513 buffCI.size = 2048;
16514 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16515 buffCI.queueFamilyIndexCount = 1;
16516 buffCI.pQueueFamilyIndices = &qfi;
16517
16518 VkBuffer dyub1;
16519 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16520 ASSERT_VK_SUCCESS(err);
16521 // buffer2
16522 buffCI.size = 1024;
16523 VkBuffer dyub2;
16524 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16525 ASSERT_VK_SUCCESS(err);
16526 // Allocate memory and bind to buffers
16527 VkMemoryAllocateInfo mem_alloc[2] = {};
16528 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16529 mem_alloc[0].pNext = NULL;
16530 mem_alloc[0].memoryTypeIndex = 0;
16531 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16532 mem_alloc[1].pNext = NULL;
16533 mem_alloc[1].memoryTypeIndex = 0;
16534
16535 VkMemoryRequirements mem_reqs1;
16536 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16537 VkMemoryRequirements mem_reqs2;
16538 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16539 mem_alloc[0].allocationSize = mem_reqs1.size;
16540 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16541 mem_alloc[1].allocationSize = mem_reqs2.size;
16542 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16543 if (!pass) {
16544 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16545 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16546 return;
16547 }
16548
16549 VkDeviceMemory mem1;
16550 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16551 ASSERT_VK_SUCCESS(err);
16552 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
16553 ASSERT_VK_SUCCESS(err);
16554 VkDeviceMemory mem2;
16555 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
16556 ASSERT_VK_SUCCESS(err);
16557 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
16558 ASSERT_VK_SUCCESS(err);
16559 // Update descriptors
16560 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
16561 buff_info[0].buffer = dyub1;
16562 buff_info[0].offset = 0;
16563 buff_info[0].range = 256;
16564 buff_info[1].buffer = dyub1;
16565 buff_info[1].offset = 256;
16566 buff_info[1].range = 512;
16567 buff_info[2].buffer = dyub2;
16568 buff_info[2].offset = 0;
16569 buff_info[2].range = 512;
16570
16571 VkWriteDescriptorSet descriptor_write;
16572 memset(&descriptor_write, 0, sizeof(descriptor_write));
16573 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16574 descriptor_write.dstSet = descriptor_set;
16575 descriptor_write.dstBinding = 0;
16576 descriptor_write.descriptorCount = BINDING_COUNT;
16577 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16578 descriptor_write.pBufferInfo = buff_info;
16579
16580 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16581
16582 BeginCommandBuffer();
16583
16584 // Create PSO to be used for draw-time errors below
16585 char const *vsSource = "#version 450\n"
16586 "\n"
16587 "out gl_PerVertex { \n"
16588 " vec4 gl_Position;\n"
16589 "};\n"
16590 "void main(){\n"
16591 " gl_Position = vec4(1);\n"
16592 "}\n";
16593 char const *fsSource = "#version 450\n"
16594 "\n"
16595 "layout(location=0) out vec4 x;\n"
16596 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
16597 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
16598 "void main(){\n"
16599 " x = vec4(bar1.y) + vec4(bar2.y);\n"
16600 "}\n";
16601 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16602 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16603 VkPipelineObj pipe(m_device);
16604 pipe.SetViewport(m_viewports);
16605 pipe.SetScissor(m_scissors);
16606 pipe.AddShader(&vs);
16607 pipe.AddShader(&fs);
16608 pipe.AddColorAttachment();
16609 pipe.CreateVKPipeline(pipeline_layout, renderPass());
16610
16611 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
16612 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
16613 // we used to have a bug in this case.
16614 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
16615 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
16616 &descriptor_set, BINDING_COUNT, dyn_off);
16617 Draw(1, 0, 0, 0);
16618 m_errorMonitor->VerifyNotFound();
16619
16620 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16621 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16622 vkFreeMemory(m_device->device(), mem1, NULL);
16623 vkFreeMemory(m_device->device(), mem2, NULL);
16624
16625 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
16626 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16627 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16628}
16629
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016630TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16631
16632 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16633 "mapping while using VK_WHOLE_SIZE does not cause access "
16634 "violations");
16635 VkResult err;
16636 uint8_t *pData;
16637 ASSERT_NO_FATAL_FAILURE(InitState());
16638
16639 VkDeviceMemory mem;
16640 VkMemoryRequirements mem_reqs;
16641 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
16642 VkMemoryAllocateInfo alloc_info = {};
16643 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16644 alloc_info.pNext = NULL;
16645 alloc_info.memoryTypeIndex = 0;
16646
16647 static const VkDeviceSize allocation_size = 0x1000;
16648 alloc_info.allocationSize = allocation_size;
16649
16650 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16651 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16652 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16653 if (!pass) {
16654 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16655 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16656 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16657 if (!pass) {
16658 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16659 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16660 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16661 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16662 if (!pass) {
16663 return;
16664 }
16665 }
16666 }
16667
16668 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16669 ASSERT_VK_SUCCESS(err);
16670
16671 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16672 // mapped range
16673 m_errorMonitor->ExpectSuccess();
16674 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16675 ASSERT_VK_SUCCESS(err);
16676 VkMappedMemoryRange mmr = {};
16677 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16678 mmr.memory = mem;
16679 mmr.offset = 0;
16680 mmr.size = VK_WHOLE_SIZE;
16681 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16682 ASSERT_VK_SUCCESS(err);
16683 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16684 ASSERT_VK_SUCCESS(err);
16685 m_errorMonitor->VerifyNotFound();
16686 vkUnmapMemory(m_device->device(), mem);
16687
16688 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16689 // mapped range
16690 m_errorMonitor->ExpectSuccess();
16691 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16692 ASSERT_VK_SUCCESS(err);
16693 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16694 mmr.memory = mem;
16695 mmr.offset = 13;
16696 mmr.size = VK_WHOLE_SIZE;
16697 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16698 ASSERT_VK_SUCCESS(err);
16699 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16700 ASSERT_VK_SUCCESS(err);
16701 m_errorMonitor->VerifyNotFound();
16702 vkUnmapMemory(m_device->device(), mem);
16703
16704 // Map with prime offset and size
16705 // Flush/Invalidate subrange of mapped area with prime offset and size
16706 m_errorMonitor->ExpectSuccess();
16707 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16708 ASSERT_VK_SUCCESS(err);
16709 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16710 mmr.memory = mem;
16711 mmr.offset = allocation_size - 107;
16712 mmr.size = 61;
16713 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16714 ASSERT_VK_SUCCESS(err);
16715 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16716 ASSERT_VK_SUCCESS(err);
16717 m_errorMonitor->VerifyNotFound();
16718 vkUnmapMemory(m_device->device(), mem);
16719
16720 // Map without offset and flush WHOLE_SIZE with two separate offsets
16721 m_errorMonitor->ExpectSuccess();
16722 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16723 ASSERT_VK_SUCCESS(err);
16724 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16725 mmr.memory = mem;
16726 mmr.offset = allocation_size - 100;
16727 mmr.size = VK_WHOLE_SIZE;
16728 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16729 ASSERT_VK_SUCCESS(err);
16730 mmr.offset = allocation_size - 200;
16731 mmr.size = VK_WHOLE_SIZE;
16732 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16733 ASSERT_VK_SUCCESS(err);
16734 m_errorMonitor->VerifyNotFound();
16735 vkUnmapMemory(m_device->device(), mem);
16736
16737 vkFreeMemory(m_device->device(), mem, NULL);
16738}
16739
16740// This is a positive test. We used to expect error in this case but spec now allows it
16741TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16742 m_errorMonitor->ExpectSuccess();
16743 vk_testing::Fence testFence;
16744 VkFenceCreateInfo fenceInfo = {};
16745 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16746 fenceInfo.pNext = NULL;
16747
16748 ASSERT_NO_FATAL_FAILURE(InitState());
16749 testFence.init(*m_device, fenceInfo);
16750 VkFence fences[1] = { testFence.handle() };
16751 VkResult result = vkResetFences(m_device->device(), 1, fences);
16752 ASSERT_VK_SUCCESS(result);
16753
16754 m_errorMonitor->VerifyNotFound();
16755}
16756
16757TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16758 m_errorMonitor->ExpectSuccess();
16759
16760 ASSERT_NO_FATAL_FAILURE(InitState());
16761 VkResult err;
16762
16763 // Record (empty!) command buffer that can be submitted multiple times
16764 // simultaneously.
16765 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16766 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16767 m_commandBuffer->BeginCommandBuffer(&cbbi);
16768 m_commandBuffer->EndCommandBuffer();
16769
16770 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16771 VkFence fence;
16772 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16773 ASSERT_VK_SUCCESS(err);
16774
16775 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16776 VkSemaphore s1, s2;
16777 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16778 ASSERT_VK_SUCCESS(err);
16779 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16780 ASSERT_VK_SUCCESS(err);
16781
16782 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16783 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16784 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16785 ASSERT_VK_SUCCESS(err);
16786
16787 // Submit CB again, signaling s2.
16788 si.pSignalSemaphores = &s2;
16789 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16790 ASSERT_VK_SUCCESS(err);
16791
16792 // Wait for fence.
16793 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16794 ASSERT_VK_SUCCESS(err);
16795
16796 // CB is still in flight from second submission, but semaphore s1 is no
16797 // longer in flight. delete it.
16798 vkDestroySemaphore(m_device->device(), s1, nullptr);
16799
16800 m_errorMonitor->VerifyNotFound();
16801
16802 // Force device idle and clean up remaining objects
16803 vkDeviceWaitIdle(m_device->device());
16804 vkDestroySemaphore(m_device->device(), s2, nullptr);
16805 vkDestroyFence(m_device->device(), fence, nullptr);
16806}
16807
16808TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16809 m_errorMonitor->ExpectSuccess();
16810
16811 ASSERT_NO_FATAL_FAILURE(InitState());
16812 VkResult err;
16813
16814 // A fence created signaled
16815 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16816 VkFence f1;
16817 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16818 ASSERT_VK_SUCCESS(err);
16819
16820 // A fence created not
16821 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16822 VkFence f2;
16823 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16824 ASSERT_VK_SUCCESS(err);
16825
16826 // Submit the unsignaled fence
16827 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16828 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16829
16830 // Wait on both fences, with signaled first.
16831 VkFence fences[] = { f1, f2 };
16832 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16833
16834 // Should have both retired!
16835 vkDestroyFence(m_device->device(), f1, nullptr);
16836 vkDestroyFence(m_device->device(), f2, nullptr);
16837
16838 m_errorMonitor->VerifyNotFound();
16839}
16840
16841TEST_F(VkPositiveLayerTest, ValidUsage) {
16842 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16843 "doesn't generate validation errors");
16844
16845 ASSERT_NO_FATAL_FAILURE(InitState());
16846
16847 m_errorMonitor->ExpectSuccess();
16848 // Verify that we can create a view with usage INPUT_ATTACHMENT
16849 VkImageObj image(m_device);
16850 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16851 ASSERT_TRUE(image.initialized());
16852 VkImageView imageView;
16853 VkImageViewCreateInfo ivci = {};
16854 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16855 ivci.image = image.handle();
16856 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16857 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16858 ivci.subresourceRange.layerCount = 1;
16859 ivci.subresourceRange.baseMipLevel = 0;
16860 ivci.subresourceRange.levelCount = 1;
16861 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16862
16863 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16864 m_errorMonitor->VerifyNotFound();
16865 vkDestroyImageView(m_device->device(), imageView, NULL);
16866}
16867
16868// This is a positive test. No failures are expected.
16869TEST_F(VkPositiveLayerTest, BindSparse) {
16870 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16871 "and then free the memory");
16872
16873 ASSERT_NO_FATAL_FAILURE(InitState());
16874
16875 auto index = m_device->graphics_queue_node_index_;
16876 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16877 return;
16878
16879 m_errorMonitor->ExpectSuccess();
16880
16881 VkImage image;
16882 VkImageCreateInfo image_create_info = {};
16883 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16884 image_create_info.pNext = NULL;
16885 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16886 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16887 image_create_info.extent.width = 64;
16888 image_create_info.extent.height = 64;
16889 image_create_info.extent.depth = 1;
16890 image_create_info.mipLevels = 1;
16891 image_create_info.arrayLayers = 1;
16892 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16893 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16894 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16895 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16896 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16897 ASSERT_VK_SUCCESS(err);
16898
16899 VkMemoryRequirements memory_reqs;
16900 VkDeviceMemory memory_one, memory_two;
16901 bool pass;
16902 VkMemoryAllocateInfo memory_info = {};
16903 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16904 memory_info.pNext = NULL;
16905 memory_info.allocationSize = 0;
16906 memory_info.memoryTypeIndex = 0;
16907 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16908 // Find an image big enough to allow sparse mapping of 2 memory regions
16909 // Increase the image size until it is at least twice the
16910 // size of the required alignment, to ensure we can bind both
16911 // allocated memory blocks to the image on aligned offsets.
16912 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16913 vkDestroyImage(m_device->device(), image, nullptr);
16914 image_create_info.extent.width *= 2;
16915 image_create_info.extent.height *= 2;
16916 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16917 ASSERT_VK_SUCCESS(err);
16918 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16919 }
16920 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16921 // at the end of the first
16922 memory_info.allocationSize = memory_reqs.alignment;
16923 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16924 ASSERT_TRUE(pass);
16925 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16926 ASSERT_VK_SUCCESS(err);
16927 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16928 ASSERT_VK_SUCCESS(err);
16929 VkSparseMemoryBind binds[2];
16930 binds[0].flags = 0;
16931 binds[0].memory = memory_one;
16932 binds[0].memoryOffset = 0;
16933 binds[0].resourceOffset = 0;
16934 binds[0].size = memory_info.allocationSize;
16935 binds[1].flags = 0;
16936 binds[1].memory = memory_two;
16937 binds[1].memoryOffset = 0;
16938 binds[1].resourceOffset = memory_info.allocationSize;
16939 binds[1].size = memory_info.allocationSize;
16940
16941 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16942 opaqueBindInfo.image = image;
16943 opaqueBindInfo.bindCount = 2;
16944 opaqueBindInfo.pBinds = binds;
16945
16946 VkFence fence = VK_NULL_HANDLE;
16947 VkBindSparseInfo bindSparseInfo = {};
16948 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16949 bindSparseInfo.imageOpaqueBindCount = 1;
16950 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16951
16952 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16953 vkQueueWaitIdle(m_device->m_queue);
16954 vkDestroyImage(m_device->device(), image, NULL);
16955 vkFreeMemory(m_device->device(), memory_one, NULL);
16956 vkFreeMemory(m_device->device(), memory_two, NULL);
16957 m_errorMonitor->VerifyNotFound();
16958}
16959
16960TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16961 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16962 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16963 "the command buffer has prior knowledge of that "
16964 "attachment's layout.");
16965
16966 m_errorMonitor->ExpectSuccess();
16967
16968 ASSERT_NO_FATAL_FAILURE(InitState());
16969
16970 // A renderpass with one color attachment.
16971 VkAttachmentDescription attachment = { 0,
16972 VK_FORMAT_R8G8B8A8_UNORM,
16973 VK_SAMPLE_COUNT_1_BIT,
16974 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16975 VK_ATTACHMENT_STORE_OP_STORE,
16976 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16977 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16978 VK_IMAGE_LAYOUT_UNDEFINED,
16979 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16980
16981 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16982
16983 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16984
16985 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16986
16987 VkRenderPass rp;
16988 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16989 ASSERT_VK_SUCCESS(err);
16990
16991 // A compatible framebuffer.
16992 VkImageObj image(m_device);
16993 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16994 ASSERT_TRUE(image.initialized());
16995
16996 VkImageViewCreateInfo ivci = {
16997 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16998 nullptr,
16999 0,
17000 image.handle(),
17001 VK_IMAGE_VIEW_TYPE_2D,
17002 VK_FORMAT_R8G8B8A8_UNORM,
17003 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17004 VK_COMPONENT_SWIZZLE_IDENTITY },
17005 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17006 };
17007 VkImageView view;
17008 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17009 ASSERT_VK_SUCCESS(err);
17010
17011 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17012 VkFramebuffer fb;
17013 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17014 ASSERT_VK_SUCCESS(err);
17015
17016 // Record a single command buffer which uses this renderpass twice. The
17017 // bug is triggered at the beginning of the second renderpass, when the
17018 // command buffer already has a layout recorded for the attachment.
17019 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17020 BeginCommandBuffer();
17021 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17022 vkCmdEndRenderPass(m_commandBuffer->handle());
17023 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17024
17025 m_errorMonitor->VerifyNotFound();
17026
17027 vkCmdEndRenderPass(m_commandBuffer->handle());
17028 EndCommandBuffer();
17029
17030 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17031 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17032 vkDestroyImageView(m_device->device(), view, nullptr);
17033}
17034
17035TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17036 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17037 "command buffer, bind them together, then destroy "
17038 "command pool and framebuffer and verify there are no "
17039 "errors.");
17040
17041 m_errorMonitor->ExpectSuccess();
17042
17043 ASSERT_NO_FATAL_FAILURE(InitState());
17044
17045 // A renderpass with one color attachment.
17046 VkAttachmentDescription attachment = { 0,
17047 VK_FORMAT_R8G8B8A8_UNORM,
17048 VK_SAMPLE_COUNT_1_BIT,
17049 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17050 VK_ATTACHMENT_STORE_OP_STORE,
17051 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17052 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17053 VK_IMAGE_LAYOUT_UNDEFINED,
17054 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17055
17056 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17057
17058 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17059
17060 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17061
17062 VkRenderPass rp;
17063 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17064 ASSERT_VK_SUCCESS(err);
17065
17066 // A compatible framebuffer.
17067 VkImageObj image(m_device);
17068 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17069 ASSERT_TRUE(image.initialized());
17070
17071 VkImageViewCreateInfo ivci = {
17072 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17073 nullptr,
17074 0,
17075 image.handle(),
17076 VK_IMAGE_VIEW_TYPE_2D,
17077 VK_FORMAT_R8G8B8A8_UNORM,
17078 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17079 VK_COMPONENT_SWIZZLE_IDENTITY },
17080 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17081 };
17082 VkImageView view;
17083 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17084 ASSERT_VK_SUCCESS(err);
17085
17086 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17087 VkFramebuffer fb;
17088 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17089 ASSERT_VK_SUCCESS(err);
17090
17091 // Explicitly create a command buffer to bind the FB to so that we can then
17092 // destroy the command pool in order to implicitly free command buffer
17093 VkCommandPool command_pool;
17094 VkCommandPoolCreateInfo pool_create_info{};
17095 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17096 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17097 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17098 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17099
17100 VkCommandBuffer command_buffer;
17101 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17102 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17103 command_buffer_allocate_info.commandPool = command_pool;
17104 command_buffer_allocate_info.commandBufferCount = 1;
17105 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17106 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17107
17108 // Begin our cmd buffer with renderpass using our framebuffer
17109 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17110 VkCommandBufferBeginInfo begin_info{};
17111 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17112 vkBeginCommandBuffer(command_buffer, &begin_info);
17113
17114 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17115 vkCmdEndRenderPass(command_buffer);
17116 vkEndCommandBuffer(command_buffer);
17117 vkDestroyImageView(m_device->device(), view, nullptr);
17118 // Destroy command pool to implicitly free command buffer
17119 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17120 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17121 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17122 m_errorMonitor->VerifyNotFound();
17123}
17124
17125TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17126 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17127 "transitions for the first subpass");
17128
17129 m_errorMonitor->ExpectSuccess();
17130
17131 ASSERT_NO_FATAL_FAILURE(InitState());
17132
17133 // A renderpass with one color attachment.
17134 VkAttachmentDescription attachment = { 0,
17135 VK_FORMAT_R8G8B8A8_UNORM,
17136 VK_SAMPLE_COUNT_1_BIT,
17137 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17138 VK_ATTACHMENT_STORE_OP_STORE,
17139 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17140 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17141 VK_IMAGE_LAYOUT_UNDEFINED,
17142 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17143
17144 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17145
17146 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17147
17148 VkSubpassDependency dep = { 0,
17149 0,
17150 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17151 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17152 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17153 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17154 VK_DEPENDENCY_BY_REGION_BIT };
17155
17156 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17157
17158 VkResult err;
17159 VkRenderPass rp;
17160 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17161 ASSERT_VK_SUCCESS(err);
17162
17163 // A compatible framebuffer.
17164 VkImageObj image(m_device);
17165 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17166 ASSERT_TRUE(image.initialized());
17167
17168 VkImageViewCreateInfo ivci = {
17169 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17170 nullptr,
17171 0,
17172 image.handle(),
17173 VK_IMAGE_VIEW_TYPE_2D,
17174 VK_FORMAT_R8G8B8A8_UNORM,
17175 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17176 VK_COMPONENT_SWIZZLE_IDENTITY },
17177 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17178 };
17179 VkImageView view;
17180 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17181 ASSERT_VK_SUCCESS(err);
17182
17183 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17184 VkFramebuffer fb;
17185 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17186 ASSERT_VK_SUCCESS(err);
17187
17188 // Record a single command buffer which issues a pipeline barrier w/
17189 // image memory barrier for the attachment. This detects the previously
17190 // missing tracking of the subpass layout by throwing a validation error
17191 // if it doesn't occur.
17192 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17193 BeginCommandBuffer();
17194 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17195
17196 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17197 nullptr,
17198 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17199 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17200 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17201 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17202 VK_QUEUE_FAMILY_IGNORED,
17203 VK_QUEUE_FAMILY_IGNORED,
17204 image.handle(),
17205 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17206 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17207 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17208 &imb);
17209
17210 vkCmdEndRenderPass(m_commandBuffer->handle());
17211 m_errorMonitor->VerifyNotFound();
17212 EndCommandBuffer();
17213
17214 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17215 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17216 vkDestroyImageView(m_device->device(), view, nullptr);
17217}
17218
17219TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17220 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17221 "is used as a depth/stencil framebuffer attachment, the "
17222 "aspectMask is ignored and both depth and stencil image "
17223 "subresources are used.");
17224
17225 VkFormatProperties format_properties;
17226 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17227 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17228 return;
17229 }
17230
17231 m_errorMonitor->ExpectSuccess();
17232
17233 ASSERT_NO_FATAL_FAILURE(InitState());
17234
17235 VkAttachmentDescription attachment = { 0,
17236 VK_FORMAT_D32_SFLOAT_S8_UINT,
17237 VK_SAMPLE_COUNT_1_BIT,
17238 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17239 VK_ATTACHMENT_STORE_OP_STORE,
17240 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17241 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17242 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17243 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17244
17245 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17246
17247 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17248
17249 VkSubpassDependency dep = { 0,
17250 0,
17251 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17252 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17253 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17254 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17255 VK_DEPENDENCY_BY_REGION_BIT};
17256
17257 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17258
17259 VkResult err;
17260 VkRenderPass rp;
17261 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17262 ASSERT_VK_SUCCESS(err);
17263
17264 VkImageObj image(m_device);
17265 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17266 0x26, // usage
17267 VK_IMAGE_TILING_OPTIMAL, 0);
17268 ASSERT_TRUE(image.initialized());
17269 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17270
17271 VkImageViewCreateInfo ivci = {
17272 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17273 nullptr,
17274 0,
17275 image.handle(),
17276 VK_IMAGE_VIEW_TYPE_2D,
17277 VK_FORMAT_D32_SFLOAT_S8_UINT,
17278 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17279 { 0x2, 0, 1, 0, 1 },
17280 };
17281 VkImageView view;
17282 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17283 ASSERT_VK_SUCCESS(err);
17284
17285 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17286 VkFramebuffer fb;
17287 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17288 ASSERT_VK_SUCCESS(err);
17289
17290 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17291 BeginCommandBuffer();
17292 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17293
17294 VkImageMemoryBarrier imb = {};
17295 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17296 imb.pNext = nullptr;
17297 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17298 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17299 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17300 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17301 imb.srcQueueFamilyIndex = 0;
17302 imb.dstQueueFamilyIndex = 0;
17303 imb.image = image.handle();
17304 imb.subresourceRange.aspectMask = 0x6;
17305 imb.subresourceRange.baseMipLevel = 0;
17306 imb.subresourceRange.levelCount = 0x1;
17307 imb.subresourceRange.baseArrayLayer = 0;
17308 imb.subresourceRange.layerCount = 0x1;
17309
17310 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17311 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17312 &imb);
17313
17314 vkCmdEndRenderPass(m_commandBuffer->handle());
17315 EndCommandBuffer();
17316 QueueCommandBuffer(false);
17317 m_errorMonitor->VerifyNotFound();
17318
17319 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17320 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17321 vkDestroyImageView(m_device->device(), view, nullptr);
17322}
17323
17324TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17325 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17326 "errors, when an attachment reference is "
17327 "VK_ATTACHMENT_UNUSED");
17328
17329 m_errorMonitor->ExpectSuccess();
17330
17331 ASSERT_NO_FATAL_FAILURE(InitState());
17332
17333 // A renderpass with no attachments
17334 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17335
17336 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17337
17338 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17339
17340 VkRenderPass rp;
17341 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17342 ASSERT_VK_SUCCESS(err);
17343
17344 // A compatible framebuffer.
17345 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17346 VkFramebuffer fb;
17347 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17348 ASSERT_VK_SUCCESS(err);
17349
17350 // Record a command buffer which just begins and ends the renderpass. The
17351 // bug manifests in BeginRenderPass.
17352 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17353 BeginCommandBuffer();
17354 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17355 vkCmdEndRenderPass(m_commandBuffer->handle());
17356 m_errorMonitor->VerifyNotFound();
17357 EndCommandBuffer();
17358
17359 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17360 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17361}
17362
17363// This is a positive test. No errors are expected.
17364TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17365 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17366 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17367 VkResult result = VK_SUCCESS;
17368 VkImageFormatProperties formatProps;
17369 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17370 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17371 &formatProps);
17372 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17373 return;
17374 }
17375
17376 ASSERT_NO_FATAL_FAILURE(InitState());
17377 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17378 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17379 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17380 VkAttachmentDescription att = {};
17381 VkAttachmentReference ref = {};
17382 att.format = depth_stencil_fmt;
17383 att.samples = VK_SAMPLE_COUNT_1_BIT;
17384 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17385 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17386 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17387 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17388 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17389 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17390
17391 VkClearValue clear;
17392 clear.depthStencil.depth = 1.0;
17393 clear.depthStencil.stencil = 0;
17394 ref.attachment = 0;
17395 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17396
17397 VkSubpassDescription subpass = {};
17398 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17399 subpass.flags = 0;
17400 subpass.inputAttachmentCount = 0;
17401 subpass.pInputAttachments = NULL;
17402 subpass.colorAttachmentCount = 0;
17403 subpass.pColorAttachments = NULL;
17404 subpass.pResolveAttachments = NULL;
17405 subpass.pDepthStencilAttachment = &ref;
17406 subpass.preserveAttachmentCount = 0;
17407 subpass.pPreserveAttachments = NULL;
17408
17409 VkRenderPass rp;
17410 VkRenderPassCreateInfo rp_info = {};
17411 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17412 rp_info.attachmentCount = 1;
17413 rp_info.pAttachments = &att;
17414 rp_info.subpassCount = 1;
17415 rp_info.pSubpasses = &subpass;
17416 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17417 ASSERT_VK_SUCCESS(result);
17418
17419 VkImageView *depthView = m_depthStencil->BindInfo();
17420 VkFramebufferCreateInfo fb_info = {};
17421 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17422 fb_info.pNext = NULL;
17423 fb_info.renderPass = rp;
17424 fb_info.attachmentCount = 1;
17425 fb_info.pAttachments = depthView;
17426 fb_info.width = 100;
17427 fb_info.height = 100;
17428 fb_info.layers = 1;
17429 VkFramebuffer fb;
17430 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17431 ASSERT_VK_SUCCESS(result);
17432
17433 VkRenderPassBeginInfo rpbinfo = {};
17434 rpbinfo.clearValueCount = 1;
17435 rpbinfo.pClearValues = &clear;
17436 rpbinfo.pNext = NULL;
17437 rpbinfo.renderPass = rp;
17438 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17439 rpbinfo.renderArea.extent.width = 100;
17440 rpbinfo.renderArea.extent.height = 100;
17441 rpbinfo.renderArea.offset.x = 0;
17442 rpbinfo.renderArea.offset.y = 0;
17443 rpbinfo.framebuffer = fb;
17444
17445 VkFence fence = {};
17446 VkFenceCreateInfo fence_ci = {};
17447 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17448 fence_ci.pNext = nullptr;
17449 fence_ci.flags = 0;
17450 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17451 ASSERT_VK_SUCCESS(result);
17452
17453 m_commandBuffer->BeginCommandBuffer();
17454 m_commandBuffer->BeginRenderPass(rpbinfo);
17455 m_commandBuffer->EndRenderPass();
17456 m_commandBuffer->EndCommandBuffer();
17457 m_commandBuffer->QueueCommandBuffer(fence);
17458
17459 VkImageObj destImage(m_device);
17460 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17461 VK_IMAGE_TILING_OPTIMAL, 0);
17462 VkImageMemoryBarrier barrier = {};
17463 VkImageSubresourceRange range;
17464 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17465 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17466 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17467 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17468 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17469 barrier.image = m_depthStencil->handle();
17470 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17471 range.baseMipLevel = 0;
17472 range.levelCount = 1;
17473 range.baseArrayLayer = 0;
17474 range.layerCount = 1;
17475 barrier.subresourceRange = range;
17476 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17477 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17478 cmdbuf.BeginCommandBuffer();
17479 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17480 &barrier);
17481 barrier.srcAccessMask = 0;
17482 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17483 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17484 barrier.image = destImage.handle();
17485 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17486 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17487 &barrier);
17488 VkImageCopy cregion;
17489 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17490 cregion.srcSubresource.mipLevel = 0;
17491 cregion.srcSubresource.baseArrayLayer = 0;
17492 cregion.srcSubresource.layerCount = 1;
17493 cregion.srcOffset.x = 0;
17494 cregion.srcOffset.y = 0;
17495 cregion.srcOffset.z = 0;
17496 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17497 cregion.dstSubresource.mipLevel = 0;
17498 cregion.dstSubresource.baseArrayLayer = 0;
17499 cregion.dstSubresource.layerCount = 1;
17500 cregion.dstOffset.x = 0;
17501 cregion.dstOffset.y = 0;
17502 cregion.dstOffset.z = 0;
17503 cregion.extent.width = 100;
17504 cregion.extent.height = 100;
17505 cregion.extent.depth = 1;
17506 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17507 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17508 cmdbuf.EndCommandBuffer();
17509
17510 VkSubmitInfo submit_info;
17511 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17512 submit_info.pNext = NULL;
17513 submit_info.waitSemaphoreCount = 0;
17514 submit_info.pWaitSemaphores = NULL;
17515 submit_info.pWaitDstStageMask = NULL;
17516 submit_info.commandBufferCount = 1;
17517 submit_info.pCommandBuffers = &cmdbuf.handle();
17518 submit_info.signalSemaphoreCount = 0;
17519 submit_info.pSignalSemaphores = NULL;
17520
17521 m_errorMonitor->ExpectSuccess();
17522 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17523 m_errorMonitor->VerifyNotFound();
17524
17525 vkQueueWaitIdle(m_device->m_queue);
17526 vkDestroyFence(m_device->device(), fence, nullptr);
17527 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17528 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17529}
17530
17531// This is a positive test. No errors should be generated.
17532TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17533 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17534
17535 m_errorMonitor->ExpectSuccess();
17536 ASSERT_NO_FATAL_FAILURE(InitState());
17537
17538 VkEvent event;
17539 VkEventCreateInfo event_create_info{};
17540 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17541 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17542
17543 VkCommandPool command_pool;
17544 VkCommandPoolCreateInfo pool_create_info{};
17545 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17546 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17547 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17548 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17549
17550 VkCommandBuffer command_buffer;
17551 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17552 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17553 command_buffer_allocate_info.commandPool = command_pool;
17554 command_buffer_allocate_info.commandBufferCount = 1;
17555 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17556 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17557
17558 VkQueue queue = VK_NULL_HANDLE;
17559 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17560
17561 {
17562 VkCommandBufferBeginInfo begin_info{};
17563 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17564 vkBeginCommandBuffer(command_buffer, &begin_info);
17565
17566 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17567 nullptr, 0, nullptr);
17568 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17569 vkEndCommandBuffer(command_buffer);
17570 }
17571 {
17572 VkSubmitInfo submit_info{};
17573 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17574 submit_info.commandBufferCount = 1;
17575 submit_info.pCommandBuffers = &command_buffer;
17576 submit_info.signalSemaphoreCount = 0;
17577 submit_info.pSignalSemaphores = nullptr;
17578 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17579 }
17580 { vkSetEvent(m_device->device(), event); }
17581
17582 vkQueueWaitIdle(queue);
17583
17584 vkDestroyEvent(m_device->device(), event, nullptr);
17585 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17586 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17587
17588 m_errorMonitor->VerifyNotFound();
17589}
17590// This is a positive test. No errors should be generated.
17591TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17592 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17593
17594 ASSERT_NO_FATAL_FAILURE(InitState());
17595 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17596 return;
17597
17598 m_errorMonitor->ExpectSuccess();
17599
17600 VkQueryPool query_pool;
17601 VkQueryPoolCreateInfo query_pool_create_info{};
17602 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17603 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17604 query_pool_create_info.queryCount = 1;
17605 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17606
17607 VkCommandPool command_pool;
17608 VkCommandPoolCreateInfo pool_create_info{};
17609 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17610 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17611 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17612 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17613
17614 VkCommandBuffer command_buffer;
17615 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17616 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17617 command_buffer_allocate_info.commandPool = command_pool;
17618 command_buffer_allocate_info.commandBufferCount = 1;
17619 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17620 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17621
17622 VkCommandBuffer secondary_command_buffer;
17623 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17624 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17625
17626 VkQueue queue = VK_NULL_HANDLE;
17627 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17628
17629 uint32_t qfi = 0;
17630 VkBufferCreateInfo buff_create_info = {};
17631 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17632 buff_create_info.size = 1024;
17633 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17634 buff_create_info.queueFamilyIndexCount = 1;
17635 buff_create_info.pQueueFamilyIndices = &qfi;
17636
17637 VkResult err;
17638 VkBuffer buffer;
17639 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17640 ASSERT_VK_SUCCESS(err);
17641 VkMemoryAllocateInfo mem_alloc = {};
17642 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17643 mem_alloc.pNext = NULL;
17644 mem_alloc.allocationSize = 1024;
17645 mem_alloc.memoryTypeIndex = 0;
17646
17647 VkMemoryRequirements memReqs;
17648 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17649 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17650 if (!pass) {
17651 vkDestroyBuffer(m_device->device(), buffer, NULL);
17652 return;
17653 }
17654
17655 VkDeviceMemory mem;
17656 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17657 ASSERT_VK_SUCCESS(err);
17658 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17659 ASSERT_VK_SUCCESS(err);
17660
17661 VkCommandBufferInheritanceInfo hinfo = {};
17662 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17663 hinfo.renderPass = VK_NULL_HANDLE;
17664 hinfo.subpass = 0;
17665 hinfo.framebuffer = VK_NULL_HANDLE;
17666 hinfo.occlusionQueryEnable = VK_FALSE;
17667 hinfo.queryFlags = 0;
17668 hinfo.pipelineStatistics = 0;
17669
17670 {
17671 VkCommandBufferBeginInfo begin_info{};
17672 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17673 begin_info.pInheritanceInfo = &hinfo;
17674 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17675
17676 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17677 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17678
17679 vkEndCommandBuffer(secondary_command_buffer);
17680
17681 begin_info.pInheritanceInfo = nullptr;
17682 vkBeginCommandBuffer(command_buffer, &begin_info);
17683
17684 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17685 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17686
17687 vkEndCommandBuffer(command_buffer);
17688 }
17689 {
17690 VkSubmitInfo submit_info{};
17691 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17692 submit_info.commandBufferCount = 1;
17693 submit_info.pCommandBuffers = &command_buffer;
17694 submit_info.signalSemaphoreCount = 0;
17695 submit_info.pSignalSemaphores = nullptr;
17696 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17697 }
17698
17699 vkQueueWaitIdle(queue);
17700
17701 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17702 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17703 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17704 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17705 vkDestroyBuffer(m_device->device(), buffer, NULL);
17706 vkFreeMemory(m_device->device(), mem, NULL);
17707
17708 m_errorMonitor->VerifyNotFound();
17709}
17710
17711// This is a positive test. No errors should be generated.
17712TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17713 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17714
17715 ASSERT_NO_FATAL_FAILURE(InitState());
17716 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17717 return;
17718
17719 m_errorMonitor->ExpectSuccess();
17720
17721 VkQueryPool query_pool;
17722 VkQueryPoolCreateInfo query_pool_create_info{};
17723 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17724 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17725 query_pool_create_info.queryCount = 1;
17726 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17727
17728 VkCommandPool command_pool;
17729 VkCommandPoolCreateInfo pool_create_info{};
17730 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17731 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17732 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17733 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17734
17735 VkCommandBuffer command_buffer[2];
17736 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17737 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17738 command_buffer_allocate_info.commandPool = command_pool;
17739 command_buffer_allocate_info.commandBufferCount = 2;
17740 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17741 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17742
17743 VkQueue queue = VK_NULL_HANDLE;
17744 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17745
17746 uint32_t qfi = 0;
17747 VkBufferCreateInfo buff_create_info = {};
17748 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17749 buff_create_info.size = 1024;
17750 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17751 buff_create_info.queueFamilyIndexCount = 1;
17752 buff_create_info.pQueueFamilyIndices = &qfi;
17753
17754 VkResult err;
17755 VkBuffer buffer;
17756 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17757 ASSERT_VK_SUCCESS(err);
17758 VkMemoryAllocateInfo mem_alloc = {};
17759 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17760 mem_alloc.pNext = NULL;
17761 mem_alloc.allocationSize = 1024;
17762 mem_alloc.memoryTypeIndex = 0;
17763
17764 VkMemoryRequirements memReqs;
17765 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17766 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17767 if (!pass) {
17768 vkDestroyBuffer(m_device->device(), buffer, NULL);
17769 return;
17770 }
17771
17772 VkDeviceMemory mem;
17773 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17774 ASSERT_VK_SUCCESS(err);
17775 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17776 ASSERT_VK_SUCCESS(err);
17777
17778 {
17779 VkCommandBufferBeginInfo begin_info{};
17780 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17781 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17782
17783 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17784 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17785
17786 vkEndCommandBuffer(command_buffer[0]);
17787
17788 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17789
17790 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17791
17792 vkEndCommandBuffer(command_buffer[1]);
17793 }
17794 {
17795 VkSubmitInfo submit_info{};
17796 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17797 submit_info.commandBufferCount = 2;
17798 submit_info.pCommandBuffers = command_buffer;
17799 submit_info.signalSemaphoreCount = 0;
17800 submit_info.pSignalSemaphores = nullptr;
17801 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17802 }
17803
17804 vkQueueWaitIdle(queue);
17805
17806 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17807 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17808 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17809 vkDestroyBuffer(m_device->device(), buffer, NULL);
17810 vkFreeMemory(m_device->device(), mem, NULL);
17811
17812 m_errorMonitor->VerifyNotFound();
17813}
17814
Tony Barbourc46924f2016-11-04 11:49:52 -060017815TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017816 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17817
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017818 ASSERT_NO_FATAL_FAILURE(InitState());
17819 VkEvent event;
17820 VkEventCreateInfo event_create_info{};
17821 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17822 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17823
17824 VkCommandPool command_pool;
17825 VkCommandPoolCreateInfo pool_create_info{};
17826 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17827 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17828 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17829 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17830
17831 VkCommandBuffer command_buffer;
17832 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17833 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17834 command_buffer_allocate_info.commandPool = command_pool;
17835 command_buffer_allocate_info.commandBufferCount = 1;
17836 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17837 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17838
17839 VkQueue queue = VK_NULL_HANDLE;
17840 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17841
17842 {
17843 VkCommandBufferBeginInfo begin_info{};
17844 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17845 vkBeginCommandBuffer(command_buffer, &begin_info);
17846
17847 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017848 vkEndCommandBuffer(command_buffer);
17849 }
17850 {
17851 VkSubmitInfo submit_info{};
17852 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17853 submit_info.commandBufferCount = 1;
17854 submit_info.pCommandBuffers = &command_buffer;
17855 submit_info.signalSemaphoreCount = 0;
17856 submit_info.pSignalSemaphores = nullptr;
17857 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17858 }
17859 {
17860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17861 "command buffer.");
17862 vkSetEvent(m_device->device(), event);
17863 m_errorMonitor->VerifyFound();
17864 }
17865
17866 vkQueueWaitIdle(queue);
17867
17868 vkDestroyEvent(m_device->device(), event, nullptr);
17869 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17870 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17871}
17872
17873// This is a positive test. No errors should be generated.
17874TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17875 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17876 "run through a Submit & WaitForFences cycle 3 times. This "
17877 "previously revealed a bug so running this positive test "
17878 "to prevent a regression.");
17879 m_errorMonitor->ExpectSuccess();
17880
17881 ASSERT_NO_FATAL_FAILURE(InitState());
17882 VkQueue queue = VK_NULL_HANDLE;
17883 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17884
17885 static const uint32_t NUM_OBJECTS = 2;
17886 static const uint32_t NUM_FRAMES = 3;
17887 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17888 VkFence fences[NUM_OBJECTS] = {};
17889
17890 VkCommandPool cmd_pool;
17891 VkCommandPoolCreateInfo cmd_pool_ci = {};
17892 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17893 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17894 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17895 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17896 ASSERT_VK_SUCCESS(err);
17897
17898 VkCommandBufferAllocateInfo cmd_buf_info = {};
17899 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17900 cmd_buf_info.commandPool = cmd_pool;
17901 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17902 cmd_buf_info.commandBufferCount = 1;
17903
17904 VkFenceCreateInfo fence_ci = {};
17905 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17906 fence_ci.pNext = nullptr;
17907 fence_ci.flags = 0;
17908
17909 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17910 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17911 ASSERT_VK_SUCCESS(err);
17912 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17913 ASSERT_VK_SUCCESS(err);
17914 }
17915
17916 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17917 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17918 // Create empty cmd buffer
17919 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17920 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17921
17922 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17923 ASSERT_VK_SUCCESS(err);
17924 err = vkEndCommandBuffer(cmd_buffers[obj]);
17925 ASSERT_VK_SUCCESS(err);
17926
17927 VkSubmitInfo submit_info = {};
17928 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17929 submit_info.commandBufferCount = 1;
17930 submit_info.pCommandBuffers = &cmd_buffers[obj];
17931 // Submit cmd buffer and wait for fence
17932 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17933 ASSERT_VK_SUCCESS(err);
17934 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17935 ASSERT_VK_SUCCESS(err);
17936 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17937 ASSERT_VK_SUCCESS(err);
17938 }
17939 }
17940 m_errorMonitor->VerifyNotFound();
17941 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17942 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17943 vkDestroyFence(m_device->device(), fences[i], nullptr);
17944 }
17945}
17946// This is a positive test. No errors should be generated.
17947TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17948
17949 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17950 "submitted on separate queues followed by a QueueWaitIdle.");
17951
17952 ASSERT_NO_FATAL_FAILURE(InitState());
17953 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17954 return;
17955
17956 m_errorMonitor->ExpectSuccess();
17957
17958 VkSemaphore semaphore;
17959 VkSemaphoreCreateInfo semaphore_create_info{};
17960 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17961 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17962
17963 VkCommandPool command_pool;
17964 VkCommandPoolCreateInfo pool_create_info{};
17965 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17966 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17967 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17968 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17969
17970 VkCommandBuffer command_buffer[2];
17971 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17972 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17973 command_buffer_allocate_info.commandPool = command_pool;
17974 command_buffer_allocate_info.commandBufferCount = 2;
17975 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17976 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17977
17978 VkQueue queue = VK_NULL_HANDLE;
17979 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17980
17981 {
17982 VkCommandBufferBeginInfo begin_info{};
17983 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17984 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17985
17986 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17987 nullptr, 0, nullptr, 0, nullptr);
17988
17989 VkViewport viewport{};
17990 viewport.maxDepth = 1.0f;
17991 viewport.minDepth = 0.0f;
17992 viewport.width = 512;
17993 viewport.height = 512;
17994 viewport.x = 0;
17995 viewport.y = 0;
17996 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17997 vkEndCommandBuffer(command_buffer[0]);
17998 }
17999 {
18000 VkCommandBufferBeginInfo begin_info{};
18001 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18002 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18003
18004 VkViewport viewport{};
18005 viewport.maxDepth = 1.0f;
18006 viewport.minDepth = 0.0f;
18007 viewport.width = 512;
18008 viewport.height = 512;
18009 viewport.x = 0;
18010 viewport.y = 0;
18011 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18012 vkEndCommandBuffer(command_buffer[1]);
18013 }
18014 {
18015 VkSubmitInfo submit_info{};
18016 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18017 submit_info.commandBufferCount = 1;
18018 submit_info.pCommandBuffers = &command_buffer[0];
18019 submit_info.signalSemaphoreCount = 1;
18020 submit_info.pSignalSemaphores = &semaphore;
18021 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18022 }
18023 {
18024 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18025 VkSubmitInfo submit_info{};
18026 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18027 submit_info.commandBufferCount = 1;
18028 submit_info.pCommandBuffers = &command_buffer[1];
18029 submit_info.waitSemaphoreCount = 1;
18030 submit_info.pWaitSemaphores = &semaphore;
18031 submit_info.pWaitDstStageMask = flags;
18032 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18033 }
18034
18035 vkQueueWaitIdle(m_device->m_queue);
18036
18037 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18038 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18039 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18040
18041 m_errorMonitor->VerifyNotFound();
18042}
18043
18044// This is a positive test. No errors should be generated.
18045TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18046
18047 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18048 "submitted on separate queues, the second having a fence"
18049 "followed by a QueueWaitIdle.");
18050
18051 ASSERT_NO_FATAL_FAILURE(InitState());
18052 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18053 return;
18054
18055 m_errorMonitor->ExpectSuccess();
18056
18057 VkFence fence;
18058 VkFenceCreateInfo fence_create_info{};
18059 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18060 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18061
18062 VkSemaphore semaphore;
18063 VkSemaphoreCreateInfo semaphore_create_info{};
18064 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18065 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18066
18067 VkCommandPool command_pool;
18068 VkCommandPoolCreateInfo pool_create_info{};
18069 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18070 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18071 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18072 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18073
18074 VkCommandBuffer command_buffer[2];
18075 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18076 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18077 command_buffer_allocate_info.commandPool = command_pool;
18078 command_buffer_allocate_info.commandBufferCount = 2;
18079 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18080 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18081
18082 VkQueue queue = VK_NULL_HANDLE;
18083 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18084
18085 {
18086 VkCommandBufferBeginInfo begin_info{};
18087 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18088 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18089
18090 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18091 nullptr, 0, nullptr, 0, nullptr);
18092
18093 VkViewport viewport{};
18094 viewport.maxDepth = 1.0f;
18095 viewport.minDepth = 0.0f;
18096 viewport.width = 512;
18097 viewport.height = 512;
18098 viewport.x = 0;
18099 viewport.y = 0;
18100 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18101 vkEndCommandBuffer(command_buffer[0]);
18102 }
18103 {
18104 VkCommandBufferBeginInfo begin_info{};
18105 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18106 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18107
18108 VkViewport viewport{};
18109 viewport.maxDepth = 1.0f;
18110 viewport.minDepth = 0.0f;
18111 viewport.width = 512;
18112 viewport.height = 512;
18113 viewport.x = 0;
18114 viewport.y = 0;
18115 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18116 vkEndCommandBuffer(command_buffer[1]);
18117 }
18118 {
18119 VkSubmitInfo submit_info{};
18120 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18121 submit_info.commandBufferCount = 1;
18122 submit_info.pCommandBuffers = &command_buffer[0];
18123 submit_info.signalSemaphoreCount = 1;
18124 submit_info.pSignalSemaphores = &semaphore;
18125 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18126 }
18127 {
18128 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18129 VkSubmitInfo submit_info{};
18130 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18131 submit_info.commandBufferCount = 1;
18132 submit_info.pCommandBuffers = &command_buffer[1];
18133 submit_info.waitSemaphoreCount = 1;
18134 submit_info.pWaitSemaphores = &semaphore;
18135 submit_info.pWaitDstStageMask = flags;
18136 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18137 }
18138
18139 vkQueueWaitIdle(m_device->m_queue);
18140
18141 vkDestroyFence(m_device->device(), fence, nullptr);
18142 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18143 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18144 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18145
18146 m_errorMonitor->VerifyNotFound();
18147}
18148
18149// This is a positive test. No errors should be generated.
18150TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18151
18152 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18153 "submitted on separate queues, the second having a fence"
18154 "followed by two consecutive WaitForFences calls on the same fence.");
18155
18156 ASSERT_NO_FATAL_FAILURE(InitState());
18157 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18158 return;
18159
18160 m_errorMonitor->ExpectSuccess();
18161
18162 VkFence fence;
18163 VkFenceCreateInfo fence_create_info{};
18164 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18165 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18166
18167 VkSemaphore semaphore;
18168 VkSemaphoreCreateInfo semaphore_create_info{};
18169 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18170 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18171
18172 VkCommandPool command_pool;
18173 VkCommandPoolCreateInfo pool_create_info{};
18174 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18175 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18176 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18177 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18178
18179 VkCommandBuffer command_buffer[2];
18180 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18181 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18182 command_buffer_allocate_info.commandPool = command_pool;
18183 command_buffer_allocate_info.commandBufferCount = 2;
18184 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18185 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18186
18187 VkQueue queue = VK_NULL_HANDLE;
18188 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18189
18190 {
18191 VkCommandBufferBeginInfo begin_info{};
18192 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18193 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18194
18195 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18196 nullptr, 0, nullptr, 0, nullptr);
18197
18198 VkViewport viewport{};
18199 viewport.maxDepth = 1.0f;
18200 viewport.minDepth = 0.0f;
18201 viewport.width = 512;
18202 viewport.height = 512;
18203 viewport.x = 0;
18204 viewport.y = 0;
18205 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18206 vkEndCommandBuffer(command_buffer[0]);
18207 }
18208 {
18209 VkCommandBufferBeginInfo begin_info{};
18210 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18211 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18212
18213 VkViewport viewport{};
18214 viewport.maxDepth = 1.0f;
18215 viewport.minDepth = 0.0f;
18216 viewport.width = 512;
18217 viewport.height = 512;
18218 viewport.x = 0;
18219 viewport.y = 0;
18220 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18221 vkEndCommandBuffer(command_buffer[1]);
18222 }
18223 {
18224 VkSubmitInfo submit_info{};
18225 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18226 submit_info.commandBufferCount = 1;
18227 submit_info.pCommandBuffers = &command_buffer[0];
18228 submit_info.signalSemaphoreCount = 1;
18229 submit_info.pSignalSemaphores = &semaphore;
18230 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18231 }
18232 {
18233 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18234 VkSubmitInfo submit_info{};
18235 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18236 submit_info.commandBufferCount = 1;
18237 submit_info.pCommandBuffers = &command_buffer[1];
18238 submit_info.waitSemaphoreCount = 1;
18239 submit_info.pWaitSemaphores = &semaphore;
18240 submit_info.pWaitDstStageMask = flags;
18241 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18242 }
18243
18244 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18245 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18246
18247 vkDestroyFence(m_device->device(), fence, nullptr);
18248 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18249 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18250 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18251
18252 m_errorMonitor->VerifyNotFound();
18253}
18254
18255TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18256
18257 ASSERT_NO_FATAL_FAILURE(InitState());
18258 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18259 printf("Test requires two queues, skipping\n");
18260 return;
18261 }
18262
18263 VkResult err;
18264
18265 m_errorMonitor->ExpectSuccess();
18266
18267 VkQueue q0 = m_device->m_queue;
18268 VkQueue q1 = nullptr;
18269 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18270 ASSERT_NE(q1, nullptr);
18271
18272 // An (empty) command buffer. We must have work in the first submission --
18273 // the layer treats unfenced work differently from fenced work.
18274 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18275 VkCommandPool pool;
18276 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18277 ASSERT_VK_SUCCESS(err);
18278 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18279 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18280 VkCommandBuffer cb;
18281 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18282 ASSERT_VK_SUCCESS(err);
18283 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18284 err = vkBeginCommandBuffer(cb, &cbbi);
18285 ASSERT_VK_SUCCESS(err);
18286 err = vkEndCommandBuffer(cb);
18287 ASSERT_VK_SUCCESS(err);
18288
18289 // A semaphore
18290 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18291 VkSemaphore s;
18292 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18293 ASSERT_VK_SUCCESS(err);
18294
18295 // First submission, to q0
18296 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18297
18298 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18299 ASSERT_VK_SUCCESS(err);
18300
18301 // Second submission, to q1, waiting on s
18302 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18303 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18304
18305 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18306 ASSERT_VK_SUCCESS(err);
18307
18308 // Wait for q0 idle
18309 err = vkQueueWaitIdle(q0);
18310 ASSERT_VK_SUCCESS(err);
18311
18312 // Command buffer should have been completed (it was on q0); reset the pool.
18313 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18314
18315 m_errorMonitor->VerifyNotFound();
18316
18317 // Force device completely idle and clean up resources
18318 vkDeviceWaitIdle(m_device->device());
18319 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18320 vkDestroySemaphore(m_device->device(), s, nullptr);
18321}
18322
18323// This is a positive test. No errors should be generated.
18324TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18325
18326 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18327 "submitted on separate queues, the second having a fence, "
18328 "followed by a WaitForFences call.");
18329
18330 ASSERT_NO_FATAL_FAILURE(InitState());
18331 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18332 return;
18333
18334 m_errorMonitor->ExpectSuccess();
18335
18336 ASSERT_NO_FATAL_FAILURE(InitState());
18337 VkFence fence;
18338 VkFenceCreateInfo fence_create_info{};
18339 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18340 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18341
18342 VkSemaphore semaphore;
18343 VkSemaphoreCreateInfo semaphore_create_info{};
18344 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18345 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18346
18347 VkCommandPool command_pool;
18348 VkCommandPoolCreateInfo pool_create_info{};
18349 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18350 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18351 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18352 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18353
18354 VkCommandBuffer command_buffer[2];
18355 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18356 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18357 command_buffer_allocate_info.commandPool = command_pool;
18358 command_buffer_allocate_info.commandBufferCount = 2;
18359 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18360 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18361
18362 VkQueue queue = VK_NULL_HANDLE;
18363 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18364
18365 {
18366 VkCommandBufferBeginInfo begin_info{};
18367 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18368 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18369
18370 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18371 nullptr, 0, nullptr, 0, nullptr);
18372
18373 VkViewport viewport{};
18374 viewport.maxDepth = 1.0f;
18375 viewport.minDepth = 0.0f;
18376 viewport.width = 512;
18377 viewport.height = 512;
18378 viewport.x = 0;
18379 viewport.y = 0;
18380 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18381 vkEndCommandBuffer(command_buffer[0]);
18382 }
18383 {
18384 VkCommandBufferBeginInfo begin_info{};
18385 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18386 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18387
18388 VkViewport viewport{};
18389 viewport.maxDepth = 1.0f;
18390 viewport.minDepth = 0.0f;
18391 viewport.width = 512;
18392 viewport.height = 512;
18393 viewport.x = 0;
18394 viewport.y = 0;
18395 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18396 vkEndCommandBuffer(command_buffer[1]);
18397 }
18398 {
18399 VkSubmitInfo submit_info{};
18400 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18401 submit_info.commandBufferCount = 1;
18402 submit_info.pCommandBuffers = &command_buffer[0];
18403 submit_info.signalSemaphoreCount = 1;
18404 submit_info.pSignalSemaphores = &semaphore;
18405 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18406 }
18407 {
18408 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18409 VkSubmitInfo submit_info{};
18410 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18411 submit_info.commandBufferCount = 1;
18412 submit_info.pCommandBuffers = &command_buffer[1];
18413 submit_info.waitSemaphoreCount = 1;
18414 submit_info.pWaitSemaphores = &semaphore;
18415 submit_info.pWaitDstStageMask = flags;
18416 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18417 }
18418
18419 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18420
18421 vkDestroyFence(m_device->device(), fence, nullptr);
18422 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18423 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18424 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18425
18426 m_errorMonitor->VerifyNotFound();
18427}
18428
18429// This is a positive test. No errors should be generated.
18430TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18431
18432 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18433 "on the same queue, sharing a signal/wait semaphore, the "
18434 "second having a fence, "
18435 "followed by a WaitForFences call.");
18436
18437 m_errorMonitor->ExpectSuccess();
18438
18439 ASSERT_NO_FATAL_FAILURE(InitState());
18440 VkFence fence;
18441 VkFenceCreateInfo fence_create_info{};
18442 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18443 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18444
18445 VkSemaphore semaphore;
18446 VkSemaphoreCreateInfo semaphore_create_info{};
18447 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18448 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18449
18450 VkCommandPool command_pool;
18451 VkCommandPoolCreateInfo pool_create_info{};
18452 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18453 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18454 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18455 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18456
18457 VkCommandBuffer command_buffer[2];
18458 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18459 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18460 command_buffer_allocate_info.commandPool = command_pool;
18461 command_buffer_allocate_info.commandBufferCount = 2;
18462 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18463 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18464
18465 {
18466 VkCommandBufferBeginInfo begin_info{};
18467 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18468 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18469
18470 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18471 nullptr, 0, nullptr, 0, nullptr);
18472
18473 VkViewport viewport{};
18474 viewport.maxDepth = 1.0f;
18475 viewport.minDepth = 0.0f;
18476 viewport.width = 512;
18477 viewport.height = 512;
18478 viewport.x = 0;
18479 viewport.y = 0;
18480 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18481 vkEndCommandBuffer(command_buffer[0]);
18482 }
18483 {
18484 VkCommandBufferBeginInfo begin_info{};
18485 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18486 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18487
18488 VkViewport viewport{};
18489 viewport.maxDepth = 1.0f;
18490 viewport.minDepth = 0.0f;
18491 viewport.width = 512;
18492 viewport.height = 512;
18493 viewport.x = 0;
18494 viewport.y = 0;
18495 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18496 vkEndCommandBuffer(command_buffer[1]);
18497 }
18498 {
18499 VkSubmitInfo submit_info{};
18500 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18501 submit_info.commandBufferCount = 1;
18502 submit_info.pCommandBuffers = &command_buffer[0];
18503 submit_info.signalSemaphoreCount = 1;
18504 submit_info.pSignalSemaphores = &semaphore;
18505 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18506 }
18507 {
18508 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18509 VkSubmitInfo submit_info{};
18510 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18511 submit_info.commandBufferCount = 1;
18512 submit_info.pCommandBuffers = &command_buffer[1];
18513 submit_info.waitSemaphoreCount = 1;
18514 submit_info.pWaitSemaphores = &semaphore;
18515 submit_info.pWaitDstStageMask = flags;
18516 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18517 }
18518
18519 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18520
18521 vkDestroyFence(m_device->device(), fence, nullptr);
18522 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18523 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18524 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18525
18526 m_errorMonitor->VerifyNotFound();
18527}
18528
18529// This is a positive test. No errors should be generated.
18530TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18531
18532 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18533 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18534 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18535
18536 m_errorMonitor->ExpectSuccess();
18537
18538 ASSERT_NO_FATAL_FAILURE(InitState());
18539 VkFence fence;
18540 VkFenceCreateInfo fence_create_info{};
18541 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18542 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18543
18544 VkCommandPool command_pool;
18545 VkCommandPoolCreateInfo pool_create_info{};
18546 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18547 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18548 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18549 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18550
18551 VkCommandBuffer command_buffer[2];
18552 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18553 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18554 command_buffer_allocate_info.commandPool = command_pool;
18555 command_buffer_allocate_info.commandBufferCount = 2;
18556 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18557 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18558
18559 {
18560 VkCommandBufferBeginInfo begin_info{};
18561 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18562 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18563
18564 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18565 nullptr, 0, nullptr, 0, nullptr);
18566
18567 VkViewport viewport{};
18568 viewport.maxDepth = 1.0f;
18569 viewport.minDepth = 0.0f;
18570 viewport.width = 512;
18571 viewport.height = 512;
18572 viewport.x = 0;
18573 viewport.y = 0;
18574 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18575 vkEndCommandBuffer(command_buffer[0]);
18576 }
18577 {
18578 VkCommandBufferBeginInfo begin_info{};
18579 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18580 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18581
18582 VkViewport viewport{};
18583 viewport.maxDepth = 1.0f;
18584 viewport.minDepth = 0.0f;
18585 viewport.width = 512;
18586 viewport.height = 512;
18587 viewport.x = 0;
18588 viewport.y = 0;
18589 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18590 vkEndCommandBuffer(command_buffer[1]);
18591 }
18592 {
18593 VkSubmitInfo submit_info{};
18594 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18595 submit_info.commandBufferCount = 1;
18596 submit_info.pCommandBuffers = &command_buffer[0];
18597 submit_info.signalSemaphoreCount = 0;
18598 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18599 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18600 }
18601 {
18602 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18603 VkSubmitInfo submit_info{};
18604 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18605 submit_info.commandBufferCount = 1;
18606 submit_info.pCommandBuffers = &command_buffer[1];
18607 submit_info.waitSemaphoreCount = 0;
18608 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18609 submit_info.pWaitDstStageMask = flags;
18610 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18611 }
18612
18613 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18614
18615 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18616 ASSERT_VK_SUCCESS(err);
18617
18618 vkDestroyFence(m_device->device(), fence, nullptr);
18619 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18620 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18621
18622 m_errorMonitor->VerifyNotFound();
18623}
18624
18625// This is a positive test. No errors should be generated.
18626TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18627
18628 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18629 "on the same queue, the second having a fence, followed "
18630 "by a WaitForFences call.");
18631
18632 m_errorMonitor->ExpectSuccess();
18633
18634 ASSERT_NO_FATAL_FAILURE(InitState());
18635 VkFence fence;
18636 VkFenceCreateInfo fence_create_info{};
18637 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18638 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18639
18640 VkCommandPool command_pool;
18641 VkCommandPoolCreateInfo pool_create_info{};
18642 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18643 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18644 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18645 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18646
18647 VkCommandBuffer command_buffer[2];
18648 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18649 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18650 command_buffer_allocate_info.commandPool = command_pool;
18651 command_buffer_allocate_info.commandBufferCount = 2;
18652 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18653 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18654
18655 {
18656 VkCommandBufferBeginInfo begin_info{};
18657 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18658 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18659
18660 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18661 nullptr, 0, nullptr, 0, nullptr);
18662
18663 VkViewport viewport{};
18664 viewport.maxDepth = 1.0f;
18665 viewport.minDepth = 0.0f;
18666 viewport.width = 512;
18667 viewport.height = 512;
18668 viewport.x = 0;
18669 viewport.y = 0;
18670 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18671 vkEndCommandBuffer(command_buffer[0]);
18672 }
18673 {
18674 VkCommandBufferBeginInfo begin_info{};
18675 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18676 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18677
18678 VkViewport viewport{};
18679 viewport.maxDepth = 1.0f;
18680 viewport.minDepth = 0.0f;
18681 viewport.width = 512;
18682 viewport.height = 512;
18683 viewport.x = 0;
18684 viewport.y = 0;
18685 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18686 vkEndCommandBuffer(command_buffer[1]);
18687 }
18688 {
18689 VkSubmitInfo submit_info{};
18690 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18691 submit_info.commandBufferCount = 1;
18692 submit_info.pCommandBuffers = &command_buffer[0];
18693 submit_info.signalSemaphoreCount = 0;
18694 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18695 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18696 }
18697 {
18698 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18699 VkSubmitInfo submit_info{};
18700 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18701 submit_info.commandBufferCount = 1;
18702 submit_info.pCommandBuffers = &command_buffer[1];
18703 submit_info.waitSemaphoreCount = 0;
18704 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18705 submit_info.pWaitDstStageMask = flags;
18706 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18707 }
18708
18709 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18710
18711 vkDestroyFence(m_device->device(), fence, nullptr);
18712 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18713 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18714
18715 m_errorMonitor->VerifyNotFound();
18716}
18717
18718// This is a positive test. No errors should be generated.
18719TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18720
18721 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18722 "QueueSubmit call followed by a WaitForFences call.");
18723 ASSERT_NO_FATAL_FAILURE(InitState());
18724
18725 m_errorMonitor->ExpectSuccess();
18726
18727 VkFence fence;
18728 VkFenceCreateInfo fence_create_info{};
18729 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18730 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18731
18732 VkSemaphore semaphore;
18733 VkSemaphoreCreateInfo semaphore_create_info{};
18734 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18735 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18736
18737 VkCommandPool command_pool;
18738 VkCommandPoolCreateInfo pool_create_info{};
18739 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18740 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18741 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18742 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18743
18744 VkCommandBuffer command_buffer[2];
18745 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18746 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18747 command_buffer_allocate_info.commandPool = command_pool;
18748 command_buffer_allocate_info.commandBufferCount = 2;
18749 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18750 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18751
18752 {
18753 VkCommandBufferBeginInfo begin_info{};
18754 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18755 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18756
18757 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18758 nullptr, 0, nullptr, 0, nullptr);
18759
18760 VkViewport viewport{};
18761 viewport.maxDepth = 1.0f;
18762 viewport.minDepth = 0.0f;
18763 viewport.width = 512;
18764 viewport.height = 512;
18765 viewport.x = 0;
18766 viewport.y = 0;
18767 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18768 vkEndCommandBuffer(command_buffer[0]);
18769 }
18770 {
18771 VkCommandBufferBeginInfo begin_info{};
18772 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18773 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18774
18775 VkViewport viewport{};
18776 viewport.maxDepth = 1.0f;
18777 viewport.minDepth = 0.0f;
18778 viewport.width = 512;
18779 viewport.height = 512;
18780 viewport.x = 0;
18781 viewport.y = 0;
18782 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18783 vkEndCommandBuffer(command_buffer[1]);
18784 }
18785 {
18786 VkSubmitInfo submit_info[2];
18787 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18788
18789 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18790 submit_info[0].pNext = NULL;
18791 submit_info[0].commandBufferCount = 1;
18792 submit_info[0].pCommandBuffers = &command_buffer[0];
18793 submit_info[0].signalSemaphoreCount = 1;
18794 submit_info[0].pSignalSemaphores = &semaphore;
18795 submit_info[0].waitSemaphoreCount = 0;
18796 submit_info[0].pWaitSemaphores = NULL;
18797 submit_info[0].pWaitDstStageMask = 0;
18798
18799 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18800 submit_info[1].pNext = NULL;
18801 submit_info[1].commandBufferCount = 1;
18802 submit_info[1].pCommandBuffers = &command_buffer[1];
18803 submit_info[1].waitSemaphoreCount = 1;
18804 submit_info[1].pWaitSemaphores = &semaphore;
18805 submit_info[1].pWaitDstStageMask = flags;
18806 submit_info[1].signalSemaphoreCount = 0;
18807 submit_info[1].pSignalSemaphores = NULL;
18808 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18809 }
18810
18811 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18812
18813 vkDestroyFence(m_device->device(), fence, nullptr);
18814 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18815 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18816 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18817
18818 m_errorMonitor->VerifyNotFound();
18819}
18820
18821TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18822 m_errorMonitor->ExpectSuccess();
18823
18824 ASSERT_NO_FATAL_FAILURE(InitState());
18825 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18826
18827 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18828 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18829
18830 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18831 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18832 m_errorMonitor->VerifyNotFound();
18833 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18834 m_errorMonitor->VerifyNotFound();
18835 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18836 m_errorMonitor->VerifyNotFound();
18837
18838 m_commandBuffer->EndCommandBuffer();
18839 m_errorMonitor->VerifyNotFound();
18840}
18841
18842TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18843 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18844 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18845 "has a valid layout, and a second subpass then uses a "
18846 "valid *READ_ONLY* layout.");
18847 m_errorMonitor->ExpectSuccess();
18848 ASSERT_NO_FATAL_FAILURE(InitState());
18849
18850 VkAttachmentReference attach[2] = {};
18851 attach[0].attachment = 0;
18852 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18853 attach[1].attachment = 0;
18854 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18855 VkSubpassDescription subpasses[2] = {};
18856 // First subpass clears DS attach on load
18857 subpasses[0].pDepthStencilAttachment = &attach[0];
18858 // 2nd subpass reads in DS as input attachment
18859 subpasses[1].inputAttachmentCount = 1;
18860 subpasses[1].pInputAttachments = &attach[1];
18861 VkAttachmentDescription attach_desc = {};
18862 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18863 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18864 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18865 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18866 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18867 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18868 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18869 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18870 VkRenderPassCreateInfo rpci = {};
18871 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18872 rpci.attachmentCount = 1;
18873 rpci.pAttachments = &attach_desc;
18874 rpci.subpassCount = 2;
18875 rpci.pSubpasses = subpasses;
18876
18877 // Now create RenderPass and verify no errors
18878 VkRenderPass rp;
18879 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18880 m_errorMonitor->VerifyNotFound();
18881
18882 vkDestroyRenderPass(m_device->device(), rp, NULL);
18883}
18884
18885TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18886 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18887 "as vertex attributes");
18888 m_errorMonitor->ExpectSuccess();
18889
18890 ASSERT_NO_FATAL_FAILURE(InitState());
18891 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18892
18893 VkVertexInputBindingDescription input_binding;
18894 memset(&input_binding, 0, sizeof(input_binding));
18895
18896 VkVertexInputAttributeDescription input_attribs[2];
18897 memset(input_attribs, 0, sizeof(input_attribs));
18898
18899 for (int i = 0; i < 2; i++) {
18900 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18901 input_attribs[i].location = i;
18902 }
18903
18904 char const *vsSource = "#version 450\n"
18905 "\n"
18906 "layout(location=0) in mat2x4 x;\n"
18907 "out gl_PerVertex {\n"
18908 " vec4 gl_Position;\n"
18909 "};\n"
18910 "void main(){\n"
18911 " gl_Position = x[0] + x[1];\n"
18912 "}\n";
18913 char const *fsSource = "#version 450\n"
18914 "\n"
18915 "layout(location=0) out vec4 color;\n"
18916 "void main(){\n"
18917 " color = vec4(1);\n"
18918 "}\n";
18919
18920 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18921 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18922
18923 VkPipelineObj pipe(m_device);
18924 pipe.AddColorAttachment();
18925 pipe.AddShader(&vs);
18926 pipe.AddShader(&fs);
18927
18928 pipe.AddVertexInputBindings(&input_binding, 1);
18929 pipe.AddVertexInputAttribs(input_attribs, 2);
18930
18931 VkDescriptorSetObj descriptorSet(m_device);
18932 descriptorSet.AppendDummy();
18933 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18934
18935 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18936
18937 /* expect success */
18938 m_errorMonitor->VerifyNotFound();
18939}
18940
18941TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18942 m_errorMonitor->ExpectSuccess();
18943
18944 ASSERT_NO_FATAL_FAILURE(InitState());
18945 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18946
18947 VkVertexInputBindingDescription input_binding;
18948 memset(&input_binding, 0, sizeof(input_binding));
18949
18950 VkVertexInputAttributeDescription input_attribs[2];
18951 memset(input_attribs, 0, sizeof(input_attribs));
18952
18953 for (int i = 0; i < 2; i++) {
18954 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18955 input_attribs[i].location = i;
18956 }
18957
18958 char const *vsSource = "#version 450\n"
18959 "\n"
18960 "layout(location=0) in vec4 x[2];\n"
18961 "out gl_PerVertex {\n"
18962 " vec4 gl_Position;\n"
18963 "};\n"
18964 "void main(){\n"
18965 " gl_Position = x[0] + x[1];\n"
18966 "}\n";
18967 char const *fsSource = "#version 450\n"
18968 "\n"
18969 "layout(location=0) out vec4 color;\n"
18970 "void main(){\n"
18971 " color = vec4(1);\n"
18972 "}\n";
18973
18974 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18975 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18976
18977 VkPipelineObj pipe(m_device);
18978 pipe.AddColorAttachment();
18979 pipe.AddShader(&vs);
18980 pipe.AddShader(&fs);
18981
18982 pipe.AddVertexInputBindings(&input_binding, 1);
18983 pipe.AddVertexInputAttribs(input_attribs, 2);
18984
18985 VkDescriptorSetObj descriptorSet(m_device);
18986 descriptorSet.AppendDummy();
18987 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18988
18989 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18990
18991 m_errorMonitor->VerifyNotFound();
18992}
18993
18994TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18995 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18996 "through multiple vertex shader inputs, each consuming a different "
18997 "subset of the components.");
18998 m_errorMonitor->ExpectSuccess();
18999
19000 ASSERT_NO_FATAL_FAILURE(InitState());
19001 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19002
19003 VkVertexInputBindingDescription input_binding;
19004 memset(&input_binding, 0, sizeof(input_binding));
19005
19006 VkVertexInputAttributeDescription input_attribs[3];
19007 memset(input_attribs, 0, sizeof(input_attribs));
19008
19009 for (int i = 0; i < 3; i++) {
19010 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19011 input_attribs[i].location = i;
19012 }
19013
19014 char const *vsSource = "#version 450\n"
19015 "\n"
19016 "layout(location=0) in vec4 x;\n"
19017 "layout(location=1) in vec3 y1;\n"
19018 "layout(location=1, component=3) in float y2;\n"
19019 "layout(location=2) in vec4 z;\n"
19020 "out gl_PerVertex {\n"
19021 " vec4 gl_Position;\n"
19022 "};\n"
19023 "void main(){\n"
19024 " gl_Position = x + vec4(y1, y2) + z;\n"
19025 "}\n";
19026 char const *fsSource = "#version 450\n"
19027 "\n"
19028 "layout(location=0) out vec4 color;\n"
19029 "void main(){\n"
19030 " color = vec4(1);\n"
19031 "}\n";
19032
19033 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19034 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19035
19036 VkPipelineObj pipe(m_device);
19037 pipe.AddColorAttachment();
19038 pipe.AddShader(&vs);
19039 pipe.AddShader(&fs);
19040
19041 pipe.AddVertexInputBindings(&input_binding, 1);
19042 pipe.AddVertexInputAttribs(input_attribs, 3);
19043
19044 VkDescriptorSetObj descriptorSet(m_device);
19045 descriptorSet.AppendDummy();
19046 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19047
19048 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19049
19050 m_errorMonitor->VerifyNotFound();
19051}
19052
19053TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19054 m_errorMonitor->ExpectSuccess();
19055
19056 ASSERT_NO_FATAL_FAILURE(InitState());
19057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19058
19059 char const *vsSource = "#version 450\n"
19060 "out gl_PerVertex {\n"
19061 " vec4 gl_Position;\n"
19062 "};\n"
19063 "void main(){\n"
19064 " gl_Position = vec4(0);\n"
19065 "}\n";
19066 char const *fsSource = "#version 450\n"
19067 "\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 fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19075
19076 VkPipelineObj pipe(m_device);
19077 pipe.AddColorAttachment();
19078 pipe.AddShader(&vs);
19079 pipe.AddShader(&fs);
19080
19081 VkDescriptorSetObj descriptorSet(m_device);
19082 descriptorSet.AppendDummy();
19083 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19084
19085 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19086
19087 m_errorMonitor->VerifyNotFound();
19088}
19089
19090TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19091 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19092 "set out in 14.1.3: fundamental type must match, and producer side must "
19093 "have at least as many components");
19094 m_errorMonitor->ExpectSuccess();
19095
19096 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19097
19098 ASSERT_NO_FATAL_FAILURE(InitState());
19099 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19100
19101 char const *vsSource = "#version 450\n"
19102 "out gl_PerVertex {\n"
19103 " vec4 gl_Position;\n"
19104 "};\n"
19105 "layout(location=0) out vec3 x;\n"
19106 "layout(location=1) out ivec3 y;\n"
19107 "layout(location=2) out vec3 z;\n"
19108 "void main(){\n"
19109 " gl_Position = vec4(0);\n"
19110 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19111 "}\n";
19112 char const *fsSource = "#version 450\n"
19113 "\n"
19114 "layout(location=0) out vec4 color;\n"
19115 "layout(location=0) in float x;\n"
19116 "layout(location=1) flat in int y;\n"
19117 "layout(location=2) in vec2 z;\n"
19118 "void main(){\n"
19119 " color = vec4(1 + x + y + z.x);\n"
19120 "}\n";
19121
19122 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19123 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19124
19125 VkPipelineObj pipe(m_device);
19126 pipe.AddColorAttachment();
19127 pipe.AddShader(&vs);
19128 pipe.AddShader(&fs);
19129
19130 VkDescriptorSetObj descriptorSet(m_device);
19131 descriptorSet.AppendDummy();
19132 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19133
19134 VkResult err = VK_SUCCESS;
19135 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19136 ASSERT_VK_SUCCESS(err);
19137
19138 m_errorMonitor->VerifyNotFound();
19139}
19140
19141TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19142 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19143 "passed between the TCS and TES stages");
19144 m_errorMonitor->ExpectSuccess();
19145
19146 ASSERT_NO_FATAL_FAILURE(InitState());
19147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19148
19149 if (!m_device->phy().features().tessellationShader) {
19150 printf("Device does not support tessellation shaders; skipped.\n");
19151 return;
19152 }
19153
19154 char const *vsSource = "#version 450\n"
19155 "void main(){}\n";
19156 char const *tcsSource = "#version 450\n"
19157 "layout(location=0) out int x[];\n"
19158 "layout(vertices=3) out;\n"
19159 "void main(){\n"
19160 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19161 " gl_TessLevelInner[0] = 1;\n"
19162 " x[gl_InvocationID] = gl_InvocationID;\n"
19163 "}\n";
19164 char const *tesSource = "#version 450\n"
19165 "layout(triangles, equal_spacing, cw) in;\n"
19166 "layout(location=0) in int x[];\n"
19167 "out gl_PerVertex { vec4 gl_Position; };\n"
19168 "void main(){\n"
19169 " gl_Position.xyz = gl_TessCoord;\n"
19170 " gl_Position.w = x[0] + x[1] + x[2];\n"
19171 "}\n";
19172 char const *fsSource = "#version 450\n"
19173 "layout(location=0) out vec4 color;\n"
19174 "void main(){\n"
19175 " color = vec4(1);\n"
19176 "}\n";
19177
19178 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19179 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19180 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19181 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19182
19183 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19184 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19185
19186 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19187
19188 VkPipelineObj pipe(m_device);
19189 pipe.SetInputAssembly(&iasci);
19190 pipe.SetTessellation(&tsci);
19191 pipe.AddColorAttachment();
19192 pipe.AddShader(&vs);
19193 pipe.AddShader(&tcs);
19194 pipe.AddShader(&tes);
19195 pipe.AddShader(&fs);
19196
19197 VkDescriptorSetObj descriptorSet(m_device);
19198 descriptorSet.AppendDummy();
19199 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19200
19201 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19202
19203 m_errorMonitor->VerifyNotFound();
19204}
19205
19206TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19207 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19208 "interface block passed into the geometry shader. This "
19209 "is interesting because the 'extra' array level is not "
19210 "present on the member type, but on the block instance.");
19211 m_errorMonitor->ExpectSuccess();
19212
19213 ASSERT_NO_FATAL_FAILURE(InitState());
19214 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19215
19216 if (!m_device->phy().features().geometryShader) {
19217 printf("Device does not support geometry shaders; skipped.\n");
19218 return;
19219 }
19220
19221 char const *vsSource = "#version 450\n"
19222 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19223 "void main(){\n"
19224 " vs_out.x = vec4(1);\n"
19225 "}\n";
19226 char const *gsSource = "#version 450\n"
19227 "layout(triangles) in;\n"
19228 "layout(triangle_strip, max_vertices=3) out;\n"
19229 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19230 "out gl_PerVertex { vec4 gl_Position; };\n"
19231 "void main() {\n"
19232 " gl_Position = gs_in[0].x;\n"
19233 " EmitVertex();\n"
19234 "}\n";
19235 char const *fsSource = "#version 450\n"
19236 "layout(location=0) out vec4 color;\n"
19237 "void main(){\n"
19238 " color = vec4(1);\n"
19239 "}\n";
19240
19241 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19242 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19243 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19244
19245 VkPipelineObj pipe(m_device);
19246 pipe.AddColorAttachment();
19247 pipe.AddShader(&vs);
19248 pipe.AddShader(&gs);
19249 pipe.AddShader(&fs);
19250
19251 VkDescriptorSetObj descriptorSet(m_device);
19252 descriptorSet.AppendDummy();
19253 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19254
19255 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19256
19257 m_errorMonitor->VerifyNotFound();
19258}
19259
19260TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19261 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19262 "attributes. This is interesting because they consume multiple "
19263 "locations.");
19264 m_errorMonitor->ExpectSuccess();
19265
19266 ASSERT_NO_FATAL_FAILURE(InitState());
19267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19268
19269 if (!m_device->phy().features().shaderFloat64) {
19270 printf("Device does not support 64bit vertex attributes; skipped.\n");
19271 return;
19272 }
19273
19274 VkVertexInputBindingDescription input_bindings[1];
19275 memset(input_bindings, 0, sizeof(input_bindings));
19276
19277 VkVertexInputAttributeDescription input_attribs[4];
19278 memset(input_attribs, 0, sizeof(input_attribs));
19279 input_attribs[0].location = 0;
19280 input_attribs[0].offset = 0;
19281 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19282 input_attribs[1].location = 2;
19283 input_attribs[1].offset = 32;
19284 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19285 input_attribs[2].location = 4;
19286 input_attribs[2].offset = 64;
19287 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19288 input_attribs[3].location = 6;
19289 input_attribs[3].offset = 96;
19290 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19291
19292 char const *vsSource = "#version 450\n"
19293 "\n"
19294 "layout(location=0) in dmat4 x;\n"
19295 "out gl_PerVertex {\n"
19296 " vec4 gl_Position;\n"
19297 "};\n"
19298 "void main(){\n"
19299 " gl_Position = vec4(x[0][0]);\n"
19300 "}\n";
19301 char const *fsSource = "#version 450\n"
19302 "\n"
19303 "layout(location=0) out vec4 color;\n"
19304 "void main(){\n"
19305 " color = vec4(1);\n"
19306 "}\n";
19307
19308 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19309 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19310
19311 VkPipelineObj pipe(m_device);
19312 pipe.AddColorAttachment();
19313 pipe.AddShader(&vs);
19314 pipe.AddShader(&fs);
19315
19316 pipe.AddVertexInputBindings(input_bindings, 1);
19317 pipe.AddVertexInputAttribs(input_attribs, 4);
19318
19319 VkDescriptorSetObj descriptorSet(m_device);
19320 descriptorSet.AppendDummy();
19321 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19322
19323 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19324
19325 m_errorMonitor->VerifyNotFound();
19326}
19327
19328TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19329 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19330 m_errorMonitor->ExpectSuccess();
19331
19332 ASSERT_NO_FATAL_FAILURE(InitState());
19333
19334 char const *vsSource = "#version 450\n"
19335 "\n"
19336 "out gl_PerVertex {\n"
19337 " vec4 gl_Position;\n"
19338 "};\n"
19339 "void main(){\n"
19340 " gl_Position = vec4(1);\n"
19341 "}\n";
19342 char const *fsSource = "#version 450\n"
19343 "\n"
19344 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19345 "layout(location=0) out vec4 color;\n"
19346 "void main() {\n"
19347 " color = subpassLoad(x);\n"
19348 "}\n";
19349
19350 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19351 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19352
19353 VkPipelineObj pipe(m_device);
19354 pipe.AddShader(&vs);
19355 pipe.AddShader(&fs);
19356 pipe.AddColorAttachment();
19357 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19358
19359 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19360 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19361 VkDescriptorSetLayout dsl;
19362 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19363 ASSERT_VK_SUCCESS(err);
19364
19365 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19366 VkPipelineLayout pl;
19367 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19368 ASSERT_VK_SUCCESS(err);
19369
19370 VkAttachmentDescription descs[2] = {
19371 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19372 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19373 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19374 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19375 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19376 };
19377 VkAttachmentReference color = {
19378 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19379 };
19380 VkAttachmentReference input = {
19381 1, VK_IMAGE_LAYOUT_GENERAL,
19382 };
19383
19384 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19385
19386 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19387 VkRenderPass rp;
19388 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19389 ASSERT_VK_SUCCESS(err);
19390
19391 // should be OK. would go wrong here if it's going to...
19392 pipe.CreateVKPipeline(pl, rp);
19393
19394 m_errorMonitor->VerifyNotFound();
19395
19396 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19397 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19398 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19399}
19400
19401TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19402 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19403 "descriptor-backed resource which is not provided, but the shader does not "
19404 "statically use it. This is interesting because it requires compute pipelines "
19405 "to have a proper descriptor use walk, which they didn't for some time.");
19406 m_errorMonitor->ExpectSuccess();
19407
19408 ASSERT_NO_FATAL_FAILURE(InitState());
19409
19410 char const *csSource = "#version 450\n"
19411 "\n"
19412 "layout(local_size_x=1) in;\n"
19413 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19414 "void main(){\n"
19415 " // x is not used.\n"
19416 "}\n";
19417
19418 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19419
19420 VkDescriptorSetObj descriptorSet(m_device);
19421 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19422
19423 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19424 nullptr,
19425 0,
19426 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19427 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19428 descriptorSet.GetPipelineLayout(),
19429 VK_NULL_HANDLE,
19430 -1 };
19431
19432 VkPipeline pipe;
19433 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19434
19435 m_errorMonitor->VerifyNotFound();
19436
19437 if (err == VK_SUCCESS) {
19438 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19439 }
19440}
19441
19442TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19443 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19444 "sampler portion of a combined image + sampler");
19445 m_errorMonitor->ExpectSuccess();
19446
19447 ASSERT_NO_FATAL_FAILURE(InitState());
19448
19449 VkDescriptorSetLayoutBinding bindings[] = {
19450 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19451 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19452 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19453 };
19454 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19455 VkDescriptorSetLayout dsl;
19456 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19457 ASSERT_VK_SUCCESS(err);
19458
19459 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19460 VkPipelineLayout pl;
19461 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19462 ASSERT_VK_SUCCESS(err);
19463
19464 char const *csSource = "#version 450\n"
19465 "\n"
19466 "layout(local_size_x=1) in;\n"
19467 "layout(set=0, binding=0) uniform sampler s;\n"
19468 "layout(set=0, binding=1) uniform texture2D t;\n"
19469 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19470 "void main() {\n"
19471 " x = texture(sampler2D(t, s), vec2(0));\n"
19472 "}\n";
19473 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19474
19475 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19476 nullptr,
19477 0,
19478 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19479 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19480 pl,
19481 VK_NULL_HANDLE,
19482 -1 };
19483
19484 VkPipeline pipe;
19485 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19486
19487 m_errorMonitor->VerifyNotFound();
19488
19489 if (err == VK_SUCCESS) {
19490 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19491 }
19492
19493 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19494 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19495}
19496
19497TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19498 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19499 "image portion of a combined image + sampler");
19500 m_errorMonitor->ExpectSuccess();
19501
19502 ASSERT_NO_FATAL_FAILURE(InitState());
19503
19504 VkDescriptorSetLayoutBinding bindings[] = {
19505 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19506 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19507 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19508 };
19509 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19510 VkDescriptorSetLayout dsl;
19511 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19512 ASSERT_VK_SUCCESS(err);
19513
19514 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19515 VkPipelineLayout pl;
19516 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19517 ASSERT_VK_SUCCESS(err);
19518
19519 char const *csSource = "#version 450\n"
19520 "\n"
19521 "layout(local_size_x=1) in;\n"
19522 "layout(set=0, binding=0) uniform texture2D t;\n"
19523 "layout(set=0, binding=1) uniform sampler s;\n"
19524 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19525 "void main() {\n"
19526 " x = texture(sampler2D(t, s), vec2(0));\n"
19527 "}\n";
19528 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19529
19530 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19531 nullptr,
19532 0,
19533 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19534 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19535 pl,
19536 VK_NULL_HANDLE,
19537 -1 };
19538
19539 VkPipeline pipe;
19540 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19541
19542 m_errorMonitor->VerifyNotFound();
19543
19544 if (err == VK_SUCCESS) {
19545 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19546 }
19547
19548 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19549 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19550}
19551
19552TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19553 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19554 "both the sampler and the image of a combined image+sampler "
19555 "but via separate variables");
19556 m_errorMonitor->ExpectSuccess();
19557
19558 ASSERT_NO_FATAL_FAILURE(InitState());
19559
19560 VkDescriptorSetLayoutBinding bindings[] = {
19561 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19562 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19563 };
19564 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19565 VkDescriptorSetLayout dsl;
19566 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19567 ASSERT_VK_SUCCESS(err);
19568
19569 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19570 VkPipelineLayout pl;
19571 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19572 ASSERT_VK_SUCCESS(err);
19573
19574 char const *csSource = "#version 450\n"
19575 "\n"
19576 "layout(local_size_x=1) in;\n"
19577 "layout(set=0, binding=0) uniform texture2D t;\n"
19578 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19579 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19580 "void main() {\n"
19581 " x = texture(sampler2D(t, s), vec2(0));\n"
19582 "}\n";
19583 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19584
19585 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19586 nullptr,
19587 0,
19588 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19589 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19590 pl,
19591 VK_NULL_HANDLE,
19592 -1 };
19593
19594 VkPipeline pipe;
19595 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19596
19597 m_errorMonitor->VerifyNotFound();
19598
19599 if (err == VK_SUCCESS) {
19600 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19601 }
19602
19603 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19604 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19605}
19606
19607TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19608 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19609
19610 ASSERT_NO_FATAL_FAILURE(InitState());
19611
19612 // Positive test to check parameter_validation and unique_objects support
19613 // for NV_dedicated_allocation
19614 uint32_t extension_count = 0;
19615 bool supports_nv_dedicated_allocation = false;
19616 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19617 ASSERT_VK_SUCCESS(err);
19618
19619 if (extension_count > 0) {
19620 std::vector<VkExtensionProperties> available_extensions(extension_count);
19621
19622 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19623 ASSERT_VK_SUCCESS(err);
19624
19625 for (const auto &extension_props : available_extensions) {
19626 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19627 supports_nv_dedicated_allocation = true;
19628 }
19629 }
19630 }
19631
19632 if (supports_nv_dedicated_allocation) {
19633 m_errorMonitor->ExpectSuccess();
19634
19635 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19636 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19637 dedicated_buffer_create_info.pNext = nullptr;
19638 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19639
19640 uint32_t queue_family_index = 0;
19641 VkBufferCreateInfo buffer_create_info = {};
19642 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19643 buffer_create_info.pNext = &dedicated_buffer_create_info;
19644 buffer_create_info.size = 1024;
19645 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19646 buffer_create_info.queueFamilyIndexCount = 1;
19647 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19648
19649 VkBuffer buffer;
19650 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19651 ASSERT_VK_SUCCESS(err);
19652
19653 VkMemoryRequirements memory_reqs;
19654 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19655
19656 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19657 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19658 dedicated_memory_info.pNext = nullptr;
19659 dedicated_memory_info.buffer = buffer;
19660 dedicated_memory_info.image = VK_NULL_HANDLE;
19661
19662 VkMemoryAllocateInfo memory_info = {};
19663 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19664 memory_info.pNext = &dedicated_memory_info;
19665 memory_info.allocationSize = memory_reqs.size;
19666
19667 bool pass;
19668 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19669 ASSERT_TRUE(pass);
19670
19671 VkDeviceMemory buffer_memory;
19672 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19673 ASSERT_VK_SUCCESS(err);
19674
19675 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19676 ASSERT_VK_SUCCESS(err);
19677
19678 vkDestroyBuffer(m_device->device(), buffer, NULL);
19679 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19680
19681 m_errorMonitor->VerifyNotFound();
19682 }
19683}
19684
19685TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19686 VkResult err;
19687
19688 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19689
19690 ASSERT_NO_FATAL_FAILURE(InitState());
19691 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19692
19693 std::vector<const char *> device_extension_names;
19694 auto features = m_device->phy().features();
19695 // Artificially disable support for non-solid fill modes
19696 features.fillModeNonSolid = false;
19697 // The sacrificial device object
19698 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19699
19700 VkRenderpassObj render_pass(&test_device);
19701
19702 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19703 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19704 pipeline_layout_ci.setLayoutCount = 0;
19705 pipeline_layout_ci.pSetLayouts = NULL;
19706
19707 VkPipelineLayout pipeline_layout;
19708 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19709 ASSERT_VK_SUCCESS(err);
19710
19711 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19712 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19713 rs_ci.pNext = nullptr;
19714 rs_ci.lineWidth = 1.0f;
19715 rs_ci.rasterizerDiscardEnable = true;
19716
19717 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19718 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19719
19720 // Set polygonMode=FILL. No error is expected
19721 m_errorMonitor->ExpectSuccess();
19722 {
19723 VkPipelineObj pipe(&test_device);
19724 pipe.AddShader(&vs);
19725 pipe.AddShader(&fs);
19726 pipe.AddColorAttachment();
19727 // Set polygonMode to a good value
19728 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19729 pipe.SetRasterization(&rs_ci);
19730 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19731 }
19732 m_errorMonitor->VerifyNotFound();
19733
19734 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19735}
19736
19737TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19738 VkResult err;
19739 ASSERT_NO_FATAL_FAILURE(InitState());
19740 ASSERT_NO_FATAL_FAILURE(InitViewport());
19741 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19742
19743 VkPipelineLayout pipeline_layout;
19744 VkPushConstantRange pc_range = {};
19745 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19746 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19747 pipeline_layout_ci.pushConstantRangeCount = 1;
19748 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19749
19750 //
19751 // Check for invalid push constant ranges in pipeline layouts.
19752 //
19753 struct PipelineLayoutTestCase {
19754 VkPushConstantRange const range;
19755 char const *msg;
19756 };
19757
19758 // Check for overlapping ranges
19759 const uint32_t ranges_per_test = 5;
19760 struct OverlappingRangeTestCase {
19761 VkPushConstantRange const ranges[ranges_per_test];
19762 char const *msg;
19763 };
19764
19765 // Run some positive tests to make sure overlap checking in the layer is OK
19766 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19767 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19768 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19769 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19770 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19771 "" },
19772 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19773 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19774 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19775 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19776 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19777 "" } } };
19778 for (const auto &iter : overlapping_range_tests_pos) {
19779 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19780 m_errorMonitor->ExpectSuccess();
19781 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19782 m_errorMonitor->VerifyNotFound();
19783 if (VK_SUCCESS == err) {
19784 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19785 }
19786 }
19787
19788 //
19789 // CmdPushConstants tests
19790 //
19791 const uint8_t dummy_values[100] = {};
19792
19793 BeginCommandBuffer();
19794
19795 // positive overlapping range tests with cmd
19796 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19797 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19798 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19799 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19800 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19801 } };
19802
19803 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19804 const VkPushConstantRange pc_range4[] = {
19805 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19806 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19807 };
19808
19809 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19810 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19811 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19812 ASSERT_VK_SUCCESS(err);
19813 for (const auto &iter : cmd_overlap_tests_pos) {
19814 m_errorMonitor->ExpectSuccess();
19815 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19816 iter.range.size, dummy_values);
19817 m_errorMonitor->VerifyNotFound();
19818 }
19819 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19820
19821 EndCommandBuffer();
19822}
19823
19824
19825
19826
19827
19828
19829
19830#if 0 // A few devices have issues with this test so disabling for now
19831TEST_F(VkPositiveLayerTest, LongFenceChain)
19832{
19833 m_errorMonitor->ExpectSuccess();
19834
19835 ASSERT_NO_FATAL_FAILURE(InitState());
19836 VkResult err;
19837
19838 std::vector<VkFence> fences;
19839
19840 const int chainLength = 32768;
19841
19842 for (int i = 0; i < chainLength; i++) {
19843 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19844 VkFence fence;
19845 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19846 ASSERT_VK_SUCCESS(err);
19847
19848 fences.push_back(fence);
19849
19850 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19851 0, nullptr, 0, nullptr };
19852 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19853 ASSERT_VK_SUCCESS(err);
19854
19855 }
19856
19857 // BOOM, stack overflow.
19858 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19859
19860 for (auto fence : fences)
19861 vkDestroyFence(m_device->device(), fence, nullptr);
19862
19863 m_errorMonitor->VerifyNotFound();
19864}
19865#endif
19866
19867
Cody Northrop1242dfd2016-07-13 17:24:59 -060019868#if defined(ANDROID) && defined(VALIDATION_APK)
19869static bool initialized = false;
19870static bool active = false;
19871
19872// Convert Intents to argv
19873// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019874std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019875 std::vector<std::string> args;
19876 JavaVM &vm = *app.activity->vm;
19877 JNIEnv *p_env;
19878 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19879 return args;
19880
19881 JNIEnv &env = *p_env;
19882 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019883 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019884 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019885 jmethodID get_string_extra_method =
19886 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019887 jvalue get_string_extra_args;
19888 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019889 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019890
19891 std::string args_str;
19892 if (extra_str) {
19893 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19894 args_str = extra_utf;
19895 env.ReleaseStringUTFChars(extra_str, extra_utf);
19896 env.DeleteLocalRef(extra_str);
19897 }
19898
19899 env.DeleteLocalRef(get_string_extra_args.l);
19900 env.DeleteLocalRef(intent);
19901 vm.DetachCurrentThread();
19902
19903 // split args_str
19904 std::stringstream ss(args_str);
19905 std::string arg;
19906 while (std::getline(ss, arg, ' ')) {
19907 if (!arg.empty())
19908 args.push_back(arg);
19909 }
19910
19911 return args;
19912}
19913
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019914static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019915
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019916static void processCommand(struct android_app *app, int32_t cmd) {
19917 switch (cmd) {
19918 case APP_CMD_INIT_WINDOW: {
19919 if (app->window) {
19920 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019921 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019922 break;
19923 }
19924 case APP_CMD_GAINED_FOCUS: {
19925 active = true;
19926 break;
19927 }
19928 case APP_CMD_LOST_FOCUS: {
19929 active = false;
19930 break;
19931 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019932 }
19933}
19934
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019935void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019936 app_dummy();
19937
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019938 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019939
19940 int vulkanSupport = InitVulkan();
19941 if (vulkanSupport == 0) {
19942 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19943 return;
19944 }
19945
19946 app->onAppCmd = processCommand;
19947 app->onInputEvent = processInput;
19948
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019949 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019950 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019951 struct android_poll_source *source;
19952 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019953 if (source) {
19954 source->process(app, source);
19955 }
19956
19957 if (app->destroyRequested != 0) {
19958 VkTestFramework::Finish();
19959 return;
19960 }
19961 }
19962
19963 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019964 // Use the following key to send arguments to gtest, i.e.
19965 // --es args "--gtest_filter=-VkLayerTest.foo"
19966 const char key[] = "args";
19967 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019968
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019969 std::string filter = "";
19970 if (args.size() > 0) {
19971 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19972 filter += args[0];
19973 } else {
19974 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19975 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019976
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019977 int argc = 2;
19978 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19979 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019980
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019981 // Route output to files until we can override the gtest output
19982 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19983 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019985 ::testing::InitGoogleTest(&argc, argv);
19986 VkTestFramework::InitArgs(&argc, argv);
19987 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019989 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019991 if (result != 0) {
19992 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19993 } else {
19994 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19995 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019996
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019997 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019998
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019999 fclose(stdout);
20000 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020001
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020002 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020003
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020004 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020005 }
20006 }
20007}
20008#endif
20009
Tony Barbour300a6082015-04-07 13:44:53 -060020010int main(int argc, char **argv) {
20011 int result;
20012
Cody Northrop8e54a402016-03-08 22:25:52 -070020013#ifdef ANDROID
20014 int vulkanSupport = InitVulkan();
20015 if (vulkanSupport == 0)
20016 return 1;
20017#endif
20018
Tony Barbour300a6082015-04-07 13:44:53 -060020019 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020020 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020021
20022 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20023
20024 result = RUN_ALL_TESTS();
20025
Tony Barbour6918cd52015-04-09 12:58:51 -060020026 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020027 return result;
20028}