blob: 05411f8a3af610838209137a98588bdb90d885c1 [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());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001943
1944 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
1945
Tony Barbourf92621a2016-05-02 14:28:12 -06001946 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001947 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001948 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001949 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001950
Tony Barbourf92621a2016-05-02 14:28:12 -06001951 VkImageView dsv;
1952 VkImageViewCreateInfo dsvci = {};
1953 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1954 dsvci.image = image.handle();
1955 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001956 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06001957 dsvci.subresourceRange.layerCount = 1;
1958 dsvci.subresourceRange.baseMipLevel = 0;
1959 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001960 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001961
Tony Barbourf92621a2016-05-02 14:28:12 -06001962 // Create a view with depth / stencil aspect for image with different usage
1963 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001964
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001965 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001966
1967 // Initialize buffer with TRANSFER_DST usage
1968 vk_testing::Buffer buffer;
1969 VkMemoryPropertyFlags reqs = 0;
1970 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1971 VkBufferImageCopy region = {};
1972 region.bufferRowLength = 128;
1973 region.bufferImageHeight = 128;
1974 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1975 region.imageSubresource.layerCount = 1;
1976 region.imageExtent.height = 16;
1977 region.imageExtent.width = 16;
1978 region.imageExtent.depth = 1;
1979
Tony Barbourf92621a2016-05-02 14:28:12 -06001980 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1981 // TRANSFER_DST
1982 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001983
Chris Forbesda581202016-10-06 18:25:26 +13001984 // two separate errors from this call:
1985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1987
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001988 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1989 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001990 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001991}
Tony Barbour75d79f02016-08-30 09:39:07 -06001992
Tony Barbour75d79f02016-08-30 09:39:07 -06001993
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001994#endif // MEM_TRACKER_TESTS
1995
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001996#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001997
1998TEST_F(VkLayerTest, LeakAnObject) {
1999 VkResult err;
2000
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002001 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002002
2003 // Note that we have to create a new device since destroying the
2004 // framework's device causes Teardown() to fail and just calling Teardown
2005 // will destroy the errorMonitor.
2006
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002008
2009 ASSERT_NO_FATAL_FAILURE(InitState());
2010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002011 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002012 std::vector<VkDeviceQueueCreateInfo> queue_info;
2013 queue_info.reserve(queue_props.size());
2014 std::vector<std::vector<float>> queue_priorities;
2015 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2016 VkDeviceQueueCreateInfo qi = {};
2017 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2018 qi.pNext = NULL;
2019 qi.queueFamilyIndex = i;
2020 qi.queueCount = queue_props[i].queueCount;
2021 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2022 qi.pQueuePriorities = queue_priorities[i].data();
2023 queue_info.push_back(qi);
2024 }
2025
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002026 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002027
2028 // The sacrificial device object
2029 VkDevice testDevice;
2030 VkDeviceCreateInfo device_create_info = {};
2031 auto features = m_device->phy().features();
2032 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2033 device_create_info.pNext = NULL;
2034 device_create_info.queueCreateInfoCount = queue_info.size();
2035 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002036 device_create_info.enabledLayerCount = 0;
2037 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002038 device_create_info.pEnabledFeatures = &features;
2039 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2040 ASSERT_VK_SUCCESS(err);
2041
2042 VkFence fence;
2043 VkFenceCreateInfo fence_create_info = {};
2044 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2045 fence_create_info.pNext = NULL;
2046 fence_create_info.flags = 0;
2047 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2048 ASSERT_VK_SUCCESS(err);
2049
2050 // Induce failure by not calling vkDestroyFence
2051 vkDestroyDevice(testDevice, NULL);
2052 m_errorMonitor->VerifyFound();
2053}
2054
2055TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2056
2057 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2058 "attempt to delete them from another.");
2059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002061
Cody Northropc31a84f2016-08-22 10:41:47 -06002062 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002063 VkCommandPool command_pool_one;
2064 VkCommandPool command_pool_two;
2065
2066 VkCommandPoolCreateInfo pool_create_info{};
2067 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2068 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2069 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2070
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002071 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002072
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002073 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002074
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002075 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002076 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002077 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002078 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002079 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002080 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002081 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002082
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002083 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002084
2085 m_errorMonitor->VerifyFound();
2086
2087 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2088 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2089}
2090
2091TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2092 VkResult err;
2093
2094 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002095 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002096
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002098
2099 ASSERT_NO_FATAL_FAILURE(InitState());
2100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2101
2102 VkDescriptorPoolSize ds_type_count = {};
2103 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2104 ds_type_count.descriptorCount = 1;
2105
2106 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2107 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2108 ds_pool_ci.pNext = NULL;
2109 ds_pool_ci.flags = 0;
2110 ds_pool_ci.maxSets = 1;
2111 ds_pool_ci.poolSizeCount = 1;
2112 ds_pool_ci.pPoolSizes = &ds_type_count;
2113
2114 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002115 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002116 ASSERT_VK_SUCCESS(err);
2117
2118 // Create a second descriptor pool
2119 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002120 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002121 ASSERT_VK_SUCCESS(err);
2122
2123 VkDescriptorSetLayoutBinding dsl_binding = {};
2124 dsl_binding.binding = 0;
2125 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2126 dsl_binding.descriptorCount = 1;
2127 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2128 dsl_binding.pImmutableSamplers = NULL;
2129
2130 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2131 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2132 ds_layout_ci.pNext = NULL;
2133 ds_layout_ci.bindingCount = 1;
2134 ds_layout_ci.pBindings = &dsl_binding;
2135
2136 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002137 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002138 ASSERT_VK_SUCCESS(err);
2139
2140 VkDescriptorSet descriptorSet;
2141 VkDescriptorSetAllocateInfo alloc_info = {};
2142 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2143 alloc_info.descriptorSetCount = 1;
2144 alloc_info.descriptorPool = ds_pool_one;
2145 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002146 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002147 ASSERT_VK_SUCCESS(err);
2148
2149 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2150
2151 m_errorMonitor->VerifyFound();
2152
2153 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2154 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2155 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2156}
2157
2158TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002160
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002161 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002162
2163 ASSERT_NO_FATAL_FAILURE(InitState());
2164
2165 // Pass bogus handle into GetImageMemoryRequirements
2166 VkMemoryRequirements mem_reqs;
2167 uint64_t fakeImageHandle = 0xCADECADE;
2168 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2169
2170 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2171
2172 m_errorMonitor->VerifyFound();
2173}
2174
Karl Schultz6addd812016-02-02 17:17:23 -07002175TEST_F(VkLayerTest, PipelineNotBound) {
2176 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002177
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002178 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002179
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002181
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002182 ASSERT_NO_FATAL_FAILURE(InitState());
2183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002184
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002185 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002186 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2187 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002188
2189 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002190 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2191 ds_pool_ci.pNext = NULL;
2192 ds_pool_ci.maxSets = 1;
2193 ds_pool_ci.poolSizeCount = 1;
2194 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002195
2196 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002197 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002198 ASSERT_VK_SUCCESS(err);
2199
2200 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002201 dsl_binding.binding = 0;
2202 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2203 dsl_binding.descriptorCount = 1;
2204 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2205 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002206
2207 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002208 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2209 ds_layout_ci.pNext = NULL;
2210 ds_layout_ci.bindingCount = 1;
2211 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002212
2213 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002214 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002215 ASSERT_VK_SUCCESS(err);
2216
2217 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002218 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002219 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002220 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002221 alloc_info.descriptorPool = ds_pool;
2222 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002223 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002224 ASSERT_VK_SUCCESS(err);
2225
2226 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002227 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2228 pipeline_layout_ci.pNext = NULL;
2229 pipeline_layout_ci.setLayoutCount = 1;
2230 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002231
2232 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002233 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002234 ASSERT_VK_SUCCESS(err);
2235
Mark Youngad779052016-01-06 14:26:04 -07002236 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002237
2238 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002239 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002240
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002241 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002242
Chia-I Wuf7458c52015-10-26 21:10:41 +08002243 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2244 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2245 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002246}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002247
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002248TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2249 VkResult err;
2250
2251 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2252 "during bind[Buffer|Image]Memory time");
2253
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002254 ASSERT_NO_FATAL_FAILURE(InitState());
2255
2256 // Create an image, allocate memory, set a bad typeIndex and then try to
2257 // bind it
2258 VkImage image;
2259 VkDeviceMemory mem;
2260 VkMemoryRequirements mem_reqs;
2261 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2262 const int32_t tex_width = 32;
2263 const int32_t tex_height = 32;
2264
2265 VkImageCreateInfo image_create_info = {};
2266 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2267 image_create_info.pNext = NULL;
2268 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2269 image_create_info.format = tex_format;
2270 image_create_info.extent.width = tex_width;
2271 image_create_info.extent.height = tex_height;
2272 image_create_info.extent.depth = 1;
2273 image_create_info.mipLevels = 1;
2274 image_create_info.arrayLayers = 1;
2275 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2276 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2277 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2278 image_create_info.flags = 0;
2279
2280 VkMemoryAllocateInfo mem_alloc = {};
2281 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2282 mem_alloc.pNext = NULL;
2283 mem_alloc.allocationSize = 0;
2284 mem_alloc.memoryTypeIndex = 0;
2285
2286 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2287 ASSERT_VK_SUCCESS(err);
2288
2289 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2290 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002291
2292 // Introduce Failure, select invalid TypeIndex
2293 VkPhysicalDeviceMemoryProperties memory_info;
2294
2295 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2296 unsigned int i;
2297 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2298 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2299 mem_alloc.memoryTypeIndex = i;
2300 break;
2301 }
2302 }
2303 if (i >= memory_info.memoryTypeCount) {
2304 printf("No invalid memory type index could be found; skipped.\n");
2305 vkDestroyImage(m_device->device(), image, NULL);
2306 return;
2307 }
2308
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002309 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 -06002310
2311 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2312 ASSERT_VK_SUCCESS(err);
2313
2314 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2315 (void)err;
2316
2317 m_errorMonitor->VerifyFound();
2318
2319 vkDestroyImage(m_device->device(), image, NULL);
2320 vkFreeMemory(m_device->device(), mem, NULL);
2321}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002322
Karl Schultz6addd812016-02-02 17:17:23 -07002323TEST_F(VkLayerTest, BindInvalidMemory) {
2324 VkResult err;
2325 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002326
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002328
Tobin Ehlisec598302015-09-15 15:02:17 -06002329 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002330
2331 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002332 VkImage image;
2333 VkDeviceMemory mem;
2334 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002335
Karl Schultz6addd812016-02-02 17:17:23 -07002336 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2337 const int32_t tex_width = 32;
2338 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002339
2340 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002341 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2342 image_create_info.pNext = NULL;
2343 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2344 image_create_info.format = tex_format;
2345 image_create_info.extent.width = tex_width;
2346 image_create_info.extent.height = tex_height;
2347 image_create_info.extent.depth = 1;
2348 image_create_info.mipLevels = 1;
2349 image_create_info.arrayLayers = 1;
2350 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2351 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2352 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2353 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002354
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002355 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002356 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2357 mem_alloc.pNext = NULL;
2358 mem_alloc.allocationSize = 0;
2359 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002360
Chia-I Wuf7458c52015-10-26 21:10:41 +08002361 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002362 ASSERT_VK_SUCCESS(err);
2363
Karl Schultz6addd812016-02-02 17:17:23 -07002364 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002365
2366 mem_alloc.allocationSize = mem_reqs.size;
2367
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002368 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002369 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002370
2371 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002372 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002373 ASSERT_VK_SUCCESS(err);
2374
2375 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002376 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002377
2378 // Try to bind free memory that has been freed
2379 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2380 // This may very well return an error.
2381 (void)err;
2382
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002383 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002384
Chia-I Wuf7458c52015-10-26 21:10:41 +08002385 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002386}
2387
Karl Schultz6addd812016-02-02 17:17:23 -07002388TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2389 VkResult err;
2390 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002391
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002393
Tobin Ehlisec598302015-09-15 15:02:17 -06002394 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002395
Karl Schultz6addd812016-02-02 17:17:23 -07002396 // Create an image object, allocate memory, destroy the object and then try
2397 // to bind it
2398 VkImage image;
2399 VkDeviceMemory mem;
2400 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002401
Karl Schultz6addd812016-02-02 17:17:23 -07002402 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2403 const int32_t tex_width = 32;
2404 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002405
2406 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002407 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2408 image_create_info.pNext = NULL;
2409 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2410 image_create_info.format = tex_format;
2411 image_create_info.extent.width = tex_width;
2412 image_create_info.extent.height = tex_height;
2413 image_create_info.extent.depth = 1;
2414 image_create_info.mipLevels = 1;
2415 image_create_info.arrayLayers = 1;
2416 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2417 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2418 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2419 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002420
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002421 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002422 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2423 mem_alloc.pNext = NULL;
2424 mem_alloc.allocationSize = 0;
2425 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002426
Chia-I Wuf7458c52015-10-26 21:10:41 +08002427 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002428 ASSERT_VK_SUCCESS(err);
2429
Karl Schultz6addd812016-02-02 17:17:23 -07002430 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002431
2432 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002433 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002434 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002435
2436 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002437 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002438 ASSERT_VK_SUCCESS(err);
2439
2440 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002441 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002442 ASSERT_VK_SUCCESS(err);
2443
2444 // Now Try to bind memory to this destroyed object
2445 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2446 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002447 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002448
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002449 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002450
Chia-I Wuf7458c52015-10-26 21:10:41 +08002451 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002452}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002453
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002454#endif // OBJ_TRACKER_TESTS
2455
Tobin Ehlis0788f522015-05-26 16:11:58 -06002456#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002457
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002458TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2459 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2460
2461 ASSERT_NO_FATAL_FAILURE(InitState());
2462 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2463
2464 VkVertexInputBindingDescription input_binding;
2465 memset(&input_binding, 0, sizeof(input_binding));
2466
2467 VkVertexInputAttributeDescription input_attribs;
2468 memset(&input_attribs, 0, sizeof(input_attribs));
2469
2470 // Pick a really bad format for this purpose and make sure it should fail
2471 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2472 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2473 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2474 printf("Format unsuitable for test; skipped.\n");
2475 return;
2476 }
2477
2478 input_attribs.location = 0;
2479 char const *vsSource = "#version 450\n"
2480 "\n"
2481 "out gl_PerVertex {\n"
2482 " vec4 gl_Position;\n"
2483 "};\n"
2484 "void main(){\n"
2485 " gl_Position = vec4(1);\n"
2486 "}\n";
2487 char const *fsSource = "#version 450\n"
2488 "\n"
2489 "layout(location=0) out vec4 color;\n"
2490 "void main(){\n"
2491 " color = vec4(1);\n"
2492 "}\n";
2493
2494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2495 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2496 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2497
2498 VkPipelineObj pipe(m_device);
2499 pipe.AddColorAttachment();
2500 pipe.AddShader(&vs);
2501 pipe.AddShader(&fs);
2502
2503 pipe.AddVertexInputBindings(&input_binding, 1);
2504 pipe.AddVertexInputAttribs(&input_attribs, 1);
2505
2506 VkDescriptorSetObj descriptorSet(m_device);
2507 descriptorSet.AppendDummy();
2508 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2509
2510 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2511
2512 m_errorMonitor->VerifyFound();
2513}
2514
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002515TEST_F(VkLayerTest, ImageSampleCounts) {
2516
2517 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2518 "validation errors.");
2519 ASSERT_NO_FATAL_FAILURE(InitState());
2520
2521 VkMemoryPropertyFlags reqs = 0;
2522 VkImageCreateInfo image_create_info = {};
2523 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2524 image_create_info.pNext = NULL;
2525 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2526 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2527 image_create_info.extent.width = 256;
2528 image_create_info.extent.height = 256;
2529 image_create_info.extent.depth = 1;
2530 image_create_info.mipLevels = 1;
2531 image_create_info.arrayLayers = 1;
2532 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2533 image_create_info.flags = 0;
2534
2535 VkImageBlit blit_region = {};
2536 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2537 blit_region.srcSubresource.baseArrayLayer = 0;
2538 blit_region.srcSubresource.layerCount = 1;
2539 blit_region.srcSubresource.mipLevel = 0;
2540 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2541 blit_region.dstSubresource.baseArrayLayer = 0;
2542 blit_region.dstSubresource.layerCount = 1;
2543 blit_region.dstSubresource.mipLevel = 0;
2544
2545 // Create two images, the source with sampleCount = 2, and attempt to blit
2546 // between them
2547 {
2548 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002549 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002550 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002551 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002552 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002553 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002554 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002555 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002556 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2558 "of VK_SAMPLE_COUNT_2_BIT but "
2559 "must be VK_SAMPLE_COUNT_1_BIT");
2560 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2561 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002562 m_errorMonitor->VerifyFound();
2563 m_commandBuffer->EndCommandBuffer();
2564 }
2565
2566 // Create two images, the dest with sampleCount = 4, and attempt to blit
2567 // between them
2568 {
2569 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002570 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002571 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002572 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002573 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002574 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002575 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002576 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002577 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2579 "of VK_SAMPLE_COUNT_4_BIT but "
2580 "must be VK_SAMPLE_COUNT_1_BIT");
2581 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2582 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002583 m_errorMonitor->VerifyFound();
2584 m_commandBuffer->EndCommandBuffer();
2585 }
2586
2587 VkBufferImageCopy copy_region = {};
2588 copy_region.bufferRowLength = 128;
2589 copy_region.bufferImageHeight = 128;
2590 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2591 copy_region.imageSubresource.layerCount = 1;
2592 copy_region.imageExtent.height = 64;
2593 copy_region.imageExtent.width = 64;
2594 copy_region.imageExtent.depth = 1;
2595
2596 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2597 // buffer to image
2598 {
2599 vk_testing::Buffer src_buffer;
2600 VkMemoryPropertyFlags reqs = 0;
2601 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2602 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002603 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002604 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002605 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002606 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2608 "of VK_SAMPLE_COUNT_8_BIT but "
2609 "must be VK_SAMPLE_COUNT_1_BIT");
2610 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2611 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002612 m_errorMonitor->VerifyFound();
2613 m_commandBuffer->EndCommandBuffer();
2614 }
2615
2616 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2617 // image to buffer
2618 {
2619 vk_testing::Buffer dst_buffer;
2620 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2621 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002622 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002623 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002624 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002625 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2627 "of VK_SAMPLE_COUNT_2_BIT but "
2628 "must be VK_SAMPLE_COUNT_1_BIT");
2629 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002630 dst_buffer.handle(), 1, &copy_region);
2631 m_errorMonitor->VerifyFound();
2632 m_commandBuffer->EndCommandBuffer();
2633 }
2634}
2635
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002636TEST_F(VkLayerTest, BlitImageFormats) {
2637
2638 // Image blit with mismatched formats
2639 const char * expected_message =
2640 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2641 " the other one must also have signed/unsigned integer format";
2642
2643 ASSERT_NO_FATAL_FAILURE(InitState());
2644
2645 VkImageObj src_image(m_device);
2646 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2647 VkImageObj dst_image(m_device);
2648 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2649 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002650 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 -06002651
2652 VkImageBlit blitRegion = {};
2653 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2654 blitRegion.srcSubresource.baseArrayLayer = 0;
2655 blitRegion.srcSubresource.layerCount = 1;
2656 blitRegion.srcSubresource.mipLevel = 0;
2657 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2658 blitRegion.dstSubresource.baseArrayLayer = 0;
2659 blitRegion.dstSubresource.layerCount = 1;
2660 blitRegion.dstSubresource.mipLevel = 0;
2661
2662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2663
2664 // Unsigned int vs not an int
2665 BeginCommandBuffer();
2666 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2667 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2668
2669 m_errorMonitor->VerifyFound();
2670
2671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2672
2673 // Unsigned int vs signed int
2674 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2675 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2676
2677 m_errorMonitor->VerifyFound();
2678
2679 EndCommandBuffer();
2680}
2681
2682
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002683TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2684 VkResult err;
2685 bool pass;
2686
2687 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2688 ASSERT_NO_FATAL_FAILURE(InitState());
2689
2690 // If w/d/h granularity is 1, test is not meaningful
2691 // TODO: When virtual device limits are available, create a set of limits for this test that
2692 // will always have a granularity of > 1 for w, h, and d
2693 auto index = m_device->graphics_queue_node_index_;
2694 auto queue_family_properties = m_device->phy().queue_properties();
2695
2696 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2697 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2698 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2699 return;
2700 }
2701
2702 // Create two images of different types and try to copy between them
2703 VkImage srcImage;
2704 VkImage dstImage;
2705 VkDeviceMemory srcMem;
2706 VkDeviceMemory destMem;
2707 VkMemoryRequirements memReqs;
2708
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002709 VkImageCreateInfo image_create_info = {};
2710 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2711 image_create_info.pNext = NULL;
2712 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2713 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2714 image_create_info.extent.width = 32;
2715 image_create_info.extent.height = 32;
2716 image_create_info.extent.depth = 1;
2717 image_create_info.mipLevels = 1;
2718 image_create_info.arrayLayers = 4;
2719 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2720 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2721 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2722 image_create_info.flags = 0;
2723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002724 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002725 ASSERT_VK_SUCCESS(err);
2726
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002727 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002728 ASSERT_VK_SUCCESS(err);
2729
2730 // Allocate memory
2731 VkMemoryAllocateInfo memAlloc = {};
2732 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2733 memAlloc.pNext = NULL;
2734 memAlloc.allocationSize = 0;
2735 memAlloc.memoryTypeIndex = 0;
2736
2737 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2738 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002739 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002740 ASSERT_TRUE(pass);
2741 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2742 ASSERT_VK_SUCCESS(err);
2743
2744 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2745 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002746 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002747 ASSERT_VK_SUCCESS(err);
2748 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2749 ASSERT_VK_SUCCESS(err);
2750
2751 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2752 ASSERT_VK_SUCCESS(err);
2753 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2754 ASSERT_VK_SUCCESS(err);
2755
2756 BeginCommandBuffer();
2757 VkImageCopy copyRegion;
2758 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2759 copyRegion.srcSubresource.mipLevel = 0;
2760 copyRegion.srcSubresource.baseArrayLayer = 0;
2761 copyRegion.srcSubresource.layerCount = 1;
2762 copyRegion.srcOffset.x = 0;
2763 copyRegion.srcOffset.y = 0;
2764 copyRegion.srcOffset.z = 0;
2765 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2766 copyRegion.dstSubresource.mipLevel = 0;
2767 copyRegion.dstSubresource.baseArrayLayer = 0;
2768 copyRegion.dstSubresource.layerCount = 1;
2769 copyRegion.dstOffset.x = 0;
2770 copyRegion.dstOffset.y = 0;
2771 copyRegion.dstOffset.z = 0;
2772 copyRegion.extent.width = 1;
2773 copyRegion.extent.height = 1;
2774 copyRegion.extent.depth = 1;
2775
2776 // Introduce failure by setting srcOffset to a bad granularity value
2777 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2779 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002780 m_errorMonitor->VerifyFound();
2781
2782 // Introduce failure by setting extent to a bad granularity value
2783 copyRegion.srcOffset.y = 0;
2784 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2786 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002787 m_errorMonitor->VerifyFound();
2788
2789 // Now do some buffer/image copies
2790 vk_testing::Buffer buffer;
2791 VkMemoryPropertyFlags reqs = 0;
2792 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2793 VkBufferImageCopy region = {};
2794 region.bufferOffset = 0;
2795 region.bufferRowLength = 3;
2796 region.bufferImageHeight = 128;
2797 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2798 region.imageSubresource.layerCount = 1;
2799 region.imageExtent.height = 16;
2800 region.imageExtent.width = 16;
2801 region.imageExtent.depth = 1;
2802 region.imageOffset.x = 0;
2803 region.imageOffset.y = 0;
2804 region.imageOffset.z = 0;
2805
2806 // Introduce failure by setting bufferRowLength to a bad granularity value
2807 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2809 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2810 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002811 m_errorMonitor->VerifyFound();
2812 region.bufferRowLength = 128;
2813
2814 // Introduce failure by setting bufferOffset to a bad granularity value
2815 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2817 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2818 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002819 m_errorMonitor->VerifyFound();
2820 region.bufferOffset = 0;
2821
2822 // Introduce failure by setting bufferImageHeight to a bad granularity value
2823 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2825 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2826 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002827 m_errorMonitor->VerifyFound();
2828 region.bufferImageHeight = 128;
2829
2830 // Introduce failure by setting imageExtent to a bad granularity value
2831 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2833 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2834 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002835 m_errorMonitor->VerifyFound();
2836 region.imageExtent.width = 16;
2837
2838 // Introduce failure by setting imageOffset to a bad granularity value
2839 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2841 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2842 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002843 m_errorMonitor->VerifyFound();
2844
2845 EndCommandBuffer();
2846
2847 vkDestroyImage(m_device->device(), srcImage, NULL);
2848 vkDestroyImage(m_device->device(), dstImage, NULL);
2849 vkFreeMemory(m_device->device(), srcMem, NULL);
2850 vkFreeMemory(m_device->device(), destMem, NULL);
2851}
2852
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002853TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002854 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2855 "attempt to submit them on a queue created in a different "
2856 "queue family.");
2857
Cody Northropc31a84f2016-08-22 10:41:47 -06002858 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002859 // This test is meaningless unless we have multiple queue families
2860 auto queue_family_properties = m_device->phy().queue_properties();
2861 if (queue_family_properties.size() < 2) {
2862 return;
2863 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002865 // Get safe index of another queue family
2866 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2867 ASSERT_NO_FATAL_FAILURE(InitState());
2868 // Create a second queue using a different queue family
2869 VkQueue other_queue;
2870 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2871
2872 // Record an empty cmd buffer
2873 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2874 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2875 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2876 vkEndCommandBuffer(m_commandBuffer->handle());
2877
2878 // And submit on the wrong queue
2879 VkSubmitInfo submit_info = {};
2880 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2881 submit_info.commandBufferCount = 1;
2882 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002883 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002884
2885 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002886}
2887
Chris Forbes4c24a922016-11-16 08:59:10 +13002888TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2889 ASSERT_NO_FATAL_FAILURE(InitState());
2890
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002891 // There are no attachments, but refer to attachment 0.
2892 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002893 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002894 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2895 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002896 };
2897
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002898 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2899 nullptr,
2900 0,
2901 0,
2902 nullptr,
2903 1,
2904 subpasses,
2905 0,
2906 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002907 VkRenderPass rp;
2908
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002909 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002911 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002912 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2913 m_errorMonitor->VerifyFound();
2914}
2915
Chris Forbesa58c4522016-09-28 15:19:39 +13002916TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2917 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2918 ASSERT_NO_FATAL_FAILURE(InitState());
2919
2920 // A renderpass with two subpasses, both writing the same attachment.
2921 VkAttachmentDescription attach[] = {
2922 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2923 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2924 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2925 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2926 },
2927 };
2928 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2929 VkSubpassDescription subpasses[] = {
2930 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2931 1, &ref, nullptr, nullptr, 0, nullptr },
2932 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2933 1, &ref, nullptr, nullptr, 0, nullptr },
2934 };
2935 VkSubpassDependency dep = {
2936 0, 1,
2937 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2938 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2939 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2940 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2941 VK_DEPENDENCY_BY_REGION_BIT
2942 };
2943 VkRenderPassCreateInfo rpci = {
2944 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2945 0, 1, attach, 2, subpasses, 1, &dep
2946 };
2947 VkRenderPass rp;
2948 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2949 ASSERT_VK_SUCCESS(err);
2950
2951 VkImageObj image(m_device);
2952 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2953 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2954 VK_IMAGE_TILING_OPTIMAL, 0);
2955 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2956
2957 VkFramebufferCreateInfo fbci = {
2958 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2959 0, rp, 1, &imageView, 32, 32, 1
2960 };
2961 VkFramebuffer fb;
2962 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2963 ASSERT_VK_SUCCESS(err);
2964
2965 char const *vsSource =
2966 "#version 450\n"
2967 "void main() { gl_Position = vec4(1); }\n";
2968 char const *fsSource =
2969 "#version 450\n"
2970 "layout(location=0) out vec4 color;\n"
2971 "void main() { color = vec4(1); }\n";
2972
2973 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2974 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2975 VkPipelineObj pipe(m_device);
2976 pipe.AddColorAttachment();
2977 pipe.AddShader(&vs);
2978 pipe.AddShader(&fs);
2979 VkViewport view_port = {};
2980 m_viewports.push_back(view_port);
2981 pipe.SetViewport(m_viewports);
2982 VkRect2D rect = {};
2983 m_scissors.push_back(rect);
2984 pipe.SetScissor(m_scissors);
2985
2986 VkPipelineLayoutCreateInfo plci = {
2987 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2988 0, 0, nullptr, 0, nullptr
2989 };
2990 VkPipelineLayout pl;
2991 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2992 ASSERT_VK_SUCCESS(err);
2993 pipe.CreateVKPipeline(pl, rp);
2994
2995 BeginCommandBuffer();
2996
2997 VkRenderPassBeginInfo rpbi = {
2998 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2999 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
3000 };
3001
3002 // subtest 1: bind in the wrong subpass
3003 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3004 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3006 "built for subpass 0 but used in subpass 1");
3007 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3008 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3009 m_errorMonitor->VerifyFound();
3010
3011 vkCmdEndRenderPass(m_commandBuffer->handle());
3012
3013 // subtest 2: bind in correct subpass, then transition to next subpass
3014 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3015 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3016 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3018 "built for subpass 0 but used in subpass 1");
3019 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3020 m_errorMonitor->VerifyFound();
3021
3022 vkCmdEndRenderPass(m_commandBuffer->handle());
3023
3024 EndCommandBuffer();
3025
3026 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3027 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3028 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3029}
3030
Tony Barbour4e919972016-08-09 13:27:40 -06003031TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3032 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3033 "with extent outside of framebuffer");
3034 ASSERT_NO_FATAL_FAILURE(InitState());
3035 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3036
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3038 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003039
3040 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3041 m_renderPassBeginInfo.renderArea.extent.width = 257;
3042 m_renderPassBeginInfo.renderArea.extent.height = 257;
3043 BeginCommandBuffer();
3044 m_errorMonitor->VerifyFound();
3045}
3046
3047TEST_F(VkLayerTest, DisabledIndependentBlend) {
3048 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3049 "blend and then specifying different blend states for two "
3050 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003051 VkPhysicalDeviceFeatures features = {};
3052 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003053 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003054
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3056 "Invalid Pipeline CreateInfo: If independent blend feature not "
3057 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003058
Cody Northropc31a84f2016-08-22 10:41:47 -06003059 VkDescriptorSetObj descriptorSet(m_device);
3060 descriptorSet.AppendDummy();
3061 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003062
Cody Northropc31a84f2016-08-22 10:41:47 -06003063 VkPipelineObj pipeline(m_device);
3064 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003065 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003066 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003067
Cody Northropc31a84f2016-08-22 10:41:47 -06003068 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3069 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3070 att_state1.blendEnable = VK_TRUE;
3071 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3072 att_state2.blendEnable = VK_FALSE;
3073 pipeline.AddColorAttachment(0, &att_state1);
3074 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003075 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003076 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003077}
3078
Chris Forbes26ec2122016-11-29 08:58:33 +13003079#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003080TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3081 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3082 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003083 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003084
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3086 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003087
3088 // Create a renderPass with a single color attachment
3089 VkAttachmentReference attach = {};
3090 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3091 VkSubpassDescription subpass = {};
3092 VkRenderPassCreateInfo rpci = {};
3093 rpci.subpassCount = 1;
3094 rpci.pSubpasses = &subpass;
3095 rpci.attachmentCount = 1;
3096 VkAttachmentDescription attach_desc = {};
3097 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3098 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3099 rpci.pAttachments = &attach_desc;
3100 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3101 VkRenderPass rp;
3102 subpass.pDepthStencilAttachment = &attach;
3103 subpass.pColorAttachments = NULL;
3104 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3105 m_errorMonitor->VerifyFound();
3106}
Chris Forbes26ec2122016-11-29 08:58:33 +13003107#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003108
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003109TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3110 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3111 "attachment reference of VK_ATTACHMENT_UNUSED");
3112
3113 ASSERT_NO_FATAL_FAILURE(InitState());
3114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3115
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003117
3118 VkAttachmentReference color_attach = {};
3119 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3120 color_attach.attachment = 0;
3121 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3122 VkSubpassDescription subpass = {};
3123 subpass.colorAttachmentCount = 1;
3124 subpass.pColorAttachments = &color_attach;
3125 subpass.preserveAttachmentCount = 1;
3126 subpass.pPreserveAttachments = &preserve_attachment;
3127
3128 VkRenderPassCreateInfo rpci = {};
3129 rpci.subpassCount = 1;
3130 rpci.pSubpasses = &subpass;
3131 rpci.attachmentCount = 1;
3132 VkAttachmentDescription attach_desc = {};
3133 attach_desc.format = VK_FORMAT_UNDEFINED;
3134 rpci.pAttachments = &attach_desc;
3135 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3136 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003137 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003138
3139 m_errorMonitor->VerifyFound();
3140
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003141 if (result == VK_SUCCESS) {
3142 vkDestroyRenderPass(m_device->device(), rp, NULL);
3143 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003144}
3145
Chris Forbesc5389742016-06-29 11:49:23 +12003146TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003147 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3148 "when the source of a subpass multisample resolve "
3149 "does not have multiple samples.");
3150
Chris Forbesc5389742016-06-29 11:49:23 +12003151 ASSERT_NO_FATAL_FAILURE(InitState());
3152
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3154 "Subpass 0 requests multisample resolve from attachment 0 which has "
3155 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003156
3157 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003158 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3159 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3160 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3161 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3162 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3163 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003164 };
3165
3166 VkAttachmentReference color = {
3167 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3168 };
3169
3170 VkAttachmentReference resolve = {
3171 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3172 };
3173
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003174 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003175
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003176 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003177
3178 VkRenderPass rp;
3179 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3180
3181 m_errorMonitor->VerifyFound();
3182
3183 if (err == VK_SUCCESS)
3184 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3185}
3186
3187TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003188 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3189 "when a subpass multisample resolve operation is "
3190 "requested, and the destination of that resolve has "
3191 "multiple samples.");
3192
Chris Forbesc5389742016-06-29 11:49:23 +12003193 ASSERT_NO_FATAL_FAILURE(InitState());
3194
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3196 "Subpass 0 requests multisample resolve into attachment 1, which "
3197 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003198
3199 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003200 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3201 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3202 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3203 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3204 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3205 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003206 };
3207
3208 VkAttachmentReference color = {
3209 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3210 };
3211
3212 VkAttachmentReference resolve = {
3213 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3214 };
3215
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003216 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003217
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003218 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003219
3220 VkRenderPass rp;
3221 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3222
3223 m_errorMonitor->VerifyFound();
3224
3225 if (err == VK_SUCCESS)
3226 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3227}
3228
Chris Forbes3f128ef2016-06-29 14:58:53 +12003229TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003230 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3231 "when the color and depth attachments used by a subpass "
3232 "have inconsistent sample counts");
3233
Chris Forbes3f128ef2016-06-29 14:58:53 +12003234 ASSERT_NO_FATAL_FAILURE(InitState());
3235
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3237 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003238
3239 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003240 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3241 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3242 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3243 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3244 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3245 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003246 };
3247
3248 VkAttachmentReference color[] = {
3249 {
3250 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3251 },
3252 {
3253 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3254 },
3255 };
3256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003257 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003258
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003259 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003260
3261 VkRenderPass rp;
3262 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3263
3264 m_errorMonitor->VerifyFound();
3265
3266 if (err == VK_SUCCESS)
3267 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3268}
3269
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003270TEST_F(VkLayerTest, FramebufferCreateErrors) {
3271 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003272 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003273 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003274 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3275 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3276 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3277 " 6. Framebuffer attachment where dimensions don't match\n"
3278 " 7. Framebuffer attachment w/o identity swizzle\n"
3279 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003280
3281 ASSERT_NO_FATAL_FAILURE(InitState());
3282 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3283
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3285 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3286 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003287
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003288 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003289 VkAttachmentReference attach = {};
3290 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3291 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003292 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003293 VkRenderPassCreateInfo rpci = {};
3294 rpci.subpassCount = 1;
3295 rpci.pSubpasses = &subpass;
3296 rpci.attachmentCount = 1;
3297 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003298 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003299 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003300 rpci.pAttachments = &attach_desc;
3301 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3302 VkRenderPass rp;
3303 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3304 ASSERT_VK_SUCCESS(err);
3305
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003306 VkImageView ivs[2];
3307 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3308 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003309 VkFramebufferCreateInfo fb_info = {};
3310 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3311 fb_info.pNext = NULL;
3312 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003313 // Set mis-matching attachmentCount
3314 fb_info.attachmentCount = 2;
3315 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003316 fb_info.width = 100;
3317 fb_info.height = 100;
3318 fb_info.layers = 1;
3319
3320 VkFramebuffer fb;
3321 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3322
3323 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003324 if (err == VK_SUCCESS) {
3325 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3326 }
3327 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003328
3329 // Create a renderPass with a depth-stencil attachment created with
3330 // IMAGE_USAGE_COLOR_ATTACHMENT
3331 // Add our color attachment to pDepthStencilAttachment
3332 subpass.pDepthStencilAttachment = &attach;
3333 subpass.pColorAttachments = NULL;
3334 VkRenderPass rp_ds;
3335 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3336 ASSERT_VK_SUCCESS(err);
3337 // Set correct attachment count, but attachment has COLOR usage bit set
3338 fb_info.attachmentCount = 1;
3339 fb_info.renderPass = rp_ds;
3340
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003342 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3343
3344 m_errorMonitor->VerifyFound();
3345 if (err == VK_SUCCESS) {
3346 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3347 }
3348 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003349
3350 // Create new renderpass with alternate attachment format from fb
3351 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3352 subpass.pDepthStencilAttachment = NULL;
3353 subpass.pColorAttachments = &attach;
3354 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3355 ASSERT_VK_SUCCESS(err);
3356
3357 // Cause error due to mis-matched formats between rp & fb
3358 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3359 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3361 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003362 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3363
3364 m_errorMonitor->VerifyFound();
3365 if (err == VK_SUCCESS) {
3366 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3367 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003368 vkDestroyRenderPass(m_device->device(), rp, NULL);
3369
3370 // Create new renderpass with alternate sample count from fb
3371 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3372 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3373 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3374 ASSERT_VK_SUCCESS(err);
3375
3376 // Cause error due to mis-matched sample count between rp & fb
3377 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3379 "that do not match the "
3380 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003381 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3382
3383 m_errorMonitor->VerifyFound();
3384 if (err == VK_SUCCESS) {
3385 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3386 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003387
3388 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003389
3390 // Create a custom imageView with non-1 mip levels
3391 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003392 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 -06003393 ASSERT_TRUE(image.initialized());
3394
3395 VkImageView view;
3396 VkImageViewCreateInfo ivci = {};
3397 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3398 ivci.image = image.handle();
3399 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3400 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3401 ivci.subresourceRange.layerCount = 1;
3402 ivci.subresourceRange.baseMipLevel = 0;
3403 // Set level count 2 (only 1 is allowed for FB attachment)
3404 ivci.subresourceRange.levelCount = 2;
3405 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3406 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3407 ASSERT_VK_SUCCESS(err);
3408 // Re-create renderpass to have matching sample count
3409 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3410 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3411 ASSERT_VK_SUCCESS(err);
3412
3413 fb_info.renderPass = rp;
3414 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003416 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3417
3418 m_errorMonitor->VerifyFound();
3419 if (err == VK_SUCCESS) {
3420 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3421 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003422 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003423 // Update view to original color buffer and grow FB dimensions too big
3424 fb_info.pAttachments = ivs;
3425 fb_info.height = 1024;
3426 fb_info.width = 1024;
3427 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3429 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003430 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3431
3432 m_errorMonitor->VerifyFound();
3433 if (err == VK_SUCCESS) {
3434 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3435 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003436 // Create view attachment with non-identity swizzle
3437 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3438 ivci.image = image.handle();
3439 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3440 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3441 ivci.subresourceRange.layerCount = 1;
3442 ivci.subresourceRange.baseMipLevel = 0;
3443 ivci.subresourceRange.levelCount = 1;
3444 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3445 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3446 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3447 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3448 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3449 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3450 ASSERT_VK_SUCCESS(err);
3451
3452 fb_info.pAttachments = &view;
3453 fb_info.height = 100;
3454 fb_info.width = 100;
3455 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3457 "framebuffer attachments must have "
3458 "been created with the identity "
3459 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003460 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3461
3462 m_errorMonitor->VerifyFound();
3463 if (err == VK_SUCCESS) {
3464 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3465 }
3466 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003467 // Request fb that exceeds max dimensions
3468 // reset attachment to color attachment
3469 fb_info.pAttachments = ivs;
3470 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3471 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3472 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3474 "dimensions exceed physical device "
3475 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003476 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3477
3478 m_errorMonitor->VerifyFound();
3479 if (err == VK_SUCCESS) {
3480 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3481 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003482
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003483 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003484}
3485
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003486TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003487 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3488 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003489
Cody Northropc31a84f2016-08-22 10:41:47 -06003490 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003491 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3493 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003494 m_errorMonitor->VerifyFound();
3495}
3496
3497TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003498 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3499 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003500
Cody Northropc31a84f2016-08-22 10:41:47 -06003501 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003502 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3504 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003505 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003506}
3507
3508TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003509 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3510 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003511
Cody Northropc31a84f2016-08-22 10:41:47 -06003512 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003513 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003514 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 -06003515 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003516 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003517}
3518
3519TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003520 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3521 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003522
Cody Northropc31a84f2016-08-22 10:41:47 -06003523 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003524 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003525 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 -06003526 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003527 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003528}
3529
Cortd713fe82016-07-27 09:51:27 -07003530TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003531 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3532 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003533
3534 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003535 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3537 "Dynamic blend constants state not set for this command buffer");
3538 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003539 m_errorMonitor->VerifyFound();
3540}
3541
3542TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003543 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3544 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003545
3546 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003547 if (!m_device->phy().features().depthBounds) {
3548 printf("Device does not support depthBounds test; skipped.\n");
3549 return;
3550 }
3551 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3553 "Dynamic depth bounds state not set for this command buffer");
3554 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003555 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003556}
3557
3558TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003559 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3560 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003561
3562 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003563 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3565 "Dynamic stencil read mask state not set for this command buffer");
3566 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003567 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003568}
3569
3570TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003571 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3572 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003573
3574 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003575 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3577 "Dynamic stencil write mask state not set for this command buffer");
3578 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003579 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003580}
3581
3582TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003583 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3584 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003585
3586 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003587 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3589 "Dynamic stencil reference state not set for this command buffer");
3590 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003591 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003592}
3593
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003594TEST_F(VkLayerTest, IndexBufferNotBound) {
3595 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003596
3597 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3599 "Index buffer object not bound to this command buffer when Indexed ");
3600 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003601 m_errorMonitor->VerifyFound();
3602}
3603
Karl Schultz6addd812016-02-02 17:17:23 -07003604TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3606 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3607 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003608
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003609 ASSERT_NO_FATAL_FAILURE(InitState());
3610 ASSERT_NO_FATAL_FAILURE(InitViewport());
3611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3612
Karl Schultz6addd812016-02-02 17:17:23 -07003613 // We luck out b/c by default the framework creates CB w/ the
3614 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003615 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003616 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003617 EndCommandBuffer();
3618
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003619 // Bypass framework since it does the waits automatically
3620 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003621 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003622 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3623 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003624 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003625 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003626 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003627 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003628 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003629 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003630 submit_info.pSignalSemaphores = NULL;
3631
Chris Forbes40028e22016-06-13 09:59:34 +12003632 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003633 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003634 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003635
Karl Schultz6addd812016-02-02 17:17:23 -07003636 // Cause validation error by re-submitting cmd buffer that should only be
3637 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003638 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003639 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003640
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003641 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003642}
3643
Karl Schultz6addd812016-02-02 17:17:23 -07003644TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003645 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003646 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003647
3648 ASSERT_NO_FATAL_FAILURE(InitState());
3649 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003650
Karl Schultz6addd812016-02-02 17:17:23 -07003651 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3652 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003653 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003654 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003655 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003656
3657 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003658 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3659 ds_pool_ci.pNext = NULL;
3660 ds_pool_ci.flags = 0;
3661 ds_pool_ci.maxSets = 1;
3662 ds_pool_ci.poolSizeCount = 1;
3663 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003664
3665 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003666 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003667 ASSERT_VK_SUCCESS(err);
3668
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003669 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3670 dsl_binding_samp.binding = 0;
3671 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3672 dsl_binding_samp.descriptorCount = 1;
3673 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3674 dsl_binding_samp.pImmutableSamplers = NULL;
3675
3676 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3677 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3678 ds_layout_ci.pNext = NULL;
3679 ds_layout_ci.bindingCount = 1;
3680 ds_layout_ci.pBindings = &dsl_binding_samp;
3681
3682 VkDescriptorSetLayout ds_layout_samp;
3683 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3684 ASSERT_VK_SUCCESS(err);
3685
3686 // Try to allocate 2 sets when pool only has 1 set
3687 VkDescriptorSet descriptor_sets[2];
3688 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3689 VkDescriptorSetAllocateInfo alloc_info = {};
3690 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3691 alloc_info.descriptorSetCount = 2;
3692 alloc_info.descriptorPool = ds_pool;
3693 alloc_info.pSetLayouts = set_layouts;
3694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3695 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3696 m_errorMonitor->VerifyFound();
3697
3698 alloc_info.descriptorSetCount = 1;
3699 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003700 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003701 dsl_binding.binding = 0;
3702 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3703 dsl_binding.descriptorCount = 1;
3704 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3705 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003706
Karl Schultz6addd812016-02-02 17:17:23 -07003707 ds_layout_ci.bindingCount = 1;
3708 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003709
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003710 VkDescriptorSetLayout ds_layout_ub;
3711 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003712 ASSERT_VK_SUCCESS(err);
3713
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003714 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003715 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003716 alloc_info.pSetLayouts = &ds_layout_ub;
3717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3718 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003719
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003720 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003721
Karl Schultz2825ab92016-12-02 08:23:14 -07003722 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003723 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003724 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003725}
3726
Karl Schultz6addd812016-02-02 17:17:23 -07003727TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3728 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003729
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3731 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3732 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003733
Tobin Ehlise735c692015-10-08 13:13:50 -06003734 ASSERT_NO_FATAL_FAILURE(InitState());
3735 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003736
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003737 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003738 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3739 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003740
3741 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003742 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3743 ds_pool_ci.pNext = NULL;
3744 ds_pool_ci.maxSets = 1;
3745 ds_pool_ci.poolSizeCount = 1;
3746 ds_pool_ci.flags = 0;
3747 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3748 // app can only call vkResetDescriptorPool on this pool.;
3749 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003750
3751 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003752 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003753 ASSERT_VK_SUCCESS(err);
3754
3755 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003756 dsl_binding.binding = 0;
3757 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3758 dsl_binding.descriptorCount = 1;
3759 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3760 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003761
3762 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003763 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3764 ds_layout_ci.pNext = NULL;
3765 ds_layout_ci.bindingCount = 1;
3766 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003767
3768 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003769 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003770 ASSERT_VK_SUCCESS(err);
3771
3772 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003773 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003774 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003775 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003776 alloc_info.descriptorPool = ds_pool;
3777 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003778 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003779 ASSERT_VK_SUCCESS(err);
3780
3781 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003782 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003783
Chia-I Wuf7458c52015-10-26 21:10:41 +08003784 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3785 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003786}
3787
Karl Schultz6addd812016-02-02 17:17:23 -07003788TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003789 // Attempt to clear Descriptor Pool with bad object.
3790 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003791
3792 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003794 uint64_t fake_pool_handle = 0xbaad6001;
3795 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3796 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003797 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003798}
3799
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003800TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003801 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3802 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003803 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003804 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003805
3806 uint64_t fake_set_handle = 0xbaad6001;
3807 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003808 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06003810
3811 ASSERT_NO_FATAL_FAILURE(InitState());
3812
3813 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3814 layout_bindings[0].binding = 0;
3815 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3816 layout_bindings[0].descriptorCount = 1;
3817 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3818 layout_bindings[0].pImmutableSamplers = NULL;
3819
3820 VkDescriptorSetLayout descriptor_set_layout;
3821 VkDescriptorSetLayoutCreateInfo dslci = {};
3822 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3823 dslci.pNext = NULL;
3824 dslci.bindingCount = 1;
3825 dslci.pBindings = layout_bindings;
3826 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003827 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003828
3829 VkPipelineLayout pipeline_layout;
3830 VkPipelineLayoutCreateInfo plci = {};
3831 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3832 plci.pNext = NULL;
3833 plci.setLayoutCount = 1;
3834 plci.pSetLayouts = &descriptor_set_layout;
3835 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003836 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003837
3838 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003839 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3840 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003841 m_errorMonitor->VerifyFound();
3842 EndCommandBuffer();
3843 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3844 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003845}
3846
Karl Schultz6addd812016-02-02 17:17:23 -07003847TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003848 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3849 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003850 uint64_t fake_layout_handle = 0xbaad6001;
3851 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06003853 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003854 VkPipelineLayout pipeline_layout;
3855 VkPipelineLayoutCreateInfo plci = {};
3856 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3857 plci.pNext = NULL;
3858 plci.setLayoutCount = 1;
3859 plci.pSetLayouts = &bad_layout;
3860 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3861
3862 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003863}
3864
Mark Muellerd4914412016-06-13 17:52:06 -06003865TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3866 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3867 "1) A uniform buffer update must have a valid buffer index."
3868 "2) When using an array of descriptors in a single WriteDescriptor,"
3869 " the descriptor types and stageflags must all be the same."
3870 "3) Immutable Sampler state must match across descriptors");
3871
3872 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003873 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3874 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3875 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3876 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3877 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003878
Mark Muellerd4914412016-06-13 17:52:06 -06003879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3880
3881 ASSERT_NO_FATAL_FAILURE(InitState());
3882 VkDescriptorPoolSize ds_type_count[4] = {};
3883 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3884 ds_type_count[0].descriptorCount = 1;
3885 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3886 ds_type_count[1].descriptorCount = 1;
3887 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3888 ds_type_count[2].descriptorCount = 1;
3889 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3890 ds_type_count[3].descriptorCount = 1;
3891
3892 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3893 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3894 ds_pool_ci.maxSets = 1;
3895 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3896 ds_pool_ci.pPoolSizes = ds_type_count;
3897
3898 VkDescriptorPool ds_pool;
3899 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3900 ASSERT_VK_SUCCESS(err);
3901
Mark Muellerb9896722016-06-16 09:54:29 -06003902 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003903 layout_binding[0].binding = 0;
3904 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3905 layout_binding[0].descriptorCount = 1;
3906 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3907 layout_binding[0].pImmutableSamplers = NULL;
3908
3909 layout_binding[1].binding = 1;
3910 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3911 layout_binding[1].descriptorCount = 1;
3912 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3913 layout_binding[1].pImmutableSamplers = NULL;
3914
3915 VkSamplerCreateInfo sampler_ci = {};
3916 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3917 sampler_ci.pNext = NULL;
3918 sampler_ci.magFilter = VK_FILTER_NEAREST;
3919 sampler_ci.minFilter = VK_FILTER_NEAREST;
3920 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3921 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3922 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3923 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3924 sampler_ci.mipLodBias = 1.0;
3925 sampler_ci.anisotropyEnable = VK_FALSE;
3926 sampler_ci.maxAnisotropy = 1;
3927 sampler_ci.compareEnable = VK_FALSE;
3928 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3929 sampler_ci.minLod = 1.0;
3930 sampler_ci.maxLod = 1.0;
3931 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3932 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3933 VkSampler sampler;
3934
3935 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3936 ASSERT_VK_SUCCESS(err);
3937
3938 layout_binding[2].binding = 2;
3939 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3940 layout_binding[2].descriptorCount = 1;
3941 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3942 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3943
Mark Muellerd4914412016-06-13 17:52:06 -06003944 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3945 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3946 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3947 ds_layout_ci.pBindings = layout_binding;
3948 VkDescriptorSetLayout ds_layout;
3949 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3950 ASSERT_VK_SUCCESS(err);
3951
3952 VkDescriptorSetAllocateInfo alloc_info = {};
3953 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3954 alloc_info.descriptorSetCount = 1;
3955 alloc_info.descriptorPool = ds_pool;
3956 alloc_info.pSetLayouts = &ds_layout;
3957 VkDescriptorSet descriptorSet;
3958 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3959 ASSERT_VK_SUCCESS(err);
3960
3961 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3962 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3963 pipeline_layout_ci.pNext = NULL;
3964 pipeline_layout_ci.setLayoutCount = 1;
3965 pipeline_layout_ci.pSetLayouts = &ds_layout;
3966
3967 VkPipelineLayout pipeline_layout;
3968 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3969 ASSERT_VK_SUCCESS(err);
3970
Mark Mueller5c838ce2016-06-16 09:54:29 -06003971 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003972 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3973 descriptor_write.dstSet = descriptorSet;
3974 descriptor_write.dstBinding = 0;
3975 descriptor_write.descriptorCount = 1;
3976 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3977
Mark Mueller5c838ce2016-06-16 09:54:29 -06003978 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003979 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3980 m_errorMonitor->VerifyFound();
3981
3982 // Create a buffer to update the descriptor with
3983 uint32_t qfi = 0;
3984 VkBufferCreateInfo buffCI = {};
3985 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3986 buffCI.size = 1024;
3987 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3988 buffCI.queueFamilyIndexCount = 1;
3989 buffCI.pQueueFamilyIndices = &qfi;
3990
3991 VkBuffer dyub;
3992 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3993 ASSERT_VK_SUCCESS(err);
3994 VkDescriptorBufferInfo buffInfo = {};
3995 buffInfo.buffer = dyub;
3996 buffInfo.offset = 0;
3997 buffInfo.range = 1024;
3998
3999 descriptor_write.pBufferInfo = &buffInfo;
4000 descriptor_write.descriptorCount = 2;
4001
Mark Mueller5c838ce2016-06-16 09:54:29 -06004002 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4004 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4005 m_errorMonitor->VerifyFound();
4006
Mark Mueller5c838ce2016-06-16 09:54:29 -06004007 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4008 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004009 descriptor_write.dstBinding = 1;
4010 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004011
Mark Mueller5c838ce2016-06-16 09:54:29 -06004012 // Make pImageInfo index non-null to avoid complaints of it missing
4013 VkDescriptorImageInfo imageInfo = {};
4014 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4015 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4017 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4018 m_errorMonitor->VerifyFound();
4019
Mark Muellerd4914412016-06-13 17:52:06 -06004020 vkDestroyBuffer(m_device->device(), dyub, NULL);
4021 vkDestroySampler(m_device->device(), sampler, NULL);
4022 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4023 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4024 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4025}
4026
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004027TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4028 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4029 "due to a buffer dependency being destroyed.");
4030 ASSERT_NO_FATAL_FAILURE(InitState());
4031
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004032 VkBuffer buffer;
4033 VkDeviceMemory mem;
4034 VkMemoryRequirements mem_reqs;
4035
4036 VkBufferCreateInfo buf_info = {};
4037 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004038 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004039 buf_info.size = 256;
4040 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4041 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4042 ASSERT_VK_SUCCESS(err);
4043
4044 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4045
4046 VkMemoryAllocateInfo alloc_info = {};
4047 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4048 alloc_info.allocationSize = 256;
4049 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004050 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 -06004051 if (!pass) {
4052 vkDestroyBuffer(m_device->device(), buffer, NULL);
4053 return;
4054 }
4055 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4056 ASSERT_VK_SUCCESS(err);
4057
4058 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4059 ASSERT_VK_SUCCESS(err);
4060
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004061 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004062 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004063 m_commandBuffer->EndCommandBuffer();
4064
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004066 // Destroy buffer dependency prior to submit to cause ERROR
4067 vkDestroyBuffer(m_device->device(), buffer, NULL);
4068
4069 VkSubmitInfo submit_info = {};
4070 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4071 submit_info.commandBufferCount = 1;
4072 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4073 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4074
4075 m_errorMonitor->VerifyFound();
4076 vkFreeMemory(m_device->handle(), mem, NULL);
4077}
4078
Tobin Ehlisea413442016-09-28 10:23:59 -06004079TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4080 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4081
4082 ASSERT_NO_FATAL_FAILURE(InitState());
4083 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4084
4085 VkDescriptorPoolSize ds_type_count;
4086 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4087 ds_type_count.descriptorCount = 1;
4088
4089 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4090 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4091 ds_pool_ci.maxSets = 1;
4092 ds_pool_ci.poolSizeCount = 1;
4093 ds_pool_ci.pPoolSizes = &ds_type_count;
4094
4095 VkDescriptorPool ds_pool;
4096 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4097 ASSERT_VK_SUCCESS(err);
4098
4099 VkDescriptorSetLayoutBinding layout_binding;
4100 layout_binding.binding = 0;
4101 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4102 layout_binding.descriptorCount = 1;
4103 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4104 layout_binding.pImmutableSamplers = NULL;
4105
4106 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4107 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4108 ds_layout_ci.bindingCount = 1;
4109 ds_layout_ci.pBindings = &layout_binding;
4110 VkDescriptorSetLayout ds_layout;
4111 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4112 ASSERT_VK_SUCCESS(err);
4113
4114 VkDescriptorSetAllocateInfo alloc_info = {};
4115 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4116 alloc_info.descriptorSetCount = 1;
4117 alloc_info.descriptorPool = ds_pool;
4118 alloc_info.pSetLayouts = &ds_layout;
4119 VkDescriptorSet descriptor_set;
4120 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4121 ASSERT_VK_SUCCESS(err);
4122
4123 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4124 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4125 pipeline_layout_ci.pNext = NULL;
4126 pipeline_layout_ci.setLayoutCount = 1;
4127 pipeline_layout_ci.pSetLayouts = &ds_layout;
4128
4129 VkPipelineLayout pipeline_layout;
4130 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4131 ASSERT_VK_SUCCESS(err);
4132
4133 VkBuffer buffer;
4134 uint32_t queue_family_index = 0;
4135 VkBufferCreateInfo buffer_create_info = {};
4136 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4137 buffer_create_info.size = 1024;
4138 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4139 buffer_create_info.queueFamilyIndexCount = 1;
4140 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4141
4142 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4143 ASSERT_VK_SUCCESS(err);
4144
4145 VkMemoryRequirements memory_reqs;
4146 VkDeviceMemory buffer_memory;
4147
4148 VkMemoryAllocateInfo memory_info = {};
4149 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4150 memory_info.allocationSize = 0;
4151 memory_info.memoryTypeIndex = 0;
4152
4153 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4154 memory_info.allocationSize = memory_reqs.size;
4155 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4156 ASSERT_TRUE(pass);
4157
4158 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4159 ASSERT_VK_SUCCESS(err);
4160 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4161 ASSERT_VK_SUCCESS(err);
4162
4163 VkBufferView view;
4164 VkBufferViewCreateInfo bvci = {};
4165 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4166 bvci.buffer = buffer;
4167 bvci.format = VK_FORMAT_R8_UNORM;
4168 bvci.range = VK_WHOLE_SIZE;
4169
4170 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4171 ASSERT_VK_SUCCESS(err);
4172
4173 VkWriteDescriptorSet descriptor_write = {};
4174 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4175 descriptor_write.dstSet = descriptor_set;
4176 descriptor_write.dstBinding = 0;
4177 descriptor_write.descriptorCount = 1;
4178 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4179 descriptor_write.pTexelBufferView = &view;
4180
4181 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4182
4183 char const *vsSource = "#version 450\n"
4184 "\n"
4185 "out gl_PerVertex { \n"
4186 " vec4 gl_Position;\n"
4187 "};\n"
4188 "void main(){\n"
4189 " gl_Position = vec4(1);\n"
4190 "}\n";
4191 char const *fsSource = "#version 450\n"
4192 "\n"
4193 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4194 "layout(location=0) out vec4 x;\n"
4195 "void main(){\n"
4196 " x = imageLoad(s, 0);\n"
4197 "}\n";
4198 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4199 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4200 VkPipelineObj pipe(m_device);
4201 pipe.AddShader(&vs);
4202 pipe.AddShader(&fs);
4203 pipe.AddColorAttachment();
4204 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4205
4206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4208
4209 BeginCommandBuffer();
4210 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4211 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4212 VkRect2D scissor = {{0, 0}, {16, 16}};
4213 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4214 // Bind pipeline to cmd buffer
4215 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4216 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4217 &descriptor_set, 0, nullptr);
4218 Draw(1, 0, 0, 0);
4219 EndCommandBuffer();
4220
4221 // Delete BufferView in order to invalidate cmd buffer
4222 vkDestroyBufferView(m_device->device(), view, NULL);
4223 // Now attempt submit of cmd buffer
4224 VkSubmitInfo submit_info = {};
4225 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4226 submit_info.commandBufferCount = 1;
4227 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4228 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4229 m_errorMonitor->VerifyFound();
4230
4231 // Clean-up
4232 vkDestroyBuffer(m_device->device(), buffer, NULL);
4233 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4234 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4235 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4236 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4237}
4238
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004239TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4240 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4241 "due to an image dependency being destroyed.");
4242 ASSERT_NO_FATAL_FAILURE(InitState());
4243
4244 VkImage image;
4245 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4246 VkImageCreateInfo image_create_info = {};
4247 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4248 image_create_info.pNext = NULL;
4249 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4250 image_create_info.format = tex_format;
4251 image_create_info.extent.width = 32;
4252 image_create_info.extent.height = 32;
4253 image_create_info.extent.depth = 1;
4254 image_create_info.mipLevels = 1;
4255 image_create_info.arrayLayers = 1;
4256 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4257 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004258 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004259 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004260 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004261 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004262 // Have to bind memory to image before recording cmd in cmd buffer using it
4263 VkMemoryRequirements mem_reqs;
4264 VkDeviceMemory image_mem;
4265 bool pass;
4266 VkMemoryAllocateInfo mem_alloc = {};
4267 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4268 mem_alloc.pNext = NULL;
4269 mem_alloc.memoryTypeIndex = 0;
4270 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4271 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004272 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004273 ASSERT_TRUE(pass);
4274 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4275 ASSERT_VK_SUCCESS(err);
4276 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4277 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004278
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004279 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004280 VkClearColorValue ccv;
4281 ccv.float32[0] = 1.0f;
4282 ccv.float32[1] = 1.0f;
4283 ccv.float32[2] = 1.0f;
4284 ccv.float32[3] = 1.0f;
4285 VkImageSubresourceRange isr = {};
4286 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004287 isr.baseArrayLayer = 0;
4288 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004289 isr.layerCount = 1;
4290 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004291 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004292 m_commandBuffer->EndCommandBuffer();
4293
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004295 // Destroy image dependency prior to submit to cause ERROR
4296 vkDestroyImage(m_device->device(), image, NULL);
4297
4298 VkSubmitInfo submit_info = {};
4299 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4300 submit_info.commandBufferCount = 1;
4301 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4302 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4303
4304 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004305 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004306}
4307
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004308TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4309 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4310 "due to a framebuffer image dependency being destroyed.");
4311 VkFormatProperties format_properties;
4312 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004313 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4314 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004315 return;
4316 }
4317
4318 ASSERT_NO_FATAL_FAILURE(InitState());
4319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4320
4321 VkImageCreateInfo image_ci = {};
4322 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4323 image_ci.pNext = NULL;
4324 image_ci.imageType = VK_IMAGE_TYPE_2D;
4325 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4326 image_ci.extent.width = 32;
4327 image_ci.extent.height = 32;
4328 image_ci.extent.depth = 1;
4329 image_ci.mipLevels = 1;
4330 image_ci.arrayLayers = 1;
4331 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4332 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004333 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004334 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4335 image_ci.flags = 0;
4336 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004337 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004338
4339 VkMemoryRequirements memory_reqs;
4340 VkDeviceMemory image_memory;
4341 bool pass;
4342 VkMemoryAllocateInfo memory_info = {};
4343 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4344 memory_info.pNext = NULL;
4345 memory_info.allocationSize = 0;
4346 memory_info.memoryTypeIndex = 0;
4347 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4348 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004349 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004350 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004351 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004352 ASSERT_VK_SUCCESS(err);
4353 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4354 ASSERT_VK_SUCCESS(err);
4355
4356 VkImageViewCreateInfo ivci = {
4357 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4358 nullptr,
4359 0,
4360 image,
4361 VK_IMAGE_VIEW_TYPE_2D,
4362 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004363 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004364 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4365 };
4366 VkImageView view;
4367 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4368 ASSERT_VK_SUCCESS(err);
4369
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004370 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004371 VkFramebuffer fb;
4372 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4373 ASSERT_VK_SUCCESS(err);
4374
4375 // Just use default renderpass with our framebuffer
4376 m_renderPassBeginInfo.framebuffer = fb;
4377 // Create Null cmd buffer for submit
4378 BeginCommandBuffer();
4379 EndCommandBuffer();
4380 // Destroy image attached to framebuffer to invalidate cmd buffer
4381 vkDestroyImage(m_device->device(), image, NULL);
4382 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004384 QueueCommandBuffer(false);
4385 m_errorMonitor->VerifyFound();
4386
4387 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4388 vkDestroyImageView(m_device->device(), view, nullptr);
4389 vkFreeMemory(m_device->device(), image_memory, nullptr);
4390}
4391
Tobin Ehlisb329f992016-10-12 13:20:29 -06004392TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4393 TEST_DESCRIPTION("Delete in-use framebuffer.");
4394 VkFormatProperties format_properties;
4395 VkResult err = VK_SUCCESS;
4396 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4397
4398 ASSERT_NO_FATAL_FAILURE(InitState());
4399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4400
4401 VkImageObj image(m_device);
4402 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4403 ASSERT_TRUE(image.initialized());
4404 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4405
4406 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4407 VkFramebuffer fb;
4408 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4409 ASSERT_VK_SUCCESS(err);
4410
4411 // Just use default renderpass with our framebuffer
4412 m_renderPassBeginInfo.framebuffer = fb;
4413 // Create Null cmd buffer for submit
4414 BeginCommandBuffer();
4415 EndCommandBuffer();
4416 // Submit cmd buffer to put it in-flight
4417 VkSubmitInfo submit_info = {};
4418 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4419 submit_info.commandBufferCount = 1;
4420 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4421 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4422 // Destroy framebuffer while in-flight
4423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4424 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4425 m_errorMonitor->VerifyFound();
4426 // Wait for queue to complete so we can safely destroy everything
4427 vkQueueWaitIdle(m_device->m_queue);
4428 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4429}
4430
Tobin Ehlis88becd72016-09-21 14:33:41 -06004431TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4432 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4433 VkFormatProperties format_properties;
4434 VkResult err = VK_SUCCESS;
4435 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004436
4437 ASSERT_NO_FATAL_FAILURE(InitState());
4438 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4439
4440 VkImageCreateInfo image_ci = {};
4441 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4442 image_ci.pNext = NULL;
4443 image_ci.imageType = VK_IMAGE_TYPE_2D;
4444 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4445 image_ci.extent.width = 256;
4446 image_ci.extent.height = 256;
4447 image_ci.extent.depth = 1;
4448 image_ci.mipLevels = 1;
4449 image_ci.arrayLayers = 1;
4450 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4451 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004452 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004453 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4454 image_ci.flags = 0;
4455 VkImage image;
4456 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4457
4458 VkMemoryRequirements memory_reqs;
4459 VkDeviceMemory image_memory;
4460 bool pass;
4461 VkMemoryAllocateInfo memory_info = {};
4462 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4463 memory_info.pNext = NULL;
4464 memory_info.allocationSize = 0;
4465 memory_info.memoryTypeIndex = 0;
4466 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4467 memory_info.allocationSize = memory_reqs.size;
4468 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4469 ASSERT_TRUE(pass);
4470 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4471 ASSERT_VK_SUCCESS(err);
4472 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4473 ASSERT_VK_SUCCESS(err);
4474
4475 VkImageViewCreateInfo ivci = {
4476 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4477 nullptr,
4478 0,
4479 image,
4480 VK_IMAGE_VIEW_TYPE_2D,
4481 VK_FORMAT_B8G8R8A8_UNORM,
4482 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4483 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4484 };
4485 VkImageView view;
4486 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4487 ASSERT_VK_SUCCESS(err);
4488
4489 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4490 VkFramebuffer fb;
4491 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4492 ASSERT_VK_SUCCESS(err);
4493
4494 // Just use default renderpass with our framebuffer
4495 m_renderPassBeginInfo.framebuffer = fb;
4496 // Create Null cmd buffer for submit
4497 BeginCommandBuffer();
4498 EndCommandBuffer();
4499 // Submit cmd buffer to put it (and attached imageView) in-flight
4500 VkSubmitInfo submit_info = {};
4501 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4502 submit_info.commandBufferCount = 1;
4503 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4504 // Submit cmd buffer to put framebuffer and children in-flight
4505 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4506 // Destroy image attached to framebuffer while in-flight
4507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4508 vkDestroyImage(m_device->device(), image, NULL);
4509 m_errorMonitor->VerifyFound();
4510 // Wait for queue to complete so we can safely destroy image and other objects
4511 vkQueueWaitIdle(m_device->m_queue);
4512 vkDestroyImage(m_device->device(), image, NULL);
4513 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4514 vkDestroyImageView(m_device->device(), view, nullptr);
4515 vkFreeMemory(m_device->device(), image_memory, nullptr);
4516}
4517
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004518TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4519 TEST_DESCRIPTION("Delete in-use renderPass.");
4520
4521 ASSERT_NO_FATAL_FAILURE(InitState());
4522 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4523
4524 // Create simple renderpass
4525 VkAttachmentReference attach = {};
4526 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4527 VkSubpassDescription subpass = {};
4528 subpass.pColorAttachments = &attach;
4529 VkRenderPassCreateInfo rpci = {};
4530 rpci.subpassCount = 1;
4531 rpci.pSubpasses = &subpass;
4532 rpci.attachmentCount = 1;
4533 VkAttachmentDescription attach_desc = {};
4534 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4535 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4536 rpci.pAttachments = &attach_desc;
4537 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4538 VkRenderPass rp;
4539 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4540 ASSERT_VK_SUCCESS(err);
4541
4542 // Create a pipeline that uses the given renderpass
4543 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4544 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4545
4546 VkPipelineLayout pipeline_layout;
4547 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4548 ASSERT_VK_SUCCESS(err);
4549
4550 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4551 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4552 vp_state_ci.viewportCount = 1;
4553 VkViewport vp = {}; // Just need dummy vp to point to
4554 vp_state_ci.pViewports = &vp;
4555 vp_state_ci.scissorCount = 1;
4556 VkRect2D scissors = {}; // Dummy scissors to point to
4557 vp_state_ci.pScissors = &scissors;
4558
4559 VkPipelineShaderStageCreateInfo shaderStages[2];
4560 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4561
4562 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4563 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4564 // but add it to be able to run on more devices
4565 shaderStages[0] = vs.GetStageCreateInfo();
4566 shaderStages[1] = fs.GetStageCreateInfo();
4567
4568 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4569 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4570
4571 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4572 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4573 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4574
4575 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4576 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4577 rs_ci.rasterizerDiscardEnable = true;
4578 rs_ci.lineWidth = 1.0f;
4579
4580 VkPipelineColorBlendAttachmentState att = {};
4581 att.blendEnable = VK_FALSE;
4582 att.colorWriteMask = 0xf;
4583
4584 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4585 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4586 cb_ci.attachmentCount = 1;
4587 cb_ci.pAttachments = &att;
4588
4589 VkGraphicsPipelineCreateInfo gp_ci = {};
4590 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4591 gp_ci.stageCount = 2;
4592 gp_ci.pStages = shaderStages;
4593 gp_ci.pVertexInputState = &vi_ci;
4594 gp_ci.pInputAssemblyState = &ia_ci;
4595 gp_ci.pViewportState = &vp_state_ci;
4596 gp_ci.pRasterizationState = &rs_ci;
4597 gp_ci.pColorBlendState = &cb_ci;
4598 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4599 gp_ci.layout = pipeline_layout;
4600 gp_ci.renderPass = rp;
4601
4602 VkPipelineCacheCreateInfo pc_ci = {};
4603 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4604
4605 VkPipeline pipeline;
4606 VkPipelineCache pipe_cache;
4607 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4608 ASSERT_VK_SUCCESS(err);
4609
4610 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4611 ASSERT_VK_SUCCESS(err);
4612 // Bind pipeline to cmd buffer, will also bind renderpass
4613 m_commandBuffer->BeginCommandBuffer();
4614 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4615 m_commandBuffer->EndCommandBuffer();
4616
4617 VkSubmitInfo submit_info = {};
4618 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4619 submit_info.commandBufferCount = 1;
4620 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4621 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4622
4623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4624 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4625 m_errorMonitor->VerifyFound();
4626
4627 // Wait for queue to complete so we can safely destroy everything
4628 vkQueueWaitIdle(m_device->m_queue);
4629 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4630 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4631 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4632 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4633}
4634
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004635TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004636 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004637 ASSERT_NO_FATAL_FAILURE(InitState());
4638
4639 VkImage image;
4640 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4641 VkImageCreateInfo image_create_info = {};
4642 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4643 image_create_info.pNext = NULL;
4644 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4645 image_create_info.format = tex_format;
4646 image_create_info.extent.width = 32;
4647 image_create_info.extent.height = 32;
4648 image_create_info.extent.depth = 1;
4649 image_create_info.mipLevels = 1;
4650 image_create_info.arrayLayers = 1;
4651 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4652 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004653 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004654 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004655 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004656 ASSERT_VK_SUCCESS(err);
4657 // Have to bind memory to image before recording cmd in cmd buffer using it
4658 VkMemoryRequirements mem_reqs;
4659 VkDeviceMemory image_mem;
4660 bool pass;
4661 VkMemoryAllocateInfo mem_alloc = {};
4662 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4663 mem_alloc.pNext = NULL;
4664 mem_alloc.memoryTypeIndex = 0;
4665 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4666 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004667 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004668 ASSERT_TRUE(pass);
4669 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4670 ASSERT_VK_SUCCESS(err);
4671
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004672 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004674 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004675
4676 m_commandBuffer->BeginCommandBuffer();
4677 VkClearColorValue ccv;
4678 ccv.float32[0] = 1.0f;
4679 ccv.float32[1] = 1.0f;
4680 ccv.float32[2] = 1.0f;
4681 ccv.float32[3] = 1.0f;
4682 VkImageSubresourceRange isr = {};
4683 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4684 isr.baseArrayLayer = 0;
4685 isr.baseMipLevel = 0;
4686 isr.layerCount = 1;
4687 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004688 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004689 m_commandBuffer->EndCommandBuffer();
4690
4691 m_errorMonitor->VerifyFound();
4692 vkDestroyImage(m_device->device(), image, NULL);
4693 vkFreeMemory(m_device->device(), image_mem, nullptr);
4694}
4695
4696TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004697 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004698 ASSERT_NO_FATAL_FAILURE(InitState());
4699
4700 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004701 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 -06004702 VK_IMAGE_TILING_OPTIMAL, 0);
4703 ASSERT_TRUE(image.initialized());
4704
4705 VkBuffer buffer;
4706 VkDeviceMemory mem;
4707 VkMemoryRequirements mem_reqs;
4708
4709 VkBufferCreateInfo buf_info = {};
4710 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004711 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004712 buf_info.size = 256;
4713 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4714 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4715 ASSERT_VK_SUCCESS(err);
4716
4717 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4718
4719 VkMemoryAllocateInfo alloc_info = {};
4720 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4721 alloc_info.allocationSize = 256;
4722 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004723 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 -06004724 if (!pass) {
4725 vkDestroyBuffer(m_device->device(), buffer, NULL);
4726 return;
4727 }
4728 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4729 ASSERT_VK_SUCCESS(err);
4730
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004731 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004733 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004734 VkBufferImageCopy region = {};
4735 region.bufferRowLength = 128;
4736 region.bufferImageHeight = 128;
4737 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4738
4739 region.imageSubresource.layerCount = 1;
4740 region.imageExtent.height = 4;
4741 region.imageExtent.width = 4;
4742 region.imageExtent.depth = 1;
4743 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004744 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4745 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004746 m_commandBuffer->EndCommandBuffer();
4747
4748 m_errorMonitor->VerifyFound();
4749
4750 vkDestroyBuffer(m_device->device(), buffer, NULL);
4751 vkFreeMemory(m_device->handle(), mem, NULL);
4752}
4753
Tobin Ehlis85940f52016-07-07 16:57:21 -06004754TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4755 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4756 "due to an event dependency being destroyed.");
4757 ASSERT_NO_FATAL_FAILURE(InitState());
4758
4759 VkEvent event;
4760 VkEventCreateInfo evci = {};
4761 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4762 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4763 ASSERT_VK_SUCCESS(result);
4764
4765 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004766 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004767 m_commandBuffer->EndCommandBuffer();
4768
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004770 // Destroy event dependency prior to submit to cause ERROR
4771 vkDestroyEvent(m_device->device(), event, NULL);
4772
4773 VkSubmitInfo submit_info = {};
4774 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4775 submit_info.commandBufferCount = 1;
4776 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4777 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4778
4779 m_errorMonitor->VerifyFound();
4780}
4781
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004782TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4783 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4784 "due to a query pool dependency being destroyed.");
4785 ASSERT_NO_FATAL_FAILURE(InitState());
4786
4787 VkQueryPool query_pool;
4788 VkQueryPoolCreateInfo qpci{};
4789 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4790 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4791 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004792 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004793 ASSERT_VK_SUCCESS(result);
4794
4795 m_commandBuffer->BeginCommandBuffer();
4796 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4797 m_commandBuffer->EndCommandBuffer();
4798
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004800 // Destroy query pool dependency prior to submit to cause ERROR
4801 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4802
4803 VkSubmitInfo submit_info = {};
4804 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4805 submit_info.commandBufferCount = 1;
4806 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4807 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4808
4809 m_errorMonitor->VerifyFound();
4810}
4811
Tobin Ehlis24130d92016-07-08 15:50:53 -06004812TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4813 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4814 "due to a pipeline dependency being destroyed.");
4815 ASSERT_NO_FATAL_FAILURE(InitState());
4816 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4817
4818 VkResult err;
4819
4820 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4821 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4822
4823 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004824 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004825 ASSERT_VK_SUCCESS(err);
4826
4827 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4828 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4829 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004830 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004831 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004832 vp_state_ci.scissorCount = 1;
4833 VkRect2D scissors = {}; // Dummy scissors to point to
4834 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004835
4836 VkPipelineShaderStageCreateInfo shaderStages[2];
4837 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4838
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004839 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4840 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4841 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004842 shaderStages[0] = vs.GetStageCreateInfo();
4843 shaderStages[1] = fs.GetStageCreateInfo();
4844
4845 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4846 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4847
4848 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4849 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4850 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4851
4852 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4853 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004854 rs_ci.rasterizerDiscardEnable = true;
4855 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004856
4857 VkPipelineColorBlendAttachmentState att = {};
4858 att.blendEnable = VK_FALSE;
4859 att.colorWriteMask = 0xf;
4860
4861 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4862 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4863 cb_ci.attachmentCount = 1;
4864 cb_ci.pAttachments = &att;
4865
4866 VkGraphicsPipelineCreateInfo gp_ci = {};
4867 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4868 gp_ci.stageCount = 2;
4869 gp_ci.pStages = shaderStages;
4870 gp_ci.pVertexInputState = &vi_ci;
4871 gp_ci.pInputAssemblyState = &ia_ci;
4872 gp_ci.pViewportState = &vp_state_ci;
4873 gp_ci.pRasterizationState = &rs_ci;
4874 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004875 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4876 gp_ci.layout = pipeline_layout;
4877 gp_ci.renderPass = renderPass();
4878
4879 VkPipelineCacheCreateInfo pc_ci = {};
4880 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4881
4882 VkPipeline pipeline;
4883 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004884 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004885 ASSERT_VK_SUCCESS(err);
4886
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004887 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004888 ASSERT_VK_SUCCESS(err);
4889
4890 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004891 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004892 m_commandBuffer->EndCommandBuffer();
4893 // Now destroy pipeline in order to cause error when submitting
4894 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4895
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004897
4898 VkSubmitInfo submit_info = {};
4899 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4900 submit_info.commandBufferCount = 1;
4901 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4902 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4903
4904 m_errorMonitor->VerifyFound();
4905 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4906 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4907}
4908
Tobin Ehlis31289162016-08-17 14:57:58 -06004909TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4910 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4911 "due to a bound descriptor set with a buffer dependency "
4912 "being destroyed.");
4913 ASSERT_NO_FATAL_FAILURE(InitState());
4914 ASSERT_NO_FATAL_FAILURE(InitViewport());
4915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4916
4917 VkDescriptorPoolSize ds_type_count = {};
4918 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4919 ds_type_count.descriptorCount = 1;
4920
4921 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4922 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4923 ds_pool_ci.pNext = NULL;
4924 ds_pool_ci.maxSets = 1;
4925 ds_pool_ci.poolSizeCount = 1;
4926 ds_pool_ci.pPoolSizes = &ds_type_count;
4927
4928 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004929 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004930 ASSERT_VK_SUCCESS(err);
4931
4932 VkDescriptorSetLayoutBinding dsl_binding = {};
4933 dsl_binding.binding = 0;
4934 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4935 dsl_binding.descriptorCount = 1;
4936 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4937 dsl_binding.pImmutableSamplers = NULL;
4938
4939 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4940 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4941 ds_layout_ci.pNext = NULL;
4942 ds_layout_ci.bindingCount = 1;
4943 ds_layout_ci.pBindings = &dsl_binding;
4944 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004945 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004946 ASSERT_VK_SUCCESS(err);
4947
4948 VkDescriptorSet descriptorSet;
4949 VkDescriptorSetAllocateInfo alloc_info = {};
4950 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4951 alloc_info.descriptorSetCount = 1;
4952 alloc_info.descriptorPool = ds_pool;
4953 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004954 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004955 ASSERT_VK_SUCCESS(err);
4956
4957 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4958 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4959 pipeline_layout_ci.pNext = NULL;
4960 pipeline_layout_ci.setLayoutCount = 1;
4961 pipeline_layout_ci.pSetLayouts = &ds_layout;
4962
4963 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004964 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004965 ASSERT_VK_SUCCESS(err);
4966
4967 // Create a buffer to update the descriptor with
4968 uint32_t qfi = 0;
4969 VkBufferCreateInfo buffCI = {};
4970 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4971 buffCI.size = 1024;
4972 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4973 buffCI.queueFamilyIndexCount = 1;
4974 buffCI.pQueueFamilyIndices = &qfi;
4975
4976 VkBuffer buffer;
4977 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4978 ASSERT_VK_SUCCESS(err);
4979 // Allocate memory and bind to buffer so we can make it to the appropriate
4980 // error
4981 VkMemoryAllocateInfo mem_alloc = {};
4982 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4983 mem_alloc.pNext = NULL;
4984 mem_alloc.allocationSize = 1024;
4985 mem_alloc.memoryTypeIndex = 0;
4986
4987 VkMemoryRequirements memReqs;
4988 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004989 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004990 if (!pass) {
4991 vkDestroyBuffer(m_device->device(), buffer, NULL);
4992 return;
4993 }
4994
4995 VkDeviceMemory mem;
4996 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4997 ASSERT_VK_SUCCESS(err);
4998 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4999 ASSERT_VK_SUCCESS(err);
5000 // Correctly update descriptor to avoid "NOT_UPDATED" error
5001 VkDescriptorBufferInfo buffInfo = {};
5002 buffInfo.buffer = buffer;
5003 buffInfo.offset = 0;
5004 buffInfo.range = 1024;
5005
5006 VkWriteDescriptorSet descriptor_write;
5007 memset(&descriptor_write, 0, sizeof(descriptor_write));
5008 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5009 descriptor_write.dstSet = descriptorSet;
5010 descriptor_write.dstBinding = 0;
5011 descriptor_write.descriptorCount = 1;
5012 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5013 descriptor_write.pBufferInfo = &buffInfo;
5014
5015 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5016
5017 // Create PSO to be used for draw-time errors below
5018 char const *vsSource = "#version 450\n"
5019 "\n"
5020 "out gl_PerVertex { \n"
5021 " vec4 gl_Position;\n"
5022 "};\n"
5023 "void main(){\n"
5024 " gl_Position = vec4(1);\n"
5025 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005026 char const *fsSource = "#version 450\n"
5027 "\n"
5028 "layout(location=0) out vec4 x;\n"
5029 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5030 "void main(){\n"
5031 " x = vec4(bar.y);\n"
5032 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005033 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5034 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5035 VkPipelineObj pipe(m_device);
5036 pipe.AddShader(&vs);
5037 pipe.AddShader(&fs);
5038 pipe.AddColorAttachment();
5039 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5040
5041 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005042 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5043 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5044 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005045 Draw(1, 0, 0, 0);
5046 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005048 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5049 vkDestroyBuffer(m_device->device(), buffer, NULL);
5050 // Attempt to submit cmd buffer
5051 VkSubmitInfo submit_info = {};
5052 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5053 submit_info.commandBufferCount = 1;
5054 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5055 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5056 m_errorMonitor->VerifyFound();
5057 // Cleanup
5058 vkFreeMemory(m_device->device(), mem, NULL);
5059
5060 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5061 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5062 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5063}
5064
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005065TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5066 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5067 "due to a bound descriptor sets with a combined image "
5068 "sampler having their image, sampler, and descriptor set "
5069 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005070 "submit associated cmd buffers. Attempt to destroy a "
5071 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005072 ASSERT_NO_FATAL_FAILURE(InitState());
5073 ASSERT_NO_FATAL_FAILURE(InitViewport());
5074 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5075
5076 VkDescriptorPoolSize ds_type_count = {};
5077 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5078 ds_type_count.descriptorCount = 1;
5079
5080 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5081 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5082 ds_pool_ci.pNext = NULL;
5083 ds_pool_ci.maxSets = 1;
5084 ds_pool_ci.poolSizeCount = 1;
5085 ds_pool_ci.pPoolSizes = &ds_type_count;
5086
5087 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005088 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005089 ASSERT_VK_SUCCESS(err);
5090
5091 VkDescriptorSetLayoutBinding dsl_binding = {};
5092 dsl_binding.binding = 0;
5093 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5094 dsl_binding.descriptorCount = 1;
5095 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5096 dsl_binding.pImmutableSamplers = NULL;
5097
5098 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5099 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5100 ds_layout_ci.pNext = NULL;
5101 ds_layout_ci.bindingCount = 1;
5102 ds_layout_ci.pBindings = &dsl_binding;
5103 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005104 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005105 ASSERT_VK_SUCCESS(err);
5106
5107 VkDescriptorSet descriptorSet;
5108 VkDescriptorSetAllocateInfo alloc_info = {};
5109 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5110 alloc_info.descriptorSetCount = 1;
5111 alloc_info.descriptorPool = ds_pool;
5112 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005113 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005114 ASSERT_VK_SUCCESS(err);
5115
5116 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5117 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5118 pipeline_layout_ci.pNext = NULL;
5119 pipeline_layout_ci.setLayoutCount = 1;
5120 pipeline_layout_ci.pSetLayouts = &ds_layout;
5121
5122 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005123 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005124 ASSERT_VK_SUCCESS(err);
5125
5126 // Create images to update the descriptor with
5127 VkImage image;
5128 VkImage image2;
5129 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5130 const int32_t tex_width = 32;
5131 const int32_t tex_height = 32;
5132 VkImageCreateInfo image_create_info = {};
5133 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5134 image_create_info.pNext = NULL;
5135 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5136 image_create_info.format = tex_format;
5137 image_create_info.extent.width = tex_width;
5138 image_create_info.extent.height = tex_height;
5139 image_create_info.extent.depth = 1;
5140 image_create_info.mipLevels = 1;
5141 image_create_info.arrayLayers = 1;
5142 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5143 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5144 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5145 image_create_info.flags = 0;
5146 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5147 ASSERT_VK_SUCCESS(err);
5148 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5149 ASSERT_VK_SUCCESS(err);
5150
5151 VkMemoryRequirements memory_reqs;
5152 VkDeviceMemory image_memory;
5153 bool pass;
5154 VkMemoryAllocateInfo memory_info = {};
5155 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5156 memory_info.pNext = NULL;
5157 memory_info.allocationSize = 0;
5158 memory_info.memoryTypeIndex = 0;
5159 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5160 // Allocate enough memory for both images
5161 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005162 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005163 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005164 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005165 ASSERT_VK_SUCCESS(err);
5166 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5167 ASSERT_VK_SUCCESS(err);
5168 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005169 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005170 ASSERT_VK_SUCCESS(err);
5171
5172 VkImageViewCreateInfo image_view_create_info = {};
5173 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5174 image_view_create_info.image = image;
5175 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5176 image_view_create_info.format = tex_format;
5177 image_view_create_info.subresourceRange.layerCount = 1;
5178 image_view_create_info.subresourceRange.baseMipLevel = 0;
5179 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005180 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005181
5182 VkImageView view;
5183 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005184 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005185 ASSERT_VK_SUCCESS(err);
5186 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005187 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005188 ASSERT_VK_SUCCESS(err);
5189 // Create Samplers
5190 VkSamplerCreateInfo sampler_ci = {};
5191 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5192 sampler_ci.pNext = NULL;
5193 sampler_ci.magFilter = VK_FILTER_NEAREST;
5194 sampler_ci.minFilter = VK_FILTER_NEAREST;
5195 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5196 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5197 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5198 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5199 sampler_ci.mipLodBias = 1.0;
5200 sampler_ci.anisotropyEnable = VK_FALSE;
5201 sampler_ci.maxAnisotropy = 1;
5202 sampler_ci.compareEnable = VK_FALSE;
5203 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5204 sampler_ci.minLod = 1.0;
5205 sampler_ci.maxLod = 1.0;
5206 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5207 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5208 VkSampler sampler;
5209 VkSampler sampler2;
5210 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5211 ASSERT_VK_SUCCESS(err);
5212 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5213 ASSERT_VK_SUCCESS(err);
5214 // Update descriptor with image and sampler
5215 VkDescriptorImageInfo img_info = {};
5216 img_info.sampler = sampler;
5217 img_info.imageView = view;
5218 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5219
5220 VkWriteDescriptorSet descriptor_write;
5221 memset(&descriptor_write, 0, sizeof(descriptor_write));
5222 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5223 descriptor_write.dstSet = descriptorSet;
5224 descriptor_write.dstBinding = 0;
5225 descriptor_write.descriptorCount = 1;
5226 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5227 descriptor_write.pImageInfo = &img_info;
5228
5229 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5230
5231 // Create PSO to be used for draw-time errors below
5232 char const *vsSource = "#version 450\n"
5233 "\n"
5234 "out gl_PerVertex { \n"
5235 " vec4 gl_Position;\n"
5236 "};\n"
5237 "void main(){\n"
5238 " gl_Position = vec4(1);\n"
5239 "}\n";
5240 char const *fsSource = "#version 450\n"
5241 "\n"
5242 "layout(set=0, binding=0) uniform sampler2D s;\n"
5243 "layout(location=0) out vec4 x;\n"
5244 "void main(){\n"
5245 " x = texture(s, vec2(1));\n"
5246 "}\n";
5247 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5248 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5249 VkPipelineObj pipe(m_device);
5250 pipe.AddShader(&vs);
5251 pipe.AddShader(&fs);
5252 pipe.AddColorAttachment();
5253 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5254
5255 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005257 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005258 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5259 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5260 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005261 Draw(1, 0, 0, 0);
5262 EndCommandBuffer();
5263 // Destroy sampler invalidates the cmd buffer, causing error on submit
5264 vkDestroySampler(m_device->device(), sampler, NULL);
5265 // Attempt to submit cmd buffer
5266 VkSubmitInfo submit_info = {};
5267 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5268 submit_info.commandBufferCount = 1;
5269 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5270 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5271 m_errorMonitor->VerifyFound();
5272 // Now re-update descriptor with valid sampler and delete image
5273 img_info.sampler = sampler2;
5274 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005276 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005277 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5278 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5279 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005280 Draw(1, 0, 0, 0);
5281 EndCommandBuffer();
5282 // Destroy image invalidates the cmd buffer, causing error on submit
5283 vkDestroyImage(m_device->device(), image, NULL);
5284 // Attempt to submit cmd buffer
5285 submit_info = {};
5286 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5287 submit_info.commandBufferCount = 1;
5288 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5289 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5290 m_errorMonitor->VerifyFound();
5291 // Now update descriptor to be valid, but then free descriptor
5292 img_info.imageView = view2;
5293 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005295 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005296 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5297 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5298 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005299 Draw(1, 0, 0, 0);
5300 EndCommandBuffer();
5301 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005303 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005304 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005305 // Attempt to submit cmd buffer
5306 submit_info = {};
5307 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5308 submit_info.commandBufferCount = 1;
5309 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5310 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5311 m_errorMonitor->VerifyFound();
5312 // Cleanup
5313 vkFreeMemory(m_device->device(), image_memory, NULL);
5314 vkDestroySampler(m_device->device(), sampler2, NULL);
5315 vkDestroyImage(m_device->device(), image2, NULL);
5316 vkDestroyImageView(m_device->device(), view, NULL);
5317 vkDestroyImageView(m_device->device(), view2, NULL);
5318 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5319 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5320 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5321}
5322
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005323TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5324 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5325 ASSERT_NO_FATAL_FAILURE(InitState());
5326 ASSERT_NO_FATAL_FAILURE(InitViewport());
5327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5328
5329 VkDescriptorPoolSize ds_type_count = {};
5330 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5331 ds_type_count.descriptorCount = 1;
5332
5333 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5334 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5335 ds_pool_ci.pNext = NULL;
5336 ds_pool_ci.maxSets = 1;
5337 ds_pool_ci.poolSizeCount = 1;
5338 ds_pool_ci.pPoolSizes = &ds_type_count;
5339
5340 VkDescriptorPool ds_pool;
5341 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5342 ASSERT_VK_SUCCESS(err);
5343
5344 VkDescriptorSetLayoutBinding dsl_binding = {};
5345 dsl_binding.binding = 0;
5346 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5347 dsl_binding.descriptorCount = 1;
5348 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5349 dsl_binding.pImmutableSamplers = NULL;
5350
5351 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5352 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5353 ds_layout_ci.pNext = NULL;
5354 ds_layout_ci.bindingCount = 1;
5355 ds_layout_ci.pBindings = &dsl_binding;
5356 VkDescriptorSetLayout ds_layout;
5357 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5358 ASSERT_VK_SUCCESS(err);
5359
5360 VkDescriptorSet descriptor_set;
5361 VkDescriptorSetAllocateInfo alloc_info = {};
5362 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5363 alloc_info.descriptorSetCount = 1;
5364 alloc_info.descriptorPool = ds_pool;
5365 alloc_info.pSetLayouts = &ds_layout;
5366 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5367 ASSERT_VK_SUCCESS(err);
5368
5369 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5370 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5371 pipeline_layout_ci.pNext = NULL;
5372 pipeline_layout_ci.setLayoutCount = 1;
5373 pipeline_layout_ci.pSetLayouts = &ds_layout;
5374
5375 VkPipelineLayout pipeline_layout;
5376 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5377 ASSERT_VK_SUCCESS(err);
5378
5379 // Create image to update the descriptor with
5380 VkImageObj image(m_device);
5381 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5382 ASSERT_TRUE(image.initialized());
5383
5384 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5385 // Create Sampler
5386 VkSamplerCreateInfo sampler_ci = {};
5387 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5388 sampler_ci.pNext = NULL;
5389 sampler_ci.magFilter = VK_FILTER_NEAREST;
5390 sampler_ci.minFilter = VK_FILTER_NEAREST;
5391 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5392 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5393 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5394 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5395 sampler_ci.mipLodBias = 1.0;
5396 sampler_ci.anisotropyEnable = VK_FALSE;
5397 sampler_ci.maxAnisotropy = 1;
5398 sampler_ci.compareEnable = VK_FALSE;
5399 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5400 sampler_ci.minLod = 1.0;
5401 sampler_ci.maxLod = 1.0;
5402 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5403 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5404 VkSampler sampler;
5405 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5406 ASSERT_VK_SUCCESS(err);
5407 // Update descriptor with image and sampler
5408 VkDescriptorImageInfo img_info = {};
5409 img_info.sampler = sampler;
5410 img_info.imageView = view;
5411 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5412
5413 VkWriteDescriptorSet descriptor_write;
5414 memset(&descriptor_write, 0, sizeof(descriptor_write));
5415 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5416 descriptor_write.dstSet = descriptor_set;
5417 descriptor_write.dstBinding = 0;
5418 descriptor_write.descriptorCount = 1;
5419 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5420 descriptor_write.pImageInfo = &img_info;
5421
5422 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5423
5424 // Create PSO to be used for draw-time errors below
5425 char const *vsSource = "#version 450\n"
5426 "\n"
5427 "out gl_PerVertex { \n"
5428 " vec4 gl_Position;\n"
5429 "};\n"
5430 "void main(){\n"
5431 " gl_Position = vec4(1);\n"
5432 "}\n";
5433 char const *fsSource = "#version 450\n"
5434 "\n"
5435 "layout(set=0, binding=0) uniform sampler2D s;\n"
5436 "layout(location=0) out vec4 x;\n"
5437 "void main(){\n"
5438 " x = texture(s, vec2(1));\n"
5439 "}\n";
5440 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5441 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5442 VkPipelineObj pipe(m_device);
5443 pipe.AddShader(&vs);
5444 pipe.AddShader(&fs);
5445 pipe.AddColorAttachment();
5446 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5447
5448 BeginCommandBuffer();
5449 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5450 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5451 &descriptor_set, 0, NULL);
5452 Draw(1, 0, 0, 0);
5453 EndCommandBuffer();
5454 // Submit cmd buffer to put pool in-flight
5455 VkSubmitInfo submit_info = {};
5456 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5457 submit_info.commandBufferCount = 1;
5458 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5459 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5460 // Destroy pool while in-flight, causing error
5461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5462 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5463 m_errorMonitor->VerifyFound();
5464 vkQueueWaitIdle(m_device->m_queue);
5465 // Cleanup
5466 vkDestroySampler(m_device->device(), sampler, NULL);
5467 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5468 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5469 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5470}
5471
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005472TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5473 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5474 ASSERT_NO_FATAL_FAILURE(InitState());
5475 ASSERT_NO_FATAL_FAILURE(InitViewport());
5476 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5477
5478 VkDescriptorPoolSize ds_type_count = {};
5479 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5480 ds_type_count.descriptorCount = 1;
5481
5482 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5483 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5484 ds_pool_ci.pNext = NULL;
5485 ds_pool_ci.maxSets = 1;
5486 ds_pool_ci.poolSizeCount = 1;
5487 ds_pool_ci.pPoolSizes = &ds_type_count;
5488
5489 VkDescriptorPool ds_pool;
5490 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5491 ASSERT_VK_SUCCESS(err);
5492
5493 VkDescriptorSetLayoutBinding dsl_binding = {};
5494 dsl_binding.binding = 0;
5495 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5496 dsl_binding.descriptorCount = 1;
5497 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5498 dsl_binding.pImmutableSamplers = NULL;
5499
5500 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5501 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5502 ds_layout_ci.pNext = NULL;
5503 ds_layout_ci.bindingCount = 1;
5504 ds_layout_ci.pBindings = &dsl_binding;
5505 VkDescriptorSetLayout ds_layout;
5506 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5507 ASSERT_VK_SUCCESS(err);
5508
5509 VkDescriptorSet descriptorSet;
5510 VkDescriptorSetAllocateInfo alloc_info = {};
5511 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5512 alloc_info.descriptorSetCount = 1;
5513 alloc_info.descriptorPool = ds_pool;
5514 alloc_info.pSetLayouts = &ds_layout;
5515 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5516 ASSERT_VK_SUCCESS(err);
5517
5518 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5519 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5520 pipeline_layout_ci.pNext = NULL;
5521 pipeline_layout_ci.setLayoutCount = 1;
5522 pipeline_layout_ci.pSetLayouts = &ds_layout;
5523
5524 VkPipelineLayout pipeline_layout;
5525 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5526 ASSERT_VK_SUCCESS(err);
5527
5528 // Create images to update the descriptor with
5529 VkImage image;
5530 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5531 const int32_t tex_width = 32;
5532 const int32_t tex_height = 32;
5533 VkImageCreateInfo image_create_info = {};
5534 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5535 image_create_info.pNext = NULL;
5536 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5537 image_create_info.format = tex_format;
5538 image_create_info.extent.width = tex_width;
5539 image_create_info.extent.height = tex_height;
5540 image_create_info.extent.depth = 1;
5541 image_create_info.mipLevels = 1;
5542 image_create_info.arrayLayers = 1;
5543 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5544 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5545 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5546 image_create_info.flags = 0;
5547 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5548 ASSERT_VK_SUCCESS(err);
5549 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5550 VkMemoryRequirements memory_reqs;
5551 VkDeviceMemory image_memory;
5552 bool pass;
5553 VkMemoryAllocateInfo memory_info = {};
5554 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5555 memory_info.pNext = NULL;
5556 memory_info.allocationSize = 0;
5557 memory_info.memoryTypeIndex = 0;
5558 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5559 // Allocate enough memory for image
5560 memory_info.allocationSize = memory_reqs.size;
5561 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5562 ASSERT_TRUE(pass);
5563 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5564 ASSERT_VK_SUCCESS(err);
5565 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5566 ASSERT_VK_SUCCESS(err);
5567
5568 VkImageViewCreateInfo image_view_create_info = {};
5569 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5570 image_view_create_info.image = image;
5571 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5572 image_view_create_info.format = tex_format;
5573 image_view_create_info.subresourceRange.layerCount = 1;
5574 image_view_create_info.subresourceRange.baseMipLevel = 0;
5575 image_view_create_info.subresourceRange.levelCount = 1;
5576 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5577
5578 VkImageView view;
5579 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5580 ASSERT_VK_SUCCESS(err);
5581 // Create Samplers
5582 VkSamplerCreateInfo sampler_ci = {};
5583 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5584 sampler_ci.pNext = NULL;
5585 sampler_ci.magFilter = VK_FILTER_NEAREST;
5586 sampler_ci.minFilter = VK_FILTER_NEAREST;
5587 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5588 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5589 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5590 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5591 sampler_ci.mipLodBias = 1.0;
5592 sampler_ci.anisotropyEnable = VK_FALSE;
5593 sampler_ci.maxAnisotropy = 1;
5594 sampler_ci.compareEnable = VK_FALSE;
5595 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5596 sampler_ci.minLod = 1.0;
5597 sampler_ci.maxLod = 1.0;
5598 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5599 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5600 VkSampler sampler;
5601 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5602 ASSERT_VK_SUCCESS(err);
5603 // Update descriptor with image and sampler
5604 VkDescriptorImageInfo img_info = {};
5605 img_info.sampler = sampler;
5606 img_info.imageView = view;
5607 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5608
5609 VkWriteDescriptorSet descriptor_write;
5610 memset(&descriptor_write, 0, sizeof(descriptor_write));
5611 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5612 descriptor_write.dstSet = descriptorSet;
5613 descriptor_write.dstBinding = 0;
5614 descriptor_write.descriptorCount = 1;
5615 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5616 descriptor_write.pImageInfo = &img_info;
5617 // Break memory binding and attempt update
5618 vkFreeMemory(m_device->device(), image_memory, nullptr);
5619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005620 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5622 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5623 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5624 m_errorMonitor->VerifyFound();
5625 // Cleanup
5626 vkDestroyImage(m_device->device(), image, NULL);
5627 vkDestroySampler(m_device->device(), sampler, NULL);
5628 vkDestroyImageView(m_device->device(), view, NULL);
5629 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5630 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5631 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5632}
5633
Karl Schultz6addd812016-02-02 17:17:23 -07005634TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005635 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5636 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005637 // Create a valid cmd buffer
5638 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005639 uint64_t fake_pipeline_handle = 0xbaad6001;
5640 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005641 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005642 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5643
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Karl Schultzbdb75952016-04-19 11:36:49 -06005645 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005646 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005647 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005648
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005649 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005650 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 -06005651 Draw(1, 0, 0, 0);
5652 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005653
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005654 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005655 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 +12005656 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005657 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5658 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005659}
5660
Karl Schultz6addd812016-02-02 17:17:23 -07005661TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005662 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005663 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005664
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005666
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005667 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005668 ASSERT_NO_FATAL_FAILURE(InitViewport());
5669 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005670 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005671 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5672 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005673
5674 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005675 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5676 ds_pool_ci.pNext = NULL;
5677 ds_pool_ci.maxSets = 1;
5678 ds_pool_ci.poolSizeCount = 1;
5679 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005680
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005681 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005682 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005683 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005684
Tony Barboureb254902015-07-15 12:50:33 -06005685 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005686 dsl_binding.binding = 0;
5687 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5688 dsl_binding.descriptorCount = 1;
5689 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5690 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005691
Tony Barboureb254902015-07-15 12:50:33 -06005692 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005693 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5694 ds_layout_ci.pNext = NULL;
5695 ds_layout_ci.bindingCount = 1;
5696 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005697 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005698 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005699 ASSERT_VK_SUCCESS(err);
5700
5701 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005702 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005703 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005704 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005705 alloc_info.descriptorPool = ds_pool;
5706 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005707 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005708 ASSERT_VK_SUCCESS(err);
5709
Tony Barboureb254902015-07-15 12:50:33 -06005710 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005711 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5712 pipeline_layout_ci.pNext = NULL;
5713 pipeline_layout_ci.setLayoutCount = 1;
5714 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005715
5716 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005717 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005718 ASSERT_VK_SUCCESS(err);
5719
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005720 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005721 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005722 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005723 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005724
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005725 VkPipelineObj pipe(m_device);
5726 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005727 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005728 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005729 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005730
5731 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005732 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5733 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5734 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005735
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005736 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005737
Chia-I Wuf7458c52015-10-26 21:10:41 +08005738 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5739 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5740 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005741}
5742
Karl Schultz6addd812016-02-02 17:17:23 -07005743TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005744 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005745 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005746
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005748
5749 ASSERT_NO_FATAL_FAILURE(InitState());
5750 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005751 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5752 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005753
5754 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005755 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5756 ds_pool_ci.pNext = NULL;
5757 ds_pool_ci.maxSets = 1;
5758 ds_pool_ci.poolSizeCount = 1;
5759 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005760
5761 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005762 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005763 ASSERT_VK_SUCCESS(err);
5764
5765 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005766 dsl_binding.binding = 0;
5767 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5768 dsl_binding.descriptorCount = 1;
5769 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5770 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005771
5772 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005773 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5774 ds_layout_ci.pNext = NULL;
5775 ds_layout_ci.bindingCount = 1;
5776 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005777 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005779 ASSERT_VK_SUCCESS(err);
5780
5781 VkDescriptorSet descriptorSet;
5782 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005783 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005784 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005785 alloc_info.descriptorPool = ds_pool;
5786 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005787 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005788 ASSERT_VK_SUCCESS(err);
5789
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005790 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005791 VkWriteDescriptorSet descriptor_write;
5792 memset(&descriptor_write, 0, sizeof(descriptor_write));
5793 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5794 descriptor_write.dstSet = descriptorSet;
5795 descriptor_write.dstBinding = 0;
5796 descriptor_write.descriptorCount = 1;
5797 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5798 descriptor_write.pTexelBufferView = &view;
5799
5800 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5801
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005802 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005803
5804 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5805 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5806}
5807
Mark Youngd339ba32016-05-30 13:28:35 -06005808TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005809 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 -06005810
5811 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005813 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005814
5815 ASSERT_NO_FATAL_FAILURE(InitState());
5816
5817 // Create a buffer with no bound memory and then attempt to create
5818 // a buffer view.
5819 VkBufferCreateInfo buff_ci = {};
5820 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005821 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005822 buff_ci.size = 256;
5823 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5824 VkBuffer buffer;
5825 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5826 ASSERT_VK_SUCCESS(err);
5827
5828 VkBufferViewCreateInfo buff_view_ci = {};
5829 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5830 buff_view_ci.buffer = buffer;
5831 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5832 buff_view_ci.range = VK_WHOLE_SIZE;
5833 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005834 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005835
5836 m_errorMonitor->VerifyFound();
5837 vkDestroyBuffer(m_device->device(), buffer, NULL);
5838 // If last error is success, it still created the view, so delete it.
5839 if (err == VK_SUCCESS) {
5840 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5841 }
5842}
5843
Karl Schultz6addd812016-02-02 17:17:23 -07005844TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5845 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5846 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005847 // 1. No dynamicOffset supplied
5848 // 2. Too many dynamicOffsets supplied
5849 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005850 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5852 "0 dynamicOffsets are left in "
5853 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005854
5855 ASSERT_NO_FATAL_FAILURE(InitState());
5856 ASSERT_NO_FATAL_FAILURE(InitViewport());
5857 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5858
5859 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005860 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5861 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005862
5863 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005864 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5865 ds_pool_ci.pNext = NULL;
5866 ds_pool_ci.maxSets = 1;
5867 ds_pool_ci.poolSizeCount = 1;
5868 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005869
5870 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005871 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005872 ASSERT_VK_SUCCESS(err);
5873
5874 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005875 dsl_binding.binding = 0;
5876 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5877 dsl_binding.descriptorCount = 1;
5878 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5879 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005880
5881 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005882 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5883 ds_layout_ci.pNext = NULL;
5884 ds_layout_ci.bindingCount = 1;
5885 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005886 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005887 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005888 ASSERT_VK_SUCCESS(err);
5889
5890 VkDescriptorSet descriptorSet;
5891 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005892 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005893 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005894 alloc_info.descriptorPool = ds_pool;
5895 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005896 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005897 ASSERT_VK_SUCCESS(err);
5898
5899 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005900 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5901 pipeline_layout_ci.pNext = NULL;
5902 pipeline_layout_ci.setLayoutCount = 1;
5903 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005904
5905 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005906 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005907 ASSERT_VK_SUCCESS(err);
5908
5909 // Create a buffer to update the descriptor with
5910 uint32_t qfi = 0;
5911 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005912 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5913 buffCI.size = 1024;
5914 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5915 buffCI.queueFamilyIndexCount = 1;
5916 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005917
5918 VkBuffer dyub;
5919 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5920 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005921 // Allocate memory and bind to buffer so we can make it to the appropriate
5922 // error
5923 VkMemoryAllocateInfo mem_alloc = {};
5924 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5925 mem_alloc.pNext = NULL;
5926 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005927 mem_alloc.memoryTypeIndex = 0;
5928
5929 VkMemoryRequirements memReqs;
5930 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005931 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005932 if (!pass) {
5933 vkDestroyBuffer(m_device->device(), dyub, NULL);
5934 return;
5935 }
5936
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005937 VkDeviceMemory mem;
5938 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5939 ASSERT_VK_SUCCESS(err);
5940 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5941 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005942 // Correctly update descriptor to avoid "NOT_UPDATED" error
5943 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005944 buffInfo.buffer = dyub;
5945 buffInfo.offset = 0;
5946 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005947
5948 VkWriteDescriptorSet descriptor_write;
5949 memset(&descriptor_write, 0, sizeof(descriptor_write));
5950 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5951 descriptor_write.dstSet = descriptorSet;
5952 descriptor_write.dstBinding = 0;
5953 descriptor_write.descriptorCount = 1;
5954 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5955 descriptor_write.pBufferInfo = &buffInfo;
5956
5957 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5958
5959 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005960 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5961 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005962 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005963 uint32_t pDynOff[2] = {512, 756};
5964 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5966 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5967 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5968 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005969 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005970 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5972 "offset 0 and range 1024 that "
5973 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005974 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005975 char const *vsSource = "#version 450\n"
5976 "\n"
5977 "out gl_PerVertex { \n"
5978 " vec4 gl_Position;\n"
5979 "};\n"
5980 "void main(){\n"
5981 " gl_Position = vec4(1);\n"
5982 "}\n";
5983 char const *fsSource = "#version 450\n"
5984 "\n"
5985 "layout(location=0) out vec4 x;\n"
5986 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5987 "void main(){\n"
5988 " x = vec4(bar.y);\n"
5989 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005990 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5991 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5992 VkPipelineObj pipe(m_device);
5993 pipe.AddShader(&vs);
5994 pipe.AddShader(&fs);
5995 pipe.AddColorAttachment();
5996 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5997
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005998 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005999 // This update should succeed, but offset size of 512 will overstep buffer
6000 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006001 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6002 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006003 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006004 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006005
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006006 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006007 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006008
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006009 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006010 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006011 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6012}
6013
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006014TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6015 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6016 "that doesn't have memory bound");
6017 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006019 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6021 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006022
6023 ASSERT_NO_FATAL_FAILURE(InitState());
6024 ASSERT_NO_FATAL_FAILURE(InitViewport());
6025 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6026
6027 VkDescriptorPoolSize ds_type_count = {};
6028 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6029 ds_type_count.descriptorCount = 1;
6030
6031 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6032 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6033 ds_pool_ci.pNext = NULL;
6034 ds_pool_ci.maxSets = 1;
6035 ds_pool_ci.poolSizeCount = 1;
6036 ds_pool_ci.pPoolSizes = &ds_type_count;
6037
6038 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006039 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006040 ASSERT_VK_SUCCESS(err);
6041
6042 VkDescriptorSetLayoutBinding dsl_binding = {};
6043 dsl_binding.binding = 0;
6044 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6045 dsl_binding.descriptorCount = 1;
6046 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6047 dsl_binding.pImmutableSamplers = NULL;
6048
6049 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6050 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6051 ds_layout_ci.pNext = NULL;
6052 ds_layout_ci.bindingCount = 1;
6053 ds_layout_ci.pBindings = &dsl_binding;
6054 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006055 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006056 ASSERT_VK_SUCCESS(err);
6057
6058 VkDescriptorSet descriptorSet;
6059 VkDescriptorSetAllocateInfo alloc_info = {};
6060 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6061 alloc_info.descriptorSetCount = 1;
6062 alloc_info.descriptorPool = ds_pool;
6063 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006064 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006065 ASSERT_VK_SUCCESS(err);
6066
6067 // Create a buffer to update the descriptor with
6068 uint32_t qfi = 0;
6069 VkBufferCreateInfo buffCI = {};
6070 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6071 buffCI.size = 1024;
6072 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6073 buffCI.queueFamilyIndexCount = 1;
6074 buffCI.pQueueFamilyIndices = &qfi;
6075
6076 VkBuffer dyub;
6077 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6078 ASSERT_VK_SUCCESS(err);
6079
6080 // Attempt to update descriptor without binding memory to it
6081 VkDescriptorBufferInfo buffInfo = {};
6082 buffInfo.buffer = dyub;
6083 buffInfo.offset = 0;
6084 buffInfo.range = 1024;
6085
6086 VkWriteDescriptorSet descriptor_write;
6087 memset(&descriptor_write, 0, sizeof(descriptor_write));
6088 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6089 descriptor_write.dstSet = descriptorSet;
6090 descriptor_write.dstBinding = 0;
6091 descriptor_write.descriptorCount = 1;
6092 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6093 descriptor_write.pBufferInfo = &buffInfo;
6094
6095 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6096 m_errorMonitor->VerifyFound();
6097
6098 vkDestroyBuffer(m_device->device(), dyub, NULL);
6099 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6100 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6101}
6102
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006103TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006104 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006105 ASSERT_NO_FATAL_FAILURE(InitState());
6106 ASSERT_NO_FATAL_FAILURE(InitViewport());
6107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6108
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006109 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006110 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006111 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6112 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6113 pipeline_layout_ci.pushConstantRangeCount = 1;
6114 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6115
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006116 //
6117 // Check for invalid push constant ranges in pipeline layouts.
6118 //
6119 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006120 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006121 char const *msg;
6122 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006123
Karl Schultzc81037d2016-05-12 08:11:23 -06006124 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6125 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6126 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6127 "vkCreatePipelineLayout() call has push constants index 0 with "
6128 "size 0."},
6129 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6130 "vkCreatePipelineLayout() call has push constants index 0 with "
6131 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006132 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006133 "vkCreatePipelineLayout() call has push constants index 0 with "
6134 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006135 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006136 "vkCreatePipelineLayout() call has push constants index 0 with "
6137 "size 0."},
6138 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6139 "vkCreatePipelineLayout() call has push constants index 0 with "
6140 "offset 1. Offset must"},
6141 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6142 "vkCreatePipelineLayout() call has push constants index 0 "
6143 "with offset "},
6144 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6145 "vkCreatePipelineLayout() call has push constants "
6146 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006147 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006148 "vkCreatePipelineLayout() call has push constants index 0 "
6149 "with offset "},
6150 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6151 "vkCreatePipelineLayout() call has push "
6152 "constants index 0 with offset "},
6153 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6154 "vkCreatePipelineLayout() call has push "
6155 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006156 }};
6157
6158 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006159 for (const auto &iter : range_tests) {
6160 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6162 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006163 m_errorMonitor->VerifyFound();
6164 if (VK_SUCCESS == err) {
6165 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6166 }
6167 }
6168
6169 // Check for invalid stage flag
6170 pc_range.offset = 0;
6171 pc_range.size = 16;
6172 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006173 m_errorMonitor->SetDesiredFailureMsg(
6174 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6175 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006176 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006177 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006178 if (VK_SUCCESS == err) {
6179 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6180 }
6181
6182 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006183 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006184 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006185 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006186 char const *msg;
6187 };
6188
Karl Schultzc81037d2016-05-12 08:11:23 -06006189 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006190 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6191 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6192 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6193 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6194 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006195 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006196 {
6197 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6198 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6199 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6200 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6201 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006202 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006203 },
6204 {
6205 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6206 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6207 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6208 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6209 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006210 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006211 },
6212 {
6213 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6214 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6215 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6216 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6217 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006218 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006219 },
6220 {
6221 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6222 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6223 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6224 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6225 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006226 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006227 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006228
Karl Schultzc81037d2016-05-12 08:11:23 -06006229 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006230 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006231 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6233 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006234 m_errorMonitor->VerifyFound();
6235 if (VK_SUCCESS == err) {
6236 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6237 }
6238 }
6239
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006240 //
6241 // CmdPushConstants tests
6242 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006243 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006244
6245 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006246 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6247 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006248 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6249 "vkCmdPushConstants() call has push constants with size 1. Size "
6250 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006251 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006252 "vkCmdPushConstants() call has push constants with size 1. Size "
6253 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006254 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006255 "vkCmdPushConstants() call has push constants with offset 1. "
6256 "Offset must be a multiple of 4."},
6257 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6258 "vkCmdPushConstants() call has push constants with offset 1. "
6259 "Offset must be a multiple of 4."},
6260 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6261 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6262 "0x1 not within flag-matching ranges in pipeline layout"},
6263 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6264 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6265 "0x1 not within flag-matching ranges in pipeline layout"},
6266 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6267 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6268 "0x1 not within flag-matching ranges in pipeline layout"},
6269 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6270 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6271 "0x1 not within flag-matching ranges in pipeline layout"},
6272 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6273 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6274 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006275 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006276 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6277 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006278 }};
6279
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006280 BeginCommandBuffer();
6281
6282 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006283 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006284 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006285 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006286 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006287 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006288 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006289 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006290 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6292 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006293 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006294 m_errorMonitor->VerifyFound();
6295 }
6296
6297 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006299 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006300 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006301 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006302
Karl Schultzc81037d2016-05-12 08:11:23 -06006303 // overlapping range tests with cmd
6304 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6305 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6306 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6307 "0x1 not within flag-matching ranges in pipeline layout"},
6308 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6309 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6310 "0x1 not within flag-matching ranges in pipeline layout"},
6311 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6312 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6313 "0x1 not within flag-matching ranges in pipeline layout"},
6314 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006315 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006316 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006317 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6318 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006319 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006320 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006321 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006322 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006323 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006324 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6326 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006327 iter.range.size, dummy_values);
6328 m_errorMonitor->VerifyFound();
6329 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006330 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6331
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006332 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006333}
6334
Karl Schultz6addd812016-02-02 17:17:23 -07006335TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006336 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006337 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006338
6339 ASSERT_NO_FATAL_FAILURE(InitState());
6340 ASSERT_NO_FATAL_FAILURE(InitViewport());
6341 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6342
Mike Stroyanb8a61002016-06-20 16:00:28 -06006343 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6344 VkImageTiling tiling;
6345 VkFormatProperties format_properties;
6346 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006347 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006348 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006349 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006350 tiling = VK_IMAGE_TILING_OPTIMAL;
6351 } else {
6352 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6353 "skipped.\n");
6354 return;
6355 }
6356
Tobin Ehlis559c6382015-11-05 09:52:49 -07006357 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6358 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006359 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6360 ds_type_count[0].descriptorCount = 10;
6361 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6362 ds_type_count[1].descriptorCount = 2;
6363 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6364 ds_type_count[2].descriptorCount = 2;
6365 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6366 ds_type_count[3].descriptorCount = 5;
6367 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6368 // type
6369 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6370 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6371 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006372
6373 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006374 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6375 ds_pool_ci.pNext = NULL;
6376 ds_pool_ci.maxSets = 5;
6377 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6378 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006379
6380 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006381 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006382 ASSERT_VK_SUCCESS(err);
6383
6384 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6385 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006386 dsl_binding[0].binding = 0;
6387 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6388 dsl_binding[0].descriptorCount = 5;
6389 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6390 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006391
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006392 // Create layout identical to set0 layout but w/ different stageFlags
6393 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006394 dsl_fs_stage_only.binding = 0;
6395 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6396 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006397 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6398 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006399 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006400 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006401 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6402 ds_layout_ci.pNext = NULL;
6403 ds_layout_ci.bindingCount = 1;
6404 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006405 static const uint32_t NUM_LAYOUTS = 4;
6406 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006407 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006408 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6409 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006410 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006411 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006412 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006413 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006414 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006415 dsl_binding[0].binding = 0;
6416 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006417 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006418 dsl_binding[1].binding = 1;
6419 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6420 dsl_binding[1].descriptorCount = 2;
6421 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6422 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006423 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006424 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006425 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006426 ASSERT_VK_SUCCESS(err);
6427 dsl_binding[0].binding = 0;
6428 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006429 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006430 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006431 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006432 ASSERT_VK_SUCCESS(err);
6433 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006434 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006435 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006436 ASSERT_VK_SUCCESS(err);
6437
6438 static const uint32_t NUM_SETS = 4;
6439 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6440 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006441 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006442 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006443 alloc_info.descriptorPool = ds_pool;
6444 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006445 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006446 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006447 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006448 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006449 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006450 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006451 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006452
6453 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006454 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6455 pipeline_layout_ci.pNext = NULL;
6456 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6457 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006458
6459 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006460 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006461 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006462 // Create pipelineLayout with only one setLayout
6463 pipeline_layout_ci.setLayoutCount = 1;
6464 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006465 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006466 ASSERT_VK_SUCCESS(err);
6467 // Create pipelineLayout with 2 descriptor setLayout at index 0
6468 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6469 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006470 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006471 ASSERT_VK_SUCCESS(err);
6472 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6473 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6474 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006475 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006476 ASSERT_VK_SUCCESS(err);
6477 // Create pipelineLayout with UB type, but stageFlags for FS only
6478 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6479 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006480 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006481 ASSERT_VK_SUCCESS(err);
6482 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6483 VkDescriptorSetLayout pl_bad_s0[2] = {};
6484 pl_bad_s0[0] = ds_layout_fs_only;
6485 pl_bad_s0[1] = ds_layout[1];
6486 pipeline_layout_ci.setLayoutCount = 2;
6487 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6488 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006489 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006490 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006491
6492 // Create a buffer to update the descriptor with
6493 uint32_t qfi = 0;
6494 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006495 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6496 buffCI.size = 1024;
6497 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6498 buffCI.queueFamilyIndexCount = 1;
6499 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006500
6501 VkBuffer dyub;
6502 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6503 ASSERT_VK_SUCCESS(err);
6504 // Correctly update descriptor to avoid "NOT_UPDATED" error
6505 static const uint32_t NUM_BUFFS = 5;
6506 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006507 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006508 buffInfo[i].buffer = dyub;
6509 buffInfo[i].offset = 0;
6510 buffInfo[i].range = 1024;
6511 }
Karl Schultz6addd812016-02-02 17:17:23 -07006512 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006513 const int32_t tex_width = 32;
6514 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006515 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006516 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6517 image_create_info.pNext = NULL;
6518 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6519 image_create_info.format = tex_format;
6520 image_create_info.extent.width = tex_width;
6521 image_create_info.extent.height = tex_height;
6522 image_create_info.extent.depth = 1;
6523 image_create_info.mipLevels = 1;
6524 image_create_info.arrayLayers = 1;
6525 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006526 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006527 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006528 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006529 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6530 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006531
Karl Schultz6addd812016-02-02 17:17:23 -07006532 VkMemoryRequirements memReqs;
6533 VkDeviceMemory imageMem;
6534 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006535 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006536 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6537 memAlloc.pNext = NULL;
6538 memAlloc.allocationSize = 0;
6539 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006540 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6541 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006542 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006543 ASSERT_TRUE(pass);
6544 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6545 ASSERT_VK_SUCCESS(err);
6546 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6547 ASSERT_VK_SUCCESS(err);
6548
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006549 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006550 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6551 image_view_create_info.image = image;
6552 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6553 image_view_create_info.format = tex_format;
6554 image_view_create_info.subresourceRange.layerCount = 1;
6555 image_view_create_info.subresourceRange.baseMipLevel = 0;
6556 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006557 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006558
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006559 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006560 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006561 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006562 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006563 imageInfo[0].imageView = view;
6564 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6565 imageInfo[1].imageView = view;
6566 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006567 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006568 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006569 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006570 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006571
6572 static const uint32_t NUM_SET_UPDATES = 3;
6573 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6574 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6575 descriptor_write[0].dstSet = descriptorSet[0];
6576 descriptor_write[0].dstBinding = 0;
6577 descriptor_write[0].descriptorCount = 5;
6578 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6579 descriptor_write[0].pBufferInfo = buffInfo;
6580 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6581 descriptor_write[1].dstSet = descriptorSet[1];
6582 descriptor_write[1].dstBinding = 0;
6583 descriptor_write[1].descriptorCount = 2;
6584 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6585 descriptor_write[1].pImageInfo = imageInfo;
6586 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6587 descriptor_write[2].dstSet = descriptorSet[1];
6588 descriptor_write[2].dstBinding = 1;
6589 descriptor_write[2].descriptorCount = 2;
6590 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006591 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006592
6593 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006594
Tobin Ehlis88452832015-12-03 09:40:56 -07006595 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006596 char const *vsSource = "#version 450\n"
6597 "\n"
6598 "out gl_PerVertex {\n"
6599 " vec4 gl_Position;\n"
6600 "};\n"
6601 "void main(){\n"
6602 " gl_Position = vec4(1);\n"
6603 "}\n";
6604 char const *fsSource = "#version 450\n"
6605 "\n"
6606 "layout(location=0) out vec4 x;\n"
6607 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6608 "void main(){\n"
6609 " x = vec4(bar.y);\n"
6610 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006611 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6612 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006613 VkPipelineObj pipe(m_device);
6614 pipe.AddShader(&vs);
6615 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006616 pipe.AddColorAttachment();
6617 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006618
6619 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006620
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006621 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006622 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6623 // of PSO
6624 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6625 // cmd_pipeline.c
6626 // due to the fact that cmd_alloc_dset_data() has not been called in
6627 // cmd_bind_graphics_pipeline()
6628 // TODO : Want to cause various binding incompatibility issues here to test
6629 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006630 // First cause various verify_layout_compatibility() fails
6631 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006632 // verify_set_layout_compatibility fail cases:
6633 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006635 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6636 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006637 m_errorMonitor->VerifyFound();
6638
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006639 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6641 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6642 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006643 m_errorMonitor->VerifyFound();
6644
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006645 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006646 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6647 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6649 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6650 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006651 m_errorMonitor->VerifyFound();
6652
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006653 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6654 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6656 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6657 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006658 m_errorMonitor->VerifyFound();
6659
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006660 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6661 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6663 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6664 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6665 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006666 m_errorMonitor->VerifyFound();
6667
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006668 // Cause INFO messages due to disturbing previously bound Sets
6669 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006670 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6671 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006672 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6674 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6675 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006676 m_errorMonitor->VerifyFound();
6677
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006678 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6679 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006680 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6682 "any subsequent sets were disturbed ");
6683 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6684 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006685 m_errorMonitor->VerifyFound();
6686
Tobin Ehlis10fad692016-07-07 12:00:36 -06006687 // Now that we're done actively using the pipelineLayout that gfx pipeline
6688 // was created with, we should be able to delete it. Do that now to verify
6689 // that validation obeys pipelineLayout lifetime
6690 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6691
Tobin Ehlis88452832015-12-03 09:40:56 -07006692 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006693 // 1. Error due to not binding required set (we actually use same code as
6694 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006695 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6696 &descriptorSet[0], 0, NULL);
6697 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6698 &descriptorSet[1], 0, NULL);
6699 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 -07006700 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006701 m_errorMonitor->VerifyFound();
6702
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006703 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006704 // 2. Error due to bound set not being compatible with PSO's
6705 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006706 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6707 &descriptorSet[0], 0, NULL);
6708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006709 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006710 m_errorMonitor->VerifyFound();
6711
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006712 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006713 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006714 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6715 }
6716 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006717 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006718 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6719 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006720 vkFreeMemory(m_device->device(), imageMem, NULL);
6721 vkDestroyImage(m_device->device(), image, NULL);
6722 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006723}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006724
Karl Schultz6addd812016-02-02 17:17:23 -07006725TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006726
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6728 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006729
6730 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006731 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006732 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006733 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006734
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006735 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006736}
6737
Karl Schultz6addd812016-02-02 17:17:23 -07006738TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6739 VkResult err;
6740 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006741
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006743
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006744 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006745
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006746 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006747 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006748 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006749 cmd.commandPool = m_commandPool;
6750 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006751 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006752
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006753 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006754 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006755
6756 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006757 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006758 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006759 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006760 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006761 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 -07006762 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006763
6764 // The error should be caught by validation of the BeginCommandBuffer call
6765 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6766
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006767 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006768 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006769}
6770
Karl Schultz6addd812016-02-02 17:17:23 -07006771TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006772 // Cause error due to Begin while recording CB
6773 // Then cause 2 errors for attempting to reset CB w/o having
6774 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6775 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006777
6778 ASSERT_NO_FATAL_FAILURE(InitState());
6779
6780 // Calls AllocateCommandBuffers
6781 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6782
Karl Schultz6addd812016-02-02 17:17:23 -07006783 // Force the failure by setting the Renderpass and Framebuffer fields with
6784 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006785 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006786 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006787 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6788 cmd_buf_info.pNext = NULL;
6789 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006790 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006791
6792 // Begin CB to transition to recording state
6793 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6794 // Can't re-begin. This should trigger error
6795 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006796 m_errorMonitor->VerifyFound();
6797
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006799 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6800 // Reset attempt will trigger error due to incorrect CommandPool state
6801 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006802 m_errorMonitor->VerifyFound();
6803
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006805 // Transition CB to RECORDED state
6806 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6807 // Now attempting to Begin will implicitly reset, which triggers error
6808 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006809 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006810}
6811
Karl Schultz6addd812016-02-02 17:17:23 -07006812TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006813 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006814 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006815
Mike Weiblencce7ec72016-10-17 19:33:05 -06006816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006817
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006818 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006820
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006821 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006822 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6823 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006824
6825 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006826 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6827 ds_pool_ci.pNext = NULL;
6828 ds_pool_ci.maxSets = 1;
6829 ds_pool_ci.poolSizeCount = 1;
6830 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006831
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006832 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006833 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006834 ASSERT_VK_SUCCESS(err);
6835
Tony Barboureb254902015-07-15 12:50:33 -06006836 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006837 dsl_binding.binding = 0;
6838 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6839 dsl_binding.descriptorCount = 1;
6840 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6841 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006842
Tony Barboureb254902015-07-15 12:50:33 -06006843 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006844 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6845 ds_layout_ci.pNext = NULL;
6846 ds_layout_ci.bindingCount = 1;
6847 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006848
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006849 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006850 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006851 ASSERT_VK_SUCCESS(err);
6852
6853 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006854 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006855 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006856 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006857 alloc_info.descriptorPool = ds_pool;
6858 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006859 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006860 ASSERT_VK_SUCCESS(err);
6861
Tony Barboureb254902015-07-15 12:50:33 -06006862 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006863 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6864 pipeline_layout_ci.setLayoutCount = 1;
6865 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006866
6867 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006868 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006869 ASSERT_VK_SUCCESS(err);
6870
Tobin Ehlise68360f2015-10-01 11:15:13 -06006871 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006872 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006873
6874 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006875 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6876 vp_state_ci.scissorCount = 1;
6877 vp_state_ci.pScissors = &sc;
6878 vp_state_ci.viewportCount = 1;
6879 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006880
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006881 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6882 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6883 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6884 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6885 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6886 rs_state_ci.depthClampEnable = VK_FALSE;
6887 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6888 rs_state_ci.depthBiasEnable = VK_FALSE;
6889
Tony Barboureb254902015-07-15 12:50:33 -06006890 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006891 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6892 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006893 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006894 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6895 gp_ci.layout = pipeline_layout;
6896 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006897
6898 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006899 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6900 pc_ci.initialDataSize = 0;
6901 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006902
6903 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006904 VkPipelineCache pipelineCache;
6905
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006906 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006907 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006908 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006909
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006910 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006911
Chia-I Wuf7458c52015-10-26 21:10:41 +08006912 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6913 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6914 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6915 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006916}
Tobin Ehlis912df022015-09-17 08:46:18 -06006917/*// TODO : This test should be good, but needs Tess support in compiler to run
6918TEST_F(VkLayerTest, InvalidPatchControlPoints)
6919{
6920 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006921 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006922
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006924 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6925primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006926
Tobin Ehlis912df022015-09-17 08:46:18 -06006927 ASSERT_NO_FATAL_FAILURE(InitState());
6928 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006929
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006930 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006931 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006932 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006933
6934 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6935 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6936 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006937 ds_pool_ci.poolSizeCount = 1;
6938 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006939
6940 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006941 err = vkCreateDescriptorPool(m_device->device(),
6942VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006943 ASSERT_VK_SUCCESS(err);
6944
6945 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006946 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006947 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006948 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006949 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6950 dsl_binding.pImmutableSamplers = NULL;
6951
6952 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006953 ds_layout_ci.sType =
6954VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006955 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006956 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006957 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006958
6959 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006960 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6961&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006962 ASSERT_VK_SUCCESS(err);
6963
6964 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006965 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6966VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006967 ASSERT_VK_SUCCESS(err);
6968
6969 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006970 pipeline_layout_ci.sType =
6971VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006972 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006973 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006974 pipeline_layout_ci.pSetLayouts = &ds_layout;
6975
6976 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006977 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6978&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006979 ASSERT_VK_SUCCESS(err);
6980
6981 VkPipelineShaderStageCreateInfo shaderStages[3];
6982 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6983
Karl Schultz6addd812016-02-02 17:17:23 -07006984 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6985this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006986 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006987 VkShaderObj
6988tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6989this);
6990 VkShaderObj
6991te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6992this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006993
Karl Schultz6addd812016-02-02 17:17:23 -07006994 shaderStages[0].sType =
6995VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006996 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006997 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006998 shaderStages[1].sType =
6999VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007000 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007001 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007002 shaderStages[2].sType =
7003VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007004 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007005 shaderStages[2].shader = te.handle();
7006
7007 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007008 iaCI.sType =
7009VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007010 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007011
7012 VkPipelineTessellationStateCreateInfo tsCI = {};
7013 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7014 tsCI.patchControlPoints = 0; // This will cause an error
7015
7016 VkGraphicsPipelineCreateInfo gp_ci = {};
7017 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7018 gp_ci.pNext = NULL;
7019 gp_ci.stageCount = 3;
7020 gp_ci.pStages = shaderStages;
7021 gp_ci.pVertexInputState = NULL;
7022 gp_ci.pInputAssemblyState = &iaCI;
7023 gp_ci.pTessellationState = &tsCI;
7024 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007025 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007026 gp_ci.pMultisampleState = NULL;
7027 gp_ci.pDepthStencilState = NULL;
7028 gp_ci.pColorBlendState = NULL;
7029 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7030 gp_ci.layout = pipeline_layout;
7031 gp_ci.renderPass = renderPass();
7032
7033 VkPipelineCacheCreateInfo pc_ci = {};
7034 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7035 pc_ci.pNext = NULL;
7036 pc_ci.initialSize = 0;
7037 pc_ci.initialData = 0;
7038 pc_ci.maxSize = 0;
7039
7040 VkPipeline pipeline;
7041 VkPipelineCache pipelineCache;
7042
Karl Schultz6addd812016-02-02 17:17:23 -07007043 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7044&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007045 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007046 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7047&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007048
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007049 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007050
Chia-I Wuf7458c52015-10-26 21:10:41 +08007051 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7052 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7053 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7054 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007055}
7056*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06007057// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07007058TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007059 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007060
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7062 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007063
Tobin Ehlise68360f2015-10-01 11:15:13 -06007064 ASSERT_NO_FATAL_FAILURE(InitState());
7065 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007066
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007067 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007068 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7069 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007070
7071 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007072 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7073 ds_pool_ci.maxSets = 1;
7074 ds_pool_ci.poolSizeCount = 1;
7075 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007076
7077 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007078 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007079 ASSERT_VK_SUCCESS(err);
7080
7081 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007082 dsl_binding.binding = 0;
7083 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7084 dsl_binding.descriptorCount = 1;
7085 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007086
7087 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007088 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7089 ds_layout_ci.bindingCount = 1;
7090 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007091
7092 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007093 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007094 ASSERT_VK_SUCCESS(err);
7095
7096 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007097 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007098 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007099 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007100 alloc_info.descriptorPool = ds_pool;
7101 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007102 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007103 ASSERT_VK_SUCCESS(err);
7104
7105 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007106 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7107 pipeline_layout_ci.setLayoutCount = 1;
7108 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007109
7110 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007111 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007112 ASSERT_VK_SUCCESS(err);
7113
7114 VkViewport vp = {}; // Just need dummy vp to point to
7115
7116 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007117 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7118 vp_state_ci.scissorCount = 0;
7119 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7120 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007121
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007122 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7123 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7124 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7125 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7126 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7127 rs_state_ci.depthClampEnable = VK_FALSE;
7128 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7129 rs_state_ci.depthBiasEnable = VK_FALSE;
7130
Cody Northropeb3a6c12015-10-05 14:44:45 -06007131 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007132 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007133
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007134 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7135 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7136 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007137 shaderStages[0] = vs.GetStageCreateInfo();
7138 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007139
7140 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007141 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7142 gp_ci.stageCount = 2;
7143 gp_ci.pStages = shaderStages;
7144 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007145 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007146 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7147 gp_ci.layout = pipeline_layout;
7148 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007149
7150 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007151 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007152
7153 VkPipeline pipeline;
7154 VkPipelineCache pipelineCache;
7155
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007156 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007157 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007158 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007159
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007160 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007161
Chia-I Wuf7458c52015-10-26 21:10:41 +08007162 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7163 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7164 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7165 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007166}
Karl Schultz6addd812016-02-02 17:17:23 -07007167// Don't set viewport state in PSO. This is an error b/c we always need this
7168// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007169// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007170TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007171 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007172 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007173
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007175
Tobin Ehlise68360f2015-10-01 11:15:13 -06007176 ASSERT_NO_FATAL_FAILURE(InitState());
7177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007178
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007179 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007180 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7181 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007182
7183 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007184 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7185 ds_pool_ci.maxSets = 1;
7186 ds_pool_ci.poolSizeCount = 1;
7187 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007188
7189 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007190 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007191 ASSERT_VK_SUCCESS(err);
7192
7193 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007194 dsl_binding.binding = 0;
7195 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7196 dsl_binding.descriptorCount = 1;
7197 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007198
7199 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007200 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7201 ds_layout_ci.bindingCount = 1;
7202 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007203
7204 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007205 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007206 ASSERT_VK_SUCCESS(err);
7207
7208 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007209 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007210 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007211 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007212 alloc_info.descriptorPool = ds_pool;
7213 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007214 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007215 ASSERT_VK_SUCCESS(err);
7216
7217 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007218 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7219 pipeline_layout_ci.setLayoutCount = 1;
7220 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007221
7222 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007223 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007224 ASSERT_VK_SUCCESS(err);
7225
7226 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7227 // Set scissor as dynamic to avoid second error
7228 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007229 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7230 dyn_state_ci.dynamicStateCount = 1;
7231 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007232
Cody Northropeb3a6c12015-10-05 14:44:45 -06007233 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007234 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007235
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007236 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7237 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7238 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007239 shaderStages[0] = vs.GetStageCreateInfo();
7240 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007241
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007242 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7243 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7244 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7245 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7246 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7247 rs_state_ci.depthClampEnable = VK_FALSE;
7248 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7249 rs_state_ci.depthBiasEnable = VK_FALSE;
7250
Tobin Ehlise68360f2015-10-01 11:15:13 -06007251 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007252 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7253 gp_ci.stageCount = 2;
7254 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007255 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007256 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7257 // should cause validation error
7258 gp_ci.pDynamicState = &dyn_state_ci;
7259 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7260 gp_ci.layout = pipeline_layout;
7261 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007262
7263 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007264 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007265
7266 VkPipeline pipeline;
7267 VkPipelineCache pipelineCache;
7268
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007269 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007270 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007271 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007272
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007273 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007274
Chia-I Wuf7458c52015-10-26 21:10:41 +08007275 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7276 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7277 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7278 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007279}
7280// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007281// Then run second test where dynamic scissor count doesn't match PSO scissor
7282// count
7283TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7284 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007285
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7287 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007288
Tobin Ehlise68360f2015-10-01 11:15:13 -06007289 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007290
7291 if (!m_device->phy().features().multiViewport) {
7292 printf("Device does not support multiple viewports/scissors; skipped.\n");
7293 return;
7294 }
7295
Tobin Ehlise68360f2015-10-01 11:15:13 -06007296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007297
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007298 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007299 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7300 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007301
7302 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007303 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7304 ds_pool_ci.maxSets = 1;
7305 ds_pool_ci.poolSizeCount = 1;
7306 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007307
7308 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007309 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007310 ASSERT_VK_SUCCESS(err);
7311
7312 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007313 dsl_binding.binding = 0;
7314 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7315 dsl_binding.descriptorCount = 1;
7316 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007317
7318 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007319 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7320 ds_layout_ci.bindingCount = 1;
7321 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007322
7323 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007324 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007325 ASSERT_VK_SUCCESS(err);
7326
7327 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007328 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007329 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007330 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007331 alloc_info.descriptorPool = ds_pool;
7332 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007333 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007334 ASSERT_VK_SUCCESS(err);
7335
7336 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007337 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7338 pipeline_layout_ci.setLayoutCount = 1;
7339 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007340
7341 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007342 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007343 ASSERT_VK_SUCCESS(err);
7344
7345 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007346 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7347 vp_state_ci.viewportCount = 1;
7348 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7349 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007350 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007351
7352 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7353 // Set scissor as dynamic to avoid that error
7354 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007355 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7356 dyn_state_ci.dynamicStateCount = 1;
7357 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007358
Cody Northropeb3a6c12015-10-05 14:44:45 -06007359 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007360 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007361
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007362 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7363 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7364 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007365 shaderStages[0] = vs.GetStageCreateInfo();
7366 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007367
Cody Northropf6622dc2015-10-06 10:33:21 -06007368 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7369 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7370 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007371 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007372 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007373 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007374 vi_ci.pVertexAttributeDescriptions = nullptr;
7375
7376 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7377 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7378 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7379
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007380 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007381 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007382 rs_ci.pNext = nullptr;
7383
Mark Youngc89c6312016-03-31 16:03:20 -06007384 VkPipelineColorBlendAttachmentState att = {};
7385 att.blendEnable = VK_FALSE;
7386 att.colorWriteMask = 0xf;
7387
Cody Northropf6622dc2015-10-06 10:33:21 -06007388 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7389 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7390 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007391 cb_ci.attachmentCount = 1;
7392 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007393
Tobin Ehlise68360f2015-10-01 11:15:13 -06007394 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007395 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7396 gp_ci.stageCount = 2;
7397 gp_ci.pStages = shaderStages;
7398 gp_ci.pVertexInputState = &vi_ci;
7399 gp_ci.pInputAssemblyState = &ia_ci;
7400 gp_ci.pViewportState = &vp_state_ci;
7401 gp_ci.pRasterizationState = &rs_ci;
7402 gp_ci.pColorBlendState = &cb_ci;
7403 gp_ci.pDynamicState = &dyn_state_ci;
7404 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7405 gp_ci.layout = pipeline_layout;
7406 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007407
7408 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007409 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007410
7411 VkPipeline pipeline;
7412 VkPipelineCache pipelineCache;
7413
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007414 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007415 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007416 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007417
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007418 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007419
Tobin Ehlisd332f282015-10-02 11:00:56 -06007420 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007421 // First need to successfully create the PSO from above by setting
7422 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007423 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 -07007424
7425 VkViewport vp = {}; // Just need dummy vp to point to
7426 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007427 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007428 ASSERT_VK_SUCCESS(err);
7429 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007430 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007431 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007432 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007433 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007434 Draw(1, 0, 0, 0);
7435
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007436 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007437
7438 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7439 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7440 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7441 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007442 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007443}
7444// Create PSO w/o non-zero scissorCount but no scissor data
7445// Then run second test where dynamic viewportCount doesn't match PSO
7446// viewportCount
7447TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7448 VkResult err;
7449
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007450 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 -07007451
7452 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007453
7454 if (!m_device->phy().features().multiViewport) {
7455 printf("Device does not support multiple viewports/scissors; skipped.\n");
7456 return;
7457 }
7458
Karl Schultz6addd812016-02-02 17:17:23 -07007459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7460
7461 VkDescriptorPoolSize ds_type_count = {};
7462 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7463 ds_type_count.descriptorCount = 1;
7464
7465 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7466 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7467 ds_pool_ci.maxSets = 1;
7468 ds_pool_ci.poolSizeCount = 1;
7469 ds_pool_ci.pPoolSizes = &ds_type_count;
7470
7471 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007472 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007473 ASSERT_VK_SUCCESS(err);
7474
7475 VkDescriptorSetLayoutBinding dsl_binding = {};
7476 dsl_binding.binding = 0;
7477 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7478 dsl_binding.descriptorCount = 1;
7479 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7480
7481 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7482 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7483 ds_layout_ci.bindingCount = 1;
7484 ds_layout_ci.pBindings = &dsl_binding;
7485
7486 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007487 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007488 ASSERT_VK_SUCCESS(err);
7489
7490 VkDescriptorSet descriptorSet;
7491 VkDescriptorSetAllocateInfo alloc_info = {};
7492 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7493 alloc_info.descriptorSetCount = 1;
7494 alloc_info.descriptorPool = ds_pool;
7495 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007496 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007497 ASSERT_VK_SUCCESS(err);
7498
7499 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7500 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7501 pipeline_layout_ci.setLayoutCount = 1;
7502 pipeline_layout_ci.pSetLayouts = &ds_layout;
7503
7504 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007505 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007506 ASSERT_VK_SUCCESS(err);
7507
7508 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7509 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7510 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007511 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007512 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007513 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007514
7515 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7516 // Set scissor as dynamic to avoid that error
7517 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7518 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7519 dyn_state_ci.dynamicStateCount = 1;
7520 dyn_state_ci.pDynamicStates = &vp_state;
7521
7522 VkPipelineShaderStageCreateInfo shaderStages[2];
7523 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7524
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007525 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7526 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7527 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007528 shaderStages[0] = vs.GetStageCreateInfo();
7529 shaderStages[1] = fs.GetStageCreateInfo();
7530
7531 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7532 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7533 vi_ci.pNext = nullptr;
7534 vi_ci.vertexBindingDescriptionCount = 0;
7535 vi_ci.pVertexBindingDescriptions = nullptr;
7536 vi_ci.vertexAttributeDescriptionCount = 0;
7537 vi_ci.pVertexAttributeDescriptions = nullptr;
7538
7539 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7540 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7541 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7542
7543 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7544 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7545 rs_ci.pNext = nullptr;
7546
Mark Youngc89c6312016-03-31 16:03:20 -06007547 VkPipelineColorBlendAttachmentState att = {};
7548 att.blendEnable = VK_FALSE;
7549 att.colorWriteMask = 0xf;
7550
Karl Schultz6addd812016-02-02 17:17:23 -07007551 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7552 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7553 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007554 cb_ci.attachmentCount = 1;
7555 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007556
7557 VkGraphicsPipelineCreateInfo gp_ci = {};
7558 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7559 gp_ci.stageCount = 2;
7560 gp_ci.pStages = shaderStages;
7561 gp_ci.pVertexInputState = &vi_ci;
7562 gp_ci.pInputAssemblyState = &ia_ci;
7563 gp_ci.pViewportState = &vp_state_ci;
7564 gp_ci.pRasterizationState = &rs_ci;
7565 gp_ci.pColorBlendState = &cb_ci;
7566 gp_ci.pDynamicState = &dyn_state_ci;
7567 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7568 gp_ci.layout = pipeline_layout;
7569 gp_ci.renderPass = renderPass();
7570
7571 VkPipelineCacheCreateInfo pc_ci = {};
7572 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7573
7574 VkPipeline pipeline;
7575 VkPipelineCache pipelineCache;
7576
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007577 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007578 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007579 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007580
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007581 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007582
7583 // Now hit second fail case where we set scissor w/ different count than PSO
7584 // First need to successfully create the PSO from above by setting
7585 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007586 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 -06007587
Tobin Ehlisd332f282015-10-02 11:00:56 -06007588 VkRect2D sc = {}; // Just need dummy vp to point to
7589 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007590 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007591 ASSERT_VK_SUCCESS(err);
7592 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007593 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007594 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007595 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007596 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007597 Draw(1, 0, 0, 0);
7598
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007599 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007600
Chia-I Wuf7458c52015-10-26 21:10:41 +08007601 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7602 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7603 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7604 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007605 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007606}
7607
Mark Young7394fdd2016-03-31 14:56:43 -06007608TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7609 VkResult err;
7610
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007612
7613 ASSERT_NO_FATAL_FAILURE(InitState());
7614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7615
7616 VkDescriptorPoolSize ds_type_count = {};
7617 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7618 ds_type_count.descriptorCount = 1;
7619
7620 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7621 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7622 ds_pool_ci.maxSets = 1;
7623 ds_pool_ci.poolSizeCount = 1;
7624 ds_pool_ci.pPoolSizes = &ds_type_count;
7625
7626 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007627 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007628 ASSERT_VK_SUCCESS(err);
7629
7630 VkDescriptorSetLayoutBinding dsl_binding = {};
7631 dsl_binding.binding = 0;
7632 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7633 dsl_binding.descriptorCount = 1;
7634 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7635
7636 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7637 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7638 ds_layout_ci.bindingCount = 1;
7639 ds_layout_ci.pBindings = &dsl_binding;
7640
7641 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007642 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007643 ASSERT_VK_SUCCESS(err);
7644
7645 VkDescriptorSet descriptorSet;
7646 VkDescriptorSetAllocateInfo alloc_info = {};
7647 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7648 alloc_info.descriptorSetCount = 1;
7649 alloc_info.descriptorPool = ds_pool;
7650 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007651 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007652 ASSERT_VK_SUCCESS(err);
7653
7654 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7655 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7656 pipeline_layout_ci.setLayoutCount = 1;
7657 pipeline_layout_ci.pSetLayouts = &ds_layout;
7658
7659 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007660 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007661 ASSERT_VK_SUCCESS(err);
7662
7663 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7664 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7665 vp_state_ci.scissorCount = 1;
7666 vp_state_ci.pScissors = NULL;
7667 vp_state_ci.viewportCount = 1;
7668 vp_state_ci.pViewports = NULL;
7669
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007670 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007671 // Set scissor as dynamic to avoid that error
7672 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7673 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7674 dyn_state_ci.dynamicStateCount = 2;
7675 dyn_state_ci.pDynamicStates = dynamic_states;
7676
7677 VkPipelineShaderStageCreateInfo shaderStages[2];
7678 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7679
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007680 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7681 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007682 this); // TODO - We shouldn't need a fragment shader
7683 // but add it to be able to run on more devices
7684 shaderStages[0] = vs.GetStageCreateInfo();
7685 shaderStages[1] = fs.GetStageCreateInfo();
7686
7687 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7688 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7689 vi_ci.pNext = nullptr;
7690 vi_ci.vertexBindingDescriptionCount = 0;
7691 vi_ci.pVertexBindingDescriptions = nullptr;
7692 vi_ci.vertexAttributeDescriptionCount = 0;
7693 vi_ci.pVertexAttributeDescriptions = nullptr;
7694
7695 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7696 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7697 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7698
7699 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7700 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7701 rs_ci.pNext = nullptr;
7702
Mark Young47107952016-05-02 15:59:55 -06007703 // Check too low (line width of -1.0f).
7704 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007705
7706 VkPipelineColorBlendAttachmentState att = {};
7707 att.blendEnable = VK_FALSE;
7708 att.colorWriteMask = 0xf;
7709
7710 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7711 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7712 cb_ci.pNext = nullptr;
7713 cb_ci.attachmentCount = 1;
7714 cb_ci.pAttachments = &att;
7715
7716 VkGraphicsPipelineCreateInfo gp_ci = {};
7717 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7718 gp_ci.stageCount = 2;
7719 gp_ci.pStages = shaderStages;
7720 gp_ci.pVertexInputState = &vi_ci;
7721 gp_ci.pInputAssemblyState = &ia_ci;
7722 gp_ci.pViewportState = &vp_state_ci;
7723 gp_ci.pRasterizationState = &rs_ci;
7724 gp_ci.pColorBlendState = &cb_ci;
7725 gp_ci.pDynamicState = &dyn_state_ci;
7726 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7727 gp_ci.layout = pipeline_layout;
7728 gp_ci.renderPass = renderPass();
7729
7730 VkPipelineCacheCreateInfo pc_ci = {};
7731 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7732
7733 VkPipeline pipeline;
7734 VkPipelineCache pipelineCache;
7735
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007736 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007737 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007738 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007739
7740 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007741 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007742
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007744
7745 // Check too high (line width of 65536.0f).
7746 rs_ci.lineWidth = 65536.0f;
7747
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007748 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007749 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007750 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007751
7752 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007753 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007754
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007756
7757 dyn_state_ci.dynamicStateCount = 3;
7758
7759 rs_ci.lineWidth = 1.0f;
7760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007761 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007762 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007763 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007764 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007765 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007766
7767 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007768 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007769 m_errorMonitor->VerifyFound();
7770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007772
7773 // Check too high with dynamic setting.
7774 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7775 m_errorMonitor->VerifyFound();
7776 EndCommandBuffer();
7777
7778 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7779 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7780 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7781 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007782 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007783}
7784
Karl Schultz6addd812016-02-02 17:17:23 -07007785TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007786 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7788 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007789
7790 ASSERT_NO_FATAL_FAILURE(InitState());
7791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007792
Tony Barbourfe3351b2015-07-28 10:17:20 -06007793 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007794 // Don't care about RenderPass handle b/c error should be flagged before
7795 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007796 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007797
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007798 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007799}
7800
Karl Schultz6addd812016-02-02 17:17:23 -07007801TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007802 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7804 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007805
7806 ASSERT_NO_FATAL_FAILURE(InitState());
7807 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007808
Tony Barbourfe3351b2015-07-28 10:17:20 -06007809 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007810 // Just create a dummy Renderpass that's non-NULL so we can get to the
7811 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007812 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007813
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007814 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007815}
7816
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007817TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7818 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7819 "the number of renderPass attachments that use loadOp"
7820 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7821
7822 ASSERT_NO_FATAL_FAILURE(InitState());
7823 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7824
7825 // Create a renderPass with a single attachment that uses loadOp CLEAR
7826 VkAttachmentReference attach = {};
7827 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7828 VkSubpassDescription subpass = {};
7829 subpass.inputAttachmentCount = 1;
7830 subpass.pInputAttachments = &attach;
7831 VkRenderPassCreateInfo rpci = {};
7832 rpci.subpassCount = 1;
7833 rpci.pSubpasses = &subpass;
7834 rpci.attachmentCount = 1;
7835 VkAttachmentDescription attach_desc = {};
7836 attach_desc.format = VK_FORMAT_UNDEFINED;
7837 // Set loadOp to CLEAR
7838 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7839 rpci.pAttachments = &attach_desc;
7840 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7841 VkRenderPass rp;
7842 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7843
7844 VkCommandBufferInheritanceInfo hinfo = {};
7845 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7846 hinfo.renderPass = VK_NULL_HANDLE;
7847 hinfo.subpass = 0;
7848 hinfo.framebuffer = VK_NULL_HANDLE;
7849 hinfo.occlusionQueryEnable = VK_FALSE;
7850 hinfo.queryFlags = 0;
7851 hinfo.pipelineStatistics = 0;
7852 VkCommandBufferBeginInfo info = {};
7853 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7854 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7855 info.pInheritanceInfo = &hinfo;
7856
7857 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7858 VkRenderPassBeginInfo rp_begin = {};
7859 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7860 rp_begin.pNext = NULL;
7861 rp_begin.renderPass = renderPass();
7862 rp_begin.framebuffer = framebuffer();
7863 rp_begin.clearValueCount = 0; // Should be 1
7864
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7866 "there must be at least 1 entries in "
7867 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007869 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007870
7871 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007872
7873 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007874}
7875
Slawomir Cygan0808f392016-11-28 17:53:23 +01007876TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
7877 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is greater than"
7878 "the number of renderPass attachments that use loadOp"
7879 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7880
7881 ASSERT_NO_FATAL_FAILURE(InitState());
7882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7883
7884 // Create a renderPass with a single attachment that uses loadOp CLEAR
7885 VkAttachmentReference attach = {};
7886 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7887 VkSubpassDescription subpass = {};
7888 subpass.inputAttachmentCount = 1;
7889 subpass.pInputAttachments = &attach;
7890 VkRenderPassCreateInfo rpci = {};
7891 rpci.subpassCount = 1;
7892 rpci.pSubpasses = &subpass;
7893 rpci.attachmentCount = 1;
7894 VkAttachmentDescription attach_desc = {};
7895 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
7896 // Set loadOp to CLEAR
7897 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7898 rpci.pAttachments = &attach_desc;
7899 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7900 VkRenderPass rp;
7901 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7902
7903 VkCommandBufferBeginInfo info = {};
7904 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7905 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7906
7907 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7908 VkRenderPassBeginInfo rp_begin = {};
7909 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7910 rp_begin.pNext = NULL;
7911 rp_begin.renderPass = renderPass();
7912 rp_begin.framebuffer = framebuffer();
7913 rp_begin.clearValueCount = 2; // Should be 1
7914
7915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " has a clearValueCount of"
7916 " 2 but only first 1 entries in pClearValues array are used");
7917
7918 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
7919
7920 m_errorMonitor->VerifyFound();
7921
7922 vkDestroyRenderPass(m_device->device(), rp, NULL);
7923}
7924
7925
Cody Northrop3bb4d962016-05-09 16:15:57 -06007926TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7927
7928 TEST_DESCRIPTION("End a command buffer with an active render pass");
7929
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7931 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007932
7933 ASSERT_NO_FATAL_FAILURE(InitState());
7934 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7935
7936 // The framework's BeginCommandBuffer calls CreateRenderPass
7937 BeginCommandBuffer();
7938
7939 // Call directly into vkEndCommandBuffer instead of the
7940 // the framework's EndCommandBuffer, which inserts a
7941 // vkEndRenderPass
7942 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7943
7944 m_errorMonitor->VerifyFound();
7945
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007946 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7947 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007948}
7949
Karl Schultz6addd812016-02-02 17:17:23 -07007950TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007951 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7953 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007954
7955 ASSERT_NO_FATAL_FAILURE(InitState());
7956 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007957
7958 // Renderpass is started here
7959 BeginCommandBuffer();
7960
7961 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007962 vk_testing::Buffer dstBuffer;
7963 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007964
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007965 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007966
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007967 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007968}
7969
Karl Schultz6addd812016-02-02 17:17:23 -07007970TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007971 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7973 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007974
7975 ASSERT_NO_FATAL_FAILURE(InitState());
7976 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007977
7978 // Renderpass is started here
7979 BeginCommandBuffer();
7980
7981 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007982 vk_testing::Buffer dstBuffer;
7983 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007984
Karl Schultz6addd812016-02-02 17:17:23 -07007985 VkDeviceSize dstOffset = 0;
7986 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007987 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007988
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007989 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007990
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007991 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007992}
7993
Karl Schultz6addd812016-02-02 17:17:23 -07007994TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007995 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7997 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007998
7999 ASSERT_NO_FATAL_FAILURE(InitState());
8000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008001
8002 // Renderpass is started here
8003 BeginCommandBuffer();
8004
Michael Lentine0a369f62016-02-03 16:51:46 -06008005 VkClearColorValue clear_color;
8006 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008007 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8008 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8009 const int32_t tex_width = 32;
8010 const int32_t tex_height = 32;
8011 VkImageCreateInfo image_create_info = {};
8012 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8013 image_create_info.pNext = NULL;
8014 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8015 image_create_info.format = tex_format;
8016 image_create_info.extent.width = tex_width;
8017 image_create_info.extent.height = tex_height;
8018 image_create_info.extent.depth = 1;
8019 image_create_info.mipLevels = 1;
8020 image_create_info.arrayLayers = 1;
8021 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8022 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8023 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008024
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008025 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008026 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008027
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008028 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008029
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008030 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008031
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008032 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008033}
8034
Karl Schultz6addd812016-02-02 17:17:23 -07008035TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008036 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8038 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008039
8040 ASSERT_NO_FATAL_FAILURE(InitState());
8041 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008042
8043 // Renderpass is started here
8044 BeginCommandBuffer();
8045
8046 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008047 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008048 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8049 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8050 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8051 image_create_info.extent.width = 64;
8052 image_create_info.extent.height = 64;
8053 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8054 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008055
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008056 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008057 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008058
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008059 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008060
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008061 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8062 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008063
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008064 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008065}
8066
Karl Schultz6addd812016-02-02 17:17:23 -07008067TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008068 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008069 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008070
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8072 "must be issued inside an active "
8073 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008074
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008075 ASSERT_NO_FATAL_FAILURE(InitState());
8076 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008077
8078 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008079 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008080 ASSERT_VK_SUCCESS(err);
8081
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008082 VkClearAttachment color_attachment;
8083 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8084 color_attachment.clearValue.color.float32[0] = 0;
8085 color_attachment.clearValue.color.float32[1] = 0;
8086 color_attachment.clearValue.color.float32[2] = 0;
8087 color_attachment.clearValue.color.float32[3] = 0;
8088 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008089 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008090 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008091
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008092 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008093}
8094
Chris Forbes3b97e932016-09-07 11:29:24 +12008095TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8096 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8097 "called too many times in a renderpass instance");
8098
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8100 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008101
8102 ASSERT_NO_FATAL_FAILURE(InitState());
8103 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8104
8105 BeginCommandBuffer();
8106
8107 // error here.
8108 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8109 m_errorMonitor->VerifyFound();
8110
8111 EndCommandBuffer();
8112}
8113
Chris Forbes6d624702016-09-07 13:57:05 +12008114TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8115 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8116 "called before the final subpass has been reached");
8117
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8119 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008120
8121 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008122 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8123 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008124
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008125 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008126
8127 VkRenderPass rp;
8128 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8129 ASSERT_VK_SUCCESS(err);
8130
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008131 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008132
8133 VkFramebuffer fb;
8134 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8135 ASSERT_VK_SUCCESS(err);
8136
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008137 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008138
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008139 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 +12008140
8141 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8142
8143 // Error here.
8144 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8145 m_errorMonitor->VerifyFound();
8146
8147 // Clean up.
8148 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8149 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8150}
8151
Karl Schultz9e66a292016-04-21 15:57:51 -06008152TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8153 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8155 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008156
8157 ASSERT_NO_FATAL_FAILURE(InitState());
8158 BeginCommandBuffer();
8159
8160 VkBufferMemoryBarrier buf_barrier = {};
8161 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8162 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8163 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8164 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8165 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8166 buf_barrier.buffer = VK_NULL_HANDLE;
8167 buf_barrier.offset = 0;
8168 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008169 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8170 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008171
8172 m_errorMonitor->VerifyFound();
8173}
8174
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008175TEST_F(VkLayerTest, InvalidBarriers) {
8176 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8177
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008179
8180 ASSERT_NO_FATAL_FAILURE(InitState());
8181 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8182
8183 VkMemoryBarrier mem_barrier = {};
8184 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8185 mem_barrier.pNext = NULL;
8186 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8187 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8188 BeginCommandBuffer();
8189 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008190 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008191 &mem_barrier, 0, nullptr, 0, nullptr);
8192 m_errorMonitor->VerifyFound();
8193
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008195 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008196 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 -06008197 ASSERT_TRUE(image.initialized());
8198 VkImageMemoryBarrier img_barrier = {};
8199 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8200 img_barrier.pNext = NULL;
8201 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8202 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8203 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8204 // New layout can't be UNDEFINED
8205 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8206 img_barrier.image = image.handle();
8207 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8208 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8209 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8210 img_barrier.subresourceRange.baseArrayLayer = 0;
8211 img_barrier.subresourceRange.baseMipLevel = 0;
8212 img_barrier.subresourceRange.layerCount = 1;
8213 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008214 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8215 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008216 m_errorMonitor->VerifyFound();
8217 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8218
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8220 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008221 // baseArrayLayer + layerCount must be <= image's arrayLayers
8222 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008223 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8224 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008225 m_errorMonitor->VerifyFound();
8226 img_barrier.subresourceRange.baseArrayLayer = 0;
8227
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008229 // baseMipLevel + levelCount must be <= image's mipLevels
8230 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008231 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8232 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008233 m_errorMonitor->VerifyFound();
8234 img_barrier.subresourceRange.baseMipLevel = 0;
8235
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008236 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 -06008237 vk_testing::Buffer buffer;
8238 buffer.init(*m_device, 256);
8239 VkBufferMemoryBarrier buf_barrier = {};
8240 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8241 buf_barrier.pNext = NULL;
8242 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8243 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8244 buf_barrier.buffer = buffer.handle();
8245 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8246 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8247 buf_barrier.offset = 0;
8248 buf_barrier.size = VK_WHOLE_SIZE;
8249 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008250 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8251 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008252 m_errorMonitor->VerifyFound();
8253 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8254
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008256 buf_barrier.offset = 257;
8257 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008258 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8259 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008260 m_errorMonitor->VerifyFound();
8261 buf_barrier.offset = 0;
8262
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008264 buf_barrier.size = 257;
8265 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008266 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8267 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008268 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008269
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008270 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008271 m_errorMonitor->SetDesiredFailureMsg(
8272 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8273 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8274 m_errorMonitor->SetDesiredFailureMsg(
8275 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8276 "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 -06008277 VkDepthStencilObj ds_image(m_device);
8278 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8279 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008280 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8281 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008282 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008283 // Use of COLOR aspect on DS image is error
8284 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008285 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8286 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008287 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008288 // Now test depth-only
8289 VkFormatProperties format_props;
8290
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008291 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8292 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8294 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8296 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008297 VkDepthStencilObj d_image(m_device);
8298 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8299 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008300 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008301 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008302 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008303 // Use of COLOR aspect on depth image is error
8304 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008305 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8306 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008307 m_errorMonitor->VerifyFound();
8308 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008309 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8310 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008311 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8313 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008314 VkDepthStencilObj s_image(m_device);
8315 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8316 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008317 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008318 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008319 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008320 // Use of COLOR aspect on depth image is error
8321 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008322 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8323 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008324 m_errorMonitor->VerifyFound();
8325 }
8326 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8328 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8330 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008331 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008332 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 -06008333 ASSERT_TRUE(c_image.initialized());
8334 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8335 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8336 img_barrier.image = c_image.handle();
8337 // Set aspect to depth (non-color)
8338 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008339 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8340 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008341 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008342}
8343
Tony Barbour18ba25c2016-09-29 13:42:40 -06008344TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8345 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8346
8347 m_errorMonitor->SetDesiredFailureMsg(
8348 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8349 "must have required access bit");
8350 ASSERT_NO_FATAL_FAILURE(InitState());
8351 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008352 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 -06008353 ASSERT_TRUE(image.initialized());
8354
8355 VkImageMemoryBarrier barrier = {};
8356 VkImageSubresourceRange range;
8357 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8358 barrier.srcAccessMask = 0;
8359 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8360 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8361 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8362 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8363 barrier.image = image.handle();
8364 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8365 range.baseMipLevel = 0;
8366 range.levelCount = 1;
8367 range.baseArrayLayer = 0;
8368 range.layerCount = 1;
8369 barrier.subresourceRange = range;
8370 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8371 cmdbuf.BeginCommandBuffer();
8372 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8373 &barrier);
8374 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8375 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8376 barrier.srcAccessMask = 0;
8377 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8378 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8379 &barrier);
8380
8381 m_errorMonitor->VerifyFound();
8382}
8383
Karl Schultz6addd812016-02-02 17:17:23 -07008384TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008385 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008386 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008387
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008389
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008390 ASSERT_NO_FATAL_FAILURE(InitState());
8391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008392 uint32_t qfi = 0;
8393 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008394 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8395 buffCI.size = 1024;
8396 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8397 buffCI.queueFamilyIndexCount = 1;
8398 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008399
8400 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008401 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008402 ASSERT_VK_SUCCESS(err);
8403
8404 BeginCommandBuffer();
8405 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008406 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8407 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008408 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008409 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008410
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008411 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008412
Chia-I Wuf7458c52015-10-26 21:10:41 +08008413 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008414}
8415
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008416TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8417 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8419 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8420 "of the indices specified when the device was created, via the "
8421 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008422
8423 ASSERT_NO_FATAL_FAILURE(InitState());
8424 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8425 VkBufferCreateInfo buffCI = {};
8426 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8427 buffCI.size = 1024;
8428 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8429 buffCI.queueFamilyIndexCount = 1;
8430 // Introduce failure by specifying invalid queue_family_index
8431 uint32_t qfi = 777;
8432 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008433 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008434
8435 VkBuffer ib;
8436 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8437
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008438 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008439 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008440}
8441
Karl Schultz6addd812016-02-02 17:17:23 -07008442TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008443TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008444 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008445
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008446 ASSERT_NO_FATAL_FAILURE(InitState());
8447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008448
Chris Forbesf29a84f2016-10-06 18:39:28 +13008449 // An empty primary command buffer
8450 VkCommandBufferObj cb(m_device, m_commandPool);
8451 cb.BeginCommandBuffer();
8452 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008453
Chris Forbesf29a84f2016-10-06 18:39:28 +13008454 m_commandBuffer->BeginCommandBuffer();
8455 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8456 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008457
Chris Forbesf29a84f2016-10-06 18:39:28 +13008458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8459 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008460 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008461}
8462
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008463TEST_F(VkLayerTest, DSUsageBitsErrors) {
8464 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8465 "that do not have correct usage bits sets.");
8466 VkResult err;
8467
8468 ASSERT_NO_FATAL_FAILURE(InitState());
8469 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8470 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8471 ds_type_count[i].type = VkDescriptorType(i);
8472 ds_type_count[i].descriptorCount = 1;
8473 }
8474 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8475 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8476 ds_pool_ci.pNext = NULL;
8477 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8478 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8479 ds_pool_ci.pPoolSizes = ds_type_count;
8480
8481 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008482 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008483 ASSERT_VK_SUCCESS(err);
8484
8485 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008486 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008487 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8488 dsl_binding[i].binding = 0;
8489 dsl_binding[i].descriptorType = VkDescriptorType(i);
8490 dsl_binding[i].descriptorCount = 1;
8491 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8492 dsl_binding[i].pImmutableSamplers = NULL;
8493 }
8494
8495 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8496 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8497 ds_layout_ci.pNext = NULL;
8498 ds_layout_ci.bindingCount = 1;
8499 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8500 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8501 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008502 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008503 ASSERT_VK_SUCCESS(err);
8504 }
8505 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8506 VkDescriptorSetAllocateInfo alloc_info = {};
8507 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8508 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8509 alloc_info.descriptorPool = ds_pool;
8510 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008511 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008512 ASSERT_VK_SUCCESS(err);
8513
8514 // Create a buffer & bufferView to be used for invalid updates
8515 VkBufferCreateInfo buff_ci = {};
8516 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8517 // This usage is not valid for any descriptor type
8518 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8519 buff_ci.size = 256;
8520 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8521 VkBuffer buffer;
8522 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8523 ASSERT_VK_SUCCESS(err);
8524
8525 VkBufferViewCreateInfo buff_view_ci = {};
8526 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8527 buff_view_ci.buffer = buffer;
8528 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8529 buff_view_ci.range = VK_WHOLE_SIZE;
8530 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008531 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008532 ASSERT_VK_SUCCESS(err);
8533
8534 // Create an image to be used for invalid updates
8535 VkImageCreateInfo image_ci = {};
8536 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8537 image_ci.imageType = VK_IMAGE_TYPE_2D;
8538 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8539 image_ci.extent.width = 64;
8540 image_ci.extent.height = 64;
8541 image_ci.extent.depth = 1;
8542 image_ci.mipLevels = 1;
8543 image_ci.arrayLayers = 1;
8544 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8545 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8546 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8547 // This usage is not valid for any descriptor type
8548 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8549 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8550 VkImage image;
8551 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8552 ASSERT_VK_SUCCESS(err);
8553 // Bind memory to image
8554 VkMemoryRequirements mem_reqs;
8555 VkDeviceMemory image_mem;
8556 bool pass;
8557 VkMemoryAllocateInfo mem_alloc = {};
8558 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8559 mem_alloc.pNext = NULL;
8560 mem_alloc.allocationSize = 0;
8561 mem_alloc.memoryTypeIndex = 0;
8562 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8563 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008564 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008565 ASSERT_TRUE(pass);
8566 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8567 ASSERT_VK_SUCCESS(err);
8568 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8569 ASSERT_VK_SUCCESS(err);
8570 // Now create view for image
8571 VkImageViewCreateInfo image_view_ci = {};
8572 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8573 image_view_ci.image = image;
8574 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8575 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8576 image_view_ci.subresourceRange.layerCount = 1;
8577 image_view_ci.subresourceRange.baseArrayLayer = 0;
8578 image_view_ci.subresourceRange.levelCount = 1;
8579 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8580 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008581 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008582 ASSERT_VK_SUCCESS(err);
8583
8584 VkDescriptorBufferInfo buff_info = {};
8585 buff_info.buffer = buffer;
8586 VkDescriptorImageInfo img_info = {};
8587 img_info.imageView = image_view;
8588 VkWriteDescriptorSet descriptor_write = {};
8589 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8590 descriptor_write.dstBinding = 0;
8591 descriptor_write.descriptorCount = 1;
8592 descriptor_write.pTexelBufferView = &buff_view;
8593 descriptor_write.pBufferInfo = &buff_info;
8594 descriptor_write.pImageInfo = &img_info;
8595
8596 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008597 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8598 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8599 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8600 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8601 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8602 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8603 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8604 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8605 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8606 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8607 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008608 // Start loop at 1 as SAMPLER desc type has no usage bit error
8609 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8610 descriptor_write.descriptorType = VkDescriptorType(i);
8611 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008613
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008614 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008615
8616 m_errorMonitor->VerifyFound();
8617 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8618 }
8619 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8620 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008621 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008622 vkDestroyImageView(m_device->device(), image_view, NULL);
8623 vkDestroyBuffer(m_device->device(), buffer, NULL);
8624 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008625 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008626 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8627}
8628
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008629TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008630 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8631 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8632 "1. offset value greater than buffer size\n"
8633 "2. range value of 0\n"
8634 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008635 VkResult err;
8636
8637 ASSERT_NO_FATAL_FAILURE(InitState());
8638 VkDescriptorPoolSize ds_type_count = {};
8639 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8640 ds_type_count.descriptorCount = 1;
8641
8642 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8643 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8644 ds_pool_ci.pNext = NULL;
8645 ds_pool_ci.maxSets = 1;
8646 ds_pool_ci.poolSizeCount = 1;
8647 ds_pool_ci.pPoolSizes = &ds_type_count;
8648
8649 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008650 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008651 ASSERT_VK_SUCCESS(err);
8652
8653 // Create layout with single uniform buffer descriptor
8654 VkDescriptorSetLayoutBinding dsl_binding = {};
8655 dsl_binding.binding = 0;
8656 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8657 dsl_binding.descriptorCount = 1;
8658 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8659 dsl_binding.pImmutableSamplers = NULL;
8660
8661 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8662 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8663 ds_layout_ci.pNext = NULL;
8664 ds_layout_ci.bindingCount = 1;
8665 ds_layout_ci.pBindings = &dsl_binding;
8666 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008667 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008668 ASSERT_VK_SUCCESS(err);
8669
8670 VkDescriptorSet descriptor_set = {};
8671 VkDescriptorSetAllocateInfo alloc_info = {};
8672 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8673 alloc_info.descriptorSetCount = 1;
8674 alloc_info.descriptorPool = ds_pool;
8675 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008676 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008677 ASSERT_VK_SUCCESS(err);
8678
8679 // Create a buffer to be used for invalid updates
8680 VkBufferCreateInfo buff_ci = {};
8681 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8682 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8683 buff_ci.size = 256;
8684 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8685 VkBuffer buffer;
8686 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8687 ASSERT_VK_SUCCESS(err);
8688 // Have to bind memory to buffer before descriptor update
8689 VkMemoryAllocateInfo mem_alloc = {};
8690 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8691 mem_alloc.pNext = NULL;
8692 mem_alloc.allocationSize = 256;
8693 mem_alloc.memoryTypeIndex = 0;
8694
8695 VkMemoryRequirements mem_reqs;
8696 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008697 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008698 if (!pass) {
8699 vkDestroyBuffer(m_device->device(), buffer, NULL);
8700 return;
8701 }
8702
8703 VkDeviceMemory mem;
8704 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8705 ASSERT_VK_SUCCESS(err);
8706 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8707 ASSERT_VK_SUCCESS(err);
8708
8709 VkDescriptorBufferInfo buff_info = {};
8710 buff_info.buffer = buffer;
8711 // First make offset 1 larger than buffer size
8712 buff_info.offset = 257;
8713 buff_info.range = VK_WHOLE_SIZE;
8714 VkWriteDescriptorSet descriptor_write = {};
8715 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8716 descriptor_write.dstBinding = 0;
8717 descriptor_write.descriptorCount = 1;
8718 descriptor_write.pTexelBufferView = nullptr;
8719 descriptor_write.pBufferInfo = &buff_info;
8720 descriptor_write.pImageInfo = nullptr;
8721
8722 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8723 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008725
8726 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8727
8728 m_errorMonitor->VerifyFound();
8729 // Now cause error due to range of 0
8730 buff_info.offset = 0;
8731 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8733 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008734
8735 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8736
8737 m_errorMonitor->VerifyFound();
8738 // Now cause error due to range exceeding buffer size - offset
8739 buff_info.offset = 128;
8740 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008741 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 -06008742
8743 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8744
8745 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008746 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008747 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8748 vkDestroyBuffer(m_device->device(), buffer, NULL);
8749 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8750 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8751}
8752
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008753TEST_F(VkLayerTest, DSAspectBitsErrors) {
8754 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8755 // are set, but could expand this test to hit more cases.
8756 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8757 "that do not have correct aspect bits sets.");
8758 VkResult err;
8759
8760 ASSERT_NO_FATAL_FAILURE(InitState());
8761 VkDescriptorPoolSize ds_type_count = {};
8762 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8763 ds_type_count.descriptorCount = 1;
8764
8765 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8766 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8767 ds_pool_ci.pNext = NULL;
8768 ds_pool_ci.maxSets = 5;
8769 ds_pool_ci.poolSizeCount = 1;
8770 ds_pool_ci.pPoolSizes = &ds_type_count;
8771
8772 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008773 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008774 ASSERT_VK_SUCCESS(err);
8775
8776 VkDescriptorSetLayoutBinding dsl_binding = {};
8777 dsl_binding.binding = 0;
8778 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8779 dsl_binding.descriptorCount = 1;
8780 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8781 dsl_binding.pImmutableSamplers = NULL;
8782
8783 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8784 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8785 ds_layout_ci.pNext = NULL;
8786 ds_layout_ci.bindingCount = 1;
8787 ds_layout_ci.pBindings = &dsl_binding;
8788 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008789 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008790 ASSERT_VK_SUCCESS(err);
8791
8792 VkDescriptorSet descriptor_set = {};
8793 VkDescriptorSetAllocateInfo alloc_info = {};
8794 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8795 alloc_info.descriptorSetCount = 1;
8796 alloc_info.descriptorPool = ds_pool;
8797 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008798 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008799 ASSERT_VK_SUCCESS(err);
8800
8801 // Create an image to be used for invalid updates
8802 VkImageCreateInfo image_ci = {};
8803 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8804 image_ci.imageType = VK_IMAGE_TYPE_2D;
8805 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8806 image_ci.extent.width = 64;
8807 image_ci.extent.height = 64;
8808 image_ci.extent.depth = 1;
8809 image_ci.mipLevels = 1;
8810 image_ci.arrayLayers = 1;
8811 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8812 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8813 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8814 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8815 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8816 VkImage image;
8817 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8818 ASSERT_VK_SUCCESS(err);
8819 // Bind memory to image
8820 VkMemoryRequirements mem_reqs;
8821 VkDeviceMemory image_mem;
8822 bool pass;
8823 VkMemoryAllocateInfo mem_alloc = {};
8824 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8825 mem_alloc.pNext = NULL;
8826 mem_alloc.allocationSize = 0;
8827 mem_alloc.memoryTypeIndex = 0;
8828 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8829 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008830 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008831 ASSERT_TRUE(pass);
8832 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8833 ASSERT_VK_SUCCESS(err);
8834 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8835 ASSERT_VK_SUCCESS(err);
8836 // Now create view for image
8837 VkImageViewCreateInfo image_view_ci = {};
8838 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8839 image_view_ci.image = image;
8840 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8841 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8842 image_view_ci.subresourceRange.layerCount = 1;
8843 image_view_ci.subresourceRange.baseArrayLayer = 0;
8844 image_view_ci.subresourceRange.levelCount = 1;
8845 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008846 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008847
8848 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008849 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008850 ASSERT_VK_SUCCESS(err);
8851
8852 VkDescriptorImageInfo img_info = {};
8853 img_info.imageView = image_view;
8854 VkWriteDescriptorSet descriptor_write = {};
8855 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8856 descriptor_write.dstBinding = 0;
8857 descriptor_write.descriptorCount = 1;
8858 descriptor_write.pTexelBufferView = NULL;
8859 descriptor_write.pBufferInfo = NULL;
8860 descriptor_write.pImageInfo = &img_info;
8861 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8862 descriptor_write.dstSet = descriptor_set;
8863 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8864 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008866
8867 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8868
8869 m_errorMonitor->VerifyFound();
8870 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8871 vkDestroyImage(m_device->device(), image, NULL);
8872 vkFreeMemory(m_device->device(), image_mem, NULL);
8873 vkDestroyImageView(m_device->device(), image_view, NULL);
8874 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8875 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8876}
8877
Karl Schultz6addd812016-02-02 17:17:23 -07008878TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008879 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008880 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008881
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8883 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8884 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008885
Tobin Ehlis3b780662015-05-28 12:11:26 -06008886 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008887 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008888 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008889 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8890 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008891
8892 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008893 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8894 ds_pool_ci.pNext = NULL;
8895 ds_pool_ci.maxSets = 1;
8896 ds_pool_ci.poolSizeCount = 1;
8897 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008898
Tobin Ehlis3b780662015-05-28 12:11:26 -06008899 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008900 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008901 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008902 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008903 dsl_binding.binding = 0;
8904 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8905 dsl_binding.descriptorCount = 1;
8906 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8907 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008908
Tony Barboureb254902015-07-15 12:50:33 -06008909 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008910 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8911 ds_layout_ci.pNext = NULL;
8912 ds_layout_ci.bindingCount = 1;
8913 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008914
Tobin Ehlis3b780662015-05-28 12:11:26 -06008915 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008916 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008917 ASSERT_VK_SUCCESS(err);
8918
8919 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008920 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008921 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008922 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008923 alloc_info.descriptorPool = ds_pool;
8924 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008925 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008926 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008927
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008928 VkSamplerCreateInfo sampler_ci = {};
8929 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8930 sampler_ci.pNext = NULL;
8931 sampler_ci.magFilter = VK_FILTER_NEAREST;
8932 sampler_ci.minFilter = VK_FILTER_NEAREST;
8933 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8934 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8935 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8936 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8937 sampler_ci.mipLodBias = 1.0;
8938 sampler_ci.anisotropyEnable = VK_FALSE;
8939 sampler_ci.maxAnisotropy = 1;
8940 sampler_ci.compareEnable = VK_FALSE;
8941 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8942 sampler_ci.minLod = 1.0;
8943 sampler_ci.maxLod = 1.0;
8944 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8945 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8946 VkSampler sampler;
8947 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8948 ASSERT_VK_SUCCESS(err);
8949
8950 VkDescriptorImageInfo info = {};
8951 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008952
8953 VkWriteDescriptorSet descriptor_write;
8954 memset(&descriptor_write, 0, sizeof(descriptor_write));
8955 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008956 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008957 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008958 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008959 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008960 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008961
8962 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8963
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008964 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008965
Chia-I Wuf7458c52015-10-26 21:10:41 +08008966 vkDestroySampler(m_device->device(), sampler, NULL);
8967 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8968 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008969}
8970
Karl Schultz6addd812016-02-02 17:17:23 -07008971TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008972 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008973 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008974
Tobin Ehlisf922ef82016-11-30 10:19:14 -07008975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008976
Tobin Ehlis3b780662015-05-28 12:11:26 -06008977 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008978 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008979 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008980 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8981 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008982
8983 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008984 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8985 ds_pool_ci.pNext = NULL;
8986 ds_pool_ci.maxSets = 1;
8987 ds_pool_ci.poolSizeCount = 1;
8988 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008989
Tobin Ehlis3b780662015-05-28 12:11:26 -06008990 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008991 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008992 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008993
Tony Barboureb254902015-07-15 12:50:33 -06008994 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008995 dsl_binding.binding = 0;
8996 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8997 dsl_binding.descriptorCount = 1;
8998 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8999 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009000
9001 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009002 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9003 ds_layout_ci.pNext = NULL;
9004 ds_layout_ci.bindingCount = 1;
9005 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009006
Tobin Ehlis3b780662015-05-28 12:11:26 -06009007 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009008 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009009 ASSERT_VK_SUCCESS(err);
9010
9011 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009012 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009013 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009014 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009015 alloc_info.descriptorPool = ds_pool;
9016 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009017 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009018 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009019
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009020 // Correctly update descriptor to avoid "NOT_UPDATED" error
9021 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009022 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009023 buff_info.offset = 0;
9024 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009025
9026 VkWriteDescriptorSet descriptor_write;
9027 memset(&descriptor_write, 0, sizeof(descriptor_write));
9028 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009029 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009030 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009031 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009032 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9033 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009034
9035 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9036
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009037 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009038
Chia-I Wuf7458c52015-10-26 21:10:41 +08009039 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9040 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009041}
9042
Karl Schultz6addd812016-02-02 17:17:23 -07009043TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009044 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009045 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009046
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009048
Tobin Ehlis3b780662015-05-28 12:11:26 -06009049 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009050 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009051 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009052 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9053 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009054
9055 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009056 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9057 ds_pool_ci.pNext = NULL;
9058 ds_pool_ci.maxSets = 1;
9059 ds_pool_ci.poolSizeCount = 1;
9060 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009061
Tobin Ehlis3b780662015-05-28 12:11:26 -06009062 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009063 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009064 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009065
Tony Barboureb254902015-07-15 12:50:33 -06009066 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009067 dsl_binding.binding = 0;
9068 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9069 dsl_binding.descriptorCount = 1;
9070 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9071 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009072
9073 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009074 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9075 ds_layout_ci.pNext = NULL;
9076 ds_layout_ci.bindingCount = 1;
9077 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009078 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009079 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009080 ASSERT_VK_SUCCESS(err);
9081
9082 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009083 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009084 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009085 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009086 alloc_info.descriptorPool = ds_pool;
9087 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009088 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009089 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009090
Tony Barboureb254902015-07-15 12:50:33 -06009091 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009092 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9093 sampler_ci.pNext = NULL;
9094 sampler_ci.magFilter = VK_FILTER_NEAREST;
9095 sampler_ci.minFilter = VK_FILTER_NEAREST;
9096 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9097 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9098 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9099 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9100 sampler_ci.mipLodBias = 1.0;
9101 sampler_ci.anisotropyEnable = VK_FALSE;
9102 sampler_ci.maxAnisotropy = 1;
9103 sampler_ci.compareEnable = VK_FALSE;
9104 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9105 sampler_ci.minLod = 1.0;
9106 sampler_ci.maxLod = 1.0;
9107 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9108 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009109
Tobin Ehlis3b780662015-05-28 12:11:26 -06009110 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009111 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009112 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009113
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009114 VkDescriptorImageInfo info = {};
9115 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009116
9117 VkWriteDescriptorSet descriptor_write;
9118 memset(&descriptor_write, 0, sizeof(descriptor_write));
9119 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009120 descriptor_write.dstSet = descriptorSet;
9121 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009122 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009123 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009124 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009125 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009126
9127 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9128
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009129 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009130
Chia-I Wuf7458c52015-10-26 21:10:41 +08009131 vkDestroySampler(m_device->device(), sampler, NULL);
9132 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9133 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009134}
9135
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009136TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9137 // Create layout w/ empty binding and attempt to update it
9138 VkResult err;
9139
9140 ASSERT_NO_FATAL_FAILURE(InitState());
9141
9142 VkDescriptorPoolSize ds_type_count = {};
9143 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9144 ds_type_count.descriptorCount = 1;
9145
9146 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9147 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9148 ds_pool_ci.pNext = NULL;
9149 ds_pool_ci.maxSets = 1;
9150 ds_pool_ci.poolSizeCount = 1;
9151 ds_pool_ci.pPoolSizes = &ds_type_count;
9152
9153 VkDescriptorPool ds_pool;
9154 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9155 ASSERT_VK_SUCCESS(err);
9156
9157 VkDescriptorSetLayoutBinding dsl_binding = {};
9158 dsl_binding.binding = 0;
9159 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9160 dsl_binding.descriptorCount = 0;
9161 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9162 dsl_binding.pImmutableSamplers = NULL;
9163
9164 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9165 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9166 ds_layout_ci.pNext = NULL;
9167 ds_layout_ci.bindingCount = 1;
9168 ds_layout_ci.pBindings = &dsl_binding;
9169 VkDescriptorSetLayout ds_layout;
9170 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9171 ASSERT_VK_SUCCESS(err);
9172
9173 VkDescriptorSet descriptor_set;
9174 VkDescriptorSetAllocateInfo alloc_info = {};
9175 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9176 alloc_info.descriptorSetCount = 1;
9177 alloc_info.descriptorPool = ds_pool;
9178 alloc_info.pSetLayouts = &ds_layout;
9179 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9180 ASSERT_VK_SUCCESS(err);
9181
9182 VkSamplerCreateInfo sampler_ci = {};
9183 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9184 sampler_ci.magFilter = VK_FILTER_NEAREST;
9185 sampler_ci.minFilter = VK_FILTER_NEAREST;
9186 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9187 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9188 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9189 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9190 sampler_ci.mipLodBias = 1.0;
9191 sampler_ci.maxAnisotropy = 1;
9192 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9193 sampler_ci.minLod = 1.0;
9194 sampler_ci.maxLod = 1.0;
9195 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9196
9197 VkSampler sampler;
9198 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9199 ASSERT_VK_SUCCESS(err);
9200
9201 VkDescriptorImageInfo info = {};
9202 info.sampler = sampler;
9203
9204 VkWriteDescriptorSet descriptor_write;
9205 memset(&descriptor_write, 0, sizeof(descriptor_write));
9206 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9207 descriptor_write.dstSet = descriptor_set;
9208 descriptor_write.dstBinding = 0;
9209 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9210 // This is the wrong type, but empty binding error will be flagged first
9211 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9212 descriptor_write.pImageInfo = &info;
9213
9214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9215 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9216 m_errorMonitor->VerifyFound();
9217
9218 vkDestroySampler(m_device->device(), sampler, NULL);
9219 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9220 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9221}
9222
Karl Schultz6addd812016-02-02 17:17:23 -07009223TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9224 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9225 // types
9226 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009227
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009228 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 -06009229
Tobin Ehlis3b780662015-05-28 12:11:26 -06009230 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009231
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009232 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009233 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9234 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009235
9236 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009237 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9238 ds_pool_ci.pNext = NULL;
9239 ds_pool_ci.maxSets = 1;
9240 ds_pool_ci.poolSizeCount = 1;
9241 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009242
Tobin Ehlis3b780662015-05-28 12:11:26 -06009243 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009244 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009245 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009246 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009247 dsl_binding.binding = 0;
9248 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9249 dsl_binding.descriptorCount = 1;
9250 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9251 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009252
Tony Barboureb254902015-07-15 12:50:33 -06009253 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009254 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9255 ds_layout_ci.pNext = NULL;
9256 ds_layout_ci.bindingCount = 1;
9257 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009258
Tobin Ehlis3b780662015-05-28 12:11:26 -06009259 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009260 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009261 ASSERT_VK_SUCCESS(err);
9262
9263 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009264 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009265 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009266 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009267 alloc_info.descriptorPool = ds_pool;
9268 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009269 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009270 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009271
Tony Barboureb254902015-07-15 12:50:33 -06009272 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009273 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9274 sampler_ci.pNext = NULL;
9275 sampler_ci.magFilter = VK_FILTER_NEAREST;
9276 sampler_ci.minFilter = VK_FILTER_NEAREST;
9277 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9278 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9279 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9280 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9281 sampler_ci.mipLodBias = 1.0;
9282 sampler_ci.anisotropyEnable = VK_FALSE;
9283 sampler_ci.maxAnisotropy = 1;
9284 sampler_ci.compareEnable = VK_FALSE;
9285 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9286 sampler_ci.minLod = 1.0;
9287 sampler_ci.maxLod = 1.0;
9288 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9289 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009290 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009291 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009292 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009293
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009294 VkDescriptorImageInfo info = {};
9295 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009296
9297 VkWriteDescriptorSet descriptor_write;
9298 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009299 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009300 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009301 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009302 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009303 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009304 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009305
9306 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9307
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009308 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009309
Chia-I Wuf7458c52015-10-26 21:10:41 +08009310 vkDestroySampler(m_device->device(), sampler, NULL);
9311 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9312 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009313}
9314
Karl Schultz6addd812016-02-02 17:17:23 -07009315TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009316 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009317 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009318
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9320 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009321
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009322 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009323 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9324 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009325 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009326 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9327 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009328
9329 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009330 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9331 ds_pool_ci.pNext = NULL;
9332 ds_pool_ci.maxSets = 1;
9333 ds_pool_ci.poolSizeCount = 1;
9334 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009335
9336 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009337 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009338 ASSERT_VK_SUCCESS(err);
9339
9340 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009341 dsl_binding.binding = 0;
9342 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9343 dsl_binding.descriptorCount = 1;
9344 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9345 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009346
9347 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009348 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9349 ds_layout_ci.pNext = NULL;
9350 ds_layout_ci.bindingCount = 1;
9351 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009352 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009353 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009354 ASSERT_VK_SUCCESS(err);
9355
9356 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009357 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009358 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009359 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009360 alloc_info.descriptorPool = ds_pool;
9361 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009362 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009363 ASSERT_VK_SUCCESS(err);
9364
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009365 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009366
9367 VkDescriptorImageInfo descriptor_info;
9368 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9369 descriptor_info.sampler = sampler;
9370
9371 VkWriteDescriptorSet descriptor_write;
9372 memset(&descriptor_write, 0, sizeof(descriptor_write));
9373 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009374 descriptor_write.dstSet = descriptorSet;
9375 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009376 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009377 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9378 descriptor_write.pImageInfo = &descriptor_info;
9379
9380 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9381
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009382 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009383
Chia-I Wuf7458c52015-10-26 21:10:41 +08009384 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9385 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009386}
9387
Karl Schultz6addd812016-02-02 17:17:23 -07009388TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9389 // Create a single combined Image/Sampler descriptor and send it an invalid
9390 // imageView
9391 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009392
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009394
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009395 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009396 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009397 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9398 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009399
9400 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009401 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9402 ds_pool_ci.pNext = NULL;
9403 ds_pool_ci.maxSets = 1;
9404 ds_pool_ci.poolSizeCount = 1;
9405 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009406
9407 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009408 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009409 ASSERT_VK_SUCCESS(err);
9410
9411 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009412 dsl_binding.binding = 0;
9413 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9414 dsl_binding.descriptorCount = 1;
9415 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9416 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009417
9418 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009419 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9420 ds_layout_ci.pNext = NULL;
9421 ds_layout_ci.bindingCount = 1;
9422 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009423 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009424 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009425 ASSERT_VK_SUCCESS(err);
9426
9427 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009428 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009429 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009430 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009431 alloc_info.descriptorPool = ds_pool;
9432 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009433 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009434 ASSERT_VK_SUCCESS(err);
9435
9436 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009437 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9438 sampler_ci.pNext = NULL;
9439 sampler_ci.magFilter = VK_FILTER_NEAREST;
9440 sampler_ci.minFilter = VK_FILTER_NEAREST;
9441 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9442 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9443 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9444 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9445 sampler_ci.mipLodBias = 1.0;
9446 sampler_ci.anisotropyEnable = VK_FALSE;
9447 sampler_ci.maxAnisotropy = 1;
9448 sampler_ci.compareEnable = VK_FALSE;
9449 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9450 sampler_ci.minLod = 1.0;
9451 sampler_ci.maxLod = 1.0;
9452 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9453 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009454
9455 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009456 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009457 ASSERT_VK_SUCCESS(err);
9458
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009459 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009460
9461 VkDescriptorImageInfo descriptor_info;
9462 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9463 descriptor_info.sampler = sampler;
9464 descriptor_info.imageView = view;
9465
9466 VkWriteDescriptorSet descriptor_write;
9467 memset(&descriptor_write, 0, sizeof(descriptor_write));
9468 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009469 descriptor_write.dstSet = descriptorSet;
9470 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009471 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009472 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9473 descriptor_write.pImageInfo = &descriptor_info;
9474
9475 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9476
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009477 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009478
Chia-I Wuf7458c52015-10-26 21:10:41 +08009479 vkDestroySampler(m_device->device(), sampler, NULL);
9480 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9481 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009482}
9483
Karl Schultz6addd812016-02-02 17:17:23 -07009484TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9485 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9486 // into the other
9487 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009488
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9490 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9491 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009492
Tobin Ehlis04356f92015-10-27 16:35:27 -06009493 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009494 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009495 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009496 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9497 ds_type_count[0].descriptorCount = 1;
9498 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9499 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009500
9501 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009502 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9503 ds_pool_ci.pNext = NULL;
9504 ds_pool_ci.maxSets = 1;
9505 ds_pool_ci.poolSizeCount = 2;
9506 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009507
9508 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009509 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009510 ASSERT_VK_SUCCESS(err);
9511 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009512 dsl_binding[0].binding = 0;
9513 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9514 dsl_binding[0].descriptorCount = 1;
9515 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9516 dsl_binding[0].pImmutableSamplers = NULL;
9517 dsl_binding[1].binding = 1;
9518 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9519 dsl_binding[1].descriptorCount = 1;
9520 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9521 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009522
9523 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009524 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9525 ds_layout_ci.pNext = NULL;
9526 ds_layout_ci.bindingCount = 2;
9527 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009528
9529 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009530 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009531 ASSERT_VK_SUCCESS(err);
9532
9533 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009534 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009535 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009536 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009537 alloc_info.descriptorPool = ds_pool;
9538 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009539 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009540 ASSERT_VK_SUCCESS(err);
9541
9542 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009543 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9544 sampler_ci.pNext = NULL;
9545 sampler_ci.magFilter = VK_FILTER_NEAREST;
9546 sampler_ci.minFilter = VK_FILTER_NEAREST;
9547 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9548 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9549 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9550 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9551 sampler_ci.mipLodBias = 1.0;
9552 sampler_ci.anisotropyEnable = VK_FALSE;
9553 sampler_ci.maxAnisotropy = 1;
9554 sampler_ci.compareEnable = VK_FALSE;
9555 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9556 sampler_ci.minLod = 1.0;
9557 sampler_ci.maxLod = 1.0;
9558 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9559 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009560
9561 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009562 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009563 ASSERT_VK_SUCCESS(err);
9564
9565 VkDescriptorImageInfo info = {};
9566 info.sampler = sampler;
9567
9568 VkWriteDescriptorSet descriptor_write;
9569 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9570 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009571 descriptor_write.dstSet = descriptorSet;
9572 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009573 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009574 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9575 descriptor_write.pImageInfo = &info;
9576 // This write update should succeed
9577 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9578 // Now perform a copy update that fails due to type mismatch
9579 VkCopyDescriptorSet copy_ds_update;
9580 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9581 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9582 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009583 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009584 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009585 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009586 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009587 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9588
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009589 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009590 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009591 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 -06009592 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9593 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9594 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009595 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009596 copy_ds_update.dstSet = descriptorSet;
9597 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009598 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009599 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9600
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009601 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009602
Tobin Ehlis04356f92015-10-27 16:35:27 -06009603 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9605 "update array offset of 0 and update of "
9606 "5 descriptors oversteps total number "
9607 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009608
Tobin Ehlis04356f92015-10-27 16:35:27 -06009609 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9610 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9611 copy_ds_update.srcSet = descriptorSet;
9612 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009613 copy_ds_update.dstSet = descriptorSet;
9614 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009615 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009616 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9617
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009618 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009619
Chia-I Wuf7458c52015-10-26 21:10:41 +08009620 vkDestroySampler(m_device->device(), sampler, NULL);
9621 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9622 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009623}
9624
Karl Schultz6addd812016-02-02 17:17:23 -07009625TEST_F(VkLayerTest, NumSamplesMismatch) {
9626 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9627 // sampleCount
9628 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009629
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009631
Tobin Ehlis3b780662015-05-28 12:11:26 -06009632 ASSERT_NO_FATAL_FAILURE(InitState());
9633 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009634 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009635 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009636 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009637
9638 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009639 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9640 ds_pool_ci.pNext = NULL;
9641 ds_pool_ci.maxSets = 1;
9642 ds_pool_ci.poolSizeCount = 1;
9643 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009644
Tobin Ehlis3b780662015-05-28 12:11:26 -06009645 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009646 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009647 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009648
Tony Barboureb254902015-07-15 12:50:33 -06009649 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009650 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009651 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009652 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009653 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9654 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009655
Tony Barboureb254902015-07-15 12:50:33 -06009656 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9657 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9658 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009659 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009660 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009661
Tobin Ehlis3b780662015-05-28 12:11:26 -06009662 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009663 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009664 ASSERT_VK_SUCCESS(err);
9665
9666 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009667 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009668 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009669 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009670 alloc_info.descriptorPool = ds_pool;
9671 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009672 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009673 ASSERT_VK_SUCCESS(err);
9674
Tony Barboureb254902015-07-15 12:50:33 -06009675 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009676 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009677 pipe_ms_state_ci.pNext = NULL;
9678 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9679 pipe_ms_state_ci.sampleShadingEnable = 0;
9680 pipe_ms_state_ci.minSampleShading = 1.0;
9681 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009682
Tony Barboureb254902015-07-15 12:50:33 -06009683 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009684 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9685 pipeline_layout_ci.pNext = NULL;
9686 pipeline_layout_ci.setLayoutCount = 1;
9687 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009688
9689 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009690 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009691 ASSERT_VK_SUCCESS(err);
9692
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009693 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9694 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9695 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009696 VkPipelineObj pipe(m_device);
9697 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009698 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009699 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009700 pipe.SetMSAA(&pipe_ms_state_ci);
9701 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009702
Tony Barbourfe3351b2015-07-28 10:17:20 -06009703 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009704 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009705
Mark Young29927482016-05-04 14:38:51 -06009706 // Render triangle (the error should trigger on the attempt to draw).
9707 Draw(3, 1, 0, 0);
9708
9709 // Finalize recording of the command buffer
9710 EndCommandBuffer();
9711
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009712 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009713
Chia-I Wuf7458c52015-10-26 21:10:41 +08009714 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9715 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9716 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009717}
Mark Young29927482016-05-04 14:38:51 -06009718
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009719TEST_F(VkLayerTest, RenderPassIncompatible) {
9720 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9721 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009722 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009723 VkResult err;
9724
9725 ASSERT_NO_FATAL_FAILURE(InitState());
9726 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9727
9728 VkDescriptorSetLayoutBinding dsl_binding = {};
9729 dsl_binding.binding = 0;
9730 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9731 dsl_binding.descriptorCount = 1;
9732 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9733 dsl_binding.pImmutableSamplers = NULL;
9734
9735 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9736 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9737 ds_layout_ci.pNext = NULL;
9738 ds_layout_ci.bindingCount = 1;
9739 ds_layout_ci.pBindings = &dsl_binding;
9740
9741 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009742 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009743 ASSERT_VK_SUCCESS(err);
9744
9745 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9746 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9747 pipeline_layout_ci.pNext = NULL;
9748 pipeline_layout_ci.setLayoutCount = 1;
9749 pipeline_layout_ci.pSetLayouts = &ds_layout;
9750
9751 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009752 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009753 ASSERT_VK_SUCCESS(err);
9754
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009755 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9756 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9757 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009758 // Create a renderpass that will be incompatible with default renderpass
9759 VkAttachmentReference attach = {};
9760 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9761 VkAttachmentReference color_att = {};
9762 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9763 VkSubpassDescription subpass = {};
9764 subpass.inputAttachmentCount = 1;
9765 subpass.pInputAttachments = &attach;
9766 subpass.colorAttachmentCount = 1;
9767 subpass.pColorAttachments = &color_att;
9768 VkRenderPassCreateInfo rpci = {};
9769 rpci.subpassCount = 1;
9770 rpci.pSubpasses = &subpass;
9771 rpci.attachmentCount = 1;
9772 VkAttachmentDescription attach_desc = {};
9773 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009774 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9775 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009776 rpci.pAttachments = &attach_desc;
9777 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9778 VkRenderPass rp;
9779 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9780 VkPipelineObj pipe(m_device);
9781 pipe.AddShader(&vs);
9782 pipe.AddShader(&fs);
9783 pipe.AddColorAttachment();
9784 VkViewport view_port = {};
9785 m_viewports.push_back(view_port);
9786 pipe.SetViewport(m_viewports);
9787 VkRect2D rect = {};
9788 m_scissors.push_back(rect);
9789 pipe.SetScissor(m_scissors);
9790 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9791
9792 VkCommandBufferInheritanceInfo cbii = {};
9793 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9794 cbii.renderPass = rp;
9795 cbii.subpass = 0;
9796 VkCommandBufferBeginInfo cbbi = {};
9797 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9798 cbbi.pInheritanceInfo = &cbii;
9799 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9800 VkRenderPassBeginInfo rpbi = {};
9801 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9802 rpbi.framebuffer = m_framebuffer;
9803 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009804 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9805 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009806
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009808 // Render triangle (the error should trigger on the attempt to draw).
9809 Draw(3, 1, 0, 0);
9810
9811 // Finalize recording of the command buffer
9812 EndCommandBuffer();
9813
9814 m_errorMonitor->VerifyFound();
9815
9816 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9817 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9818 vkDestroyRenderPass(m_device->device(), rp, NULL);
9819}
9820
Mark Youngc89c6312016-03-31 16:03:20 -06009821TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9822 // Create Pipeline where the number of blend attachments doesn't match the
9823 // number of color attachments. In this case, we don't add any color
9824 // blend attachments even though we have a color attachment.
9825 VkResult err;
9826
9827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009828 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009829
9830 ASSERT_NO_FATAL_FAILURE(InitState());
9831 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9832 VkDescriptorPoolSize ds_type_count = {};
9833 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9834 ds_type_count.descriptorCount = 1;
9835
9836 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9837 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9838 ds_pool_ci.pNext = NULL;
9839 ds_pool_ci.maxSets = 1;
9840 ds_pool_ci.poolSizeCount = 1;
9841 ds_pool_ci.pPoolSizes = &ds_type_count;
9842
9843 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009844 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009845 ASSERT_VK_SUCCESS(err);
9846
9847 VkDescriptorSetLayoutBinding dsl_binding = {};
9848 dsl_binding.binding = 0;
9849 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9850 dsl_binding.descriptorCount = 1;
9851 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9852 dsl_binding.pImmutableSamplers = NULL;
9853
9854 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9855 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9856 ds_layout_ci.pNext = NULL;
9857 ds_layout_ci.bindingCount = 1;
9858 ds_layout_ci.pBindings = &dsl_binding;
9859
9860 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009862 ASSERT_VK_SUCCESS(err);
9863
9864 VkDescriptorSet descriptorSet;
9865 VkDescriptorSetAllocateInfo alloc_info = {};
9866 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9867 alloc_info.descriptorSetCount = 1;
9868 alloc_info.descriptorPool = ds_pool;
9869 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009870 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009871 ASSERT_VK_SUCCESS(err);
9872
9873 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009874 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009875 pipe_ms_state_ci.pNext = NULL;
9876 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9877 pipe_ms_state_ci.sampleShadingEnable = 0;
9878 pipe_ms_state_ci.minSampleShading = 1.0;
9879 pipe_ms_state_ci.pSampleMask = NULL;
9880
9881 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9882 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9883 pipeline_layout_ci.pNext = NULL;
9884 pipeline_layout_ci.setLayoutCount = 1;
9885 pipeline_layout_ci.pSetLayouts = &ds_layout;
9886
9887 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009888 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009889 ASSERT_VK_SUCCESS(err);
9890
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009891 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9892 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9893 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009894 VkPipelineObj pipe(m_device);
9895 pipe.AddShader(&vs);
9896 pipe.AddShader(&fs);
9897 pipe.SetMSAA(&pipe_ms_state_ci);
9898 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9899
9900 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009901 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009902
Mark Young29927482016-05-04 14:38:51 -06009903 // Render triangle (the error should trigger on the attempt to draw).
9904 Draw(3, 1, 0, 0);
9905
9906 // Finalize recording of the command buffer
9907 EndCommandBuffer();
9908
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009909 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009910
9911 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9912 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9913 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9914}
Mark Young29927482016-05-04 14:38:51 -06009915
Mark Muellerd4914412016-06-13 17:52:06 -06009916TEST_F(VkLayerTest, MissingClearAttachment) {
9917 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9918 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009919 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009921 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009922
9923 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9924 m_errorMonitor->VerifyFound();
9925}
9926
Karl Schultz6addd812016-02-02 17:17:23 -07009927TEST_F(VkLayerTest, ClearCmdNoDraw) {
9928 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9929 // to issuing a Draw
9930 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009931
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009933 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009934
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009935 ASSERT_NO_FATAL_FAILURE(InitState());
9936 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009937
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009938 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009939 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9940 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009941
9942 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009943 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9944 ds_pool_ci.pNext = NULL;
9945 ds_pool_ci.maxSets = 1;
9946 ds_pool_ci.poolSizeCount = 1;
9947 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009948
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009949 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009950 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009951 ASSERT_VK_SUCCESS(err);
9952
Tony Barboureb254902015-07-15 12:50:33 -06009953 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009954 dsl_binding.binding = 0;
9955 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9956 dsl_binding.descriptorCount = 1;
9957 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9958 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009959
Tony Barboureb254902015-07-15 12:50:33 -06009960 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009961 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9962 ds_layout_ci.pNext = NULL;
9963 ds_layout_ci.bindingCount = 1;
9964 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009965
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009966 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009967 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009968 ASSERT_VK_SUCCESS(err);
9969
9970 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009971 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009972 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009973 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009974 alloc_info.descriptorPool = ds_pool;
9975 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009976 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009977 ASSERT_VK_SUCCESS(err);
9978
Tony Barboureb254902015-07-15 12:50:33 -06009979 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009980 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009981 pipe_ms_state_ci.pNext = NULL;
9982 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9983 pipe_ms_state_ci.sampleShadingEnable = 0;
9984 pipe_ms_state_ci.minSampleShading = 1.0;
9985 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009986
Tony Barboureb254902015-07-15 12:50:33 -06009987 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009988 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9989 pipeline_layout_ci.pNext = NULL;
9990 pipeline_layout_ci.setLayoutCount = 1;
9991 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009992
9993 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009994 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009995 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009996
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009997 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009998 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009999 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010000 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010001
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010002 VkPipelineObj pipe(m_device);
10003 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010004 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010005 pipe.SetMSAA(&pipe_ms_state_ci);
10006 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010007
10008 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010009
Karl Schultz6addd812016-02-02 17:17:23 -070010010 // Main thing we care about for this test is that the VkImage obj we're
10011 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010012 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010013 VkClearAttachment color_attachment;
10014 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10015 color_attachment.clearValue.color.float32[0] = 1.0;
10016 color_attachment.clearValue.color.float32[1] = 1.0;
10017 color_attachment.clearValue.color.float32[2] = 1.0;
10018 color_attachment.clearValue.color.float32[3] = 1.0;
10019 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010020 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010022 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010023
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010024 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010025
Chia-I Wuf7458c52015-10-26 21:10:41 +080010026 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10027 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10028 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010029}
10030
Karl Schultz6addd812016-02-02 17:17:23 -070010031TEST_F(VkLayerTest, VtxBufferBadIndex) {
10032 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10035 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010036
Tobin Ehlis502480b2015-06-24 15:53:07 -060010037 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010038 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010040
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010041 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010042 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10043 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010044
10045 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010046 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10047 ds_pool_ci.pNext = NULL;
10048 ds_pool_ci.maxSets = 1;
10049 ds_pool_ci.poolSizeCount = 1;
10050 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010051
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010052 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010053 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010054 ASSERT_VK_SUCCESS(err);
10055
Tony Barboureb254902015-07-15 12:50:33 -060010056 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010057 dsl_binding.binding = 0;
10058 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10059 dsl_binding.descriptorCount = 1;
10060 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10061 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010062
Tony Barboureb254902015-07-15 12:50:33 -060010063 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010064 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10065 ds_layout_ci.pNext = NULL;
10066 ds_layout_ci.bindingCount = 1;
10067 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010068
Tobin Ehlis502480b2015-06-24 15:53:07 -060010069 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010070 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010071 ASSERT_VK_SUCCESS(err);
10072
10073 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010074 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010075 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010076 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010077 alloc_info.descriptorPool = ds_pool;
10078 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010079 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010080 ASSERT_VK_SUCCESS(err);
10081
Tony Barboureb254902015-07-15 12:50:33 -060010082 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010083 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010084 pipe_ms_state_ci.pNext = NULL;
10085 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10086 pipe_ms_state_ci.sampleShadingEnable = 0;
10087 pipe_ms_state_ci.minSampleShading = 1.0;
10088 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010089
Tony Barboureb254902015-07-15 12:50:33 -060010090 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010091 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10092 pipeline_layout_ci.pNext = NULL;
10093 pipeline_layout_ci.setLayoutCount = 1;
10094 pipeline_layout_ci.pSetLayouts = &ds_layout;
10095 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010096
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010097 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010098 ASSERT_VK_SUCCESS(err);
10099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010100 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10101 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10102 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010103 VkPipelineObj pipe(m_device);
10104 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010105 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010106 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010107 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010108 pipe.SetViewport(m_viewports);
10109 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010110 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010111
10112 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010113 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010114 // Don't care about actual data, just need to get to draw to flag error
10115 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010116 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010117 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010118 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010119
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010120 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010121
Chia-I Wuf7458c52015-10-26 21:10:41 +080010122 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10123 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10124 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010125}
Mark Muellerdfe37552016-07-07 14:47:42 -060010126
Mark Mueller2ee294f2016-08-04 12:59:48 -060010127TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10128 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10129 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010130 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010131
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010132 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10133 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010134
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010135 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10136 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010137
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010138 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010139
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010141 // The following test fails with recent NVidia drivers.
10142 // By the time core_validation is reached, the NVidia
10143 // driver has sanitized the invalid condition and core_validation
10144 // is not introduced to the failure condition. This is not the case
10145 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010146 // uint32_t count = static_cast<uint32_t>(~0);
10147 // VkPhysicalDevice physical_device;
10148 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10149 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010150
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010152 float queue_priority = 0.0;
10153
10154 VkDeviceQueueCreateInfo queue_create_info = {};
10155 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10156 queue_create_info.queueCount = 1;
10157 queue_create_info.pQueuePriorities = &queue_priority;
10158 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10159
10160 VkPhysicalDeviceFeatures features = m_device->phy().features();
10161 VkDevice testDevice;
10162 VkDeviceCreateInfo device_create_info = {};
10163 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10164 device_create_info.queueCreateInfoCount = 1;
10165 device_create_info.pQueueCreateInfos = &queue_create_info;
10166 device_create_info.pEnabledFeatures = &features;
10167 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10168 m_errorMonitor->VerifyFound();
10169
10170 queue_create_info.queueFamilyIndex = 1;
10171
10172 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10173 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10174 for (unsigned i = 0; i < feature_count; i++) {
10175 if (VK_FALSE == feature_array[i]) {
10176 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010178 device_create_info.pEnabledFeatures = &features;
10179 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10180 m_errorMonitor->VerifyFound();
10181 break;
10182 }
10183 }
10184}
10185
Tobin Ehlis16edf082016-11-21 12:33:49 -070010186TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10187 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10188
10189 ASSERT_NO_FATAL_FAILURE(InitState());
10190
10191 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10192 std::vector<VkDeviceQueueCreateInfo> queue_info;
10193 queue_info.reserve(queue_props.size());
10194 std::vector<std::vector<float>> queue_priorities;
10195 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10196 VkDeviceQueueCreateInfo qi{};
10197 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10198 qi.queueFamilyIndex = i;
10199 qi.queueCount = queue_props[i].queueCount;
10200 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10201 qi.pQueuePriorities = queue_priorities[i].data();
10202 queue_info.push_back(qi);
10203 }
10204
10205 std::vector<const char *> device_extension_names;
10206
10207 VkDevice local_device;
10208 VkDeviceCreateInfo device_create_info = {};
10209 auto features = m_device->phy().features();
10210 // Intentionally disable pipeline stats
10211 features.pipelineStatisticsQuery = VK_FALSE;
10212 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10213 device_create_info.pNext = NULL;
10214 device_create_info.queueCreateInfoCount = queue_info.size();
10215 device_create_info.pQueueCreateInfos = queue_info.data();
10216 device_create_info.enabledLayerCount = 0;
10217 device_create_info.ppEnabledLayerNames = NULL;
10218 device_create_info.pEnabledFeatures = &features;
10219 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10220 ASSERT_VK_SUCCESS(err);
10221
10222 VkQueryPoolCreateInfo qpci{};
10223 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10224 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10225 qpci.queryCount = 1;
10226 VkQueryPool query_pool;
10227
10228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10229 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10230 m_errorMonitor->VerifyFound();
10231
10232 vkDestroyDevice(local_device, nullptr);
10233}
10234
Mark Mueller2ee294f2016-08-04 12:59:48 -060010235TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10236 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10237 "End a command buffer with a query still in progress.");
10238
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010239 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10240 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10241 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010243 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010244
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010246
10247 ASSERT_NO_FATAL_FAILURE(InitState());
10248
10249 VkEvent event;
10250 VkEventCreateInfo event_create_info{};
10251 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10252 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10253
Mark Mueller2ee294f2016-08-04 12:59:48 -060010254 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010255 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010256
10257 BeginCommandBuffer();
10258
10259 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010260 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 -060010261 ASSERT_TRUE(image.initialized());
10262 VkImageMemoryBarrier img_barrier = {};
10263 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10264 img_barrier.pNext = NULL;
10265 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10266 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10267 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10268 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10269 img_barrier.image = image.handle();
10270 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010271
10272 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10273 // that layer validation catches the case when it is not.
10274 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010275 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10276 img_barrier.subresourceRange.baseArrayLayer = 0;
10277 img_barrier.subresourceRange.baseMipLevel = 0;
10278 img_barrier.subresourceRange.layerCount = 1;
10279 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010280 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10281 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010282 m_errorMonitor->VerifyFound();
10283
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010285
10286 VkQueryPool query_pool;
10287 VkQueryPoolCreateInfo query_pool_create_info = {};
10288 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10289 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10290 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010291 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010292
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010293 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010294 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10295
10296 vkEndCommandBuffer(m_commandBuffer->handle());
10297 m_errorMonitor->VerifyFound();
10298
10299 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10300 vkDestroyEvent(m_device->device(), event, nullptr);
10301}
10302
Mark Muellerdfe37552016-07-07 14:47:42 -060010303TEST_F(VkLayerTest, VertexBufferInvalid) {
10304 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10305 "delete a buffer twice, use an invalid offset for each "
10306 "buffer type, and attempt to bind a null buffer");
10307
10308 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10309 "using deleted buffer ";
Mark Muellerdfe37552016-07-07 14:47:42 -060010310 const char *invalid_offset_message = "vkBindBufferMemory(): "
10311 "memoryOffset is 0x";
10312 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10313 "storage memoryOffset "
10314 "is 0x";
10315 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10316 "texel memoryOffset "
10317 "is 0x";
10318 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10319 "uniform memoryOffset "
10320 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010321
10322 ASSERT_NO_FATAL_FAILURE(InitState());
10323 ASSERT_NO_FATAL_FAILURE(InitViewport());
10324 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10325
10326 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010327 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010328 pipe_ms_state_ci.pNext = NULL;
10329 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10330 pipe_ms_state_ci.sampleShadingEnable = 0;
10331 pipe_ms_state_ci.minSampleShading = 1.0;
10332 pipe_ms_state_ci.pSampleMask = nullptr;
10333
10334 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10335 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10336 VkPipelineLayout pipeline_layout;
10337
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010338 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010339 ASSERT_VK_SUCCESS(err);
10340
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010341 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10342 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010343 VkPipelineObj pipe(m_device);
10344 pipe.AddShader(&vs);
10345 pipe.AddShader(&fs);
10346 pipe.AddColorAttachment();
10347 pipe.SetMSAA(&pipe_ms_state_ci);
10348 pipe.SetViewport(m_viewports);
10349 pipe.SetScissor(m_scissors);
10350 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10351
10352 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010353 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010354
10355 {
10356 // Create and bind a vertex buffer in a reduced scope, which will cause
10357 // it to be deleted upon leaving this scope
10358 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010359 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010360 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10361 draw_verticies.AddVertexInputToPipe(pipe);
10362 }
10363
10364 Draw(1, 0, 0, 0);
10365
10366 EndCommandBuffer();
10367
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010369 QueueCommandBuffer(false);
10370 m_errorMonitor->VerifyFound();
10371
10372 {
10373 // Create and bind a vertex buffer in a reduced scope, and delete it
10374 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010375 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010377 buffer_test.TestDoubleDestroy();
10378 }
10379 m_errorMonitor->VerifyFound();
10380
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010381 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010382 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10384 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10385 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010386 m_errorMonitor->VerifyFound();
10387 }
10388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010389 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10390 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010391 // Create and bind a memory buffer with an invalid offset again,
10392 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10394 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10395 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010396 m_errorMonitor->VerifyFound();
10397 }
10398
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010399 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010400 // Create and bind a memory buffer with an invalid offset again, but
10401 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10403 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10404 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010405 m_errorMonitor->VerifyFound();
10406 }
10407
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010408 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010409 // Create and bind a memory buffer with an invalid offset again, but
10410 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10412 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10413 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010414 m_errorMonitor->VerifyFound();
10415 }
10416
10417 {
10418 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010420 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10421 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010422 m_errorMonitor->VerifyFound();
10423 }
10424
10425 {
10426 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010428 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10429 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010430 }
10431 m_errorMonitor->VerifyFound();
10432
10433 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10434}
10435
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010436// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10437TEST_F(VkLayerTest, InvalidImageLayout) {
10438 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010439 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10440 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010441 // 3 in ValidateCmdBufImageLayouts
10442 // * -1 Attempt to submit cmd buf w/ deleted image
10443 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10444 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010445
10446 ASSERT_NO_FATAL_FAILURE(InitState());
10447 // Create src & dst images to use for copy operations
10448 VkImage src_image;
10449 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010450 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010451
10452 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10453 const int32_t tex_width = 32;
10454 const int32_t tex_height = 32;
10455
10456 VkImageCreateInfo image_create_info = {};
10457 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10458 image_create_info.pNext = NULL;
10459 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10460 image_create_info.format = tex_format;
10461 image_create_info.extent.width = tex_width;
10462 image_create_info.extent.height = tex_height;
10463 image_create_info.extent.depth = 1;
10464 image_create_info.mipLevels = 1;
10465 image_create_info.arrayLayers = 4;
10466 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10467 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10468 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010469 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010470 image_create_info.flags = 0;
10471
10472 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10473 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010474 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010475 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10476 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010477 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10478 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10479 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10480 ASSERT_VK_SUCCESS(err);
10481
10482 // Allocate memory
10483 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010484 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010485 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010486 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10487 mem_alloc.pNext = NULL;
10488 mem_alloc.allocationSize = 0;
10489 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010490
10491 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010492 mem_alloc.allocationSize = img_mem_reqs.size;
10493 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010494 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010495 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010496 ASSERT_VK_SUCCESS(err);
10497
10498 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010499 mem_alloc.allocationSize = img_mem_reqs.size;
10500 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010501 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010502 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010503 ASSERT_VK_SUCCESS(err);
10504
10505 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010506 mem_alloc.allocationSize = img_mem_reqs.size;
10507 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010508 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010509 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010510 ASSERT_VK_SUCCESS(err);
10511
10512 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10513 ASSERT_VK_SUCCESS(err);
10514 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10515 ASSERT_VK_SUCCESS(err);
10516 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10517 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010518
10519 BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010520 VkImageCopy copy_region;
10521 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10522 copy_region.srcSubresource.mipLevel = 0;
10523 copy_region.srcSubresource.baseArrayLayer = 0;
10524 copy_region.srcSubresource.layerCount = 1;
10525 copy_region.srcOffset.x = 0;
10526 copy_region.srcOffset.y = 0;
10527 copy_region.srcOffset.z = 0;
10528 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10529 copy_region.dstSubresource.mipLevel = 0;
10530 copy_region.dstSubresource.baseArrayLayer = 0;
10531 copy_region.dstSubresource.layerCount = 1;
10532 copy_region.dstOffset.x = 0;
10533 copy_region.dstOffset.y = 0;
10534 copy_region.dstOffset.z = 0;
10535 copy_region.extent.width = 1;
10536 copy_region.extent.height = 1;
10537 copy_region.extent.depth = 1;
10538
10539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10540 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10541 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010542 m_errorMonitor->VerifyFound();
10543 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10545 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10546 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010547 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010548 m_errorMonitor->VerifyFound();
10549 // Final src error is due to bad layout type
10550 m_errorMonitor->SetDesiredFailureMsg(
10551 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10552 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010553 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010554 m_errorMonitor->VerifyFound();
10555 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10557 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010558 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010559 m_errorMonitor->VerifyFound();
10560 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10562 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10563 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010564 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010565 m_errorMonitor->VerifyFound();
10566 m_errorMonitor->SetDesiredFailureMsg(
10567 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10568 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010569 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010570 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010571
Cort3b021012016-12-07 12:00:57 -080010572 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10573 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10574 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10575 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10576 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10577 transfer_dst_image_barrier[0].srcAccessMask = 0;
10578 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10579 transfer_dst_image_barrier[0].image = dst_image;
10580 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10581 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10582 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10583 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10584 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10585 transfer_dst_image_barrier[0].image = depth_image;
10586 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10587 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10588 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10589
10590 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010591 VkClearColorValue color_clear_value = {};
10592 VkImageSubresourceRange clear_range;
10593 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10594 clear_range.baseMipLevel = 0;
10595 clear_range.baseArrayLayer = 0;
10596 clear_range.layerCount = 1;
10597 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010598
Cort3b021012016-12-07 12:00:57 -080010599 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10600 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010603 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010604 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010605 // Fail due to provided layout not matching actual current layout for color clear.
10606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010607 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010608 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010609
Cort530cf382016-12-08 09:59:47 -080010610 VkClearDepthStencilValue depth_clear_value = {};
10611 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010612
10613 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10614 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010617 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010618 m_errorMonitor->VerifyFound();
10619 // Fail due to provided layout not matching actual current layout for depth clear.
10620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010621 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010622 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010623
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010624 // Now cause error due to bad image layout transition in PipelineBarrier
10625 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010626 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010627 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010628 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010629 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010630 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10631 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010632 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10634 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10635 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10636 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10637 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010638 m_errorMonitor->VerifyFound();
10639
10640 // Finally some layout errors at RenderPass create time
10641 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10642 VkAttachmentReference attach = {};
10643 // perf warning for GENERAL layout w/ non-DS input attachment
10644 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10645 VkSubpassDescription subpass = {};
10646 subpass.inputAttachmentCount = 1;
10647 subpass.pInputAttachments = &attach;
10648 VkRenderPassCreateInfo rpci = {};
10649 rpci.subpassCount = 1;
10650 rpci.pSubpasses = &subpass;
10651 rpci.attachmentCount = 1;
10652 VkAttachmentDescription attach_desc = {};
10653 attach_desc.format = VK_FORMAT_UNDEFINED;
10654 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010655 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010656 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10658 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010659 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10660 m_errorMonitor->VerifyFound();
10661 // error w/ non-general layout
10662 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10663
10664 m_errorMonitor->SetDesiredFailureMsg(
10665 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10666 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10667 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10668 m_errorMonitor->VerifyFound();
10669 subpass.inputAttachmentCount = 0;
10670 subpass.colorAttachmentCount = 1;
10671 subpass.pColorAttachments = &attach;
10672 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10673 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10675 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010676 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10677 m_errorMonitor->VerifyFound();
10678 // error w/ non-color opt or GENERAL layout for color attachment
10679 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10680 m_errorMonitor->SetDesiredFailureMsg(
10681 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10682 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10683 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10684 m_errorMonitor->VerifyFound();
10685 subpass.colorAttachmentCount = 0;
10686 subpass.pDepthStencilAttachment = &attach;
10687 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10688 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10690 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010691 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10692 m_errorMonitor->VerifyFound();
10693 // error w/ non-ds opt or GENERAL layout for color attachment
10694 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10696 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10697 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010698 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10699 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010700 // For this error we need a valid renderpass so create default one
10701 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10702 attach.attachment = 0;
10703 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10704 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10705 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10706 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10707 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10708 // Can't do a CLEAR load on READ_ONLY initialLayout
10709 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10710 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10711 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10713 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10714 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010715 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10716 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010717
Cort3b021012016-12-07 12:00:57 -080010718 vkFreeMemory(m_device->device(), src_image_mem, NULL);
10719 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
10720 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010721 vkDestroyImage(m_device->device(), src_image, NULL);
10722 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080010723 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010724}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010725
Tobin Ehlise0936662016-10-11 08:10:51 -060010726TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10727 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10728 VkResult err;
10729
10730 ASSERT_NO_FATAL_FAILURE(InitState());
10731
10732 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10733 VkImageTiling tiling;
10734 VkFormatProperties format_properties;
10735 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10736 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10737 tiling = VK_IMAGE_TILING_LINEAR;
10738 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10739 tiling = VK_IMAGE_TILING_OPTIMAL;
10740 } else {
10741 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10742 "skipped.\n");
10743 return;
10744 }
10745
10746 VkDescriptorPoolSize ds_type = {};
10747 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10748 ds_type.descriptorCount = 1;
10749
10750 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10751 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10752 ds_pool_ci.maxSets = 1;
10753 ds_pool_ci.poolSizeCount = 1;
10754 ds_pool_ci.pPoolSizes = &ds_type;
10755 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10756
10757 VkDescriptorPool ds_pool;
10758 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10759 ASSERT_VK_SUCCESS(err);
10760
10761 VkDescriptorSetLayoutBinding dsl_binding = {};
10762 dsl_binding.binding = 0;
10763 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10764 dsl_binding.descriptorCount = 1;
10765 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10766 dsl_binding.pImmutableSamplers = NULL;
10767
10768 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10769 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10770 ds_layout_ci.pNext = NULL;
10771 ds_layout_ci.bindingCount = 1;
10772 ds_layout_ci.pBindings = &dsl_binding;
10773
10774 VkDescriptorSetLayout ds_layout;
10775 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10776 ASSERT_VK_SUCCESS(err);
10777
10778 VkDescriptorSetAllocateInfo alloc_info = {};
10779 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10780 alloc_info.descriptorSetCount = 1;
10781 alloc_info.descriptorPool = ds_pool;
10782 alloc_info.pSetLayouts = &ds_layout;
10783 VkDescriptorSet descriptor_set;
10784 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10785 ASSERT_VK_SUCCESS(err);
10786
10787 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10788 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10789 pipeline_layout_ci.pNext = NULL;
10790 pipeline_layout_ci.setLayoutCount = 1;
10791 pipeline_layout_ci.pSetLayouts = &ds_layout;
10792 VkPipelineLayout pipeline_layout;
10793 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10794 ASSERT_VK_SUCCESS(err);
10795
10796 VkImageObj image(m_device);
10797 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10798 ASSERT_TRUE(image.initialized());
10799 VkImageView view = image.targetView(tex_format);
10800
10801 VkDescriptorImageInfo image_info = {};
10802 image_info.imageView = view;
10803 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10804
10805 VkWriteDescriptorSet descriptor_write = {};
10806 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10807 descriptor_write.dstSet = descriptor_set;
10808 descriptor_write.dstBinding = 0;
10809 descriptor_write.descriptorCount = 1;
10810 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10811 descriptor_write.pImageInfo = &image_info;
10812
10813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10814 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10815 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10816 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10817 m_errorMonitor->VerifyFound();
10818
10819 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10820 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10821 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10822 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10823}
10824
Mark Mueller93b938f2016-08-18 10:27:40 -060010825TEST_F(VkLayerTest, SimultaneousUse) {
10826 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10827 "in primary and secondary command buffers.");
10828
10829 ASSERT_NO_FATAL_FAILURE(InitState());
10830 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10831
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010832 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010833 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10834 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010835
10836 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010837 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010838 command_buffer_allocate_info.commandPool = m_commandPool;
10839 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10840 command_buffer_allocate_info.commandBufferCount = 1;
10841
10842 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010843 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010844 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10845 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010846 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010847 command_buffer_inheritance_info.renderPass = m_renderPass;
10848 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10849 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010850 command_buffer_begin_info.flags =
10851 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010852 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10853
10854 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010855 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10856 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010857 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010858 vkEndCommandBuffer(secondary_command_buffer);
10859
Mark Mueller93b938f2016-08-18 10:27:40 -060010860 VkSubmitInfo submit_info = {};
10861 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10862 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010863 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010864 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010865
Mark Mueller4042b652016-09-05 22:52:21 -060010866 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010867 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10869 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010870 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010871 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10872 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010873
10874 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010875 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10876
Mark Mueller4042b652016-09-05 22:52:21 -060010877 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010878 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010879 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010880
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10882 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010883 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010884 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10885 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010886}
10887
Mark Mueller917f6bc2016-08-30 10:57:19 -060010888TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10889 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10890 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010891 "Delete objects that are inuse. Call VkQueueSubmit "
10892 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010893
10894 ASSERT_NO_FATAL_FAILURE(InitState());
10895 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10896
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010897 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10898 const char *cannot_delete_event_message = "Cannot delete event 0x";
10899 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10900 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010901
10902 BeginCommandBuffer();
10903
10904 VkEvent event;
10905 VkEventCreateInfo event_create_info = {};
10906 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10907 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010908 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010909
Mark Muellerc8d441e2016-08-23 17:36:00 -060010910 EndCommandBuffer();
10911 vkDestroyEvent(m_device->device(), event, nullptr);
10912
10913 VkSubmitInfo submit_info = {};
10914 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10915 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010916 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010918 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10919 m_errorMonitor->VerifyFound();
10920
10921 m_errorMonitor->SetDesiredFailureMsg(0, "");
10922 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10923
10924 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10925
Mark Mueller917f6bc2016-08-30 10:57:19 -060010926 VkSemaphoreCreateInfo semaphore_create_info = {};
10927 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10928 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010929 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010930 VkFenceCreateInfo fence_create_info = {};
10931 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10932 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010933 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010934
10935 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010936 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010937 descriptor_pool_type_count.descriptorCount = 1;
10938
10939 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10940 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10941 descriptor_pool_create_info.maxSets = 1;
10942 descriptor_pool_create_info.poolSizeCount = 1;
10943 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010944 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010945
10946 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010947 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010948
10949 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010950 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010951 descriptorset_layout_binding.descriptorCount = 1;
10952 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10953
10954 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010955 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010956 descriptorset_layout_create_info.bindingCount = 1;
10957 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10958
10959 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010960 ASSERT_VK_SUCCESS(
10961 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010962
10963 VkDescriptorSet descriptorset;
10964 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010965 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010966 descriptorset_allocate_info.descriptorSetCount = 1;
10967 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10968 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010969 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010970
Mark Mueller4042b652016-09-05 22:52:21 -060010971 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10972
10973 VkDescriptorBufferInfo buffer_info = {};
10974 buffer_info.buffer = buffer_test.GetBuffer();
10975 buffer_info.offset = 0;
10976 buffer_info.range = 1024;
10977
10978 VkWriteDescriptorSet write_descriptor_set = {};
10979 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10980 write_descriptor_set.dstSet = descriptorset;
10981 write_descriptor_set.descriptorCount = 1;
10982 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10983 write_descriptor_set.pBufferInfo = &buffer_info;
10984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010985 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010987 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10988 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010989
10990 VkPipelineObj pipe(m_device);
10991 pipe.AddColorAttachment();
10992 pipe.AddShader(&vs);
10993 pipe.AddShader(&fs);
10994
10995 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010996 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010997 pipeline_layout_create_info.setLayoutCount = 1;
10998 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10999
11000 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011001 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011002
11003 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11004
Mark Muellerc8d441e2016-08-23 17:36:00 -060011005 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011006 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011008 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11009 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11010 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011011
Mark Muellerc8d441e2016-08-23 17:36:00 -060011012 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011013
Mark Mueller917f6bc2016-08-30 10:57:19 -060011014 submit_info.signalSemaphoreCount = 1;
11015 submit_info.pSignalSemaphores = &semaphore;
11016 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011017
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011019 vkDestroyEvent(m_device->device(), event, nullptr);
11020 m_errorMonitor->VerifyFound();
11021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011023 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11024 m_errorMonitor->VerifyFound();
11025
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011027 vkDestroyFence(m_device->device(), fence, nullptr);
11028 m_errorMonitor->VerifyFound();
11029
Tobin Ehlis122207b2016-09-01 08:50:06 -070011030 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011031 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11032 vkDestroyFence(m_device->device(), fence, nullptr);
11033 vkDestroyEvent(m_device->device(), event, nullptr);
11034 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011035 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011036 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11037}
11038
Tobin Ehlis2adda372016-09-01 08:51:06 -070011039TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11040 TEST_DESCRIPTION("Delete in-use query pool.");
11041
11042 ASSERT_NO_FATAL_FAILURE(InitState());
11043 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11044
11045 VkQueryPool query_pool;
11046 VkQueryPoolCreateInfo query_pool_ci{};
11047 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11048 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11049 query_pool_ci.queryCount = 1;
11050 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
11051 BeginCommandBuffer();
11052 // Reset query pool to create binding with cmd buffer
11053 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11054
11055 EndCommandBuffer();
11056
11057 VkSubmitInfo submit_info = {};
11058 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11059 submit_info.commandBufferCount = 1;
11060 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11061 // Submit cmd buffer and then destroy query pool while in-flight
11062 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11063
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070011065 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11066 m_errorMonitor->VerifyFound();
11067
11068 vkQueueWaitIdle(m_device->m_queue);
11069 // Now that cmd buffer done we can safely destroy query_pool
11070 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11071}
11072
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011073TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11074 TEST_DESCRIPTION("Delete in-use pipeline.");
11075
11076 ASSERT_NO_FATAL_FAILURE(InitState());
11077 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11078
11079 // Empty pipeline layout used for binding PSO
11080 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11081 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11082 pipeline_layout_ci.setLayoutCount = 0;
11083 pipeline_layout_ci.pSetLayouts = NULL;
11084
11085 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011086 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011087 ASSERT_VK_SUCCESS(err);
11088
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011090 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011091 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11092 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011093 // Store pipeline handle so we can actually delete it before test finishes
11094 VkPipeline delete_this_pipeline;
11095 { // Scope pipeline so it will be auto-deleted
11096 VkPipelineObj pipe(m_device);
11097 pipe.AddShader(&vs);
11098 pipe.AddShader(&fs);
11099 pipe.AddColorAttachment();
11100 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11101 delete_this_pipeline = pipe.handle();
11102
11103 BeginCommandBuffer();
11104 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011105 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011106
11107 EndCommandBuffer();
11108
11109 VkSubmitInfo submit_info = {};
11110 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11111 submit_info.commandBufferCount = 1;
11112 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11113 // Submit cmd buffer and then pipeline destroyed while in-flight
11114 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11115 } // Pipeline deletion triggered here
11116 m_errorMonitor->VerifyFound();
11117 // Make sure queue finished and then actually delete pipeline
11118 vkQueueWaitIdle(m_device->m_queue);
11119 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11120 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11121}
11122
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011123TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11124 TEST_DESCRIPTION("Delete in-use imageView.");
11125
11126 ASSERT_NO_FATAL_FAILURE(InitState());
11127 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11128
11129 VkDescriptorPoolSize ds_type_count;
11130 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11131 ds_type_count.descriptorCount = 1;
11132
11133 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11134 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11135 ds_pool_ci.maxSets = 1;
11136 ds_pool_ci.poolSizeCount = 1;
11137 ds_pool_ci.pPoolSizes = &ds_type_count;
11138
11139 VkDescriptorPool ds_pool;
11140 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11141 ASSERT_VK_SUCCESS(err);
11142
11143 VkSamplerCreateInfo sampler_ci = {};
11144 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11145 sampler_ci.pNext = NULL;
11146 sampler_ci.magFilter = VK_FILTER_NEAREST;
11147 sampler_ci.minFilter = VK_FILTER_NEAREST;
11148 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11149 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11150 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11151 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11152 sampler_ci.mipLodBias = 1.0;
11153 sampler_ci.anisotropyEnable = VK_FALSE;
11154 sampler_ci.maxAnisotropy = 1;
11155 sampler_ci.compareEnable = VK_FALSE;
11156 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11157 sampler_ci.minLod = 1.0;
11158 sampler_ci.maxLod = 1.0;
11159 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11160 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11161 VkSampler sampler;
11162
11163 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11164 ASSERT_VK_SUCCESS(err);
11165
11166 VkDescriptorSetLayoutBinding layout_binding;
11167 layout_binding.binding = 0;
11168 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11169 layout_binding.descriptorCount = 1;
11170 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11171 layout_binding.pImmutableSamplers = NULL;
11172
11173 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11174 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11175 ds_layout_ci.bindingCount = 1;
11176 ds_layout_ci.pBindings = &layout_binding;
11177 VkDescriptorSetLayout ds_layout;
11178 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11179 ASSERT_VK_SUCCESS(err);
11180
11181 VkDescriptorSetAllocateInfo alloc_info = {};
11182 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11183 alloc_info.descriptorSetCount = 1;
11184 alloc_info.descriptorPool = ds_pool;
11185 alloc_info.pSetLayouts = &ds_layout;
11186 VkDescriptorSet descriptor_set;
11187 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11188 ASSERT_VK_SUCCESS(err);
11189
11190 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11191 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11192 pipeline_layout_ci.pNext = NULL;
11193 pipeline_layout_ci.setLayoutCount = 1;
11194 pipeline_layout_ci.pSetLayouts = &ds_layout;
11195
11196 VkPipelineLayout pipeline_layout;
11197 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11198 ASSERT_VK_SUCCESS(err);
11199
11200 VkImageObj image(m_device);
11201 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11202 ASSERT_TRUE(image.initialized());
11203
11204 VkImageView view;
11205 VkImageViewCreateInfo ivci = {};
11206 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11207 ivci.image = image.handle();
11208 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11209 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11210 ivci.subresourceRange.layerCount = 1;
11211 ivci.subresourceRange.baseMipLevel = 0;
11212 ivci.subresourceRange.levelCount = 1;
11213 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11214
11215 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11216 ASSERT_VK_SUCCESS(err);
11217
11218 VkDescriptorImageInfo image_info{};
11219 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11220 image_info.imageView = view;
11221 image_info.sampler = sampler;
11222
11223 VkWriteDescriptorSet descriptor_write = {};
11224 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11225 descriptor_write.dstSet = descriptor_set;
11226 descriptor_write.dstBinding = 0;
11227 descriptor_write.descriptorCount = 1;
11228 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11229 descriptor_write.pImageInfo = &image_info;
11230
11231 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11232
11233 // Create PSO to use the sampler
11234 char const *vsSource = "#version 450\n"
11235 "\n"
11236 "out gl_PerVertex { \n"
11237 " vec4 gl_Position;\n"
11238 "};\n"
11239 "void main(){\n"
11240 " gl_Position = vec4(1);\n"
11241 "}\n";
11242 char const *fsSource = "#version 450\n"
11243 "\n"
11244 "layout(set=0, binding=0) uniform sampler2D s;\n"
11245 "layout(location=0) out vec4 x;\n"
11246 "void main(){\n"
11247 " x = texture(s, vec2(1));\n"
11248 "}\n";
11249 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11250 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11251 VkPipelineObj pipe(m_device);
11252 pipe.AddShader(&vs);
11253 pipe.AddShader(&fs);
11254 pipe.AddColorAttachment();
11255 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11256
11257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
11258
11259 BeginCommandBuffer();
11260 // Bind pipeline to cmd buffer
11261 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11262 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11263 &descriptor_set, 0, nullptr);
11264 Draw(1, 0, 0, 0);
11265 EndCommandBuffer();
11266 // Submit cmd buffer then destroy sampler
11267 VkSubmitInfo submit_info = {};
11268 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11269 submit_info.commandBufferCount = 1;
11270 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11271 // Submit cmd buffer and then destroy imageView while in-flight
11272 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11273
11274 vkDestroyImageView(m_device->device(), view, nullptr);
11275 m_errorMonitor->VerifyFound();
11276 vkQueueWaitIdle(m_device->m_queue);
11277 // Now we can actually destroy imageView
11278 vkDestroyImageView(m_device->device(), view, NULL);
11279 vkDestroySampler(m_device->device(), sampler, nullptr);
11280 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11281 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11282 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11283}
11284
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011285TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11286 TEST_DESCRIPTION("Delete in-use bufferView.");
11287
11288 ASSERT_NO_FATAL_FAILURE(InitState());
11289 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11290
11291 VkDescriptorPoolSize ds_type_count;
11292 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11293 ds_type_count.descriptorCount = 1;
11294
11295 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11296 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11297 ds_pool_ci.maxSets = 1;
11298 ds_pool_ci.poolSizeCount = 1;
11299 ds_pool_ci.pPoolSizes = &ds_type_count;
11300
11301 VkDescriptorPool ds_pool;
11302 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11303 ASSERT_VK_SUCCESS(err);
11304
11305 VkDescriptorSetLayoutBinding layout_binding;
11306 layout_binding.binding = 0;
11307 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11308 layout_binding.descriptorCount = 1;
11309 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11310 layout_binding.pImmutableSamplers = NULL;
11311
11312 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11313 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11314 ds_layout_ci.bindingCount = 1;
11315 ds_layout_ci.pBindings = &layout_binding;
11316 VkDescriptorSetLayout ds_layout;
11317 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11318 ASSERT_VK_SUCCESS(err);
11319
11320 VkDescriptorSetAllocateInfo alloc_info = {};
11321 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11322 alloc_info.descriptorSetCount = 1;
11323 alloc_info.descriptorPool = ds_pool;
11324 alloc_info.pSetLayouts = &ds_layout;
11325 VkDescriptorSet descriptor_set;
11326 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11327 ASSERT_VK_SUCCESS(err);
11328
11329 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11330 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11331 pipeline_layout_ci.pNext = NULL;
11332 pipeline_layout_ci.setLayoutCount = 1;
11333 pipeline_layout_ci.pSetLayouts = &ds_layout;
11334
11335 VkPipelineLayout pipeline_layout;
11336 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11337 ASSERT_VK_SUCCESS(err);
11338
11339 VkBuffer buffer;
11340 uint32_t queue_family_index = 0;
11341 VkBufferCreateInfo buffer_create_info = {};
11342 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11343 buffer_create_info.size = 1024;
11344 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11345 buffer_create_info.queueFamilyIndexCount = 1;
11346 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11347
11348 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11349 ASSERT_VK_SUCCESS(err);
11350
11351 VkMemoryRequirements memory_reqs;
11352 VkDeviceMemory buffer_memory;
11353
11354 VkMemoryAllocateInfo memory_info = {};
11355 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11356 memory_info.allocationSize = 0;
11357 memory_info.memoryTypeIndex = 0;
11358
11359 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11360 memory_info.allocationSize = memory_reqs.size;
11361 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11362 ASSERT_TRUE(pass);
11363
11364 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11365 ASSERT_VK_SUCCESS(err);
11366 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11367 ASSERT_VK_SUCCESS(err);
11368
11369 VkBufferView view;
11370 VkBufferViewCreateInfo bvci = {};
11371 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11372 bvci.buffer = buffer;
11373 bvci.format = VK_FORMAT_R8_UNORM;
11374 bvci.range = VK_WHOLE_SIZE;
11375
11376 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11377 ASSERT_VK_SUCCESS(err);
11378
11379 VkWriteDescriptorSet descriptor_write = {};
11380 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11381 descriptor_write.dstSet = descriptor_set;
11382 descriptor_write.dstBinding = 0;
11383 descriptor_write.descriptorCount = 1;
11384 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11385 descriptor_write.pTexelBufferView = &view;
11386
11387 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11388
11389 char const *vsSource = "#version 450\n"
11390 "\n"
11391 "out gl_PerVertex { \n"
11392 " vec4 gl_Position;\n"
11393 "};\n"
11394 "void main(){\n"
11395 " gl_Position = vec4(1);\n"
11396 "}\n";
11397 char const *fsSource = "#version 450\n"
11398 "\n"
11399 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11400 "layout(location=0) out vec4 x;\n"
11401 "void main(){\n"
11402 " x = imageLoad(s, 0);\n"
11403 "}\n";
11404 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11405 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11406 VkPipelineObj pipe(m_device);
11407 pipe.AddShader(&vs);
11408 pipe.AddShader(&fs);
11409 pipe.AddColorAttachment();
11410 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11411
11412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11413
11414 BeginCommandBuffer();
11415 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11416 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11417 VkRect2D scissor = {{0, 0}, {16, 16}};
11418 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11419 // Bind pipeline to cmd buffer
11420 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11421 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11422 &descriptor_set, 0, nullptr);
11423 Draw(1, 0, 0, 0);
11424 EndCommandBuffer();
11425
11426 VkSubmitInfo submit_info = {};
11427 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11428 submit_info.commandBufferCount = 1;
11429 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11430 // Submit cmd buffer and then destroy bufferView while in-flight
11431 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11432
11433 vkDestroyBufferView(m_device->device(), view, nullptr);
11434 m_errorMonitor->VerifyFound();
11435 vkQueueWaitIdle(m_device->m_queue);
11436 // Now we can actually destroy bufferView
11437 vkDestroyBufferView(m_device->device(), view, NULL);
11438 vkDestroyBuffer(m_device->device(), buffer, NULL);
11439 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11440 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11441 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11442 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11443}
11444
Tobin Ehlis209532e2016-09-07 13:52:18 -060011445TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11446 TEST_DESCRIPTION("Delete in-use sampler.");
11447
11448 ASSERT_NO_FATAL_FAILURE(InitState());
11449 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11450
11451 VkDescriptorPoolSize ds_type_count;
11452 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11453 ds_type_count.descriptorCount = 1;
11454
11455 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11456 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11457 ds_pool_ci.maxSets = 1;
11458 ds_pool_ci.poolSizeCount = 1;
11459 ds_pool_ci.pPoolSizes = &ds_type_count;
11460
11461 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011462 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011463 ASSERT_VK_SUCCESS(err);
11464
11465 VkSamplerCreateInfo sampler_ci = {};
11466 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11467 sampler_ci.pNext = NULL;
11468 sampler_ci.magFilter = VK_FILTER_NEAREST;
11469 sampler_ci.minFilter = VK_FILTER_NEAREST;
11470 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11471 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11472 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11473 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11474 sampler_ci.mipLodBias = 1.0;
11475 sampler_ci.anisotropyEnable = VK_FALSE;
11476 sampler_ci.maxAnisotropy = 1;
11477 sampler_ci.compareEnable = VK_FALSE;
11478 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11479 sampler_ci.minLod = 1.0;
11480 sampler_ci.maxLod = 1.0;
11481 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11482 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11483 VkSampler sampler;
11484
11485 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11486 ASSERT_VK_SUCCESS(err);
11487
11488 VkDescriptorSetLayoutBinding layout_binding;
11489 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011490 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011491 layout_binding.descriptorCount = 1;
11492 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11493 layout_binding.pImmutableSamplers = NULL;
11494
11495 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11496 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11497 ds_layout_ci.bindingCount = 1;
11498 ds_layout_ci.pBindings = &layout_binding;
11499 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011500 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011501 ASSERT_VK_SUCCESS(err);
11502
11503 VkDescriptorSetAllocateInfo alloc_info = {};
11504 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11505 alloc_info.descriptorSetCount = 1;
11506 alloc_info.descriptorPool = ds_pool;
11507 alloc_info.pSetLayouts = &ds_layout;
11508 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011509 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011510 ASSERT_VK_SUCCESS(err);
11511
11512 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11513 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11514 pipeline_layout_ci.pNext = NULL;
11515 pipeline_layout_ci.setLayoutCount = 1;
11516 pipeline_layout_ci.pSetLayouts = &ds_layout;
11517
11518 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011519 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011520 ASSERT_VK_SUCCESS(err);
11521
11522 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011523 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 -060011524 ASSERT_TRUE(image.initialized());
11525
11526 VkImageView view;
11527 VkImageViewCreateInfo ivci = {};
11528 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11529 ivci.image = image.handle();
11530 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11531 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11532 ivci.subresourceRange.layerCount = 1;
11533 ivci.subresourceRange.baseMipLevel = 0;
11534 ivci.subresourceRange.levelCount = 1;
11535 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11536
11537 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11538 ASSERT_VK_SUCCESS(err);
11539
11540 VkDescriptorImageInfo image_info{};
11541 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11542 image_info.imageView = view;
11543 image_info.sampler = sampler;
11544
11545 VkWriteDescriptorSet descriptor_write = {};
11546 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11547 descriptor_write.dstSet = descriptor_set;
11548 descriptor_write.dstBinding = 0;
11549 descriptor_write.descriptorCount = 1;
11550 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11551 descriptor_write.pImageInfo = &image_info;
11552
11553 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11554
11555 // Create PSO to use the sampler
11556 char const *vsSource = "#version 450\n"
11557 "\n"
11558 "out gl_PerVertex { \n"
11559 " vec4 gl_Position;\n"
11560 "};\n"
11561 "void main(){\n"
11562 " gl_Position = vec4(1);\n"
11563 "}\n";
11564 char const *fsSource = "#version 450\n"
11565 "\n"
11566 "layout(set=0, binding=0) uniform sampler2D s;\n"
11567 "layout(location=0) out vec4 x;\n"
11568 "void main(){\n"
11569 " x = texture(s, vec2(1));\n"
11570 "}\n";
11571 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11572 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11573 VkPipelineObj pipe(m_device);
11574 pipe.AddShader(&vs);
11575 pipe.AddShader(&fs);
11576 pipe.AddColorAttachment();
11577 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11578
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011580
11581 BeginCommandBuffer();
11582 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011583 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11584 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11585 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011586 Draw(1, 0, 0, 0);
11587 EndCommandBuffer();
11588 // Submit cmd buffer then destroy sampler
11589 VkSubmitInfo submit_info = {};
11590 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11591 submit_info.commandBufferCount = 1;
11592 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11593 // Submit cmd buffer and then destroy sampler while in-flight
11594 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11595
11596 vkDestroySampler(m_device->device(), sampler, nullptr);
11597 m_errorMonitor->VerifyFound();
11598 vkQueueWaitIdle(m_device->m_queue);
11599 // Now we can actually destroy sampler
11600 vkDestroySampler(m_device->device(), sampler, nullptr);
11601 vkDestroyImageView(m_device->device(), view, NULL);
11602 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11603 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11604 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11605}
11606
Mark Mueller1cd9f412016-08-25 13:23:52 -060011607TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011608 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011609 "signaled but not waited on by the queue. Wait on a "
11610 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011611
11612 ASSERT_NO_FATAL_FAILURE(InitState());
11613 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11614
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011615 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11616 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11617 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011618
11619 BeginCommandBuffer();
11620 EndCommandBuffer();
11621
11622 VkSemaphoreCreateInfo semaphore_create_info = {};
11623 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11624 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011625 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011626 VkSubmitInfo submit_info = {};
11627 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11628 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011629 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011630 submit_info.signalSemaphoreCount = 1;
11631 submit_info.pSignalSemaphores = &semaphore;
11632 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11633 m_errorMonitor->SetDesiredFailureMsg(0, "");
11634 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11635 BeginCommandBuffer();
11636 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011638 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11639 m_errorMonitor->VerifyFound();
11640
Mark Mueller1cd9f412016-08-25 13:23:52 -060011641 VkFenceCreateInfo fence_create_info = {};
11642 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11643 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011644 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011645
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011647 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11648 m_errorMonitor->VerifyFound();
11649
Mark Mueller4042b652016-09-05 22:52:21 -060011650 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011651 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011652 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11653}
11654
Tobin Ehlis4af23302016-07-19 10:50:30 -060011655TEST_F(VkLayerTest, FramebufferIncompatible) {
11656 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11657 "that does not match the framebuffer for the active "
11658 "renderpass.");
11659 ASSERT_NO_FATAL_FAILURE(InitState());
11660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11661
11662 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011663 VkAttachmentDescription attachment = {0,
11664 VK_FORMAT_B8G8R8A8_UNORM,
11665 VK_SAMPLE_COUNT_1_BIT,
11666 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11667 VK_ATTACHMENT_STORE_OP_STORE,
11668 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11669 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11670 VK_IMAGE_LAYOUT_UNDEFINED,
11671 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011672
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011673 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011674
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011675 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011676
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011677 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011678
11679 VkRenderPass rp;
11680 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11681 ASSERT_VK_SUCCESS(err);
11682
11683 // A compatible framebuffer.
11684 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011685 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 -060011686 ASSERT_TRUE(image.initialized());
11687
11688 VkImageViewCreateInfo ivci = {
11689 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11690 nullptr,
11691 0,
11692 image.handle(),
11693 VK_IMAGE_VIEW_TYPE_2D,
11694 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011695 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11696 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011697 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11698 };
11699 VkImageView view;
11700 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11701 ASSERT_VK_SUCCESS(err);
11702
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011703 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011704 VkFramebuffer fb;
11705 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11706 ASSERT_VK_SUCCESS(err);
11707
11708 VkCommandBufferAllocateInfo cbai = {};
11709 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11710 cbai.commandPool = m_commandPool;
11711 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11712 cbai.commandBufferCount = 1;
11713
11714 VkCommandBuffer sec_cb;
11715 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11716 ASSERT_VK_SUCCESS(err);
11717 VkCommandBufferBeginInfo cbbi = {};
11718 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130011719 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060011720 cbii.renderPass = renderPass();
11721 cbii.framebuffer = fb;
11722 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11723 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011724 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 -060011725 cbbi.pInheritanceInfo = &cbii;
11726 vkBeginCommandBuffer(sec_cb, &cbbi);
11727 vkEndCommandBuffer(sec_cb);
11728
Chris Forbes3400bc52016-09-13 18:10:34 +120011729 VkCommandBufferBeginInfo cbbi2 = {
11730 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11731 0, nullptr
11732 };
11733 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11734 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011735
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011737 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011738 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11739 m_errorMonitor->VerifyFound();
11740 // Cleanup
11741 vkDestroyImageView(m_device->device(), view, NULL);
11742 vkDestroyRenderPass(m_device->device(), rp, NULL);
11743 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11744}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011745
11746TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11747 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11748 "invalid value. If logicOp is not available, attempt to "
11749 "use it and verify that we see the correct error.");
11750 ASSERT_NO_FATAL_FAILURE(InitState());
11751 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11752
11753 auto features = m_device->phy().features();
11754 // Set the expected error depending on whether or not logicOp available
11755 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11757 "enabled, logicOpEnable must be "
11758 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011759 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011761 }
11762 // Create a pipeline using logicOp
11763 VkResult err;
11764
11765 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11766 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11767
11768 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011769 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011770 ASSERT_VK_SUCCESS(err);
11771
11772 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11773 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11774 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011775 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011776 vp_state_ci.pViewports = &vp;
11777 vp_state_ci.scissorCount = 1;
11778 VkRect2D scissors = {}; // Dummy scissors to point to
11779 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011780
11781 VkPipelineShaderStageCreateInfo shaderStages[2];
11782 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11783
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011784 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11785 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011786 shaderStages[0] = vs.GetStageCreateInfo();
11787 shaderStages[1] = fs.GetStageCreateInfo();
11788
11789 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11790 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11791
11792 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11793 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11794 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11795
11796 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11797 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011798 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011799
11800 VkPipelineColorBlendAttachmentState att = {};
11801 att.blendEnable = VK_FALSE;
11802 att.colorWriteMask = 0xf;
11803
11804 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11805 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11806 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11807 cb_ci.logicOpEnable = VK_TRUE;
11808 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11809 cb_ci.attachmentCount = 1;
11810 cb_ci.pAttachments = &att;
11811
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011812 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11813 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11814 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11815
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011816 VkGraphicsPipelineCreateInfo gp_ci = {};
11817 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11818 gp_ci.stageCount = 2;
11819 gp_ci.pStages = shaderStages;
11820 gp_ci.pVertexInputState = &vi_ci;
11821 gp_ci.pInputAssemblyState = &ia_ci;
11822 gp_ci.pViewportState = &vp_state_ci;
11823 gp_ci.pRasterizationState = &rs_ci;
11824 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011825 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011826 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11827 gp_ci.layout = pipeline_layout;
11828 gp_ci.renderPass = renderPass();
11829
11830 VkPipelineCacheCreateInfo pc_ci = {};
11831 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11832
11833 VkPipeline pipeline;
11834 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011835 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011836 ASSERT_VK_SUCCESS(err);
11837
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011838 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011839 m_errorMonitor->VerifyFound();
11840 if (VK_SUCCESS == err) {
11841 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11842 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011843 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11844 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11845}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011846#endif // DRAW_STATE_TESTS
11847
Tobin Ehlis0788f522015-05-26 16:11:58 -060011848#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011849#if GTEST_IS_THREADSAFE
11850struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011851 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011852 VkEvent event;
11853 bool bailout;
11854};
11855
Karl Schultz6addd812016-02-02 17:17:23 -070011856extern "C" void *AddToCommandBuffer(void *arg) {
11857 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011858
Mike Stroyana6d14942016-07-13 15:10:05 -060011859 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011860 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011861 if (data->bailout) {
11862 break;
11863 }
11864 }
11865 return NULL;
11866}
11867
Karl Schultz6addd812016-02-02 17:17:23 -070011868TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011869 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011870
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011872
Mike Stroyanaccf7692015-05-12 16:00:45 -060011873 ASSERT_NO_FATAL_FAILURE(InitState());
11874 ASSERT_NO_FATAL_FAILURE(InitViewport());
11875 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11876
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011877 // Calls AllocateCommandBuffers
11878 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011879
11880 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011881 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011882
11883 VkEventCreateInfo event_info;
11884 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011885 VkResult err;
11886
11887 memset(&event_info, 0, sizeof(event_info));
11888 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11889
Chia-I Wuf7458c52015-10-26 21:10:41 +080011890 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011891 ASSERT_VK_SUCCESS(err);
11892
Mike Stroyanaccf7692015-05-12 16:00:45 -060011893 err = vkResetEvent(device(), event);
11894 ASSERT_VK_SUCCESS(err);
11895
11896 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011897 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011898 data.event = event;
11899 data.bailout = false;
11900 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011901
11902 // First do some correct operations using multiple threads.
11903 // Add many entries to command buffer from another thread.
11904 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11905 // Make non-conflicting calls from this thread at the same time.
11906 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011907 uint32_t count;
11908 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011909 }
11910 test_platform_thread_join(thread, NULL);
11911
11912 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011913 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011914 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011915 // Add many entries to command buffer from this thread at the same time.
11916 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011917
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011918 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011919 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011920
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011921 m_errorMonitor->SetBailout(NULL);
11922
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011923 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011924
Chia-I Wuf7458c52015-10-26 21:10:41 +080011925 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011926}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011927#endif // GTEST_IS_THREADSAFE
11928#endif // THREADING_TESTS
11929
Chris Forbes9f7ff632015-05-25 11:13:08 +120011930#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011931TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011932 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11933 "with an impossible code size");
11934
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011936
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011937 ASSERT_NO_FATAL_FAILURE(InitState());
11938 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11939
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011940 VkShaderModule module;
11941 VkShaderModuleCreateInfo moduleCreateInfo;
11942 struct icd_spv_header spv;
11943
11944 spv.magic = ICD_SPV_MAGIC;
11945 spv.version = ICD_SPV_VERSION;
11946 spv.gen_magic = 0;
11947
11948 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11949 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011950 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011951 moduleCreateInfo.codeSize = 4;
11952 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011953 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011954
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011955 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011956}
11957
Karl Schultz6addd812016-02-02 17:17:23 -070011958TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011959 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11960 "with a bad magic number");
11961
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011963
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011964 ASSERT_NO_FATAL_FAILURE(InitState());
11965 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11966
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011967 VkShaderModule module;
11968 VkShaderModuleCreateInfo moduleCreateInfo;
11969 struct icd_spv_header spv;
11970
11971 spv.magic = ~ICD_SPV_MAGIC;
11972 spv.version = ICD_SPV_VERSION;
11973 spv.gen_magic = 0;
11974
11975 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11976 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011977 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011978 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11979 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011980 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011981
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011982 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011983}
11984
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011985#if 0
11986// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011987TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011989 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011990
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011991 ASSERT_NO_FATAL_FAILURE(InitState());
11992 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11993
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011994 VkShaderModule module;
11995 VkShaderModuleCreateInfo moduleCreateInfo;
11996 struct icd_spv_header spv;
11997
11998 spv.magic = ICD_SPV_MAGIC;
11999 spv.version = ~ICD_SPV_VERSION;
12000 spv.gen_magic = 0;
12001
12002 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12003 moduleCreateInfo.pNext = NULL;
12004
Karl Schultz6addd812016-02-02 17:17:23 -070012005 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012006 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12007 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012008 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012009
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012010 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012011}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012012#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012013
Karl Schultz6addd812016-02-02 17:17:23 -070012014TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012015 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
12016 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012018
Chris Forbes9f7ff632015-05-25 11:13:08 +120012019 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012022 char const *vsSource = "#version 450\n"
12023 "\n"
12024 "layout(location=0) out float x;\n"
12025 "out gl_PerVertex {\n"
12026 " vec4 gl_Position;\n"
12027 "};\n"
12028 "void main(){\n"
12029 " gl_Position = vec4(1);\n"
12030 " x = 0;\n"
12031 "}\n";
12032 char const *fsSource = "#version 450\n"
12033 "\n"
12034 "layout(location=0) out vec4 color;\n"
12035 "void main(){\n"
12036 " color = vec4(1);\n"
12037 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012038
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012039 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12040 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012041
12042 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012043 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012044 pipe.AddShader(&vs);
12045 pipe.AddShader(&fs);
12046
Chris Forbes9f7ff632015-05-25 11:13:08 +120012047 VkDescriptorSetObj descriptorSet(m_device);
12048 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012049 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012050
Tony Barbour5781e8f2015-08-04 16:23:11 -060012051 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012052
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012053 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012054}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012055
Mark Mueller098c9cb2016-09-08 09:01:57 -060012056TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12057 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12058
12059 ASSERT_NO_FATAL_FAILURE(InitState());
12060 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12061
12062 const char *bad_specialization_message =
12063 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
12064
12065 char const *vsSource =
12066 "#version 450\n"
12067 "\n"
12068 "out gl_PerVertex {\n"
12069 " vec4 gl_Position;\n"
12070 "};\n"
12071 "void main(){\n"
12072 " gl_Position = vec4(1);\n"
12073 "}\n";
12074
12075 char const *fsSource =
12076 "#version 450\n"
12077 "\n"
12078 "layout (constant_id = 0) const float r = 0.0f;\n"
12079 "layout(location = 0) out vec4 uFragColor;\n"
12080 "void main(){\n"
12081 " uFragColor = vec4(r,1,0,1);\n"
12082 "}\n";
12083
12084 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12085 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12086
12087 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12088 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12089
12090 VkPipelineLayout pipeline_layout;
12091 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12092
12093 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12094 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12095 vp_state_create_info.viewportCount = 1;
12096 VkViewport viewport = {};
12097 vp_state_create_info.pViewports = &viewport;
12098 vp_state_create_info.scissorCount = 1;
12099 VkRect2D scissors = {};
12100 vp_state_create_info.pScissors = &scissors;
12101
12102 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12103
12104 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12105 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12106 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12107 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12108
12109 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
12110 vs.GetStageCreateInfo(),
12111 fs.GetStageCreateInfo()
12112 };
12113
12114 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12115 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12116
12117 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12118 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12119 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12120
12121 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12122 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12123 rasterization_state_create_info.pNext = nullptr;
12124 rasterization_state_create_info.lineWidth = 1.0f;
12125 rasterization_state_create_info.rasterizerDiscardEnable = true;
12126
12127 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12128 color_blend_attachment_state.blendEnable = VK_FALSE;
12129 color_blend_attachment_state.colorWriteMask = 0xf;
12130
12131 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12132 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12133 color_blend_state_create_info.attachmentCount = 1;
12134 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12135
12136 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12137 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12138 graphicspipe_create_info.stageCount = 2;
12139 graphicspipe_create_info.pStages = shader_stage_create_info;
12140 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12141 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12142 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12143 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12144 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12145 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12146 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12147 graphicspipe_create_info.layout = pipeline_layout;
12148 graphicspipe_create_info.renderPass = renderPass();
12149
12150 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12151 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12152
12153 VkPipelineCache pipelineCache;
12154 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12155
12156 // This structure maps constant ids to data locations.
12157 const VkSpecializationMapEntry entry =
12158 // id, offset, size
12159 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12160
12161 uint32_t data = 1;
12162
12163 // Set up the info describing spec map and data
12164 const VkSpecializationInfo specialization_info = {
12165 1,
12166 &entry,
12167 1 * sizeof(float),
12168 &data,
12169 };
12170 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12171
12172 VkPipeline pipeline;
12173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12174 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12175 m_errorMonitor->VerifyFound();
12176
12177 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12178 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12179}
12180
12181TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12182 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12183
12184 ASSERT_NO_FATAL_FAILURE(InitState());
12185 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12186
12187 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12188
12189 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12190 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12191 descriptor_pool_type_count[0].descriptorCount = 1;
12192 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12193 descriptor_pool_type_count[1].descriptorCount = 1;
12194
12195 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12196 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12197 descriptor_pool_create_info.maxSets = 1;
12198 descriptor_pool_create_info.poolSizeCount = 2;
12199 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12200 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12201
12202 VkDescriptorPool descriptorset_pool;
12203 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12204
12205 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12206 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12207 descriptorset_layout_binding.descriptorCount = 1;
12208 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12209
12210 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12211 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12212 descriptorset_layout_create_info.bindingCount = 1;
12213 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12214
12215 VkDescriptorSetLayout descriptorset_layout;
12216 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12217
12218 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12219 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12220 descriptorset_allocate_info.descriptorSetCount = 1;
12221 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12222 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12223 VkDescriptorSet descriptorset;
12224 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12225
12226 // Challenge core_validation with a non uniform buffer type.
12227 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12228
Mark Mueller098c9cb2016-09-08 09:01:57 -060012229 char const *vsSource =
12230 "#version 450\n"
12231 "\n"
12232 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12233 " mat4 mvp;\n"
12234 "} ubuf;\n"
12235 "out gl_PerVertex {\n"
12236 " vec4 gl_Position;\n"
12237 "};\n"
12238 "void main(){\n"
12239 " gl_Position = ubuf.mvp * vec4(1);\n"
12240 "}\n";
12241
12242 char const *fsSource =
12243 "#version 450\n"
12244 "\n"
12245 "layout(location = 0) out vec4 uFragColor;\n"
12246 "void main(){\n"
12247 " uFragColor = vec4(0,1,0,1);\n"
12248 "}\n";
12249
12250 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12251 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12252
12253 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12254 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12255 pipeline_layout_create_info.setLayoutCount = 1;
12256 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12257
12258 VkPipelineLayout pipeline_layout;
12259 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12260
12261 VkPipelineObj pipe(m_device);
12262 pipe.AddColorAttachment();
12263 pipe.AddShader(&vs);
12264 pipe.AddShader(&fs);
12265
12266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12267 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12268 m_errorMonitor->VerifyFound();
12269
12270 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12271 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12272 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12273}
12274
12275TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12276 TEST_DESCRIPTION(
12277 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12278
12279 ASSERT_NO_FATAL_FAILURE(InitState());
12280 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12281
12282 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12283
12284 VkDescriptorPoolSize descriptor_pool_type_count = {};
12285 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12286 descriptor_pool_type_count.descriptorCount = 1;
12287
12288 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12289 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12290 descriptor_pool_create_info.maxSets = 1;
12291 descriptor_pool_create_info.poolSizeCount = 1;
12292 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12293 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12294
12295 VkDescriptorPool descriptorset_pool;
12296 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12297
12298 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12299 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12300 descriptorset_layout_binding.descriptorCount = 1;
12301 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12302 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12303
12304 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12305 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12306 descriptorset_layout_create_info.bindingCount = 1;
12307 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12308
12309 VkDescriptorSetLayout descriptorset_layout;
12310 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12311 nullptr, &descriptorset_layout));
12312
12313 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12314 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12315 descriptorset_allocate_info.descriptorSetCount = 1;
12316 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12317 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12318 VkDescriptorSet descriptorset;
12319 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12320
12321 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12322
Mark Mueller098c9cb2016-09-08 09:01:57 -060012323 char const *vsSource =
12324 "#version 450\n"
12325 "\n"
12326 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12327 " mat4 mvp;\n"
12328 "} ubuf;\n"
12329 "out gl_PerVertex {\n"
12330 " vec4 gl_Position;\n"
12331 "};\n"
12332 "void main(){\n"
12333 " gl_Position = ubuf.mvp * vec4(1);\n"
12334 "}\n";
12335
12336 char const *fsSource =
12337 "#version 450\n"
12338 "\n"
12339 "layout(location = 0) out vec4 uFragColor;\n"
12340 "void main(){\n"
12341 " uFragColor = vec4(0,1,0,1);\n"
12342 "}\n";
12343
12344 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12345 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12346
12347 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12348 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12349 pipeline_layout_create_info.setLayoutCount = 1;
12350 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12351
12352 VkPipelineLayout pipeline_layout;
12353 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12354
12355 VkPipelineObj pipe(m_device);
12356 pipe.AddColorAttachment();
12357 pipe.AddShader(&vs);
12358 pipe.AddShader(&fs);
12359
12360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12361 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12362 m_errorMonitor->VerifyFound();
12363
12364 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12365 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12366 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12367}
12368
12369TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12370 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12371 "accessible from the current shader stage.");
12372
12373 ASSERT_NO_FATAL_FAILURE(InitState());
12374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12375
12376 const char *push_constant_not_accessible_message =
12377 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12378
12379 char const *vsSource =
12380 "#version 450\n"
12381 "\n"
12382 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12383 "out gl_PerVertex {\n"
12384 " vec4 gl_Position;\n"
12385 "};\n"
12386 "void main(){\n"
12387 " gl_Position = vec4(consts.x);\n"
12388 "}\n";
12389
12390 char const *fsSource =
12391 "#version 450\n"
12392 "\n"
12393 "layout(location = 0) out vec4 uFragColor;\n"
12394 "void main(){\n"
12395 " uFragColor = vec4(0,1,0,1);\n"
12396 "}\n";
12397
12398 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12399 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12400
12401 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12402 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12403
12404 // Set up a push constant range
12405 VkPushConstantRange push_constant_ranges = {};
12406 // Set to the wrong stage to challenge core_validation
12407 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12408 push_constant_ranges.size = 4;
12409
12410 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12411 pipeline_layout_create_info.pushConstantRangeCount = 1;
12412
12413 VkPipelineLayout pipeline_layout;
12414 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12415
12416 VkPipelineObj pipe(m_device);
12417 pipe.AddColorAttachment();
12418 pipe.AddShader(&vs);
12419 pipe.AddShader(&fs);
12420
12421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12422 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12423 m_errorMonitor->VerifyFound();
12424
12425 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12426}
12427
12428TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12429 TEST_DESCRIPTION(
12430 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12431
12432 ASSERT_NO_FATAL_FAILURE(InitState());
12433 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12434
12435 const char *feature_not_enabled_message =
12436 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12437
12438 // Some awkward steps are required to test with custom device features.
12439 std::vector<const char *> device_extension_names;
12440 auto features = m_device->phy().features();
12441 // Disable support for 64 bit floats
12442 features.shaderFloat64 = false;
12443 // The sacrificial device object
12444 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12445
12446 char const *vsSource = "#version 450\n"
12447 "\n"
12448 "out gl_PerVertex {\n"
12449 " vec4 gl_Position;\n"
12450 "};\n"
12451 "void main(){\n"
12452 " gl_Position = vec4(1);\n"
12453 "}\n";
12454 char const *fsSource = "#version 450\n"
12455 "\n"
12456 "layout(location=0) out vec4 color;\n"
12457 "void main(){\n"
12458 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12459 " color = vec4(green);\n"
12460 "}\n";
12461
12462 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12463 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12464
12465 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012466
12467 VkPipelineObj pipe(&test_device);
12468 pipe.AddColorAttachment();
12469 pipe.AddShader(&vs);
12470 pipe.AddShader(&fs);
12471
12472 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12473 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12474 VkPipelineLayout pipeline_layout;
12475 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12476
12477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12478 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12479 m_errorMonitor->VerifyFound();
12480
12481 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12482}
12483
12484TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12485 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12486
12487 ASSERT_NO_FATAL_FAILURE(InitState());
12488 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12489
12490 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12491
12492 char const *vsSource = "#version 450\n"
12493 "\n"
12494 "out gl_PerVertex {\n"
12495 " vec4 gl_Position;\n"
12496 "};\n"
12497 "layout(xfb_buffer = 1) out;"
12498 "void main(){\n"
12499 " gl_Position = vec4(1);\n"
12500 "}\n";
12501 char const *fsSource = "#version 450\n"
12502 "\n"
12503 "layout(location=0) out vec4 color;\n"
12504 "void main(){\n"
12505 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12506 " color = vec4(green);\n"
12507 "}\n";
12508
12509 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12510 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12511
12512 VkPipelineObj pipe(m_device);
12513 pipe.AddColorAttachment();
12514 pipe.AddShader(&vs);
12515 pipe.AddShader(&fs);
12516
12517 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12518 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12519 VkPipelineLayout pipeline_layout;
12520 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12521
12522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12523 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12524 m_errorMonitor->VerifyFound();
12525
12526 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12527}
12528
Karl Schultz6addd812016-02-02 17:17:23 -070012529TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012530 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12531 "which is not present in the outputs of the previous stage");
12532
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012534
Chris Forbes59cb88d2015-05-25 11:13:13 +120012535 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012536 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012537
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012538 char const *vsSource = "#version 450\n"
12539 "\n"
12540 "out gl_PerVertex {\n"
12541 " vec4 gl_Position;\n"
12542 "};\n"
12543 "void main(){\n"
12544 " gl_Position = vec4(1);\n"
12545 "}\n";
12546 char const *fsSource = "#version 450\n"
12547 "\n"
12548 "layout(location=0) in float x;\n"
12549 "layout(location=0) out vec4 color;\n"
12550 "void main(){\n"
12551 " color = vec4(x);\n"
12552 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012553
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012554 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12555 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012556
12557 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012558 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012559 pipe.AddShader(&vs);
12560 pipe.AddShader(&fs);
12561
Chris Forbes59cb88d2015-05-25 11:13:13 +120012562 VkDescriptorSetObj descriptorSet(m_device);
12563 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012564 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012565
Tony Barbour5781e8f2015-08-04 16:23:11 -060012566 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012567
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012568 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012569}
12570
Karl Schultz6addd812016-02-02 17:17:23 -070012571TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012572 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12573 "within an interace block, which is not present in the outputs "
12574 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012576
12577 ASSERT_NO_FATAL_FAILURE(InitState());
12578 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12579
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012580 char const *vsSource = "#version 450\n"
12581 "\n"
12582 "out gl_PerVertex {\n"
12583 " vec4 gl_Position;\n"
12584 "};\n"
12585 "void main(){\n"
12586 " gl_Position = vec4(1);\n"
12587 "}\n";
12588 char const *fsSource = "#version 450\n"
12589 "\n"
12590 "in block { layout(location=0) float x; } ins;\n"
12591 "layout(location=0) out vec4 color;\n"
12592 "void main(){\n"
12593 " color = vec4(ins.x);\n"
12594 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012595
12596 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12597 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12598
12599 VkPipelineObj pipe(m_device);
12600 pipe.AddColorAttachment();
12601 pipe.AddShader(&vs);
12602 pipe.AddShader(&fs);
12603
12604 VkDescriptorSetObj descriptorSet(m_device);
12605 descriptorSet.AppendDummy();
12606 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12607
12608 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12609
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012610 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012611}
12612
Karl Schultz6addd812016-02-02 17:17:23 -070012613TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012614 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012615 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12617 "output arr[2] of float32' vs 'ptr to "
12618 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012619
12620 ASSERT_NO_FATAL_FAILURE(InitState());
12621 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012623 char const *vsSource = "#version 450\n"
12624 "\n"
12625 "layout(location=0) out float x[2];\n"
12626 "out gl_PerVertex {\n"
12627 " vec4 gl_Position;\n"
12628 "};\n"
12629 "void main(){\n"
12630 " x[0] = 0; x[1] = 0;\n"
12631 " gl_Position = vec4(1);\n"
12632 "}\n";
12633 char const *fsSource = "#version 450\n"
12634 "\n"
12635 "layout(location=0) in float x[3];\n"
12636 "layout(location=0) out vec4 color;\n"
12637 "void main(){\n"
12638 " color = vec4(x[0] + x[1] + x[2]);\n"
12639 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012640
12641 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12642 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12643
12644 VkPipelineObj pipe(m_device);
12645 pipe.AddColorAttachment();
12646 pipe.AddShader(&vs);
12647 pipe.AddShader(&fs);
12648
12649 VkDescriptorSetObj descriptorSet(m_device);
12650 descriptorSet.AppendDummy();
12651 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12652
12653 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12654
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012655 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012656}
12657
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012658
Karl Schultz6addd812016-02-02 17:17:23 -070012659TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012660 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012661 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012663
Chris Forbesb56af562015-05-25 11:13:17 +120012664 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012666
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012667 char const *vsSource = "#version 450\n"
12668 "\n"
12669 "layout(location=0) out int x;\n"
12670 "out gl_PerVertex {\n"
12671 " vec4 gl_Position;\n"
12672 "};\n"
12673 "void main(){\n"
12674 " x = 0;\n"
12675 " gl_Position = vec4(1);\n"
12676 "}\n";
12677 char const *fsSource = "#version 450\n"
12678 "\n"
12679 "layout(location=0) in float x;\n" /* VS writes int */
12680 "layout(location=0) out vec4 color;\n"
12681 "void main(){\n"
12682 " color = vec4(x);\n"
12683 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012684
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012685 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12686 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012687
12688 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012689 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012690 pipe.AddShader(&vs);
12691 pipe.AddShader(&fs);
12692
Chris Forbesb56af562015-05-25 11:13:17 +120012693 VkDescriptorSetObj descriptorSet(m_device);
12694 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012695 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012696
Tony Barbour5781e8f2015-08-04 16:23:11 -060012697 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012698
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012699 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012700}
12701
Karl Schultz6addd812016-02-02 17:17:23 -070012702TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012703 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012704 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012705 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012707
12708 ASSERT_NO_FATAL_FAILURE(InitState());
12709 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12710
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012711 char const *vsSource = "#version 450\n"
12712 "\n"
12713 "out block { layout(location=0) int x; } outs;\n"
12714 "out gl_PerVertex {\n"
12715 " vec4 gl_Position;\n"
12716 "};\n"
12717 "void main(){\n"
12718 " outs.x = 0;\n"
12719 " gl_Position = vec4(1);\n"
12720 "}\n";
12721 char const *fsSource = "#version 450\n"
12722 "\n"
12723 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12724 "layout(location=0) out vec4 color;\n"
12725 "void main(){\n"
12726 " color = vec4(ins.x);\n"
12727 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012728
12729 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12730 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12731
12732 VkPipelineObj pipe(m_device);
12733 pipe.AddColorAttachment();
12734 pipe.AddShader(&vs);
12735 pipe.AddShader(&fs);
12736
12737 VkDescriptorSetObj descriptorSet(m_device);
12738 descriptorSet.AppendDummy();
12739 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12740
12741 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12742
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012743 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012744}
12745
12746TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012747 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012748 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012749 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012750 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 +130012751
12752 ASSERT_NO_FATAL_FAILURE(InitState());
12753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12754
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012755 char const *vsSource = "#version 450\n"
12756 "\n"
12757 "out block { layout(location=1) float x; } outs;\n"
12758 "out gl_PerVertex {\n"
12759 " vec4 gl_Position;\n"
12760 "};\n"
12761 "void main(){\n"
12762 " outs.x = 0;\n"
12763 " gl_Position = vec4(1);\n"
12764 "}\n";
12765 char const *fsSource = "#version 450\n"
12766 "\n"
12767 "in block { layout(location=0) float x; } ins;\n"
12768 "layout(location=0) out vec4 color;\n"
12769 "void main(){\n"
12770 " color = vec4(ins.x);\n"
12771 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012772
12773 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12774 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12775
12776 VkPipelineObj pipe(m_device);
12777 pipe.AddColorAttachment();
12778 pipe.AddShader(&vs);
12779 pipe.AddShader(&fs);
12780
12781 VkDescriptorSetObj descriptorSet(m_device);
12782 descriptorSet.AppendDummy();
12783 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12784
12785 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12786
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012787 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012788}
12789
12790TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012791 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012792 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012793 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012794 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 +130012795
12796 ASSERT_NO_FATAL_FAILURE(InitState());
12797 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12798
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012799 char const *vsSource = "#version 450\n"
12800 "\n"
12801 "out block { layout(location=0, component=0) float x; } outs;\n"
12802 "out gl_PerVertex {\n"
12803 " vec4 gl_Position;\n"
12804 "};\n"
12805 "void main(){\n"
12806 " outs.x = 0;\n"
12807 " gl_Position = vec4(1);\n"
12808 "}\n";
12809 char const *fsSource = "#version 450\n"
12810 "\n"
12811 "in block { layout(location=0, component=1) float x; } ins;\n"
12812 "layout(location=0) out vec4 color;\n"
12813 "void main(){\n"
12814 " color = vec4(ins.x);\n"
12815 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012816
12817 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12818 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12819
12820 VkPipelineObj pipe(m_device);
12821 pipe.AddColorAttachment();
12822 pipe.AddShader(&vs);
12823 pipe.AddShader(&fs);
12824
12825 VkDescriptorSetObj descriptorSet(m_device);
12826 descriptorSet.AppendDummy();
12827 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12828
12829 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12830
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012831 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012832}
12833
Chris Forbes1f3b0152016-11-30 12:48:40 +130012834TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
12835 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
12836
12837 ASSERT_NO_FATAL_FAILURE(InitState());
12838 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12839
12840 char const *vsSource = "#version 450\n"
12841 "layout(location=0) out mediump float x;\n"
12842 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
12843 char const *fsSource = "#version 450\n"
12844 "layout(location=0) in highp float x;\n"
12845 "layout(location=0) out vec4 color;\n"
12846 "void main() { color = vec4(x); }\n";
12847
12848 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12849 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12850
12851 VkPipelineObj pipe(m_device);
12852 pipe.AddColorAttachment();
12853 pipe.AddShader(&vs);
12854 pipe.AddShader(&fs);
12855
12856 VkDescriptorSetObj descriptorSet(m_device);
12857 descriptorSet.AppendDummy();
12858 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12859
12860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
12861
12862 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12863
12864 m_errorMonitor->VerifyFound();
12865}
12866
Chris Forbes870a39e2016-11-30 12:55:56 +130012867TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
12868 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
12869
12870 ASSERT_NO_FATAL_FAILURE(InitState());
12871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12872
12873 char const *vsSource = "#version 450\n"
12874 "out block { layout(location=0) mediump float x; };\n"
12875 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
12876 char const *fsSource = "#version 450\n"
12877 "in block { layout(location=0) highp float x; };\n"
12878 "layout(location=0) out vec4 color;\n"
12879 "void main() { color = vec4(x); }\n";
12880
12881 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12882 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12883
12884 VkPipelineObj pipe(m_device);
12885 pipe.AddColorAttachment();
12886 pipe.AddShader(&vs);
12887 pipe.AddShader(&fs);
12888
12889 VkDescriptorSetObj descriptorSet(m_device);
12890 descriptorSet.AppendDummy();
12891 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12892
12893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
12894
12895 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12896
12897 m_errorMonitor->VerifyFound();
12898}
12899
Karl Schultz6addd812016-02-02 17:17:23 -070012900TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012901 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12902 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012904
Chris Forbesde136e02015-05-25 11:13:28 +120012905 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012907
12908 VkVertexInputBindingDescription input_binding;
12909 memset(&input_binding, 0, sizeof(input_binding));
12910
12911 VkVertexInputAttributeDescription input_attrib;
12912 memset(&input_attrib, 0, sizeof(input_attrib));
12913 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12914
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012915 char const *vsSource = "#version 450\n"
12916 "\n"
12917 "out gl_PerVertex {\n"
12918 " vec4 gl_Position;\n"
12919 "};\n"
12920 "void main(){\n"
12921 " gl_Position = vec4(1);\n"
12922 "}\n";
12923 char const *fsSource = "#version 450\n"
12924 "\n"
12925 "layout(location=0) out vec4 color;\n"
12926 "void main(){\n"
12927 " color = vec4(1);\n"
12928 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012929
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012930 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12931 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012932
12933 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012934 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012935 pipe.AddShader(&vs);
12936 pipe.AddShader(&fs);
12937
12938 pipe.AddVertexInputBindings(&input_binding, 1);
12939 pipe.AddVertexInputAttribs(&input_attrib, 1);
12940
Chris Forbesde136e02015-05-25 11:13:28 +120012941 VkDescriptorSetObj descriptorSet(m_device);
12942 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012943 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012944
Tony Barbour5781e8f2015-08-04 16:23:11 -060012945 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012946
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012947 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012948}
12949
Karl Schultz6addd812016-02-02 17:17:23 -070012950TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012951 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12952 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012954
12955 ASSERT_NO_FATAL_FAILURE(InitState());
12956 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12957
12958 VkVertexInputBindingDescription input_binding;
12959 memset(&input_binding, 0, sizeof(input_binding));
12960
12961 VkVertexInputAttributeDescription input_attrib;
12962 memset(&input_attrib, 0, sizeof(input_attrib));
12963 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12964
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012965 char const *vsSource = "#version 450\n"
12966 "\n"
12967 "layout(location=1) in float x;\n"
12968 "out gl_PerVertex {\n"
12969 " vec4 gl_Position;\n"
12970 "};\n"
12971 "void main(){\n"
12972 " gl_Position = vec4(x);\n"
12973 "}\n";
12974 char const *fsSource = "#version 450\n"
12975 "\n"
12976 "layout(location=0) out vec4 color;\n"
12977 "void main(){\n"
12978 " color = vec4(1);\n"
12979 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012980
12981 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12982 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12983
12984 VkPipelineObj pipe(m_device);
12985 pipe.AddColorAttachment();
12986 pipe.AddShader(&vs);
12987 pipe.AddShader(&fs);
12988
12989 pipe.AddVertexInputBindings(&input_binding, 1);
12990 pipe.AddVertexInputAttribs(&input_attrib, 1);
12991
12992 VkDescriptorSetObj descriptorSet(m_device);
12993 descriptorSet.AppendDummy();
12994 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12995
12996 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12997
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012998 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012999}
13000
Karl Schultz6addd812016-02-02 17:17:23 -070013001TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013002 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013003 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013004 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 -060013005
Chris Forbes62e8e502015-05-25 11:13:29 +120013006 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013007 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013008
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013009 char const *vsSource = "#version 450\n"
13010 "\n"
13011 "layout(location=0) in vec4 x;\n" /* not provided */
13012 "out gl_PerVertex {\n"
13013 " vec4 gl_Position;\n"
13014 "};\n"
13015 "void main(){\n"
13016 " gl_Position = x;\n"
13017 "}\n";
13018 char const *fsSource = "#version 450\n"
13019 "\n"
13020 "layout(location=0) out vec4 color;\n"
13021 "void main(){\n"
13022 " color = vec4(1);\n"
13023 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013024
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013025 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13026 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013027
13028 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013029 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013030 pipe.AddShader(&vs);
13031 pipe.AddShader(&fs);
13032
Chris Forbes62e8e502015-05-25 11:13:29 +120013033 VkDescriptorSetObj descriptorSet(m_device);
13034 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013035 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013036
Tony Barbour5781e8f2015-08-04 16:23:11 -060013037 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013038
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013039 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013040}
13041
Karl Schultz6addd812016-02-02 17:17:23 -070013042TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013043 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13044 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013045 "vertex shader input that consumes it");
13046 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 -060013047
Chris Forbesc97d98e2015-05-25 11:13:31 +120013048 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013049 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013050
13051 VkVertexInputBindingDescription input_binding;
13052 memset(&input_binding, 0, sizeof(input_binding));
13053
13054 VkVertexInputAttributeDescription input_attrib;
13055 memset(&input_attrib, 0, sizeof(input_attrib));
13056 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13057
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013058 char const *vsSource = "#version 450\n"
13059 "\n"
13060 "layout(location=0) in int x;\n" /* attrib provided float */
13061 "out gl_PerVertex {\n"
13062 " vec4 gl_Position;\n"
13063 "};\n"
13064 "void main(){\n"
13065 " gl_Position = vec4(x);\n"
13066 "}\n";
13067 char const *fsSource = "#version 450\n"
13068 "\n"
13069 "layout(location=0) out vec4 color;\n"
13070 "void main(){\n"
13071 " color = vec4(1);\n"
13072 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013073
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013074 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13075 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013076
13077 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013078 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013079 pipe.AddShader(&vs);
13080 pipe.AddShader(&fs);
13081
13082 pipe.AddVertexInputBindings(&input_binding, 1);
13083 pipe.AddVertexInputAttribs(&input_attrib, 1);
13084
Chris Forbesc97d98e2015-05-25 11:13:31 +120013085 VkDescriptorSetObj descriptorSet(m_device);
13086 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013087 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013088
Tony Barbour5781e8f2015-08-04 16:23:11 -060013089 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013090
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013091 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013092}
13093
Chris Forbesc68b43c2016-04-06 11:18:47 +120013094TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013095 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13096 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13098 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013099
13100 ASSERT_NO_FATAL_FAILURE(InitState());
13101 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13102
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013103 char const *vsSource = "#version 450\n"
13104 "\n"
13105 "out gl_PerVertex {\n"
13106 " vec4 gl_Position;\n"
13107 "};\n"
13108 "void main(){\n"
13109 " gl_Position = vec4(1);\n"
13110 "}\n";
13111 char const *fsSource = "#version 450\n"
13112 "\n"
13113 "layout(location=0) out vec4 color;\n"
13114 "void main(){\n"
13115 " color = vec4(1);\n"
13116 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013117
13118 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13119 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13120
13121 VkPipelineObj pipe(m_device);
13122 pipe.AddColorAttachment();
13123 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060013124 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013125 pipe.AddShader(&fs);
13126
13127 VkDescriptorSetObj descriptorSet(m_device);
13128 descriptorSet.AppendDummy();
13129 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13130
13131 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13132
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013133 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013134}
13135
Chris Forbes82ff92a2016-09-09 10:50:24 +120013136TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
13137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13138 "No entrypoint found named `foo`");
13139
13140 ASSERT_NO_FATAL_FAILURE(InitState());
13141 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13142
13143 char const *vsSource = "#version 450\n"
13144 "out gl_PerVertex {\n"
13145 " vec4 gl_Position;\n"
13146 "};\n"
13147 "void main(){\n"
13148 " gl_Position = vec4(0);\n"
13149 "}\n";
13150 char const *fsSource = "#version 450\n"
13151 "\n"
13152 "layout(location=0) out vec4 color;\n"
13153 "void main(){\n"
13154 " color = vec4(1);\n"
13155 "}\n";
13156
13157 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13158 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13159
13160 VkPipelineObj pipe(m_device);
13161 pipe.AddColorAttachment();
13162 pipe.AddShader(&vs);
13163 pipe.AddShader(&fs);
13164
13165 VkDescriptorSetObj descriptorSet(m_device);
13166 descriptorSet.AppendDummy();
13167 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13168
13169 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13170
13171 m_errorMonitor->VerifyFound();
13172}
13173
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013174TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
13175 m_errorMonitor->SetDesiredFailureMsg(
13176 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13177 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13178 "uses a depth/stencil attachment");
13179
13180 ASSERT_NO_FATAL_FAILURE(InitState());
13181 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13182
13183 char const *vsSource = "#version 450\n"
13184 "void main(){ gl_Position = vec4(0); }\n";
13185 char const *fsSource = "#version 450\n"
13186 "\n"
13187 "layout(location=0) out vec4 color;\n"
13188 "void main(){\n"
13189 " color = vec4(1);\n"
13190 "}\n";
13191
13192 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13193 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13194
13195 VkPipelineObj pipe(m_device);
13196 pipe.AddColorAttachment();
13197 pipe.AddShader(&vs);
13198 pipe.AddShader(&fs);
13199
13200 VkDescriptorSetObj descriptorSet(m_device);
13201 descriptorSet.AppendDummy();
13202 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13203
13204 VkAttachmentDescription attachments[] = {
13205 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
13206 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13207 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13208 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13209 },
13210 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
13211 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13212 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13213 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13214 },
13215 };
13216 VkAttachmentReference refs[] = {
13217 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13218 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13219 };
13220 VkSubpassDescription subpass = {
13221 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13222 1, &refs[0], nullptr, &refs[1],
13223 0, nullptr
13224 };
13225 VkRenderPassCreateInfo rpci = {
13226 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13227 0, 2, attachments, 1, &subpass, 0, nullptr
13228 };
13229 VkRenderPass rp;
13230 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13231 ASSERT_VK_SUCCESS(err);
13232
13233 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13234
13235 m_errorMonitor->VerifyFound();
13236
13237 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13238}
13239
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013240TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013241 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13242 "the TCS without the patch decoration, but consumed in the TES "
13243 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13245 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013246
13247 ASSERT_NO_FATAL_FAILURE(InitState());
13248 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13249
Chris Forbesc1e852d2016-04-04 19:26:42 +120013250 if (!m_device->phy().features().tessellationShader) {
13251 printf("Device does not support tessellation shaders; skipped.\n");
13252 return;
13253 }
13254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013255 char const *vsSource = "#version 450\n"
13256 "void main(){}\n";
13257 char const *tcsSource = "#version 450\n"
13258 "layout(location=0) out int x[];\n"
13259 "layout(vertices=3) out;\n"
13260 "void main(){\n"
13261 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13262 " gl_TessLevelInner[0] = 1;\n"
13263 " x[gl_InvocationID] = gl_InvocationID;\n"
13264 "}\n";
13265 char const *tesSource = "#version 450\n"
13266 "layout(triangles, equal_spacing, cw) in;\n"
13267 "layout(location=0) patch in int x;\n"
13268 "out gl_PerVertex { vec4 gl_Position; };\n"
13269 "void main(){\n"
13270 " gl_Position.xyz = gl_TessCoord;\n"
13271 " gl_Position.w = x;\n"
13272 "}\n";
13273 char const *fsSource = "#version 450\n"
13274 "layout(location=0) out vec4 color;\n"
13275 "void main(){\n"
13276 " color = vec4(1);\n"
13277 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013278
13279 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13280 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13281 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13282 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13283
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013284 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13285 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013286
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013287 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013288
13289 VkPipelineObj pipe(m_device);
13290 pipe.SetInputAssembly(&iasci);
13291 pipe.SetTessellation(&tsci);
13292 pipe.AddColorAttachment();
13293 pipe.AddShader(&vs);
13294 pipe.AddShader(&tcs);
13295 pipe.AddShader(&tes);
13296 pipe.AddShader(&fs);
13297
13298 VkDescriptorSetObj descriptorSet(m_device);
13299 descriptorSet.AppendDummy();
13300 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13301
13302 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13303
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013304 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013305}
13306
Karl Schultz6addd812016-02-02 17:17:23 -070013307TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013308 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13309 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13311 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013312
Chris Forbes280ba2c2015-06-12 11:16:41 +120013313 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013315
13316 /* Two binding descriptions for binding 0 */
13317 VkVertexInputBindingDescription input_bindings[2];
13318 memset(input_bindings, 0, sizeof(input_bindings));
13319
13320 VkVertexInputAttributeDescription input_attrib;
13321 memset(&input_attrib, 0, sizeof(input_attrib));
13322 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13323
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013324 char const *vsSource = "#version 450\n"
13325 "\n"
13326 "layout(location=0) in float x;\n" /* attrib provided float */
13327 "out gl_PerVertex {\n"
13328 " vec4 gl_Position;\n"
13329 "};\n"
13330 "void main(){\n"
13331 " gl_Position = vec4(x);\n"
13332 "}\n";
13333 char const *fsSource = "#version 450\n"
13334 "\n"
13335 "layout(location=0) out vec4 color;\n"
13336 "void main(){\n"
13337 " color = vec4(1);\n"
13338 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013339
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013340 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13341 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013342
13343 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013344 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013345 pipe.AddShader(&vs);
13346 pipe.AddShader(&fs);
13347
13348 pipe.AddVertexInputBindings(input_bindings, 2);
13349 pipe.AddVertexInputAttribs(&input_attrib, 1);
13350
Chris Forbes280ba2c2015-06-12 11:16:41 +120013351 VkDescriptorSetObj descriptorSet(m_device);
13352 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013353 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013354
Tony Barbour5781e8f2015-08-04 16:23:11 -060013355 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013356
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013357 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013358}
Chris Forbes8f68b562015-05-25 11:13:32 +120013359
Karl Schultz6addd812016-02-02 17:17:23 -070013360TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013361 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013362 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013364
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013365 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013366
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013367 char const *vsSource = "#version 450\n"
13368 "\n"
13369 "out gl_PerVertex {\n"
13370 " vec4 gl_Position;\n"
13371 "};\n"
13372 "void main(){\n"
13373 " gl_Position = vec4(1);\n"
13374 "}\n";
13375 char const *fsSource = "#version 450\n"
13376 "\n"
13377 "void main(){\n"
13378 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013379
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013380 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13381 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013382
13383 VkPipelineObj pipe(m_device);
13384 pipe.AddShader(&vs);
13385 pipe.AddShader(&fs);
13386
Chia-I Wu08accc62015-07-07 11:50:03 +080013387 /* set up CB 0, not written */
13388 pipe.AddColorAttachment();
13389 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013390
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013391 VkDescriptorSetObj descriptorSet(m_device);
13392 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013393 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013394
Tony Barbour5781e8f2015-08-04 16:23:11 -060013395 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013396
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013397 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013398}
13399
Karl Schultz6addd812016-02-02 17:17:23 -070013400TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013401 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013402 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013404 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013405
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013406 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013407
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013408 char const *vsSource = "#version 450\n"
13409 "\n"
13410 "out gl_PerVertex {\n"
13411 " vec4 gl_Position;\n"
13412 "};\n"
13413 "void main(){\n"
13414 " gl_Position = vec4(1);\n"
13415 "}\n";
13416 char const *fsSource = "#version 450\n"
13417 "\n"
13418 "layout(location=0) out vec4 x;\n"
13419 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13420 "void main(){\n"
13421 " x = vec4(1);\n"
13422 " y = vec4(1);\n"
13423 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013424
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013425 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13426 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013427
13428 VkPipelineObj pipe(m_device);
13429 pipe.AddShader(&vs);
13430 pipe.AddShader(&fs);
13431
Chia-I Wu08accc62015-07-07 11:50:03 +080013432 /* set up CB 0, not written */
13433 pipe.AddColorAttachment();
13434 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013435 /* FS writes CB 1, but we don't configure it */
13436
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013437 VkDescriptorSetObj descriptorSet(m_device);
13438 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013439 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013440
Tony Barbour5781e8f2015-08-04 16:23:11 -060013441 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013442
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013443 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013444}
13445
Karl Schultz6addd812016-02-02 17:17:23 -070013446TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013447 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013448 "type of an fragment shader output variable, and the format of the corresponding attachment");
13449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013450
Chris Forbesa36d69e2015-05-25 11:13:44 +120013451 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013452
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013453 char const *vsSource = "#version 450\n"
13454 "\n"
13455 "out gl_PerVertex {\n"
13456 " vec4 gl_Position;\n"
13457 "};\n"
13458 "void main(){\n"
13459 " gl_Position = vec4(1);\n"
13460 "}\n";
13461 char const *fsSource = "#version 450\n"
13462 "\n"
13463 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13464 "void main(){\n"
13465 " x = ivec4(1);\n"
13466 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013467
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013468 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13469 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013470
13471 VkPipelineObj pipe(m_device);
13472 pipe.AddShader(&vs);
13473 pipe.AddShader(&fs);
13474
Chia-I Wu08accc62015-07-07 11:50:03 +080013475 /* set up CB 0; type is UNORM by default */
13476 pipe.AddColorAttachment();
13477 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013478
Chris Forbesa36d69e2015-05-25 11:13:44 +120013479 VkDescriptorSetObj descriptorSet(m_device);
13480 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013481 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013482
Tony Barbour5781e8f2015-08-04 16:23:11 -060013483 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013484
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013485 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013486}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013487
Karl Schultz6addd812016-02-02 17:17:23 -070013488TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013489 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13490 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013492
Chris Forbes556c76c2015-08-14 12:04:59 +120013493 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013494
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013495 char const *vsSource = "#version 450\n"
13496 "\n"
13497 "out gl_PerVertex {\n"
13498 " vec4 gl_Position;\n"
13499 "};\n"
13500 "void main(){\n"
13501 " gl_Position = vec4(1);\n"
13502 "}\n";
13503 char const *fsSource = "#version 450\n"
13504 "\n"
13505 "layout(location=0) out vec4 x;\n"
13506 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13507 "void main(){\n"
13508 " x = vec4(bar.y);\n"
13509 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013510
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013511 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13512 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013513
Chris Forbes556c76c2015-08-14 12:04:59 +120013514 VkPipelineObj pipe(m_device);
13515 pipe.AddShader(&vs);
13516 pipe.AddShader(&fs);
13517
13518 /* set up CB 0; type is UNORM by default */
13519 pipe.AddColorAttachment();
13520 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13521
13522 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013523 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013524
13525 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13526
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013527 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013528}
13529
Chris Forbes5c59e902016-02-26 16:56:09 +130013530TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013531 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13532 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013534
13535 ASSERT_NO_FATAL_FAILURE(InitState());
13536
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013537 char const *vsSource = "#version 450\n"
13538 "\n"
13539 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13540 "out gl_PerVertex {\n"
13541 " vec4 gl_Position;\n"
13542 "};\n"
13543 "void main(){\n"
13544 " gl_Position = vec4(consts.x);\n"
13545 "}\n";
13546 char const *fsSource = "#version 450\n"
13547 "\n"
13548 "layout(location=0) out vec4 x;\n"
13549 "void main(){\n"
13550 " x = vec4(1);\n"
13551 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013552
13553 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13554 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13555
13556 VkPipelineObj pipe(m_device);
13557 pipe.AddShader(&vs);
13558 pipe.AddShader(&fs);
13559
13560 /* set up CB 0; type is UNORM by default */
13561 pipe.AddColorAttachment();
13562 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13563
13564 VkDescriptorSetObj descriptorSet(m_device);
13565 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13566
13567 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13568
13569 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013570 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013571}
13572
Chris Forbes3fb17902016-08-22 14:57:55 +120013573TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13574 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13575 "which is not included in the subpass description");
13576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13577 "consumes input attachment index 0 but not provided in subpass");
13578
13579 ASSERT_NO_FATAL_FAILURE(InitState());
13580
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013581 char const *vsSource = "#version 450\n"
13582 "\n"
13583 "out gl_PerVertex {\n"
13584 " vec4 gl_Position;\n"
13585 "};\n"
13586 "void main(){\n"
13587 " gl_Position = vec4(1);\n"
13588 "}\n";
13589 char const *fsSource = "#version 450\n"
13590 "\n"
13591 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13592 "layout(location=0) out vec4 color;\n"
13593 "void main() {\n"
13594 " color = subpassLoad(x);\n"
13595 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013596
13597 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13598 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13599
13600 VkPipelineObj pipe(m_device);
13601 pipe.AddShader(&vs);
13602 pipe.AddShader(&fs);
13603 pipe.AddColorAttachment();
13604 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13605
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013606 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13607 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013608 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013609 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013610 ASSERT_VK_SUCCESS(err);
13611
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013612 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013613 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013614 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013615 ASSERT_VK_SUCCESS(err);
13616
13617 // error here.
13618 pipe.CreateVKPipeline(pl, renderPass());
13619
13620 m_errorMonitor->VerifyFound();
13621
13622 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13623 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13624}
13625
Chris Forbes5a9a0472016-08-22 16:02:09 +120013626TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13627 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13628 "with a format having a different fundamental type");
13629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13630 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13631
13632 ASSERT_NO_FATAL_FAILURE(InitState());
13633
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013634 char const *vsSource = "#version 450\n"
13635 "\n"
13636 "out gl_PerVertex {\n"
13637 " vec4 gl_Position;\n"
13638 "};\n"
13639 "void main(){\n"
13640 " gl_Position = vec4(1);\n"
13641 "}\n";
13642 char const *fsSource = "#version 450\n"
13643 "\n"
13644 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13645 "layout(location=0) out vec4 color;\n"
13646 "void main() {\n"
13647 " color = subpassLoad(x);\n"
13648 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013649
13650 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13651 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13652
13653 VkPipelineObj pipe(m_device);
13654 pipe.AddShader(&vs);
13655 pipe.AddShader(&fs);
13656 pipe.AddColorAttachment();
13657 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13658
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013659 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13660 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013661 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013662 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013663 ASSERT_VK_SUCCESS(err);
13664
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013665 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013666 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013667 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013668 ASSERT_VK_SUCCESS(err);
13669
13670 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013671 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13672 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13673 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13674 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13675 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 +120013676 };
13677 VkAttachmentReference color = {
13678 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13679 };
13680 VkAttachmentReference input = {
13681 1, VK_IMAGE_LAYOUT_GENERAL,
13682 };
13683
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013684 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013685
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013686 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013687 VkRenderPass rp;
13688 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13689 ASSERT_VK_SUCCESS(err);
13690
13691 // error here.
13692 pipe.CreateVKPipeline(pl, rp);
13693
13694 m_errorMonitor->VerifyFound();
13695
13696 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13697 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13698 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13699}
13700
Chris Forbes541f7b02016-08-22 15:30:27 +120013701TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13702 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13703 "which is not included in the subpass description -- array case");
13704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13705 "consumes input attachment index 1 but not provided in subpass");
13706
13707 ASSERT_NO_FATAL_FAILURE(InitState());
13708
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013709 char const *vsSource = "#version 450\n"
13710 "\n"
13711 "out gl_PerVertex {\n"
13712 " vec4 gl_Position;\n"
13713 "};\n"
13714 "void main(){\n"
13715 " gl_Position = vec4(1);\n"
13716 "}\n";
13717 char const *fsSource = "#version 450\n"
13718 "\n"
13719 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13720 "layout(location=0) out vec4 color;\n"
13721 "void main() {\n"
13722 " color = subpassLoad(xs[1]);\n"
13723 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013724
13725 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13726 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13727
13728 VkPipelineObj pipe(m_device);
13729 pipe.AddShader(&vs);
13730 pipe.AddShader(&fs);
13731 pipe.AddColorAttachment();
13732 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13733
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013734 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13735 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013736 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013737 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013738 ASSERT_VK_SUCCESS(err);
13739
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013740 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013741 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013742 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013743 ASSERT_VK_SUCCESS(err);
13744
13745 // error here.
13746 pipe.CreateVKPipeline(pl, renderPass());
13747
13748 m_errorMonitor->VerifyFound();
13749
13750 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13751 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13752}
13753
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013754TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013755 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13756 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013758
13759 ASSERT_NO_FATAL_FAILURE(InitState());
13760
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013761 char const *csSource = "#version 450\n"
13762 "\n"
13763 "layout(local_size_x=1) in;\n"
13764 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13765 "void main(){\n"
13766 " x = vec4(1);\n"
13767 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013768
13769 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13770
13771 VkDescriptorSetObj descriptorSet(m_device);
13772 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13773
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013774 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13775 nullptr,
13776 0,
13777 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13778 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13779 descriptorSet.GetPipelineLayout(),
13780 VK_NULL_HANDLE,
13781 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013782
13783 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013784 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013785
13786 m_errorMonitor->VerifyFound();
13787
13788 if (err == VK_SUCCESS) {
13789 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13790 }
13791}
13792
Chris Forbes22a9b092016-07-19 14:34:05 +120013793TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013794 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13795 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13797 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013798
13799 ASSERT_NO_FATAL_FAILURE(InitState());
13800
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013801 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13802 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013803 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013804 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013805 ASSERT_VK_SUCCESS(err);
13806
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013807 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013808 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013809 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013810 ASSERT_VK_SUCCESS(err);
13811
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013812 char const *csSource = "#version 450\n"
13813 "\n"
13814 "layout(local_size_x=1) in;\n"
13815 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13816 "void main() {\n"
13817 " x.x = 1.0f;\n"
13818 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013819 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13820
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013821 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13822 nullptr,
13823 0,
13824 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13825 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13826 pl,
13827 VK_NULL_HANDLE,
13828 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013829
13830 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013831 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013832
13833 m_errorMonitor->VerifyFound();
13834
13835 if (err == VK_SUCCESS) {
13836 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13837 }
13838
13839 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13840 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13841}
13842
Chris Forbes50020592016-07-27 13:52:41 +120013843TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13844 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13845 "does not match the dimensionality declared in the shader");
13846
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013847 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 +120013848
13849 ASSERT_NO_FATAL_FAILURE(InitState());
13850 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13851
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013852 char const *vsSource = "#version 450\n"
13853 "\n"
13854 "out gl_PerVertex { vec4 gl_Position; };\n"
13855 "void main() { gl_Position = vec4(0); }\n";
13856 char const *fsSource = "#version 450\n"
13857 "\n"
13858 "layout(set=0, binding=0) uniform sampler3D s;\n"
13859 "layout(location=0) out vec4 color;\n"
13860 "void main() {\n"
13861 " color = texture(s, vec3(0));\n"
13862 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013863 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13864 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13865
13866 VkPipelineObj pipe(m_device);
13867 pipe.AddShader(&vs);
13868 pipe.AddShader(&fs);
13869 pipe.AddColorAttachment();
13870
13871 VkTextureObj texture(m_device, nullptr);
13872 VkSamplerObj sampler(m_device);
13873
13874 VkDescriptorSetObj descriptorSet(m_device);
13875 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13876 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13877
13878 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13879 ASSERT_VK_SUCCESS(err);
13880
13881 BeginCommandBuffer();
13882
13883 m_commandBuffer->BindPipeline(pipe);
13884 m_commandBuffer->BindDescriptorSet(descriptorSet);
13885
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013886 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013887 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013888 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013889 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13890
13891 // error produced here.
13892 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13893
13894 m_errorMonitor->VerifyFound();
13895
13896 EndCommandBuffer();
13897}
13898
Chris Forbes5533bfc2016-07-27 14:12:34 +120013899TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13900 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13901 "are consumed via singlesample images types in the shader, or vice versa.");
13902
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013904
13905 ASSERT_NO_FATAL_FAILURE(InitState());
13906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13907
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013908 char const *vsSource = "#version 450\n"
13909 "\n"
13910 "out gl_PerVertex { vec4 gl_Position; };\n"
13911 "void main() { gl_Position = vec4(0); }\n";
13912 char const *fsSource = "#version 450\n"
13913 "\n"
13914 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13915 "layout(location=0) out vec4 color;\n"
13916 "void main() {\n"
13917 " color = texelFetch(s, ivec2(0), 0);\n"
13918 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013919 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13920 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13921
13922 VkPipelineObj pipe(m_device);
13923 pipe.AddShader(&vs);
13924 pipe.AddShader(&fs);
13925 pipe.AddColorAttachment();
13926
13927 VkTextureObj texture(m_device, nullptr);
13928 VkSamplerObj sampler(m_device);
13929
13930 VkDescriptorSetObj descriptorSet(m_device);
13931 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13932 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13933
13934 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13935 ASSERT_VK_SUCCESS(err);
13936
13937 BeginCommandBuffer();
13938
13939 m_commandBuffer->BindPipeline(pipe);
13940 m_commandBuffer->BindDescriptorSet(descriptorSet);
13941
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013942 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013943 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013944 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013945 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13946
13947 // error produced here.
13948 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13949
13950 m_errorMonitor->VerifyFound();
13951
13952 EndCommandBuffer();
13953}
13954
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013955#endif // SHADER_CHECKER_TESTS
13956
13957#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013958TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013960
13961 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013962
13963 // Create an image
13964 VkImage image;
13965
Karl Schultz6addd812016-02-02 17:17:23 -070013966 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13967 const int32_t tex_width = 32;
13968 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013969
13970 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013971 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13972 image_create_info.pNext = NULL;
13973 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13974 image_create_info.format = tex_format;
13975 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013976 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013977 image_create_info.extent.depth = 1;
13978 image_create_info.mipLevels = 1;
13979 image_create_info.arrayLayers = 1;
13980 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13981 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13982 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13983 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013984
13985 // Introduce error by sending down a bogus width extent
13986 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013987 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013988
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013989 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013990}
13991
Mark Youngc48c4c12016-04-11 14:26:49 -060013992TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13994 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013995
13996 ASSERT_NO_FATAL_FAILURE(InitState());
13997
13998 // Create an image
13999 VkImage image;
14000
14001 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14002 const int32_t tex_width = 32;
14003 const int32_t tex_height = 32;
14004
14005 VkImageCreateInfo image_create_info = {};
14006 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14007 image_create_info.pNext = NULL;
14008 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14009 image_create_info.format = tex_format;
14010 image_create_info.extent.width = tex_width;
14011 image_create_info.extent.height = tex_height;
14012 image_create_info.extent.depth = 1;
14013 image_create_info.mipLevels = 1;
14014 image_create_info.arrayLayers = 1;
14015 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14016 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14017 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14018 image_create_info.flags = 0;
14019
14020 // Introduce error by sending down a bogus width extent
14021 image_create_info.extent.width = 0;
14022 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14023
14024 m_errorMonitor->VerifyFound();
14025}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014026#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014027
Tobin Ehliscde08892015-09-22 10:11:37 -060014028#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014029
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014030TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
14031 TEST_DESCRIPTION("Create a render pass with an attachment description "
14032 "format set to VK_FORMAT_UNDEFINED");
14033
14034 ASSERT_NO_FATAL_FAILURE(InitState());
14035 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14036
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014038
14039 VkAttachmentReference color_attach = {};
14040 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14041 color_attach.attachment = 0;
14042 VkSubpassDescription subpass = {};
14043 subpass.colorAttachmentCount = 1;
14044 subpass.pColorAttachments = &color_attach;
14045
14046 VkRenderPassCreateInfo rpci = {};
14047 rpci.subpassCount = 1;
14048 rpci.pSubpasses = &subpass;
14049 rpci.attachmentCount = 1;
14050 VkAttachmentDescription attach_desc = {};
14051 attach_desc.format = VK_FORMAT_UNDEFINED;
14052 rpci.pAttachments = &attach_desc;
14053 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14054 VkRenderPass rp;
14055 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14056
14057 m_errorMonitor->VerifyFound();
14058
14059 if (result == VK_SUCCESS) {
14060 vkDestroyRenderPass(m_device->device(), rp, NULL);
14061 }
14062}
14063
Karl Schultz6addd812016-02-02 17:17:23 -070014064TEST_F(VkLayerTest, InvalidImageView) {
14065 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014066
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014068
Tobin Ehliscde08892015-09-22 10:11:37 -060014069 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014070
Mike Stroyana3082432015-09-25 13:39:21 -060014071 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014072 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014073
Karl Schultz6addd812016-02-02 17:17:23 -070014074 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14075 const int32_t tex_width = 32;
14076 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014077
14078 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014079 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14080 image_create_info.pNext = NULL;
14081 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14082 image_create_info.format = tex_format;
14083 image_create_info.extent.width = tex_width;
14084 image_create_info.extent.height = tex_height;
14085 image_create_info.extent.depth = 1;
14086 image_create_info.mipLevels = 1;
14087 image_create_info.arrayLayers = 1;
14088 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14089 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14090 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14091 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014092
Chia-I Wuf7458c52015-10-26 21:10:41 +080014093 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014094 ASSERT_VK_SUCCESS(err);
14095
14096 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014097 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014098 image_view_create_info.image = image;
14099 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14100 image_view_create_info.format = tex_format;
14101 image_view_create_info.subresourceRange.layerCount = 1;
14102 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
14103 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014104 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014105
14106 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014107 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014108
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014109 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014110 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014111}
Mike Stroyana3082432015-09-25 13:39:21 -060014112
Mark Youngd339ba32016-05-30 13:28:35 -060014113TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14114 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014116 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014117
14118 ASSERT_NO_FATAL_FAILURE(InitState());
14119
14120 // Create an image and try to create a view with no memory backing the image
14121 VkImage image;
14122
14123 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14124 const int32_t tex_width = 32;
14125 const int32_t tex_height = 32;
14126
14127 VkImageCreateInfo image_create_info = {};
14128 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14129 image_create_info.pNext = NULL;
14130 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14131 image_create_info.format = tex_format;
14132 image_create_info.extent.width = tex_width;
14133 image_create_info.extent.height = tex_height;
14134 image_create_info.extent.depth = 1;
14135 image_create_info.mipLevels = 1;
14136 image_create_info.arrayLayers = 1;
14137 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14138 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14139 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14140 image_create_info.flags = 0;
14141
14142 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14143 ASSERT_VK_SUCCESS(err);
14144
14145 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014146 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014147 image_view_create_info.image = image;
14148 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14149 image_view_create_info.format = tex_format;
14150 image_view_create_info.subresourceRange.layerCount = 1;
14151 image_view_create_info.subresourceRange.baseMipLevel = 0;
14152 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014153 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014154
14155 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014156 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014157
14158 m_errorMonitor->VerifyFound();
14159 vkDestroyImage(m_device->device(), image, NULL);
14160 // If last error is success, it still created the view, so delete it.
14161 if (err == VK_SUCCESS) {
14162 vkDestroyImageView(m_device->device(), view, NULL);
14163 }
Mark Youngd339ba32016-05-30 13:28:35 -060014164}
14165
Karl Schultz6addd812016-02-02 17:17:23 -070014166TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014167 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014169 "formats must have ONLY the "
14170 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14172 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014173
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014174 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014175
Karl Schultz6addd812016-02-02 17:17:23 -070014176 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014177 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014178 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014179 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014180
14181 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014182 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014183 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014184 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14185 image_view_create_info.format = tex_format;
14186 image_view_create_info.subresourceRange.baseMipLevel = 0;
14187 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014188 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014189 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014190 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014191
14192 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014193 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014194
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014195 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014196}
14197
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014198TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014199 VkResult err;
14200 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014201
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14203 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014204
Mike Stroyana3082432015-09-25 13:39:21 -060014205 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014206
14207 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014208 VkImage srcImage;
14209 VkImage dstImage;
14210 VkDeviceMemory srcMem;
14211 VkDeviceMemory destMem;
14212 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014213
14214 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014215 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14216 image_create_info.pNext = NULL;
14217 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14218 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14219 image_create_info.extent.width = 32;
14220 image_create_info.extent.height = 32;
14221 image_create_info.extent.depth = 1;
14222 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014223 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014224 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14225 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14226 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14227 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014228
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014229 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014230 ASSERT_VK_SUCCESS(err);
14231
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014232 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014233 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014234 ASSERT_VK_SUCCESS(err);
14235
14236 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014237 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014238 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14239 memAlloc.pNext = NULL;
14240 memAlloc.allocationSize = 0;
14241 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014242
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014243 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014244 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014245 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014246 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014247 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014248 ASSERT_VK_SUCCESS(err);
14249
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014250 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014251 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014252 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014253 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014254 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014255 ASSERT_VK_SUCCESS(err);
14256
14257 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14258 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014259 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014260 ASSERT_VK_SUCCESS(err);
14261
14262 BeginCommandBuffer();
14263 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014264 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014265 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014266 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014267 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014268 copyRegion.srcOffset.x = 0;
14269 copyRegion.srcOffset.y = 0;
14270 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014271 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014272 copyRegion.dstSubresource.mipLevel = 0;
14273 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014274 // Introduce failure by forcing the dst layerCount to differ from src
14275 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014276 copyRegion.dstOffset.x = 0;
14277 copyRegion.dstOffset.y = 0;
14278 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014279 copyRegion.extent.width = 1;
14280 copyRegion.extent.height = 1;
14281 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014282 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014283 EndCommandBuffer();
14284
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014285 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014286
Chia-I Wuf7458c52015-10-26 21:10:41 +080014287 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014288 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014289 vkFreeMemory(m_device->device(), srcMem, NULL);
14290 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014291}
14292
Tony Barbourd6673642016-05-05 14:46:39 -060014293TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14294
14295 TEST_DESCRIPTION("Creating images with unsuported formats ");
14296
14297 ASSERT_NO_FATAL_FAILURE(InitState());
14298 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14299 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014300 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 -060014301 VK_IMAGE_TILING_OPTIMAL, 0);
14302 ASSERT_TRUE(image.initialized());
14303
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014304 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014305 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014306 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014307 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14308 image_create_info.format = VK_FORMAT_UNDEFINED;
14309 image_create_info.extent.width = 32;
14310 image_create_info.extent.height = 32;
14311 image_create_info.extent.depth = 1;
14312 image_create_info.mipLevels = 1;
14313 image_create_info.arrayLayers = 1;
14314 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14315 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14316 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014317
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14319 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014320
14321 VkImage localImage;
14322 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14323 m_errorMonitor->VerifyFound();
14324
Tony Barbourd6673642016-05-05 14:46:39 -060014325 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014326 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014327 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14328 VkFormat format = static_cast<VkFormat>(f);
14329 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014330 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014331 unsupported = format;
14332 break;
14333 }
14334 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014335
Tony Barbourd6673642016-05-05 14:46:39 -060014336 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014337 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014339
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014340 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014341 m_errorMonitor->VerifyFound();
14342 }
14343}
14344
14345TEST_F(VkLayerTest, ImageLayerViewTests) {
14346 VkResult ret;
14347 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14348
14349 ASSERT_NO_FATAL_FAILURE(InitState());
14350
14351 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014352 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 -060014353 VK_IMAGE_TILING_OPTIMAL, 0);
14354 ASSERT_TRUE(image.initialized());
14355
14356 VkImageView imgView;
14357 VkImageViewCreateInfo imgViewInfo = {};
14358 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14359 imgViewInfo.image = image.handle();
14360 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14361 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14362 imgViewInfo.subresourceRange.layerCount = 1;
14363 imgViewInfo.subresourceRange.baseMipLevel = 0;
14364 imgViewInfo.subresourceRange.levelCount = 1;
14365 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14366
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060014368 // View can't have baseMipLevel >= image's mipLevels - Expect
14369 // VIEW_CREATE_ERROR
14370 imgViewInfo.subresourceRange.baseMipLevel = 1;
14371 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14372 m_errorMonitor->VerifyFound();
14373 imgViewInfo.subresourceRange.baseMipLevel = 0;
14374
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014376 // View can't have baseArrayLayer >= image's arraySize - Expect
14377 // VIEW_CREATE_ERROR
14378 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14379 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14380 m_errorMonitor->VerifyFound();
14381 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14382
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14384 "pCreateInfo->subresourceRange."
14385 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014386 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14387 imgViewInfo.subresourceRange.levelCount = 0;
14388 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14389 m_errorMonitor->VerifyFound();
14390 imgViewInfo.subresourceRange.levelCount = 1;
14391
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14393 "pCreateInfo->subresourceRange."
14394 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014395 m_errorMonitor->SetDesiredFailureMsg(
14396 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14397 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014398 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14399 imgViewInfo.subresourceRange.layerCount = 0;
14400 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14401 m_errorMonitor->VerifyFound();
14402 imgViewInfo.subresourceRange.layerCount = 1;
14403
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14406 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14407 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014408 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14409 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14410 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14411 m_errorMonitor->VerifyFound();
14412 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14415 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14416 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014417 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14418 // VIEW_CREATE_ERROR
14419 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14420 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14421 m_errorMonitor->VerifyFound();
14422 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14423
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14425 "differing formats but they must be "
14426 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014427 // TODO: Update framework to easily passing mutable flag into ImageObj init
14428 // For now just allowing image for this one test to not have memory bound
14429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14430 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014431 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14432 // VIEW_CREATE_ERROR
14433 VkImageCreateInfo mutImgInfo = image.create_info();
14434 VkImage mutImage;
14435 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014436 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014437 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14438 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14439 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14440 ASSERT_VK_SUCCESS(ret);
14441 imgViewInfo.image = mutImage;
14442 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14443 m_errorMonitor->VerifyFound();
14444 imgViewInfo.image = image.handle();
14445 vkDestroyImage(m_device->handle(), mutImage, NULL);
14446}
14447
14448TEST_F(VkLayerTest, MiscImageLayerTests) {
14449
14450 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14451
14452 ASSERT_NO_FATAL_FAILURE(InitState());
14453
14454 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014455 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 -060014456 VK_IMAGE_TILING_OPTIMAL, 0);
14457 ASSERT_TRUE(image.initialized());
14458
Tony Barbourd6673642016-05-05 14:46:39 -060014459 vk_testing::Buffer buffer;
14460 VkMemoryPropertyFlags reqs = 0;
14461 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14462 VkBufferImageCopy region = {};
14463 region.bufferRowLength = 128;
14464 region.bufferImageHeight = 128;
14465 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14466 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014467 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014468 region.imageExtent.height = 4;
14469 region.imageExtent.width = 4;
14470 region.imageExtent.depth = 1;
14471 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014472
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014473 // Image must have offset.z of 0 and extent.depth of 1
14474 // Introduce failure by setting imageExtent.depth to 0
14475 region.imageExtent.depth = 0;
14476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14477 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14478 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14479 m_errorMonitor->VerifyFound();
14480
14481 region.imageExtent.depth = 1;
14482
14483 // Image must have offset.z of 0 and extent.depth of 1
14484 // Introduce failure by setting imageOffset.z to 4
14485 region.imageOffset.z = 4;
14486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14487 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14488 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14489 m_errorMonitor->VerifyFound();
14490
14491 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014492 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14493 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14494 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014496 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14497 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014498 m_errorMonitor->VerifyFound();
14499
14500 // BufferOffset must be a multiple of 4
14501 // Introduce failure by setting bufferOffset to a value not divisible by 4
14502 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014504 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14505 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014506 m_errorMonitor->VerifyFound();
14507
14508 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14509 region.bufferOffset = 0;
14510 region.imageExtent.height = 128;
14511 region.imageExtent.width = 128;
14512 // Introduce failure by setting bufferRowLength > 0 but less than width
14513 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014515 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14516 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014517 m_errorMonitor->VerifyFound();
14518
14519 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14520 region.bufferRowLength = 128;
14521 // Introduce failure by setting bufferRowHeight > 0 but less than height
14522 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014524 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14525 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014526 m_errorMonitor->VerifyFound();
14527
14528 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14530 "If the format of srcImage is a depth, stencil, depth stencil or "
14531 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014532 // Expect INVALID_FILTER
14533 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014534 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 -060014535 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014536 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 -060014537 VkImageBlit blitRegion = {};
14538 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14539 blitRegion.srcSubresource.baseArrayLayer = 0;
14540 blitRegion.srcSubresource.layerCount = 1;
14541 blitRegion.srcSubresource.mipLevel = 0;
14542 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14543 blitRegion.dstSubresource.baseArrayLayer = 0;
14544 blitRegion.dstSubresource.layerCount = 1;
14545 blitRegion.dstSubresource.mipLevel = 0;
14546
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014547 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14548 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014549 m_errorMonitor->VerifyFound();
14550
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014551 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14553 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14554 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014555 m_errorMonitor->VerifyFound();
14556
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014558 VkImageMemoryBarrier img_barrier;
14559 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14560 img_barrier.pNext = NULL;
14561 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14562 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14563 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14564 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14565 img_barrier.image = image.handle();
14566 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14567 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14568 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14569 img_barrier.subresourceRange.baseArrayLayer = 0;
14570 img_barrier.subresourceRange.baseMipLevel = 0;
14571 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14572 img_barrier.subresourceRange.layerCount = 0;
14573 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014574 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14575 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014576 m_errorMonitor->VerifyFound();
14577 img_barrier.subresourceRange.layerCount = 1;
14578}
14579
14580TEST_F(VkLayerTest, ImageFormatLimits) {
14581
14582 TEST_DESCRIPTION("Exceed the limits of image format ");
14583
Cody Northropc31a84f2016-08-22 10:41:47 -060014584 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014586 VkImageCreateInfo image_create_info = {};
14587 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14588 image_create_info.pNext = NULL;
14589 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14590 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14591 image_create_info.extent.width = 32;
14592 image_create_info.extent.height = 32;
14593 image_create_info.extent.depth = 1;
14594 image_create_info.mipLevels = 1;
14595 image_create_info.arrayLayers = 1;
14596 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14597 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14598 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14599 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14600 image_create_info.flags = 0;
14601
14602 VkImage nullImg;
14603 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014604 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14605 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014606 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14607 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14608 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14609 m_errorMonitor->VerifyFound();
14610 image_create_info.extent.depth = 1;
14611
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014613 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14614 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14615 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14616 m_errorMonitor->VerifyFound();
14617 image_create_info.mipLevels = 1;
14618
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014620 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14621 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14622 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14623 m_errorMonitor->VerifyFound();
14624 image_create_info.arrayLayers = 1;
14625
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014627 int samples = imgFmtProps.sampleCounts >> 1;
14628 image_create_info.samples = (VkSampleCountFlagBits)samples;
14629 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14630 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14631 m_errorMonitor->VerifyFound();
14632 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14633
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14635 "VK_IMAGE_LAYOUT_UNDEFINED or "
14636 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014637 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14638 // Expect INVALID_LAYOUT
14639 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14640 m_errorMonitor->VerifyFound();
14641 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14642}
14643
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014644TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14645
14646 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014648
14649 ASSERT_NO_FATAL_FAILURE(InitState());
14650
14651 VkImageObj src_image(m_device);
14652 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14653 VkImageObj dst_image(m_device);
14654 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14655
14656 BeginCommandBuffer();
14657 VkImageCopy copy_region;
14658 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14659 copy_region.srcSubresource.mipLevel = 0;
14660 copy_region.srcSubresource.baseArrayLayer = 0;
14661 copy_region.srcSubresource.layerCount = 0;
14662 copy_region.srcOffset.x = 0;
14663 copy_region.srcOffset.y = 0;
14664 copy_region.srcOffset.z = 0;
14665 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14666 copy_region.dstSubresource.mipLevel = 0;
14667 copy_region.dstSubresource.baseArrayLayer = 0;
14668 copy_region.dstSubresource.layerCount = 0;
14669 copy_region.dstOffset.x = 0;
14670 copy_region.dstOffset.y = 0;
14671 copy_region.dstOffset.z = 0;
14672 copy_region.extent.width = 64;
14673 copy_region.extent.height = 64;
14674 copy_region.extent.depth = 1;
14675 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14676 &copy_region);
14677 EndCommandBuffer();
14678
14679 m_errorMonitor->VerifyFound();
14680}
14681
14682TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14683
14684 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014686
14687 ASSERT_NO_FATAL_FAILURE(InitState());
14688
14689 VkImageObj src_image(m_device);
14690 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14691 VkImageObj dst_image(m_device);
14692 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14693
14694 BeginCommandBuffer();
14695 VkImageCopy copy_region;
14696 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14697 copy_region.srcSubresource.mipLevel = 0;
14698 copy_region.srcSubresource.baseArrayLayer = 0;
14699 copy_region.srcSubresource.layerCount = 0;
14700 copy_region.srcOffset.x = 0;
14701 copy_region.srcOffset.y = 0;
14702 copy_region.srcOffset.z = 0;
14703 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14704 copy_region.dstSubresource.mipLevel = 0;
14705 copy_region.dstSubresource.baseArrayLayer = 0;
14706 copy_region.dstSubresource.layerCount = 0;
14707 copy_region.dstOffset.x = 0;
14708 copy_region.dstOffset.y = 0;
14709 copy_region.dstOffset.z = 0;
14710 copy_region.extent.width = 64;
14711 copy_region.extent.height = 64;
14712 copy_region.extent.depth = 1;
14713 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14714 &copy_region);
14715 EndCommandBuffer();
14716
14717 m_errorMonitor->VerifyFound();
14718}
14719
Karl Schultz6addd812016-02-02 17:17:23 -070014720TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014721 VkResult err;
14722 bool pass;
14723
14724 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14726 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014727
14728 ASSERT_NO_FATAL_FAILURE(InitState());
14729
14730 // Create two images of different types and try to copy between them
14731 VkImage srcImage;
14732 VkImage dstImage;
14733 VkDeviceMemory srcMem;
14734 VkDeviceMemory destMem;
14735 VkMemoryRequirements memReqs;
14736
14737 VkImageCreateInfo image_create_info = {};
14738 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14739 image_create_info.pNext = NULL;
14740 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14741 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14742 image_create_info.extent.width = 32;
14743 image_create_info.extent.height = 32;
14744 image_create_info.extent.depth = 1;
14745 image_create_info.mipLevels = 1;
14746 image_create_info.arrayLayers = 1;
14747 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14748 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14749 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14750 image_create_info.flags = 0;
14751
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014752 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014753 ASSERT_VK_SUCCESS(err);
14754
14755 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14756 // Introduce failure by creating second image with a different-sized format.
14757 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14758
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014759 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014760 ASSERT_VK_SUCCESS(err);
14761
14762 // Allocate memory
14763 VkMemoryAllocateInfo memAlloc = {};
14764 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14765 memAlloc.pNext = NULL;
14766 memAlloc.allocationSize = 0;
14767 memAlloc.memoryTypeIndex = 0;
14768
14769 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14770 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014771 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014772 ASSERT_TRUE(pass);
14773 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14774 ASSERT_VK_SUCCESS(err);
14775
14776 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14777 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014778 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014779 ASSERT_TRUE(pass);
14780 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14781 ASSERT_VK_SUCCESS(err);
14782
14783 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14784 ASSERT_VK_SUCCESS(err);
14785 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14786 ASSERT_VK_SUCCESS(err);
14787
14788 BeginCommandBuffer();
14789 VkImageCopy copyRegion;
14790 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14791 copyRegion.srcSubresource.mipLevel = 0;
14792 copyRegion.srcSubresource.baseArrayLayer = 0;
14793 copyRegion.srcSubresource.layerCount = 0;
14794 copyRegion.srcOffset.x = 0;
14795 copyRegion.srcOffset.y = 0;
14796 copyRegion.srcOffset.z = 0;
14797 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14798 copyRegion.dstSubresource.mipLevel = 0;
14799 copyRegion.dstSubresource.baseArrayLayer = 0;
14800 copyRegion.dstSubresource.layerCount = 0;
14801 copyRegion.dstOffset.x = 0;
14802 copyRegion.dstOffset.y = 0;
14803 copyRegion.dstOffset.z = 0;
14804 copyRegion.extent.width = 1;
14805 copyRegion.extent.height = 1;
14806 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014807 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014808 EndCommandBuffer();
14809
14810 m_errorMonitor->VerifyFound();
14811
14812 vkDestroyImage(m_device->device(), srcImage, NULL);
14813 vkDestroyImage(m_device->device(), dstImage, NULL);
14814 vkFreeMemory(m_device->device(), srcMem, NULL);
14815 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014816}
14817
Karl Schultz6addd812016-02-02 17:17:23 -070014818TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14819 VkResult err;
14820 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014821
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014822 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14824 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014825
Mike Stroyana3082432015-09-25 13:39:21 -060014826 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014827
14828 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014829 VkImage srcImage;
14830 VkImage dstImage;
14831 VkDeviceMemory srcMem;
14832 VkDeviceMemory destMem;
14833 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014834
14835 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014836 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14837 image_create_info.pNext = NULL;
14838 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14839 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14840 image_create_info.extent.width = 32;
14841 image_create_info.extent.height = 32;
14842 image_create_info.extent.depth = 1;
14843 image_create_info.mipLevels = 1;
14844 image_create_info.arrayLayers = 1;
14845 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14846 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14847 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14848 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014849
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014850 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014851 ASSERT_VK_SUCCESS(err);
14852
Karl Schultzbdb75952016-04-19 11:36:49 -060014853 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14854
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014855 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014856 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014857 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014858 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014859
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014860 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014861 ASSERT_VK_SUCCESS(err);
14862
14863 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014864 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014865 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14866 memAlloc.pNext = NULL;
14867 memAlloc.allocationSize = 0;
14868 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014869
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014870 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014871 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014872 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014873 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014874 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014875 ASSERT_VK_SUCCESS(err);
14876
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014877 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014878 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014879 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014880 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014881 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014882 ASSERT_VK_SUCCESS(err);
14883
14884 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14885 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014886 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014887 ASSERT_VK_SUCCESS(err);
14888
14889 BeginCommandBuffer();
14890 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014891 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014892 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014893 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014894 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014895 copyRegion.srcOffset.x = 0;
14896 copyRegion.srcOffset.y = 0;
14897 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014898 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014899 copyRegion.dstSubresource.mipLevel = 0;
14900 copyRegion.dstSubresource.baseArrayLayer = 0;
14901 copyRegion.dstSubresource.layerCount = 0;
14902 copyRegion.dstOffset.x = 0;
14903 copyRegion.dstOffset.y = 0;
14904 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014905 copyRegion.extent.width = 1;
14906 copyRegion.extent.height = 1;
14907 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014908 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014909 EndCommandBuffer();
14910
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014911 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014912
Chia-I Wuf7458c52015-10-26 21:10:41 +080014913 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014914 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014915 vkFreeMemory(m_device->device(), srcMem, NULL);
14916 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014917}
14918
Karl Schultz6addd812016-02-02 17:17:23 -070014919TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14920 VkResult err;
14921 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014922
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14924 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014925
Mike Stroyana3082432015-09-25 13:39:21 -060014926 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014927
14928 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014929 VkImage srcImage;
14930 VkImage dstImage;
14931 VkDeviceMemory srcMem;
14932 VkDeviceMemory destMem;
14933 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014934
14935 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014936 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14937 image_create_info.pNext = NULL;
14938 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14939 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14940 image_create_info.extent.width = 32;
14941 image_create_info.extent.height = 1;
14942 image_create_info.extent.depth = 1;
14943 image_create_info.mipLevels = 1;
14944 image_create_info.arrayLayers = 1;
14945 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14946 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14947 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14948 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014949
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014950 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014951 ASSERT_VK_SUCCESS(err);
14952
Karl Schultz6addd812016-02-02 17:17:23 -070014953 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014954
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014955 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014956 ASSERT_VK_SUCCESS(err);
14957
14958 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014959 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014960 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14961 memAlloc.pNext = NULL;
14962 memAlloc.allocationSize = 0;
14963 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014964
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014965 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014966 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014967 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014968 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014969 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014970 ASSERT_VK_SUCCESS(err);
14971
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014972 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014973 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014974 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014975 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014976 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014977 ASSERT_VK_SUCCESS(err);
14978
14979 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14980 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014981 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014982 ASSERT_VK_SUCCESS(err);
14983
14984 BeginCommandBuffer();
14985 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014986 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14987 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014988 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014989 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014990 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014991 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014992 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014993 resolveRegion.srcOffset.x = 0;
14994 resolveRegion.srcOffset.y = 0;
14995 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014996 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014997 resolveRegion.dstSubresource.mipLevel = 0;
14998 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014999 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015000 resolveRegion.dstOffset.x = 0;
15001 resolveRegion.dstOffset.y = 0;
15002 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015003 resolveRegion.extent.width = 1;
15004 resolveRegion.extent.height = 1;
15005 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015006 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015007 EndCommandBuffer();
15008
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015009 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015010
Chia-I Wuf7458c52015-10-26 21:10:41 +080015011 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015012 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015013 vkFreeMemory(m_device->device(), srcMem, NULL);
15014 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015015}
15016
Karl Schultz6addd812016-02-02 17:17:23 -070015017TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15018 VkResult err;
15019 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015020
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15022 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015023
Mike Stroyana3082432015-09-25 13:39:21 -060015024 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015025
Chris Forbesa7530692016-05-08 12:35:39 +120015026 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015027 VkImage srcImage;
15028 VkImage dstImage;
15029 VkDeviceMemory srcMem;
15030 VkDeviceMemory destMem;
15031 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015032
15033 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015034 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15035 image_create_info.pNext = NULL;
15036 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15037 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15038 image_create_info.extent.width = 32;
15039 image_create_info.extent.height = 1;
15040 image_create_info.extent.depth = 1;
15041 image_create_info.mipLevels = 1;
15042 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015043 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015044 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
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_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015048 image_create_info.flags = 0;
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, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015051 ASSERT_VK_SUCCESS(err);
15052
Karl Schultz6addd812016-02-02 17:17:23 -070015053 // Note: Some implementations expect color attachment usage for any
15054 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015055 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015056
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015057 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015058 ASSERT_VK_SUCCESS(err);
15059
15060 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015061 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015062 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15063 memAlloc.pNext = NULL;
15064 memAlloc.allocationSize = 0;
15065 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015066
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015067 vkGetImageMemoryRequirements(m_device->device(), srcImage, &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, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015072 ASSERT_VK_SUCCESS(err);
15073
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015074 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015075 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015076 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015077 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015078 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015079 ASSERT_VK_SUCCESS(err);
15080
15081 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15082 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015083 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015084 ASSERT_VK_SUCCESS(err);
15085
15086 BeginCommandBuffer();
15087 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015088 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15089 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015090 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015091 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015092 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015093 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015094 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015095 resolveRegion.srcOffset.x = 0;
15096 resolveRegion.srcOffset.y = 0;
15097 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015098 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015099 resolveRegion.dstSubresource.mipLevel = 0;
15100 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015101 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015102 resolveRegion.dstOffset.x = 0;
15103 resolveRegion.dstOffset.y = 0;
15104 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015105 resolveRegion.extent.width = 1;
15106 resolveRegion.extent.height = 1;
15107 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015108 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015109 EndCommandBuffer();
15110
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015111 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015112
Chia-I Wuf7458c52015-10-26 21:10:41 +080015113 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015114 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015115 vkFreeMemory(m_device->device(), srcMem, NULL);
15116 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015117}
15118
Karl Schultz6addd812016-02-02 17:17:23 -070015119TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15120 VkResult err;
15121 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015122
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15124 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015125
Mike Stroyana3082432015-09-25 13:39:21 -060015126 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015127
15128 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015129 VkImage srcImage;
15130 VkImage dstImage;
15131 VkDeviceMemory srcMem;
15132 VkDeviceMemory destMem;
15133 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015134
15135 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015136 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15137 image_create_info.pNext = NULL;
15138 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15139 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15140 image_create_info.extent.width = 32;
15141 image_create_info.extent.height = 1;
15142 image_create_info.extent.depth = 1;
15143 image_create_info.mipLevels = 1;
15144 image_create_info.arrayLayers = 1;
15145 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15146 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15147 // Note: Some implementations expect color attachment usage for any
15148 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015149 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015150 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015151
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015152 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015153 ASSERT_VK_SUCCESS(err);
15154
Karl Schultz6addd812016-02-02 17:17:23 -070015155 // Set format to something other than source image
15156 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15157 // Note: Some implementations expect color attachment usage for any
15158 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015159 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015160 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015161
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015162 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015163 ASSERT_VK_SUCCESS(err);
15164
15165 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015166 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015167 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15168 memAlloc.pNext = NULL;
15169 memAlloc.allocationSize = 0;
15170 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015171
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015172 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015173 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015174 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015175 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015176 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015177 ASSERT_VK_SUCCESS(err);
15178
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015179 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015180 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015181 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015182 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015183 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015184 ASSERT_VK_SUCCESS(err);
15185
15186 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15187 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015188 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015189 ASSERT_VK_SUCCESS(err);
15190
15191 BeginCommandBuffer();
15192 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015193 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15194 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015195 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015196 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015197 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015198 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015199 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015200 resolveRegion.srcOffset.x = 0;
15201 resolveRegion.srcOffset.y = 0;
15202 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015203 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015204 resolveRegion.dstSubresource.mipLevel = 0;
15205 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015206 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015207 resolveRegion.dstOffset.x = 0;
15208 resolveRegion.dstOffset.y = 0;
15209 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015210 resolveRegion.extent.width = 1;
15211 resolveRegion.extent.height = 1;
15212 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015213 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015214 EndCommandBuffer();
15215
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015216 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015217
Chia-I Wuf7458c52015-10-26 21:10:41 +080015218 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015219 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015220 vkFreeMemory(m_device->device(), srcMem, NULL);
15221 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015222}
15223
Karl Schultz6addd812016-02-02 17:17:23 -070015224TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15225 VkResult err;
15226 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015227
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15229 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015230
Mike Stroyana3082432015-09-25 13:39:21 -060015231 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015232
15233 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015234 VkImage srcImage;
15235 VkImage dstImage;
15236 VkDeviceMemory srcMem;
15237 VkDeviceMemory destMem;
15238 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015239
15240 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015241 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15242 image_create_info.pNext = NULL;
15243 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15244 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15245 image_create_info.extent.width = 32;
15246 image_create_info.extent.height = 1;
15247 image_create_info.extent.depth = 1;
15248 image_create_info.mipLevels = 1;
15249 image_create_info.arrayLayers = 1;
15250 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15251 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15252 // Note: Some implementations expect color attachment usage for any
15253 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015254 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015255 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015256
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015257 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015258 ASSERT_VK_SUCCESS(err);
15259
Karl Schultz6addd812016-02-02 17:17:23 -070015260 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15261 // Note: Some implementations expect color attachment usage for any
15262 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015263 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015264 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015266 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015267 ASSERT_VK_SUCCESS(err);
15268
15269 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015270 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015271 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15272 memAlloc.pNext = NULL;
15273 memAlloc.allocationSize = 0;
15274 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015275
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015276 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015277 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015278 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015279 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015280 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015281 ASSERT_VK_SUCCESS(err);
15282
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015283 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015284 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015285 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015286 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015287 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015288 ASSERT_VK_SUCCESS(err);
15289
15290 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15291 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015292 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015293 ASSERT_VK_SUCCESS(err);
15294
15295 BeginCommandBuffer();
15296 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015297 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15298 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015299 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015300 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015301 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015302 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015303 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015304 resolveRegion.srcOffset.x = 0;
15305 resolveRegion.srcOffset.y = 0;
15306 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015307 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015308 resolveRegion.dstSubresource.mipLevel = 0;
15309 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015310 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015311 resolveRegion.dstOffset.x = 0;
15312 resolveRegion.dstOffset.y = 0;
15313 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015314 resolveRegion.extent.width = 1;
15315 resolveRegion.extent.height = 1;
15316 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015317 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015318 EndCommandBuffer();
15319
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015320 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015321
Chia-I Wuf7458c52015-10-26 21:10:41 +080015322 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015323 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015324 vkFreeMemory(m_device->device(), srcMem, NULL);
15325 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015326}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015327
Karl Schultz6addd812016-02-02 17:17:23 -070015328TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015329 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015330 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15331 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015332 // The image format check comes 2nd in validation so we trigger it first,
15333 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015334 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015335
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15337 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015338
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015339 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015340
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015341 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015342 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15343 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015344
15345 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015346 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15347 ds_pool_ci.pNext = NULL;
15348 ds_pool_ci.maxSets = 1;
15349 ds_pool_ci.poolSizeCount = 1;
15350 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015351
15352 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015353 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015354 ASSERT_VK_SUCCESS(err);
15355
15356 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015357 dsl_binding.binding = 0;
15358 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15359 dsl_binding.descriptorCount = 1;
15360 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15361 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015362
15363 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015364 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15365 ds_layout_ci.pNext = NULL;
15366 ds_layout_ci.bindingCount = 1;
15367 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015368 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015369 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015370 ASSERT_VK_SUCCESS(err);
15371
15372 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015373 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015374 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015375 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015376 alloc_info.descriptorPool = ds_pool;
15377 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015378 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015379 ASSERT_VK_SUCCESS(err);
15380
Karl Schultz6addd812016-02-02 17:17:23 -070015381 VkImage image_bad;
15382 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015383 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015384 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015385 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015386 const int32_t tex_width = 32;
15387 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015388
15389 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015390 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15391 image_create_info.pNext = NULL;
15392 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15393 image_create_info.format = tex_format_bad;
15394 image_create_info.extent.width = tex_width;
15395 image_create_info.extent.height = tex_height;
15396 image_create_info.extent.depth = 1;
15397 image_create_info.mipLevels = 1;
15398 image_create_info.arrayLayers = 1;
15399 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15400 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015401 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015402 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015403
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015404 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015405 ASSERT_VK_SUCCESS(err);
15406 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015407 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15408 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015409 ASSERT_VK_SUCCESS(err);
15410
15411 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015412 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015413 image_view_create_info.image = image_bad;
15414 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15415 image_view_create_info.format = tex_format_bad;
15416 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15417 image_view_create_info.subresourceRange.baseMipLevel = 0;
15418 image_view_create_info.subresourceRange.layerCount = 1;
15419 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015420 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015421
15422 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015423 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015424
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015425 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015426
Chia-I Wuf7458c52015-10-26 21:10:41 +080015427 vkDestroyImage(m_device->device(), image_bad, NULL);
15428 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015429 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15430 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015431}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015432
15433TEST_F(VkLayerTest, ClearImageErrors) {
15434 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15435 "ClearDepthStencilImage with a color image.");
15436
15437 ASSERT_NO_FATAL_FAILURE(InitState());
15438 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15439
15440 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15441 BeginCommandBuffer();
15442 m_commandBuffer->EndRenderPass();
15443
15444 // Color image
15445 VkClearColorValue clear_color;
15446 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15447 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15448 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15449 const int32_t img_width = 32;
15450 const int32_t img_height = 32;
15451 VkImageCreateInfo image_create_info = {};
15452 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15453 image_create_info.pNext = NULL;
15454 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15455 image_create_info.format = color_format;
15456 image_create_info.extent.width = img_width;
15457 image_create_info.extent.height = img_height;
15458 image_create_info.extent.depth = 1;
15459 image_create_info.mipLevels = 1;
15460 image_create_info.arrayLayers = 1;
15461 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15462 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15463 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15464
15465 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015466 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015467
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015468 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015469
15470 // Depth/Stencil image
15471 VkClearDepthStencilValue clear_value = {0};
15472 reqs = 0; // don't need HOST_VISIBLE DS image
15473 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15474 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15475 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15476 ds_image_create_info.extent.width = 64;
15477 ds_image_create_info.extent.height = 64;
15478 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15479 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15480
15481 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015482 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015483
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015484 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 -060015485
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015487
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015488 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015489 &color_range);
15490
15491 m_errorMonitor->VerifyFound();
15492
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15494 "image created without "
15495 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015496
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015497 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015498 &color_range);
15499
15500 m_errorMonitor->VerifyFound();
15501
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015502 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15504 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015505
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015506 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15507 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015508
15509 m_errorMonitor->VerifyFound();
15510}
Tobin Ehliscde08892015-09-22 10:11:37 -060015511#endif // IMAGE_TESTS
15512
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015513
15514// WSI Enabled Tests
15515//
Chris Forbes09368e42016-10-13 11:59:22 +130015516#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015517TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15518
15519#if defined(VK_USE_PLATFORM_XCB_KHR)
15520 VkSurfaceKHR surface = VK_NULL_HANDLE;
15521
15522 VkResult err;
15523 bool pass;
15524 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15525 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15526 // uint32_t swapchain_image_count = 0;
15527 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15528 // uint32_t image_index = 0;
15529 // VkPresentInfoKHR present_info = {};
15530
15531 ASSERT_NO_FATAL_FAILURE(InitState());
15532
15533 // Use the create function from one of the VK_KHR_*_surface extension in
15534 // order to create a surface, testing all known errors in the process,
15535 // before successfully creating a surface:
15536 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15538 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15539 pass = (err != VK_SUCCESS);
15540 ASSERT_TRUE(pass);
15541 m_errorMonitor->VerifyFound();
15542
15543 // Next, try to create a surface with the wrong
15544 // VkXcbSurfaceCreateInfoKHR::sType:
15545 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15546 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15548 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15549 pass = (err != VK_SUCCESS);
15550 ASSERT_TRUE(pass);
15551 m_errorMonitor->VerifyFound();
15552
15553 // Create a native window, and then correctly create a surface:
15554 xcb_connection_t *connection;
15555 xcb_screen_t *screen;
15556 xcb_window_t xcb_window;
15557 xcb_intern_atom_reply_t *atom_wm_delete_window;
15558
15559 const xcb_setup_t *setup;
15560 xcb_screen_iterator_t iter;
15561 int scr;
15562 uint32_t value_mask, value_list[32];
15563 int width = 1;
15564 int height = 1;
15565
15566 connection = xcb_connect(NULL, &scr);
15567 ASSERT_TRUE(connection != NULL);
15568 setup = xcb_get_setup(connection);
15569 iter = xcb_setup_roots_iterator(setup);
15570 while (scr-- > 0)
15571 xcb_screen_next(&iter);
15572 screen = iter.data;
15573
15574 xcb_window = xcb_generate_id(connection);
15575
15576 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15577 value_list[0] = screen->black_pixel;
15578 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15579
15580 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15581 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15582
15583 /* Magic code that will send notification when window is destroyed */
15584 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15585 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15586
15587 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15588 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15589 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15590 free(reply);
15591
15592 xcb_map_window(connection, xcb_window);
15593
15594 // Force the x/y coordinates to 100,100 results are identical in consecutive
15595 // runs
15596 const uint32_t coords[] = { 100, 100 };
15597 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15598
15599 // Finally, try to correctly create a surface:
15600 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15601 xcb_create_info.pNext = NULL;
15602 xcb_create_info.flags = 0;
15603 xcb_create_info.connection = connection;
15604 xcb_create_info.window = xcb_window;
15605 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15606 pass = (err == VK_SUCCESS);
15607 ASSERT_TRUE(pass);
15608
15609 // Check if surface supports presentation:
15610
15611 // 1st, do so without having queried the queue families:
15612 VkBool32 supported = false;
15613 // TODO: Get the following error to come out:
15614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15615 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15616 "function");
15617 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15618 pass = (err != VK_SUCCESS);
15619 // ASSERT_TRUE(pass);
15620 // m_errorMonitor->VerifyFound();
15621
15622 // Next, query a queue family index that's too large:
15623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15624 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15625 pass = (err != VK_SUCCESS);
15626 ASSERT_TRUE(pass);
15627 m_errorMonitor->VerifyFound();
15628
15629 // Finally, do so correctly:
15630 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15631 // SUPPORTED
15632 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15633 pass = (err == VK_SUCCESS);
15634 ASSERT_TRUE(pass);
15635
15636 // Before proceeding, try to create a swapchain without having called
15637 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15638 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15639 swapchain_create_info.pNext = NULL;
15640 swapchain_create_info.flags = 0;
15641 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15642 swapchain_create_info.surface = surface;
15643 swapchain_create_info.imageArrayLayers = 1;
15644 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15645 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15647 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15648 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15649 pass = (err != VK_SUCCESS);
15650 ASSERT_TRUE(pass);
15651 m_errorMonitor->VerifyFound();
15652
15653 // Get the surface capabilities:
15654 VkSurfaceCapabilitiesKHR surface_capabilities;
15655
15656 // Do so correctly (only error logged by this entrypoint is if the
15657 // extension isn't enabled):
15658 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15659 pass = (err == VK_SUCCESS);
15660 ASSERT_TRUE(pass);
15661
15662 // Get the surface formats:
15663 uint32_t surface_format_count;
15664
15665 // First, try without a pointer to surface_format_count:
15666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15667 "specified as NULL");
15668 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15669 pass = (err == VK_SUCCESS);
15670 ASSERT_TRUE(pass);
15671 m_errorMonitor->VerifyFound();
15672
15673 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15674 // correctly done a 1st try (to get the count):
15675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15676 surface_format_count = 0;
15677 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15678 pass = (err == VK_SUCCESS);
15679 ASSERT_TRUE(pass);
15680 m_errorMonitor->VerifyFound();
15681
15682 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15683 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15684 pass = (err == VK_SUCCESS);
15685 ASSERT_TRUE(pass);
15686
15687 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15688 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15689
15690 // Next, do a 2nd try with surface_format_count being set too high:
15691 surface_format_count += 5;
15692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15693 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15694 pass = (err == VK_SUCCESS);
15695 ASSERT_TRUE(pass);
15696 m_errorMonitor->VerifyFound();
15697
15698 // Finally, do a correct 1st and 2nd try:
15699 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15700 pass = (err == VK_SUCCESS);
15701 ASSERT_TRUE(pass);
15702 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15703 pass = (err == VK_SUCCESS);
15704 ASSERT_TRUE(pass);
15705
15706 // Get the surface present modes:
15707 uint32_t surface_present_mode_count;
15708
15709 // First, try without a pointer to surface_format_count:
15710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15711 "specified as NULL");
15712
15713 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15714 pass = (err == VK_SUCCESS);
15715 ASSERT_TRUE(pass);
15716 m_errorMonitor->VerifyFound();
15717
15718 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15719 // correctly done a 1st try (to get the count):
15720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15721 surface_present_mode_count = 0;
15722 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15723 (VkPresentModeKHR *)&surface_present_mode_count);
15724 pass = (err == VK_SUCCESS);
15725 ASSERT_TRUE(pass);
15726 m_errorMonitor->VerifyFound();
15727
15728 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15729 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15730 pass = (err == VK_SUCCESS);
15731 ASSERT_TRUE(pass);
15732
15733 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15734 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15735
15736 // Next, do a 2nd try with surface_format_count being set too high:
15737 surface_present_mode_count += 5;
15738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15739 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15740 pass = (err == VK_SUCCESS);
15741 ASSERT_TRUE(pass);
15742 m_errorMonitor->VerifyFound();
15743
15744 // Finally, do a correct 1st and 2nd try:
15745 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15746 pass = (err == VK_SUCCESS);
15747 ASSERT_TRUE(pass);
15748 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15749 pass = (err == VK_SUCCESS);
15750 ASSERT_TRUE(pass);
15751
15752 // Create a swapchain:
15753
15754 // First, try without a pointer to swapchain_create_info:
15755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15756 "specified as NULL");
15757
15758 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15759 pass = (err != VK_SUCCESS);
15760 ASSERT_TRUE(pass);
15761 m_errorMonitor->VerifyFound();
15762
15763 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15764 // sType:
15765 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15767
15768 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15769 pass = (err != VK_SUCCESS);
15770 ASSERT_TRUE(pass);
15771 m_errorMonitor->VerifyFound();
15772
15773 // Next, call with a NULL swapchain pointer:
15774 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15775 swapchain_create_info.pNext = NULL;
15776 swapchain_create_info.flags = 0;
15777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15778 "specified as NULL");
15779
15780 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15781 pass = (err != VK_SUCCESS);
15782 ASSERT_TRUE(pass);
15783 m_errorMonitor->VerifyFound();
15784
15785 // TODO: Enhance swapchain layer so that
15786 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15787
15788 // Next, call with a queue family index that's too large:
15789 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15790 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15791 swapchain_create_info.queueFamilyIndexCount = 2;
15792 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15794 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15795 pass = (err != VK_SUCCESS);
15796 ASSERT_TRUE(pass);
15797 m_errorMonitor->VerifyFound();
15798
15799 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15800 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15801 swapchain_create_info.queueFamilyIndexCount = 1;
15802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15803 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15804 "pCreateInfo->pQueueFamilyIndices).");
15805 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15806 pass = (err != VK_SUCCESS);
15807 ASSERT_TRUE(pass);
15808 m_errorMonitor->VerifyFound();
15809
15810 // Next, call with an invalid imageSharingMode:
15811 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15812 swapchain_create_info.queueFamilyIndexCount = 1;
15813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15814 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15815 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15816 pass = (err != VK_SUCCESS);
15817 ASSERT_TRUE(pass);
15818 m_errorMonitor->VerifyFound();
15819 // Fix for the future:
15820 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15821 // SUPPORTED
15822 swapchain_create_info.queueFamilyIndexCount = 0;
15823 queueFamilyIndex[0] = 0;
15824 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15825
15826 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15827 // Get the images from a swapchain:
15828 // Acquire an image from a swapchain:
15829 // Present an image to a swapchain:
15830 // Destroy the swapchain:
15831
15832 // TODOs:
15833 //
15834 // - Try destroying the device without first destroying the swapchain
15835 //
15836 // - Try destroying the device without first destroying the surface
15837 //
15838 // - Try destroying the surface without first destroying the swapchain
15839
15840 // Destroy the surface:
15841 vkDestroySurfaceKHR(instance(), surface, NULL);
15842
15843 // Tear down the window:
15844 xcb_destroy_window(connection, xcb_window);
15845 xcb_disconnect(connection);
15846
15847#else // VK_USE_PLATFORM_XCB_KHR
15848 return;
15849#endif // VK_USE_PLATFORM_XCB_KHR
15850}
Chris Forbes09368e42016-10-13 11:59:22 +130015851#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015852
15853//
15854// POSITIVE VALIDATION TESTS
15855//
15856// These tests do not expect to encounter ANY validation errors pass only if this is true
15857
Tobin Ehlise0006882016-11-03 10:14:28 -060015858TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15859 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15860 "by a transition in the primary.");
15861 VkResult err;
15862 m_errorMonitor->ExpectSuccess();
15863 ASSERT_NO_FATAL_FAILURE(InitState());
15864 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15865 // Allocate a secondary and primary cmd buffer
15866 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15867 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15868 command_buffer_allocate_info.commandPool = m_commandPool;
15869 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15870 command_buffer_allocate_info.commandBufferCount = 1;
15871
15872 VkCommandBuffer secondary_command_buffer;
15873 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15874 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15875 VkCommandBuffer primary_command_buffer;
15876 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15877 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15878 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15879 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15880 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15881 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15882 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15883
15884 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15885 ASSERT_VK_SUCCESS(err);
15886 VkImageObj image(m_device);
15887 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15888 ASSERT_TRUE(image.initialized());
15889 VkImageMemoryBarrier img_barrier = {};
15890 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15891 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15892 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15893 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15894 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15895 img_barrier.image = image.handle();
15896 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15897 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15898 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15899 img_barrier.subresourceRange.baseArrayLayer = 0;
15900 img_barrier.subresourceRange.baseMipLevel = 0;
15901 img_barrier.subresourceRange.layerCount = 1;
15902 img_barrier.subresourceRange.levelCount = 1;
15903 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15904 0, nullptr, 1, &img_barrier);
15905 err = vkEndCommandBuffer(secondary_command_buffer);
15906 ASSERT_VK_SUCCESS(err);
15907
15908 // Now update primary cmd buffer to execute secondary and transitions image
15909 command_buffer_begin_info.pInheritanceInfo = nullptr;
15910 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15911 ASSERT_VK_SUCCESS(err);
15912 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15913 VkImageMemoryBarrier img_barrier2 = {};
15914 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15915 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15916 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15917 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15918 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15919 img_barrier2.image = image.handle();
15920 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15921 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15922 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15923 img_barrier2.subresourceRange.baseArrayLayer = 0;
15924 img_barrier2.subresourceRange.baseMipLevel = 0;
15925 img_barrier2.subresourceRange.layerCount = 1;
15926 img_barrier2.subresourceRange.levelCount = 1;
15927 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15928 nullptr, 1, &img_barrier2);
15929 err = vkEndCommandBuffer(primary_command_buffer);
15930 ASSERT_VK_SUCCESS(err);
15931 VkSubmitInfo submit_info = {};
15932 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15933 submit_info.commandBufferCount = 1;
15934 submit_info.pCommandBuffers = &primary_command_buffer;
15935 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15936 ASSERT_VK_SUCCESS(err);
15937 m_errorMonitor->VerifyNotFound();
15938 err = vkDeviceWaitIdle(m_device->device());
15939 ASSERT_VK_SUCCESS(err);
15940 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15941 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15942}
15943
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015944// This is a positive test. No failures are expected.
15945TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15946 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15947 "is ignoring VkWriteDescriptorSet members that are not "
15948 "related to the descriptor type specified by "
15949 "VkWriteDescriptorSet::descriptorType. Correct "
15950 "validation behavior will result in the test running to "
15951 "completion without validation errors.");
15952
15953 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15954
15955 ASSERT_NO_FATAL_FAILURE(InitState());
15956
15957 // Image Case
15958 {
15959 m_errorMonitor->ExpectSuccess();
15960
15961 VkImage image;
15962 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15963 const int32_t tex_width = 32;
15964 const int32_t tex_height = 32;
15965 VkImageCreateInfo image_create_info = {};
15966 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15967 image_create_info.pNext = NULL;
15968 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15969 image_create_info.format = tex_format;
15970 image_create_info.extent.width = tex_width;
15971 image_create_info.extent.height = tex_height;
15972 image_create_info.extent.depth = 1;
15973 image_create_info.mipLevels = 1;
15974 image_create_info.arrayLayers = 1;
15975 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15976 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15977 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15978 image_create_info.flags = 0;
15979 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15980 ASSERT_VK_SUCCESS(err);
15981
15982 VkMemoryRequirements memory_reqs;
15983 VkDeviceMemory image_memory;
15984 bool pass;
15985 VkMemoryAllocateInfo memory_info = {};
15986 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15987 memory_info.pNext = NULL;
15988 memory_info.allocationSize = 0;
15989 memory_info.memoryTypeIndex = 0;
15990 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15991 memory_info.allocationSize = memory_reqs.size;
15992 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15993 ASSERT_TRUE(pass);
15994 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15995 ASSERT_VK_SUCCESS(err);
15996 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15997 ASSERT_VK_SUCCESS(err);
15998
15999 VkImageViewCreateInfo image_view_create_info = {};
16000 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16001 image_view_create_info.image = image;
16002 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16003 image_view_create_info.format = tex_format;
16004 image_view_create_info.subresourceRange.layerCount = 1;
16005 image_view_create_info.subresourceRange.baseMipLevel = 0;
16006 image_view_create_info.subresourceRange.levelCount = 1;
16007 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16008
16009 VkImageView view;
16010 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16011 ASSERT_VK_SUCCESS(err);
16012
16013 VkDescriptorPoolSize ds_type_count = {};
16014 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16015 ds_type_count.descriptorCount = 1;
16016
16017 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16018 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16019 ds_pool_ci.pNext = NULL;
16020 ds_pool_ci.maxSets = 1;
16021 ds_pool_ci.poolSizeCount = 1;
16022 ds_pool_ci.pPoolSizes = &ds_type_count;
16023
16024 VkDescriptorPool ds_pool;
16025 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16026 ASSERT_VK_SUCCESS(err);
16027
16028 VkDescriptorSetLayoutBinding dsl_binding = {};
16029 dsl_binding.binding = 0;
16030 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16031 dsl_binding.descriptorCount = 1;
16032 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16033 dsl_binding.pImmutableSamplers = NULL;
16034
16035 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16036 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16037 ds_layout_ci.pNext = NULL;
16038 ds_layout_ci.bindingCount = 1;
16039 ds_layout_ci.pBindings = &dsl_binding;
16040 VkDescriptorSetLayout ds_layout;
16041 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16042 ASSERT_VK_SUCCESS(err);
16043
16044 VkDescriptorSet descriptor_set;
16045 VkDescriptorSetAllocateInfo alloc_info = {};
16046 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16047 alloc_info.descriptorSetCount = 1;
16048 alloc_info.descriptorPool = ds_pool;
16049 alloc_info.pSetLayouts = &ds_layout;
16050 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16051 ASSERT_VK_SUCCESS(err);
16052
16053 VkDescriptorImageInfo image_info = {};
16054 image_info.imageView = view;
16055 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16056
16057 VkWriteDescriptorSet descriptor_write;
16058 memset(&descriptor_write, 0, sizeof(descriptor_write));
16059 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16060 descriptor_write.dstSet = descriptor_set;
16061 descriptor_write.dstBinding = 0;
16062 descriptor_write.descriptorCount = 1;
16063 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16064 descriptor_write.pImageInfo = &image_info;
16065
16066 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16067 // be
16068 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16069 // This will most likely produce a crash if the parameter_validation
16070 // layer
16071 // does not correctly ignore pBufferInfo.
16072 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16073 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16074
16075 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16076
16077 m_errorMonitor->VerifyNotFound();
16078
16079 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16080 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16081 vkDestroyImageView(m_device->device(), view, NULL);
16082 vkDestroyImage(m_device->device(), image, NULL);
16083 vkFreeMemory(m_device->device(), image_memory, NULL);
16084 }
16085
16086 // Buffer Case
16087 {
16088 m_errorMonitor->ExpectSuccess();
16089
16090 VkBuffer buffer;
16091 uint32_t queue_family_index = 0;
16092 VkBufferCreateInfo buffer_create_info = {};
16093 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16094 buffer_create_info.size = 1024;
16095 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16096 buffer_create_info.queueFamilyIndexCount = 1;
16097 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16098
16099 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16100 ASSERT_VK_SUCCESS(err);
16101
16102 VkMemoryRequirements memory_reqs;
16103 VkDeviceMemory buffer_memory;
16104 bool pass;
16105 VkMemoryAllocateInfo memory_info = {};
16106 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16107 memory_info.pNext = NULL;
16108 memory_info.allocationSize = 0;
16109 memory_info.memoryTypeIndex = 0;
16110
16111 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16112 memory_info.allocationSize = memory_reqs.size;
16113 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16114 ASSERT_TRUE(pass);
16115
16116 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16117 ASSERT_VK_SUCCESS(err);
16118 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16119 ASSERT_VK_SUCCESS(err);
16120
16121 VkDescriptorPoolSize ds_type_count = {};
16122 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16123 ds_type_count.descriptorCount = 1;
16124
16125 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16126 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16127 ds_pool_ci.pNext = NULL;
16128 ds_pool_ci.maxSets = 1;
16129 ds_pool_ci.poolSizeCount = 1;
16130 ds_pool_ci.pPoolSizes = &ds_type_count;
16131
16132 VkDescriptorPool ds_pool;
16133 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16134 ASSERT_VK_SUCCESS(err);
16135
16136 VkDescriptorSetLayoutBinding dsl_binding = {};
16137 dsl_binding.binding = 0;
16138 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16139 dsl_binding.descriptorCount = 1;
16140 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16141 dsl_binding.pImmutableSamplers = NULL;
16142
16143 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16144 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16145 ds_layout_ci.pNext = NULL;
16146 ds_layout_ci.bindingCount = 1;
16147 ds_layout_ci.pBindings = &dsl_binding;
16148 VkDescriptorSetLayout ds_layout;
16149 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16150 ASSERT_VK_SUCCESS(err);
16151
16152 VkDescriptorSet descriptor_set;
16153 VkDescriptorSetAllocateInfo alloc_info = {};
16154 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16155 alloc_info.descriptorSetCount = 1;
16156 alloc_info.descriptorPool = ds_pool;
16157 alloc_info.pSetLayouts = &ds_layout;
16158 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16159 ASSERT_VK_SUCCESS(err);
16160
16161 VkDescriptorBufferInfo buffer_info = {};
16162 buffer_info.buffer = buffer;
16163 buffer_info.offset = 0;
16164 buffer_info.range = 1024;
16165
16166 VkWriteDescriptorSet descriptor_write;
16167 memset(&descriptor_write, 0, sizeof(descriptor_write));
16168 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16169 descriptor_write.dstSet = descriptor_set;
16170 descriptor_write.dstBinding = 0;
16171 descriptor_write.descriptorCount = 1;
16172 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16173 descriptor_write.pBufferInfo = &buffer_info;
16174
16175 // Set pImageInfo and pTexelBufferView to invalid values, which should
16176 // be
16177 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16178 // This will most likely produce a crash if the parameter_validation
16179 // layer
16180 // does not correctly ignore pImageInfo.
16181 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16182 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16183
16184 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16185
16186 m_errorMonitor->VerifyNotFound();
16187
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016188 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16189 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16190 vkDestroyBuffer(m_device->device(), buffer, NULL);
16191 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16192 }
16193
16194 // Texel Buffer Case
16195 {
16196 m_errorMonitor->ExpectSuccess();
16197
16198 VkBuffer buffer;
16199 uint32_t queue_family_index = 0;
16200 VkBufferCreateInfo buffer_create_info = {};
16201 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16202 buffer_create_info.size = 1024;
16203 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16204 buffer_create_info.queueFamilyIndexCount = 1;
16205 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16206
16207 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16208 ASSERT_VK_SUCCESS(err);
16209
16210 VkMemoryRequirements memory_reqs;
16211 VkDeviceMemory buffer_memory;
16212 bool pass;
16213 VkMemoryAllocateInfo memory_info = {};
16214 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16215 memory_info.pNext = NULL;
16216 memory_info.allocationSize = 0;
16217 memory_info.memoryTypeIndex = 0;
16218
16219 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16220 memory_info.allocationSize = memory_reqs.size;
16221 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16222 ASSERT_TRUE(pass);
16223
16224 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16225 ASSERT_VK_SUCCESS(err);
16226 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16227 ASSERT_VK_SUCCESS(err);
16228
16229 VkBufferViewCreateInfo buff_view_ci = {};
16230 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16231 buff_view_ci.buffer = buffer;
16232 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16233 buff_view_ci.range = VK_WHOLE_SIZE;
16234 VkBufferView buffer_view;
16235 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16236
16237 VkDescriptorPoolSize ds_type_count = {};
16238 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16239 ds_type_count.descriptorCount = 1;
16240
16241 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16242 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16243 ds_pool_ci.pNext = NULL;
16244 ds_pool_ci.maxSets = 1;
16245 ds_pool_ci.poolSizeCount = 1;
16246 ds_pool_ci.pPoolSizes = &ds_type_count;
16247
16248 VkDescriptorPool ds_pool;
16249 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16250 ASSERT_VK_SUCCESS(err);
16251
16252 VkDescriptorSetLayoutBinding dsl_binding = {};
16253 dsl_binding.binding = 0;
16254 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16255 dsl_binding.descriptorCount = 1;
16256 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16257 dsl_binding.pImmutableSamplers = NULL;
16258
16259 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16260 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16261 ds_layout_ci.pNext = NULL;
16262 ds_layout_ci.bindingCount = 1;
16263 ds_layout_ci.pBindings = &dsl_binding;
16264 VkDescriptorSetLayout ds_layout;
16265 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16266 ASSERT_VK_SUCCESS(err);
16267
16268 VkDescriptorSet descriptor_set;
16269 VkDescriptorSetAllocateInfo alloc_info = {};
16270 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16271 alloc_info.descriptorSetCount = 1;
16272 alloc_info.descriptorPool = ds_pool;
16273 alloc_info.pSetLayouts = &ds_layout;
16274 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16275 ASSERT_VK_SUCCESS(err);
16276
16277 VkWriteDescriptorSet descriptor_write;
16278 memset(&descriptor_write, 0, sizeof(descriptor_write));
16279 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16280 descriptor_write.dstSet = descriptor_set;
16281 descriptor_write.dstBinding = 0;
16282 descriptor_write.descriptorCount = 1;
16283 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16284 descriptor_write.pTexelBufferView = &buffer_view;
16285
16286 // Set pImageInfo and pBufferInfo to invalid values, which should be
16287 // ignored for descriptorType ==
16288 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16289 // This will most likely produce a crash if the parameter_validation
16290 // layer
16291 // does not correctly ignore pImageInfo and pBufferInfo.
16292 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16293 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16294
16295 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16296
16297 m_errorMonitor->VerifyNotFound();
16298
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016299 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16300 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16301 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16302 vkDestroyBuffer(m_device->device(), buffer, NULL);
16303 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16304 }
16305}
16306
Tobin Ehlisf7428442016-10-25 07:58:24 -060016307TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16308 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16309
16310 ASSERT_NO_FATAL_FAILURE(InitState());
16311 // Create layout where two binding #s are "1"
16312 static const uint32_t NUM_BINDINGS = 3;
16313 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16314 dsl_binding[0].binding = 1;
16315 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16316 dsl_binding[0].descriptorCount = 1;
16317 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16318 dsl_binding[0].pImmutableSamplers = NULL;
16319 dsl_binding[1].binding = 0;
16320 dsl_binding[1].descriptorCount = 1;
16321 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16322 dsl_binding[1].descriptorCount = 1;
16323 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16324 dsl_binding[1].pImmutableSamplers = NULL;
16325 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16326 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16327 dsl_binding[2].descriptorCount = 1;
16328 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16329 dsl_binding[2].pImmutableSamplers = NULL;
16330
16331 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16332 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16333 ds_layout_ci.pNext = NULL;
16334 ds_layout_ci.bindingCount = NUM_BINDINGS;
16335 ds_layout_ci.pBindings = dsl_binding;
16336 VkDescriptorSetLayout ds_layout;
16337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16338 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16339 m_errorMonitor->VerifyFound();
16340}
16341
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016342TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016343 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16344
16345 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016346
16347 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016348
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016349 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16350
16351 {
16352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16353 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16354 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16355 m_errorMonitor->VerifyFound();
16356 }
16357
16358 {
16359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16360 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16361 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16362 m_errorMonitor->VerifyFound();
16363 }
16364
16365 {
16366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16367 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16368 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16369 m_errorMonitor->VerifyFound();
16370 }
16371
16372 {
16373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16374 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16375 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16376 m_errorMonitor->VerifyFound();
16377 }
16378
16379 {
16380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16381 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16382 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16383 m_errorMonitor->VerifyFound();
16384 }
16385
16386 {
16387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16388 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16389 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16390 m_errorMonitor->VerifyFound();
16391 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016392
16393 {
16394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16395 VkRect2D scissor = {{-1, 0}, {16, 16}};
16396 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16397 m_errorMonitor->VerifyFound();
16398 }
16399
16400 {
16401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16402 VkRect2D scissor = {{0, -2}, {16, 16}};
16403 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16404 m_errorMonitor->VerifyFound();
16405 }
16406
16407 {
16408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16409 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16410 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16411 m_errorMonitor->VerifyFound();
16412 }
16413
16414 {
16415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16416 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16417 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16418 m_errorMonitor->VerifyFound();
16419 }
16420
16421 EndCommandBuffer();
16422}
16423
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016424// This is a positive test. No failures are expected.
16425TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16426 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16427 VkResult err;
16428
16429 ASSERT_NO_FATAL_FAILURE(InitState());
16430 m_errorMonitor->ExpectSuccess();
16431 VkDescriptorPoolSize ds_type_count = {};
16432 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16433 ds_type_count.descriptorCount = 2;
16434
16435 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16436 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16437 ds_pool_ci.pNext = NULL;
16438 ds_pool_ci.maxSets = 1;
16439 ds_pool_ci.poolSizeCount = 1;
16440 ds_pool_ci.pPoolSizes = &ds_type_count;
16441
16442 VkDescriptorPool ds_pool;
16443 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16444 ASSERT_VK_SUCCESS(err);
16445
16446 // Create layout with two uniform buffer descriptors w/ empty binding between them
16447 static const uint32_t NUM_BINDINGS = 3;
16448 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16449 dsl_binding[0].binding = 0;
16450 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16451 dsl_binding[0].descriptorCount = 1;
16452 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16453 dsl_binding[0].pImmutableSamplers = NULL;
16454 dsl_binding[1].binding = 1;
16455 dsl_binding[1].descriptorCount = 0; // empty binding
16456 dsl_binding[2].binding = 2;
16457 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16458 dsl_binding[2].descriptorCount = 1;
16459 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16460 dsl_binding[2].pImmutableSamplers = NULL;
16461
16462 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16463 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16464 ds_layout_ci.pNext = NULL;
16465 ds_layout_ci.bindingCount = NUM_BINDINGS;
16466 ds_layout_ci.pBindings = dsl_binding;
16467 VkDescriptorSetLayout ds_layout;
16468 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16469 ASSERT_VK_SUCCESS(err);
16470
16471 VkDescriptorSet descriptor_set = {};
16472 VkDescriptorSetAllocateInfo alloc_info = {};
16473 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16474 alloc_info.descriptorSetCount = 1;
16475 alloc_info.descriptorPool = ds_pool;
16476 alloc_info.pSetLayouts = &ds_layout;
16477 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16478 ASSERT_VK_SUCCESS(err);
16479
16480 // Create a buffer to be used for update
16481 VkBufferCreateInfo buff_ci = {};
16482 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16483 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16484 buff_ci.size = 256;
16485 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16486 VkBuffer buffer;
16487 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16488 ASSERT_VK_SUCCESS(err);
16489 // Have to bind memory to buffer before descriptor update
16490 VkMemoryAllocateInfo mem_alloc = {};
16491 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16492 mem_alloc.pNext = NULL;
16493 mem_alloc.allocationSize = 512; // one allocation for both buffers
16494 mem_alloc.memoryTypeIndex = 0;
16495
16496 VkMemoryRequirements mem_reqs;
16497 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16498 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16499 if (!pass) {
16500 vkDestroyBuffer(m_device->device(), buffer, NULL);
16501 return;
16502 }
16503
16504 VkDeviceMemory mem;
16505 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16506 ASSERT_VK_SUCCESS(err);
16507 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16508 ASSERT_VK_SUCCESS(err);
16509
16510 // Only update the descriptor at binding 2
16511 VkDescriptorBufferInfo buff_info = {};
16512 buff_info.buffer = buffer;
16513 buff_info.offset = 0;
16514 buff_info.range = VK_WHOLE_SIZE;
16515 VkWriteDescriptorSet descriptor_write = {};
16516 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16517 descriptor_write.dstBinding = 2;
16518 descriptor_write.descriptorCount = 1;
16519 descriptor_write.pTexelBufferView = nullptr;
16520 descriptor_write.pBufferInfo = &buff_info;
16521 descriptor_write.pImageInfo = nullptr;
16522 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16523 descriptor_write.dstSet = descriptor_set;
16524
16525 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16526
16527 m_errorMonitor->VerifyNotFound();
16528 // Cleanup
16529 vkFreeMemory(m_device->device(), mem, NULL);
16530 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16531 vkDestroyBuffer(m_device->device(), buffer, NULL);
16532 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16533}
16534
16535// This is a positive test. No failures are expected.
16536TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16537 VkResult err;
16538 bool pass;
16539
16540 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16541 "the buffer, create an image, and bind the same memory to "
16542 "it");
16543
16544 m_errorMonitor->ExpectSuccess();
16545
16546 ASSERT_NO_FATAL_FAILURE(InitState());
16547
16548 VkBuffer buffer;
16549 VkImage image;
16550 VkDeviceMemory mem;
16551 VkMemoryRequirements mem_reqs;
16552
16553 VkBufferCreateInfo buf_info = {};
16554 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16555 buf_info.pNext = NULL;
16556 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16557 buf_info.size = 256;
16558 buf_info.queueFamilyIndexCount = 0;
16559 buf_info.pQueueFamilyIndices = NULL;
16560 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16561 buf_info.flags = 0;
16562 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16563 ASSERT_VK_SUCCESS(err);
16564
16565 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16566
16567 VkMemoryAllocateInfo alloc_info = {};
16568 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16569 alloc_info.pNext = NULL;
16570 alloc_info.memoryTypeIndex = 0;
16571
16572 // Ensure memory is big enough for both bindings
16573 alloc_info.allocationSize = 0x10000;
16574
16575 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16576 if (!pass) {
16577 vkDestroyBuffer(m_device->device(), buffer, NULL);
16578 return;
16579 }
16580
16581 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16582 ASSERT_VK_SUCCESS(err);
16583
16584 uint8_t *pData;
16585 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16586 ASSERT_VK_SUCCESS(err);
16587
16588 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16589
16590 vkUnmapMemory(m_device->device(), mem);
16591
16592 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16593 ASSERT_VK_SUCCESS(err);
16594
16595 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16596 // memory. In fact, it was never used by the GPU.
16597 // Just be be sure, wait for idle.
16598 vkDestroyBuffer(m_device->device(), buffer, NULL);
16599 vkDeviceWaitIdle(m_device->device());
16600
16601 VkImageCreateInfo image_create_info = {};
16602 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16603 image_create_info.pNext = NULL;
16604 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16605 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16606 image_create_info.extent.width = 64;
16607 image_create_info.extent.height = 64;
16608 image_create_info.extent.depth = 1;
16609 image_create_info.mipLevels = 1;
16610 image_create_info.arrayLayers = 1;
16611 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16612 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16613 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16614 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16615 image_create_info.queueFamilyIndexCount = 0;
16616 image_create_info.pQueueFamilyIndices = NULL;
16617 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16618 image_create_info.flags = 0;
16619
16620 VkMemoryAllocateInfo mem_alloc = {};
16621 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16622 mem_alloc.pNext = NULL;
16623 mem_alloc.allocationSize = 0;
16624 mem_alloc.memoryTypeIndex = 0;
16625
16626 /* Create a mappable image. It will be the texture if linear images are ok
16627 * to be textures or it will be the staging image if they are not.
16628 */
16629 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16630 ASSERT_VK_SUCCESS(err);
16631
16632 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16633
16634 mem_alloc.allocationSize = mem_reqs.size;
16635
16636 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16637 if (!pass) {
16638 vkDestroyImage(m_device->device(), image, NULL);
16639 return;
16640 }
16641
16642 // VALIDATION FAILURE:
16643 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16644 ASSERT_VK_SUCCESS(err);
16645
16646 m_errorMonitor->VerifyNotFound();
16647
16648 vkFreeMemory(m_device->device(), mem, NULL);
16649 vkDestroyBuffer(m_device->device(), buffer, NULL);
16650 vkDestroyImage(m_device->device(), image, NULL);
16651}
16652
Tobin Ehlis953e8392016-11-17 10:54:13 -070016653TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16654 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16655 // We previously had a bug where dynamic offset of inactive bindings was still being used
16656 VkResult err;
16657 m_errorMonitor->ExpectSuccess();
16658
16659 ASSERT_NO_FATAL_FAILURE(InitState());
16660 ASSERT_NO_FATAL_FAILURE(InitViewport());
16661 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16662
16663 VkDescriptorPoolSize ds_type_count = {};
16664 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16665 ds_type_count.descriptorCount = 3;
16666
16667 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16668 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16669 ds_pool_ci.pNext = NULL;
16670 ds_pool_ci.maxSets = 1;
16671 ds_pool_ci.poolSizeCount = 1;
16672 ds_pool_ci.pPoolSizes = &ds_type_count;
16673
16674 VkDescriptorPool ds_pool;
16675 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16676 ASSERT_VK_SUCCESS(err);
16677
16678 const uint32_t BINDING_COUNT = 3;
16679 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016680 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016681 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16682 dsl_binding[0].descriptorCount = 1;
16683 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16684 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016685 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016686 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16687 dsl_binding[1].descriptorCount = 1;
16688 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16689 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016690 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016691 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16692 dsl_binding[2].descriptorCount = 1;
16693 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16694 dsl_binding[2].pImmutableSamplers = NULL;
16695
16696 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16697 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16698 ds_layout_ci.pNext = NULL;
16699 ds_layout_ci.bindingCount = BINDING_COUNT;
16700 ds_layout_ci.pBindings = dsl_binding;
16701 VkDescriptorSetLayout ds_layout;
16702 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16703 ASSERT_VK_SUCCESS(err);
16704
16705 VkDescriptorSet descriptor_set;
16706 VkDescriptorSetAllocateInfo alloc_info = {};
16707 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16708 alloc_info.descriptorSetCount = 1;
16709 alloc_info.descriptorPool = ds_pool;
16710 alloc_info.pSetLayouts = &ds_layout;
16711 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16712 ASSERT_VK_SUCCESS(err);
16713
16714 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16715 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16716 pipeline_layout_ci.pNext = NULL;
16717 pipeline_layout_ci.setLayoutCount = 1;
16718 pipeline_layout_ci.pSetLayouts = &ds_layout;
16719
16720 VkPipelineLayout pipeline_layout;
16721 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16722 ASSERT_VK_SUCCESS(err);
16723
16724 // Create two buffers to update the descriptors with
16725 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16726 uint32_t qfi = 0;
16727 VkBufferCreateInfo buffCI = {};
16728 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16729 buffCI.size = 2048;
16730 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16731 buffCI.queueFamilyIndexCount = 1;
16732 buffCI.pQueueFamilyIndices = &qfi;
16733
16734 VkBuffer dyub1;
16735 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16736 ASSERT_VK_SUCCESS(err);
16737 // buffer2
16738 buffCI.size = 1024;
16739 VkBuffer dyub2;
16740 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16741 ASSERT_VK_SUCCESS(err);
16742 // Allocate memory and bind to buffers
16743 VkMemoryAllocateInfo mem_alloc[2] = {};
16744 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16745 mem_alloc[0].pNext = NULL;
16746 mem_alloc[0].memoryTypeIndex = 0;
16747 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16748 mem_alloc[1].pNext = NULL;
16749 mem_alloc[1].memoryTypeIndex = 0;
16750
16751 VkMemoryRequirements mem_reqs1;
16752 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16753 VkMemoryRequirements mem_reqs2;
16754 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16755 mem_alloc[0].allocationSize = mem_reqs1.size;
16756 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16757 mem_alloc[1].allocationSize = mem_reqs2.size;
16758 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16759 if (!pass) {
16760 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16761 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16762 return;
16763 }
16764
16765 VkDeviceMemory mem1;
16766 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16767 ASSERT_VK_SUCCESS(err);
16768 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
16769 ASSERT_VK_SUCCESS(err);
16770 VkDeviceMemory mem2;
16771 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
16772 ASSERT_VK_SUCCESS(err);
16773 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
16774 ASSERT_VK_SUCCESS(err);
16775 // Update descriptors
16776 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
16777 buff_info[0].buffer = dyub1;
16778 buff_info[0].offset = 0;
16779 buff_info[0].range = 256;
16780 buff_info[1].buffer = dyub1;
16781 buff_info[1].offset = 256;
16782 buff_info[1].range = 512;
16783 buff_info[2].buffer = dyub2;
16784 buff_info[2].offset = 0;
16785 buff_info[2].range = 512;
16786
16787 VkWriteDescriptorSet descriptor_write;
16788 memset(&descriptor_write, 0, sizeof(descriptor_write));
16789 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16790 descriptor_write.dstSet = descriptor_set;
16791 descriptor_write.dstBinding = 0;
16792 descriptor_write.descriptorCount = BINDING_COUNT;
16793 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16794 descriptor_write.pBufferInfo = buff_info;
16795
16796 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16797
16798 BeginCommandBuffer();
16799
16800 // Create PSO to be used for draw-time errors below
16801 char const *vsSource = "#version 450\n"
16802 "\n"
16803 "out gl_PerVertex { \n"
16804 " vec4 gl_Position;\n"
16805 "};\n"
16806 "void main(){\n"
16807 " gl_Position = vec4(1);\n"
16808 "}\n";
16809 char const *fsSource = "#version 450\n"
16810 "\n"
16811 "layout(location=0) out vec4 x;\n"
16812 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
16813 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
16814 "void main(){\n"
16815 " x = vec4(bar1.y) + vec4(bar2.y);\n"
16816 "}\n";
16817 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16818 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16819 VkPipelineObj pipe(m_device);
16820 pipe.SetViewport(m_viewports);
16821 pipe.SetScissor(m_scissors);
16822 pipe.AddShader(&vs);
16823 pipe.AddShader(&fs);
16824 pipe.AddColorAttachment();
16825 pipe.CreateVKPipeline(pipeline_layout, renderPass());
16826
16827 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
16828 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
16829 // we used to have a bug in this case.
16830 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
16831 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
16832 &descriptor_set, BINDING_COUNT, dyn_off);
16833 Draw(1, 0, 0, 0);
16834 m_errorMonitor->VerifyNotFound();
16835
16836 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16837 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16838 vkFreeMemory(m_device->device(), mem1, NULL);
16839 vkFreeMemory(m_device->device(), mem2, NULL);
16840
16841 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
16842 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16843 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16844}
16845
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016846TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16847
16848 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16849 "mapping while using VK_WHOLE_SIZE does not cause access "
16850 "violations");
16851 VkResult err;
16852 uint8_t *pData;
16853 ASSERT_NO_FATAL_FAILURE(InitState());
16854
16855 VkDeviceMemory mem;
16856 VkMemoryRequirements mem_reqs;
16857 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016858 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016859 VkMemoryAllocateInfo alloc_info = {};
16860 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16861 alloc_info.pNext = NULL;
16862 alloc_info.memoryTypeIndex = 0;
16863
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016864 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016865 alloc_info.allocationSize = allocation_size;
16866
16867 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16868 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16869 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16870 if (!pass) {
16871 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16872 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16873 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16874 if (!pass) {
16875 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16876 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16877 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16878 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16879 if (!pass) {
16880 return;
16881 }
16882 }
16883 }
16884
16885 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16886 ASSERT_VK_SUCCESS(err);
16887
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016888 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016889 m_errorMonitor->ExpectSuccess();
16890 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16891 ASSERT_VK_SUCCESS(err);
16892 VkMappedMemoryRange mmr = {};
16893 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16894 mmr.memory = mem;
16895 mmr.offset = 0;
16896 mmr.size = VK_WHOLE_SIZE;
16897 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16898 ASSERT_VK_SUCCESS(err);
16899 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16900 ASSERT_VK_SUCCESS(err);
16901 m_errorMonitor->VerifyNotFound();
16902 vkUnmapMemory(m_device->device(), mem);
16903
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016904 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016905 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016906 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016907 ASSERT_VK_SUCCESS(err);
16908 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16909 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016910 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016911 mmr.size = VK_WHOLE_SIZE;
16912 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16913 ASSERT_VK_SUCCESS(err);
16914 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16915 ASSERT_VK_SUCCESS(err);
16916 m_errorMonitor->VerifyNotFound();
16917 vkUnmapMemory(m_device->device(), mem);
16918
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016919 // Map with offset and size
16920 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016921 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016922 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016923 ASSERT_VK_SUCCESS(err);
16924 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16925 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016926 mmr.offset = 4 * atom_size;
16927 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016928 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16929 ASSERT_VK_SUCCESS(err);
16930 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16931 ASSERT_VK_SUCCESS(err);
16932 m_errorMonitor->VerifyNotFound();
16933 vkUnmapMemory(m_device->device(), mem);
16934
16935 // Map without offset and flush WHOLE_SIZE with two separate offsets
16936 m_errorMonitor->ExpectSuccess();
16937 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16938 ASSERT_VK_SUCCESS(err);
16939 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16940 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016941 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016942 mmr.size = VK_WHOLE_SIZE;
16943 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16944 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016945 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016946 mmr.size = VK_WHOLE_SIZE;
16947 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16948 ASSERT_VK_SUCCESS(err);
16949 m_errorMonitor->VerifyNotFound();
16950 vkUnmapMemory(m_device->device(), mem);
16951
16952 vkFreeMemory(m_device->device(), mem, NULL);
16953}
16954
16955// This is a positive test. We used to expect error in this case but spec now allows it
16956TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16957 m_errorMonitor->ExpectSuccess();
16958 vk_testing::Fence testFence;
16959 VkFenceCreateInfo fenceInfo = {};
16960 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16961 fenceInfo.pNext = NULL;
16962
16963 ASSERT_NO_FATAL_FAILURE(InitState());
16964 testFence.init(*m_device, fenceInfo);
16965 VkFence fences[1] = { testFence.handle() };
16966 VkResult result = vkResetFences(m_device->device(), 1, fences);
16967 ASSERT_VK_SUCCESS(result);
16968
16969 m_errorMonitor->VerifyNotFound();
16970}
16971
16972TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16973 m_errorMonitor->ExpectSuccess();
16974
16975 ASSERT_NO_FATAL_FAILURE(InitState());
16976 VkResult err;
16977
16978 // Record (empty!) command buffer that can be submitted multiple times
16979 // simultaneously.
16980 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16981 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16982 m_commandBuffer->BeginCommandBuffer(&cbbi);
16983 m_commandBuffer->EndCommandBuffer();
16984
16985 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16986 VkFence fence;
16987 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16988 ASSERT_VK_SUCCESS(err);
16989
16990 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16991 VkSemaphore s1, s2;
16992 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16993 ASSERT_VK_SUCCESS(err);
16994 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16995 ASSERT_VK_SUCCESS(err);
16996
16997 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16998 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16999 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17000 ASSERT_VK_SUCCESS(err);
17001
17002 // Submit CB again, signaling s2.
17003 si.pSignalSemaphores = &s2;
17004 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17005 ASSERT_VK_SUCCESS(err);
17006
17007 // Wait for fence.
17008 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17009 ASSERT_VK_SUCCESS(err);
17010
17011 // CB is still in flight from second submission, but semaphore s1 is no
17012 // longer in flight. delete it.
17013 vkDestroySemaphore(m_device->device(), s1, nullptr);
17014
17015 m_errorMonitor->VerifyNotFound();
17016
17017 // Force device idle and clean up remaining objects
17018 vkDeviceWaitIdle(m_device->device());
17019 vkDestroySemaphore(m_device->device(), s2, nullptr);
17020 vkDestroyFence(m_device->device(), fence, nullptr);
17021}
17022
17023TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17024 m_errorMonitor->ExpectSuccess();
17025
17026 ASSERT_NO_FATAL_FAILURE(InitState());
17027 VkResult err;
17028
17029 // A fence created signaled
17030 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
17031 VkFence f1;
17032 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17033 ASSERT_VK_SUCCESS(err);
17034
17035 // A fence created not
17036 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17037 VkFence f2;
17038 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17039 ASSERT_VK_SUCCESS(err);
17040
17041 // Submit the unsignaled fence
17042 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
17043 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17044
17045 // Wait on both fences, with signaled first.
17046 VkFence fences[] = { f1, f2 };
17047 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17048
17049 // Should have both retired!
17050 vkDestroyFence(m_device->device(), f1, nullptr);
17051 vkDestroyFence(m_device->device(), f2, nullptr);
17052
17053 m_errorMonitor->VerifyNotFound();
17054}
17055
17056TEST_F(VkPositiveLayerTest, ValidUsage) {
17057 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
17058 "doesn't generate validation errors");
17059
17060 ASSERT_NO_FATAL_FAILURE(InitState());
17061
17062 m_errorMonitor->ExpectSuccess();
17063 // Verify that we can create a view with usage INPUT_ATTACHMENT
17064 VkImageObj image(m_device);
17065 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17066 ASSERT_TRUE(image.initialized());
17067 VkImageView imageView;
17068 VkImageViewCreateInfo ivci = {};
17069 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17070 ivci.image = image.handle();
17071 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17072 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17073 ivci.subresourceRange.layerCount = 1;
17074 ivci.subresourceRange.baseMipLevel = 0;
17075 ivci.subresourceRange.levelCount = 1;
17076 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17077
17078 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17079 m_errorMonitor->VerifyNotFound();
17080 vkDestroyImageView(m_device->device(), imageView, NULL);
17081}
17082
17083// This is a positive test. No failures are expected.
17084TEST_F(VkPositiveLayerTest, BindSparse) {
17085 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17086 "and then free the memory");
17087
17088 ASSERT_NO_FATAL_FAILURE(InitState());
17089
17090 auto index = m_device->graphics_queue_node_index_;
17091 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
17092 return;
17093
17094 m_errorMonitor->ExpectSuccess();
17095
17096 VkImage image;
17097 VkImageCreateInfo image_create_info = {};
17098 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17099 image_create_info.pNext = NULL;
17100 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17101 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17102 image_create_info.extent.width = 64;
17103 image_create_info.extent.height = 64;
17104 image_create_info.extent.depth = 1;
17105 image_create_info.mipLevels = 1;
17106 image_create_info.arrayLayers = 1;
17107 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17108 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17109 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17110 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17111 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17112 ASSERT_VK_SUCCESS(err);
17113
17114 VkMemoryRequirements memory_reqs;
17115 VkDeviceMemory memory_one, memory_two;
17116 bool pass;
17117 VkMemoryAllocateInfo memory_info = {};
17118 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17119 memory_info.pNext = NULL;
17120 memory_info.allocationSize = 0;
17121 memory_info.memoryTypeIndex = 0;
17122 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17123 // Find an image big enough to allow sparse mapping of 2 memory regions
17124 // Increase the image size until it is at least twice the
17125 // size of the required alignment, to ensure we can bind both
17126 // allocated memory blocks to the image on aligned offsets.
17127 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17128 vkDestroyImage(m_device->device(), image, nullptr);
17129 image_create_info.extent.width *= 2;
17130 image_create_info.extent.height *= 2;
17131 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17132 ASSERT_VK_SUCCESS(err);
17133 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17134 }
17135 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17136 // at the end of the first
17137 memory_info.allocationSize = memory_reqs.alignment;
17138 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17139 ASSERT_TRUE(pass);
17140 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17141 ASSERT_VK_SUCCESS(err);
17142 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17143 ASSERT_VK_SUCCESS(err);
17144 VkSparseMemoryBind binds[2];
17145 binds[0].flags = 0;
17146 binds[0].memory = memory_one;
17147 binds[0].memoryOffset = 0;
17148 binds[0].resourceOffset = 0;
17149 binds[0].size = memory_info.allocationSize;
17150 binds[1].flags = 0;
17151 binds[1].memory = memory_two;
17152 binds[1].memoryOffset = 0;
17153 binds[1].resourceOffset = memory_info.allocationSize;
17154 binds[1].size = memory_info.allocationSize;
17155
17156 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17157 opaqueBindInfo.image = image;
17158 opaqueBindInfo.bindCount = 2;
17159 opaqueBindInfo.pBinds = binds;
17160
17161 VkFence fence = VK_NULL_HANDLE;
17162 VkBindSparseInfo bindSparseInfo = {};
17163 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17164 bindSparseInfo.imageOpaqueBindCount = 1;
17165 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17166
17167 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17168 vkQueueWaitIdle(m_device->m_queue);
17169 vkDestroyImage(m_device->device(), image, NULL);
17170 vkFreeMemory(m_device->device(), memory_one, NULL);
17171 vkFreeMemory(m_device->device(), memory_two, NULL);
17172 m_errorMonitor->VerifyNotFound();
17173}
17174
17175TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
17176 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
17177 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17178 "the command buffer has prior knowledge of that "
17179 "attachment's layout.");
17180
17181 m_errorMonitor->ExpectSuccess();
17182
17183 ASSERT_NO_FATAL_FAILURE(InitState());
17184
17185 // A renderpass with one color attachment.
17186 VkAttachmentDescription attachment = { 0,
17187 VK_FORMAT_R8G8B8A8_UNORM,
17188 VK_SAMPLE_COUNT_1_BIT,
17189 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17190 VK_ATTACHMENT_STORE_OP_STORE,
17191 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17192 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17193 VK_IMAGE_LAYOUT_UNDEFINED,
17194 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17195
17196 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17197
17198 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17199
17200 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17201
17202 VkRenderPass rp;
17203 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17204 ASSERT_VK_SUCCESS(err);
17205
17206 // A compatible framebuffer.
17207 VkImageObj image(m_device);
17208 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17209 ASSERT_TRUE(image.initialized());
17210
17211 VkImageViewCreateInfo ivci = {
17212 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17213 nullptr,
17214 0,
17215 image.handle(),
17216 VK_IMAGE_VIEW_TYPE_2D,
17217 VK_FORMAT_R8G8B8A8_UNORM,
17218 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17219 VK_COMPONENT_SWIZZLE_IDENTITY },
17220 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17221 };
17222 VkImageView view;
17223 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17224 ASSERT_VK_SUCCESS(err);
17225
17226 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17227 VkFramebuffer fb;
17228 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17229 ASSERT_VK_SUCCESS(err);
17230
17231 // Record a single command buffer which uses this renderpass twice. The
17232 // bug is triggered at the beginning of the second renderpass, when the
17233 // command buffer already has a layout recorded for the attachment.
17234 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17235 BeginCommandBuffer();
17236 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17237 vkCmdEndRenderPass(m_commandBuffer->handle());
17238 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17239
17240 m_errorMonitor->VerifyNotFound();
17241
17242 vkCmdEndRenderPass(m_commandBuffer->handle());
17243 EndCommandBuffer();
17244
17245 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17246 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17247 vkDestroyImageView(m_device->device(), view, nullptr);
17248}
17249
17250TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17251 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17252 "command buffer, bind them together, then destroy "
17253 "command pool and framebuffer and verify there are no "
17254 "errors.");
17255
17256 m_errorMonitor->ExpectSuccess();
17257
17258 ASSERT_NO_FATAL_FAILURE(InitState());
17259
17260 // A renderpass with one color attachment.
17261 VkAttachmentDescription attachment = { 0,
17262 VK_FORMAT_R8G8B8A8_UNORM,
17263 VK_SAMPLE_COUNT_1_BIT,
17264 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17265 VK_ATTACHMENT_STORE_OP_STORE,
17266 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17267 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17268 VK_IMAGE_LAYOUT_UNDEFINED,
17269 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17270
17271 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17272
17273 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17274
17275 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17276
17277 VkRenderPass rp;
17278 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17279 ASSERT_VK_SUCCESS(err);
17280
17281 // A compatible framebuffer.
17282 VkImageObj image(m_device);
17283 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17284 ASSERT_TRUE(image.initialized());
17285
17286 VkImageViewCreateInfo ivci = {
17287 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17288 nullptr,
17289 0,
17290 image.handle(),
17291 VK_IMAGE_VIEW_TYPE_2D,
17292 VK_FORMAT_R8G8B8A8_UNORM,
17293 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17294 VK_COMPONENT_SWIZZLE_IDENTITY },
17295 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17296 };
17297 VkImageView view;
17298 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17299 ASSERT_VK_SUCCESS(err);
17300
17301 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17302 VkFramebuffer fb;
17303 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17304 ASSERT_VK_SUCCESS(err);
17305
17306 // Explicitly create a command buffer to bind the FB to so that we can then
17307 // destroy the command pool in order to implicitly free command buffer
17308 VkCommandPool command_pool;
17309 VkCommandPoolCreateInfo pool_create_info{};
17310 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17311 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17312 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17313 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17314
17315 VkCommandBuffer command_buffer;
17316 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17317 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17318 command_buffer_allocate_info.commandPool = command_pool;
17319 command_buffer_allocate_info.commandBufferCount = 1;
17320 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17321 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17322
17323 // Begin our cmd buffer with renderpass using our framebuffer
17324 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17325 VkCommandBufferBeginInfo begin_info{};
17326 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17327 vkBeginCommandBuffer(command_buffer, &begin_info);
17328
17329 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17330 vkCmdEndRenderPass(command_buffer);
17331 vkEndCommandBuffer(command_buffer);
17332 vkDestroyImageView(m_device->device(), view, nullptr);
17333 // Destroy command pool to implicitly free command buffer
17334 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17335 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17336 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17337 m_errorMonitor->VerifyNotFound();
17338}
17339
17340TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17341 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17342 "transitions for the first subpass");
17343
17344 m_errorMonitor->ExpectSuccess();
17345
17346 ASSERT_NO_FATAL_FAILURE(InitState());
17347
17348 // A renderpass with one color attachment.
17349 VkAttachmentDescription attachment = { 0,
17350 VK_FORMAT_R8G8B8A8_UNORM,
17351 VK_SAMPLE_COUNT_1_BIT,
17352 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17353 VK_ATTACHMENT_STORE_OP_STORE,
17354 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17355 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17356 VK_IMAGE_LAYOUT_UNDEFINED,
17357 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17358
17359 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17360
17361 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17362
17363 VkSubpassDependency dep = { 0,
17364 0,
17365 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17366 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17367 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17368 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17369 VK_DEPENDENCY_BY_REGION_BIT };
17370
17371 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17372
17373 VkResult err;
17374 VkRenderPass rp;
17375 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17376 ASSERT_VK_SUCCESS(err);
17377
17378 // A compatible framebuffer.
17379 VkImageObj image(m_device);
17380 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17381 ASSERT_TRUE(image.initialized());
17382
17383 VkImageViewCreateInfo ivci = {
17384 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17385 nullptr,
17386 0,
17387 image.handle(),
17388 VK_IMAGE_VIEW_TYPE_2D,
17389 VK_FORMAT_R8G8B8A8_UNORM,
17390 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17391 VK_COMPONENT_SWIZZLE_IDENTITY },
17392 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17393 };
17394 VkImageView view;
17395 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17396 ASSERT_VK_SUCCESS(err);
17397
17398 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17399 VkFramebuffer fb;
17400 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17401 ASSERT_VK_SUCCESS(err);
17402
17403 // Record a single command buffer which issues a pipeline barrier w/
17404 // image memory barrier for the attachment. This detects the previously
17405 // missing tracking of the subpass layout by throwing a validation error
17406 // if it doesn't occur.
17407 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17408 BeginCommandBuffer();
17409 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17410
17411 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17412 nullptr,
17413 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17414 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17415 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17416 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17417 VK_QUEUE_FAMILY_IGNORED,
17418 VK_QUEUE_FAMILY_IGNORED,
17419 image.handle(),
17420 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17421 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17422 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17423 &imb);
17424
17425 vkCmdEndRenderPass(m_commandBuffer->handle());
17426 m_errorMonitor->VerifyNotFound();
17427 EndCommandBuffer();
17428
17429 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17430 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17431 vkDestroyImageView(m_device->device(), view, nullptr);
17432}
17433
17434TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17435 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17436 "is used as a depth/stencil framebuffer attachment, the "
17437 "aspectMask is ignored and both depth and stencil image "
17438 "subresources are used.");
17439
17440 VkFormatProperties format_properties;
17441 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17442 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17443 return;
17444 }
17445
17446 m_errorMonitor->ExpectSuccess();
17447
17448 ASSERT_NO_FATAL_FAILURE(InitState());
17449
17450 VkAttachmentDescription attachment = { 0,
17451 VK_FORMAT_D32_SFLOAT_S8_UINT,
17452 VK_SAMPLE_COUNT_1_BIT,
17453 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17454 VK_ATTACHMENT_STORE_OP_STORE,
17455 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17456 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17457 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17458 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17459
17460 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17461
17462 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17463
17464 VkSubpassDependency dep = { 0,
17465 0,
17466 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17467 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17468 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17469 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17470 VK_DEPENDENCY_BY_REGION_BIT};
17471
17472 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17473
17474 VkResult err;
17475 VkRenderPass rp;
17476 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17477 ASSERT_VK_SUCCESS(err);
17478
17479 VkImageObj image(m_device);
17480 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17481 0x26, // usage
17482 VK_IMAGE_TILING_OPTIMAL, 0);
17483 ASSERT_TRUE(image.initialized());
17484 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17485
17486 VkImageViewCreateInfo ivci = {
17487 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17488 nullptr,
17489 0,
17490 image.handle(),
17491 VK_IMAGE_VIEW_TYPE_2D,
17492 VK_FORMAT_D32_SFLOAT_S8_UINT,
17493 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17494 { 0x2, 0, 1, 0, 1 },
17495 };
17496 VkImageView view;
17497 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17498 ASSERT_VK_SUCCESS(err);
17499
17500 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17501 VkFramebuffer fb;
17502 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17503 ASSERT_VK_SUCCESS(err);
17504
17505 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17506 BeginCommandBuffer();
17507 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17508
17509 VkImageMemoryBarrier imb = {};
17510 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17511 imb.pNext = nullptr;
17512 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17513 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17514 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17515 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17516 imb.srcQueueFamilyIndex = 0;
17517 imb.dstQueueFamilyIndex = 0;
17518 imb.image = image.handle();
17519 imb.subresourceRange.aspectMask = 0x6;
17520 imb.subresourceRange.baseMipLevel = 0;
17521 imb.subresourceRange.levelCount = 0x1;
17522 imb.subresourceRange.baseArrayLayer = 0;
17523 imb.subresourceRange.layerCount = 0x1;
17524
17525 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17526 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17527 &imb);
17528
17529 vkCmdEndRenderPass(m_commandBuffer->handle());
17530 EndCommandBuffer();
17531 QueueCommandBuffer(false);
17532 m_errorMonitor->VerifyNotFound();
17533
17534 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17535 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17536 vkDestroyImageView(m_device->device(), view, nullptr);
17537}
17538
17539TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17540 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17541 "errors, when an attachment reference is "
17542 "VK_ATTACHMENT_UNUSED");
17543
17544 m_errorMonitor->ExpectSuccess();
17545
17546 ASSERT_NO_FATAL_FAILURE(InitState());
17547
17548 // A renderpass with no attachments
17549 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17550
17551 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17552
17553 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17554
17555 VkRenderPass rp;
17556 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17557 ASSERT_VK_SUCCESS(err);
17558
17559 // A compatible framebuffer.
17560 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17561 VkFramebuffer fb;
17562 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17563 ASSERT_VK_SUCCESS(err);
17564
17565 // Record a command buffer which just begins and ends the renderpass. The
17566 // bug manifests in BeginRenderPass.
17567 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17568 BeginCommandBuffer();
17569 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17570 vkCmdEndRenderPass(m_commandBuffer->handle());
17571 m_errorMonitor->VerifyNotFound();
17572 EndCommandBuffer();
17573
17574 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17575 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17576}
17577
17578// This is a positive test. No errors are expected.
17579TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17580 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17581 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17582 VkResult result = VK_SUCCESS;
17583 VkImageFormatProperties formatProps;
17584 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17585 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17586 &formatProps);
17587 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17588 return;
17589 }
17590
17591 ASSERT_NO_FATAL_FAILURE(InitState());
17592 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17593 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17594 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17595 VkAttachmentDescription att = {};
17596 VkAttachmentReference ref = {};
17597 att.format = depth_stencil_fmt;
17598 att.samples = VK_SAMPLE_COUNT_1_BIT;
17599 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17600 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17601 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17602 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17603 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17604 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17605
17606 VkClearValue clear;
17607 clear.depthStencil.depth = 1.0;
17608 clear.depthStencil.stencil = 0;
17609 ref.attachment = 0;
17610 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17611
17612 VkSubpassDescription subpass = {};
17613 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17614 subpass.flags = 0;
17615 subpass.inputAttachmentCount = 0;
17616 subpass.pInputAttachments = NULL;
17617 subpass.colorAttachmentCount = 0;
17618 subpass.pColorAttachments = NULL;
17619 subpass.pResolveAttachments = NULL;
17620 subpass.pDepthStencilAttachment = &ref;
17621 subpass.preserveAttachmentCount = 0;
17622 subpass.pPreserveAttachments = NULL;
17623
17624 VkRenderPass rp;
17625 VkRenderPassCreateInfo rp_info = {};
17626 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17627 rp_info.attachmentCount = 1;
17628 rp_info.pAttachments = &att;
17629 rp_info.subpassCount = 1;
17630 rp_info.pSubpasses = &subpass;
17631 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17632 ASSERT_VK_SUCCESS(result);
17633
17634 VkImageView *depthView = m_depthStencil->BindInfo();
17635 VkFramebufferCreateInfo fb_info = {};
17636 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17637 fb_info.pNext = NULL;
17638 fb_info.renderPass = rp;
17639 fb_info.attachmentCount = 1;
17640 fb_info.pAttachments = depthView;
17641 fb_info.width = 100;
17642 fb_info.height = 100;
17643 fb_info.layers = 1;
17644 VkFramebuffer fb;
17645 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17646 ASSERT_VK_SUCCESS(result);
17647
17648 VkRenderPassBeginInfo rpbinfo = {};
17649 rpbinfo.clearValueCount = 1;
17650 rpbinfo.pClearValues = &clear;
17651 rpbinfo.pNext = NULL;
17652 rpbinfo.renderPass = rp;
17653 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17654 rpbinfo.renderArea.extent.width = 100;
17655 rpbinfo.renderArea.extent.height = 100;
17656 rpbinfo.renderArea.offset.x = 0;
17657 rpbinfo.renderArea.offset.y = 0;
17658 rpbinfo.framebuffer = fb;
17659
17660 VkFence fence = {};
17661 VkFenceCreateInfo fence_ci = {};
17662 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17663 fence_ci.pNext = nullptr;
17664 fence_ci.flags = 0;
17665 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17666 ASSERT_VK_SUCCESS(result);
17667
17668 m_commandBuffer->BeginCommandBuffer();
17669 m_commandBuffer->BeginRenderPass(rpbinfo);
17670 m_commandBuffer->EndRenderPass();
17671 m_commandBuffer->EndCommandBuffer();
17672 m_commandBuffer->QueueCommandBuffer(fence);
17673
17674 VkImageObj destImage(m_device);
17675 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17676 VK_IMAGE_TILING_OPTIMAL, 0);
17677 VkImageMemoryBarrier barrier = {};
17678 VkImageSubresourceRange range;
17679 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17680 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17681 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17682 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17683 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17684 barrier.image = m_depthStencil->handle();
17685 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17686 range.baseMipLevel = 0;
17687 range.levelCount = 1;
17688 range.baseArrayLayer = 0;
17689 range.layerCount = 1;
17690 barrier.subresourceRange = range;
17691 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17692 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17693 cmdbuf.BeginCommandBuffer();
17694 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17695 &barrier);
17696 barrier.srcAccessMask = 0;
17697 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17698 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17699 barrier.image = destImage.handle();
17700 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17701 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17702 &barrier);
17703 VkImageCopy cregion;
17704 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17705 cregion.srcSubresource.mipLevel = 0;
17706 cregion.srcSubresource.baseArrayLayer = 0;
17707 cregion.srcSubresource.layerCount = 1;
17708 cregion.srcOffset.x = 0;
17709 cregion.srcOffset.y = 0;
17710 cregion.srcOffset.z = 0;
17711 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17712 cregion.dstSubresource.mipLevel = 0;
17713 cregion.dstSubresource.baseArrayLayer = 0;
17714 cregion.dstSubresource.layerCount = 1;
17715 cregion.dstOffset.x = 0;
17716 cregion.dstOffset.y = 0;
17717 cregion.dstOffset.z = 0;
17718 cregion.extent.width = 100;
17719 cregion.extent.height = 100;
17720 cregion.extent.depth = 1;
17721 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17722 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17723 cmdbuf.EndCommandBuffer();
17724
17725 VkSubmitInfo submit_info;
17726 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17727 submit_info.pNext = NULL;
17728 submit_info.waitSemaphoreCount = 0;
17729 submit_info.pWaitSemaphores = NULL;
17730 submit_info.pWaitDstStageMask = NULL;
17731 submit_info.commandBufferCount = 1;
17732 submit_info.pCommandBuffers = &cmdbuf.handle();
17733 submit_info.signalSemaphoreCount = 0;
17734 submit_info.pSignalSemaphores = NULL;
17735
17736 m_errorMonitor->ExpectSuccess();
17737 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17738 m_errorMonitor->VerifyNotFound();
17739
17740 vkQueueWaitIdle(m_device->m_queue);
17741 vkDestroyFence(m_device->device(), fence, nullptr);
17742 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17743 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17744}
17745
17746// This is a positive test. No errors should be generated.
17747TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17748 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17749
17750 m_errorMonitor->ExpectSuccess();
17751 ASSERT_NO_FATAL_FAILURE(InitState());
17752
17753 VkEvent event;
17754 VkEventCreateInfo event_create_info{};
17755 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17756 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17757
17758 VkCommandPool command_pool;
17759 VkCommandPoolCreateInfo pool_create_info{};
17760 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17761 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17762 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17763 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17764
17765 VkCommandBuffer command_buffer;
17766 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17767 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17768 command_buffer_allocate_info.commandPool = command_pool;
17769 command_buffer_allocate_info.commandBufferCount = 1;
17770 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17771 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17772
17773 VkQueue queue = VK_NULL_HANDLE;
17774 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17775
17776 {
17777 VkCommandBufferBeginInfo begin_info{};
17778 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17779 vkBeginCommandBuffer(command_buffer, &begin_info);
17780
17781 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17782 nullptr, 0, nullptr);
17783 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17784 vkEndCommandBuffer(command_buffer);
17785 }
17786 {
17787 VkSubmitInfo submit_info{};
17788 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17789 submit_info.commandBufferCount = 1;
17790 submit_info.pCommandBuffers = &command_buffer;
17791 submit_info.signalSemaphoreCount = 0;
17792 submit_info.pSignalSemaphores = nullptr;
17793 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17794 }
17795 { vkSetEvent(m_device->device(), event); }
17796
17797 vkQueueWaitIdle(queue);
17798
17799 vkDestroyEvent(m_device->device(), event, nullptr);
17800 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17801 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17802
17803 m_errorMonitor->VerifyNotFound();
17804}
17805// This is a positive test. No errors should be generated.
17806TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17807 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17808
17809 ASSERT_NO_FATAL_FAILURE(InitState());
17810 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17811 return;
17812
17813 m_errorMonitor->ExpectSuccess();
17814
17815 VkQueryPool query_pool;
17816 VkQueryPoolCreateInfo query_pool_create_info{};
17817 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17818 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17819 query_pool_create_info.queryCount = 1;
17820 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17821
17822 VkCommandPool command_pool;
17823 VkCommandPoolCreateInfo pool_create_info{};
17824 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17825 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17826 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17827 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17828
17829 VkCommandBuffer command_buffer;
17830 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17831 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17832 command_buffer_allocate_info.commandPool = command_pool;
17833 command_buffer_allocate_info.commandBufferCount = 1;
17834 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17835 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17836
17837 VkCommandBuffer secondary_command_buffer;
17838 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17839 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17840
17841 VkQueue queue = VK_NULL_HANDLE;
17842 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17843
17844 uint32_t qfi = 0;
17845 VkBufferCreateInfo buff_create_info = {};
17846 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17847 buff_create_info.size = 1024;
17848 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17849 buff_create_info.queueFamilyIndexCount = 1;
17850 buff_create_info.pQueueFamilyIndices = &qfi;
17851
17852 VkResult err;
17853 VkBuffer buffer;
17854 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17855 ASSERT_VK_SUCCESS(err);
17856 VkMemoryAllocateInfo mem_alloc = {};
17857 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17858 mem_alloc.pNext = NULL;
17859 mem_alloc.allocationSize = 1024;
17860 mem_alloc.memoryTypeIndex = 0;
17861
17862 VkMemoryRequirements memReqs;
17863 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17864 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17865 if (!pass) {
17866 vkDestroyBuffer(m_device->device(), buffer, NULL);
17867 return;
17868 }
17869
17870 VkDeviceMemory mem;
17871 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17872 ASSERT_VK_SUCCESS(err);
17873 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17874 ASSERT_VK_SUCCESS(err);
17875
17876 VkCommandBufferInheritanceInfo hinfo = {};
17877 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17878 hinfo.renderPass = VK_NULL_HANDLE;
17879 hinfo.subpass = 0;
17880 hinfo.framebuffer = VK_NULL_HANDLE;
17881 hinfo.occlusionQueryEnable = VK_FALSE;
17882 hinfo.queryFlags = 0;
17883 hinfo.pipelineStatistics = 0;
17884
17885 {
17886 VkCommandBufferBeginInfo begin_info{};
17887 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17888 begin_info.pInheritanceInfo = &hinfo;
17889 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17890
17891 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17892 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17893
17894 vkEndCommandBuffer(secondary_command_buffer);
17895
17896 begin_info.pInheritanceInfo = nullptr;
17897 vkBeginCommandBuffer(command_buffer, &begin_info);
17898
17899 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17900 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17901
17902 vkEndCommandBuffer(command_buffer);
17903 }
17904 {
17905 VkSubmitInfo submit_info{};
17906 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17907 submit_info.commandBufferCount = 1;
17908 submit_info.pCommandBuffers = &command_buffer;
17909 submit_info.signalSemaphoreCount = 0;
17910 submit_info.pSignalSemaphores = nullptr;
17911 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17912 }
17913
17914 vkQueueWaitIdle(queue);
17915
17916 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17917 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17918 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17919 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17920 vkDestroyBuffer(m_device->device(), buffer, NULL);
17921 vkFreeMemory(m_device->device(), mem, NULL);
17922
17923 m_errorMonitor->VerifyNotFound();
17924}
17925
17926// This is a positive test. No errors should be generated.
17927TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17928 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17929
17930 ASSERT_NO_FATAL_FAILURE(InitState());
17931 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17932 return;
17933
17934 m_errorMonitor->ExpectSuccess();
17935
17936 VkQueryPool query_pool;
17937 VkQueryPoolCreateInfo query_pool_create_info{};
17938 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17939 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17940 query_pool_create_info.queryCount = 1;
17941 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17942
17943 VkCommandPool command_pool;
17944 VkCommandPoolCreateInfo pool_create_info{};
17945 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17946 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17947 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17948 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17949
17950 VkCommandBuffer command_buffer[2];
17951 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17952 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17953 command_buffer_allocate_info.commandPool = command_pool;
17954 command_buffer_allocate_info.commandBufferCount = 2;
17955 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17956 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17957
17958 VkQueue queue = VK_NULL_HANDLE;
17959 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17960
17961 uint32_t qfi = 0;
17962 VkBufferCreateInfo buff_create_info = {};
17963 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17964 buff_create_info.size = 1024;
17965 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17966 buff_create_info.queueFamilyIndexCount = 1;
17967 buff_create_info.pQueueFamilyIndices = &qfi;
17968
17969 VkResult err;
17970 VkBuffer buffer;
17971 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17972 ASSERT_VK_SUCCESS(err);
17973 VkMemoryAllocateInfo mem_alloc = {};
17974 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17975 mem_alloc.pNext = NULL;
17976 mem_alloc.allocationSize = 1024;
17977 mem_alloc.memoryTypeIndex = 0;
17978
17979 VkMemoryRequirements memReqs;
17980 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17981 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17982 if (!pass) {
17983 vkDestroyBuffer(m_device->device(), buffer, NULL);
17984 return;
17985 }
17986
17987 VkDeviceMemory mem;
17988 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17989 ASSERT_VK_SUCCESS(err);
17990 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17991 ASSERT_VK_SUCCESS(err);
17992
17993 {
17994 VkCommandBufferBeginInfo begin_info{};
17995 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17996 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17997
17998 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17999 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18000
18001 vkEndCommandBuffer(command_buffer[0]);
18002
18003 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18004
18005 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18006
18007 vkEndCommandBuffer(command_buffer[1]);
18008 }
18009 {
18010 VkSubmitInfo submit_info{};
18011 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18012 submit_info.commandBufferCount = 2;
18013 submit_info.pCommandBuffers = command_buffer;
18014 submit_info.signalSemaphoreCount = 0;
18015 submit_info.pSignalSemaphores = nullptr;
18016 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18017 }
18018
18019 vkQueueWaitIdle(queue);
18020
18021 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18022 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18023 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18024 vkDestroyBuffer(m_device->device(), buffer, NULL);
18025 vkFreeMemory(m_device->device(), mem, NULL);
18026
18027 m_errorMonitor->VerifyNotFound();
18028}
18029
Tony Barbourc46924f2016-11-04 11:49:52 -060018030TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018031 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18032
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018033 ASSERT_NO_FATAL_FAILURE(InitState());
18034 VkEvent event;
18035 VkEventCreateInfo event_create_info{};
18036 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18037 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18038
18039 VkCommandPool command_pool;
18040 VkCommandPoolCreateInfo pool_create_info{};
18041 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18042 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18043 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18044 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18045
18046 VkCommandBuffer command_buffer;
18047 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18048 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18049 command_buffer_allocate_info.commandPool = command_pool;
18050 command_buffer_allocate_info.commandBufferCount = 1;
18051 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18052 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18053
18054 VkQueue queue = VK_NULL_HANDLE;
18055 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18056
18057 {
18058 VkCommandBufferBeginInfo begin_info{};
18059 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18060 vkBeginCommandBuffer(command_buffer, &begin_info);
18061
18062 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018063 vkEndCommandBuffer(command_buffer);
18064 }
18065 {
18066 VkSubmitInfo submit_info{};
18067 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18068 submit_info.commandBufferCount = 1;
18069 submit_info.pCommandBuffers = &command_buffer;
18070 submit_info.signalSemaphoreCount = 0;
18071 submit_info.pSignalSemaphores = nullptr;
18072 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18073 }
18074 {
18075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
18076 "command buffer.");
18077 vkSetEvent(m_device->device(), event);
18078 m_errorMonitor->VerifyFound();
18079 }
18080
18081 vkQueueWaitIdle(queue);
18082
18083 vkDestroyEvent(m_device->device(), event, nullptr);
18084 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18085 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18086}
18087
18088// This is a positive test. No errors should be generated.
18089TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
18090 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
18091 "run through a Submit & WaitForFences cycle 3 times. This "
18092 "previously revealed a bug so running this positive test "
18093 "to prevent a regression.");
18094 m_errorMonitor->ExpectSuccess();
18095
18096 ASSERT_NO_FATAL_FAILURE(InitState());
18097 VkQueue queue = VK_NULL_HANDLE;
18098 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18099
18100 static const uint32_t NUM_OBJECTS = 2;
18101 static const uint32_t NUM_FRAMES = 3;
18102 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18103 VkFence fences[NUM_OBJECTS] = {};
18104
18105 VkCommandPool cmd_pool;
18106 VkCommandPoolCreateInfo cmd_pool_ci = {};
18107 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18108 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18109 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18110 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18111 ASSERT_VK_SUCCESS(err);
18112
18113 VkCommandBufferAllocateInfo cmd_buf_info = {};
18114 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18115 cmd_buf_info.commandPool = cmd_pool;
18116 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18117 cmd_buf_info.commandBufferCount = 1;
18118
18119 VkFenceCreateInfo fence_ci = {};
18120 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18121 fence_ci.pNext = nullptr;
18122 fence_ci.flags = 0;
18123
18124 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18125 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18126 ASSERT_VK_SUCCESS(err);
18127 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18128 ASSERT_VK_SUCCESS(err);
18129 }
18130
18131 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18132 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18133 // Create empty cmd buffer
18134 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18135 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18136
18137 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18138 ASSERT_VK_SUCCESS(err);
18139 err = vkEndCommandBuffer(cmd_buffers[obj]);
18140 ASSERT_VK_SUCCESS(err);
18141
18142 VkSubmitInfo submit_info = {};
18143 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18144 submit_info.commandBufferCount = 1;
18145 submit_info.pCommandBuffers = &cmd_buffers[obj];
18146 // Submit cmd buffer and wait for fence
18147 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18148 ASSERT_VK_SUCCESS(err);
18149 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18150 ASSERT_VK_SUCCESS(err);
18151 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18152 ASSERT_VK_SUCCESS(err);
18153 }
18154 }
18155 m_errorMonitor->VerifyNotFound();
18156 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18157 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18158 vkDestroyFence(m_device->device(), fences[i], nullptr);
18159 }
18160}
18161// This is a positive test. No errors should be generated.
18162TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
18163
18164 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18165 "submitted on separate queues followed by a QueueWaitIdle.");
18166
18167 ASSERT_NO_FATAL_FAILURE(InitState());
18168 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18169 return;
18170
18171 m_errorMonitor->ExpectSuccess();
18172
18173 VkSemaphore semaphore;
18174 VkSemaphoreCreateInfo semaphore_create_info{};
18175 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18176 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18177
18178 VkCommandPool command_pool;
18179 VkCommandPoolCreateInfo pool_create_info{};
18180 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18181 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18182 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18183 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18184
18185 VkCommandBuffer command_buffer[2];
18186 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18187 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18188 command_buffer_allocate_info.commandPool = command_pool;
18189 command_buffer_allocate_info.commandBufferCount = 2;
18190 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18191 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18192
18193 VkQueue queue = VK_NULL_HANDLE;
18194 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18195
18196 {
18197 VkCommandBufferBeginInfo begin_info{};
18198 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18199 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18200
18201 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18202 nullptr, 0, nullptr, 0, nullptr);
18203
18204 VkViewport viewport{};
18205 viewport.maxDepth = 1.0f;
18206 viewport.minDepth = 0.0f;
18207 viewport.width = 512;
18208 viewport.height = 512;
18209 viewport.x = 0;
18210 viewport.y = 0;
18211 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18212 vkEndCommandBuffer(command_buffer[0]);
18213 }
18214 {
18215 VkCommandBufferBeginInfo begin_info{};
18216 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18217 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18218
18219 VkViewport viewport{};
18220 viewport.maxDepth = 1.0f;
18221 viewport.minDepth = 0.0f;
18222 viewport.width = 512;
18223 viewport.height = 512;
18224 viewport.x = 0;
18225 viewport.y = 0;
18226 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18227 vkEndCommandBuffer(command_buffer[1]);
18228 }
18229 {
18230 VkSubmitInfo submit_info{};
18231 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18232 submit_info.commandBufferCount = 1;
18233 submit_info.pCommandBuffers = &command_buffer[0];
18234 submit_info.signalSemaphoreCount = 1;
18235 submit_info.pSignalSemaphores = &semaphore;
18236 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18237 }
18238 {
18239 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18240 VkSubmitInfo submit_info{};
18241 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18242 submit_info.commandBufferCount = 1;
18243 submit_info.pCommandBuffers = &command_buffer[1];
18244 submit_info.waitSemaphoreCount = 1;
18245 submit_info.pWaitSemaphores = &semaphore;
18246 submit_info.pWaitDstStageMask = flags;
18247 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18248 }
18249
18250 vkQueueWaitIdle(m_device->m_queue);
18251
18252 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18253 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18254 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18255
18256 m_errorMonitor->VerifyNotFound();
18257}
18258
18259// This is a positive test. No errors should be generated.
18260TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18261
18262 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18263 "submitted on separate queues, the second having a fence"
18264 "followed by a QueueWaitIdle.");
18265
18266 ASSERT_NO_FATAL_FAILURE(InitState());
18267 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18268 return;
18269
18270 m_errorMonitor->ExpectSuccess();
18271
18272 VkFence fence;
18273 VkFenceCreateInfo fence_create_info{};
18274 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18275 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18276
18277 VkSemaphore semaphore;
18278 VkSemaphoreCreateInfo semaphore_create_info{};
18279 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18280 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18281
18282 VkCommandPool command_pool;
18283 VkCommandPoolCreateInfo pool_create_info{};
18284 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18285 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18286 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18287 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18288
18289 VkCommandBuffer command_buffer[2];
18290 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18291 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18292 command_buffer_allocate_info.commandPool = command_pool;
18293 command_buffer_allocate_info.commandBufferCount = 2;
18294 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18295 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18296
18297 VkQueue queue = VK_NULL_HANDLE;
18298 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18299
18300 {
18301 VkCommandBufferBeginInfo begin_info{};
18302 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18303 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18304
18305 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18306 nullptr, 0, nullptr, 0, nullptr);
18307
18308 VkViewport viewport{};
18309 viewport.maxDepth = 1.0f;
18310 viewport.minDepth = 0.0f;
18311 viewport.width = 512;
18312 viewport.height = 512;
18313 viewport.x = 0;
18314 viewport.y = 0;
18315 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18316 vkEndCommandBuffer(command_buffer[0]);
18317 }
18318 {
18319 VkCommandBufferBeginInfo begin_info{};
18320 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18321 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18322
18323 VkViewport viewport{};
18324 viewport.maxDepth = 1.0f;
18325 viewport.minDepth = 0.0f;
18326 viewport.width = 512;
18327 viewport.height = 512;
18328 viewport.x = 0;
18329 viewport.y = 0;
18330 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18331 vkEndCommandBuffer(command_buffer[1]);
18332 }
18333 {
18334 VkSubmitInfo submit_info{};
18335 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18336 submit_info.commandBufferCount = 1;
18337 submit_info.pCommandBuffers = &command_buffer[0];
18338 submit_info.signalSemaphoreCount = 1;
18339 submit_info.pSignalSemaphores = &semaphore;
18340 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18341 }
18342 {
18343 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18344 VkSubmitInfo submit_info{};
18345 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18346 submit_info.commandBufferCount = 1;
18347 submit_info.pCommandBuffers = &command_buffer[1];
18348 submit_info.waitSemaphoreCount = 1;
18349 submit_info.pWaitSemaphores = &semaphore;
18350 submit_info.pWaitDstStageMask = flags;
18351 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18352 }
18353
18354 vkQueueWaitIdle(m_device->m_queue);
18355
18356 vkDestroyFence(m_device->device(), fence, nullptr);
18357 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18358 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18359 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18360
18361 m_errorMonitor->VerifyNotFound();
18362}
18363
18364// This is a positive test. No errors should be generated.
18365TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18366
18367 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18368 "submitted on separate queues, the second having a fence"
18369 "followed by two consecutive WaitForFences calls on the same fence.");
18370
18371 ASSERT_NO_FATAL_FAILURE(InitState());
18372 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18373 return;
18374
18375 m_errorMonitor->ExpectSuccess();
18376
18377 VkFence fence;
18378 VkFenceCreateInfo fence_create_info{};
18379 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18380 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18381
18382 VkSemaphore semaphore;
18383 VkSemaphoreCreateInfo semaphore_create_info{};
18384 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18385 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18386
18387 VkCommandPool command_pool;
18388 VkCommandPoolCreateInfo pool_create_info{};
18389 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18390 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18391 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18392 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18393
18394 VkCommandBuffer command_buffer[2];
18395 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18396 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18397 command_buffer_allocate_info.commandPool = command_pool;
18398 command_buffer_allocate_info.commandBufferCount = 2;
18399 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18400 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18401
18402 VkQueue queue = VK_NULL_HANDLE;
18403 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18404
18405 {
18406 VkCommandBufferBeginInfo begin_info{};
18407 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18408 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18409
18410 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18411 nullptr, 0, nullptr, 0, nullptr);
18412
18413 VkViewport viewport{};
18414 viewport.maxDepth = 1.0f;
18415 viewport.minDepth = 0.0f;
18416 viewport.width = 512;
18417 viewport.height = 512;
18418 viewport.x = 0;
18419 viewport.y = 0;
18420 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18421 vkEndCommandBuffer(command_buffer[0]);
18422 }
18423 {
18424 VkCommandBufferBeginInfo begin_info{};
18425 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18426 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18427
18428 VkViewport viewport{};
18429 viewport.maxDepth = 1.0f;
18430 viewport.minDepth = 0.0f;
18431 viewport.width = 512;
18432 viewport.height = 512;
18433 viewport.x = 0;
18434 viewport.y = 0;
18435 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18436 vkEndCommandBuffer(command_buffer[1]);
18437 }
18438 {
18439 VkSubmitInfo submit_info{};
18440 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18441 submit_info.commandBufferCount = 1;
18442 submit_info.pCommandBuffers = &command_buffer[0];
18443 submit_info.signalSemaphoreCount = 1;
18444 submit_info.pSignalSemaphores = &semaphore;
18445 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18446 }
18447 {
18448 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18449 VkSubmitInfo submit_info{};
18450 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18451 submit_info.commandBufferCount = 1;
18452 submit_info.pCommandBuffers = &command_buffer[1];
18453 submit_info.waitSemaphoreCount = 1;
18454 submit_info.pWaitSemaphores = &semaphore;
18455 submit_info.pWaitDstStageMask = flags;
18456 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18457 }
18458
18459 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18460 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18461
18462 vkDestroyFence(m_device->device(), fence, nullptr);
18463 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18464 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18465 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18466
18467 m_errorMonitor->VerifyNotFound();
18468}
18469
18470TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18471
18472 ASSERT_NO_FATAL_FAILURE(InitState());
18473 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18474 printf("Test requires two queues, skipping\n");
18475 return;
18476 }
18477
18478 VkResult err;
18479
18480 m_errorMonitor->ExpectSuccess();
18481
18482 VkQueue q0 = m_device->m_queue;
18483 VkQueue q1 = nullptr;
18484 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18485 ASSERT_NE(q1, nullptr);
18486
18487 // An (empty) command buffer. We must have work in the first submission --
18488 // the layer treats unfenced work differently from fenced work.
18489 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18490 VkCommandPool pool;
18491 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18492 ASSERT_VK_SUCCESS(err);
18493 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18494 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18495 VkCommandBuffer cb;
18496 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18497 ASSERT_VK_SUCCESS(err);
18498 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18499 err = vkBeginCommandBuffer(cb, &cbbi);
18500 ASSERT_VK_SUCCESS(err);
18501 err = vkEndCommandBuffer(cb);
18502 ASSERT_VK_SUCCESS(err);
18503
18504 // A semaphore
18505 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18506 VkSemaphore s;
18507 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18508 ASSERT_VK_SUCCESS(err);
18509
18510 // First submission, to q0
18511 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18512
18513 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18514 ASSERT_VK_SUCCESS(err);
18515
18516 // Second submission, to q1, waiting on s
18517 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18518 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18519
18520 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18521 ASSERT_VK_SUCCESS(err);
18522
18523 // Wait for q0 idle
18524 err = vkQueueWaitIdle(q0);
18525 ASSERT_VK_SUCCESS(err);
18526
18527 // Command buffer should have been completed (it was on q0); reset the pool.
18528 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18529
18530 m_errorMonitor->VerifyNotFound();
18531
18532 // Force device completely idle and clean up resources
18533 vkDeviceWaitIdle(m_device->device());
18534 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18535 vkDestroySemaphore(m_device->device(), s, nullptr);
18536}
18537
18538// This is a positive test. No errors should be generated.
18539TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18540
18541 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18542 "submitted on separate queues, the second having a fence, "
18543 "followed by a WaitForFences call.");
18544
18545 ASSERT_NO_FATAL_FAILURE(InitState());
18546 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18547 return;
18548
18549 m_errorMonitor->ExpectSuccess();
18550
18551 ASSERT_NO_FATAL_FAILURE(InitState());
18552 VkFence fence;
18553 VkFenceCreateInfo fence_create_info{};
18554 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18555 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18556
18557 VkSemaphore semaphore;
18558 VkSemaphoreCreateInfo semaphore_create_info{};
18559 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18560 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18561
18562 VkCommandPool command_pool;
18563 VkCommandPoolCreateInfo pool_create_info{};
18564 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18565 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18566 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18567 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18568
18569 VkCommandBuffer command_buffer[2];
18570 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18571 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18572 command_buffer_allocate_info.commandPool = command_pool;
18573 command_buffer_allocate_info.commandBufferCount = 2;
18574 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18575 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18576
18577 VkQueue queue = VK_NULL_HANDLE;
18578 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18579
18580 {
18581 VkCommandBufferBeginInfo begin_info{};
18582 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18583 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18584
18585 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18586 nullptr, 0, nullptr, 0, nullptr);
18587
18588 VkViewport viewport{};
18589 viewport.maxDepth = 1.0f;
18590 viewport.minDepth = 0.0f;
18591 viewport.width = 512;
18592 viewport.height = 512;
18593 viewport.x = 0;
18594 viewport.y = 0;
18595 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18596 vkEndCommandBuffer(command_buffer[0]);
18597 }
18598 {
18599 VkCommandBufferBeginInfo begin_info{};
18600 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18601 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18602
18603 VkViewport viewport{};
18604 viewport.maxDepth = 1.0f;
18605 viewport.minDepth = 0.0f;
18606 viewport.width = 512;
18607 viewport.height = 512;
18608 viewport.x = 0;
18609 viewport.y = 0;
18610 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18611 vkEndCommandBuffer(command_buffer[1]);
18612 }
18613 {
18614 VkSubmitInfo submit_info{};
18615 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18616 submit_info.commandBufferCount = 1;
18617 submit_info.pCommandBuffers = &command_buffer[0];
18618 submit_info.signalSemaphoreCount = 1;
18619 submit_info.pSignalSemaphores = &semaphore;
18620 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18621 }
18622 {
18623 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18624 VkSubmitInfo submit_info{};
18625 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18626 submit_info.commandBufferCount = 1;
18627 submit_info.pCommandBuffers = &command_buffer[1];
18628 submit_info.waitSemaphoreCount = 1;
18629 submit_info.pWaitSemaphores = &semaphore;
18630 submit_info.pWaitDstStageMask = flags;
18631 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18632 }
18633
18634 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18635
18636 vkDestroyFence(m_device->device(), fence, nullptr);
18637 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18638 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18639 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18640
18641 m_errorMonitor->VerifyNotFound();
18642}
18643
18644// This is a positive test. No errors should be generated.
18645TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18646
18647 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18648 "on the same queue, sharing a signal/wait semaphore, the "
18649 "second having a fence, "
18650 "followed by a WaitForFences call.");
18651
18652 m_errorMonitor->ExpectSuccess();
18653
18654 ASSERT_NO_FATAL_FAILURE(InitState());
18655 VkFence fence;
18656 VkFenceCreateInfo fence_create_info{};
18657 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18658 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18659
18660 VkSemaphore semaphore;
18661 VkSemaphoreCreateInfo semaphore_create_info{};
18662 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18663 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18664
18665 VkCommandPool command_pool;
18666 VkCommandPoolCreateInfo pool_create_info{};
18667 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18668 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18669 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18670 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18671
18672 VkCommandBuffer command_buffer[2];
18673 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18674 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18675 command_buffer_allocate_info.commandPool = command_pool;
18676 command_buffer_allocate_info.commandBufferCount = 2;
18677 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18678 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18679
18680 {
18681 VkCommandBufferBeginInfo begin_info{};
18682 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18683 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18684
18685 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18686 nullptr, 0, nullptr, 0, nullptr);
18687
18688 VkViewport viewport{};
18689 viewport.maxDepth = 1.0f;
18690 viewport.minDepth = 0.0f;
18691 viewport.width = 512;
18692 viewport.height = 512;
18693 viewport.x = 0;
18694 viewport.y = 0;
18695 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18696 vkEndCommandBuffer(command_buffer[0]);
18697 }
18698 {
18699 VkCommandBufferBeginInfo begin_info{};
18700 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18701 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18702
18703 VkViewport viewport{};
18704 viewport.maxDepth = 1.0f;
18705 viewport.minDepth = 0.0f;
18706 viewport.width = 512;
18707 viewport.height = 512;
18708 viewport.x = 0;
18709 viewport.y = 0;
18710 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18711 vkEndCommandBuffer(command_buffer[1]);
18712 }
18713 {
18714 VkSubmitInfo submit_info{};
18715 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18716 submit_info.commandBufferCount = 1;
18717 submit_info.pCommandBuffers = &command_buffer[0];
18718 submit_info.signalSemaphoreCount = 1;
18719 submit_info.pSignalSemaphores = &semaphore;
18720 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18721 }
18722 {
18723 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18724 VkSubmitInfo submit_info{};
18725 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18726 submit_info.commandBufferCount = 1;
18727 submit_info.pCommandBuffers = &command_buffer[1];
18728 submit_info.waitSemaphoreCount = 1;
18729 submit_info.pWaitSemaphores = &semaphore;
18730 submit_info.pWaitDstStageMask = flags;
18731 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18732 }
18733
18734 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18735
18736 vkDestroyFence(m_device->device(), fence, nullptr);
18737 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18738 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18739 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18740
18741 m_errorMonitor->VerifyNotFound();
18742}
18743
18744// This is a positive test. No errors should be generated.
18745TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18746
18747 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18748 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18749 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18750
18751 m_errorMonitor->ExpectSuccess();
18752
18753 ASSERT_NO_FATAL_FAILURE(InitState());
18754 VkFence fence;
18755 VkFenceCreateInfo fence_create_info{};
18756 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18757 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18758
18759 VkCommandPool command_pool;
18760 VkCommandPoolCreateInfo pool_create_info{};
18761 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18762 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18763 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18764 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18765
18766 VkCommandBuffer command_buffer[2];
18767 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18768 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18769 command_buffer_allocate_info.commandPool = command_pool;
18770 command_buffer_allocate_info.commandBufferCount = 2;
18771 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18772 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18773
18774 {
18775 VkCommandBufferBeginInfo begin_info{};
18776 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18777 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18778
18779 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18780 nullptr, 0, nullptr, 0, nullptr);
18781
18782 VkViewport viewport{};
18783 viewport.maxDepth = 1.0f;
18784 viewport.minDepth = 0.0f;
18785 viewport.width = 512;
18786 viewport.height = 512;
18787 viewport.x = 0;
18788 viewport.y = 0;
18789 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18790 vkEndCommandBuffer(command_buffer[0]);
18791 }
18792 {
18793 VkCommandBufferBeginInfo begin_info{};
18794 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18795 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18796
18797 VkViewport viewport{};
18798 viewport.maxDepth = 1.0f;
18799 viewport.minDepth = 0.0f;
18800 viewport.width = 512;
18801 viewport.height = 512;
18802 viewport.x = 0;
18803 viewport.y = 0;
18804 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18805 vkEndCommandBuffer(command_buffer[1]);
18806 }
18807 {
18808 VkSubmitInfo submit_info{};
18809 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18810 submit_info.commandBufferCount = 1;
18811 submit_info.pCommandBuffers = &command_buffer[0];
18812 submit_info.signalSemaphoreCount = 0;
18813 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18814 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18815 }
18816 {
18817 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18818 VkSubmitInfo submit_info{};
18819 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18820 submit_info.commandBufferCount = 1;
18821 submit_info.pCommandBuffers = &command_buffer[1];
18822 submit_info.waitSemaphoreCount = 0;
18823 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18824 submit_info.pWaitDstStageMask = flags;
18825 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18826 }
18827
18828 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18829
18830 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18831 ASSERT_VK_SUCCESS(err);
18832
18833 vkDestroyFence(m_device->device(), fence, nullptr);
18834 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18835 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18836
18837 m_errorMonitor->VerifyNotFound();
18838}
18839
18840// This is a positive test. No errors should be generated.
18841TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18842
18843 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18844 "on the same queue, the second having a fence, followed "
18845 "by a WaitForFences call.");
18846
18847 m_errorMonitor->ExpectSuccess();
18848
18849 ASSERT_NO_FATAL_FAILURE(InitState());
18850 VkFence fence;
18851 VkFenceCreateInfo fence_create_info{};
18852 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18853 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18854
18855 VkCommandPool command_pool;
18856 VkCommandPoolCreateInfo pool_create_info{};
18857 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18858 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18859 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18860 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18861
18862 VkCommandBuffer command_buffer[2];
18863 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18864 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18865 command_buffer_allocate_info.commandPool = command_pool;
18866 command_buffer_allocate_info.commandBufferCount = 2;
18867 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18868 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18869
18870 {
18871 VkCommandBufferBeginInfo begin_info{};
18872 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18873 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18874
18875 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18876 nullptr, 0, nullptr, 0, nullptr);
18877
18878 VkViewport viewport{};
18879 viewport.maxDepth = 1.0f;
18880 viewport.minDepth = 0.0f;
18881 viewport.width = 512;
18882 viewport.height = 512;
18883 viewport.x = 0;
18884 viewport.y = 0;
18885 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18886 vkEndCommandBuffer(command_buffer[0]);
18887 }
18888 {
18889 VkCommandBufferBeginInfo begin_info{};
18890 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18891 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18892
18893 VkViewport viewport{};
18894 viewport.maxDepth = 1.0f;
18895 viewport.minDepth = 0.0f;
18896 viewport.width = 512;
18897 viewport.height = 512;
18898 viewport.x = 0;
18899 viewport.y = 0;
18900 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18901 vkEndCommandBuffer(command_buffer[1]);
18902 }
18903 {
18904 VkSubmitInfo submit_info{};
18905 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18906 submit_info.commandBufferCount = 1;
18907 submit_info.pCommandBuffers = &command_buffer[0];
18908 submit_info.signalSemaphoreCount = 0;
18909 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18910 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18911 }
18912 {
18913 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18914 VkSubmitInfo submit_info{};
18915 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18916 submit_info.commandBufferCount = 1;
18917 submit_info.pCommandBuffers = &command_buffer[1];
18918 submit_info.waitSemaphoreCount = 0;
18919 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18920 submit_info.pWaitDstStageMask = flags;
18921 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18922 }
18923
18924 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18925
18926 vkDestroyFence(m_device->device(), fence, nullptr);
18927 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18928 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18929
18930 m_errorMonitor->VerifyNotFound();
18931}
18932
18933// This is a positive test. No errors should be generated.
18934TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18935
18936 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18937 "QueueSubmit call followed by a WaitForFences call.");
18938 ASSERT_NO_FATAL_FAILURE(InitState());
18939
18940 m_errorMonitor->ExpectSuccess();
18941
18942 VkFence fence;
18943 VkFenceCreateInfo fence_create_info{};
18944 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18945 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18946
18947 VkSemaphore semaphore;
18948 VkSemaphoreCreateInfo semaphore_create_info{};
18949 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18950 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18951
18952 VkCommandPool command_pool;
18953 VkCommandPoolCreateInfo pool_create_info{};
18954 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18955 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18956 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18957 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18958
18959 VkCommandBuffer command_buffer[2];
18960 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18961 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18962 command_buffer_allocate_info.commandPool = command_pool;
18963 command_buffer_allocate_info.commandBufferCount = 2;
18964 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18965 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18966
18967 {
18968 VkCommandBufferBeginInfo begin_info{};
18969 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18970 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18971
18972 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18973 nullptr, 0, nullptr, 0, nullptr);
18974
18975 VkViewport viewport{};
18976 viewport.maxDepth = 1.0f;
18977 viewport.minDepth = 0.0f;
18978 viewport.width = 512;
18979 viewport.height = 512;
18980 viewport.x = 0;
18981 viewport.y = 0;
18982 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18983 vkEndCommandBuffer(command_buffer[0]);
18984 }
18985 {
18986 VkCommandBufferBeginInfo begin_info{};
18987 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18988 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18989
18990 VkViewport viewport{};
18991 viewport.maxDepth = 1.0f;
18992 viewport.minDepth = 0.0f;
18993 viewport.width = 512;
18994 viewport.height = 512;
18995 viewport.x = 0;
18996 viewport.y = 0;
18997 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18998 vkEndCommandBuffer(command_buffer[1]);
18999 }
19000 {
19001 VkSubmitInfo submit_info[2];
19002 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19003
19004 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19005 submit_info[0].pNext = NULL;
19006 submit_info[0].commandBufferCount = 1;
19007 submit_info[0].pCommandBuffers = &command_buffer[0];
19008 submit_info[0].signalSemaphoreCount = 1;
19009 submit_info[0].pSignalSemaphores = &semaphore;
19010 submit_info[0].waitSemaphoreCount = 0;
19011 submit_info[0].pWaitSemaphores = NULL;
19012 submit_info[0].pWaitDstStageMask = 0;
19013
19014 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19015 submit_info[1].pNext = NULL;
19016 submit_info[1].commandBufferCount = 1;
19017 submit_info[1].pCommandBuffers = &command_buffer[1];
19018 submit_info[1].waitSemaphoreCount = 1;
19019 submit_info[1].pWaitSemaphores = &semaphore;
19020 submit_info[1].pWaitDstStageMask = flags;
19021 submit_info[1].signalSemaphoreCount = 0;
19022 submit_info[1].pSignalSemaphores = NULL;
19023 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19024 }
19025
19026 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19027
19028 vkDestroyFence(m_device->device(), fence, nullptr);
19029 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19030 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19031 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19032
19033 m_errorMonitor->VerifyNotFound();
19034}
19035
19036TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19037 m_errorMonitor->ExpectSuccess();
19038
19039 ASSERT_NO_FATAL_FAILURE(InitState());
19040 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19041
19042 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
19043 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
19044
19045 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19046 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19047 m_errorMonitor->VerifyNotFound();
19048 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19049 m_errorMonitor->VerifyNotFound();
19050 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19051 m_errorMonitor->VerifyNotFound();
19052
19053 m_commandBuffer->EndCommandBuffer();
19054 m_errorMonitor->VerifyNotFound();
19055}
19056
19057TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
19058 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
19059 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19060 "has a valid layout, and a second subpass then uses a "
19061 "valid *READ_ONLY* layout.");
19062 m_errorMonitor->ExpectSuccess();
19063 ASSERT_NO_FATAL_FAILURE(InitState());
19064
19065 VkAttachmentReference attach[2] = {};
19066 attach[0].attachment = 0;
19067 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19068 attach[1].attachment = 0;
19069 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19070 VkSubpassDescription subpasses[2] = {};
19071 // First subpass clears DS attach on load
19072 subpasses[0].pDepthStencilAttachment = &attach[0];
19073 // 2nd subpass reads in DS as input attachment
19074 subpasses[1].inputAttachmentCount = 1;
19075 subpasses[1].pInputAttachments = &attach[1];
19076 VkAttachmentDescription attach_desc = {};
19077 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19078 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19079 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19080 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19081 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19082 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19083 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19084 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19085 VkRenderPassCreateInfo rpci = {};
19086 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19087 rpci.attachmentCount = 1;
19088 rpci.pAttachments = &attach_desc;
19089 rpci.subpassCount = 2;
19090 rpci.pSubpasses = subpasses;
19091
19092 // Now create RenderPass and verify no errors
19093 VkRenderPass rp;
19094 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19095 m_errorMonitor->VerifyNotFound();
19096
19097 vkDestroyRenderPass(m_device->device(), rp, NULL);
19098}
19099
19100TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
19101 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
19102 "as vertex attributes");
19103 m_errorMonitor->ExpectSuccess();
19104
19105 ASSERT_NO_FATAL_FAILURE(InitState());
19106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19107
19108 VkVertexInputBindingDescription input_binding;
19109 memset(&input_binding, 0, sizeof(input_binding));
19110
19111 VkVertexInputAttributeDescription input_attribs[2];
19112 memset(input_attribs, 0, sizeof(input_attribs));
19113
19114 for (int i = 0; i < 2; i++) {
19115 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19116 input_attribs[i].location = i;
19117 }
19118
19119 char const *vsSource = "#version 450\n"
19120 "\n"
19121 "layout(location=0) in mat2x4 x;\n"
19122 "out gl_PerVertex {\n"
19123 " vec4 gl_Position;\n"
19124 "};\n"
19125 "void main(){\n"
19126 " gl_Position = x[0] + x[1];\n"
19127 "}\n";
19128 char const *fsSource = "#version 450\n"
19129 "\n"
19130 "layout(location=0) out vec4 color;\n"
19131 "void main(){\n"
19132 " color = vec4(1);\n"
19133 "}\n";
19134
19135 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19136 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19137
19138 VkPipelineObj pipe(m_device);
19139 pipe.AddColorAttachment();
19140 pipe.AddShader(&vs);
19141 pipe.AddShader(&fs);
19142
19143 pipe.AddVertexInputBindings(&input_binding, 1);
19144 pipe.AddVertexInputAttribs(input_attribs, 2);
19145
19146 VkDescriptorSetObj descriptorSet(m_device);
19147 descriptorSet.AppendDummy();
19148 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19149
19150 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19151
19152 /* expect success */
19153 m_errorMonitor->VerifyNotFound();
19154}
19155
19156TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19157 m_errorMonitor->ExpectSuccess();
19158
19159 ASSERT_NO_FATAL_FAILURE(InitState());
19160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19161
19162 VkVertexInputBindingDescription input_binding;
19163 memset(&input_binding, 0, sizeof(input_binding));
19164
19165 VkVertexInputAttributeDescription input_attribs[2];
19166 memset(input_attribs, 0, sizeof(input_attribs));
19167
19168 for (int i = 0; i < 2; i++) {
19169 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19170 input_attribs[i].location = i;
19171 }
19172
19173 char const *vsSource = "#version 450\n"
19174 "\n"
19175 "layout(location=0) in vec4 x[2];\n"
19176 "out gl_PerVertex {\n"
19177 " vec4 gl_Position;\n"
19178 "};\n"
19179 "void main(){\n"
19180 " gl_Position = x[0] + x[1];\n"
19181 "}\n";
19182 char const *fsSource = "#version 450\n"
19183 "\n"
19184 "layout(location=0) out vec4 color;\n"
19185 "void main(){\n"
19186 " color = vec4(1);\n"
19187 "}\n";
19188
19189 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19190 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19191
19192 VkPipelineObj pipe(m_device);
19193 pipe.AddColorAttachment();
19194 pipe.AddShader(&vs);
19195 pipe.AddShader(&fs);
19196
19197 pipe.AddVertexInputBindings(&input_binding, 1);
19198 pipe.AddVertexInputAttribs(input_attribs, 2);
19199
19200 VkDescriptorSetObj descriptorSet(m_device);
19201 descriptorSet.AppendDummy();
19202 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19203
19204 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19205
19206 m_errorMonitor->VerifyNotFound();
19207}
19208
19209TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
19210 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
19211 "through multiple vertex shader inputs, each consuming a different "
19212 "subset of the components.");
19213 m_errorMonitor->ExpectSuccess();
19214
19215 ASSERT_NO_FATAL_FAILURE(InitState());
19216 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19217
19218 VkVertexInputBindingDescription input_binding;
19219 memset(&input_binding, 0, sizeof(input_binding));
19220
19221 VkVertexInputAttributeDescription input_attribs[3];
19222 memset(input_attribs, 0, sizeof(input_attribs));
19223
19224 for (int i = 0; i < 3; i++) {
19225 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19226 input_attribs[i].location = i;
19227 }
19228
19229 char const *vsSource = "#version 450\n"
19230 "\n"
19231 "layout(location=0) in vec4 x;\n"
19232 "layout(location=1) in vec3 y1;\n"
19233 "layout(location=1, component=3) in float y2;\n"
19234 "layout(location=2) in vec4 z;\n"
19235 "out gl_PerVertex {\n"
19236 " vec4 gl_Position;\n"
19237 "};\n"
19238 "void main(){\n"
19239 " gl_Position = x + vec4(y1, y2) + z;\n"
19240 "}\n";
19241 char const *fsSource = "#version 450\n"
19242 "\n"
19243 "layout(location=0) out vec4 color;\n"
19244 "void main(){\n"
19245 " color = vec4(1);\n"
19246 "}\n";
19247
19248 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19249 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19250
19251 VkPipelineObj pipe(m_device);
19252 pipe.AddColorAttachment();
19253 pipe.AddShader(&vs);
19254 pipe.AddShader(&fs);
19255
19256 pipe.AddVertexInputBindings(&input_binding, 1);
19257 pipe.AddVertexInputAttribs(input_attribs, 3);
19258
19259 VkDescriptorSetObj descriptorSet(m_device);
19260 descriptorSet.AppendDummy();
19261 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19262
19263 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19264
19265 m_errorMonitor->VerifyNotFound();
19266}
19267
19268TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19269 m_errorMonitor->ExpectSuccess();
19270
19271 ASSERT_NO_FATAL_FAILURE(InitState());
19272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19273
19274 char const *vsSource = "#version 450\n"
19275 "out gl_PerVertex {\n"
19276 " vec4 gl_Position;\n"
19277 "};\n"
19278 "void main(){\n"
19279 " gl_Position = vec4(0);\n"
19280 "}\n";
19281 char const *fsSource = "#version 450\n"
19282 "\n"
19283 "layout(location=0) out vec4 color;\n"
19284 "void main(){\n"
19285 " color = vec4(1);\n"
19286 "}\n";
19287
19288 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19289 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19290
19291 VkPipelineObj pipe(m_device);
19292 pipe.AddColorAttachment();
19293 pipe.AddShader(&vs);
19294 pipe.AddShader(&fs);
19295
19296 VkDescriptorSetObj descriptorSet(m_device);
19297 descriptorSet.AppendDummy();
19298 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19299
19300 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19301
19302 m_errorMonitor->VerifyNotFound();
19303}
19304
19305TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19306 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19307 "set out in 14.1.3: fundamental type must match, and producer side must "
19308 "have at least as many components");
19309 m_errorMonitor->ExpectSuccess();
19310
19311 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19312
19313 ASSERT_NO_FATAL_FAILURE(InitState());
19314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19315
19316 char const *vsSource = "#version 450\n"
19317 "out gl_PerVertex {\n"
19318 " vec4 gl_Position;\n"
19319 "};\n"
19320 "layout(location=0) out vec3 x;\n"
19321 "layout(location=1) out ivec3 y;\n"
19322 "layout(location=2) out vec3 z;\n"
19323 "void main(){\n"
19324 " gl_Position = vec4(0);\n"
19325 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19326 "}\n";
19327 char const *fsSource = "#version 450\n"
19328 "\n"
19329 "layout(location=0) out vec4 color;\n"
19330 "layout(location=0) in float x;\n"
19331 "layout(location=1) flat in int y;\n"
19332 "layout(location=2) in vec2 z;\n"
19333 "void main(){\n"
19334 " color = vec4(1 + x + y + z.x);\n"
19335 "}\n";
19336
19337 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19338 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19339
19340 VkPipelineObj pipe(m_device);
19341 pipe.AddColorAttachment();
19342 pipe.AddShader(&vs);
19343 pipe.AddShader(&fs);
19344
19345 VkDescriptorSetObj descriptorSet(m_device);
19346 descriptorSet.AppendDummy();
19347 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19348
19349 VkResult err = VK_SUCCESS;
19350 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19351 ASSERT_VK_SUCCESS(err);
19352
19353 m_errorMonitor->VerifyNotFound();
19354}
19355
19356TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19357 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19358 "passed between the TCS and TES stages");
19359 m_errorMonitor->ExpectSuccess();
19360
19361 ASSERT_NO_FATAL_FAILURE(InitState());
19362 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19363
19364 if (!m_device->phy().features().tessellationShader) {
19365 printf("Device does not support tessellation shaders; skipped.\n");
19366 return;
19367 }
19368
19369 char const *vsSource = "#version 450\n"
19370 "void main(){}\n";
19371 char const *tcsSource = "#version 450\n"
19372 "layout(location=0) out int x[];\n"
19373 "layout(vertices=3) out;\n"
19374 "void main(){\n"
19375 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19376 " gl_TessLevelInner[0] = 1;\n"
19377 " x[gl_InvocationID] = gl_InvocationID;\n"
19378 "}\n";
19379 char const *tesSource = "#version 450\n"
19380 "layout(triangles, equal_spacing, cw) in;\n"
19381 "layout(location=0) in int x[];\n"
19382 "out gl_PerVertex { vec4 gl_Position; };\n"
19383 "void main(){\n"
19384 " gl_Position.xyz = gl_TessCoord;\n"
19385 " gl_Position.w = x[0] + x[1] + x[2];\n"
19386 "}\n";
19387 char const *fsSource = "#version 450\n"
19388 "layout(location=0) out vec4 color;\n"
19389 "void main(){\n"
19390 " color = vec4(1);\n"
19391 "}\n";
19392
19393 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19394 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19395 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19396 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19397
19398 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19399 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19400
19401 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19402
19403 VkPipelineObj pipe(m_device);
19404 pipe.SetInputAssembly(&iasci);
19405 pipe.SetTessellation(&tsci);
19406 pipe.AddColorAttachment();
19407 pipe.AddShader(&vs);
19408 pipe.AddShader(&tcs);
19409 pipe.AddShader(&tes);
19410 pipe.AddShader(&fs);
19411
19412 VkDescriptorSetObj descriptorSet(m_device);
19413 descriptorSet.AppendDummy();
19414 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19415
19416 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19417
19418 m_errorMonitor->VerifyNotFound();
19419}
19420
19421TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19422 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19423 "interface block passed into the geometry shader. This "
19424 "is interesting because the 'extra' array level is not "
19425 "present on the member type, but on the block instance.");
19426 m_errorMonitor->ExpectSuccess();
19427
19428 ASSERT_NO_FATAL_FAILURE(InitState());
19429 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19430
19431 if (!m_device->phy().features().geometryShader) {
19432 printf("Device does not support geometry shaders; skipped.\n");
19433 return;
19434 }
19435
19436 char const *vsSource = "#version 450\n"
19437 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19438 "void main(){\n"
19439 " vs_out.x = vec4(1);\n"
19440 "}\n";
19441 char const *gsSource = "#version 450\n"
19442 "layout(triangles) in;\n"
19443 "layout(triangle_strip, max_vertices=3) out;\n"
19444 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19445 "out gl_PerVertex { vec4 gl_Position; };\n"
19446 "void main() {\n"
19447 " gl_Position = gs_in[0].x;\n"
19448 " EmitVertex();\n"
19449 "}\n";
19450 char const *fsSource = "#version 450\n"
19451 "layout(location=0) out vec4 color;\n"
19452 "void main(){\n"
19453 " color = vec4(1);\n"
19454 "}\n";
19455
19456 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19457 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19458 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19459
19460 VkPipelineObj pipe(m_device);
19461 pipe.AddColorAttachment();
19462 pipe.AddShader(&vs);
19463 pipe.AddShader(&gs);
19464 pipe.AddShader(&fs);
19465
19466 VkDescriptorSetObj descriptorSet(m_device);
19467 descriptorSet.AppendDummy();
19468 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19469
19470 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19471
19472 m_errorMonitor->VerifyNotFound();
19473}
19474
19475TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19476 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19477 "attributes. This is interesting because they consume multiple "
19478 "locations.");
19479 m_errorMonitor->ExpectSuccess();
19480
19481 ASSERT_NO_FATAL_FAILURE(InitState());
19482 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19483
19484 if (!m_device->phy().features().shaderFloat64) {
19485 printf("Device does not support 64bit vertex attributes; skipped.\n");
19486 return;
19487 }
19488
19489 VkVertexInputBindingDescription input_bindings[1];
19490 memset(input_bindings, 0, sizeof(input_bindings));
19491
19492 VkVertexInputAttributeDescription input_attribs[4];
19493 memset(input_attribs, 0, sizeof(input_attribs));
19494 input_attribs[0].location = 0;
19495 input_attribs[0].offset = 0;
19496 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19497 input_attribs[1].location = 2;
19498 input_attribs[1].offset = 32;
19499 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19500 input_attribs[2].location = 4;
19501 input_attribs[2].offset = 64;
19502 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19503 input_attribs[3].location = 6;
19504 input_attribs[3].offset = 96;
19505 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19506
19507 char const *vsSource = "#version 450\n"
19508 "\n"
19509 "layout(location=0) in dmat4 x;\n"
19510 "out gl_PerVertex {\n"
19511 " vec4 gl_Position;\n"
19512 "};\n"
19513 "void main(){\n"
19514 " gl_Position = vec4(x[0][0]);\n"
19515 "}\n";
19516 char const *fsSource = "#version 450\n"
19517 "\n"
19518 "layout(location=0) out vec4 color;\n"
19519 "void main(){\n"
19520 " color = vec4(1);\n"
19521 "}\n";
19522
19523 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19524 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19525
19526 VkPipelineObj pipe(m_device);
19527 pipe.AddColorAttachment();
19528 pipe.AddShader(&vs);
19529 pipe.AddShader(&fs);
19530
19531 pipe.AddVertexInputBindings(input_bindings, 1);
19532 pipe.AddVertexInputAttribs(input_attribs, 4);
19533
19534 VkDescriptorSetObj descriptorSet(m_device);
19535 descriptorSet.AppendDummy();
19536 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19537
19538 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19539
19540 m_errorMonitor->VerifyNotFound();
19541}
19542
19543TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19544 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19545 m_errorMonitor->ExpectSuccess();
19546
19547 ASSERT_NO_FATAL_FAILURE(InitState());
19548
19549 char const *vsSource = "#version 450\n"
19550 "\n"
19551 "out gl_PerVertex {\n"
19552 " vec4 gl_Position;\n"
19553 "};\n"
19554 "void main(){\n"
19555 " gl_Position = vec4(1);\n"
19556 "}\n";
19557 char const *fsSource = "#version 450\n"
19558 "\n"
19559 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19560 "layout(location=0) out vec4 color;\n"
19561 "void main() {\n"
19562 " color = subpassLoad(x);\n"
19563 "}\n";
19564
19565 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19566 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19567
19568 VkPipelineObj pipe(m_device);
19569 pipe.AddShader(&vs);
19570 pipe.AddShader(&fs);
19571 pipe.AddColorAttachment();
19572 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19573
19574 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19575 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19576 VkDescriptorSetLayout dsl;
19577 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19578 ASSERT_VK_SUCCESS(err);
19579
19580 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19581 VkPipelineLayout pl;
19582 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19583 ASSERT_VK_SUCCESS(err);
19584
19585 VkAttachmentDescription descs[2] = {
19586 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19587 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19588 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19589 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19590 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19591 };
19592 VkAttachmentReference color = {
19593 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19594 };
19595 VkAttachmentReference input = {
19596 1, VK_IMAGE_LAYOUT_GENERAL,
19597 };
19598
19599 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19600
19601 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19602 VkRenderPass rp;
19603 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19604 ASSERT_VK_SUCCESS(err);
19605
19606 // should be OK. would go wrong here if it's going to...
19607 pipe.CreateVKPipeline(pl, rp);
19608
19609 m_errorMonitor->VerifyNotFound();
19610
19611 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19612 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19613 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19614}
19615
19616TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19617 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19618 "descriptor-backed resource which is not provided, but the shader does not "
19619 "statically use it. This is interesting because it requires compute pipelines "
19620 "to have a proper descriptor use walk, which they didn't for some time.");
19621 m_errorMonitor->ExpectSuccess();
19622
19623 ASSERT_NO_FATAL_FAILURE(InitState());
19624
19625 char const *csSource = "#version 450\n"
19626 "\n"
19627 "layout(local_size_x=1) in;\n"
19628 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19629 "void main(){\n"
19630 " // x is not used.\n"
19631 "}\n";
19632
19633 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19634
19635 VkDescriptorSetObj descriptorSet(m_device);
19636 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19637
19638 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19639 nullptr,
19640 0,
19641 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19642 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19643 descriptorSet.GetPipelineLayout(),
19644 VK_NULL_HANDLE,
19645 -1 };
19646
19647 VkPipeline pipe;
19648 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19649
19650 m_errorMonitor->VerifyNotFound();
19651
19652 if (err == VK_SUCCESS) {
19653 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19654 }
19655}
19656
19657TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19658 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19659 "sampler portion of a combined image + sampler");
19660 m_errorMonitor->ExpectSuccess();
19661
19662 ASSERT_NO_FATAL_FAILURE(InitState());
19663
19664 VkDescriptorSetLayoutBinding bindings[] = {
19665 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19666 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19667 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19668 };
19669 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19670 VkDescriptorSetLayout dsl;
19671 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19672 ASSERT_VK_SUCCESS(err);
19673
19674 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19675 VkPipelineLayout pl;
19676 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19677 ASSERT_VK_SUCCESS(err);
19678
19679 char const *csSource = "#version 450\n"
19680 "\n"
19681 "layout(local_size_x=1) in;\n"
19682 "layout(set=0, binding=0) uniform sampler s;\n"
19683 "layout(set=0, binding=1) uniform texture2D t;\n"
19684 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19685 "void main() {\n"
19686 " x = texture(sampler2D(t, s), vec2(0));\n"
19687 "}\n";
19688 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19689
19690 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19691 nullptr,
19692 0,
19693 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19694 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19695 pl,
19696 VK_NULL_HANDLE,
19697 -1 };
19698
19699 VkPipeline pipe;
19700 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19701
19702 m_errorMonitor->VerifyNotFound();
19703
19704 if (err == VK_SUCCESS) {
19705 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19706 }
19707
19708 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19709 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19710}
19711
19712TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19713 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19714 "image portion of a combined image + sampler");
19715 m_errorMonitor->ExpectSuccess();
19716
19717 ASSERT_NO_FATAL_FAILURE(InitState());
19718
19719 VkDescriptorSetLayoutBinding bindings[] = {
19720 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19721 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19722 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19723 };
19724 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19725 VkDescriptorSetLayout dsl;
19726 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19727 ASSERT_VK_SUCCESS(err);
19728
19729 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19730 VkPipelineLayout pl;
19731 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19732 ASSERT_VK_SUCCESS(err);
19733
19734 char const *csSource = "#version 450\n"
19735 "\n"
19736 "layout(local_size_x=1) in;\n"
19737 "layout(set=0, binding=0) uniform texture2D t;\n"
19738 "layout(set=0, binding=1) uniform sampler s;\n"
19739 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19740 "void main() {\n"
19741 " x = texture(sampler2D(t, s), vec2(0));\n"
19742 "}\n";
19743 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19744
19745 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19746 nullptr,
19747 0,
19748 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19749 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19750 pl,
19751 VK_NULL_HANDLE,
19752 -1 };
19753
19754 VkPipeline pipe;
19755 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19756
19757 m_errorMonitor->VerifyNotFound();
19758
19759 if (err == VK_SUCCESS) {
19760 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19761 }
19762
19763 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19764 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19765}
19766
19767TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19768 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19769 "both the sampler and the image of a combined image+sampler "
19770 "but via separate variables");
19771 m_errorMonitor->ExpectSuccess();
19772
19773 ASSERT_NO_FATAL_FAILURE(InitState());
19774
19775 VkDescriptorSetLayoutBinding bindings[] = {
19776 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19777 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19778 };
19779 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19780 VkDescriptorSetLayout dsl;
19781 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19782 ASSERT_VK_SUCCESS(err);
19783
19784 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19785 VkPipelineLayout pl;
19786 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19787 ASSERT_VK_SUCCESS(err);
19788
19789 char const *csSource = "#version 450\n"
19790 "\n"
19791 "layout(local_size_x=1) in;\n"
19792 "layout(set=0, binding=0) uniform texture2D t;\n"
19793 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19794 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19795 "void main() {\n"
19796 " x = texture(sampler2D(t, s), vec2(0));\n"
19797 "}\n";
19798 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19799
19800 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19801 nullptr,
19802 0,
19803 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19804 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19805 pl,
19806 VK_NULL_HANDLE,
19807 -1 };
19808
19809 VkPipeline pipe;
19810 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19811
19812 m_errorMonitor->VerifyNotFound();
19813
19814 if (err == VK_SUCCESS) {
19815 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19816 }
19817
19818 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19819 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19820}
19821
19822TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19823 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19824
19825 ASSERT_NO_FATAL_FAILURE(InitState());
19826
19827 // Positive test to check parameter_validation and unique_objects support
19828 // for NV_dedicated_allocation
19829 uint32_t extension_count = 0;
19830 bool supports_nv_dedicated_allocation = false;
19831 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19832 ASSERT_VK_SUCCESS(err);
19833
19834 if (extension_count > 0) {
19835 std::vector<VkExtensionProperties> available_extensions(extension_count);
19836
19837 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19838 ASSERT_VK_SUCCESS(err);
19839
19840 for (const auto &extension_props : available_extensions) {
19841 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19842 supports_nv_dedicated_allocation = true;
19843 }
19844 }
19845 }
19846
19847 if (supports_nv_dedicated_allocation) {
19848 m_errorMonitor->ExpectSuccess();
19849
19850 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19851 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19852 dedicated_buffer_create_info.pNext = nullptr;
19853 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19854
19855 uint32_t queue_family_index = 0;
19856 VkBufferCreateInfo buffer_create_info = {};
19857 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19858 buffer_create_info.pNext = &dedicated_buffer_create_info;
19859 buffer_create_info.size = 1024;
19860 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19861 buffer_create_info.queueFamilyIndexCount = 1;
19862 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19863
19864 VkBuffer buffer;
19865 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19866 ASSERT_VK_SUCCESS(err);
19867
19868 VkMemoryRequirements memory_reqs;
19869 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19870
19871 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19872 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19873 dedicated_memory_info.pNext = nullptr;
19874 dedicated_memory_info.buffer = buffer;
19875 dedicated_memory_info.image = VK_NULL_HANDLE;
19876
19877 VkMemoryAllocateInfo memory_info = {};
19878 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19879 memory_info.pNext = &dedicated_memory_info;
19880 memory_info.allocationSize = memory_reqs.size;
19881
19882 bool pass;
19883 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19884 ASSERT_TRUE(pass);
19885
19886 VkDeviceMemory buffer_memory;
19887 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19888 ASSERT_VK_SUCCESS(err);
19889
19890 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19891 ASSERT_VK_SUCCESS(err);
19892
19893 vkDestroyBuffer(m_device->device(), buffer, NULL);
19894 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19895
19896 m_errorMonitor->VerifyNotFound();
19897 }
19898}
19899
19900TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19901 VkResult err;
19902
19903 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19904
19905 ASSERT_NO_FATAL_FAILURE(InitState());
19906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19907
19908 std::vector<const char *> device_extension_names;
19909 auto features = m_device->phy().features();
19910 // Artificially disable support for non-solid fill modes
19911 features.fillModeNonSolid = false;
19912 // The sacrificial device object
19913 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19914
19915 VkRenderpassObj render_pass(&test_device);
19916
19917 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19918 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19919 pipeline_layout_ci.setLayoutCount = 0;
19920 pipeline_layout_ci.pSetLayouts = NULL;
19921
19922 VkPipelineLayout pipeline_layout;
19923 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19924 ASSERT_VK_SUCCESS(err);
19925
19926 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19927 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19928 rs_ci.pNext = nullptr;
19929 rs_ci.lineWidth = 1.0f;
19930 rs_ci.rasterizerDiscardEnable = true;
19931
19932 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19933 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19934
19935 // Set polygonMode=FILL. No error is expected
19936 m_errorMonitor->ExpectSuccess();
19937 {
19938 VkPipelineObj pipe(&test_device);
19939 pipe.AddShader(&vs);
19940 pipe.AddShader(&fs);
19941 pipe.AddColorAttachment();
19942 // Set polygonMode to a good value
19943 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19944 pipe.SetRasterization(&rs_ci);
19945 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19946 }
19947 m_errorMonitor->VerifyNotFound();
19948
19949 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19950}
19951
19952TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19953 VkResult err;
19954 ASSERT_NO_FATAL_FAILURE(InitState());
19955 ASSERT_NO_FATAL_FAILURE(InitViewport());
19956 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19957
19958 VkPipelineLayout pipeline_layout;
19959 VkPushConstantRange pc_range = {};
19960 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19961 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19962 pipeline_layout_ci.pushConstantRangeCount = 1;
19963 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19964
19965 //
19966 // Check for invalid push constant ranges in pipeline layouts.
19967 //
19968 struct PipelineLayoutTestCase {
19969 VkPushConstantRange const range;
19970 char const *msg;
19971 };
19972
19973 // Check for overlapping ranges
19974 const uint32_t ranges_per_test = 5;
19975 struct OverlappingRangeTestCase {
19976 VkPushConstantRange const ranges[ranges_per_test];
19977 char const *msg;
19978 };
19979
19980 // Run some positive tests to make sure overlap checking in the layer is OK
19981 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19982 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19983 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19984 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19985 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19986 "" },
19987 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19988 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19989 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19990 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19991 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19992 "" } } };
19993 for (const auto &iter : overlapping_range_tests_pos) {
19994 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19995 m_errorMonitor->ExpectSuccess();
19996 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19997 m_errorMonitor->VerifyNotFound();
19998 if (VK_SUCCESS == err) {
19999 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20000 }
20001 }
20002
20003 //
20004 // CmdPushConstants tests
20005 //
20006 const uint8_t dummy_values[100] = {};
20007
20008 BeginCommandBuffer();
20009
20010 // positive overlapping range tests with cmd
20011 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
20012 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
20013 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
20014 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
20015 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
20016 } };
20017
20018 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20019 const VkPushConstantRange pc_range4[] = {
20020 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
20021 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
20022 };
20023
20024 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20025 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20026 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20027 ASSERT_VK_SUCCESS(err);
20028 for (const auto &iter : cmd_overlap_tests_pos) {
20029 m_errorMonitor->ExpectSuccess();
20030 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
20031 iter.range.size, dummy_values);
20032 m_errorMonitor->VerifyNotFound();
20033 }
20034 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20035
20036 EndCommandBuffer();
20037}
20038
20039
20040
20041
20042
20043
20044
20045#if 0 // A few devices have issues with this test so disabling for now
20046TEST_F(VkPositiveLayerTest, LongFenceChain)
20047{
20048 m_errorMonitor->ExpectSuccess();
20049
20050 ASSERT_NO_FATAL_FAILURE(InitState());
20051 VkResult err;
20052
20053 std::vector<VkFence> fences;
20054
20055 const int chainLength = 32768;
20056
20057 for (int i = 0; i < chainLength; i++) {
20058 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20059 VkFence fence;
20060 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20061 ASSERT_VK_SUCCESS(err);
20062
20063 fences.push_back(fence);
20064
20065 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20066 0, nullptr, 0, nullptr };
20067 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20068 ASSERT_VK_SUCCESS(err);
20069
20070 }
20071
20072 // BOOM, stack overflow.
20073 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20074
20075 for (auto fence : fences)
20076 vkDestroyFence(m_device->device(), fence, nullptr);
20077
20078 m_errorMonitor->VerifyNotFound();
20079}
20080#endif
20081
20082
Cody Northrop1242dfd2016-07-13 17:24:59 -060020083#if defined(ANDROID) && defined(VALIDATION_APK)
20084static bool initialized = false;
20085static bool active = false;
20086
20087// Convert Intents to argv
20088// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020089std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020090 std::vector<std::string> args;
20091 JavaVM &vm = *app.activity->vm;
20092 JNIEnv *p_env;
20093 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
20094 return args;
20095
20096 JNIEnv &env = *p_env;
20097 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020098 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020099 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020100 jmethodID get_string_extra_method =
20101 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020102 jvalue get_string_extra_args;
20103 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020104 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020105
20106 std::string args_str;
20107 if (extra_str) {
20108 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20109 args_str = extra_utf;
20110 env.ReleaseStringUTFChars(extra_str, extra_utf);
20111 env.DeleteLocalRef(extra_str);
20112 }
20113
20114 env.DeleteLocalRef(get_string_extra_args.l);
20115 env.DeleteLocalRef(intent);
20116 vm.DetachCurrentThread();
20117
20118 // split args_str
20119 std::stringstream ss(args_str);
20120 std::string arg;
20121 while (std::getline(ss, arg, ' ')) {
20122 if (!arg.empty())
20123 args.push_back(arg);
20124 }
20125
20126 return args;
20127}
20128
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020129static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020130
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020131static void processCommand(struct android_app *app, int32_t cmd) {
20132 switch (cmd) {
20133 case APP_CMD_INIT_WINDOW: {
20134 if (app->window) {
20135 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020136 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020137 break;
20138 }
20139 case APP_CMD_GAINED_FOCUS: {
20140 active = true;
20141 break;
20142 }
20143 case APP_CMD_LOST_FOCUS: {
20144 active = false;
20145 break;
20146 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020147 }
20148}
20149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020150void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020151 app_dummy();
20152
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020153 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020154
20155 int vulkanSupport = InitVulkan();
20156 if (vulkanSupport == 0) {
20157 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20158 return;
20159 }
20160
20161 app->onAppCmd = processCommand;
20162 app->onInputEvent = processInput;
20163
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020164 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020165 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020166 struct android_poll_source *source;
20167 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020168 if (source) {
20169 source->process(app, source);
20170 }
20171
20172 if (app->destroyRequested != 0) {
20173 VkTestFramework::Finish();
20174 return;
20175 }
20176 }
20177
20178 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020179 // Use the following key to send arguments to gtest, i.e.
20180 // --es args "--gtest_filter=-VkLayerTest.foo"
20181 const char key[] = "args";
20182 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020183
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020184 std::string filter = "";
20185 if (args.size() > 0) {
20186 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20187 filter += args[0];
20188 } else {
20189 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20190 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020191
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020192 int argc = 2;
20193 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20194 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020195
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020196 // Route output to files until we can override the gtest output
20197 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20198 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020199
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020200 ::testing::InitGoogleTest(&argc, argv);
20201 VkTestFramework::InitArgs(&argc, argv);
20202 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020203
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020204 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020205
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020206 if (result != 0) {
20207 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20208 } else {
20209 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20210 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020211
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020212 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020214 fclose(stdout);
20215 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020216
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020217 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020219 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020220 }
20221 }
20222}
20223#endif
20224
Tony Barbour300a6082015-04-07 13:44:53 -060020225int main(int argc, char **argv) {
20226 int result;
20227
Cody Northrop8e54a402016-03-08 22:25:52 -070020228#ifdef ANDROID
20229 int vulkanSupport = InitVulkan();
20230 if (vulkanSupport == 0)
20231 return 1;
20232#endif
20233
Tony Barbour300a6082015-04-07 13:44:53 -060020234 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020235 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020236
20237 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20238
20239 result = RUN_ALL_TESTS();
20240
Tony Barbour6918cd52015-04-09 12:58:51 -060020241 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020242 return result;
20243}