blob: a440bc098aaa510271e105407820f70c30dfc2ac [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
2075 VkCommandBuffer command_buffer[9];
2076 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;
2079 command_buffer_allocate_info.commandBufferCount = 9;
2080 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002081 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002082
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002083 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
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) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
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
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
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
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
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
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
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
3079TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3080 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3081 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003082 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003083
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3085 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003086
3087 // Create a renderPass with a single color attachment
3088 VkAttachmentReference attach = {};
3089 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3090 VkSubpassDescription subpass = {};
3091 VkRenderPassCreateInfo rpci = {};
3092 rpci.subpassCount = 1;
3093 rpci.pSubpasses = &subpass;
3094 rpci.attachmentCount = 1;
3095 VkAttachmentDescription attach_desc = {};
3096 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3097 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3098 rpci.pAttachments = &attach_desc;
3099 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3100 VkRenderPass rp;
3101 subpass.pDepthStencilAttachment = &attach;
3102 subpass.pColorAttachments = NULL;
3103 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3104 m_errorMonitor->VerifyFound();
3105}
3106
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003107TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3108 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3109 "attachment reference of VK_ATTACHMENT_UNUSED");
3110
3111 ASSERT_NO_FATAL_FAILURE(InitState());
3112 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3113
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003115
3116 VkAttachmentReference color_attach = {};
3117 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3118 color_attach.attachment = 0;
3119 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3120 VkSubpassDescription subpass = {};
3121 subpass.colorAttachmentCount = 1;
3122 subpass.pColorAttachments = &color_attach;
3123 subpass.preserveAttachmentCount = 1;
3124 subpass.pPreserveAttachments = &preserve_attachment;
3125
3126 VkRenderPassCreateInfo rpci = {};
3127 rpci.subpassCount = 1;
3128 rpci.pSubpasses = &subpass;
3129 rpci.attachmentCount = 1;
3130 VkAttachmentDescription attach_desc = {};
3131 attach_desc.format = VK_FORMAT_UNDEFINED;
3132 rpci.pAttachments = &attach_desc;
3133 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3134 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003135 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003136
3137 m_errorMonitor->VerifyFound();
3138
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003139 if (result == VK_SUCCESS) {
3140 vkDestroyRenderPass(m_device->device(), rp, NULL);
3141 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003142}
3143
Chris Forbesc5389742016-06-29 11:49:23 +12003144TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003145 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3146 "when the source of a subpass multisample resolve "
3147 "does not have multiple samples.");
3148
Chris Forbesc5389742016-06-29 11:49:23 +12003149 ASSERT_NO_FATAL_FAILURE(InitState());
3150
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3152 "Subpass 0 requests multisample resolve from attachment 0 which has "
3153 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003154
3155 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003156 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3157 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3158 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3159 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3160 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3161 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003162 };
3163
3164 VkAttachmentReference color = {
3165 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3166 };
3167
3168 VkAttachmentReference resolve = {
3169 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3170 };
3171
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003172 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003173
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003174 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003175
3176 VkRenderPass rp;
3177 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3178
3179 m_errorMonitor->VerifyFound();
3180
3181 if (err == VK_SUCCESS)
3182 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3183}
3184
3185TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003186 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3187 "when a subpass multisample resolve operation is "
3188 "requested, and the destination of that resolve has "
3189 "multiple samples.");
3190
Chris Forbesc5389742016-06-29 11:49:23 +12003191 ASSERT_NO_FATAL_FAILURE(InitState());
3192
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3194 "Subpass 0 requests multisample resolve into attachment 1, which "
3195 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003196
3197 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003198 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3199 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3200 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3201 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3202 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3203 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003204 };
3205
3206 VkAttachmentReference color = {
3207 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3208 };
3209
3210 VkAttachmentReference resolve = {
3211 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3212 };
3213
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003214 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003215
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003216 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003217
3218 VkRenderPass rp;
3219 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3220
3221 m_errorMonitor->VerifyFound();
3222
3223 if (err == VK_SUCCESS)
3224 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3225}
3226
Chris Forbes3f128ef2016-06-29 14:58:53 +12003227TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003228 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3229 "when the color and depth attachments used by a subpass "
3230 "have inconsistent sample counts");
3231
Chris Forbes3f128ef2016-06-29 14:58:53 +12003232 ASSERT_NO_FATAL_FAILURE(InitState());
3233
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3235 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003236
3237 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003238 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3239 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3240 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3241 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3242 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3243 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003244 };
3245
3246 VkAttachmentReference color[] = {
3247 {
3248 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3249 },
3250 {
3251 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3252 },
3253 };
3254
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003255 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003257 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003258
3259 VkRenderPass rp;
3260 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3261
3262 m_errorMonitor->VerifyFound();
3263
3264 if (err == VK_SUCCESS)
3265 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3266}
3267
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003268TEST_F(VkLayerTest, FramebufferCreateErrors) {
3269 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003270 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003271 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003272 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3273 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3274 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3275 " 6. Framebuffer attachment where dimensions don't match\n"
3276 " 7. Framebuffer attachment w/o identity swizzle\n"
3277 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003278
3279 ASSERT_NO_FATAL_FAILURE(InitState());
3280 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3281
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3283 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3284 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003285
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003286 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003287 VkAttachmentReference attach = {};
3288 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3289 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003290 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003291 VkRenderPassCreateInfo rpci = {};
3292 rpci.subpassCount = 1;
3293 rpci.pSubpasses = &subpass;
3294 rpci.attachmentCount = 1;
3295 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003296 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003297 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003298 rpci.pAttachments = &attach_desc;
3299 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3300 VkRenderPass rp;
3301 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3302 ASSERT_VK_SUCCESS(err);
3303
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003304 VkImageView ivs[2];
3305 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3306 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003307 VkFramebufferCreateInfo fb_info = {};
3308 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3309 fb_info.pNext = NULL;
3310 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003311 // Set mis-matching attachmentCount
3312 fb_info.attachmentCount = 2;
3313 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003314 fb_info.width = 100;
3315 fb_info.height = 100;
3316 fb_info.layers = 1;
3317
3318 VkFramebuffer fb;
3319 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3320
3321 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003322 if (err == VK_SUCCESS) {
3323 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3324 }
3325 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003326
3327 // Create a renderPass with a depth-stencil attachment created with
3328 // IMAGE_USAGE_COLOR_ATTACHMENT
3329 // Add our color attachment to pDepthStencilAttachment
3330 subpass.pDepthStencilAttachment = &attach;
3331 subpass.pColorAttachments = NULL;
3332 VkRenderPass rp_ds;
3333 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3334 ASSERT_VK_SUCCESS(err);
3335 // Set correct attachment count, but attachment has COLOR usage bit set
3336 fb_info.attachmentCount = 1;
3337 fb_info.renderPass = rp_ds;
3338
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003340 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3341
3342 m_errorMonitor->VerifyFound();
3343 if (err == VK_SUCCESS) {
3344 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3345 }
3346 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003347
3348 // Create new renderpass with alternate attachment format from fb
3349 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3350 subpass.pDepthStencilAttachment = NULL;
3351 subpass.pColorAttachments = &attach;
3352 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3353 ASSERT_VK_SUCCESS(err);
3354
3355 // Cause error due to mis-matched formats between rp & fb
3356 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3357 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3359 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003360 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3361
3362 m_errorMonitor->VerifyFound();
3363 if (err == VK_SUCCESS) {
3364 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3365 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003366 vkDestroyRenderPass(m_device->device(), rp, NULL);
3367
3368 // Create new renderpass with alternate sample count from fb
3369 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3370 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3371 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3372 ASSERT_VK_SUCCESS(err);
3373
3374 // Cause error due to mis-matched sample count between rp & fb
3375 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3377 "that do not match the "
3378 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003379 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3380
3381 m_errorMonitor->VerifyFound();
3382 if (err == VK_SUCCESS) {
3383 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3384 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003385
3386 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003387
3388 // Create a custom imageView with non-1 mip levels
3389 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003390 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 -06003391 ASSERT_TRUE(image.initialized());
3392
3393 VkImageView view;
3394 VkImageViewCreateInfo ivci = {};
3395 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3396 ivci.image = image.handle();
3397 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3398 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3399 ivci.subresourceRange.layerCount = 1;
3400 ivci.subresourceRange.baseMipLevel = 0;
3401 // Set level count 2 (only 1 is allowed for FB attachment)
3402 ivci.subresourceRange.levelCount = 2;
3403 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3404 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3405 ASSERT_VK_SUCCESS(err);
3406 // Re-create renderpass to have matching sample count
3407 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3408 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3409 ASSERT_VK_SUCCESS(err);
3410
3411 fb_info.renderPass = rp;
3412 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003414 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3415
3416 m_errorMonitor->VerifyFound();
3417 if (err == VK_SUCCESS) {
3418 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3419 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003420 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003421 // Update view to original color buffer and grow FB dimensions too big
3422 fb_info.pAttachments = ivs;
3423 fb_info.height = 1024;
3424 fb_info.width = 1024;
3425 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3427 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003428 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3429
3430 m_errorMonitor->VerifyFound();
3431 if (err == VK_SUCCESS) {
3432 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3433 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003434 // Create view attachment with non-identity swizzle
3435 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3436 ivci.image = image.handle();
3437 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3438 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3439 ivci.subresourceRange.layerCount = 1;
3440 ivci.subresourceRange.baseMipLevel = 0;
3441 ivci.subresourceRange.levelCount = 1;
3442 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3443 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3444 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3445 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3446 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3447 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3448 ASSERT_VK_SUCCESS(err);
3449
3450 fb_info.pAttachments = &view;
3451 fb_info.height = 100;
3452 fb_info.width = 100;
3453 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3455 "framebuffer attachments must have "
3456 "been created with the identity "
3457 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003458 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3459
3460 m_errorMonitor->VerifyFound();
3461 if (err == VK_SUCCESS) {
3462 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3463 }
3464 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003465 // Request fb that exceeds max dimensions
3466 // reset attachment to color attachment
3467 fb_info.pAttachments = ivs;
3468 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3469 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3470 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3472 "dimensions exceed physical device "
3473 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003474 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3475
3476 m_errorMonitor->VerifyFound();
3477 if (err == VK_SUCCESS) {
3478 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3479 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003480
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003481 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003482}
3483
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003484TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003485 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3486 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003487
Cody Northropc31a84f2016-08-22 10:41:47 -06003488 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003489 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3491 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003492 m_errorMonitor->VerifyFound();
3493}
3494
3495TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003496 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3497 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003498
Cody Northropc31a84f2016-08-22 10:41:47 -06003499 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003500 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3502 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003503 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003504}
3505
3506TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003507 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3508 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003509
Cody Northropc31a84f2016-08-22 10:41:47 -06003510 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003511 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003512 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 -06003513 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003514 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003515}
3516
3517TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003518 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3519 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003520
Cody Northropc31a84f2016-08-22 10:41:47 -06003521 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003522 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003523 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 -06003524 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003525 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003526}
3527
Cortd713fe82016-07-27 09:51:27 -07003528TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003529 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3530 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003531
3532 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003533 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3535 "Dynamic blend constants state not set for this command buffer");
3536 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003537 m_errorMonitor->VerifyFound();
3538}
3539
3540TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003541 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3542 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003543
3544 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003545 if (!m_device->phy().features().depthBounds) {
3546 printf("Device does not support depthBounds test; skipped.\n");
3547 return;
3548 }
3549 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3551 "Dynamic depth bounds state not set for this command buffer");
3552 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003553 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003554}
3555
3556TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003557 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3558 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003559
3560 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003561 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3563 "Dynamic stencil read mask state not set for this command buffer");
3564 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003565 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003566}
3567
3568TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003569 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3570 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003571
3572 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003573 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3575 "Dynamic stencil write mask state not set for this command buffer");
3576 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003577 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003578}
3579
3580TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003581 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3582 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003583
3584 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003585 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3587 "Dynamic stencil reference state not set for this command buffer");
3588 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003589 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003590}
3591
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003592TEST_F(VkLayerTest, IndexBufferNotBound) {
3593 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003594
3595 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3597 "Index buffer object not bound to this command buffer when Indexed ");
3598 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003599 m_errorMonitor->VerifyFound();
3600}
3601
Karl Schultz6addd812016-02-02 17:17:23 -07003602TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3604 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3605 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003606
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003607 ASSERT_NO_FATAL_FAILURE(InitState());
3608 ASSERT_NO_FATAL_FAILURE(InitViewport());
3609 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3610
Karl Schultz6addd812016-02-02 17:17:23 -07003611 // We luck out b/c by default the framework creates CB w/ the
3612 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003613 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003614 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003615 EndCommandBuffer();
3616
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003617 // Bypass framework since it does the waits automatically
3618 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003619 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003620 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3621 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003622 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003623 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003624 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003625 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003626 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003627 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003628 submit_info.pSignalSemaphores = NULL;
3629
Chris Forbes40028e22016-06-13 09:59:34 +12003630 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003631 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003632 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003633
Karl Schultz6addd812016-02-02 17:17:23 -07003634 // Cause validation error by re-submitting cmd buffer that should only be
3635 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003636 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003637 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003638
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003639 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003640}
3641
Karl Schultz6addd812016-02-02 17:17:23 -07003642TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003643 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003644 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003645
3646 ASSERT_NO_FATAL_FAILURE(InitState());
3647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003648
Karl Schultz6addd812016-02-02 17:17:23 -07003649 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3650 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003651 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003652 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003653 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003654
3655 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003656 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3657 ds_pool_ci.pNext = NULL;
3658 ds_pool_ci.flags = 0;
3659 ds_pool_ci.maxSets = 1;
3660 ds_pool_ci.poolSizeCount = 1;
3661 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003662
3663 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003664 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003665 ASSERT_VK_SUCCESS(err);
3666
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003667 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3668 dsl_binding_samp.binding = 0;
3669 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3670 dsl_binding_samp.descriptorCount = 1;
3671 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3672 dsl_binding_samp.pImmutableSamplers = NULL;
3673
3674 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3675 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3676 ds_layout_ci.pNext = NULL;
3677 ds_layout_ci.bindingCount = 1;
3678 ds_layout_ci.pBindings = &dsl_binding_samp;
3679
3680 VkDescriptorSetLayout ds_layout_samp;
3681 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3682 ASSERT_VK_SUCCESS(err);
3683
3684 // Try to allocate 2 sets when pool only has 1 set
3685 VkDescriptorSet descriptor_sets[2];
3686 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3687 VkDescriptorSetAllocateInfo alloc_info = {};
3688 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3689 alloc_info.descriptorSetCount = 2;
3690 alloc_info.descriptorPool = ds_pool;
3691 alloc_info.pSetLayouts = set_layouts;
3692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3693 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3694 m_errorMonitor->VerifyFound();
3695
3696 alloc_info.descriptorSetCount = 1;
3697 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003698 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003699 dsl_binding.binding = 0;
3700 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3701 dsl_binding.descriptorCount = 1;
3702 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3703 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003704
Karl Schultz6addd812016-02-02 17:17:23 -07003705 ds_layout_ci.bindingCount = 1;
3706 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003707
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003708 VkDescriptorSetLayout ds_layout_ub;
3709 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003710 ASSERT_VK_SUCCESS(err);
3711
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003712 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003713 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003714 alloc_info.pSetLayouts = &ds_layout_ub;
3715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3716 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003717
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003718 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003719
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003720 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003721 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003722}
3723
Karl Schultz6addd812016-02-02 17:17:23 -07003724TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3725 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003726
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3728 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3729 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003730
Tobin Ehlise735c692015-10-08 13:13:50 -06003731 ASSERT_NO_FATAL_FAILURE(InitState());
3732 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003733
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003734 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003735 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3736 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003737
3738 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003739 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3740 ds_pool_ci.pNext = NULL;
3741 ds_pool_ci.maxSets = 1;
3742 ds_pool_ci.poolSizeCount = 1;
3743 ds_pool_ci.flags = 0;
3744 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3745 // app can only call vkResetDescriptorPool on this pool.;
3746 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003747
3748 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003749 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003750 ASSERT_VK_SUCCESS(err);
3751
3752 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003753 dsl_binding.binding = 0;
3754 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3755 dsl_binding.descriptorCount = 1;
3756 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3757 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003758
3759 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003760 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3761 ds_layout_ci.pNext = NULL;
3762 ds_layout_ci.bindingCount = 1;
3763 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003764
3765 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003766 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003767 ASSERT_VK_SUCCESS(err);
3768
3769 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003770 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003771 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003772 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003773 alloc_info.descriptorPool = ds_pool;
3774 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003775 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003776 ASSERT_VK_SUCCESS(err);
3777
3778 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003779 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003780
Chia-I Wuf7458c52015-10-26 21:10:41 +08003781 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3782 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003783}
3784
Karl Schultz6addd812016-02-02 17:17:23 -07003785TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003786 // Attempt to clear Descriptor Pool with bad object.
3787 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003788
3789 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003791 uint64_t fake_pool_handle = 0xbaad6001;
3792 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3793 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003794 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003795}
3796
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003797TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003798 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3799 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003800 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003801 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003802
3803 uint64_t fake_set_handle = 0xbaad6001;
3804 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003805 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003807
3808 ASSERT_NO_FATAL_FAILURE(InitState());
3809
3810 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3811 layout_bindings[0].binding = 0;
3812 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3813 layout_bindings[0].descriptorCount = 1;
3814 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3815 layout_bindings[0].pImmutableSamplers = NULL;
3816
3817 VkDescriptorSetLayout descriptor_set_layout;
3818 VkDescriptorSetLayoutCreateInfo dslci = {};
3819 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3820 dslci.pNext = NULL;
3821 dslci.bindingCount = 1;
3822 dslci.pBindings = layout_bindings;
3823 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003824 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003825
3826 VkPipelineLayout pipeline_layout;
3827 VkPipelineLayoutCreateInfo plci = {};
3828 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3829 plci.pNext = NULL;
3830 plci.setLayoutCount = 1;
3831 plci.pSetLayouts = &descriptor_set_layout;
3832 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003833 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003834
3835 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003836 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3837 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003838 m_errorMonitor->VerifyFound();
3839 EndCommandBuffer();
3840 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3841 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003842}
3843
Karl Schultz6addd812016-02-02 17:17:23 -07003844TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003845 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3846 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003847 uint64_t fake_layout_handle = 0xbaad6001;
3848 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003850 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003851 VkPipelineLayout pipeline_layout;
3852 VkPipelineLayoutCreateInfo plci = {};
3853 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3854 plci.pNext = NULL;
3855 plci.setLayoutCount = 1;
3856 plci.pSetLayouts = &bad_layout;
3857 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3858
3859 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003860}
3861
Mark Muellerd4914412016-06-13 17:52:06 -06003862TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3863 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3864 "1) A uniform buffer update must have a valid buffer index."
3865 "2) When using an array of descriptors in a single WriteDescriptor,"
3866 " the descriptor types and stageflags must all be the same."
3867 "3) Immutable Sampler state must match across descriptors");
3868
3869 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003870 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3871 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3872 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3873 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3874 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003875
Mark Muellerd4914412016-06-13 17:52:06 -06003876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3877
3878 ASSERT_NO_FATAL_FAILURE(InitState());
3879 VkDescriptorPoolSize ds_type_count[4] = {};
3880 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3881 ds_type_count[0].descriptorCount = 1;
3882 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3883 ds_type_count[1].descriptorCount = 1;
3884 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3885 ds_type_count[2].descriptorCount = 1;
3886 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3887 ds_type_count[3].descriptorCount = 1;
3888
3889 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3890 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3891 ds_pool_ci.maxSets = 1;
3892 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3893 ds_pool_ci.pPoolSizes = ds_type_count;
3894
3895 VkDescriptorPool ds_pool;
3896 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3897 ASSERT_VK_SUCCESS(err);
3898
Mark Muellerb9896722016-06-16 09:54:29 -06003899 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003900 layout_binding[0].binding = 0;
3901 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3902 layout_binding[0].descriptorCount = 1;
3903 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3904 layout_binding[0].pImmutableSamplers = NULL;
3905
3906 layout_binding[1].binding = 1;
3907 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3908 layout_binding[1].descriptorCount = 1;
3909 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3910 layout_binding[1].pImmutableSamplers = NULL;
3911
3912 VkSamplerCreateInfo sampler_ci = {};
3913 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3914 sampler_ci.pNext = NULL;
3915 sampler_ci.magFilter = VK_FILTER_NEAREST;
3916 sampler_ci.minFilter = VK_FILTER_NEAREST;
3917 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3918 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3919 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3920 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3921 sampler_ci.mipLodBias = 1.0;
3922 sampler_ci.anisotropyEnable = VK_FALSE;
3923 sampler_ci.maxAnisotropy = 1;
3924 sampler_ci.compareEnable = VK_FALSE;
3925 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3926 sampler_ci.minLod = 1.0;
3927 sampler_ci.maxLod = 1.0;
3928 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3929 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3930 VkSampler sampler;
3931
3932 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3933 ASSERT_VK_SUCCESS(err);
3934
3935 layout_binding[2].binding = 2;
3936 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3937 layout_binding[2].descriptorCount = 1;
3938 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3939 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3940
Mark Muellerd4914412016-06-13 17:52:06 -06003941 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3942 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3943 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3944 ds_layout_ci.pBindings = layout_binding;
3945 VkDescriptorSetLayout ds_layout;
3946 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3947 ASSERT_VK_SUCCESS(err);
3948
3949 VkDescriptorSetAllocateInfo alloc_info = {};
3950 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3951 alloc_info.descriptorSetCount = 1;
3952 alloc_info.descriptorPool = ds_pool;
3953 alloc_info.pSetLayouts = &ds_layout;
3954 VkDescriptorSet descriptorSet;
3955 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3956 ASSERT_VK_SUCCESS(err);
3957
3958 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3959 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3960 pipeline_layout_ci.pNext = NULL;
3961 pipeline_layout_ci.setLayoutCount = 1;
3962 pipeline_layout_ci.pSetLayouts = &ds_layout;
3963
3964 VkPipelineLayout pipeline_layout;
3965 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3966 ASSERT_VK_SUCCESS(err);
3967
Mark Mueller5c838ce2016-06-16 09:54:29 -06003968 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003969 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3970 descriptor_write.dstSet = descriptorSet;
3971 descriptor_write.dstBinding = 0;
3972 descriptor_write.descriptorCount = 1;
3973 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3974
Mark Mueller5c838ce2016-06-16 09:54:29 -06003975 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003976 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3977 m_errorMonitor->VerifyFound();
3978
3979 // Create a buffer to update the descriptor with
3980 uint32_t qfi = 0;
3981 VkBufferCreateInfo buffCI = {};
3982 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3983 buffCI.size = 1024;
3984 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3985 buffCI.queueFamilyIndexCount = 1;
3986 buffCI.pQueueFamilyIndices = &qfi;
3987
3988 VkBuffer dyub;
3989 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3990 ASSERT_VK_SUCCESS(err);
3991 VkDescriptorBufferInfo buffInfo = {};
3992 buffInfo.buffer = dyub;
3993 buffInfo.offset = 0;
3994 buffInfo.range = 1024;
3995
3996 descriptor_write.pBufferInfo = &buffInfo;
3997 descriptor_write.descriptorCount = 2;
3998
Mark Mueller5c838ce2016-06-16 09:54:29 -06003999 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4001 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4002 m_errorMonitor->VerifyFound();
4003
Mark Mueller5c838ce2016-06-16 09:54:29 -06004004 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4005 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004006 descriptor_write.dstBinding = 1;
4007 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004008
Mark Mueller5c838ce2016-06-16 09:54:29 -06004009 // Make pImageInfo index non-null to avoid complaints of it missing
4010 VkDescriptorImageInfo imageInfo = {};
4011 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4012 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4014 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4015 m_errorMonitor->VerifyFound();
4016
Mark Muellerd4914412016-06-13 17:52:06 -06004017 vkDestroyBuffer(m_device->device(), dyub, NULL);
4018 vkDestroySampler(m_device->device(), sampler, NULL);
4019 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4020 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4021 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4022}
4023
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004024TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4025 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4026 "due to a buffer dependency being destroyed.");
4027 ASSERT_NO_FATAL_FAILURE(InitState());
4028
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004029 VkBuffer buffer;
4030 VkDeviceMemory mem;
4031 VkMemoryRequirements mem_reqs;
4032
4033 VkBufferCreateInfo buf_info = {};
4034 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004035 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004036 buf_info.size = 256;
4037 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4038 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4039 ASSERT_VK_SUCCESS(err);
4040
4041 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4042
4043 VkMemoryAllocateInfo alloc_info = {};
4044 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4045 alloc_info.allocationSize = 256;
4046 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004047 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 -06004048 if (!pass) {
4049 vkDestroyBuffer(m_device->device(), buffer, NULL);
4050 return;
4051 }
4052 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4053 ASSERT_VK_SUCCESS(err);
4054
4055 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4056 ASSERT_VK_SUCCESS(err);
4057
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004058 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004059 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004060 m_commandBuffer->EndCommandBuffer();
4061
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004063 // Destroy buffer dependency prior to submit to cause ERROR
4064 vkDestroyBuffer(m_device->device(), buffer, NULL);
4065
4066 VkSubmitInfo submit_info = {};
4067 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4068 submit_info.commandBufferCount = 1;
4069 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4070 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4071
4072 m_errorMonitor->VerifyFound();
4073 vkFreeMemory(m_device->handle(), mem, NULL);
4074}
4075
Tobin Ehlisea413442016-09-28 10:23:59 -06004076TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4077 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4078
4079 ASSERT_NO_FATAL_FAILURE(InitState());
4080 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4081
4082 VkDescriptorPoolSize ds_type_count;
4083 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4084 ds_type_count.descriptorCount = 1;
4085
4086 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4087 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4088 ds_pool_ci.maxSets = 1;
4089 ds_pool_ci.poolSizeCount = 1;
4090 ds_pool_ci.pPoolSizes = &ds_type_count;
4091
4092 VkDescriptorPool ds_pool;
4093 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4094 ASSERT_VK_SUCCESS(err);
4095
4096 VkDescriptorSetLayoutBinding layout_binding;
4097 layout_binding.binding = 0;
4098 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4099 layout_binding.descriptorCount = 1;
4100 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4101 layout_binding.pImmutableSamplers = NULL;
4102
4103 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4104 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4105 ds_layout_ci.bindingCount = 1;
4106 ds_layout_ci.pBindings = &layout_binding;
4107 VkDescriptorSetLayout ds_layout;
4108 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4109 ASSERT_VK_SUCCESS(err);
4110
4111 VkDescriptorSetAllocateInfo alloc_info = {};
4112 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4113 alloc_info.descriptorSetCount = 1;
4114 alloc_info.descriptorPool = ds_pool;
4115 alloc_info.pSetLayouts = &ds_layout;
4116 VkDescriptorSet descriptor_set;
4117 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4118 ASSERT_VK_SUCCESS(err);
4119
4120 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4121 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4122 pipeline_layout_ci.pNext = NULL;
4123 pipeline_layout_ci.setLayoutCount = 1;
4124 pipeline_layout_ci.pSetLayouts = &ds_layout;
4125
4126 VkPipelineLayout pipeline_layout;
4127 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4128 ASSERT_VK_SUCCESS(err);
4129
4130 VkBuffer buffer;
4131 uint32_t queue_family_index = 0;
4132 VkBufferCreateInfo buffer_create_info = {};
4133 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4134 buffer_create_info.size = 1024;
4135 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4136 buffer_create_info.queueFamilyIndexCount = 1;
4137 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4138
4139 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4140 ASSERT_VK_SUCCESS(err);
4141
4142 VkMemoryRequirements memory_reqs;
4143 VkDeviceMemory buffer_memory;
4144
4145 VkMemoryAllocateInfo memory_info = {};
4146 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4147 memory_info.allocationSize = 0;
4148 memory_info.memoryTypeIndex = 0;
4149
4150 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4151 memory_info.allocationSize = memory_reqs.size;
4152 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4153 ASSERT_TRUE(pass);
4154
4155 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4156 ASSERT_VK_SUCCESS(err);
4157 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4158 ASSERT_VK_SUCCESS(err);
4159
4160 VkBufferView view;
4161 VkBufferViewCreateInfo bvci = {};
4162 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4163 bvci.buffer = buffer;
4164 bvci.format = VK_FORMAT_R8_UNORM;
4165 bvci.range = VK_WHOLE_SIZE;
4166
4167 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4168 ASSERT_VK_SUCCESS(err);
4169
4170 VkWriteDescriptorSet descriptor_write = {};
4171 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4172 descriptor_write.dstSet = descriptor_set;
4173 descriptor_write.dstBinding = 0;
4174 descriptor_write.descriptorCount = 1;
4175 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4176 descriptor_write.pTexelBufferView = &view;
4177
4178 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4179
4180 char const *vsSource = "#version 450\n"
4181 "\n"
4182 "out gl_PerVertex { \n"
4183 " vec4 gl_Position;\n"
4184 "};\n"
4185 "void main(){\n"
4186 " gl_Position = vec4(1);\n"
4187 "}\n";
4188 char const *fsSource = "#version 450\n"
4189 "\n"
4190 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4191 "layout(location=0) out vec4 x;\n"
4192 "void main(){\n"
4193 " x = imageLoad(s, 0);\n"
4194 "}\n";
4195 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4196 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4197 VkPipelineObj pipe(m_device);
4198 pipe.AddShader(&vs);
4199 pipe.AddShader(&fs);
4200 pipe.AddColorAttachment();
4201 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4202
4203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4205
4206 BeginCommandBuffer();
4207 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4208 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4209 VkRect2D scissor = {{0, 0}, {16, 16}};
4210 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4211 // Bind pipeline to cmd buffer
4212 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4213 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4214 &descriptor_set, 0, nullptr);
4215 Draw(1, 0, 0, 0);
4216 EndCommandBuffer();
4217
4218 // Delete BufferView in order to invalidate cmd buffer
4219 vkDestroyBufferView(m_device->device(), view, NULL);
4220 // Now attempt submit of cmd buffer
4221 VkSubmitInfo submit_info = {};
4222 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4223 submit_info.commandBufferCount = 1;
4224 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4225 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4226 m_errorMonitor->VerifyFound();
4227
4228 // Clean-up
4229 vkDestroyBuffer(m_device->device(), buffer, NULL);
4230 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4231 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4232 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4233 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4234}
4235
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004236TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4237 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4238 "due to an image dependency being destroyed.");
4239 ASSERT_NO_FATAL_FAILURE(InitState());
4240
4241 VkImage image;
4242 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4243 VkImageCreateInfo image_create_info = {};
4244 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4245 image_create_info.pNext = NULL;
4246 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4247 image_create_info.format = tex_format;
4248 image_create_info.extent.width = 32;
4249 image_create_info.extent.height = 32;
4250 image_create_info.extent.depth = 1;
4251 image_create_info.mipLevels = 1;
4252 image_create_info.arrayLayers = 1;
4253 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4254 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004255 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004256 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004257 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004258 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004259 // Have to bind memory to image before recording cmd in cmd buffer using it
4260 VkMemoryRequirements mem_reqs;
4261 VkDeviceMemory image_mem;
4262 bool pass;
4263 VkMemoryAllocateInfo mem_alloc = {};
4264 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4265 mem_alloc.pNext = NULL;
4266 mem_alloc.memoryTypeIndex = 0;
4267 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4268 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004269 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004270 ASSERT_TRUE(pass);
4271 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4272 ASSERT_VK_SUCCESS(err);
4273 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4274 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004275
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004276 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004277 VkClearColorValue ccv;
4278 ccv.float32[0] = 1.0f;
4279 ccv.float32[1] = 1.0f;
4280 ccv.float32[2] = 1.0f;
4281 ccv.float32[3] = 1.0f;
4282 VkImageSubresourceRange isr = {};
4283 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004284 isr.baseArrayLayer = 0;
4285 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004286 isr.layerCount = 1;
4287 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004288 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004289 m_commandBuffer->EndCommandBuffer();
4290
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004292 // Destroy image dependency prior to submit to cause ERROR
4293 vkDestroyImage(m_device->device(), image, NULL);
4294
4295 VkSubmitInfo submit_info = {};
4296 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4297 submit_info.commandBufferCount = 1;
4298 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4299 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4300
4301 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004302 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004303}
4304
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004305TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4306 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4307 "due to a framebuffer image dependency being destroyed.");
4308 VkFormatProperties format_properties;
4309 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004310 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4311 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004312 return;
4313 }
4314
4315 ASSERT_NO_FATAL_FAILURE(InitState());
4316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4317
4318 VkImageCreateInfo image_ci = {};
4319 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4320 image_ci.pNext = NULL;
4321 image_ci.imageType = VK_IMAGE_TYPE_2D;
4322 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4323 image_ci.extent.width = 32;
4324 image_ci.extent.height = 32;
4325 image_ci.extent.depth = 1;
4326 image_ci.mipLevels = 1;
4327 image_ci.arrayLayers = 1;
4328 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4329 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004330 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004331 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4332 image_ci.flags = 0;
4333 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004334 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004335
4336 VkMemoryRequirements memory_reqs;
4337 VkDeviceMemory image_memory;
4338 bool pass;
4339 VkMemoryAllocateInfo memory_info = {};
4340 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4341 memory_info.pNext = NULL;
4342 memory_info.allocationSize = 0;
4343 memory_info.memoryTypeIndex = 0;
4344 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4345 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004346 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004347 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004348 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004349 ASSERT_VK_SUCCESS(err);
4350 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4351 ASSERT_VK_SUCCESS(err);
4352
4353 VkImageViewCreateInfo ivci = {
4354 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4355 nullptr,
4356 0,
4357 image,
4358 VK_IMAGE_VIEW_TYPE_2D,
4359 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004360 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004361 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4362 };
4363 VkImageView view;
4364 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4365 ASSERT_VK_SUCCESS(err);
4366
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004367 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004368 VkFramebuffer fb;
4369 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4370 ASSERT_VK_SUCCESS(err);
4371
4372 // Just use default renderpass with our framebuffer
4373 m_renderPassBeginInfo.framebuffer = fb;
4374 // Create Null cmd buffer for submit
4375 BeginCommandBuffer();
4376 EndCommandBuffer();
4377 // Destroy image attached to framebuffer to invalidate cmd buffer
4378 vkDestroyImage(m_device->device(), image, NULL);
4379 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004381 QueueCommandBuffer(false);
4382 m_errorMonitor->VerifyFound();
4383
4384 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4385 vkDestroyImageView(m_device->device(), view, nullptr);
4386 vkFreeMemory(m_device->device(), image_memory, nullptr);
4387}
4388
Tobin Ehlisb329f992016-10-12 13:20:29 -06004389TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4390 TEST_DESCRIPTION("Delete in-use framebuffer.");
4391 VkFormatProperties format_properties;
4392 VkResult err = VK_SUCCESS;
4393 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4394
4395 ASSERT_NO_FATAL_FAILURE(InitState());
4396 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4397
4398 VkImageObj image(m_device);
4399 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4400 ASSERT_TRUE(image.initialized());
4401 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4402
4403 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4404 VkFramebuffer fb;
4405 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4406 ASSERT_VK_SUCCESS(err);
4407
4408 // Just use default renderpass with our framebuffer
4409 m_renderPassBeginInfo.framebuffer = fb;
4410 // Create Null cmd buffer for submit
4411 BeginCommandBuffer();
4412 EndCommandBuffer();
4413 // Submit cmd buffer to put it in-flight
4414 VkSubmitInfo submit_info = {};
4415 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4416 submit_info.commandBufferCount = 1;
4417 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4418 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4419 // Destroy framebuffer while in-flight
4420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4421 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4422 m_errorMonitor->VerifyFound();
4423 // Wait for queue to complete so we can safely destroy everything
4424 vkQueueWaitIdle(m_device->m_queue);
4425 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4426}
4427
Tobin Ehlis88becd72016-09-21 14:33:41 -06004428TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4429 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4430 VkFormatProperties format_properties;
4431 VkResult err = VK_SUCCESS;
4432 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004433
4434 ASSERT_NO_FATAL_FAILURE(InitState());
4435 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4436
4437 VkImageCreateInfo image_ci = {};
4438 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4439 image_ci.pNext = NULL;
4440 image_ci.imageType = VK_IMAGE_TYPE_2D;
4441 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4442 image_ci.extent.width = 256;
4443 image_ci.extent.height = 256;
4444 image_ci.extent.depth = 1;
4445 image_ci.mipLevels = 1;
4446 image_ci.arrayLayers = 1;
4447 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4448 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004449 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004450 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4451 image_ci.flags = 0;
4452 VkImage image;
4453 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4454
4455 VkMemoryRequirements memory_reqs;
4456 VkDeviceMemory image_memory;
4457 bool pass;
4458 VkMemoryAllocateInfo memory_info = {};
4459 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4460 memory_info.pNext = NULL;
4461 memory_info.allocationSize = 0;
4462 memory_info.memoryTypeIndex = 0;
4463 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4464 memory_info.allocationSize = memory_reqs.size;
4465 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4466 ASSERT_TRUE(pass);
4467 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4468 ASSERT_VK_SUCCESS(err);
4469 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4470 ASSERT_VK_SUCCESS(err);
4471
4472 VkImageViewCreateInfo ivci = {
4473 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4474 nullptr,
4475 0,
4476 image,
4477 VK_IMAGE_VIEW_TYPE_2D,
4478 VK_FORMAT_B8G8R8A8_UNORM,
4479 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4480 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4481 };
4482 VkImageView view;
4483 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4484 ASSERT_VK_SUCCESS(err);
4485
4486 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4487 VkFramebuffer fb;
4488 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4489 ASSERT_VK_SUCCESS(err);
4490
4491 // Just use default renderpass with our framebuffer
4492 m_renderPassBeginInfo.framebuffer = fb;
4493 // Create Null cmd buffer for submit
4494 BeginCommandBuffer();
4495 EndCommandBuffer();
4496 // Submit cmd buffer to put it (and attached imageView) in-flight
4497 VkSubmitInfo submit_info = {};
4498 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4499 submit_info.commandBufferCount = 1;
4500 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4501 // Submit cmd buffer to put framebuffer and children in-flight
4502 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4503 // Destroy image attached to framebuffer while in-flight
4504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4505 vkDestroyImage(m_device->device(), image, NULL);
4506 m_errorMonitor->VerifyFound();
4507 // Wait for queue to complete so we can safely destroy image and other objects
4508 vkQueueWaitIdle(m_device->m_queue);
4509 vkDestroyImage(m_device->device(), image, NULL);
4510 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4511 vkDestroyImageView(m_device->device(), view, nullptr);
4512 vkFreeMemory(m_device->device(), image_memory, nullptr);
4513}
4514
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004515TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4516 TEST_DESCRIPTION("Delete in-use renderPass.");
4517
4518 ASSERT_NO_FATAL_FAILURE(InitState());
4519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4520
4521 // Create simple renderpass
4522 VkAttachmentReference attach = {};
4523 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4524 VkSubpassDescription subpass = {};
4525 subpass.pColorAttachments = &attach;
4526 VkRenderPassCreateInfo rpci = {};
4527 rpci.subpassCount = 1;
4528 rpci.pSubpasses = &subpass;
4529 rpci.attachmentCount = 1;
4530 VkAttachmentDescription attach_desc = {};
4531 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4532 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4533 rpci.pAttachments = &attach_desc;
4534 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4535 VkRenderPass rp;
4536 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4537 ASSERT_VK_SUCCESS(err);
4538
4539 // Create a pipeline that uses the given renderpass
4540 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4541 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4542
4543 VkPipelineLayout pipeline_layout;
4544 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4545 ASSERT_VK_SUCCESS(err);
4546
4547 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4548 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4549 vp_state_ci.viewportCount = 1;
4550 VkViewport vp = {}; // Just need dummy vp to point to
4551 vp_state_ci.pViewports = &vp;
4552 vp_state_ci.scissorCount = 1;
4553 VkRect2D scissors = {}; // Dummy scissors to point to
4554 vp_state_ci.pScissors = &scissors;
4555
4556 VkPipelineShaderStageCreateInfo shaderStages[2];
4557 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4558
4559 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4560 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4561 // but add it to be able to run on more devices
4562 shaderStages[0] = vs.GetStageCreateInfo();
4563 shaderStages[1] = fs.GetStageCreateInfo();
4564
4565 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4566 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4567
4568 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4569 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4570 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4571
4572 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4573 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4574 rs_ci.rasterizerDiscardEnable = true;
4575 rs_ci.lineWidth = 1.0f;
4576
4577 VkPipelineColorBlendAttachmentState att = {};
4578 att.blendEnable = VK_FALSE;
4579 att.colorWriteMask = 0xf;
4580
4581 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4582 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4583 cb_ci.attachmentCount = 1;
4584 cb_ci.pAttachments = &att;
4585
4586 VkGraphicsPipelineCreateInfo gp_ci = {};
4587 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4588 gp_ci.stageCount = 2;
4589 gp_ci.pStages = shaderStages;
4590 gp_ci.pVertexInputState = &vi_ci;
4591 gp_ci.pInputAssemblyState = &ia_ci;
4592 gp_ci.pViewportState = &vp_state_ci;
4593 gp_ci.pRasterizationState = &rs_ci;
4594 gp_ci.pColorBlendState = &cb_ci;
4595 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4596 gp_ci.layout = pipeline_layout;
4597 gp_ci.renderPass = rp;
4598
4599 VkPipelineCacheCreateInfo pc_ci = {};
4600 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4601
4602 VkPipeline pipeline;
4603 VkPipelineCache pipe_cache;
4604 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4605 ASSERT_VK_SUCCESS(err);
4606
4607 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4608 ASSERT_VK_SUCCESS(err);
4609 // Bind pipeline to cmd buffer, will also bind renderpass
4610 m_commandBuffer->BeginCommandBuffer();
4611 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4612 m_commandBuffer->EndCommandBuffer();
4613
4614 VkSubmitInfo submit_info = {};
4615 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4616 submit_info.commandBufferCount = 1;
4617 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4618 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4619
4620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4621 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4622 m_errorMonitor->VerifyFound();
4623
4624 // Wait for queue to complete so we can safely destroy everything
4625 vkQueueWaitIdle(m_device->m_queue);
4626 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4627 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4628 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4629 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4630}
4631
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004632TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004633 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004634 ASSERT_NO_FATAL_FAILURE(InitState());
4635
4636 VkImage image;
4637 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4638 VkImageCreateInfo image_create_info = {};
4639 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4640 image_create_info.pNext = NULL;
4641 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4642 image_create_info.format = tex_format;
4643 image_create_info.extent.width = 32;
4644 image_create_info.extent.height = 32;
4645 image_create_info.extent.depth = 1;
4646 image_create_info.mipLevels = 1;
4647 image_create_info.arrayLayers = 1;
4648 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4649 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004650 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004651 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004652 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004653 ASSERT_VK_SUCCESS(err);
4654 // Have to bind memory to image before recording cmd in cmd buffer using it
4655 VkMemoryRequirements mem_reqs;
4656 VkDeviceMemory image_mem;
4657 bool pass;
4658 VkMemoryAllocateInfo mem_alloc = {};
4659 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4660 mem_alloc.pNext = NULL;
4661 mem_alloc.memoryTypeIndex = 0;
4662 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4663 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004664 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004665 ASSERT_TRUE(pass);
4666 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4667 ASSERT_VK_SUCCESS(err);
4668
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004669 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004671 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004672
4673 m_commandBuffer->BeginCommandBuffer();
4674 VkClearColorValue ccv;
4675 ccv.float32[0] = 1.0f;
4676 ccv.float32[1] = 1.0f;
4677 ccv.float32[2] = 1.0f;
4678 ccv.float32[3] = 1.0f;
4679 VkImageSubresourceRange isr = {};
4680 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4681 isr.baseArrayLayer = 0;
4682 isr.baseMipLevel = 0;
4683 isr.layerCount = 1;
4684 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004685 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004686 m_commandBuffer->EndCommandBuffer();
4687
4688 m_errorMonitor->VerifyFound();
4689 vkDestroyImage(m_device->device(), image, NULL);
4690 vkFreeMemory(m_device->device(), image_mem, nullptr);
4691}
4692
4693TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004694 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004695 ASSERT_NO_FATAL_FAILURE(InitState());
4696
4697 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004698 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 -06004699 VK_IMAGE_TILING_OPTIMAL, 0);
4700 ASSERT_TRUE(image.initialized());
4701
4702 VkBuffer buffer;
4703 VkDeviceMemory mem;
4704 VkMemoryRequirements mem_reqs;
4705
4706 VkBufferCreateInfo buf_info = {};
4707 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004708 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004709 buf_info.size = 256;
4710 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4711 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4712 ASSERT_VK_SUCCESS(err);
4713
4714 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4715
4716 VkMemoryAllocateInfo alloc_info = {};
4717 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4718 alloc_info.allocationSize = 256;
4719 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004720 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 -06004721 if (!pass) {
4722 vkDestroyBuffer(m_device->device(), buffer, NULL);
4723 return;
4724 }
4725 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4726 ASSERT_VK_SUCCESS(err);
4727
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004728 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004730 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004731 VkBufferImageCopy region = {};
4732 region.bufferRowLength = 128;
4733 region.bufferImageHeight = 128;
4734 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4735
4736 region.imageSubresource.layerCount = 1;
4737 region.imageExtent.height = 4;
4738 region.imageExtent.width = 4;
4739 region.imageExtent.depth = 1;
4740 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004741 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4742 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004743 m_commandBuffer->EndCommandBuffer();
4744
4745 m_errorMonitor->VerifyFound();
4746
4747 vkDestroyBuffer(m_device->device(), buffer, NULL);
4748 vkFreeMemory(m_device->handle(), mem, NULL);
4749}
4750
Tobin Ehlis85940f52016-07-07 16:57:21 -06004751TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4752 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4753 "due to an event dependency being destroyed.");
4754 ASSERT_NO_FATAL_FAILURE(InitState());
4755
4756 VkEvent event;
4757 VkEventCreateInfo evci = {};
4758 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4759 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4760 ASSERT_VK_SUCCESS(result);
4761
4762 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004763 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004764 m_commandBuffer->EndCommandBuffer();
4765
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004767 // Destroy event dependency prior to submit to cause ERROR
4768 vkDestroyEvent(m_device->device(), event, NULL);
4769
4770 VkSubmitInfo submit_info = {};
4771 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4772 submit_info.commandBufferCount = 1;
4773 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4774 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4775
4776 m_errorMonitor->VerifyFound();
4777}
4778
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004779TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4780 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4781 "due to a query pool dependency being destroyed.");
4782 ASSERT_NO_FATAL_FAILURE(InitState());
4783
4784 VkQueryPool query_pool;
4785 VkQueryPoolCreateInfo qpci{};
4786 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4787 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4788 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004789 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004790 ASSERT_VK_SUCCESS(result);
4791
4792 m_commandBuffer->BeginCommandBuffer();
4793 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4794 m_commandBuffer->EndCommandBuffer();
4795
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004797 // Destroy query pool dependency prior to submit to cause ERROR
4798 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4799
4800 VkSubmitInfo submit_info = {};
4801 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4802 submit_info.commandBufferCount = 1;
4803 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4804 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4805
4806 m_errorMonitor->VerifyFound();
4807}
4808
Tobin Ehlis24130d92016-07-08 15:50:53 -06004809TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4810 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4811 "due to a pipeline dependency being destroyed.");
4812 ASSERT_NO_FATAL_FAILURE(InitState());
4813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4814
4815 VkResult err;
4816
4817 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4818 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4819
4820 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004821 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004822 ASSERT_VK_SUCCESS(err);
4823
4824 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4825 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4826 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004827 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004828 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004829 vp_state_ci.scissorCount = 1;
4830 VkRect2D scissors = {}; // Dummy scissors to point to
4831 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004832
4833 VkPipelineShaderStageCreateInfo shaderStages[2];
4834 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4835
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004836 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4837 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4838 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004839 shaderStages[0] = vs.GetStageCreateInfo();
4840 shaderStages[1] = fs.GetStageCreateInfo();
4841
4842 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4843 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4844
4845 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4846 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4847 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4848
4849 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4850 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004851 rs_ci.rasterizerDiscardEnable = true;
4852 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004853
4854 VkPipelineColorBlendAttachmentState att = {};
4855 att.blendEnable = VK_FALSE;
4856 att.colorWriteMask = 0xf;
4857
4858 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4859 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4860 cb_ci.attachmentCount = 1;
4861 cb_ci.pAttachments = &att;
4862
4863 VkGraphicsPipelineCreateInfo gp_ci = {};
4864 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4865 gp_ci.stageCount = 2;
4866 gp_ci.pStages = shaderStages;
4867 gp_ci.pVertexInputState = &vi_ci;
4868 gp_ci.pInputAssemblyState = &ia_ci;
4869 gp_ci.pViewportState = &vp_state_ci;
4870 gp_ci.pRasterizationState = &rs_ci;
4871 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004872 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4873 gp_ci.layout = pipeline_layout;
4874 gp_ci.renderPass = renderPass();
4875
4876 VkPipelineCacheCreateInfo pc_ci = {};
4877 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4878
4879 VkPipeline pipeline;
4880 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004881 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004882 ASSERT_VK_SUCCESS(err);
4883
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004884 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004885 ASSERT_VK_SUCCESS(err);
4886
4887 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004888 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004889 m_commandBuffer->EndCommandBuffer();
4890 // Now destroy pipeline in order to cause error when submitting
4891 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4892
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004894
4895 VkSubmitInfo submit_info = {};
4896 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4897 submit_info.commandBufferCount = 1;
4898 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4899 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4900
4901 m_errorMonitor->VerifyFound();
4902 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4903 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4904}
4905
Tobin Ehlis31289162016-08-17 14:57:58 -06004906TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4907 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4908 "due to a bound descriptor set with a buffer dependency "
4909 "being destroyed.");
4910 ASSERT_NO_FATAL_FAILURE(InitState());
4911 ASSERT_NO_FATAL_FAILURE(InitViewport());
4912 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4913
4914 VkDescriptorPoolSize ds_type_count = {};
4915 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4916 ds_type_count.descriptorCount = 1;
4917
4918 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4919 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4920 ds_pool_ci.pNext = NULL;
4921 ds_pool_ci.maxSets = 1;
4922 ds_pool_ci.poolSizeCount = 1;
4923 ds_pool_ci.pPoolSizes = &ds_type_count;
4924
4925 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004926 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004927 ASSERT_VK_SUCCESS(err);
4928
4929 VkDescriptorSetLayoutBinding dsl_binding = {};
4930 dsl_binding.binding = 0;
4931 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4932 dsl_binding.descriptorCount = 1;
4933 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4934 dsl_binding.pImmutableSamplers = NULL;
4935
4936 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4937 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4938 ds_layout_ci.pNext = NULL;
4939 ds_layout_ci.bindingCount = 1;
4940 ds_layout_ci.pBindings = &dsl_binding;
4941 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004942 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004943 ASSERT_VK_SUCCESS(err);
4944
4945 VkDescriptorSet descriptorSet;
4946 VkDescriptorSetAllocateInfo alloc_info = {};
4947 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4948 alloc_info.descriptorSetCount = 1;
4949 alloc_info.descriptorPool = ds_pool;
4950 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004951 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004952 ASSERT_VK_SUCCESS(err);
4953
4954 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4955 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4956 pipeline_layout_ci.pNext = NULL;
4957 pipeline_layout_ci.setLayoutCount = 1;
4958 pipeline_layout_ci.pSetLayouts = &ds_layout;
4959
4960 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004961 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004962 ASSERT_VK_SUCCESS(err);
4963
4964 // Create a buffer to update the descriptor with
4965 uint32_t qfi = 0;
4966 VkBufferCreateInfo buffCI = {};
4967 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4968 buffCI.size = 1024;
4969 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4970 buffCI.queueFamilyIndexCount = 1;
4971 buffCI.pQueueFamilyIndices = &qfi;
4972
4973 VkBuffer buffer;
4974 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4975 ASSERT_VK_SUCCESS(err);
4976 // Allocate memory and bind to buffer so we can make it to the appropriate
4977 // error
4978 VkMemoryAllocateInfo mem_alloc = {};
4979 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4980 mem_alloc.pNext = NULL;
4981 mem_alloc.allocationSize = 1024;
4982 mem_alloc.memoryTypeIndex = 0;
4983
4984 VkMemoryRequirements memReqs;
4985 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004986 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004987 if (!pass) {
4988 vkDestroyBuffer(m_device->device(), buffer, NULL);
4989 return;
4990 }
4991
4992 VkDeviceMemory mem;
4993 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4994 ASSERT_VK_SUCCESS(err);
4995 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4996 ASSERT_VK_SUCCESS(err);
4997 // Correctly update descriptor to avoid "NOT_UPDATED" error
4998 VkDescriptorBufferInfo buffInfo = {};
4999 buffInfo.buffer = buffer;
5000 buffInfo.offset = 0;
5001 buffInfo.range = 1024;
5002
5003 VkWriteDescriptorSet descriptor_write;
5004 memset(&descriptor_write, 0, sizeof(descriptor_write));
5005 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5006 descriptor_write.dstSet = descriptorSet;
5007 descriptor_write.dstBinding = 0;
5008 descriptor_write.descriptorCount = 1;
5009 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5010 descriptor_write.pBufferInfo = &buffInfo;
5011
5012 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5013
5014 // Create PSO to be used for draw-time errors below
5015 char const *vsSource = "#version 450\n"
5016 "\n"
5017 "out gl_PerVertex { \n"
5018 " vec4 gl_Position;\n"
5019 "};\n"
5020 "void main(){\n"
5021 " gl_Position = vec4(1);\n"
5022 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005023 char const *fsSource = "#version 450\n"
5024 "\n"
5025 "layout(location=0) out vec4 x;\n"
5026 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5027 "void main(){\n"
5028 " x = vec4(bar.y);\n"
5029 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005030 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5031 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5032 VkPipelineObj pipe(m_device);
5033 pipe.AddShader(&vs);
5034 pipe.AddShader(&fs);
5035 pipe.AddColorAttachment();
5036 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5037
5038 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005039 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5040 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5041 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005042 Draw(1, 0, 0, 0);
5043 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005045 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5046 vkDestroyBuffer(m_device->device(), buffer, NULL);
5047 // Attempt to submit cmd buffer
5048 VkSubmitInfo submit_info = {};
5049 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5050 submit_info.commandBufferCount = 1;
5051 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5052 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5053 m_errorMonitor->VerifyFound();
5054 // Cleanup
5055 vkFreeMemory(m_device->device(), mem, NULL);
5056
5057 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5058 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5059 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5060}
5061
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005062TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5063 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5064 "due to a bound descriptor sets with a combined image "
5065 "sampler having their image, sampler, and descriptor set "
5066 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005067 "submit associated cmd buffers. Attempt to destroy a "
5068 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005069 ASSERT_NO_FATAL_FAILURE(InitState());
5070 ASSERT_NO_FATAL_FAILURE(InitViewport());
5071 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5072
5073 VkDescriptorPoolSize ds_type_count = {};
5074 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5075 ds_type_count.descriptorCount = 1;
5076
5077 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5078 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5079 ds_pool_ci.pNext = NULL;
5080 ds_pool_ci.maxSets = 1;
5081 ds_pool_ci.poolSizeCount = 1;
5082 ds_pool_ci.pPoolSizes = &ds_type_count;
5083
5084 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005085 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005086 ASSERT_VK_SUCCESS(err);
5087
5088 VkDescriptorSetLayoutBinding dsl_binding = {};
5089 dsl_binding.binding = 0;
5090 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5091 dsl_binding.descriptorCount = 1;
5092 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5093 dsl_binding.pImmutableSamplers = NULL;
5094
5095 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5096 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5097 ds_layout_ci.pNext = NULL;
5098 ds_layout_ci.bindingCount = 1;
5099 ds_layout_ci.pBindings = &dsl_binding;
5100 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005101 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005102 ASSERT_VK_SUCCESS(err);
5103
5104 VkDescriptorSet descriptorSet;
5105 VkDescriptorSetAllocateInfo alloc_info = {};
5106 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5107 alloc_info.descriptorSetCount = 1;
5108 alloc_info.descriptorPool = ds_pool;
5109 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005110 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005111 ASSERT_VK_SUCCESS(err);
5112
5113 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5114 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5115 pipeline_layout_ci.pNext = NULL;
5116 pipeline_layout_ci.setLayoutCount = 1;
5117 pipeline_layout_ci.pSetLayouts = &ds_layout;
5118
5119 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005120 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005121 ASSERT_VK_SUCCESS(err);
5122
5123 // Create images to update the descriptor with
5124 VkImage image;
5125 VkImage image2;
5126 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5127 const int32_t tex_width = 32;
5128 const int32_t tex_height = 32;
5129 VkImageCreateInfo image_create_info = {};
5130 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5131 image_create_info.pNext = NULL;
5132 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5133 image_create_info.format = tex_format;
5134 image_create_info.extent.width = tex_width;
5135 image_create_info.extent.height = tex_height;
5136 image_create_info.extent.depth = 1;
5137 image_create_info.mipLevels = 1;
5138 image_create_info.arrayLayers = 1;
5139 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5140 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5141 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5142 image_create_info.flags = 0;
5143 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5144 ASSERT_VK_SUCCESS(err);
5145 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5146 ASSERT_VK_SUCCESS(err);
5147
5148 VkMemoryRequirements memory_reqs;
5149 VkDeviceMemory image_memory;
5150 bool pass;
5151 VkMemoryAllocateInfo memory_info = {};
5152 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5153 memory_info.pNext = NULL;
5154 memory_info.allocationSize = 0;
5155 memory_info.memoryTypeIndex = 0;
5156 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5157 // Allocate enough memory for both images
5158 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005159 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005160 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005161 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005162 ASSERT_VK_SUCCESS(err);
5163 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5164 ASSERT_VK_SUCCESS(err);
5165 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005166 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005167 ASSERT_VK_SUCCESS(err);
5168
5169 VkImageViewCreateInfo image_view_create_info = {};
5170 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5171 image_view_create_info.image = image;
5172 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5173 image_view_create_info.format = tex_format;
5174 image_view_create_info.subresourceRange.layerCount = 1;
5175 image_view_create_info.subresourceRange.baseMipLevel = 0;
5176 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005177 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005178
5179 VkImageView view;
5180 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005181 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005182 ASSERT_VK_SUCCESS(err);
5183 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005184 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005185 ASSERT_VK_SUCCESS(err);
5186 // Create Samplers
5187 VkSamplerCreateInfo sampler_ci = {};
5188 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5189 sampler_ci.pNext = NULL;
5190 sampler_ci.magFilter = VK_FILTER_NEAREST;
5191 sampler_ci.minFilter = VK_FILTER_NEAREST;
5192 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5193 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5194 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5195 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5196 sampler_ci.mipLodBias = 1.0;
5197 sampler_ci.anisotropyEnable = VK_FALSE;
5198 sampler_ci.maxAnisotropy = 1;
5199 sampler_ci.compareEnable = VK_FALSE;
5200 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5201 sampler_ci.minLod = 1.0;
5202 sampler_ci.maxLod = 1.0;
5203 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5204 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5205 VkSampler sampler;
5206 VkSampler sampler2;
5207 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5208 ASSERT_VK_SUCCESS(err);
5209 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5210 ASSERT_VK_SUCCESS(err);
5211 // Update descriptor with image and sampler
5212 VkDescriptorImageInfo img_info = {};
5213 img_info.sampler = sampler;
5214 img_info.imageView = view;
5215 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5216
5217 VkWriteDescriptorSet descriptor_write;
5218 memset(&descriptor_write, 0, sizeof(descriptor_write));
5219 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5220 descriptor_write.dstSet = descriptorSet;
5221 descriptor_write.dstBinding = 0;
5222 descriptor_write.descriptorCount = 1;
5223 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5224 descriptor_write.pImageInfo = &img_info;
5225
5226 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5227
5228 // Create PSO to be used for draw-time errors below
5229 char const *vsSource = "#version 450\n"
5230 "\n"
5231 "out gl_PerVertex { \n"
5232 " vec4 gl_Position;\n"
5233 "};\n"
5234 "void main(){\n"
5235 " gl_Position = vec4(1);\n"
5236 "}\n";
5237 char const *fsSource = "#version 450\n"
5238 "\n"
5239 "layout(set=0, binding=0) uniform sampler2D s;\n"
5240 "layout(location=0) out vec4 x;\n"
5241 "void main(){\n"
5242 " x = texture(s, vec2(1));\n"
5243 "}\n";
5244 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5245 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5246 VkPipelineObj pipe(m_device);
5247 pipe.AddShader(&vs);
5248 pipe.AddShader(&fs);
5249 pipe.AddColorAttachment();
5250 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5251
5252 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005254 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005255 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5256 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5257 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005258 Draw(1, 0, 0, 0);
5259 EndCommandBuffer();
5260 // Destroy sampler invalidates the cmd buffer, causing error on submit
5261 vkDestroySampler(m_device->device(), sampler, NULL);
5262 // Attempt to submit cmd buffer
5263 VkSubmitInfo submit_info = {};
5264 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5265 submit_info.commandBufferCount = 1;
5266 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5267 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5268 m_errorMonitor->VerifyFound();
5269 // Now re-update descriptor with valid sampler and delete image
5270 img_info.sampler = sampler2;
5271 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005273 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005274 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5275 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5276 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005277 Draw(1, 0, 0, 0);
5278 EndCommandBuffer();
5279 // Destroy image invalidates the cmd buffer, causing error on submit
5280 vkDestroyImage(m_device->device(), image, NULL);
5281 // Attempt to submit cmd buffer
5282 submit_info = {};
5283 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5284 submit_info.commandBufferCount = 1;
5285 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5286 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5287 m_errorMonitor->VerifyFound();
5288 // Now update descriptor to be valid, but then free descriptor
5289 img_info.imageView = view2;
5290 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005292 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005293 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5294 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5295 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005296 Draw(1, 0, 0, 0);
5297 EndCommandBuffer();
5298 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005300 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005301 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005302 // Attempt to submit cmd buffer
5303 submit_info = {};
5304 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5305 submit_info.commandBufferCount = 1;
5306 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5307 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5308 m_errorMonitor->VerifyFound();
5309 // Cleanup
5310 vkFreeMemory(m_device->device(), image_memory, NULL);
5311 vkDestroySampler(m_device->device(), sampler2, NULL);
5312 vkDestroyImage(m_device->device(), image2, NULL);
5313 vkDestroyImageView(m_device->device(), view, NULL);
5314 vkDestroyImageView(m_device->device(), view2, NULL);
5315 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5316 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5317 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5318}
5319
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005320TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5321 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5322 ASSERT_NO_FATAL_FAILURE(InitState());
5323 ASSERT_NO_FATAL_FAILURE(InitViewport());
5324 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5325
5326 VkDescriptorPoolSize ds_type_count = {};
5327 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5328 ds_type_count.descriptorCount = 1;
5329
5330 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5331 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5332 ds_pool_ci.pNext = NULL;
5333 ds_pool_ci.maxSets = 1;
5334 ds_pool_ci.poolSizeCount = 1;
5335 ds_pool_ci.pPoolSizes = &ds_type_count;
5336
5337 VkDescriptorPool ds_pool;
5338 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5339 ASSERT_VK_SUCCESS(err);
5340
5341 VkDescriptorSetLayoutBinding dsl_binding = {};
5342 dsl_binding.binding = 0;
5343 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5344 dsl_binding.descriptorCount = 1;
5345 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5346 dsl_binding.pImmutableSamplers = NULL;
5347
5348 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5349 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5350 ds_layout_ci.pNext = NULL;
5351 ds_layout_ci.bindingCount = 1;
5352 ds_layout_ci.pBindings = &dsl_binding;
5353 VkDescriptorSetLayout ds_layout;
5354 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5355 ASSERT_VK_SUCCESS(err);
5356
5357 VkDescriptorSet descriptor_set;
5358 VkDescriptorSetAllocateInfo alloc_info = {};
5359 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5360 alloc_info.descriptorSetCount = 1;
5361 alloc_info.descriptorPool = ds_pool;
5362 alloc_info.pSetLayouts = &ds_layout;
5363 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5364 ASSERT_VK_SUCCESS(err);
5365
5366 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5367 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5368 pipeline_layout_ci.pNext = NULL;
5369 pipeline_layout_ci.setLayoutCount = 1;
5370 pipeline_layout_ci.pSetLayouts = &ds_layout;
5371
5372 VkPipelineLayout pipeline_layout;
5373 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5374 ASSERT_VK_SUCCESS(err);
5375
5376 // Create image to update the descriptor with
5377 VkImageObj image(m_device);
5378 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5379 ASSERT_TRUE(image.initialized());
5380
5381 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5382 // Create Sampler
5383 VkSamplerCreateInfo sampler_ci = {};
5384 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5385 sampler_ci.pNext = NULL;
5386 sampler_ci.magFilter = VK_FILTER_NEAREST;
5387 sampler_ci.minFilter = VK_FILTER_NEAREST;
5388 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5389 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5390 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5391 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5392 sampler_ci.mipLodBias = 1.0;
5393 sampler_ci.anisotropyEnable = VK_FALSE;
5394 sampler_ci.maxAnisotropy = 1;
5395 sampler_ci.compareEnable = VK_FALSE;
5396 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5397 sampler_ci.minLod = 1.0;
5398 sampler_ci.maxLod = 1.0;
5399 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5400 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5401 VkSampler sampler;
5402 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5403 ASSERT_VK_SUCCESS(err);
5404 // Update descriptor with image and sampler
5405 VkDescriptorImageInfo img_info = {};
5406 img_info.sampler = sampler;
5407 img_info.imageView = view;
5408 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5409
5410 VkWriteDescriptorSet descriptor_write;
5411 memset(&descriptor_write, 0, sizeof(descriptor_write));
5412 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5413 descriptor_write.dstSet = descriptor_set;
5414 descriptor_write.dstBinding = 0;
5415 descriptor_write.descriptorCount = 1;
5416 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5417 descriptor_write.pImageInfo = &img_info;
5418
5419 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5420
5421 // Create PSO to be used for draw-time errors below
5422 char const *vsSource = "#version 450\n"
5423 "\n"
5424 "out gl_PerVertex { \n"
5425 " vec4 gl_Position;\n"
5426 "};\n"
5427 "void main(){\n"
5428 " gl_Position = vec4(1);\n"
5429 "}\n";
5430 char const *fsSource = "#version 450\n"
5431 "\n"
5432 "layout(set=0, binding=0) uniform sampler2D s;\n"
5433 "layout(location=0) out vec4 x;\n"
5434 "void main(){\n"
5435 " x = texture(s, vec2(1));\n"
5436 "}\n";
5437 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5438 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5439 VkPipelineObj pipe(m_device);
5440 pipe.AddShader(&vs);
5441 pipe.AddShader(&fs);
5442 pipe.AddColorAttachment();
5443 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5444
5445 BeginCommandBuffer();
5446 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5447 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5448 &descriptor_set, 0, NULL);
5449 Draw(1, 0, 0, 0);
5450 EndCommandBuffer();
5451 // Submit cmd buffer to put pool in-flight
5452 VkSubmitInfo submit_info = {};
5453 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5454 submit_info.commandBufferCount = 1;
5455 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5456 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5457 // Destroy pool while in-flight, causing error
5458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5459 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5460 m_errorMonitor->VerifyFound();
5461 vkQueueWaitIdle(m_device->m_queue);
5462 // Cleanup
5463 vkDestroySampler(m_device->device(), sampler, NULL);
5464 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5465 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5466 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5467}
5468
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005469TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5470 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5471 ASSERT_NO_FATAL_FAILURE(InitState());
5472 ASSERT_NO_FATAL_FAILURE(InitViewport());
5473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5474
5475 VkDescriptorPoolSize ds_type_count = {};
5476 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5477 ds_type_count.descriptorCount = 1;
5478
5479 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5480 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5481 ds_pool_ci.pNext = NULL;
5482 ds_pool_ci.maxSets = 1;
5483 ds_pool_ci.poolSizeCount = 1;
5484 ds_pool_ci.pPoolSizes = &ds_type_count;
5485
5486 VkDescriptorPool ds_pool;
5487 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5488 ASSERT_VK_SUCCESS(err);
5489
5490 VkDescriptorSetLayoutBinding dsl_binding = {};
5491 dsl_binding.binding = 0;
5492 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5493 dsl_binding.descriptorCount = 1;
5494 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5495 dsl_binding.pImmutableSamplers = NULL;
5496
5497 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5498 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5499 ds_layout_ci.pNext = NULL;
5500 ds_layout_ci.bindingCount = 1;
5501 ds_layout_ci.pBindings = &dsl_binding;
5502 VkDescriptorSetLayout ds_layout;
5503 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5504 ASSERT_VK_SUCCESS(err);
5505
5506 VkDescriptorSet descriptorSet;
5507 VkDescriptorSetAllocateInfo alloc_info = {};
5508 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5509 alloc_info.descriptorSetCount = 1;
5510 alloc_info.descriptorPool = ds_pool;
5511 alloc_info.pSetLayouts = &ds_layout;
5512 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5513 ASSERT_VK_SUCCESS(err);
5514
5515 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5516 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5517 pipeline_layout_ci.pNext = NULL;
5518 pipeline_layout_ci.setLayoutCount = 1;
5519 pipeline_layout_ci.pSetLayouts = &ds_layout;
5520
5521 VkPipelineLayout pipeline_layout;
5522 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5523 ASSERT_VK_SUCCESS(err);
5524
5525 // Create images to update the descriptor with
5526 VkImage image;
5527 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5528 const int32_t tex_width = 32;
5529 const int32_t tex_height = 32;
5530 VkImageCreateInfo image_create_info = {};
5531 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5532 image_create_info.pNext = NULL;
5533 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5534 image_create_info.format = tex_format;
5535 image_create_info.extent.width = tex_width;
5536 image_create_info.extent.height = tex_height;
5537 image_create_info.extent.depth = 1;
5538 image_create_info.mipLevels = 1;
5539 image_create_info.arrayLayers = 1;
5540 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5541 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5542 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5543 image_create_info.flags = 0;
5544 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5545 ASSERT_VK_SUCCESS(err);
5546 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5547 VkMemoryRequirements memory_reqs;
5548 VkDeviceMemory image_memory;
5549 bool pass;
5550 VkMemoryAllocateInfo memory_info = {};
5551 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5552 memory_info.pNext = NULL;
5553 memory_info.allocationSize = 0;
5554 memory_info.memoryTypeIndex = 0;
5555 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5556 // Allocate enough memory for image
5557 memory_info.allocationSize = memory_reqs.size;
5558 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5559 ASSERT_TRUE(pass);
5560 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5561 ASSERT_VK_SUCCESS(err);
5562 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5563 ASSERT_VK_SUCCESS(err);
5564
5565 VkImageViewCreateInfo image_view_create_info = {};
5566 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5567 image_view_create_info.image = image;
5568 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5569 image_view_create_info.format = tex_format;
5570 image_view_create_info.subresourceRange.layerCount = 1;
5571 image_view_create_info.subresourceRange.baseMipLevel = 0;
5572 image_view_create_info.subresourceRange.levelCount = 1;
5573 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5574
5575 VkImageView view;
5576 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5577 ASSERT_VK_SUCCESS(err);
5578 // Create Samplers
5579 VkSamplerCreateInfo sampler_ci = {};
5580 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5581 sampler_ci.pNext = NULL;
5582 sampler_ci.magFilter = VK_FILTER_NEAREST;
5583 sampler_ci.minFilter = VK_FILTER_NEAREST;
5584 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5585 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5586 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5587 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5588 sampler_ci.mipLodBias = 1.0;
5589 sampler_ci.anisotropyEnable = VK_FALSE;
5590 sampler_ci.maxAnisotropy = 1;
5591 sampler_ci.compareEnable = VK_FALSE;
5592 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5593 sampler_ci.minLod = 1.0;
5594 sampler_ci.maxLod = 1.0;
5595 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5596 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5597 VkSampler sampler;
5598 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5599 ASSERT_VK_SUCCESS(err);
5600 // Update descriptor with image and sampler
5601 VkDescriptorImageInfo img_info = {};
5602 img_info.sampler = sampler;
5603 img_info.imageView = view;
5604 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5605
5606 VkWriteDescriptorSet descriptor_write;
5607 memset(&descriptor_write, 0, sizeof(descriptor_write));
5608 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5609 descriptor_write.dstSet = descriptorSet;
5610 descriptor_write.dstBinding = 0;
5611 descriptor_write.descriptorCount = 1;
5612 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5613 descriptor_write.pImageInfo = &img_info;
5614 // Break memory binding and attempt update
5615 vkFreeMemory(m_device->device(), image_memory, nullptr);
5616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005617 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5619 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5620 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5621 m_errorMonitor->VerifyFound();
5622 // Cleanup
5623 vkDestroyImage(m_device->device(), image, NULL);
5624 vkDestroySampler(m_device->device(), sampler, NULL);
5625 vkDestroyImageView(m_device->device(), view, NULL);
5626 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5627 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5628 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5629}
5630
Karl Schultz6addd812016-02-02 17:17:23 -07005631TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005632 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5633 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005634 // Create a valid cmd buffer
5635 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005636 uint64_t fake_pipeline_handle = 0xbaad6001;
5637 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005638 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5640
5641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005642 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005643 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005644 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005645
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005646 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005647 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 -06005648 Draw(1, 0, 0, 0);
5649 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005650
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005651 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005652 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 +12005653 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005654 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5655 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005656}
5657
Karl Schultz6addd812016-02-02 17:17:23 -07005658TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005659 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005660 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005661
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005663
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005664 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005665 ASSERT_NO_FATAL_FAILURE(InitViewport());
5666 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005667 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005668 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5669 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005670
5671 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005672 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5673 ds_pool_ci.pNext = NULL;
5674 ds_pool_ci.maxSets = 1;
5675 ds_pool_ci.poolSizeCount = 1;
5676 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005677
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005678 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005679 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005680 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005681
Tony Barboureb254902015-07-15 12:50:33 -06005682 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005683 dsl_binding.binding = 0;
5684 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5685 dsl_binding.descriptorCount = 1;
5686 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5687 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005688
Tony Barboureb254902015-07-15 12:50:33 -06005689 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005690 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5691 ds_layout_ci.pNext = NULL;
5692 ds_layout_ci.bindingCount = 1;
5693 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005694 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005695 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005696 ASSERT_VK_SUCCESS(err);
5697
5698 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005699 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005700 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005701 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005702 alloc_info.descriptorPool = ds_pool;
5703 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005704 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005705 ASSERT_VK_SUCCESS(err);
5706
Tony Barboureb254902015-07-15 12:50:33 -06005707 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005708 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5709 pipeline_layout_ci.pNext = NULL;
5710 pipeline_layout_ci.setLayoutCount = 1;
5711 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005712
5713 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005714 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005715 ASSERT_VK_SUCCESS(err);
5716
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005717 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005718 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005719 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005720 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005721
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005722 VkPipelineObj pipe(m_device);
5723 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005724 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005725 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005726 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005727
5728 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005729 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5730 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5731 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005732
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005733 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005734
Chia-I Wuf7458c52015-10-26 21:10:41 +08005735 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5736 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5737 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005738}
5739
Karl Schultz6addd812016-02-02 17:17:23 -07005740TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005741 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005742 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5745 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005746
5747 ASSERT_NO_FATAL_FAILURE(InitState());
5748 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005749 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5750 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005751
5752 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005753 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5754 ds_pool_ci.pNext = NULL;
5755 ds_pool_ci.maxSets = 1;
5756 ds_pool_ci.poolSizeCount = 1;
5757 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005758
5759 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005760 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005761 ASSERT_VK_SUCCESS(err);
5762
5763 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005764 dsl_binding.binding = 0;
5765 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5766 dsl_binding.descriptorCount = 1;
5767 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5768 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005769
5770 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005771 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5772 ds_layout_ci.pNext = NULL;
5773 ds_layout_ci.bindingCount = 1;
5774 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005775 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005776 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005777 ASSERT_VK_SUCCESS(err);
5778
5779 VkDescriptorSet descriptorSet;
5780 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005781 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005782 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005783 alloc_info.descriptorPool = ds_pool;
5784 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005785 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005786 ASSERT_VK_SUCCESS(err);
5787
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005788 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005789 VkWriteDescriptorSet descriptor_write;
5790 memset(&descriptor_write, 0, sizeof(descriptor_write));
5791 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5792 descriptor_write.dstSet = descriptorSet;
5793 descriptor_write.dstBinding = 0;
5794 descriptor_write.descriptorCount = 1;
5795 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5796 descriptor_write.pTexelBufferView = &view;
5797
5798 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5799
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005800 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005801
5802 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5803 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5804}
5805
Mark Youngd339ba32016-05-30 13:28:35 -06005806TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005807 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 -06005808
5809 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005811 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005812
5813 ASSERT_NO_FATAL_FAILURE(InitState());
5814
5815 // Create a buffer with no bound memory and then attempt to create
5816 // a buffer view.
5817 VkBufferCreateInfo buff_ci = {};
5818 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005819 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005820 buff_ci.size = 256;
5821 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5822 VkBuffer buffer;
5823 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5824 ASSERT_VK_SUCCESS(err);
5825
5826 VkBufferViewCreateInfo buff_view_ci = {};
5827 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5828 buff_view_ci.buffer = buffer;
5829 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5830 buff_view_ci.range = VK_WHOLE_SIZE;
5831 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005832 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005833
5834 m_errorMonitor->VerifyFound();
5835 vkDestroyBuffer(m_device->device(), buffer, NULL);
5836 // If last error is success, it still created the view, so delete it.
5837 if (err == VK_SUCCESS) {
5838 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5839 }
5840}
5841
Karl Schultz6addd812016-02-02 17:17:23 -07005842TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5843 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5844 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005845 // 1. No dynamicOffset supplied
5846 // 2. Too many dynamicOffsets supplied
5847 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005848 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5850 "0 dynamicOffsets are left in "
5851 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005852
5853 ASSERT_NO_FATAL_FAILURE(InitState());
5854 ASSERT_NO_FATAL_FAILURE(InitViewport());
5855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5856
5857 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005858 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5859 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005860
5861 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005862 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5863 ds_pool_ci.pNext = NULL;
5864 ds_pool_ci.maxSets = 1;
5865 ds_pool_ci.poolSizeCount = 1;
5866 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005867
5868 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005869 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005870 ASSERT_VK_SUCCESS(err);
5871
5872 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005873 dsl_binding.binding = 0;
5874 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5875 dsl_binding.descriptorCount = 1;
5876 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5877 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005878
5879 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005880 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5881 ds_layout_ci.pNext = NULL;
5882 ds_layout_ci.bindingCount = 1;
5883 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005884 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005885 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005886 ASSERT_VK_SUCCESS(err);
5887
5888 VkDescriptorSet descriptorSet;
5889 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005890 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005891 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005892 alloc_info.descriptorPool = ds_pool;
5893 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005894 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005895 ASSERT_VK_SUCCESS(err);
5896
5897 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005898 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5899 pipeline_layout_ci.pNext = NULL;
5900 pipeline_layout_ci.setLayoutCount = 1;
5901 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005902
5903 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005904 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005905 ASSERT_VK_SUCCESS(err);
5906
5907 // Create a buffer to update the descriptor with
5908 uint32_t qfi = 0;
5909 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005910 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5911 buffCI.size = 1024;
5912 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5913 buffCI.queueFamilyIndexCount = 1;
5914 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005915
5916 VkBuffer dyub;
5917 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5918 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005919 // Allocate memory and bind to buffer so we can make it to the appropriate
5920 // error
5921 VkMemoryAllocateInfo mem_alloc = {};
5922 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5923 mem_alloc.pNext = NULL;
5924 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005925 mem_alloc.memoryTypeIndex = 0;
5926
5927 VkMemoryRequirements memReqs;
5928 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005929 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005930 if (!pass) {
5931 vkDestroyBuffer(m_device->device(), dyub, NULL);
5932 return;
5933 }
5934
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005935 VkDeviceMemory mem;
5936 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5937 ASSERT_VK_SUCCESS(err);
5938 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5939 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005940 // Correctly update descriptor to avoid "NOT_UPDATED" error
5941 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005942 buffInfo.buffer = dyub;
5943 buffInfo.offset = 0;
5944 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005945
5946 VkWriteDescriptorSet descriptor_write;
5947 memset(&descriptor_write, 0, sizeof(descriptor_write));
5948 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5949 descriptor_write.dstSet = descriptorSet;
5950 descriptor_write.dstBinding = 0;
5951 descriptor_write.descriptorCount = 1;
5952 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5953 descriptor_write.pBufferInfo = &buffInfo;
5954
5955 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5956
5957 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005958 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5959 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005960 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005961 uint32_t pDynOff[2] = {512, 756};
5962 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5964 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5965 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5966 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005967 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005968 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5970 "offset 0 and range 1024 that "
5971 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005972 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005973 char const *vsSource = "#version 450\n"
5974 "\n"
5975 "out gl_PerVertex { \n"
5976 " vec4 gl_Position;\n"
5977 "};\n"
5978 "void main(){\n"
5979 " gl_Position = vec4(1);\n"
5980 "}\n";
5981 char const *fsSource = "#version 450\n"
5982 "\n"
5983 "layout(location=0) out vec4 x;\n"
5984 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5985 "void main(){\n"
5986 " x = vec4(bar.y);\n"
5987 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005988 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5989 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5990 VkPipelineObj pipe(m_device);
5991 pipe.AddShader(&vs);
5992 pipe.AddShader(&fs);
5993 pipe.AddColorAttachment();
5994 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5995
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005996 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005997 // This update should succeed, but offset size of 512 will overstep buffer
5998 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005999 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6000 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006001 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006002 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006003
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006004 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006005 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006006
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006007 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006008 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006009 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6010}
6011
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006012TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6013 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6014 "that doesn't have memory bound");
6015 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006017 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6019 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006020
6021 ASSERT_NO_FATAL_FAILURE(InitState());
6022 ASSERT_NO_FATAL_FAILURE(InitViewport());
6023 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6024
6025 VkDescriptorPoolSize ds_type_count = {};
6026 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6027 ds_type_count.descriptorCount = 1;
6028
6029 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6030 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6031 ds_pool_ci.pNext = NULL;
6032 ds_pool_ci.maxSets = 1;
6033 ds_pool_ci.poolSizeCount = 1;
6034 ds_pool_ci.pPoolSizes = &ds_type_count;
6035
6036 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006037 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006038 ASSERT_VK_SUCCESS(err);
6039
6040 VkDescriptorSetLayoutBinding dsl_binding = {};
6041 dsl_binding.binding = 0;
6042 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6043 dsl_binding.descriptorCount = 1;
6044 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6045 dsl_binding.pImmutableSamplers = NULL;
6046
6047 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6048 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6049 ds_layout_ci.pNext = NULL;
6050 ds_layout_ci.bindingCount = 1;
6051 ds_layout_ci.pBindings = &dsl_binding;
6052 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006053 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006054 ASSERT_VK_SUCCESS(err);
6055
6056 VkDescriptorSet descriptorSet;
6057 VkDescriptorSetAllocateInfo alloc_info = {};
6058 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6059 alloc_info.descriptorSetCount = 1;
6060 alloc_info.descriptorPool = ds_pool;
6061 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006062 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006063 ASSERT_VK_SUCCESS(err);
6064
6065 // Create a buffer to update the descriptor with
6066 uint32_t qfi = 0;
6067 VkBufferCreateInfo buffCI = {};
6068 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6069 buffCI.size = 1024;
6070 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6071 buffCI.queueFamilyIndexCount = 1;
6072 buffCI.pQueueFamilyIndices = &qfi;
6073
6074 VkBuffer dyub;
6075 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6076 ASSERT_VK_SUCCESS(err);
6077
6078 // Attempt to update descriptor without binding memory to it
6079 VkDescriptorBufferInfo buffInfo = {};
6080 buffInfo.buffer = dyub;
6081 buffInfo.offset = 0;
6082 buffInfo.range = 1024;
6083
6084 VkWriteDescriptorSet descriptor_write;
6085 memset(&descriptor_write, 0, sizeof(descriptor_write));
6086 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6087 descriptor_write.dstSet = descriptorSet;
6088 descriptor_write.dstBinding = 0;
6089 descriptor_write.descriptorCount = 1;
6090 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6091 descriptor_write.pBufferInfo = &buffInfo;
6092
6093 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6094 m_errorMonitor->VerifyFound();
6095
6096 vkDestroyBuffer(m_device->device(), dyub, NULL);
6097 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6098 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6099}
6100
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006101TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006102 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006103 ASSERT_NO_FATAL_FAILURE(InitState());
6104 ASSERT_NO_FATAL_FAILURE(InitViewport());
6105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6106
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006107 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006108 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006109 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6110 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6111 pipeline_layout_ci.pushConstantRangeCount = 1;
6112 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6113
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006114 //
6115 // Check for invalid push constant ranges in pipeline layouts.
6116 //
6117 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006118 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006119 char const *msg;
6120 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006121
Karl Schultzc81037d2016-05-12 08:11:23 -06006122 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6123 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6124 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6125 "vkCreatePipelineLayout() call has push constants index 0 with "
6126 "size 0."},
6127 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6128 "vkCreatePipelineLayout() call has push constants index 0 with "
6129 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006130 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006131 "vkCreatePipelineLayout() call has push constants index 0 with "
6132 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006133 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006134 "vkCreatePipelineLayout() call has push constants index 0 with "
6135 "size 0."},
6136 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6137 "vkCreatePipelineLayout() call has push constants index 0 with "
6138 "offset 1. Offset must"},
6139 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6140 "vkCreatePipelineLayout() call has push constants index 0 "
6141 "with offset "},
6142 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6143 "vkCreatePipelineLayout() call has push constants "
6144 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006145 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006146 "vkCreatePipelineLayout() call has push constants index 0 "
6147 "with offset "},
6148 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6149 "vkCreatePipelineLayout() call has push "
6150 "constants index 0 with offset "},
6151 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6152 "vkCreatePipelineLayout() call has push "
6153 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006154 }};
6155
6156 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006157 for (const auto &iter : range_tests) {
6158 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6160 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006161 m_errorMonitor->VerifyFound();
6162 if (VK_SUCCESS == err) {
6163 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6164 }
6165 }
6166
6167 // Check for invalid stage flag
6168 pc_range.offset = 0;
6169 pc_range.size = 16;
6170 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006171 m_errorMonitor->SetDesiredFailureMsg(
6172 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6173 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006174 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006175 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006176 if (VK_SUCCESS == err) {
6177 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6178 }
6179
6180 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006181 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006182 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006183 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006184 char const *msg;
6185 };
6186
Karl Schultzc81037d2016-05-12 08:11:23 -06006187 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006188 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6189 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6190 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6191 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6192 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006193 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006194 {
6195 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6196 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6197 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6198 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6199 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006200 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006201 },
6202 {
6203 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6204 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6205 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6206 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6207 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006208 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006209 },
6210 {
6211 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6212 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6213 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6214 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6215 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006216 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006217 },
6218 {
6219 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6220 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6221 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6222 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6223 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006224 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006225 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006226
Karl Schultzc81037d2016-05-12 08:11:23 -06006227 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006228 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006229 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6231 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006232 m_errorMonitor->VerifyFound();
6233 if (VK_SUCCESS == err) {
6234 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6235 }
6236 }
6237
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006238 //
6239 // CmdPushConstants tests
6240 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006241 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006242
6243 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006244 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6245 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006246 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6247 "vkCmdPushConstants() call has push constants with size 1. Size "
6248 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006249 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006250 "vkCmdPushConstants() call has push constants with size 1. Size "
6251 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006252 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006253 "vkCmdPushConstants() call has push constants with offset 1. "
6254 "Offset must be a multiple of 4."},
6255 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6256 "vkCmdPushConstants() call has push constants with offset 1. "
6257 "Offset must be a multiple of 4."},
6258 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6259 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6260 "0x1 not within flag-matching ranges in pipeline layout"},
6261 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6262 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6263 "0x1 not within flag-matching ranges in pipeline layout"},
6264 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6265 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6266 "0x1 not within flag-matching ranges in pipeline layout"},
6267 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6268 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6269 "0x1 not within flag-matching ranges in pipeline layout"},
6270 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6271 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6272 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006273 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006274 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6275 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006276 }};
6277
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006278 BeginCommandBuffer();
6279
6280 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006281 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006282 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006283 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006284 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006285 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006286 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006287 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006288 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6290 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006291 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006292 m_errorMonitor->VerifyFound();
6293 }
6294
6295 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006297 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006298 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006299 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006300
Karl Schultzc81037d2016-05-12 08:11:23 -06006301 // overlapping range tests with cmd
6302 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6303 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6304 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6305 "0x1 not within flag-matching ranges in pipeline layout"},
6306 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6307 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6308 "0x1 not within flag-matching ranges in pipeline layout"},
6309 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6310 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6311 "0x1 not within flag-matching ranges in pipeline layout"},
6312 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006313 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006314 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006315 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6316 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006317 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006318 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006319 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006320 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006321 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006322 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6324 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006325 iter.range.size, dummy_values);
6326 m_errorMonitor->VerifyFound();
6327 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006328 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6329
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006330 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006331}
6332
Karl Schultz6addd812016-02-02 17:17:23 -07006333TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006334 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006335 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006336
6337 ASSERT_NO_FATAL_FAILURE(InitState());
6338 ASSERT_NO_FATAL_FAILURE(InitViewport());
6339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6340
Mike Stroyanb8a61002016-06-20 16:00:28 -06006341 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6342 VkImageTiling tiling;
6343 VkFormatProperties format_properties;
6344 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006345 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006346 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006347 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006348 tiling = VK_IMAGE_TILING_OPTIMAL;
6349 } else {
6350 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6351 "skipped.\n");
6352 return;
6353 }
6354
Tobin Ehlis559c6382015-11-05 09:52:49 -07006355 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6356 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006357 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6358 ds_type_count[0].descriptorCount = 10;
6359 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6360 ds_type_count[1].descriptorCount = 2;
6361 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6362 ds_type_count[2].descriptorCount = 2;
6363 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6364 ds_type_count[3].descriptorCount = 5;
6365 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6366 // type
6367 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6368 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6369 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006370
6371 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006372 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6373 ds_pool_ci.pNext = NULL;
6374 ds_pool_ci.maxSets = 5;
6375 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6376 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006377
6378 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006379 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006380 ASSERT_VK_SUCCESS(err);
6381
6382 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6383 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006384 dsl_binding[0].binding = 0;
6385 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6386 dsl_binding[0].descriptorCount = 5;
6387 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6388 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006389
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006390 // Create layout identical to set0 layout but w/ different stageFlags
6391 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006392 dsl_fs_stage_only.binding = 0;
6393 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6394 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006395 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6396 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006397 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006398 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006399 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6400 ds_layout_ci.pNext = NULL;
6401 ds_layout_ci.bindingCount = 1;
6402 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006403 static const uint32_t NUM_LAYOUTS = 4;
6404 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006405 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006406 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6407 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006408 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006409 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006410 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006411 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006412 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006413 dsl_binding[0].binding = 0;
6414 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006415 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006416 dsl_binding[1].binding = 1;
6417 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6418 dsl_binding[1].descriptorCount = 2;
6419 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6420 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006421 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006422 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006423 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006424 ASSERT_VK_SUCCESS(err);
6425 dsl_binding[0].binding = 0;
6426 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006427 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006428 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006429 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006430 ASSERT_VK_SUCCESS(err);
6431 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006432 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006433 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006434 ASSERT_VK_SUCCESS(err);
6435
6436 static const uint32_t NUM_SETS = 4;
6437 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6438 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006439 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006440 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006441 alloc_info.descriptorPool = ds_pool;
6442 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006443 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006444 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006445 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006446 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006447 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006448 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006449 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006450
6451 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006452 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6453 pipeline_layout_ci.pNext = NULL;
6454 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6455 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006456
6457 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006458 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006459 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006460 // Create pipelineLayout with only one setLayout
6461 pipeline_layout_ci.setLayoutCount = 1;
6462 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006463 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006464 ASSERT_VK_SUCCESS(err);
6465 // Create pipelineLayout with 2 descriptor setLayout at index 0
6466 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6467 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006468 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006469 ASSERT_VK_SUCCESS(err);
6470 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6471 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6472 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006473 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006474 ASSERT_VK_SUCCESS(err);
6475 // Create pipelineLayout with UB type, but stageFlags for FS only
6476 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6477 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006478 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006479 ASSERT_VK_SUCCESS(err);
6480 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6481 VkDescriptorSetLayout pl_bad_s0[2] = {};
6482 pl_bad_s0[0] = ds_layout_fs_only;
6483 pl_bad_s0[1] = ds_layout[1];
6484 pipeline_layout_ci.setLayoutCount = 2;
6485 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6486 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006487 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006488 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006489
6490 // Create a buffer to update the descriptor with
6491 uint32_t qfi = 0;
6492 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006493 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6494 buffCI.size = 1024;
6495 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6496 buffCI.queueFamilyIndexCount = 1;
6497 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006498
6499 VkBuffer dyub;
6500 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6501 ASSERT_VK_SUCCESS(err);
6502 // Correctly update descriptor to avoid "NOT_UPDATED" error
6503 static const uint32_t NUM_BUFFS = 5;
6504 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006505 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006506 buffInfo[i].buffer = dyub;
6507 buffInfo[i].offset = 0;
6508 buffInfo[i].range = 1024;
6509 }
Karl Schultz6addd812016-02-02 17:17:23 -07006510 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006511 const int32_t tex_width = 32;
6512 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006513 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006514 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6515 image_create_info.pNext = NULL;
6516 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6517 image_create_info.format = tex_format;
6518 image_create_info.extent.width = tex_width;
6519 image_create_info.extent.height = tex_height;
6520 image_create_info.extent.depth = 1;
6521 image_create_info.mipLevels = 1;
6522 image_create_info.arrayLayers = 1;
6523 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006524 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006525 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006526 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006527 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6528 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006529
Karl Schultz6addd812016-02-02 17:17:23 -07006530 VkMemoryRequirements memReqs;
6531 VkDeviceMemory imageMem;
6532 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006533 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006534 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6535 memAlloc.pNext = NULL;
6536 memAlloc.allocationSize = 0;
6537 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006538 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6539 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006540 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006541 ASSERT_TRUE(pass);
6542 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6543 ASSERT_VK_SUCCESS(err);
6544 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6545 ASSERT_VK_SUCCESS(err);
6546
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006547 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006548 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6549 image_view_create_info.image = image;
6550 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6551 image_view_create_info.format = tex_format;
6552 image_view_create_info.subresourceRange.layerCount = 1;
6553 image_view_create_info.subresourceRange.baseMipLevel = 0;
6554 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006555 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006556
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006557 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006558 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006559 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006560 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006561 imageInfo[0].imageView = view;
6562 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6563 imageInfo[1].imageView = view;
6564 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006565 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006566 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006567 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006568 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006569
6570 static const uint32_t NUM_SET_UPDATES = 3;
6571 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6572 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6573 descriptor_write[0].dstSet = descriptorSet[0];
6574 descriptor_write[0].dstBinding = 0;
6575 descriptor_write[0].descriptorCount = 5;
6576 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6577 descriptor_write[0].pBufferInfo = buffInfo;
6578 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6579 descriptor_write[1].dstSet = descriptorSet[1];
6580 descriptor_write[1].dstBinding = 0;
6581 descriptor_write[1].descriptorCount = 2;
6582 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6583 descriptor_write[1].pImageInfo = imageInfo;
6584 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6585 descriptor_write[2].dstSet = descriptorSet[1];
6586 descriptor_write[2].dstBinding = 1;
6587 descriptor_write[2].descriptorCount = 2;
6588 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006589 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006590
6591 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006592
Tobin Ehlis88452832015-12-03 09:40:56 -07006593 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006594 char const *vsSource = "#version 450\n"
6595 "\n"
6596 "out gl_PerVertex {\n"
6597 " vec4 gl_Position;\n"
6598 "};\n"
6599 "void main(){\n"
6600 " gl_Position = vec4(1);\n"
6601 "}\n";
6602 char const *fsSource = "#version 450\n"
6603 "\n"
6604 "layout(location=0) out vec4 x;\n"
6605 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6606 "void main(){\n"
6607 " x = vec4(bar.y);\n"
6608 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006609 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6610 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006611 VkPipelineObj pipe(m_device);
6612 pipe.AddShader(&vs);
6613 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006614 pipe.AddColorAttachment();
6615 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006616
6617 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006618
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006619 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006620 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6621 // of PSO
6622 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6623 // cmd_pipeline.c
6624 // due to the fact that cmd_alloc_dset_data() has not been called in
6625 // cmd_bind_graphics_pipeline()
6626 // TODO : Want to cause various binding incompatibility issues here to test
6627 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006628 // First cause various verify_layout_compatibility() fails
6629 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006630 // verify_set_layout_compatibility fail cases:
6631 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6633 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6634 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006635 m_errorMonitor->VerifyFound();
6636
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006637 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6639 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6640 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006641 m_errorMonitor->VerifyFound();
6642
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006643 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006644 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6645 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6647 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6648 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006649 m_errorMonitor->VerifyFound();
6650
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006651 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6652 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6654 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6655 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006656 m_errorMonitor->VerifyFound();
6657
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006658 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6659 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6661 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6662 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6663 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006664 m_errorMonitor->VerifyFound();
6665
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006666 // Cause INFO messages due to disturbing previously bound Sets
6667 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006668 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6669 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006670 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6672 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6673 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006674 m_errorMonitor->VerifyFound();
6675
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006676 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6677 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006678 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6680 "any subsequent sets were disturbed ");
6681 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6682 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006683 m_errorMonitor->VerifyFound();
6684
Tobin Ehlis10fad692016-07-07 12:00:36 -06006685 // Now that we're done actively using the pipelineLayout that gfx pipeline
6686 // was created with, we should be able to delete it. Do that now to verify
6687 // that validation obeys pipelineLayout lifetime
6688 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6689
Tobin Ehlis88452832015-12-03 09:40:56 -07006690 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006691 // 1. Error due to not binding required set (we actually use same code as
6692 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006693 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6694 &descriptorSet[0], 0, NULL);
6695 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6696 &descriptorSet[1], 0, NULL);
6697 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 -07006698 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006699 m_errorMonitor->VerifyFound();
6700
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006701 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006702 // 2. Error due to bound set not being compatible with PSO's
6703 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006704 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6705 &descriptorSet[0], 0, NULL);
6706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006707 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006708 m_errorMonitor->VerifyFound();
6709
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006710 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006711 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006712 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6713 }
6714 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006715 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006716 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6717 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006718 vkFreeMemory(m_device->device(), imageMem, NULL);
6719 vkDestroyImage(m_device->device(), image, NULL);
6720 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006721}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006722
Karl Schultz6addd812016-02-02 17:17:23 -07006723TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006724
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6726 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006727
6728 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006729 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006730 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006731 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006732
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006733 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006734}
6735
Karl Schultz6addd812016-02-02 17:17:23 -07006736TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6737 VkResult err;
6738 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006739
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006741
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006742 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006743
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006744 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006745 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006746 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006747 cmd.commandPool = m_commandPool;
6748 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006749 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006750
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006751 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006752 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006753
6754 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006755 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006756 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006757 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006758 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006759 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 -07006760 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006761
6762 // The error should be caught by validation of the BeginCommandBuffer call
6763 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6764
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006765 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006766 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006767}
6768
Karl Schultz6addd812016-02-02 17:17:23 -07006769TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006770 // Cause error due to Begin while recording CB
6771 // Then cause 2 errors for attempting to reset CB w/o having
6772 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6773 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006775
6776 ASSERT_NO_FATAL_FAILURE(InitState());
6777
6778 // Calls AllocateCommandBuffers
6779 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6780
Karl Schultz6addd812016-02-02 17:17:23 -07006781 // Force the failure by setting the Renderpass and Framebuffer fields with
6782 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006783 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006784 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006785 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6786 cmd_buf_info.pNext = NULL;
6787 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006788 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006789
6790 // Begin CB to transition to recording state
6791 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6792 // Can't re-begin. This should trigger error
6793 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006794 m_errorMonitor->VerifyFound();
6795
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006797 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6798 // Reset attempt will trigger error due to incorrect CommandPool state
6799 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006800 m_errorMonitor->VerifyFound();
6801
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006803 // Transition CB to RECORDED state
6804 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6805 // Now attempting to Begin will implicitly reset, which triggers error
6806 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006807 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006808}
6809
Karl Schultz6addd812016-02-02 17:17:23 -07006810TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006811 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006812 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006813
Mike Weiblencce7ec72016-10-17 19:33:05 -06006814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006815
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006816 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006817 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006818
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006819 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006820 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6821 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006822
6823 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006824 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6825 ds_pool_ci.pNext = NULL;
6826 ds_pool_ci.maxSets = 1;
6827 ds_pool_ci.poolSizeCount = 1;
6828 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006829
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006830 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006831 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006832 ASSERT_VK_SUCCESS(err);
6833
Tony Barboureb254902015-07-15 12:50:33 -06006834 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006835 dsl_binding.binding = 0;
6836 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6837 dsl_binding.descriptorCount = 1;
6838 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6839 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006840
Tony Barboureb254902015-07-15 12:50:33 -06006841 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006842 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6843 ds_layout_ci.pNext = NULL;
6844 ds_layout_ci.bindingCount = 1;
6845 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006846
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006847 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006848 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006849 ASSERT_VK_SUCCESS(err);
6850
6851 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006852 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006853 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006854 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006855 alloc_info.descriptorPool = ds_pool;
6856 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006857 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006858 ASSERT_VK_SUCCESS(err);
6859
Tony Barboureb254902015-07-15 12:50:33 -06006860 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006861 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6862 pipeline_layout_ci.setLayoutCount = 1;
6863 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006864
6865 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006866 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006867 ASSERT_VK_SUCCESS(err);
6868
Tobin Ehlise68360f2015-10-01 11:15:13 -06006869 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006870 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006871
6872 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006873 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6874 vp_state_ci.scissorCount = 1;
6875 vp_state_ci.pScissors = &sc;
6876 vp_state_ci.viewportCount = 1;
6877 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006878
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006879 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6880 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6881 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6882 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6883 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6884 rs_state_ci.depthClampEnable = VK_FALSE;
6885 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6886 rs_state_ci.depthBiasEnable = VK_FALSE;
6887
Tony Barboureb254902015-07-15 12:50:33 -06006888 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006889 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6890 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006891 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006892 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6893 gp_ci.layout = pipeline_layout;
6894 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006895
6896 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006897 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6898 pc_ci.initialDataSize = 0;
6899 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006900
6901 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006902 VkPipelineCache pipelineCache;
6903
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006904 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006905 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006906 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006907
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006908 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006909
Chia-I Wuf7458c52015-10-26 21:10:41 +08006910 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6911 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6912 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6913 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006914}
Tobin Ehlis912df022015-09-17 08:46:18 -06006915/*// TODO : This test should be good, but needs Tess support in compiler to run
6916TEST_F(VkLayerTest, InvalidPatchControlPoints)
6917{
6918 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006919 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006920
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006922 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6923primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006924
Tobin Ehlis912df022015-09-17 08:46:18 -06006925 ASSERT_NO_FATAL_FAILURE(InitState());
6926 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006927
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006928 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006929 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006930 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006931
6932 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6933 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6934 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006935 ds_pool_ci.poolSizeCount = 1;
6936 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006937
6938 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006939 err = vkCreateDescriptorPool(m_device->device(),
6940VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006941 ASSERT_VK_SUCCESS(err);
6942
6943 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006944 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006945 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006946 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006947 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6948 dsl_binding.pImmutableSamplers = NULL;
6949
6950 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006951 ds_layout_ci.sType =
6952VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006953 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006954 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006955 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006956
6957 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006958 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6959&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006960 ASSERT_VK_SUCCESS(err);
6961
6962 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006963 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6964VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006965 ASSERT_VK_SUCCESS(err);
6966
6967 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006968 pipeline_layout_ci.sType =
6969VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006970 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006971 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006972 pipeline_layout_ci.pSetLayouts = &ds_layout;
6973
6974 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006975 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6976&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006977 ASSERT_VK_SUCCESS(err);
6978
6979 VkPipelineShaderStageCreateInfo shaderStages[3];
6980 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6981
Karl Schultz6addd812016-02-02 17:17:23 -07006982 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6983this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006984 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006985 VkShaderObj
6986tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6987this);
6988 VkShaderObj
6989te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6990this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006991
Karl Schultz6addd812016-02-02 17:17:23 -07006992 shaderStages[0].sType =
6993VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006994 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006995 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006996 shaderStages[1].sType =
6997VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006998 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006999 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007000 shaderStages[2].sType =
7001VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007002 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007003 shaderStages[2].shader = te.handle();
7004
7005 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007006 iaCI.sType =
7007VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007008 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007009
7010 VkPipelineTessellationStateCreateInfo tsCI = {};
7011 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7012 tsCI.patchControlPoints = 0; // This will cause an error
7013
7014 VkGraphicsPipelineCreateInfo gp_ci = {};
7015 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7016 gp_ci.pNext = NULL;
7017 gp_ci.stageCount = 3;
7018 gp_ci.pStages = shaderStages;
7019 gp_ci.pVertexInputState = NULL;
7020 gp_ci.pInputAssemblyState = &iaCI;
7021 gp_ci.pTessellationState = &tsCI;
7022 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007023 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007024 gp_ci.pMultisampleState = NULL;
7025 gp_ci.pDepthStencilState = NULL;
7026 gp_ci.pColorBlendState = NULL;
7027 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7028 gp_ci.layout = pipeline_layout;
7029 gp_ci.renderPass = renderPass();
7030
7031 VkPipelineCacheCreateInfo pc_ci = {};
7032 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7033 pc_ci.pNext = NULL;
7034 pc_ci.initialSize = 0;
7035 pc_ci.initialData = 0;
7036 pc_ci.maxSize = 0;
7037
7038 VkPipeline pipeline;
7039 VkPipelineCache pipelineCache;
7040
Karl Schultz6addd812016-02-02 17:17:23 -07007041 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7042&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007043 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007044 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7045&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007046
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007047 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007048
Chia-I Wuf7458c52015-10-26 21:10:41 +08007049 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7050 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7051 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7052 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007053}
7054*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06007055// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07007056TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007057 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007058
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7060 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007061
Tobin Ehlise68360f2015-10-01 11:15:13 -06007062 ASSERT_NO_FATAL_FAILURE(InitState());
7063 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007064
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007065 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007066 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7067 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007068
7069 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007070 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7071 ds_pool_ci.maxSets = 1;
7072 ds_pool_ci.poolSizeCount = 1;
7073 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007074
7075 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007076 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007077 ASSERT_VK_SUCCESS(err);
7078
7079 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007080 dsl_binding.binding = 0;
7081 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7082 dsl_binding.descriptorCount = 1;
7083 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007084
7085 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007086 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7087 ds_layout_ci.bindingCount = 1;
7088 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007089
7090 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007091 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007092 ASSERT_VK_SUCCESS(err);
7093
7094 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007095 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007096 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007097 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007098 alloc_info.descriptorPool = ds_pool;
7099 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007100 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007101 ASSERT_VK_SUCCESS(err);
7102
7103 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007104 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7105 pipeline_layout_ci.setLayoutCount = 1;
7106 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007107
7108 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007109 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007110 ASSERT_VK_SUCCESS(err);
7111
7112 VkViewport vp = {}; // Just need dummy vp to point to
7113
7114 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007115 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7116 vp_state_ci.scissorCount = 0;
7117 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7118 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007119
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007120 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7121 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7122 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7123 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7124 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7125 rs_state_ci.depthClampEnable = VK_FALSE;
7126 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7127 rs_state_ci.depthBiasEnable = VK_FALSE;
7128
Cody Northropeb3a6c12015-10-05 14:44:45 -06007129 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007130 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007131
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007132 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7133 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7134 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007135 shaderStages[0] = vs.GetStageCreateInfo();
7136 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007137
7138 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007139 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7140 gp_ci.stageCount = 2;
7141 gp_ci.pStages = shaderStages;
7142 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007143 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007144 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7145 gp_ci.layout = pipeline_layout;
7146 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007147
7148 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007149 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007150
7151 VkPipeline pipeline;
7152 VkPipelineCache pipelineCache;
7153
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007154 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007155 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007156 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007157
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007158 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007159
Chia-I Wuf7458c52015-10-26 21:10:41 +08007160 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7161 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7162 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7163 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007164}
Karl Schultz6addd812016-02-02 17:17:23 -07007165// Don't set viewport state in PSO. This is an error b/c we always need this
7166// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007167// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007168TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007169 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007170 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007171
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007173
Tobin Ehlise68360f2015-10-01 11:15:13 -06007174 ASSERT_NO_FATAL_FAILURE(InitState());
7175 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007176
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007177 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007178 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7179 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007180
7181 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007182 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7183 ds_pool_ci.maxSets = 1;
7184 ds_pool_ci.poolSizeCount = 1;
7185 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007186
7187 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007188 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007189 ASSERT_VK_SUCCESS(err);
7190
7191 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007192 dsl_binding.binding = 0;
7193 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7194 dsl_binding.descriptorCount = 1;
7195 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007196
7197 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007198 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7199 ds_layout_ci.bindingCount = 1;
7200 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007201
7202 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007203 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007204 ASSERT_VK_SUCCESS(err);
7205
7206 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007207 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007208 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007209 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007210 alloc_info.descriptorPool = ds_pool;
7211 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007212 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007213 ASSERT_VK_SUCCESS(err);
7214
7215 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007216 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7217 pipeline_layout_ci.setLayoutCount = 1;
7218 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007219
7220 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007221 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007222 ASSERT_VK_SUCCESS(err);
7223
7224 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7225 // Set scissor as dynamic to avoid second error
7226 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007227 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7228 dyn_state_ci.dynamicStateCount = 1;
7229 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007230
Cody Northropeb3a6c12015-10-05 14:44:45 -06007231 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007232 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007233
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007234 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7235 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7236 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007237 shaderStages[0] = vs.GetStageCreateInfo();
7238 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007239
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007240 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7241 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7242 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7243 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7244 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7245 rs_state_ci.depthClampEnable = VK_FALSE;
7246 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7247 rs_state_ci.depthBiasEnable = VK_FALSE;
7248
Tobin Ehlise68360f2015-10-01 11:15:13 -06007249 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007250 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7251 gp_ci.stageCount = 2;
7252 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007253 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007254 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7255 // should cause validation error
7256 gp_ci.pDynamicState = &dyn_state_ci;
7257 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7258 gp_ci.layout = pipeline_layout;
7259 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007260
7261 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007262 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007263
7264 VkPipeline pipeline;
7265 VkPipelineCache pipelineCache;
7266
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007267 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007268 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007269 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007270
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007271 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007272
Chia-I Wuf7458c52015-10-26 21:10:41 +08007273 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7274 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7275 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7276 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007277}
7278// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007279// Then run second test where dynamic scissor count doesn't match PSO scissor
7280// count
7281TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7282 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007283
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7285 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007286
Tobin Ehlise68360f2015-10-01 11:15:13 -06007287 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007288
7289 if (!m_device->phy().features().multiViewport) {
7290 printf("Device does not support multiple viewports/scissors; skipped.\n");
7291 return;
7292 }
7293
Tobin Ehlise68360f2015-10-01 11:15:13 -06007294 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007295
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007296 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007297 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7298 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007299
7300 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007301 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7302 ds_pool_ci.maxSets = 1;
7303 ds_pool_ci.poolSizeCount = 1;
7304 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007305
7306 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007307 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007308 ASSERT_VK_SUCCESS(err);
7309
7310 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007311 dsl_binding.binding = 0;
7312 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7313 dsl_binding.descriptorCount = 1;
7314 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007315
7316 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007317 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7318 ds_layout_ci.bindingCount = 1;
7319 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007320
7321 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007322 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007323 ASSERT_VK_SUCCESS(err);
7324
7325 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007326 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007327 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007328 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007329 alloc_info.descriptorPool = ds_pool;
7330 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007331 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007332 ASSERT_VK_SUCCESS(err);
7333
7334 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007335 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7336 pipeline_layout_ci.setLayoutCount = 1;
7337 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007338
7339 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007340 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007341 ASSERT_VK_SUCCESS(err);
7342
7343 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007344 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7345 vp_state_ci.viewportCount = 1;
7346 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7347 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007348 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007349
7350 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7351 // Set scissor as dynamic to avoid that error
7352 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007353 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7354 dyn_state_ci.dynamicStateCount = 1;
7355 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007356
Cody Northropeb3a6c12015-10-05 14:44:45 -06007357 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007358 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007359
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007360 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7361 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7362 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007363 shaderStages[0] = vs.GetStageCreateInfo();
7364 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007365
Cody Northropf6622dc2015-10-06 10:33:21 -06007366 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7367 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7368 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007369 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007370 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007371 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007372 vi_ci.pVertexAttributeDescriptions = nullptr;
7373
7374 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7375 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7376 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7377
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007378 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007379 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007380 rs_ci.pNext = nullptr;
7381
Mark Youngc89c6312016-03-31 16:03:20 -06007382 VkPipelineColorBlendAttachmentState att = {};
7383 att.blendEnable = VK_FALSE;
7384 att.colorWriteMask = 0xf;
7385
Cody Northropf6622dc2015-10-06 10:33:21 -06007386 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7387 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7388 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007389 cb_ci.attachmentCount = 1;
7390 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007391
Tobin Ehlise68360f2015-10-01 11:15:13 -06007392 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007393 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7394 gp_ci.stageCount = 2;
7395 gp_ci.pStages = shaderStages;
7396 gp_ci.pVertexInputState = &vi_ci;
7397 gp_ci.pInputAssemblyState = &ia_ci;
7398 gp_ci.pViewportState = &vp_state_ci;
7399 gp_ci.pRasterizationState = &rs_ci;
7400 gp_ci.pColorBlendState = &cb_ci;
7401 gp_ci.pDynamicState = &dyn_state_ci;
7402 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7403 gp_ci.layout = pipeline_layout;
7404 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007405
7406 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007407 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007408
7409 VkPipeline pipeline;
7410 VkPipelineCache pipelineCache;
7411
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007412 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007413 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007414 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007415
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007416 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007417
Tobin Ehlisd332f282015-10-02 11:00:56 -06007418 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007419 // First need to successfully create the PSO from above by setting
7420 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007421 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 -07007422
7423 VkViewport vp = {}; // Just need dummy vp to point to
7424 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007425 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007426 ASSERT_VK_SUCCESS(err);
7427 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007428 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007429 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007430 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007431 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007432 Draw(1, 0, 0, 0);
7433
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007434 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007435
7436 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7437 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7438 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7439 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007440 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007441}
7442// Create PSO w/o non-zero scissorCount but no scissor data
7443// Then run second test where dynamic viewportCount doesn't match PSO
7444// viewportCount
7445TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7446 VkResult err;
7447
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007448 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 -07007449
7450 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007451
7452 if (!m_device->phy().features().multiViewport) {
7453 printf("Device does not support multiple viewports/scissors; skipped.\n");
7454 return;
7455 }
7456
Karl Schultz6addd812016-02-02 17:17:23 -07007457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7458
7459 VkDescriptorPoolSize ds_type_count = {};
7460 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7461 ds_type_count.descriptorCount = 1;
7462
7463 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7464 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7465 ds_pool_ci.maxSets = 1;
7466 ds_pool_ci.poolSizeCount = 1;
7467 ds_pool_ci.pPoolSizes = &ds_type_count;
7468
7469 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007470 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007471 ASSERT_VK_SUCCESS(err);
7472
7473 VkDescriptorSetLayoutBinding dsl_binding = {};
7474 dsl_binding.binding = 0;
7475 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7476 dsl_binding.descriptorCount = 1;
7477 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7478
7479 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7480 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7481 ds_layout_ci.bindingCount = 1;
7482 ds_layout_ci.pBindings = &dsl_binding;
7483
7484 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007485 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007486 ASSERT_VK_SUCCESS(err);
7487
7488 VkDescriptorSet descriptorSet;
7489 VkDescriptorSetAllocateInfo alloc_info = {};
7490 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7491 alloc_info.descriptorSetCount = 1;
7492 alloc_info.descriptorPool = ds_pool;
7493 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007494 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007495 ASSERT_VK_SUCCESS(err);
7496
7497 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7498 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7499 pipeline_layout_ci.setLayoutCount = 1;
7500 pipeline_layout_ci.pSetLayouts = &ds_layout;
7501
7502 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007503 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007504 ASSERT_VK_SUCCESS(err);
7505
7506 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7507 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7508 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007509 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007510 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007511 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007512
7513 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7514 // Set scissor as dynamic to avoid that error
7515 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7516 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7517 dyn_state_ci.dynamicStateCount = 1;
7518 dyn_state_ci.pDynamicStates = &vp_state;
7519
7520 VkPipelineShaderStageCreateInfo shaderStages[2];
7521 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7522
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007523 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7524 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7525 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007526 shaderStages[0] = vs.GetStageCreateInfo();
7527 shaderStages[1] = fs.GetStageCreateInfo();
7528
7529 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7530 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7531 vi_ci.pNext = nullptr;
7532 vi_ci.vertexBindingDescriptionCount = 0;
7533 vi_ci.pVertexBindingDescriptions = nullptr;
7534 vi_ci.vertexAttributeDescriptionCount = 0;
7535 vi_ci.pVertexAttributeDescriptions = nullptr;
7536
7537 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7538 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7539 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7540
7541 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7542 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7543 rs_ci.pNext = nullptr;
7544
Mark Youngc89c6312016-03-31 16:03:20 -06007545 VkPipelineColorBlendAttachmentState att = {};
7546 att.blendEnable = VK_FALSE;
7547 att.colorWriteMask = 0xf;
7548
Karl Schultz6addd812016-02-02 17:17:23 -07007549 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7550 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7551 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007552 cb_ci.attachmentCount = 1;
7553 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007554
7555 VkGraphicsPipelineCreateInfo gp_ci = {};
7556 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7557 gp_ci.stageCount = 2;
7558 gp_ci.pStages = shaderStages;
7559 gp_ci.pVertexInputState = &vi_ci;
7560 gp_ci.pInputAssemblyState = &ia_ci;
7561 gp_ci.pViewportState = &vp_state_ci;
7562 gp_ci.pRasterizationState = &rs_ci;
7563 gp_ci.pColorBlendState = &cb_ci;
7564 gp_ci.pDynamicState = &dyn_state_ci;
7565 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7566 gp_ci.layout = pipeline_layout;
7567 gp_ci.renderPass = renderPass();
7568
7569 VkPipelineCacheCreateInfo pc_ci = {};
7570 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7571
7572 VkPipeline pipeline;
7573 VkPipelineCache pipelineCache;
7574
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007575 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007576 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007577 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007578
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007579 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007580
7581 // Now hit second fail case where we set scissor w/ different count than PSO
7582 // First need to successfully create the PSO from above by setting
7583 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007584 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 -06007585
Tobin Ehlisd332f282015-10-02 11:00:56 -06007586 VkRect2D sc = {}; // Just need dummy vp to point to
7587 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007588 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007589 ASSERT_VK_SUCCESS(err);
7590 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007591 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007592 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007593 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007594 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007595 Draw(1, 0, 0, 0);
7596
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007597 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007598
Chia-I Wuf7458c52015-10-26 21:10:41 +08007599 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7600 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7601 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7602 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007603 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007604}
7605
Mark Young7394fdd2016-03-31 14:56:43 -06007606TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7607 VkResult err;
7608
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007610
7611 ASSERT_NO_FATAL_FAILURE(InitState());
7612 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7613
7614 VkDescriptorPoolSize ds_type_count = {};
7615 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7616 ds_type_count.descriptorCount = 1;
7617
7618 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7619 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7620 ds_pool_ci.maxSets = 1;
7621 ds_pool_ci.poolSizeCount = 1;
7622 ds_pool_ci.pPoolSizes = &ds_type_count;
7623
7624 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007625 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007626 ASSERT_VK_SUCCESS(err);
7627
7628 VkDescriptorSetLayoutBinding dsl_binding = {};
7629 dsl_binding.binding = 0;
7630 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7631 dsl_binding.descriptorCount = 1;
7632 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7633
7634 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7635 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7636 ds_layout_ci.bindingCount = 1;
7637 ds_layout_ci.pBindings = &dsl_binding;
7638
7639 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007640 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007641 ASSERT_VK_SUCCESS(err);
7642
7643 VkDescriptorSet descriptorSet;
7644 VkDescriptorSetAllocateInfo alloc_info = {};
7645 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7646 alloc_info.descriptorSetCount = 1;
7647 alloc_info.descriptorPool = ds_pool;
7648 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007649 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007650 ASSERT_VK_SUCCESS(err);
7651
7652 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7653 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7654 pipeline_layout_ci.setLayoutCount = 1;
7655 pipeline_layout_ci.pSetLayouts = &ds_layout;
7656
7657 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007658 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007659 ASSERT_VK_SUCCESS(err);
7660
7661 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7662 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7663 vp_state_ci.scissorCount = 1;
7664 vp_state_ci.pScissors = NULL;
7665 vp_state_ci.viewportCount = 1;
7666 vp_state_ci.pViewports = NULL;
7667
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007668 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007669 // Set scissor as dynamic to avoid that error
7670 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7671 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7672 dyn_state_ci.dynamicStateCount = 2;
7673 dyn_state_ci.pDynamicStates = dynamic_states;
7674
7675 VkPipelineShaderStageCreateInfo shaderStages[2];
7676 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7677
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007678 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7679 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007680 this); // TODO - We shouldn't need a fragment shader
7681 // but add it to be able to run on more devices
7682 shaderStages[0] = vs.GetStageCreateInfo();
7683 shaderStages[1] = fs.GetStageCreateInfo();
7684
7685 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7686 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7687 vi_ci.pNext = nullptr;
7688 vi_ci.vertexBindingDescriptionCount = 0;
7689 vi_ci.pVertexBindingDescriptions = nullptr;
7690 vi_ci.vertexAttributeDescriptionCount = 0;
7691 vi_ci.pVertexAttributeDescriptions = nullptr;
7692
7693 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7694 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7695 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7696
7697 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7698 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7699 rs_ci.pNext = nullptr;
7700
Mark Young47107952016-05-02 15:59:55 -06007701 // Check too low (line width of -1.0f).
7702 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007703
7704 VkPipelineColorBlendAttachmentState att = {};
7705 att.blendEnable = VK_FALSE;
7706 att.colorWriteMask = 0xf;
7707
7708 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7709 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7710 cb_ci.pNext = nullptr;
7711 cb_ci.attachmentCount = 1;
7712 cb_ci.pAttachments = &att;
7713
7714 VkGraphicsPipelineCreateInfo gp_ci = {};
7715 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7716 gp_ci.stageCount = 2;
7717 gp_ci.pStages = shaderStages;
7718 gp_ci.pVertexInputState = &vi_ci;
7719 gp_ci.pInputAssemblyState = &ia_ci;
7720 gp_ci.pViewportState = &vp_state_ci;
7721 gp_ci.pRasterizationState = &rs_ci;
7722 gp_ci.pColorBlendState = &cb_ci;
7723 gp_ci.pDynamicState = &dyn_state_ci;
7724 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7725 gp_ci.layout = pipeline_layout;
7726 gp_ci.renderPass = renderPass();
7727
7728 VkPipelineCacheCreateInfo pc_ci = {};
7729 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7730
7731 VkPipeline pipeline;
7732 VkPipelineCache pipelineCache;
7733
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007734 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007735 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007736 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007737
7738 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007739 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007740
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007742
7743 // Check too high (line width of 65536.0f).
7744 rs_ci.lineWidth = 65536.0f;
7745
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007746 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007747 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007748 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007749
7750 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007751 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007752
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007754
7755 dyn_state_ci.dynamicStateCount = 3;
7756
7757 rs_ci.lineWidth = 1.0f;
7758
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007759 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007760 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007761 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007762 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007763 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007764
7765 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007766 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007767 m_errorMonitor->VerifyFound();
7768
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007770
7771 // Check too high with dynamic setting.
7772 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7773 m_errorMonitor->VerifyFound();
7774 EndCommandBuffer();
7775
7776 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7777 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7778 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7779 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007780 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007781}
7782
Karl Schultz6addd812016-02-02 17:17:23 -07007783TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007784 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7786 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007787
7788 ASSERT_NO_FATAL_FAILURE(InitState());
7789 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007790
Tony Barbourfe3351b2015-07-28 10:17:20 -06007791 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007792 // Don't care about RenderPass handle b/c error should be flagged before
7793 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007794 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007795
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007796 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007797}
7798
Karl Schultz6addd812016-02-02 17:17:23 -07007799TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007800 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7802 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007803
7804 ASSERT_NO_FATAL_FAILURE(InitState());
7805 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007806
Tony Barbourfe3351b2015-07-28 10:17:20 -06007807 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007808 // Just create a dummy Renderpass that's non-NULL so we can get to the
7809 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007810 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007811
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007812 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007813}
7814
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007815TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7816 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7817 "the number of renderPass attachments that use loadOp"
7818 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7819
7820 ASSERT_NO_FATAL_FAILURE(InitState());
7821 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7822
7823 // Create a renderPass with a single attachment that uses loadOp CLEAR
7824 VkAttachmentReference attach = {};
7825 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7826 VkSubpassDescription subpass = {};
7827 subpass.inputAttachmentCount = 1;
7828 subpass.pInputAttachments = &attach;
7829 VkRenderPassCreateInfo rpci = {};
7830 rpci.subpassCount = 1;
7831 rpci.pSubpasses = &subpass;
7832 rpci.attachmentCount = 1;
7833 VkAttachmentDescription attach_desc = {};
7834 attach_desc.format = VK_FORMAT_UNDEFINED;
7835 // Set loadOp to CLEAR
7836 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7837 rpci.pAttachments = &attach_desc;
7838 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7839 VkRenderPass rp;
7840 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7841
7842 VkCommandBufferInheritanceInfo hinfo = {};
7843 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7844 hinfo.renderPass = VK_NULL_HANDLE;
7845 hinfo.subpass = 0;
7846 hinfo.framebuffer = VK_NULL_HANDLE;
7847 hinfo.occlusionQueryEnable = VK_FALSE;
7848 hinfo.queryFlags = 0;
7849 hinfo.pipelineStatistics = 0;
7850 VkCommandBufferBeginInfo info = {};
7851 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7852 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7853 info.pInheritanceInfo = &hinfo;
7854
7855 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7856 VkRenderPassBeginInfo rp_begin = {};
7857 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7858 rp_begin.pNext = NULL;
7859 rp_begin.renderPass = renderPass();
7860 rp_begin.framebuffer = framebuffer();
7861 rp_begin.clearValueCount = 0; // Should be 1
7862
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7864 "there must be at least 1 entries in "
7865 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007866
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007867 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007868
7869 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007870
7871 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007872}
7873
Cody Northrop3bb4d962016-05-09 16:15:57 -06007874TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7875
7876 TEST_DESCRIPTION("End a command buffer with an active render pass");
7877
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7879 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007880
7881 ASSERT_NO_FATAL_FAILURE(InitState());
7882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7883
7884 // The framework's BeginCommandBuffer calls CreateRenderPass
7885 BeginCommandBuffer();
7886
7887 // Call directly into vkEndCommandBuffer instead of the
7888 // the framework's EndCommandBuffer, which inserts a
7889 // vkEndRenderPass
7890 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7891
7892 m_errorMonitor->VerifyFound();
7893
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007894 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7895 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007896}
7897
Karl Schultz6addd812016-02-02 17:17:23 -07007898TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007899 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7901 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007902
7903 ASSERT_NO_FATAL_FAILURE(InitState());
7904 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007905
7906 // Renderpass is started here
7907 BeginCommandBuffer();
7908
7909 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007910 vk_testing::Buffer dstBuffer;
7911 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007912
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007913 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007914
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007915 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007916}
7917
Karl Schultz6addd812016-02-02 17:17:23 -07007918TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007919 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7921 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007922
7923 ASSERT_NO_FATAL_FAILURE(InitState());
7924 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007925
7926 // Renderpass is started here
7927 BeginCommandBuffer();
7928
7929 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007930 vk_testing::Buffer dstBuffer;
7931 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007932
Karl Schultz6addd812016-02-02 17:17:23 -07007933 VkDeviceSize dstOffset = 0;
7934 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007935 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007936
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007937 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007938
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007939 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007940}
7941
Karl Schultz6addd812016-02-02 17:17:23 -07007942TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007943 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7945 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007946
7947 ASSERT_NO_FATAL_FAILURE(InitState());
7948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007949
7950 // Renderpass is started here
7951 BeginCommandBuffer();
7952
Michael Lentine0a369f62016-02-03 16:51:46 -06007953 VkClearColorValue clear_color;
7954 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007955 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7956 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7957 const int32_t tex_width = 32;
7958 const int32_t tex_height = 32;
7959 VkImageCreateInfo image_create_info = {};
7960 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7961 image_create_info.pNext = NULL;
7962 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7963 image_create_info.format = tex_format;
7964 image_create_info.extent.width = tex_width;
7965 image_create_info.extent.height = tex_height;
7966 image_create_info.extent.depth = 1;
7967 image_create_info.mipLevels = 1;
7968 image_create_info.arrayLayers = 1;
7969 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7970 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7971 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007972
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007973 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007974 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007975
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007976 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007977
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007978 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007979
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007980 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007981}
7982
Karl Schultz6addd812016-02-02 17:17:23 -07007983TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007984 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7986 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007987
7988 ASSERT_NO_FATAL_FAILURE(InitState());
7989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007990
7991 // Renderpass is started here
7992 BeginCommandBuffer();
7993
7994 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007995 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007996 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7997 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7998 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7999 image_create_info.extent.width = 64;
8000 image_create_info.extent.height = 64;
8001 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8002 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008003
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008004 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008005 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008006
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008007 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008008
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008009 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8010 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008011
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008012 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008013}
8014
Karl Schultz6addd812016-02-02 17:17:23 -07008015TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008016 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008017 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008018
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8020 "must be issued inside an active "
8021 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008022
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008023 ASSERT_NO_FATAL_FAILURE(InitState());
8024 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008025
8026 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008027 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008028 ASSERT_VK_SUCCESS(err);
8029
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008030 VkClearAttachment color_attachment;
8031 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8032 color_attachment.clearValue.color.float32[0] = 0;
8033 color_attachment.clearValue.color.float32[1] = 0;
8034 color_attachment.clearValue.color.float32[2] = 0;
8035 color_attachment.clearValue.color.float32[3] = 0;
8036 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008037 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008038 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008039
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008040 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008041}
8042
Chris Forbes3b97e932016-09-07 11:29:24 +12008043TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8044 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8045 "called too many times in a renderpass instance");
8046
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8048 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008049
8050 ASSERT_NO_FATAL_FAILURE(InitState());
8051 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8052
8053 BeginCommandBuffer();
8054
8055 // error here.
8056 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8057 m_errorMonitor->VerifyFound();
8058
8059 EndCommandBuffer();
8060}
8061
Chris Forbes6d624702016-09-07 13:57:05 +12008062TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8063 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8064 "called before the final subpass has been reached");
8065
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8067 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008068
8069 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008070 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8071 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008072
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008073 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008074
8075 VkRenderPass rp;
8076 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8077 ASSERT_VK_SUCCESS(err);
8078
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008079 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008080
8081 VkFramebuffer fb;
8082 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8083 ASSERT_VK_SUCCESS(err);
8084
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008085 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008086
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008087 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 +12008088
8089 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8090
8091 // Error here.
8092 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8093 m_errorMonitor->VerifyFound();
8094
8095 // Clean up.
8096 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8097 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8098}
8099
Karl Schultz9e66a292016-04-21 15:57:51 -06008100TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8101 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8103 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008104
8105 ASSERT_NO_FATAL_FAILURE(InitState());
8106 BeginCommandBuffer();
8107
8108 VkBufferMemoryBarrier buf_barrier = {};
8109 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8110 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8111 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8112 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8113 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8114 buf_barrier.buffer = VK_NULL_HANDLE;
8115 buf_barrier.offset = 0;
8116 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008117 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8118 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008119
8120 m_errorMonitor->VerifyFound();
8121}
8122
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008123TEST_F(VkLayerTest, InvalidBarriers) {
8124 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8125
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008127
8128 ASSERT_NO_FATAL_FAILURE(InitState());
8129 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8130
8131 VkMemoryBarrier mem_barrier = {};
8132 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8133 mem_barrier.pNext = NULL;
8134 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8135 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8136 BeginCommandBuffer();
8137 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008138 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008139 &mem_barrier, 0, nullptr, 0, nullptr);
8140 m_errorMonitor->VerifyFound();
8141
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008143 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008144 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 -06008145 ASSERT_TRUE(image.initialized());
8146 VkImageMemoryBarrier img_barrier = {};
8147 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8148 img_barrier.pNext = NULL;
8149 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8150 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8151 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8152 // New layout can't be UNDEFINED
8153 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8154 img_barrier.image = image.handle();
8155 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8156 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8157 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8158 img_barrier.subresourceRange.baseArrayLayer = 0;
8159 img_barrier.subresourceRange.baseMipLevel = 0;
8160 img_barrier.subresourceRange.layerCount = 1;
8161 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008162 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8163 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008164 m_errorMonitor->VerifyFound();
8165 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8166
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8168 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008169 // baseArrayLayer + layerCount must be <= image's arrayLayers
8170 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008171 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8172 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008173 m_errorMonitor->VerifyFound();
8174 img_barrier.subresourceRange.baseArrayLayer = 0;
8175
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008177 // baseMipLevel + levelCount must be <= image's mipLevels
8178 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008179 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8180 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008181 m_errorMonitor->VerifyFound();
8182 img_barrier.subresourceRange.baseMipLevel = 0;
8183
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008184 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 -06008185 vk_testing::Buffer buffer;
8186 buffer.init(*m_device, 256);
8187 VkBufferMemoryBarrier buf_barrier = {};
8188 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8189 buf_barrier.pNext = NULL;
8190 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8191 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8192 buf_barrier.buffer = buffer.handle();
8193 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8194 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8195 buf_barrier.offset = 0;
8196 buf_barrier.size = VK_WHOLE_SIZE;
8197 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008198 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8199 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008200 m_errorMonitor->VerifyFound();
8201 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8202
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008204 buf_barrier.offset = 257;
8205 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008206 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8207 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008208 m_errorMonitor->VerifyFound();
8209 buf_barrier.offset = 0;
8210
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008212 buf_barrier.size = 257;
8213 // Size greater than total size
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, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008216 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008217
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008218 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008219 m_errorMonitor->SetDesiredFailureMsg(
8220 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8221 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8222 m_errorMonitor->SetDesiredFailureMsg(
8223 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8224 "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 -06008225 VkDepthStencilObj ds_image(m_device);
8226 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8227 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008228 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8229 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008230 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008231 // Use of COLOR aspect on DS image is error
8232 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008233 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8234 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008235 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008236 // Now test depth-only
8237 VkFormatProperties format_props;
8238
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008239 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8240 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8242 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8244 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008245 VkDepthStencilObj d_image(m_device);
8246 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8247 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008248 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008249 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008250 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008251 // Use of COLOR aspect on depth image is error
8252 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008253 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8254 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008255 m_errorMonitor->VerifyFound();
8256 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008257 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8258 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008259 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8261 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008262 VkDepthStencilObj s_image(m_device);
8263 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8264 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008265 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008266 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008267 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008268 // Use of COLOR aspect on depth image is error
8269 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008270 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8271 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008272 m_errorMonitor->VerifyFound();
8273 }
8274 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8276 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8278 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008279 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008280 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 -06008281 ASSERT_TRUE(c_image.initialized());
8282 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8283 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8284 img_barrier.image = c_image.handle();
8285 // Set aspect to depth (non-color)
8286 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008287 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8288 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008289 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008290}
8291
Tony Barbour18ba25c2016-09-29 13:42:40 -06008292TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8293 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8294
8295 m_errorMonitor->SetDesiredFailureMsg(
8296 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8297 "must have required access bit");
8298 ASSERT_NO_FATAL_FAILURE(InitState());
8299 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008300 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 -06008301 ASSERT_TRUE(image.initialized());
8302
8303 VkImageMemoryBarrier barrier = {};
8304 VkImageSubresourceRange range;
8305 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8306 barrier.srcAccessMask = 0;
8307 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8308 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8309 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8310 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8311 barrier.image = image.handle();
8312 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8313 range.baseMipLevel = 0;
8314 range.levelCount = 1;
8315 range.baseArrayLayer = 0;
8316 range.layerCount = 1;
8317 barrier.subresourceRange = range;
8318 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8319 cmdbuf.BeginCommandBuffer();
8320 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8321 &barrier);
8322 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8323 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8324 barrier.srcAccessMask = 0;
8325 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8326 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8327 &barrier);
8328
8329 m_errorMonitor->VerifyFound();
8330}
8331
Karl Schultz6addd812016-02-02 17:17:23 -07008332TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008333 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008334 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008335
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008337
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008338 ASSERT_NO_FATAL_FAILURE(InitState());
8339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008340 uint32_t qfi = 0;
8341 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008342 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8343 buffCI.size = 1024;
8344 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8345 buffCI.queueFamilyIndexCount = 1;
8346 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008347
8348 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008349 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008350 ASSERT_VK_SUCCESS(err);
8351
8352 BeginCommandBuffer();
8353 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008354 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8355 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008356 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008357 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008358
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008359 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008360
Chia-I Wuf7458c52015-10-26 21:10:41 +08008361 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008362}
8363
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008364TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8365 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8367 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8368 "of the indices specified when the device was created, via the "
8369 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008370
8371 ASSERT_NO_FATAL_FAILURE(InitState());
8372 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8373 VkBufferCreateInfo buffCI = {};
8374 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8375 buffCI.size = 1024;
8376 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8377 buffCI.queueFamilyIndexCount = 1;
8378 // Introduce failure by specifying invalid queue_family_index
8379 uint32_t qfi = 777;
8380 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008381 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008382
8383 VkBuffer ib;
8384 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8385
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008386 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008387 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008388}
8389
Karl Schultz6addd812016-02-02 17:17:23 -07008390TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008391TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008392 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008393
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008394 ASSERT_NO_FATAL_FAILURE(InitState());
8395 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008396
Chris Forbesf29a84f2016-10-06 18:39:28 +13008397 // An empty primary command buffer
8398 VkCommandBufferObj cb(m_device, m_commandPool);
8399 cb.BeginCommandBuffer();
8400 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008401
Chris Forbesf29a84f2016-10-06 18:39:28 +13008402 m_commandBuffer->BeginCommandBuffer();
8403 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8404 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008405
Chris Forbesf29a84f2016-10-06 18:39:28 +13008406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8407 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008408 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008409}
8410
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008411TEST_F(VkLayerTest, DSUsageBitsErrors) {
8412 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8413 "that do not have correct usage bits sets.");
8414 VkResult err;
8415
8416 ASSERT_NO_FATAL_FAILURE(InitState());
8417 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8418 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8419 ds_type_count[i].type = VkDescriptorType(i);
8420 ds_type_count[i].descriptorCount = 1;
8421 }
8422 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8423 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8424 ds_pool_ci.pNext = NULL;
8425 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8426 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8427 ds_pool_ci.pPoolSizes = ds_type_count;
8428
8429 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008430 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008431 ASSERT_VK_SUCCESS(err);
8432
8433 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008434 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008435 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8436 dsl_binding[i].binding = 0;
8437 dsl_binding[i].descriptorType = VkDescriptorType(i);
8438 dsl_binding[i].descriptorCount = 1;
8439 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8440 dsl_binding[i].pImmutableSamplers = NULL;
8441 }
8442
8443 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8444 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8445 ds_layout_ci.pNext = NULL;
8446 ds_layout_ci.bindingCount = 1;
8447 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8448 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8449 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008450 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008451 ASSERT_VK_SUCCESS(err);
8452 }
8453 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8454 VkDescriptorSetAllocateInfo alloc_info = {};
8455 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8456 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8457 alloc_info.descriptorPool = ds_pool;
8458 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008459 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008460 ASSERT_VK_SUCCESS(err);
8461
8462 // Create a buffer & bufferView to be used for invalid updates
8463 VkBufferCreateInfo buff_ci = {};
8464 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8465 // This usage is not valid for any descriptor type
8466 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8467 buff_ci.size = 256;
8468 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8469 VkBuffer buffer;
8470 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8471 ASSERT_VK_SUCCESS(err);
8472
8473 VkBufferViewCreateInfo buff_view_ci = {};
8474 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8475 buff_view_ci.buffer = buffer;
8476 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8477 buff_view_ci.range = VK_WHOLE_SIZE;
8478 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008479 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008480 ASSERT_VK_SUCCESS(err);
8481
8482 // Create an image to be used for invalid updates
8483 VkImageCreateInfo image_ci = {};
8484 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8485 image_ci.imageType = VK_IMAGE_TYPE_2D;
8486 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8487 image_ci.extent.width = 64;
8488 image_ci.extent.height = 64;
8489 image_ci.extent.depth = 1;
8490 image_ci.mipLevels = 1;
8491 image_ci.arrayLayers = 1;
8492 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8493 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8494 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8495 // This usage is not valid for any descriptor type
8496 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8497 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8498 VkImage image;
8499 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8500 ASSERT_VK_SUCCESS(err);
8501 // Bind memory to image
8502 VkMemoryRequirements mem_reqs;
8503 VkDeviceMemory image_mem;
8504 bool pass;
8505 VkMemoryAllocateInfo mem_alloc = {};
8506 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8507 mem_alloc.pNext = NULL;
8508 mem_alloc.allocationSize = 0;
8509 mem_alloc.memoryTypeIndex = 0;
8510 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8511 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008512 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008513 ASSERT_TRUE(pass);
8514 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8515 ASSERT_VK_SUCCESS(err);
8516 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8517 ASSERT_VK_SUCCESS(err);
8518 // Now create view for image
8519 VkImageViewCreateInfo image_view_ci = {};
8520 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8521 image_view_ci.image = image;
8522 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8523 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8524 image_view_ci.subresourceRange.layerCount = 1;
8525 image_view_ci.subresourceRange.baseArrayLayer = 0;
8526 image_view_ci.subresourceRange.levelCount = 1;
8527 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8528 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008529 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008530 ASSERT_VK_SUCCESS(err);
8531
8532 VkDescriptorBufferInfo buff_info = {};
8533 buff_info.buffer = buffer;
8534 VkDescriptorImageInfo img_info = {};
8535 img_info.imageView = image_view;
8536 VkWriteDescriptorSet descriptor_write = {};
8537 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8538 descriptor_write.dstBinding = 0;
8539 descriptor_write.descriptorCount = 1;
8540 descriptor_write.pTexelBufferView = &buff_view;
8541 descriptor_write.pBufferInfo = &buff_info;
8542 descriptor_write.pImageInfo = &img_info;
8543
8544 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008545 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8546 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8547 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8548 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8549 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8550 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8551 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8552 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8553 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8554 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8555 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008556 // Start loop at 1 as SAMPLER desc type has no usage bit error
8557 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8558 descriptor_write.descriptorType = VkDescriptorType(i);
8559 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008561
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008562 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008563
8564 m_errorMonitor->VerifyFound();
8565 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8566 }
8567 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8568 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008569 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008570 vkDestroyImageView(m_device->device(), image_view, NULL);
8571 vkDestroyBuffer(m_device->device(), buffer, NULL);
8572 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008573 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008574 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8575}
8576
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008577TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008578 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8579 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8580 "1. offset value greater than buffer size\n"
8581 "2. range value of 0\n"
8582 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008583 VkResult err;
8584
8585 ASSERT_NO_FATAL_FAILURE(InitState());
8586 VkDescriptorPoolSize ds_type_count = {};
8587 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8588 ds_type_count.descriptorCount = 1;
8589
8590 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8591 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8592 ds_pool_ci.pNext = NULL;
8593 ds_pool_ci.maxSets = 1;
8594 ds_pool_ci.poolSizeCount = 1;
8595 ds_pool_ci.pPoolSizes = &ds_type_count;
8596
8597 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008598 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008599 ASSERT_VK_SUCCESS(err);
8600
8601 // Create layout with single uniform buffer descriptor
8602 VkDescriptorSetLayoutBinding dsl_binding = {};
8603 dsl_binding.binding = 0;
8604 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8605 dsl_binding.descriptorCount = 1;
8606 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8607 dsl_binding.pImmutableSamplers = NULL;
8608
8609 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8610 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8611 ds_layout_ci.pNext = NULL;
8612 ds_layout_ci.bindingCount = 1;
8613 ds_layout_ci.pBindings = &dsl_binding;
8614 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008615 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008616 ASSERT_VK_SUCCESS(err);
8617
8618 VkDescriptorSet descriptor_set = {};
8619 VkDescriptorSetAllocateInfo alloc_info = {};
8620 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8621 alloc_info.descriptorSetCount = 1;
8622 alloc_info.descriptorPool = ds_pool;
8623 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008624 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008625 ASSERT_VK_SUCCESS(err);
8626
8627 // Create a buffer to be used for invalid updates
8628 VkBufferCreateInfo buff_ci = {};
8629 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8630 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8631 buff_ci.size = 256;
8632 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8633 VkBuffer buffer;
8634 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8635 ASSERT_VK_SUCCESS(err);
8636 // Have to bind memory to buffer before descriptor update
8637 VkMemoryAllocateInfo mem_alloc = {};
8638 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8639 mem_alloc.pNext = NULL;
8640 mem_alloc.allocationSize = 256;
8641 mem_alloc.memoryTypeIndex = 0;
8642
8643 VkMemoryRequirements mem_reqs;
8644 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008645 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008646 if (!pass) {
8647 vkDestroyBuffer(m_device->device(), buffer, NULL);
8648 return;
8649 }
8650
8651 VkDeviceMemory mem;
8652 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8653 ASSERT_VK_SUCCESS(err);
8654 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8655 ASSERT_VK_SUCCESS(err);
8656
8657 VkDescriptorBufferInfo buff_info = {};
8658 buff_info.buffer = buffer;
8659 // First make offset 1 larger than buffer size
8660 buff_info.offset = 257;
8661 buff_info.range = VK_WHOLE_SIZE;
8662 VkWriteDescriptorSet descriptor_write = {};
8663 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8664 descriptor_write.dstBinding = 0;
8665 descriptor_write.descriptorCount = 1;
8666 descriptor_write.pTexelBufferView = nullptr;
8667 descriptor_write.pBufferInfo = &buff_info;
8668 descriptor_write.pImageInfo = nullptr;
8669
8670 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8671 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008673
8674 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8675
8676 m_errorMonitor->VerifyFound();
8677 // Now cause error due to range of 0
8678 buff_info.offset = 0;
8679 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8681 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008682
8683 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8684
8685 m_errorMonitor->VerifyFound();
8686 // Now cause error due to range exceeding buffer size - offset
8687 buff_info.offset = 128;
8688 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008689 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 -06008690
8691 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8692
8693 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008694 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008695 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8696 vkDestroyBuffer(m_device->device(), buffer, NULL);
8697 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8698 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8699}
8700
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008701TEST_F(VkLayerTest, DSAspectBitsErrors) {
8702 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8703 // are set, but could expand this test to hit more cases.
8704 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8705 "that do not have correct aspect bits sets.");
8706 VkResult err;
8707
8708 ASSERT_NO_FATAL_FAILURE(InitState());
8709 VkDescriptorPoolSize ds_type_count = {};
8710 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8711 ds_type_count.descriptorCount = 1;
8712
8713 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8714 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8715 ds_pool_ci.pNext = NULL;
8716 ds_pool_ci.maxSets = 5;
8717 ds_pool_ci.poolSizeCount = 1;
8718 ds_pool_ci.pPoolSizes = &ds_type_count;
8719
8720 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008721 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008722 ASSERT_VK_SUCCESS(err);
8723
8724 VkDescriptorSetLayoutBinding dsl_binding = {};
8725 dsl_binding.binding = 0;
8726 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8727 dsl_binding.descriptorCount = 1;
8728 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8729 dsl_binding.pImmutableSamplers = NULL;
8730
8731 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8732 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8733 ds_layout_ci.pNext = NULL;
8734 ds_layout_ci.bindingCount = 1;
8735 ds_layout_ci.pBindings = &dsl_binding;
8736 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008737 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008738 ASSERT_VK_SUCCESS(err);
8739
8740 VkDescriptorSet descriptor_set = {};
8741 VkDescriptorSetAllocateInfo alloc_info = {};
8742 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8743 alloc_info.descriptorSetCount = 1;
8744 alloc_info.descriptorPool = ds_pool;
8745 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008746 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008747 ASSERT_VK_SUCCESS(err);
8748
8749 // Create an image to be used for invalid updates
8750 VkImageCreateInfo image_ci = {};
8751 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8752 image_ci.imageType = VK_IMAGE_TYPE_2D;
8753 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8754 image_ci.extent.width = 64;
8755 image_ci.extent.height = 64;
8756 image_ci.extent.depth = 1;
8757 image_ci.mipLevels = 1;
8758 image_ci.arrayLayers = 1;
8759 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8760 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8761 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8762 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8763 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8764 VkImage image;
8765 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8766 ASSERT_VK_SUCCESS(err);
8767 // Bind memory to image
8768 VkMemoryRequirements mem_reqs;
8769 VkDeviceMemory image_mem;
8770 bool pass;
8771 VkMemoryAllocateInfo mem_alloc = {};
8772 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8773 mem_alloc.pNext = NULL;
8774 mem_alloc.allocationSize = 0;
8775 mem_alloc.memoryTypeIndex = 0;
8776 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8777 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008778 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008779 ASSERT_TRUE(pass);
8780 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8781 ASSERT_VK_SUCCESS(err);
8782 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8783 ASSERT_VK_SUCCESS(err);
8784 // Now create view for image
8785 VkImageViewCreateInfo image_view_ci = {};
8786 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8787 image_view_ci.image = image;
8788 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8789 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8790 image_view_ci.subresourceRange.layerCount = 1;
8791 image_view_ci.subresourceRange.baseArrayLayer = 0;
8792 image_view_ci.subresourceRange.levelCount = 1;
8793 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008794 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008795
8796 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008797 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008798 ASSERT_VK_SUCCESS(err);
8799
8800 VkDescriptorImageInfo img_info = {};
8801 img_info.imageView = image_view;
8802 VkWriteDescriptorSet descriptor_write = {};
8803 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8804 descriptor_write.dstBinding = 0;
8805 descriptor_write.descriptorCount = 1;
8806 descriptor_write.pTexelBufferView = NULL;
8807 descriptor_write.pBufferInfo = NULL;
8808 descriptor_write.pImageInfo = &img_info;
8809 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8810 descriptor_write.dstSet = descriptor_set;
8811 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8812 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008814
8815 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8816
8817 m_errorMonitor->VerifyFound();
8818 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8819 vkDestroyImage(m_device->device(), image, NULL);
8820 vkFreeMemory(m_device->device(), image_mem, NULL);
8821 vkDestroyImageView(m_device->device(), image_view, NULL);
8822 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8823 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8824}
8825
Karl Schultz6addd812016-02-02 17:17:23 -07008826TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008827 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008828 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008829
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8831 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8832 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008833
Tobin Ehlis3b780662015-05-28 12:11:26 -06008834 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008835 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008836 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008837 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8838 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008839
8840 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008841 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8842 ds_pool_ci.pNext = NULL;
8843 ds_pool_ci.maxSets = 1;
8844 ds_pool_ci.poolSizeCount = 1;
8845 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008846
Tobin Ehlis3b780662015-05-28 12:11:26 -06008847 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008848 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008849 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008850 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008851 dsl_binding.binding = 0;
8852 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8853 dsl_binding.descriptorCount = 1;
8854 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8855 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008856
Tony Barboureb254902015-07-15 12:50:33 -06008857 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008858 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8859 ds_layout_ci.pNext = NULL;
8860 ds_layout_ci.bindingCount = 1;
8861 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008862
Tobin Ehlis3b780662015-05-28 12:11:26 -06008863 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008864 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008865 ASSERT_VK_SUCCESS(err);
8866
8867 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008868 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008869 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008870 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008871 alloc_info.descriptorPool = ds_pool;
8872 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008873 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008874 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008875
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008876 VkSamplerCreateInfo sampler_ci = {};
8877 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8878 sampler_ci.pNext = NULL;
8879 sampler_ci.magFilter = VK_FILTER_NEAREST;
8880 sampler_ci.minFilter = VK_FILTER_NEAREST;
8881 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8882 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8883 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8884 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8885 sampler_ci.mipLodBias = 1.0;
8886 sampler_ci.anisotropyEnable = VK_FALSE;
8887 sampler_ci.maxAnisotropy = 1;
8888 sampler_ci.compareEnable = VK_FALSE;
8889 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8890 sampler_ci.minLod = 1.0;
8891 sampler_ci.maxLod = 1.0;
8892 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8893 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8894 VkSampler sampler;
8895 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8896 ASSERT_VK_SUCCESS(err);
8897
8898 VkDescriptorImageInfo info = {};
8899 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008900
8901 VkWriteDescriptorSet descriptor_write;
8902 memset(&descriptor_write, 0, sizeof(descriptor_write));
8903 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008904 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008905 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008906 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008907 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008908 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008909
8910 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8911
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008912 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008913
Chia-I Wuf7458c52015-10-26 21:10:41 +08008914 vkDestroySampler(m_device->device(), sampler, NULL);
8915 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8916 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008917}
8918
Karl Schultz6addd812016-02-02 17:17:23 -07008919TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008920 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008921 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008922
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8924 " binding #0 with 1 total descriptors but update of 1 descriptors "
8925 "starting at binding offset of 0 combined with update array element "
8926 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008927
Tobin Ehlis3b780662015-05-28 12:11:26 -06008928 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008929 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008930 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008931 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8932 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008933
8934 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008935 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8936 ds_pool_ci.pNext = NULL;
8937 ds_pool_ci.maxSets = 1;
8938 ds_pool_ci.poolSizeCount = 1;
8939 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008940
Tobin Ehlis3b780662015-05-28 12:11:26 -06008941 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008942 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008943 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008944
Tony Barboureb254902015-07-15 12:50:33 -06008945 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008946 dsl_binding.binding = 0;
8947 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8948 dsl_binding.descriptorCount = 1;
8949 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8950 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008951
8952 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008953 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8954 ds_layout_ci.pNext = NULL;
8955 ds_layout_ci.bindingCount = 1;
8956 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008957
Tobin Ehlis3b780662015-05-28 12:11:26 -06008958 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008959 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008960 ASSERT_VK_SUCCESS(err);
8961
8962 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008963 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008964 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008965 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008966 alloc_info.descriptorPool = ds_pool;
8967 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008968 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008969 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008970
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008971 // Correctly update descriptor to avoid "NOT_UPDATED" error
8972 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008973 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008974 buff_info.offset = 0;
8975 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008976
8977 VkWriteDescriptorSet descriptor_write;
8978 memset(&descriptor_write, 0, sizeof(descriptor_write));
8979 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008980 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008981 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008982 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008983 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8984 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008985
8986 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8987
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008988 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008989
Chia-I Wuf7458c52015-10-26 21:10:41 +08008990 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8991 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008992}
8993
Karl Schultz6addd812016-02-02 17:17:23 -07008994TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07008995 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07008996 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008997
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07008998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008999
Tobin Ehlis3b780662015-05-28 12:11:26 -06009000 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009001 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009002 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009003 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9004 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009005
9006 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009007 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9008 ds_pool_ci.pNext = NULL;
9009 ds_pool_ci.maxSets = 1;
9010 ds_pool_ci.poolSizeCount = 1;
9011 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009012
Tobin Ehlis3b780662015-05-28 12:11:26 -06009013 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009014 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009015 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009016
Tony Barboureb254902015-07-15 12:50:33 -06009017 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009018 dsl_binding.binding = 0;
9019 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9020 dsl_binding.descriptorCount = 1;
9021 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9022 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009023
9024 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009025 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9026 ds_layout_ci.pNext = NULL;
9027 ds_layout_ci.bindingCount = 1;
9028 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009029 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009030 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009031 ASSERT_VK_SUCCESS(err);
9032
9033 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009034 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009035 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009036 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009037 alloc_info.descriptorPool = ds_pool;
9038 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009039 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009040 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009041
Tony Barboureb254902015-07-15 12:50:33 -06009042 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009043 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9044 sampler_ci.pNext = NULL;
9045 sampler_ci.magFilter = VK_FILTER_NEAREST;
9046 sampler_ci.minFilter = VK_FILTER_NEAREST;
9047 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9048 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9049 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9050 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9051 sampler_ci.mipLodBias = 1.0;
9052 sampler_ci.anisotropyEnable = VK_FALSE;
9053 sampler_ci.maxAnisotropy = 1;
9054 sampler_ci.compareEnable = VK_FALSE;
9055 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9056 sampler_ci.minLod = 1.0;
9057 sampler_ci.maxLod = 1.0;
9058 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9059 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009060
Tobin Ehlis3b780662015-05-28 12:11:26 -06009061 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009062 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009063 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009064
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009065 VkDescriptorImageInfo info = {};
9066 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009067
9068 VkWriteDescriptorSet descriptor_write;
9069 memset(&descriptor_write, 0, sizeof(descriptor_write));
9070 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009071 descriptor_write.dstSet = descriptorSet;
9072 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009073 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009074 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009075 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009076 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009077
9078 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9079
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009080 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009081
Chia-I Wuf7458c52015-10-26 21:10:41 +08009082 vkDestroySampler(m_device->device(), sampler, NULL);
9083 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9084 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009085}
9086
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009087TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9088 // Create layout w/ empty binding and attempt to update it
9089 VkResult err;
9090
9091 ASSERT_NO_FATAL_FAILURE(InitState());
9092
9093 VkDescriptorPoolSize ds_type_count = {};
9094 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9095 ds_type_count.descriptorCount = 1;
9096
9097 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9098 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9099 ds_pool_ci.pNext = NULL;
9100 ds_pool_ci.maxSets = 1;
9101 ds_pool_ci.poolSizeCount = 1;
9102 ds_pool_ci.pPoolSizes = &ds_type_count;
9103
9104 VkDescriptorPool ds_pool;
9105 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9106 ASSERT_VK_SUCCESS(err);
9107
9108 VkDescriptorSetLayoutBinding dsl_binding = {};
9109 dsl_binding.binding = 0;
9110 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9111 dsl_binding.descriptorCount = 0;
9112 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9113 dsl_binding.pImmutableSamplers = NULL;
9114
9115 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9116 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9117 ds_layout_ci.pNext = NULL;
9118 ds_layout_ci.bindingCount = 1;
9119 ds_layout_ci.pBindings = &dsl_binding;
9120 VkDescriptorSetLayout ds_layout;
9121 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9122 ASSERT_VK_SUCCESS(err);
9123
9124 VkDescriptorSet descriptor_set;
9125 VkDescriptorSetAllocateInfo alloc_info = {};
9126 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9127 alloc_info.descriptorSetCount = 1;
9128 alloc_info.descriptorPool = ds_pool;
9129 alloc_info.pSetLayouts = &ds_layout;
9130 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9131 ASSERT_VK_SUCCESS(err);
9132
9133 VkSamplerCreateInfo sampler_ci = {};
9134 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9135 sampler_ci.magFilter = VK_FILTER_NEAREST;
9136 sampler_ci.minFilter = VK_FILTER_NEAREST;
9137 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9138 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9139 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9140 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9141 sampler_ci.mipLodBias = 1.0;
9142 sampler_ci.maxAnisotropy = 1;
9143 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9144 sampler_ci.minLod = 1.0;
9145 sampler_ci.maxLod = 1.0;
9146 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9147
9148 VkSampler sampler;
9149 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9150 ASSERT_VK_SUCCESS(err);
9151
9152 VkDescriptorImageInfo info = {};
9153 info.sampler = sampler;
9154
9155 VkWriteDescriptorSet descriptor_write;
9156 memset(&descriptor_write, 0, sizeof(descriptor_write));
9157 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9158 descriptor_write.dstSet = descriptor_set;
9159 descriptor_write.dstBinding = 0;
9160 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9161 // This is the wrong type, but empty binding error will be flagged first
9162 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9163 descriptor_write.pImageInfo = &info;
9164
9165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9166 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9167 m_errorMonitor->VerifyFound();
9168
9169 vkDestroySampler(m_device->device(), sampler, NULL);
9170 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9171 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9172}
9173
Karl Schultz6addd812016-02-02 17:17:23 -07009174TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9175 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9176 // types
9177 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009178
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009179 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 -06009180
Tobin Ehlis3b780662015-05-28 12:11:26 -06009181 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009182
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009183 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009184 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9185 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009186
9187 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009188 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9189 ds_pool_ci.pNext = NULL;
9190 ds_pool_ci.maxSets = 1;
9191 ds_pool_ci.poolSizeCount = 1;
9192 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009193
Tobin Ehlis3b780662015-05-28 12:11:26 -06009194 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009195 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009196 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009197 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009198 dsl_binding.binding = 0;
9199 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9200 dsl_binding.descriptorCount = 1;
9201 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9202 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009203
Tony Barboureb254902015-07-15 12:50:33 -06009204 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009205 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9206 ds_layout_ci.pNext = NULL;
9207 ds_layout_ci.bindingCount = 1;
9208 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009209
Tobin Ehlis3b780662015-05-28 12:11:26 -06009210 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009211 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009212 ASSERT_VK_SUCCESS(err);
9213
9214 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009215 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009216 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009217 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009218 alloc_info.descriptorPool = ds_pool;
9219 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009220 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009221 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009222
Tony Barboureb254902015-07-15 12:50:33 -06009223 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009224 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9225 sampler_ci.pNext = NULL;
9226 sampler_ci.magFilter = VK_FILTER_NEAREST;
9227 sampler_ci.minFilter = VK_FILTER_NEAREST;
9228 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9229 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9230 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9231 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9232 sampler_ci.mipLodBias = 1.0;
9233 sampler_ci.anisotropyEnable = VK_FALSE;
9234 sampler_ci.maxAnisotropy = 1;
9235 sampler_ci.compareEnable = VK_FALSE;
9236 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9237 sampler_ci.minLod = 1.0;
9238 sampler_ci.maxLod = 1.0;
9239 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9240 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009241 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009242 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009243 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009244
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009245 VkDescriptorImageInfo info = {};
9246 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009247
9248 VkWriteDescriptorSet descriptor_write;
9249 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009250 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009251 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009252 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009253 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009254 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009255 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009256
9257 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9258
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009259 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009260
Chia-I Wuf7458c52015-10-26 21:10:41 +08009261 vkDestroySampler(m_device->device(), sampler, NULL);
9262 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9263 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009264}
9265
Karl Schultz6addd812016-02-02 17:17:23 -07009266TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009267 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009268 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009269
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9271 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009272
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009273 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009274 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9275 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009276 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009277 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9278 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009279
9280 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009281 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9282 ds_pool_ci.pNext = NULL;
9283 ds_pool_ci.maxSets = 1;
9284 ds_pool_ci.poolSizeCount = 1;
9285 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009286
9287 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009288 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009289 ASSERT_VK_SUCCESS(err);
9290
9291 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009292 dsl_binding.binding = 0;
9293 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9294 dsl_binding.descriptorCount = 1;
9295 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9296 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009297
9298 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009299 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9300 ds_layout_ci.pNext = NULL;
9301 ds_layout_ci.bindingCount = 1;
9302 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009303 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009304 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009305 ASSERT_VK_SUCCESS(err);
9306
9307 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009308 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009309 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009310 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009311 alloc_info.descriptorPool = ds_pool;
9312 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009313 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009314 ASSERT_VK_SUCCESS(err);
9315
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009316 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009317
9318 VkDescriptorImageInfo descriptor_info;
9319 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9320 descriptor_info.sampler = sampler;
9321
9322 VkWriteDescriptorSet descriptor_write;
9323 memset(&descriptor_write, 0, sizeof(descriptor_write));
9324 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009325 descriptor_write.dstSet = descriptorSet;
9326 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009327 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009328 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9329 descriptor_write.pImageInfo = &descriptor_info;
9330
9331 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9332
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009333 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009334
Chia-I Wuf7458c52015-10-26 21:10:41 +08009335 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9336 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009337}
9338
Karl Schultz6addd812016-02-02 17:17:23 -07009339TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9340 // Create a single combined Image/Sampler descriptor and send it an invalid
9341 // imageView
9342 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009343
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9345 "image sampler descriptor failed due "
9346 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009347
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009348 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009349 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009350 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9351 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009352
9353 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009354 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9355 ds_pool_ci.pNext = NULL;
9356 ds_pool_ci.maxSets = 1;
9357 ds_pool_ci.poolSizeCount = 1;
9358 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009359
9360 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009361 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009362 ASSERT_VK_SUCCESS(err);
9363
9364 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009365 dsl_binding.binding = 0;
9366 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9367 dsl_binding.descriptorCount = 1;
9368 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9369 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009370
9371 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009372 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9373 ds_layout_ci.pNext = NULL;
9374 ds_layout_ci.bindingCount = 1;
9375 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009376 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009377 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009378 ASSERT_VK_SUCCESS(err);
9379
9380 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009381 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009382 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009383 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009384 alloc_info.descriptorPool = ds_pool;
9385 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009386 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009387 ASSERT_VK_SUCCESS(err);
9388
9389 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009390 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9391 sampler_ci.pNext = NULL;
9392 sampler_ci.magFilter = VK_FILTER_NEAREST;
9393 sampler_ci.minFilter = VK_FILTER_NEAREST;
9394 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9395 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9396 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9397 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9398 sampler_ci.mipLodBias = 1.0;
9399 sampler_ci.anisotropyEnable = VK_FALSE;
9400 sampler_ci.maxAnisotropy = 1;
9401 sampler_ci.compareEnable = VK_FALSE;
9402 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9403 sampler_ci.minLod = 1.0;
9404 sampler_ci.maxLod = 1.0;
9405 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9406 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009407
9408 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009409 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009410 ASSERT_VK_SUCCESS(err);
9411
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009412 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009413
9414 VkDescriptorImageInfo descriptor_info;
9415 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9416 descriptor_info.sampler = sampler;
9417 descriptor_info.imageView = view;
9418
9419 VkWriteDescriptorSet descriptor_write;
9420 memset(&descriptor_write, 0, sizeof(descriptor_write));
9421 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009422 descriptor_write.dstSet = descriptorSet;
9423 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009424 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009425 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9426 descriptor_write.pImageInfo = &descriptor_info;
9427
9428 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9429
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009430 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009431
Chia-I Wuf7458c52015-10-26 21:10:41 +08009432 vkDestroySampler(m_device->device(), sampler, NULL);
9433 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9434 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009435}
9436
Karl Schultz6addd812016-02-02 17:17:23 -07009437TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9438 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9439 // into the other
9440 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009441
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9443 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9444 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009445
Tobin Ehlis04356f92015-10-27 16:35:27 -06009446 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009447 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009448 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009449 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9450 ds_type_count[0].descriptorCount = 1;
9451 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9452 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009453
9454 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009455 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9456 ds_pool_ci.pNext = NULL;
9457 ds_pool_ci.maxSets = 1;
9458 ds_pool_ci.poolSizeCount = 2;
9459 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009460
9461 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009462 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009463 ASSERT_VK_SUCCESS(err);
9464 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009465 dsl_binding[0].binding = 0;
9466 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9467 dsl_binding[0].descriptorCount = 1;
9468 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9469 dsl_binding[0].pImmutableSamplers = NULL;
9470 dsl_binding[1].binding = 1;
9471 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9472 dsl_binding[1].descriptorCount = 1;
9473 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9474 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009475
9476 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009477 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9478 ds_layout_ci.pNext = NULL;
9479 ds_layout_ci.bindingCount = 2;
9480 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009481
9482 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009483 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009484 ASSERT_VK_SUCCESS(err);
9485
9486 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009487 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009488 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009489 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009490 alloc_info.descriptorPool = ds_pool;
9491 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009492 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009493 ASSERT_VK_SUCCESS(err);
9494
9495 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009496 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9497 sampler_ci.pNext = NULL;
9498 sampler_ci.magFilter = VK_FILTER_NEAREST;
9499 sampler_ci.minFilter = VK_FILTER_NEAREST;
9500 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9501 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9502 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9503 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9504 sampler_ci.mipLodBias = 1.0;
9505 sampler_ci.anisotropyEnable = VK_FALSE;
9506 sampler_ci.maxAnisotropy = 1;
9507 sampler_ci.compareEnable = VK_FALSE;
9508 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9509 sampler_ci.minLod = 1.0;
9510 sampler_ci.maxLod = 1.0;
9511 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9512 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009513
9514 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009515 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009516 ASSERT_VK_SUCCESS(err);
9517
9518 VkDescriptorImageInfo info = {};
9519 info.sampler = sampler;
9520
9521 VkWriteDescriptorSet descriptor_write;
9522 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9523 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009524 descriptor_write.dstSet = descriptorSet;
9525 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009526 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009527 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9528 descriptor_write.pImageInfo = &info;
9529 // This write update should succeed
9530 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9531 // Now perform a copy update that fails due to type mismatch
9532 VkCopyDescriptorSet copy_ds_update;
9533 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9534 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9535 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009536 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009537 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009538 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009539 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009540 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9541
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009542 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009543 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009544 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 -06009545 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9546 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9547 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009548 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009549 copy_ds_update.dstSet = descriptorSet;
9550 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009551 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009552 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9553
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009554 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009555
Tobin Ehlis04356f92015-10-27 16:35:27 -06009556 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9558 "update array offset of 0 and update of "
9559 "5 descriptors oversteps total number "
9560 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009561
Tobin Ehlis04356f92015-10-27 16:35:27 -06009562 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9563 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9564 copy_ds_update.srcSet = descriptorSet;
9565 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009566 copy_ds_update.dstSet = descriptorSet;
9567 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009568 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009569 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9570
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009571 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009572
Chia-I Wuf7458c52015-10-26 21:10:41 +08009573 vkDestroySampler(m_device->device(), sampler, NULL);
9574 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9575 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009576}
9577
Karl Schultz6addd812016-02-02 17:17:23 -07009578TEST_F(VkLayerTest, NumSamplesMismatch) {
9579 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9580 // sampleCount
9581 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009582
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009584
Tobin Ehlis3b780662015-05-28 12:11:26 -06009585 ASSERT_NO_FATAL_FAILURE(InitState());
9586 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009587 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009588 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009589 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009590
9591 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009592 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9593 ds_pool_ci.pNext = NULL;
9594 ds_pool_ci.maxSets = 1;
9595 ds_pool_ci.poolSizeCount = 1;
9596 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009597
Tobin Ehlis3b780662015-05-28 12:11:26 -06009598 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009599 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009600 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009601
Tony Barboureb254902015-07-15 12:50:33 -06009602 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009603 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009604 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009605 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009606 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9607 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009608
Tony Barboureb254902015-07-15 12:50:33 -06009609 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9610 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9611 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009612 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009613 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009614
Tobin Ehlis3b780662015-05-28 12:11:26 -06009615 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009616 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009617 ASSERT_VK_SUCCESS(err);
9618
9619 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009620 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009621 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009622 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009623 alloc_info.descriptorPool = ds_pool;
9624 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009625 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009626 ASSERT_VK_SUCCESS(err);
9627
Tony Barboureb254902015-07-15 12:50:33 -06009628 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009629 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009630 pipe_ms_state_ci.pNext = NULL;
9631 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9632 pipe_ms_state_ci.sampleShadingEnable = 0;
9633 pipe_ms_state_ci.minSampleShading = 1.0;
9634 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009635
Tony Barboureb254902015-07-15 12:50:33 -06009636 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009637 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9638 pipeline_layout_ci.pNext = NULL;
9639 pipeline_layout_ci.setLayoutCount = 1;
9640 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009641
9642 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009643 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009644 ASSERT_VK_SUCCESS(err);
9645
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009646 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9647 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9648 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009649 VkPipelineObj pipe(m_device);
9650 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009651 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009652 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009653 pipe.SetMSAA(&pipe_ms_state_ci);
9654 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009655
Tony Barbourfe3351b2015-07-28 10:17:20 -06009656 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009657 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009658
Mark Young29927482016-05-04 14:38:51 -06009659 // Render triangle (the error should trigger on the attempt to draw).
9660 Draw(3, 1, 0, 0);
9661
9662 // Finalize recording of the command buffer
9663 EndCommandBuffer();
9664
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009665 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009666
Chia-I Wuf7458c52015-10-26 21:10:41 +08009667 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9668 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9669 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009670}
Mark Young29927482016-05-04 14:38:51 -06009671
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009672TEST_F(VkLayerTest, RenderPassIncompatible) {
9673 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9674 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009675 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009676 VkResult err;
9677
9678 ASSERT_NO_FATAL_FAILURE(InitState());
9679 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9680
9681 VkDescriptorSetLayoutBinding dsl_binding = {};
9682 dsl_binding.binding = 0;
9683 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9684 dsl_binding.descriptorCount = 1;
9685 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9686 dsl_binding.pImmutableSamplers = NULL;
9687
9688 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9689 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9690 ds_layout_ci.pNext = NULL;
9691 ds_layout_ci.bindingCount = 1;
9692 ds_layout_ci.pBindings = &dsl_binding;
9693
9694 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009695 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009696 ASSERT_VK_SUCCESS(err);
9697
9698 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9699 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9700 pipeline_layout_ci.pNext = NULL;
9701 pipeline_layout_ci.setLayoutCount = 1;
9702 pipeline_layout_ci.pSetLayouts = &ds_layout;
9703
9704 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009705 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009706 ASSERT_VK_SUCCESS(err);
9707
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009708 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9709 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9710 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009711 // Create a renderpass that will be incompatible with default renderpass
9712 VkAttachmentReference attach = {};
9713 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9714 VkAttachmentReference color_att = {};
9715 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9716 VkSubpassDescription subpass = {};
9717 subpass.inputAttachmentCount = 1;
9718 subpass.pInputAttachments = &attach;
9719 subpass.colorAttachmentCount = 1;
9720 subpass.pColorAttachments = &color_att;
9721 VkRenderPassCreateInfo rpci = {};
9722 rpci.subpassCount = 1;
9723 rpci.pSubpasses = &subpass;
9724 rpci.attachmentCount = 1;
9725 VkAttachmentDescription attach_desc = {};
9726 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009727 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9728 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009729 rpci.pAttachments = &attach_desc;
9730 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9731 VkRenderPass rp;
9732 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9733 VkPipelineObj pipe(m_device);
9734 pipe.AddShader(&vs);
9735 pipe.AddShader(&fs);
9736 pipe.AddColorAttachment();
9737 VkViewport view_port = {};
9738 m_viewports.push_back(view_port);
9739 pipe.SetViewport(m_viewports);
9740 VkRect2D rect = {};
9741 m_scissors.push_back(rect);
9742 pipe.SetScissor(m_scissors);
9743 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9744
9745 VkCommandBufferInheritanceInfo cbii = {};
9746 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9747 cbii.renderPass = rp;
9748 cbii.subpass = 0;
9749 VkCommandBufferBeginInfo cbbi = {};
9750 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9751 cbbi.pInheritanceInfo = &cbii;
9752 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9753 VkRenderPassBeginInfo rpbi = {};
9754 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9755 rpbi.framebuffer = m_framebuffer;
9756 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009757 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9758 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009759
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009761 // Render triangle (the error should trigger on the attempt to draw).
9762 Draw(3, 1, 0, 0);
9763
9764 // Finalize recording of the command buffer
9765 EndCommandBuffer();
9766
9767 m_errorMonitor->VerifyFound();
9768
9769 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9770 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9771 vkDestroyRenderPass(m_device->device(), rp, NULL);
9772}
9773
Mark Youngc89c6312016-03-31 16:03:20 -06009774TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9775 // Create Pipeline where the number of blend attachments doesn't match the
9776 // number of color attachments. In this case, we don't add any color
9777 // blend attachments even though we have a color attachment.
9778 VkResult err;
9779
9780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009781 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009782
9783 ASSERT_NO_FATAL_FAILURE(InitState());
9784 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9785 VkDescriptorPoolSize ds_type_count = {};
9786 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9787 ds_type_count.descriptorCount = 1;
9788
9789 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9790 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9791 ds_pool_ci.pNext = NULL;
9792 ds_pool_ci.maxSets = 1;
9793 ds_pool_ci.poolSizeCount = 1;
9794 ds_pool_ci.pPoolSizes = &ds_type_count;
9795
9796 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009797 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009798 ASSERT_VK_SUCCESS(err);
9799
9800 VkDescriptorSetLayoutBinding dsl_binding = {};
9801 dsl_binding.binding = 0;
9802 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9803 dsl_binding.descriptorCount = 1;
9804 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9805 dsl_binding.pImmutableSamplers = NULL;
9806
9807 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9808 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9809 ds_layout_ci.pNext = NULL;
9810 ds_layout_ci.bindingCount = 1;
9811 ds_layout_ci.pBindings = &dsl_binding;
9812
9813 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009814 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009815 ASSERT_VK_SUCCESS(err);
9816
9817 VkDescriptorSet descriptorSet;
9818 VkDescriptorSetAllocateInfo alloc_info = {};
9819 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9820 alloc_info.descriptorSetCount = 1;
9821 alloc_info.descriptorPool = ds_pool;
9822 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009823 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009824 ASSERT_VK_SUCCESS(err);
9825
9826 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009827 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009828 pipe_ms_state_ci.pNext = NULL;
9829 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9830 pipe_ms_state_ci.sampleShadingEnable = 0;
9831 pipe_ms_state_ci.minSampleShading = 1.0;
9832 pipe_ms_state_ci.pSampleMask = NULL;
9833
9834 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9835 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9836 pipeline_layout_ci.pNext = NULL;
9837 pipeline_layout_ci.setLayoutCount = 1;
9838 pipeline_layout_ci.pSetLayouts = &ds_layout;
9839
9840 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009841 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009842 ASSERT_VK_SUCCESS(err);
9843
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009844 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9845 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9846 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009847 VkPipelineObj pipe(m_device);
9848 pipe.AddShader(&vs);
9849 pipe.AddShader(&fs);
9850 pipe.SetMSAA(&pipe_ms_state_ci);
9851 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9852
9853 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009854 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009855
Mark Young29927482016-05-04 14:38:51 -06009856 // Render triangle (the error should trigger on the attempt to draw).
9857 Draw(3, 1, 0, 0);
9858
9859 // Finalize recording of the command buffer
9860 EndCommandBuffer();
9861
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009862 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009863
9864 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9865 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9866 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9867}
Mark Young29927482016-05-04 14:38:51 -06009868
Mark Muellerd4914412016-06-13 17:52:06 -06009869TEST_F(VkLayerTest, MissingClearAttachment) {
9870 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9871 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009872 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009874 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009875
9876 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9877 m_errorMonitor->VerifyFound();
9878}
9879
Karl Schultz6addd812016-02-02 17:17:23 -07009880TEST_F(VkLayerTest, ClearCmdNoDraw) {
9881 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9882 // to issuing a Draw
9883 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009886 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009887
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009888 ASSERT_NO_FATAL_FAILURE(InitState());
9889 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009890
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009891 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009892 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9893 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009894
9895 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009896 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9897 ds_pool_ci.pNext = NULL;
9898 ds_pool_ci.maxSets = 1;
9899 ds_pool_ci.poolSizeCount = 1;
9900 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009901
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009902 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009903 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009904 ASSERT_VK_SUCCESS(err);
9905
Tony Barboureb254902015-07-15 12:50:33 -06009906 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009907 dsl_binding.binding = 0;
9908 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9909 dsl_binding.descriptorCount = 1;
9910 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9911 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009912
Tony Barboureb254902015-07-15 12:50:33 -06009913 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009914 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9915 ds_layout_ci.pNext = NULL;
9916 ds_layout_ci.bindingCount = 1;
9917 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009918
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009919 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009920 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009921 ASSERT_VK_SUCCESS(err);
9922
9923 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009924 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009925 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009926 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009927 alloc_info.descriptorPool = ds_pool;
9928 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009929 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009930 ASSERT_VK_SUCCESS(err);
9931
Tony Barboureb254902015-07-15 12:50:33 -06009932 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009933 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009934 pipe_ms_state_ci.pNext = NULL;
9935 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9936 pipe_ms_state_ci.sampleShadingEnable = 0;
9937 pipe_ms_state_ci.minSampleShading = 1.0;
9938 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009939
Tony Barboureb254902015-07-15 12:50:33 -06009940 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009941 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9942 pipeline_layout_ci.pNext = NULL;
9943 pipeline_layout_ci.setLayoutCount = 1;
9944 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009945
9946 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009947 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009948 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009949
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009950 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009951 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009952 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009953 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009954
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009955 VkPipelineObj pipe(m_device);
9956 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009957 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009958 pipe.SetMSAA(&pipe_ms_state_ci);
9959 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009960
9961 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009962
Karl Schultz6addd812016-02-02 17:17:23 -07009963 // Main thing we care about for this test is that the VkImage obj we're
9964 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009965 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009966 VkClearAttachment color_attachment;
9967 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9968 color_attachment.clearValue.color.float32[0] = 1.0;
9969 color_attachment.clearValue.color.float32[1] = 1.0;
9970 color_attachment.clearValue.color.float32[2] = 1.0;
9971 color_attachment.clearValue.color.float32[3] = 1.0;
9972 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009973 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009974
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009975 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009976
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009977 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009978
Chia-I Wuf7458c52015-10-26 21:10:41 +08009979 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9980 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9981 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009982}
9983
Karl Schultz6addd812016-02-02 17:17:23 -07009984TEST_F(VkLayerTest, VtxBufferBadIndex) {
9985 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009986
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9988 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009989
Tobin Ehlis502480b2015-06-24 15:53:07 -06009990 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009991 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009992 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009993
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009994 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009995 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9996 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009997
9998 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009999 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10000 ds_pool_ci.pNext = NULL;
10001 ds_pool_ci.maxSets = 1;
10002 ds_pool_ci.poolSizeCount = 1;
10003 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010004
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010005 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010006 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010007 ASSERT_VK_SUCCESS(err);
10008
Tony Barboureb254902015-07-15 12:50:33 -060010009 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010010 dsl_binding.binding = 0;
10011 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10012 dsl_binding.descriptorCount = 1;
10013 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10014 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010015
Tony Barboureb254902015-07-15 12:50:33 -060010016 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010017 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10018 ds_layout_ci.pNext = NULL;
10019 ds_layout_ci.bindingCount = 1;
10020 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010021
Tobin Ehlis502480b2015-06-24 15:53:07 -060010022 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010023 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010024 ASSERT_VK_SUCCESS(err);
10025
10026 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010027 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010028 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010029 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010030 alloc_info.descriptorPool = ds_pool;
10031 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010032 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010033 ASSERT_VK_SUCCESS(err);
10034
Tony Barboureb254902015-07-15 12:50:33 -060010035 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010036 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010037 pipe_ms_state_ci.pNext = NULL;
10038 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10039 pipe_ms_state_ci.sampleShadingEnable = 0;
10040 pipe_ms_state_ci.minSampleShading = 1.0;
10041 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010042
Tony Barboureb254902015-07-15 12:50:33 -060010043 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010044 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10045 pipeline_layout_ci.pNext = NULL;
10046 pipeline_layout_ci.setLayoutCount = 1;
10047 pipeline_layout_ci.pSetLayouts = &ds_layout;
10048 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010049
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010050 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010051 ASSERT_VK_SUCCESS(err);
10052
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010053 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10054 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10055 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010056 VkPipelineObj pipe(m_device);
10057 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010058 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010059 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010060 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010061 pipe.SetViewport(m_viewports);
10062 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010063 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010064
10065 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010066 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010067 // Don't care about actual data, just need to get to draw to flag error
10068 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010069 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010070 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010071 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010072
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010073 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010074
Chia-I Wuf7458c52015-10-26 21:10:41 +080010075 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10076 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10077 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010078}
Mark Muellerdfe37552016-07-07 14:47:42 -060010079
Mark Mueller2ee294f2016-08-04 12:59:48 -060010080TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10081 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10082 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010083 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010084
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010085 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10086 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010087
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010088 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10089 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010090
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010091 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010092
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010094 // The following test fails with recent NVidia drivers.
10095 // By the time core_validation is reached, the NVidia
10096 // driver has sanitized the invalid condition and core_validation
10097 // is not introduced to the failure condition. This is not the case
10098 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010099 // uint32_t count = static_cast<uint32_t>(~0);
10100 // VkPhysicalDevice physical_device;
10101 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10102 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010105 float queue_priority = 0.0;
10106
10107 VkDeviceQueueCreateInfo queue_create_info = {};
10108 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10109 queue_create_info.queueCount = 1;
10110 queue_create_info.pQueuePriorities = &queue_priority;
10111 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10112
10113 VkPhysicalDeviceFeatures features = m_device->phy().features();
10114 VkDevice testDevice;
10115 VkDeviceCreateInfo device_create_info = {};
10116 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10117 device_create_info.queueCreateInfoCount = 1;
10118 device_create_info.pQueueCreateInfos = &queue_create_info;
10119 device_create_info.pEnabledFeatures = &features;
10120 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10121 m_errorMonitor->VerifyFound();
10122
10123 queue_create_info.queueFamilyIndex = 1;
10124
10125 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10126 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10127 for (unsigned i = 0; i < feature_count; i++) {
10128 if (VK_FALSE == feature_array[i]) {
10129 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010131 device_create_info.pEnabledFeatures = &features;
10132 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10133 m_errorMonitor->VerifyFound();
10134 break;
10135 }
10136 }
10137}
10138
Tobin Ehlis16edf082016-11-21 12:33:49 -070010139TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10140 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10141
10142 ASSERT_NO_FATAL_FAILURE(InitState());
10143
10144 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10145 std::vector<VkDeviceQueueCreateInfo> queue_info;
10146 queue_info.reserve(queue_props.size());
10147 std::vector<std::vector<float>> queue_priorities;
10148 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10149 VkDeviceQueueCreateInfo qi{};
10150 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10151 qi.queueFamilyIndex = i;
10152 qi.queueCount = queue_props[i].queueCount;
10153 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10154 qi.pQueuePriorities = queue_priorities[i].data();
10155 queue_info.push_back(qi);
10156 }
10157
10158 std::vector<const char *> device_extension_names;
10159
10160 VkDevice local_device;
10161 VkDeviceCreateInfo device_create_info = {};
10162 auto features = m_device->phy().features();
10163 // Intentionally disable pipeline stats
10164 features.pipelineStatisticsQuery = VK_FALSE;
10165 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10166 device_create_info.pNext = NULL;
10167 device_create_info.queueCreateInfoCount = queue_info.size();
10168 device_create_info.pQueueCreateInfos = queue_info.data();
10169 device_create_info.enabledLayerCount = 0;
10170 device_create_info.ppEnabledLayerNames = NULL;
10171 device_create_info.pEnabledFeatures = &features;
10172 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10173 ASSERT_VK_SUCCESS(err);
10174
10175 VkQueryPoolCreateInfo qpci{};
10176 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10177 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10178 qpci.queryCount = 1;
10179 VkQueryPool query_pool;
10180
10181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10182 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10183 m_errorMonitor->VerifyFound();
10184
10185 vkDestroyDevice(local_device, nullptr);
10186}
10187
Mark Mueller2ee294f2016-08-04 12:59:48 -060010188TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10189 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10190 "End a command buffer with a query still in progress.");
10191
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010192 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10193 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10194 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010195
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010196 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010197
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010199
10200 ASSERT_NO_FATAL_FAILURE(InitState());
10201
10202 VkEvent event;
10203 VkEventCreateInfo event_create_info{};
10204 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10205 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10206
Mark Mueller2ee294f2016-08-04 12:59:48 -060010207 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010208 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010209
10210 BeginCommandBuffer();
10211
10212 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010213 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 -060010214 ASSERT_TRUE(image.initialized());
10215 VkImageMemoryBarrier img_barrier = {};
10216 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10217 img_barrier.pNext = NULL;
10218 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10219 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10220 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10221 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10222 img_barrier.image = image.handle();
10223 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010224
10225 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10226 // that layer validation catches the case when it is not.
10227 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010228 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10229 img_barrier.subresourceRange.baseArrayLayer = 0;
10230 img_barrier.subresourceRange.baseMipLevel = 0;
10231 img_barrier.subresourceRange.layerCount = 1;
10232 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010233 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10234 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010235 m_errorMonitor->VerifyFound();
10236
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010238
10239 VkQueryPool query_pool;
10240 VkQueryPoolCreateInfo query_pool_create_info = {};
10241 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10242 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10243 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010244 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010245
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010246 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010247 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10248
10249 vkEndCommandBuffer(m_commandBuffer->handle());
10250 m_errorMonitor->VerifyFound();
10251
10252 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10253 vkDestroyEvent(m_device->device(), event, nullptr);
10254}
10255
Mark Muellerdfe37552016-07-07 14:47:42 -060010256TEST_F(VkLayerTest, VertexBufferInvalid) {
10257 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10258 "delete a buffer twice, use an invalid offset for each "
10259 "buffer type, and attempt to bind a null buffer");
10260
10261 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10262 "using deleted buffer ";
10263 const char *double_destroy_message = "Cannot free buffer 0x";
10264 const char *invalid_offset_message = "vkBindBufferMemory(): "
10265 "memoryOffset is 0x";
10266 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10267 "storage memoryOffset "
10268 "is 0x";
10269 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10270 "texel memoryOffset "
10271 "is 0x";
10272 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10273 "uniform memoryOffset "
10274 "is 0x";
10275 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
10276 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -060010277 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010278
10279 ASSERT_NO_FATAL_FAILURE(InitState());
10280 ASSERT_NO_FATAL_FAILURE(InitViewport());
10281 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10282
10283 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010284 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010285 pipe_ms_state_ci.pNext = NULL;
10286 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10287 pipe_ms_state_ci.sampleShadingEnable = 0;
10288 pipe_ms_state_ci.minSampleShading = 1.0;
10289 pipe_ms_state_ci.pSampleMask = nullptr;
10290
10291 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10292 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10293 VkPipelineLayout pipeline_layout;
10294
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010295 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010296 ASSERT_VK_SUCCESS(err);
10297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010298 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10299 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010300 VkPipelineObj pipe(m_device);
10301 pipe.AddShader(&vs);
10302 pipe.AddShader(&fs);
10303 pipe.AddColorAttachment();
10304 pipe.SetMSAA(&pipe_ms_state_ci);
10305 pipe.SetViewport(m_viewports);
10306 pipe.SetScissor(m_scissors);
10307 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10308
10309 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010310 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010311
10312 {
10313 // Create and bind a vertex buffer in a reduced scope, which will cause
10314 // it to be deleted upon leaving this scope
10315 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010316 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010317 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10318 draw_verticies.AddVertexInputToPipe(pipe);
10319 }
10320
10321 Draw(1, 0, 0, 0);
10322
10323 EndCommandBuffer();
10324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010326 QueueCommandBuffer(false);
10327 m_errorMonitor->VerifyFound();
10328
10329 {
10330 // Create and bind a vertex buffer in a reduced scope, and delete it
10331 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010332 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010334 buffer_test.TestDoubleDestroy();
10335 }
10336 m_errorMonitor->VerifyFound();
10337
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010338 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010339 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10341 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10342 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010343 m_errorMonitor->VerifyFound();
10344 }
10345
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010346 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10347 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010348 // Create and bind a memory buffer with an invalid offset again,
10349 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10351 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10352 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010353 m_errorMonitor->VerifyFound();
10354 }
10355
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010356 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010357 // Create and bind a memory buffer with an invalid offset again, but
10358 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10360 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10361 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010362 m_errorMonitor->VerifyFound();
10363 }
10364
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010365 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010366 // Create and bind a memory buffer with an invalid offset again, but
10367 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10369 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10370 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010371 m_errorMonitor->VerifyFound();
10372 }
10373
10374 {
10375 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10377 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10378 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010379 m_errorMonitor->VerifyFound();
10380 }
10381
10382 {
10383 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10385 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10386 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010387 }
10388 m_errorMonitor->VerifyFound();
10389
10390 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10391}
10392
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010393// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10394TEST_F(VkLayerTest, InvalidImageLayout) {
10395 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010396 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10397 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010398 // 3 in ValidateCmdBufImageLayouts
10399 // * -1 Attempt to submit cmd buf w/ deleted image
10400 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10401 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10403 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010404
10405 ASSERT_NO_FATAL_FAILURE(InitState());
10406 // Create src & dst images to use for copy operations
10407 VkImage src_image;
10408 VkImage dst_image;
10409
10410 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10411 const int32_t tex_width = 32;
10412 const int32_t tex_height = 32;
10413
10414 VkImageCreateInfo image_create_info = {};
10415 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10416 image_create_info.pNext = NULL;
10417 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10418 image_create_info.format = tex_format;
10419 image_create_info.extent.width = tex_width;
10420 image_create_info.extent.height = tex_height;
10421 image_create_info.extent.depth = 1;
10422 image_create_info.mipLevels = 1;
10423 image_create_info.arrayLayers = 4;
10424 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10425 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10426 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10427 image_create_info.flags = 0;
10428
10429 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10430 ASSERT_VK_SUCCESS(err);
10431 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10432 ASSERT_VK_SUCCESS(err);
10433
10434 BeginCommandBuffer();
10435 VkImageCopy copyRegion;
10436 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10437 copyRegion.srcSubresource.mipLevel = 0;
10438 copyRegion.srcSubresource.baseArrayLayer = 0;
10439 copyRegion.srcSubresource.layerCount = 1;
10440 copyRegion.srcOffset.x = 0;
10441 copyRegion.srcOffset.y = 0;
10442 copyRegion.srcOffset.z = 0;
10443 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10444 copyRegion.dstSubresource.mipLevel = 0;
10445 copyRegion.dstSubresource.baseArrayLayer = 0;
10446 copyRegion.dstSubresource.layerCount = 1;
10447 copyRegion.dstOffset.x = 0;
10448 copyRegion.dstOffset.y = 0;
10449 copyRegion.dstOffset.z = 0;
10450 copyRegion.extent.width = 1;
10451 copyRegion.extent.height = 1;
10452 copyRegion.extent.depth = 1;
10453 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10454 m_errorMonitor->VerifyFound();
10455 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10457 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10458 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010459 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10460 m_errorMonitor->VerifyFound();
10461 // Final src error is due to bad layout type
10462 m_errorMonitor->SetDesiredFailureMsg(
10463 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10464 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10465 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10466 m_errorMonitor->VerifyFound();
10467 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10469 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010470 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10471 m_errorMonitor->VerifyFound();
10472 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10474 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10475 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010476 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10477 m_errorMonitor->VerifyFound();
10478 m_errorMonitor->SetDesiredFailureMsg(
10479 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10480 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10481 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10482 m_errorMonitor->VerifyFound();
10483 // Now cause error due to bad image layout transition in PipelineBarrier
10484 VkImageMemoryBarrier image_barrier[1] = {};
10485 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10486 image_barrier[0].image = src_image;
10487 image_barrier[0].subresourceRange.layerCount = 2;
10488 image_barrier[0].subresourceRange.levelCount = 2;
10489 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10491 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10492 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10493 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10494 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010495 m_errorMonitor->VerifyFound();
10496
10497 // Finally some layout errors at RenderPass create time
10498 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10499 VkAttachmentReference attach = {};
10500 // perf warning for GENERAL layout w/ non-DS input attachment
10501 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10502 VkSubpassDescription subpass = {};
10503 subpass.inputAttachmentCount = 1;
10504 subpass.pInputAttachments = &attach;
10505 VkRenderPassCreateInfo rpci = {};
10506 rpci.subpassCount = 1;
10507 rpci.pSubpasses = &subpass;
10508 rpci.attachmentCount = 1;
10509 VkAttachmentDescription attach_desc = {};
10510 attach_desc.format = VK_FORMAT_UNDEFINED;
10511 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010512 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010513 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10515 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010516 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10517 m_errorMonitor->VerifyFound();
10518 // error w/ non-general layout
10519 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10520
10521 m_errorMonitor->SetDesiredFailureMsg(
10522 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10523 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10524 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10525 m_errorMonitor->VerifyFound();
10526 subpass.inputAttachmentCount = 0;
10527 subpass.colorAttachmentCount = 1;
10528 subpass.pColorAttachments = &attach;
10529 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10530 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10532 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010533 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10534 m_errorMonitor->VerifyFound();
10535 // error w/ non-color opt or GENERAL layout for color attachment
10536 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10537 m_errorMonitor->SetDesiredFailureMsg(
10538 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10539 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10540 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10541 m_errorMonitor->VerifyFound();
10542 subpass.colorAttachmentCount = 0;
10543 subpass.pDepthStencilAttachment = &attach;
10544 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10545 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10547 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010548 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10549 m_errorMonitor->VerifyFound();
10550 // error w/ non-ds opt or GENERAL layout for color attachment
10551 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10553 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10554 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010555 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10556 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010557 // For this error we need a valid renderpass so create default one
10558 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10559 attach.attachment = 0;
10560 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10561 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10562 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10563 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10564 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10565 // Can't do a CLEAR load on READ_ONLY initialLayout
10566 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10567 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10568 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10570 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10571 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010572 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10573 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010574
10575 vkDestroyImage(m_device->device(), src_image, NULL);
10576 vkDestroyImage(m_device->device(), dst_image, NULL);
10577}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010578
Tobin Ehlise0936662016-10-11 08:10:51 -060010579TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10580 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10581 VkResult err;
10582
10583 ASSERT_NO_FATAL_FAILURE(InitState());
10584
10585 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10586 VkImageTiling tiling;
10587 VkFormatProperties format_properties;
10588 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10589 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10590 tiling = VK_IMAGE_TILING_LINEAR;
10591 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10592 tiling = VK_IMAGE_TILING_OPTIMAL;
10593 } else {
10594 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10595 "skipped.\n");
10596 return;
10597 }
10598
10599 VkDescriptorPoolSize ds_type = {};
10600 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10601 ds_type.descriptorCount = 1;
10602
10603 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10604 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10605 ds_pool_ci.maxSets = 1;
10606 ds_pool_ci.poolSizeCount = 1;
10607 ds_pool_ci.pPoolSizes = &ds_type;
10608 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10609
10610 VkDescriptorPool ds_pool;
10611 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10612 ASSERT_VK_SUCCESS(err);
10613
10614 VkDescriptorSetLayoutBinding dsl_binding = {};
10615 dsl_binding.binding = 0;
10616 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10617 dsl_binding.descriptorCount = 1;
10618 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10619 dsl_binding.pImmutableSamplers = NULL;
10620
10621 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10622 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10623 ds_layout_ci.pNext = NULL;
10624 ds_layout_ci.bindingCount = 1;
10625 ds_layout_ci.pBindings = &dsl_binding;
10626
10627 VkDescriptorSetLayout ds_layout;
10628 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10629 ASSERT_VK_SUCCESS(err);
10630
10631 VkDescriptorSetAllocateInfo alloc_info = {};
10632 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10633 alloc_info.descriptorSetCount = 1;
10634 alloc_info.descriptorPool = ds_pool;
10635 alloc_info.pSetLayouts = &ds_layout;
10636 VkDescriptorSet descriptor_set;
10637 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10638 ASSERT_VK_SUCCESS(err);
10639
10640 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10641 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10642 pipeline_layout_ci.pNext = NULL;
10643 pipeline_layout_ci.setLayoutCount = 1;
10644 pipeline_layout_ci.pSetLayouts = &ds_layout;
10645 VkPipelineLayout pipeline_layout;
10646 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10647 ASSERT_VK_SUCCESS(err);
10648
10649 VkImageObj image(m_device);
10650 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10651 ASSERT_TRUE(image.initialized());
10652 VkImageView view = image.targetView(tex_format);
10653
10654 VkDescriptorImageInfo image_info = {};
10655 image_info.imageView = view;
10656 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10657
10658 VkWriteDescriptorSet descriptor_write = {};
10659 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10660 descriptor_write.dstSet = descriptor_set;
10661 descriptor_write.dstBinding = 0;
10662 descriptor_write.descriptorCount = 1;
10663 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10664 descriptor_write.pImageInfo = &image_info;
10665
10666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10667 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10668 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10669 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10670 m_errorMonitor->VerifyFound();
10671
10672 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10673 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10674 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10675 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10676}
10677
Mark Mueller93b938f2016-08-18 10:27:40 -060010678TEST_F(VkLayerTest, SimultaneousUse) {
10679 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10680 "in primary and secondary command buffers.");
10681
10682 ASSERT_NO_FATAL_FAILURE(InitState());
10683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10684
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010685 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010686 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10687 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010688
10689 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010690 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010691 command_buffer_allocate_info.commandPool = m_commandPool;
10692 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10693 command_buffer_allocate_info.commandBufferCount = 1;
10694
10695 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010696 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010697 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10698 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010699 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010700 command_buffer_inheritance_info.renderPass = m_renderPass;
10701 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10702 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010703 command_buffer_begin_info.flags =
10704 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010705 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10706
10707 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010708 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10709 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010710 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010711 vkEndCommandBuffer(secondary_command_buffer);
10712
Mark Mueller93b938f2016-08-18 10:27:40 -060010713 VkSubmitInfo submit_info = {};
10714 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10715 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010716 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010717 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010718
Mark Mueller4042b652016-09-05 22:52:21 -060010719 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010720 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10722 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010723 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010724 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10725 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010726
10727 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010728 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10729
Mark Mueller4042b652016-09-05 22:52:21 -060010730 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010731 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010732 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010733
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10735 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010736 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010737 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10738 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010739}
10740
Mark Mueller917f6bc2016-08-30 10:57:19 -060010741TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10742 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10743 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010744 "Delete objects that are inuse. Call VkQueueSubmit "
10745 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010746
10747 ASSERT_NO_FATAL_FAILURE(InitState());
10748 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10749
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010750 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10751 const char *cannot_delete_event_message = "Cannot delete event 0x";
10752 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10753 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010754
10755 BeginCommandBuffer();
10756
10757 VkEvent event;
10758 VkEventCreateInfo event_create_info = {};
10759 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10760 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010761 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010762
Mark Muellerc8d441e2016-08-23 17:36:00 -060010763 EndCommandBuffer();
10764 vkDestroyEvent(m_device->device(), event, nullptr);
10765
10766 VkSubmitInfo submit_info = {};
10767 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10768 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010769 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010771 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10772 m_errorMonitor->VerifyFound();
10773
10774 m_errorMonitor->SetDesiredFailureMsg(0, "");
10775 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10776
10777 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10778
Mark Mueller917f6bc2016-08-30 10:57:19 -060010779 VkSemaphoreCreateInfo semaphore_create_info = {};
10780 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10781 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010782 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010783 VkFenceCreateInfo fence_create_info = {};
10784 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10785 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010786 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010787
10788 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010789 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010790 descriptor_pool_type_count.descriptorCount = 1;
10791
10792 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10793 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10794 descriptor_pool_create_info.maxSets = 1;
10795 descriptor_pool_create_info.poolSizeCount = 1;
10796 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010797 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010798
10799 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010800 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010801
10802 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010803 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010804 descriptorset_layout_binding.descriptorCount = 1;
10805 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10806
10807 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010808 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010809 descriptorset_layout_create_info.bindingCount = 1;
10810 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10811
10812 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010813 ASSERT_VK_SUCCESS(
10814 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010815
10816 VkDescriptorSet descriptorset;
10817 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010818 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010819 descriptorset_allocate_info.descriptorSetCount = 1;
10820 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10821 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010822 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010823
Mark Mueller4042b652016-09-05 22:52:21 -060010824 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10825
10826 VkDescriptorBufferInfo buffer_info = {};
10827 buffer_info.buffer = buffer_test.GetBuffer();
10828 buffer_info.offset = 0;
10829 buffer_info.range = 1024;
10830
10831 VkWriteDescriptorSet write_descriptor_set = {};
10832 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10833 write_descriptor_set.dstSet = descriptorset;
10834 write_descriptor_set.descriptorCount = 1;
10835 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10836 write_descriptor_set.pBufferInfo = &buffer_info;
10837
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010838 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010839
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010840 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10841 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010842
10843 VkPipelineObj pipe(m_device);
10844 pipe.AddColorAttachment();
10845 pipe.AddShader(&vs);
10846 pipe.AddShader(&fs);
10847
10848 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010849 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010850 pipeline_layout_create_info.setLayoutCount = 1;
10851 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10852
10853 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010854 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010855
10856 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10857
Mark Muellerc8d441e2016-08-23 17:36:00 -060010858 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010859 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010860
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010861 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10862 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10863 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010864
Mark Muellerc8d441e2016-08-23 17:36:00 -060010865 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010866
Mark Mueller917f6bc2016-08-30 10:57:19 -060010867 submit_info.signalSemaphoreCount = 1;
10868 submit_info.pSignalSemaphores = &semaphore;
10869 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010870
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010872 vkDestroyEvent(m_device->device(), event, nullptr);
10873 m_errorMonitor->VerifyFound();
10874
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010876 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10877 m_errorMonitor->VerifyFound();
10878
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010880 vkDestroyFence(m_device->device(), fence, nullptr);
10881 m_errorMonitor->VerifyFound();
10882
Tobin Ehlis122207b2016-09-01 08:50:06 -070010883 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010884 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10885 vkDestroyFence(m_device->device(), fence, nullptr);
10886 vkDestroyEvent(m_device->device(), event, nullptr);
10887 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010888 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010889 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10890}
10891
Tobin Ehlis2adda372016-09-01 08:51:06 -070010892TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10893 TEST_DESCRIPTION("Delete in-use query pool.");
10894
10895 ASSERT_NO_FATAL_FAILURE(InitState());
10896 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10897
10898 VkQueryPool query_pool;
10899 VkQueryPoolCreateInfo query_pool_ci{};
10900 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10901 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10902 query_pool_ci.queryCount = 1;
10903 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10904 BeginCommandBuffer();
10905 // Reset query pool to create binding with cmd buffer
10906 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10907
10908 EndCommandBuffer();
10909
10910 VkSubmitInfo submit_info = {};
10911 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10912 submit_info.commandBufferCount = 1;
10913 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10914 // Submit cmd buffer and then destroy query pool while in-flight
10915 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10916
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010918 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10919 m_errorMonitor->VerifyFound();
10920
10921 vkQueueWaitIdle(m_device->m_queue);
10922 // Now that cmd buffer done we can safely destroy query_pool
10923 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10924}
10925
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010926TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10927 TEST_DESCRIPTION("Delete in-use pipeline.");
10928
10929 ASSERT_NO_FATAL_FAILURE(InitState());
10930 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10931
10932 // Empty pipeline layout used for binding PSO
10933 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10934 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10935 pipeline_layout_ci.setLayoutCount = 0;
10936 pipeline_layout_ci.pSetLayouts = NULL;
10937
10938 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010939 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010940 ASSERT_VK_SUCCESS(err);
10941
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010943 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010944 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10945 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010946 // Store pipeline handle so we can actually delete it before test finishes
10947 VkPipeline delete_this_pipeline;
10948 { // Scope pipeline so it will be auto-deleted
10949 VkPipelineObj pipe(m_device);
10950 pipe.AddShader(&vs);
10951 pipe.AddShader(&fs);
10952 pipe.AddColorAttachment();
10953 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10954 delete_this_pipeline = pipe.handle();
10955
10956 BeginCommandBuffer();
10957 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010958 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010959
10960 EndCommandBuffer();
10961
10962 VkSubmitInfo submit_info = {};
10963 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10964 submit_info.commandBufferCount = 1;
10965 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10966 // Submit cmd buffer and then pipeline destroyed while in-flight
10967 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10968 } // Pipeline deletion triggered here
10969 m_errorMonitor->VerifyFound();
10970 // Make sure queue finished and then actually delete pipeline
10971 vkQueueWaitIdle(m_device->m_queue);
10972 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10973 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10974}
10975
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010976TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10977 TEST_DESCRIPTION("Delete in-use imageView.");
10978
10979 ASSERT_NO_FATAL_FAILURE(InitState());
10980 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10981
10982 VkDescriptorPoolSize ds_type_count;
10983 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10984 ds_type_count.descriptorCount = 1;
10985
10986 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10987 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10988 ds_pool_ci.maxSets = 1;
10989 ds_pool_ci.poolSizeCount = 1;
10990 ds_pool_ci.pPoolSizes = &ds_type_count;
10991
10992 VkDescriptorPool ds_pool;
10993 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10994 ASSERT_VK_SUCCESS(err);
10995
10996 VkSamplerCreateInfo sampler_ci = {};
10997 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10998 sampler_ci.pNext = NULL;
10999 sampler_ci.magFilter = VK_FILTER_NEAREST;
11000 sampler_ci.minFilter = VK_FILTER_NEAREST;
11001 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11002 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11003 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11004 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11005 sampler_ci.mipLodBias = 1.0;
11006 sampler_ci.anisotropyEnable = VK_FALSE;
11007 sampler_ci.maxAnisotropy = 1;
11008 sampler_ci.compareEnable = VK_FALSE;
11009 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11010 sampler_ci.minLod = 1.0;
11011 sampler_ci.maxLod = 1.0;
11012 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11013 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11014 VkSampler sampler;
11015
11016 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11017 ASSERT_VK_SUCCESS(err);
11018
11019 VkDescriptorSetLayoutBinding layout_binding;
11020 layout_binding.binding = 0;
11021 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11022 layout_binding.descriptorCount = 1;
11023 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11024 layout_binding.pImmutableSamplers = NULL;
11025
11026 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11027 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11028 ds_layout_ci.bindingCount = 1;
11029 ds_layout_ci.pBindings = &layout_binding;
11030 VkDescriptorSetLayout ds_layout;
11031 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11032 ASSERT_VK_SUCCESS(err);
11033
11034 VkDescriptorSetAllocateInfo alloc_info = {};
11035 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11036 alloc_info.descriptorSetCount = 1;
11037 alloc_info.descriptorPool = ds_pool;
11038 alloc_info.pSetLayouts = &ds_layout;
11039 VkDescriptorSet descriptor_set;
11040 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11041 ASSERT_VK_SUCCESS(err);
11042
11043 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11044 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11045 pipeline_layout_ci.pNext = NULL;
11046 pipeline_layout_ci.setLayoutCount = 1;
11047 pipeline_layout_ci.pSetLayouts = &ds_layout;
11048
11049 VkPipelineLayout pipeline_layout;
11050 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11051 ASSERT_VK_SUCCESS(err);
11052
11053 VkImageObj image(m_device);
11054 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11055 ASSERT_TRUE(image.initialized());
11056
11057 VkImageView view;
11058 VkImageViewCreateInfo ivci = {};
11059 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11060 ivci.image = image.handle();
11061 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11062 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11063 ivci.subresourceRange.layerCount = 1;
11064 ivci.subresourceRange.baseMipLevel = 0;
11065 ivci.subresourceRange.levelCount = 1;
11066 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11067
11068 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11069 ASSERT_VK_SUCCESS(err);
11070
11071 VkDescriptorImageInfo image_info{};
11072 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11073 image_info.imageView = view;
11074 image_info.sampler = sampler;
11075
11076 VkWriteDescriptorSet descriptor_write = {};
11077 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11078 descriptor_write.dstSet = descriptor_set;
11079 descriptor_write.dstBinding = 0;
11080 descriptor_write.descriptorCount = 1;
11081 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11082 descriptor_write.pImageInfo = &image_info;
11083
11084 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11085
11086 // Create PSO to use the sampler
11087 char const *vsSource = "#version 450\n"
11088 "\n"
11089 "out gl_PerVertex { \n"
11090 " vec4 gl_Position;\n"
11091 "};\n"
11092 "void main(){\n"
11093 " gl_Position = vec4(1);\n"
11094 "}\n";
11095 char const *fsSource = "#version 450\n"
11096 "\n"
11097 "layout(set=0, binding=0) uniform sampler2D s;\n"
11098 "layout(location=0) out vec4 x;\n"
11099 "void main(){\n"
11100 " x = texture(s, vec2(1));\n"
11101 "}\n";
11102 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11103 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11104 VkPipelineObj pipe(m_device);
11105 pipe.AddShader(&vs);
11106 pipe.AddShader(&fs);
11107 pipe.AddColorAttachment();
11108 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11109
11110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
11111
11112 BeginCommandBuffer();
11113 // Bind pipeline to cmd buffer
11114 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11115 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11116 &descriptor_set, 0, nullptr);
11117 Draw(1, 0, 0, 0);
11118 EndCommandBuffer();
11119 // Submit cmd buffer then destroy sampler
11120 VkSubmitInfo submit_info = {};
11121 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11122 submit_info.commandBufferCount = 1;
11123 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11124 // Submit cmd buffer and then destroy imageView while in-flight
11125 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11126
11127 vkDestroyImageView(m_device->device(), view, nullptr);
11128 m_errorMonitor->VerifyFound();
11129 vkQueueWaitIdle(m_device->m_queue);
11130 // Now we can actually destroy imageView
11131 vkDestroyImageView(m_device->device(), view, NULL);
11132 vkDestroySampler(m_device->device(), sampler, nullptr);
11133 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11134 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11135 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11136}
11137
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011138TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11139 TEST_DESCRIPTION("Delete in-use bufferView.");
11140
11141 ASSERT_NO_FATAL_FAILURE(InitState());
11142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11143
11144 VkDescriptorPoolSize ds_type_count;
11145 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11146 ds_type_count.descriptorCount = 1;
11147
11148 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11149 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11150 ds_pool_ci.maxSets = 1;
11151 ds_pool_ci.poolSizeCount = 1;
11152 ds_pool_ci.pPoolSizes = &ds_type_count;
11153
11154 VkDescriptorPool ds_pool;
11155 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11156 ASSERT_VK_SUCCESS(err);
11157
11158 VkDescriptorSetLayoutBinding layout_binding;
11159 layout_binding.binding = 0;
11160 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11161 layout_binding.descriptorCount = 1;
11162 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11163 layout_binding.pImmutableSamplers = NULL;
11164
11165 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11166 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11167 ds_layout_ci.bindingCount = 1;
11168 ds_layout_ci.pBindings = &layout_binding;
11169 VkDescriptorSetLayout ds_layout;
11170 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11171 ASSERT_VK_SUCCESS(err);
11172
11173 VkDescriptorSetAllocateInfo alloc_info = {};
11174 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11175 alloc_info.descriptorSetCount = 1;
11176 alloc_info.descriptorPool = ds_pool;
11177 alloc_info.pSetLayouts = &ds_layout;
11178 VkDescriptorSet descriptor_set;
11179 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11180 ASSERT_VK_SUCCESS(err);
11181
11182 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11183 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11184 pipeline_layout_ci.pNext = NULL;
11185 pipeline_layout_ci.setLayoutCount = 1;
11186 pipeline_layout_ci.pSetLayouts = &ds_layout;
11187
11188 VkPipelineLayout pipeline_layout;
11189 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11190 ASSERT_VK_SUCCESS(err);
11191
11192 VkBuffer buffer;
11193 uint32_t queue_family_index = 0;
11194 VkBufferCreateInfo buffer_create_info = {};
11195 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11196 buffer_create_info.size = 1024;
11197 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11198 buffer_create_info.queueFamilyIndexCount = 1;
11199 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11200
11201 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11202 ASSERT_VK_SUCCESS(err);
11203
11204 VkMemoryRequirements memory_reqs;
11205 VkDeviceMemory buffer_memory;
11206
11207 VkMemoryAllocateInfo memory_info = {};
11208 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11209 memory_info.allocationSize = 0;
11210 memory_info.memoryTypeIndex = 0;
11211
11212 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11213 memory_info.allocationSize = memory_reqs.size;
11214 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11215 ASSERT_TRUE(pass);
11216
11217 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11218 ASSERT_VK_SUCCESS(err);
11219 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11220 ASSERT_VK_SUCCESS(err);
11221
11222 VkBufferView view;
11223 VkBufferViewCreateInfo bvci = {};
11224 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11225 bvci.buffer = buffer;
11226 bvci.format = VK_FORMAT_R8_UNORM;
11227 bvci.range = VK_WHOLE_SIZE;
11228
11229 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11230 ASSERT_VK_SUCCESS(err);
11231
11232 VkWriteDescriptorSet descriptor_write = {};
11233 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11234 descriptor_write.dstSet = descriptor_set;
11235 descriptor_write.dstBinding = 0;
11236 descriptor_write.descriptorCount = 1;
11237 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11238 descriptor_write.pTexelBufferView = &view;
11239
11240 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11241
11242 char const *vsSource = "#version 450\n"
11243 "\n"
11244 "out gl_PerVertex { \n"
11245 " vec4 gl_Position;\n"
11246 "};\n"
11247 "void main(){\n"
11248 " gl_Position = vec4(1);\n"
11249 "}\n";
11250 char const *fsSource = "#version 450\n"
11251 "\n"
11252 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11253 "layout(location=0) out vec4 x;\n"
11254 "void main(){\n"
11255 " x = imageLoad(s, 0);\n"
11256 "}\n";
11257 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11258 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11259 VkPipelineObj pipe(m_device);
11260 pipe.AddShader(&vs);
11261 pipe.AddShader(&fs);
11262 pipe.AddColorAttachment();
11263 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11264
11265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11266
11267 BeginCommandBuffer();
11268 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11269 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11270 VkRect2D scissor = {{0, 0}, {16, 16}};
11271 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11272 // Bind pipeline to cmd buffer
11273 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11274 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11275 &descriptor_set, 0, nullptr);
11276 Draw(1, 0, 0, 0);
11277 EndCommandBuffer();
11278
11279 VkSubmitInfo submit_info = {};
11280 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11281 submit_info.commandBufferCount = 1;
11282 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11283 // Submit cmd buffer and then destroy bufferView while in-flight
11284 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11285
11286 vkDestroyBufferView(m_device->device(), view, nullptr);
11287 m_errorMonitor->VerifyFound();
11288 vkQueueWaitIdle(m_device->m_queue);
11289 // Now we can actually destroy bufferView
11290 vkDestroyBufferView(m_device->device(), view, NULL);
11291 vkDestroyBuffer(m_device->device(), buffer, NULL);
11292 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11293 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11294 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11295 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11296}
11297
Tobin Ehlis209532e2016-09-07 13:52:18 -060011298TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11299 TEST_DESCRIPTION("Delete in-use sampler.");
11300
11301 ASSERT_NO_FATAL_FAILURE(InitState());
11302 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11303
11304 VkDescriptorPoolSize ds_type_count;
11305 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11306 ds_type_count.descriptorCount = 1;
11307
11308 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11309 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11310 ds_pool_ci.maxSets = 1;
11311 ds_pool_ci.poolSizeCount = 1;
11312 ds_pool_ci.pPoolSizes = &ds_type_count;
11313
11314 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011315 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011316 ASSERT_VK_SUCCESS(err);
11317
11318 VkSamplerCreateInfo sampler_ci = {};
11319 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11320 sampler_ci.pNext = NULL;
11321 sampler_ci.magFilter = VK_FILTER_NEAREST;
11322 sampler_ci.minFilter = VK_FILTER_NEAREST;
11323 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11324 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11325 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11326 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11327 sampler_ci.mipLodBias = 1.0;
11328 sampler_ci.anisotropyEnable = VK_FALSE;
11329 sampler_ci.maxAnisotropy = 1;
11330 sampler_ci.compareEnable = VK_FALSE;
11331 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11332 sampler_ci.minLod = 1.0;
11333 sampler_ci.maxLod = 1.0;
11334 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11335 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11336 VkSampler sampler;
11337
11338 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11339 ASSERT_VK_SUCCESS(err);
11340
11341 VkDescriptorSetLayoutBinding layout_binding;
11342 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011343 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011344 layout_binding.descriptorCount = 1;
11345 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11346 layout_binding.pImmutableSamplers = NULL;
11347
11348 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11349 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11350 ds_layout_ci.bindingCount = 1;
11351 ds_layout_ci.pBindings = &layout_binding;
11352 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011353 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011354 ASSERT_VK_SUCCESS(err);
11355
11356 VkDescriptorSetAllocateInfo alloc_info = {};
11357 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11358 alloc_info.descriptorSetCount = 1;
11359 alloc_info.descriptorPool = ds_pool;
11360 alloc_info.pSetLayouts = &ds_layout;
11361 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011362 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011363 ASSERT_VK_SUCCESS(err);
11364
11365 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11366 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11367 pipeline_layout_ci.pNext = NULL;
11368 pipeline_layout_ci.setLayoutCount = 1;
11369 pipeline_layout_ci.pSetLayouts = &ds_layout;
11370
11371 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011372 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011373 ASSERT_VK_SUCCESS(err);
11374
11375 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011376 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 -060011377 ASSERT_TRUE(image.initialized());
11378
11379 VkImageView view;
11380 VkImageViewCreateInfo ivci = {};
11381 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11382 ivci.image = image.handle();
11383 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11384 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11385 ivci.subresourceRange.layerCount = 1;
11386 ivci.subresourceRange.baseMipLevel = 0;
11387 ivci.subresourceRange.levelCount = 1;
11388 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11389
11390 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11391 ASSERT_VK_SUCCESS(err);
11392
11393 VkDescriptorImageInfo image_info{};
11394 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11395 image_info.imageView = view;
11396 image_info.sampler = sampler;
11397
11398 VkWriteDescriptorSet descriptor_write = {};
11399 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11400 descriptor_write.dstSet = descriptor_set;
11401 descriptor_write.dstBinding = 0;
11402 descriptor_write.descriptorCount = 1;
11403 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11404 descriptor_write.pImageInfo = &image_info;
11405
11406 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11407
11408 // Create PSO to use the sampler
11409 char const *vsSource = "#version 450\n"
11410 "\n"
11411 "out gl_PerVertex { \n"
11412 " vec4 gl_Position;\n"
11413 "};\n"
11414 "void main(){\n"
11415 " gl_Position = vec4(1);\n"
11416 "}\n";
11417 char const *fsSource = "#version 450\n"
11418 "\n"
11419 "layout(set=0, binding=0) uniform sampler2D s;\n"
11420 "layout(location=0) out vec4 x;\n"
11421 "void main(){\n"
11422 " x = texture(s, vec2(1));\n"
11423 "}\n";
11424 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11425 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11426 VkPipelineObj pipe(m_device);
11427 pipe.AddShader(&vs);
11428 pipe.AddShader(&fs);
11429 pipe.AddColorAttachment();
11430 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011433
11434 BeginCommandBuffer();
11435 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011436 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11437 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11438 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011439 Draw(1, 0, 0, 0);
11440 EndCommandBuffer();
11441 // Submit cmd buffer then destroy sampler
11442 VkSubmitInfo submit_info = {};
11443 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11444 submit_info.commandBufferCount = 1;
11445 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11446 // Submit cmd buffer and then destroy sampler while in-flight
11447 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11448
11449 vkDestroySampler(m_device->device(), sampler, nullptr);
11450 m_errorMonitor->VerifyFound();
11451 vkQueueWaitIdle(m_device->m_queue);
11452 // Now we can actually destroy sampler
11453 vkDestroySampler(m_device->device(), sampler, nullptr);
11454 vkDestroyImageView(m_device->device(), view, NULL);
11455 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11456 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11457 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11458}
11459
Mark Mueller1cd9f412016-08-25 13:23:52 -060011460TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011461 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011462 "signaled but not waited on by the queue. Wait on a "
11463 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011464
11465 ASSERT_NO_FATAL_FAILURE(InitState());
11466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11467
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011468 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11469 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11470 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011471
11472 BeginCommandBuffer();
11473 EndCommandBuffer();
11474
11475 VkSemaphoreCreateInfo semaphore_create_info = {};
11476 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11477 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011478 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011479 VkSubmitInfo submit_info = {};
11480 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11481 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011482 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011483 submit_info.signalSemaphoreCount = 1;
11484 submit_info.pSignalSemaphores = &semaphore;
11485 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11486 m_errorMonitor->SetDesiredFailureMsg(0, "");
11487 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11488 BeginCommandBuffer();
11489 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011491 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11492 m_errorMonitor->VerifyFound();
11493
Mark Mueller1cd9f412016-08-25 13:23:52 -060011494 VkFenceCreateInfo fence_create_info = {};
11495 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11496 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011497 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011498
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011500 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11501 m_errorMonitor->VerifyFound();
11502
Mark Mueller4042b652016-09-05 22:52:21 -060011503 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011504 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011505 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11506}
11507
Tobin Ehlis4af23302016-07-19 10:50:30 -060011508TEST_F(VkLayerTest, FramebufferIncompatible) {
11509 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11510 "that does not match the framebuffer for the active "
11511 "renderpass.");
11512 ASSERT_NO_FATAL_FAILURE(InitState());
11513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11514
11515 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011516 VkAttachmentDescription attachment = {0,
11517 VK_FORMAT_B8G8R8A8_UNORM,
11518 VK_SAMPLE_COUNT_1_BIT,
11519 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11520 VK_ATTACHMENT_STORE_OP_STORE,
11521 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11522 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11523 VK_IMAGE_LAYOUT_UNDEFINED,
11524 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011525
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011526 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011527
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011528 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011529
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011530 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011531
11532 VkRenderPass rp;
11533 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11534 ASSERT_VK_SUCCESS(err);
11535
11536 // A compatible framebuffer.
11537 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011538 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 -060011539 ASSERT_TRUE(image.initialized());
11540
11541 VkImageViewCreateInfo ivci = {
11542 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11543 nullptr,
11544 0,
11545 image.handle(),
11546 VK_IMAGE_VIEW_TYPE_2D,
11547 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011548 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11549 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011550 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11551 };
11552 VkImageView view;
11553 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11554 ASSERT_VK_SUCCESS(err);
11555
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011556 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011557 VkFramebuffer fb;
11558 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11559 ASSERT_VK_SUCCESS(err);
11560
11561 VkCommandBufferAllocateInfo cbai = {};
11562 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11563 cbai.commandPool = m_commandPool;
11564 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11565 cbai.commandBufferCount = 1;
11566
11567 VkCommandBuffer sec_cb;
11568 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11569 ASSERT_VK_SUCCESS(err);
11570 VkCommandBufferBeginInfo cbbi = {};
11571 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130011572 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060011573 cbii.renderPass = renderPass();
11574 cbii.framebuffer = fb;
11575 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11576 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011577 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 -060011578 cbbi.pInheritanceInfo = &cbii;
11579 vkBeginCommandBuffer(sec_cb, &cbbi);
11580 vkEndCommandBuffer(sec_cb);
11581
Chris Forbes3400bc52016-09-13 18:10:34 +120011582 VkCommandBufferBeginInfo cbbi2 = {
11583 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11584 0, nullptr
11585 };
11586 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11587 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011588
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011590 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011591 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11592 m_errorMonitor->VerifyFound();
11593 // Cleanup
11594 vkDestroyImageView(m_device->device(), view, NULL);
11595 vkDestroyRenderPass(m_device->device(), rp, NULL);
11596 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11597}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011598
11599TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11600 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11601 "invalid value. If logicOp is not available, attempt to "
11602 "use it and verify that we see the correct error.");
11603 ASSERT_NO_FATAL_FAILURE(InitState());
11604 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11605
11606 auto features = m_device->phy().features();
11607 // Set the expected error depending on whether or not logicOp available
11608 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11610 "enabled, logicOpEnable must be "
11611 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011612 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011614 }
11615 // Create a pipeline using logicOp
11616 VkResult err;
11617
11618 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11619 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11620
11621 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011622 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011623 ASSERT_VK_SUCCESS(err);
11624
11625 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11626 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11627 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011628 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011629 vp_state_ci.pViewports = &vp;
11630 vp_state_ci.scissorCount = 1;
11631 VkRect2D scissors = {}; // Dummy scissors to point to
11632 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011633
11634 VkPipelineShaderStageCreateInfo shaderStages[2];
11635 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11636
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011637 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11638 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011639 shaderStages[0] = vs.GetStageCreateInfo();
11640 shaderStages[1] = fs.GetStageCreateInfo();
11641
11642 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11643 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11644
11645 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11646 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11647 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11648
11649 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11650 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011651 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011652
11653 VkPipelineColorBlendAttachmentState att = {};
11654 att.blendEnable = VK_FALSE;
11655 att.colorWriteMask = 0xf;
11656
11657 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11658 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11659 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11660 cb_ci.logicOpEnable = VK_TRUE;
11661 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11662 cb_ci.attachmentCount = 1;
11663 cb_ci.pAttachments = &att;
11664
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011665 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11666 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11667 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11668
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011669 VkGraphicsPipelineCreateInfo gp_ci = {};
11670 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11671 gp_ci.stageCount = 2;
11672 gp_ci.pStages = shaderStages;
11673 gp_ci.pVertexInputState = &vi_ci;
11674 gp_ci.pInputAssemblyState = &ia_ci;
11675 gp_ci.pViewportState = &vp_state_ci;
11676 gp_ci.pRasterizationState = &rs_ci;
11677 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011678 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011679 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11680 gp_ci.layout = pipeline_layout;
11681 gp_ci.renderPass = renderPass();
11682
11683 VkPipelineCacheCreateInfo pc_ci = {};
11684 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11685
11686 VkPipeline pipeline;
11687 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011688 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011689 ASSERT_VK_SUCCESS(err);
11690
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011691 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011692 m_errorMonitor->VerifyFound();
11693 if (VK_SUCCESS == err) {
11694 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11695 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011696 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11697 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11698}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011699#endif // DRAW_STATE_TESTS
11700
Tobin Ehlis0788f522015-05-26 16:11:58 -060011701#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011702#if GTEST_IS_THREADSAFE
11703struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011704 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011705 VkEvent event;
11706 bool bailout;
11707};
11708
Karl Schultz6addd812016-02-02 17:17:23 -070011709extern "C" void *AddToCommandBuffer(void *arg) {
11710 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011711
Mike Stroyana6d14942016-07-13 15:10:05 -060011712 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011713 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011714 if (data->bailout) {
11715 break;
11716 }
11717 }
11718 return NULL;
11719}
11720
Karl Schultz6addd812016-02-02 17:17:23 -070011721TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011722 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011723
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011725
Mike Stroyanaccf7692015-05-12 16:00:45 -060011726 ASSERT_NO_FATAL_FAILURE(InitState());
11727 ASSERT_NO_FATAL_FAILURE(InitViewport());
11728 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11729
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011730 // Calls AllocateCommandBuffers
11731 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011732
11733 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011734 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011735
11736 VkEventCreateInfo event_info;
11737 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011738 VkResult err;
11739
11740 memset(&event_info, 0, sizeof(event_info));
11741 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11742
Chia-I Wuf7458c52015-10-26 21:10:41 +080011743 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011744 ASSERT_VK_SUCCESS(err);
11745
Mike Stroyanaccf7692015-05-12 16:00:45 -060011746 err = vkResetEvent(device(), event);
11747 ASSERT_VK_SUCCESS(err);
11748
11749 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011750 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011751 data.event = event;
11752 data.bailout = false;
11753 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011754
11755 // First do some correct operations using multiple threads.
11756 // Add many entries to command buffer from another thread.
11757 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11758 // Make non-conflicting calls from this thread at the same time.
11759 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011760 uint32_t count;
11761 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011762 }
11763 test_platform_thread_join(thread, NULL);
11764
11765 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011766 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011767 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011768 // Add many entries to command buffer from this thread at the same time.
11769 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011770
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011771 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011772 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011773
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011774 m_errorMonitor->SetBailout(NULL);
11775
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011776 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011777
Chia-I Wuf7458c52015-10-26 21:10:41 +080011778 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011779}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011780#endif // GTEST_IS_THREADSAFE
11781#endif // THREADING_TESTS
11782
Chris Forbes9f7ff632015-05-25 11:13:08 +120011783#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011784TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011785 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11786 "with an impossible code size");
11787
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011789
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011790 ASSERT_NO_FATAL_FAILURE(InitState());
11791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11792
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011793 VkShaderModule module;
11794 VkShaderModuleCreateInfo moduleCreateInfo;
11795 struct icd_spv_header spv;
11796
11797 spv.magic = ICD_SPV_MAGIC;
11798 spv.version = ICD_SPV_VERSION;
11799 spv.gen_magic = 0;
11800
11801 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11802 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011803 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011804 moduleCreateInfo.codeSize = 4;
11805 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011806 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011807
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011808 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011809}
11810
Karl Schultz6addd812016-02-02 17:17:23 -070011811TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011812 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11813 "with a bad magic number");
11814
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011816
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011817 ASSERT_NO_FATAL_FAILURE(InitState());
11818 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11819
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011820 VkShaderModule module;
11821 VkShaderModuleCreateInfo moduleCreateInfo;
11822 struct icd_spv_header spv;
11823
11824 spv.magic = ~ICD_SPV_MAGIC;
11825 spv.version = ICD_SPV_VERSION;
11826 spv.gen_magic = 0;
11827
11828 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11829 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011830 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011831 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11832 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011833 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011834
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011835 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011836}
11837
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011838#if 0
11839// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011840TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011842 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011843
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011844 ASSERT_NO_FATAL_FAILURE(InitState());
11845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11846
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011847 VkShaderModule module;
11848 VkShaderModuleCreateInfo moduleCreateInfo;
11849 struct icd_spv_header spv;
11850
11851 spv.magic = ICD_SPV_MAGIC;
11852 spv.version = ~ICD_SPV_VERSION;
11853 spv.gen_magic = 0;
11854
11855 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11856 moduleCreateInfo.pNext = NULL;
11857
Karl Schultz6addd812016-02-02 17:17:23 -070011858 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011859 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11860 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011861 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011862
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011863 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011864}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011865#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011866
Karl Schultz6addd812016-02-02 17:17:23 -070011867TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011868 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11869 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011871
Chris Forbes9f7ff632015-05-25 11:13:08 +120011872 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011873 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011874
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011875 char const *vsSource = "#version 450\n"
11876 "\n"
11877 "layout(location=0) out float x;\n"
11878 "out gl_PerVertex {\n"
11879 " vec4 gl_Position;\n"
11880 "};\n"
11881 "void main(){\n"
11882 " gl_Position = vec4(1);\n"
11883 " x = 0;\n"
11884 "}\n";
11885 char const *fsSource = "#version 450\n"
11886 "\n"
11887 "layout(location=0) out vec4 color;\n"
11888 "void main(){\n"
11889 " color = vec4(1);\n"
11890 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011891
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011892 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11893 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011894
11895 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011896 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011897 pipe.AddShader(&vs);
11898 pipe.AddShader(&fs);
11899
Chris Forbes9f7ff632015-05-25 11:13:08 +120011900 VkDescriptorSetObj descriptorSet(m_device);
11901 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011902 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011903
Tony Barbour5781e8f2015-08-04 16:23:11 -060011904 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011905
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011906 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011907}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011908
Mark Mueller098c9cb2016-09-08 09:01:57 -060011909TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11910 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11911
11912 ASSERT_NO_FATAL_FAILURE(InitState());
11913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11914
11915 const char *bad_specialization_message =
11916 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11917
11918 char const *vsSource =
11919 "#version 450\n"
11920 "\n"
11921 "out gl_PerVertex {\n"
11922 " vec4 gl_Position;\n"
11923 "};\n"
11924 "void main(){\n"
11925 " gl_Position = vec4(1);\n"
11926 "}\n";
11927
11928 char const *fsSource =
11929 "#version 450\n"
11930 "\n"
11931 "layout (constant_id = 0) const float r = 0.0f;\n"
11932 "layout(location = 0) out vec4 uFragColor;\n"
11933 "void main(){\n"
11934 " uFragColor = vec4(r,1,0,1);\n"
11935 "}\n";
11936
11937 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11938 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11939
11940 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11941 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11942
11943 VkPipelineLayout pipeline_layout;
11944 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11945
11946 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11947 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11948 vp_state_create_info.viewportCount = 1;
11949 VkViewport viewport = {};
11950 vp_state_create_info.pViewports = &viewport;
11951 vp_state_create_info.scissorCount = 1;
11952 VkRect2D scissors = {};
11953 vp_state_create_info.pScissors = &scissors;
11954
11955 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11956
11957 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11958 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11959 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11960 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11961
11962 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11963 vs.GetStageCreateInfo(),
11964 fs.GetStageCreateInfo()
11965 };
11966
11967 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11968 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11969
11970 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11971 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11972 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11973
11974 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11975 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11976 rasterization_state_create_info.pNext = nullptr;
11977 rasterization_state_create_info.lineWidth = 1.0f;
11978 rasterization_state_create_info.rasterizerDiscardEnable = true;
11979
11980 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11981 color_blend_attachment_state.blendEnable = VK_FALSE;
11982 color_blend_attachment_state.colorWriteMask = 0xf;
11983
11984 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11985 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11986 color_blend_state_create_info.attachmentCount = 1;
11987 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11988
11989 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11990 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11991 graphicspipe_create_info.stageCount = 2;
11992 graphicspipe_create_info.pStages = shader_stage_create_info;
11993 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11994 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11995 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11996 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11997 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11998 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11999 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12000 graphicspipe_create_info.layout = pipeline_layout;
12001 graphicspipe_create_info.renderPass = renderPass();
12002
12003 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12004 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12005
12006 VkPipelineCache pipelineCache;
12007 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12008
12009 // This structure maps constant ids to data locations.
12010 const VkSpecializationMapEntry entry =
12011 // id, offset, size
12012 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12013
12014 uint32_t data = 1;
12015
12016 // Set up the info describing spec map and data
12017 const VkSpecializationInfo specialization_info = {
12018 1,
12019 &entry,
12020 1 * sizeof(float),
12021 &data,
12022 };
12023 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12024
12025 VkPipeline pipeline;
12026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12027 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12028 m_errorMonitor->VerifyFound();
12029
12030 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12031 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12032}
12033
12034TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12035 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12036
12037 ASSERT_NO_FATAL_FAILURE(InitState());
12038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12039
12040 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12041
12042 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12043 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12044 descriptor_pool_type_count[0].descriptorCount = 1;
12045 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12046 descriptor_pool_type_count[1].descriptorCount = 1;
12047
12048 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12049 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12050 descriptor_pool_create_info.maxSets = 1;
12051 descriptor_pool_create_info.poolSizeCount = 2;
12052 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12053 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12054
12055 VkDescriptorPool descriptorset_pool;
12056 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12057
12058 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12059 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12060 descriptorset_layout_binding.descriptorCount = 1;
12061 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12062
12063 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12064 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12065 descriptorset_layout_create_info.bindingCount = 1;
12066 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12067
12068 VkDescriptorSetLayout descriptorset_layout;
12069 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12070
12071 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12072 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12073 descriptorset_allocate_info.descriptorSetCount = 1;
12074 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12075 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12076 VkDescriptorSet descriptorset;
12077 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12078
12079 // Challenge core_validation with a non uniform buffer type.
12080 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12081
Mark Mueller098c9cb2016-09-08 09:01:57 -060012082 char const *vsSource =
12083 "#version 450\n"
12084 "\n"
12085 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12086 " mat4 mvp;\n"
12087 "} ubuf;\n"
12088 "out gl_PerVertex {\n"
12089 " vec4 gl_Position;\n"
12090 "};\n"
12091 "void main(){\n"
12092 " gl_Position = ubuf.mvp * vec4(1);\n"
12093 "}\n";
12094
12095 char const *fsSource =
12096 "#version 450\n"
12097 "\n"
12098 "layout(location = 0) out vec4 uFragColor;\n"
12099 "void main(){\n"
12100 " uFragColor = vec4(0,1,0,1);\n"
12101 "}\n";
12102
12103 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12104 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12105
12106 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12107 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12108 pipeline_layout_create_info.setLayoutCount = 1;
12109 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12110
12111 VkPipelineLayout pipeline_layout;
12112 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12113
12114 VkPipelineObj pipe(m_device);
12115 pipe.AddColorAttachment();
12116 pipe.AddShader(&vs);
12117 pipe.AddShader(&fs);
12118
12119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12120 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12121 m_errorMonitor->VerifyFound();
12122
12123 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12124 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12125 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12126}
12127
12128TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12129 TEST_DESCRIPTION(
12130 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12131
12132 ASSERT_NO_FATAL_FAILURE(InitState());
12133 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12134
12135 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12136
12137 VkDescriptorPoolSize descriptor_pool_type_count = {};
12138 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12139 descriptor_pool_type_count.descriptorCount = 1;
12140
12141 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12142 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12143 descriptor_pool_create_info.maxSets = 1;
12144 descriptor_pool_create_info.poolSizeCount = 1;
12145 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12146 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12147
12148 VkDescriptorPool descriptorset_pool;
12149 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12150
12151 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12152 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12153 descriptorset_layout_binding.descriptorCount = 1;
12154 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12155 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12156
12157 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12158 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12159 descriptorset_layout_create_info.bindingCount = 1;
12160 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12161
12162 VkDescriptorSetLayout descriptorset_layout;
12163 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12164 nullptr, &descriptorset_layout));
12165
12166 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12167 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12168 descriptorset_allocate_info.descriptorSetCount = 1;
12169 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12170 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12171 VkDescriptorSet descriptorset;
12172 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12173
12174 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12175
Mark Mueller098c9cb2016-09-08 09:01:57 -060012176 char const *vsSource =
12177 "#version 450\n"
12178 "\n"
12179 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12180 " mat4 mvp;\n"
12181 "} ubuf;\n"
12182 "out gl_PerVertex {\n"
12183 " vec4 gl_Position;\n"
12184 "};\n"
12185 "void main(){\n"
12186 " gl_Position = ubuf.mvp * vec4(1);\n"
12187 "}\n";
12188
12189 char const *fsSource =
12190 "#version 450\n"
12191 "\n"
12192 "layout(location = 0) out vec4 uFragColor;\n"
12193 "void main(){\n"
12194 " uFragColor = vec4(0,1,0,1);\n"
12195 "}\n";
12196
12197 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12198 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12199
12200 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12201 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12202 pipeline_layout_create_info.setLayoutCount = 1;
12203 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12204
12205 VkPipelineLayout pipeline_layout;
12206 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12207
12208 VkPipelineObj pipe(m_device);
12209 pipe.AddColorAttachment();
12210 pipe.AddShader(&vs);
12211 pipe.AddShader(&fs);
12212
12213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12214 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12215 m_errorMonitor->VerifyFound();
12216
12217 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12218 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12219 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12220}
12221
12222TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12223 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12224 "accessible from the current shader stage.");
12225
12226 ASSERT_NO_FATAL_FAILURE(InitState());
12227 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12228
12229 const char *push_constant_not_accessible_message =
12230 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12231
12232 char const *vsSource =
12233 "#version 450\n"
12234 "\n"
12235 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12236 "out gl_PerVertex {\n"
12237 " vec4 gl_Position;\n"
12238 "};\n"
12239 "void main(){\n"
12240 " gl_Position = vec4(consts.x);\n"
12241 "}\n";
12242
12243 char const *fsSource =
12244 "#version 450\n"
12245 "\n"
12246 "layout(location = 0) out vec4 uFragColor;\n"
12247 "void main(){\n"
12248 " uFragColor = vec4(0,1,0,1);\n"
12249 "}\n";
12250
12251 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12252 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12253
12254 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12255 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12256
12257 // Set up a push constant range
12258 VkPushConstantRange push_constant_ranges = {};
12259 // Set to the wrong stage to challenge core_validation
12260 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12261 push_constant_ranges.size = 4;
12262
12263 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12264 pipeline_layout_create_info.pushConstantRangeCount = 1;
12265
12266 VkPipelineLayout pipeline_layout;
12267 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12268
12269 VkPipelineObj pipe(m_device);
12270 pipe.AddColorAttachment();
12271 pipe.AddShader(&vs);
12272 pipe.AddShader(&fs);
12273
12274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12275 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12276 m_errorMonitor->VerifyFound();
12277
12278 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12279}
12280
12281TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12282 TEST_DESCRIPTION(
12283 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12284
12285 ASSERT_NO_FATAL_FAILURE(InitState());
12286 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12287
12288 const char *feature_not_enabled_message =
12289 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12290
12291 // Some awkward steps are required to test with custom device features.
12292 std::vector<const char *> device_extension_names;
12293 auto features = m_device->phy().features();
12294 // Disable support for 64 bit floats
12295 features.shaderFloat64 = false;
12296 // The sacrificial device object
12297 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12298
12299 char const *vsSource = "#version 450\n"
12300 "\n"
12301 "out gl_PerVertex {\n"
12302 " vec4 gl_Position;\n"
12303 "};\n"
12304 "void main(){\n"
12305 " gl_Position = vec4(1);\n"
12306 "}\n";
12307 char const *fsSource = "#version 450\n"
12308 "\n"
12309 "layout(location=0) out vec4 color;\n"
12310 "void main(){\n"
12311 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12312 " color = vec4(green);\n"
12313 "}\n";
12314
12315 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12316 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12317
12318 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012319
12320 VkPipelineObj pipe(&test_device);
12321 pipe.AddColorAttachment();
12322 pipe.AddShader(&vs);
12323 pipe.AddShader(&fs);
12324
12325 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12326 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12327 VkPipelineLayout pipeline_layout;
12328 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12329
12330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12331 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12332 m_errorMonitor->VerifyFound();
12333
12334 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12335}
12336
12337TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12338 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12339
12340 ASSERT_NO_FATAL_FAILURE(InitState());
12341 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12342
12343 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12344
12345 char const *vsSource = "#version 450\n"
12346 "\n"
12347 "out gl_PerVertex {\n"
12348 " vec4 gl_Position;\n"
12349 "};\n"
12350 "layout(xfb_buffer = 1) out;"
12351 "void main(){\n"
12352 " gl_Position = vec4(1);\n"
12353 "}\n";
12354 char const *fsSource = "#version 450\n"
12355 "\n"
12356 "layout(location=0) out vec4 color;\n"
12357 "void main(){\n"
12358 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12359 " color = vec4(green);\n"
12360 "}\n";
12361
12362 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12363 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12364
12365 VkPipelineObj pipe(m_device);
12366 pipe.AddColorAttachment();
12367 pipe.AddShader(&vs);
12368 pipe.AddShader(&fs);
12369
12370 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12371 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12372 VkPipelineLayout pipeline_layout;
12373 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12374
12375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12376 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12377 m_errorMonitor->VerifyFound();
12378
12379 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12380}
12381
Karl Schultz6addd812016-02-02 17:17:23 -070012382TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012383 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12384 "which is not present in the outputs of the previous stage");
12385
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012387
Chris Forbes59cb88d2015-05-25 11:13:13 +120012388 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012389 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012390
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012391 char const *vsSource = "#version 450\n"
12392 "\n"
12393 "out gl_PerVertex {\n"
12394 " vec4 gl_Position;\n"
12395 "};\n"
12396 "void main(){\n"
12397 " gl_Position = vec4(1);\n"
12398 "}\n";
12399 char const *fsSource = "#version 450\n"
12400 "\n"
12401 "layout(location=0) in float x;\n"
12402 "layout(location=0) out vec4 color;\n"
12403 "void main(){\n"
12404 " color = vec4(x);\n"
12405 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012406
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012407 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12408 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012409
12410 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012411 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012412 pipe.AddShader(&vs);
12413 pipe.AddShader(&fs);
12414
Chris Forbes59cb88d2015-05-25 11:13:13 +120012415 VkDescriptorSetObj descriptorSet(m_device);
12416 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012417 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012418
Tony Barbour5781e8f2015-08-04 16:23:11 -060012419 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012420
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012421 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012422}
12423
Karl Schultz6addd812016-02-02 17:17:23 -070012424TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012425 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12426 "within an interace block, which is not present in the outputs "
12427 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012429
12430 ASSERT_NO_FATAL_FAILURE(InitState());
12431 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12432
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012433 char const *vsSource = "#version 450\n"
12434 "\n"
12435 "out gl_PerVertex {\n"
12436 " vec4 gl_Position;\n"
12437 "};\n"
12438 "void main(){\n"
12439 " gl_Position = vec4(1);\n"
12440 "}\n";
12441 char const *fsSource = "#version 450\n"
12442 "\n"
12443 "in block { layout(location=0) float x; } ins;\n"
12444 "layout(location=0) out vec4 color;\n"
12445 "void main(){\n"
12446 " color = vec4(ins.x);\n"
12447 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012448
12449 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12450 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12451
12452 VkPipelineObj pipe(m_device);
12453 pipe.AddColorAttachment();
12454 pipe.AddShader(&vs);
12455 pipe.AddShader(&fs);
12456
12457 VkDescriptorSetObj descriptorSet(m_device);
12458 descriptorSet.AppendDummy();
12459 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12460
12461 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12462
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012463 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012464}
12465
Karl Schultz6addd812016-02-02 17:17:23 -070012466TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012467 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012468 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12470 "output arr[2] of float32' vs 'ptr to "
12471 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012472
12473 ASSERT_NO_FATAL_FAILURE(InitState());
12474 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12475
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012476 char const *vsSource = "#version 450\n"
12477 "\n"
12478 "layout(location=0) out float x[2];\n"
12479 "out gl_PerVertex {\n"
12480 " vec4 gl_Position;\n"
12481 "};\n"
12482 "void main(){\n"
12483 " x[0] = 0; x[1] = 0;\n"
12484 " gl_Position = vec4(1);\n"
12485 "}\n";
12486 char const *fsSource = "#version 450\n"
12487 "\n"
12488 "layout(location=0) in float x[3];\n"
12489 "layout(location=0) out vec4 color;\n"
12490 "void main(){\n"
12491 " color = vec4(x[0] + x[1] + x[2]);\n"
12492 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012493
12494 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12495 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12496
12497 VkPipelineObj pipe(m_device);
12498 pipe.AddColorAttachment();
12499 pipe.AddShader(&vs);
12500 pipe.AddShader(&fs);
12501
12502 VkDescriptorSetObj descriptorSet(m_device);
12503 descriptorSet.AppendDummy();
12504 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12505
12506 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12507
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012508 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012509}
12510
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012511
Karl Schultz6addd812016-02-02 17:17:23 -070012512TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012513 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012514 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012516
Chris Forbesb56af562015-05-25 11:13:17 +120012517 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012518 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012519
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012520 char const *vsSource = "#version 450\n"
12521 "\n"
12522 "layout(location=0) out int x;\n"
12523 "out gl_PerVertex {\n"
12524 " vec4 gl_Position;\n"
12525 "};\n"
12526 "void main(){\n"
12527 " x = 0;\n"
12528 " gl_Position = vec4(1);\n"
12529 "}\n";
12530 char const *fsSource = "#version 450\n"
12531 "\n"
12532 "layout(location=0) in float x;\n" /* VS writes int */
12533 "layout(location=0) out vec4 color;\n"
12534 "void main(){\n"
12535 " color = vec4(x);\n"
12536 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012537
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012538 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12539 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012540
12541 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012542 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012543 pipe.AddShader(&vs);
12544 pipe.AddShader(&fs);
12545
Chris Forbesb56af562015-05-25 11:13:17 +120012546 VkDescriptorSetObj descriptorSet(m_device);
12547 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012548 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012549
Tony Barbour5781e8f2015-08-04 16:23:11 -060012550 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012551
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012552 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012553}
12554
Karl Schultz6addd812016-02-02 17:17:23 -070012555TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012556 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012557 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012558 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012560
12561 ASSERT_NO_FATAL_FAILURE(InitState());
12562 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12563
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012564 char const *vsSource = "#version 450\n"
12565 "\n"
12566 "out block { layout(location=0) int x; } outs;\n"
12567 "out gl_PerVertex {\n"
12568 " vec4 gl_Position;\n"
12569 "};\n"
12570 "void main(){\n"
12571 " outs.x = 0;\n"
12572 " gl_Position = vec4(1);\n"
12573 "}\n";
12574 char const *fsSource = "#version 450\n"
12575 "\n"
12576 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12577 "layout(location=0) out vec4 color;\n"
12578 "void main(){\n"
12579 " color = vec4(ins.x);\n"
12580 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012581
12582 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12583 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12584
12585 VkPipelineObj pipe(m_device);
12586 pipe.AddColorAttachment();
12587 pipe.AddShader(&vs);
12588 pipe.AddShader(&fs);
12589
12590 VkDescriptorSetObj descriptorSet(m_device);
12591 descriptorSet.AppendDummy();
12592 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12593
12594 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12595
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012596 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012597}
12598
12599TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012600 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012601 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012602 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012603 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 +130012604
12605 ASSERT_NO_FATAL_FAILURE(InitState());
12606 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12607
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012608 char const *vsSource = "#version 450\n"
12609 "\n"
12610 "out block { layout(location=1) float x; } outs;\n"
12611 "out gl_PerVertex {\n"
12612 " vec4 gl_Position;\n"
12613 "};\n"
12614 "void main(){\n"
12615 " outs.x = 0;\n"
12616 " gl_Position = vec4(1);\n"
12617 "}\n";
12618 char const *fsSource = "#version 450\n"
12619 "\n"
12620 "in block { layout(location=0) float x; } ins;\n"
12621 "layout(location=0) out vec4 color;\n"
12622 "void main(){\n"
12623 " color = vec4(ins.x);\n"
12624 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012625
12626 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12627 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12628
12629 VkPipelineObj pipe(m_device);
12630 pipe.AddColorAttachment();
12631 pipe.AddShader(&vs);
12632 pipe.AddShader(&fs);
12633
12634 VkDescriptorSetObj descriptorSet(m_device);
12635 descriptorSet.AppendDummy();
12636 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12637
12638 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12639
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012640 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012641}
12642
12643TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012644 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012645 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012646 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012647 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 +130012648
12649 ASSERT_NO_FATAL_FAILURE(InitState());
12650 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12651
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012652 char const *vsSource = "#version 450\n"
12653 "\n"
12654 "out block { layout(location=0, component=0) float x; } outs;\n"
12655 "out gl_PerVertex {\n"
12656 " vec4 gl_Position;\n"
12657 "};\n"
12658 "void main(){\n"
12659 " outs.x = 0;\n"
12660 " gl_Position = vec4(1);\n"
12661 "}\n";
12662 char const *fsSource = "#version 450\n"
12663 "\n"
12664 "in block { layout(location=0, component=1) float x; } ins;\n"
12665 "layout(location=0) out vec4 color;\n"
12666 "void main(){\n"
12667 " color = vec4(ins.x);\n"
12668 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012669
12670 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12671 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12672
12673 VkPipelineObj pipe(m_device);
12674 pipe.AddColorAttachment();
12675 pipe.AddShader(&vs);
12676 pipe.AddShader(&fs);
12677
12678 VkDescriptorSetObj descriptorSet(m_device);
12679 descriptorSet.AppendDummy();
12680 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12681
12682 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12683
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012684 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012685}
12686
Karl Schultz6addd812016-02-02 17:17:23 -070012687TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012688 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12689 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012691
Chris Forbesde136e02015-05-25 11:13:28 +120012692 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012693 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012694
12695 VkVertexInputBindingDescription input_binding;
12696 memset(&input_binding, 0, sizeof(input_binding));
12697
12698 VkVertexInputAttributeDescription input_attrib;
12699 memset(&input_attrib, 0, sizeof(input_attrib));
12700 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12701
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012702 char const *vsSource = "#version 450\n"
12703 "\n"
12704 "out gl_PerVertex {\n"
12705 " vec4 gl_Position;\n"
12706 "};\n"
12707 "void main(){\n"
12708 " gl_Position = vec4(1);\n"
12709 "}\n";
12710 char const *fsSource = "#version 450\n"
12711 "\n"
12712 "layout(location=0) out vec4 color;\n"
12713 "void main(){\n"
12714 " color = vec4(1);\n"
12715 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012716
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012717 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12718 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012719
12720 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012721 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012722 pipe.AddShader(&vs);
12723 pipe.AddShader(&fs);
12724
12725 pipe.AddVertexInputBindings(&input_binding, 1);
12726 pipe.AddVertexInputAttribs(&input_attrib, 1);
12727
Chris Forbesde136e02015-05-25 11:13:28 +120012728 VkDescriptorSetObj descriptorSet(m_device);
12729 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012730 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012731
Tony Barbour5781e8f2015-08-04 16:23:11 -060012732 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012733
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012734 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012735}
12736
Karl Schultz6addd812016-02-02 17:17:23 -070012737TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012738 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12739 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012741
12742 ASSERT_NO_FATAL_FAILURE(InitState());
12743 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12744
12745 VkVertexInputBindingDescription input_binding;
12746 memset(&input_binding, 0, sizeof(input_binding));
12747
12748 VkVertexInputAttributeDescription input_attrib;
12749 memset(&input_attrib, 0, sizeof(input_attrib));
12750 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12751
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012752 char const *vsSource = "#version 450\n"
12753 "\n"
12754 "layout(location=1) in float x;\n"
12755 "out gl_PerVertex {\n"
12756 " vec4 gl_Position;\n"
12757 "};\n"
12758 "void main(){\n"
12759 " gl_Position = vec4(x);\n"
12760 "}\n";
12761 char const *fsSource = "#version 450\n"
12762 "\n"
12763 "layout(location=0) out vec4 color;\n"
12764 "void main(){\n"
12765 " color = vec4(1);\n"
12766 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012767
12768 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12769 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12770
12771 VkPipelineObj pipe(m_device);
12772 pipe.AddColorAttachment();
12773 pipe.AddShader(&vs);
12774 pipe.AddShader(&fs);
12775
12776 pipe.AddVertexInputBindings(&input_binding, 1);
12777 pipe.AddVertexInputAttribs(&input_attrib, 1);
12778
12779 VkDescriptorSetObj descriptorSet(m_device);
12780 descriptorSet.AppendDummy();
12781 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12782
12783 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12784
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012785 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012786}
12787
Karl Schultz6addd812016-02-02 17:17:23 -070012788TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012789 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012790 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012791 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 -060012792
Chris Forbes62e8e502015-05-25 11:13:29 +120012793 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012795
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012796 char const *vsSource = "#version 450\n"
12797 "\n"
12798 "layout(location=0) in vec4 x;\n" /* not provided */
12799 "out gl_PerVertex {\n"
12800 " vec4 gl_Position;\n"
12801 "};\n"
12802 "void main(){\n"
12803 " gl_Position = x;\n"
12804 "}\n";
12805 char const *fsSource = "#version 450\n"
12806 "\n"
12807 "layout(location=0) out vec4 color;\n"
12808 "void main(){\n"
12809 " color = vec4(1);\n"
12810 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012811
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012812 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12813 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012814
12815 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012816 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012817 pipe.AddShader(&vs);
12818 pipe.AddShader(&fs);
12819
Chris Forbes62e8e502015-05-25 11:13:29 +120012820 VkDescriptorSetObj descriptorSet(m_device);
12821 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012822 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012823
Tony Barbour5781e8f2015-08-04 16:23:11 -060012824 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012825
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012826 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012827}
12828
Karl Schultz6addd812016-02-02 17:17:23 -070012829TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012830 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12831 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012832 "vertex shader input that consumes it");
12833 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 -060012834
Chris Forbesc97d98e2015-05-25 11:13:31 +120012835 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012836 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012837
12838 VkVertexInputBindingDescription input_binding;
12839 memset(&input_binding, 0, sizeof(input_binding));
12840
12841 VkVertexInputAttributeDescription input_attrib;
12842 memset(&input_attrib, 0, sizeof(input_attrib));
12843 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12844
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012845 char const *vsSource = "#version 450\n"
12846 "\n"
12847 "layout(location=0) in int x;\n" /* attrib provided float */
12848 "out gl_PerVertex {\n"
12849 " vec4 gl_Position;\n"
12850 "};\n"
12851 "void main(){\n"
12852 " gl_Position = vec4(x);\n"
12853 "}\n";
12854 char const *fsSource = "#version 450\n"
12855 "\n"
12856 "layout(location=0) out vec4 color;\n"
12857 "void main(){\n"
12858 " color = vec4(1);\n"
12859 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012860
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012861 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12862 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012863
12864 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012865 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012866 pipe.AddShader(&vs);
12867 pipe.AddShader(&fs);
12868
12869 pipe.AddVertexInputBindings(&input_binding, 1);
12870 pipe.AddVertexInputAttribs(&input_attrib, 1);
12871
Chris Forbesc97d98e2015-05-25 11:13:31 +120012872 VkDescriptorSetObj descriptorSet(m_device);
12873 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012874 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012875
Tony Barbour5781e8f2015-08-04 16:23:11 -060012876 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012877
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012878 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012879}
12880
Chris Forbesc68b43c2016-04-06 11:18:47 +120012881TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012882 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12883 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12885 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012886
12887 ASSERT_NO_FATAL_FAILURE(InitState());
12888 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12889
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012890 char const *vsSource = "#version 450\n"
12891 "\n"
12892 "out gl_PerVertex {\n"
12893 " vec4 gl_Position;\n"
12894 "};\n"
12895 "void main(){\n"
12896 " gl_Position = vec4(1);\n"
12897 "}\n";
12898 char const *fsSource = "#version 450\n"
12899 "\n"
12900 "layout(location=0) out vec4 color;\n"
12901 "void main(){\n"
12902 " color = vec4(1);\n"
12903 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012904
12905 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12906 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12907
12908 VkPipelineObj pipe(m_device);
12909 pipe.AddColorAttachment();
12910 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012911 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012912 pipe.AddShader(&fs);
12913
12914 VkDescriptorSetObj descriptorSet(m_device);
12915 descriptorSet.AppendDummy();
12916 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12917
12918 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12919
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012920 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012921}
12922
Chris Forbes82ff92a2016-09-09 10:50:24 +120012923TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12925 "No entrypoint found named `foo`");
12926
12927 ASSERT_NO_FATAL_FAILURE(InitState());
12928 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12929
12930 char const *vsSource = "#version 450\n"
12931 "out gl_PerVertex {\n"
12932 " vec4 gl_Position;\n"
12933 "};\n"
12934 "void main(){\n"
12935 " gl_Position = vec4(0);\n"
12936 "}\n";
12937 char const *fsSource = "#version 450\n"
12938 "\n"
12939 "layout(location=0) out vec4 color;\n"
12940 "void main(){\n"
12941 " color = vec4(1);\n"
12942 "}\n";
12943
12944 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12945 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12946
12947 VkPipelineObj pipe(m_device);
12948 pipe.AddColorAttachment();
12949 pipe.AddShader(&vs);
12950 pipe.AddShader(&fs);
12951
12952 VkDescriptorSetObj descriptorSet(m_device);
12953 descriptorSet.AppendDummy();
12954 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12955
12956 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12957
12958 m_errorMonitor->VerifyFound();
12959}
12960
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012961TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12962 m_errorMonitor->SetDesiredFailureMsg(
12963 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12964 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12965 "uses a depth/stencil attachment");
12966
12967 ASSERT_NO_FATAL_FAILURE(InitState());
12968 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12969
12970 char const *vsSource = "#version 450\n"
12971 "void main(){ gl_Position = vec4(0); }\n";
12972 char const *fsSource = "#version 450\n"
12973 "\n"
12974 "layout(location=0) out vec4 color;\n"
12975 "void main(){\n"
12976 " color = vec4(1);\n"
12977 "}\n";
12978
12979 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12980 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12981
12982 VkPipelineObj pipe(m_device);
12983 pipe.AddColorAttachment();
12984 pipe.AddShader(&vs);
12985 pipe.AddShader(&fs);
12986
12987 VkDescriptorSetObj descriptorSet(m_device);
12988 descriptorSet.AppendDummy();
12989 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12990
12991 VkAttachmentDescription attachments[] = {
12992 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12993 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12994 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12995 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12996 },
12997 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12998 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12999 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13000 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13001 },
13002 };
13003 VkAttachmentReference refs[] = {
13004 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13005 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13006 };
13007 VkSubpassDescription subpass = {
13008 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13009 1, &refs[0], nullptr, &refs[1],
13010 0, nullptr
13011 };
13012 VkRenderPassCreateInfo rpci = {
13013 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13014 0, 2, attachments, 1, &subpass, 0, nullptr
13015 };
13016 VkRenderPass rp;
13017 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13018 ASSERT_VK_SUCCESS(err);
13019
13020 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13021
13022 m_errorMonitor->VerifyFound();
13023
13024 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13025}
13026
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013027TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013028 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13029 "the TCS without the patch decoration, but consumed in the TES "
13030 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13032 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013033
13034 ASSERT_NO_FATAL_FAILURE(InitState());
13035 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13036
Chris Forbesc1e852d2016-04-04 19:26:42 +120013037 if (!m_device->phy().features().tessellationShader) {
13038 printf("Device does not support tessellation shaders; skipped.\n");
13039 return;
13040 }
13041
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013042 char const *vsSource = "#version 450\n"
13043 "void main(){}\n";
13044 char const *tcsSource = "#version 450\n"
13045 "layout(location=0) out int x[];\n"
13046 "layout(vertices=3) out;\n"
13047 "void main(){\n"
13048 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13049 " gl_TessLevelInner[0] = 1;\n"
13050 " x[gl_InvocationID] = gl_InvocationID;\n"
13051 "}\n";
13052 char const *tesSource = "#version 450\n"
13053 "layout(triangles, equal_spacing, cw) in;\n"
13054 "layout(location=0) patch in int x;\n"
13055 "out gl_PerVertex { vec4 gl_Position; };\n"
13056 "void main(){\n"
13057 " gl_Position.xyz = gl_TessCoord;\n"
13058 " gl_Position.w = x;\n"
13059 "}\n";
13060 char const *fsSource = "#version 450\n"
13061 "layout(location=0) out vec4 color;\n"
13062 "void main(){\n"
13063 " color = vec4(1);\n"
13064 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013065
13066 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13067 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13068 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13069 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13070
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013071 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13072 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013073
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013074 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013075
13076 VkPipelineObj pipe(m_device);
13077 pipe.SetInputAssembly(&iasci);
13078 pipe.SetTessellation(&tsci);
13079 pipe.AddColorAttachment();
13080 pipe.AddShader(&vs);
13081 pipe.AddShader(&tcs);
13082 pipe.AddShader(&tes);
13083 pipe.AddShader(&fs);
13084
13085 VkDescriptorSetObj descriptorSet(m_device);
13086 descriptorSet.AppendDummy();
13087 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13088
13089 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13090
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013091 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013092}
13093
Karl Schultz6addd812016-02-02 17:17:23 -070013094TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013095 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13096 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13098 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013099
Chris Forbes280ba2c2015-06-12 11:16:41 +120013100 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013101 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013102
13103 /* Two binding descriptions for binding 0 */
13104 VkVertexInputBindingDescription input_bindings[2];
13105 memset(input_bindings, 0, sizeof(input_bindings));
13106
13107 VkVertexInputAttributeDescription input_attrib;
13108 memset(&input_attrib, 0, sizeof(input_attrib));
13109 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13110
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013111 char const *vsSource = "#version 450\n"
13112 "\n"
13113 "layout(location=0) in float x;\n" /* attrib provided float */
13114 "out gl_PerVertex {\n"
13115 " vec4 gl_Position;\n"
13116 "};\n"
13117 "void main(){\n"
13118 " gl_Position = vec4(x);\n"
13119 "}\n";
13120 char const *fsSource = "#version 450\n"
13121 "\n"
13122 "layout(location=0) out vec4 color;\n"
13123 "void main(){\n"
13124 " color = vec4(1);\n"
13125 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013126
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013127 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13128 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013129
13130 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013131 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013132 pipe.AddShader(&vs);
13133 pipe.AddShader(&fs);
13134
13135 pipe.AddVertexInputBindings(input_bindings, 2);
13136 pipe.AddVertexInputAttribs(&input_attrib, 1);
13137
Chris Forbes280ba2c2015-06-12 11:16:41 +120013138 VkDescriptorSetObj descriptorSet(m_device);
13139 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013140 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013141
Tony Barbour5781e8f2015-08-04 16:23:11 -060013142 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013143
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013144 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013145}
Chris Forbes8f68b562015-05-25 11:13:32 +120013146
Karl Schultz6addd812016-02-02 17:17:23 -070013147TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013148 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013149 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013151
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013152 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013153
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013154 char const *vsSource = "#version 450\n"
13155 "\n"
13156 "out gl_PerVertex {\n"
13157 " vec4 gl_Position;\n"
13158 "};\n"
13159 "void main(){\n"
13160 " gl_Position = vec4(1);\n"
13161 "}\n";
13162 char const *fsSource = "#version 450\n"
13163 "\n"
13164 "void main(){\n"
13165 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013166
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013167 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13168 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013169
13170 VkPipelineObj pipe(m_device);
13171 pipe.AddShader(&vs);
13172 pipe.AddShader(&fs);
13173
Chia-I Wu08accc62015-07-07 11:50:03 +080013174 /* set up CB 0, not written */
13175 pipe.AddColorAttachment();
13176 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013177
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013178 VkDescriptorSetObj descriptorSet(m_device);
13179 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013180 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013181
Tony Barbour5781e8f2015-08-04 16:23:11 -060013182 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013183
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013184 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013185}
13186
Karl Schultz6addd812016-02-02 17:17:23 -070013187TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013188 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013189 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013191 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013192
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013193 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013195 char const *vsSource = "#version 450\n"
13196 "\n"
13197 "out gl_PerVertex {\n"
13198 " vec4 gl_Position;\n"
13199 "};\n"
13200 "void main(){\n"
13201 " gl_Position = vec4(1);\n"
13202 "}\n";
13203 char const *fsSource = "#version 450\n"
13204 "\n"
13205 "layout(location=0) out vec4 x;\n"
13206 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13207 "void main(){\n"
13208 " x = vec4(1);\n"
13209 " y = vec4(1);\n"
13210 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013211
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013212 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13213 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013214
13215 VkPipelineObj pipe(m_device);
13216 pipe.AddShader(&vs);
13217 pipe.AddShader(&fs);
13218
Chia-I Wu08accc62015-07-07 11:50:03 +080013219 /* set up CB 0, not written */
13220 pipe.AddColorAttachment();
13221 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013222 /* FS writes CB 1, but we don't configure it */
13223
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013224 VkDescriptorSetObj descriptorSet(m_device);
13225 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013226 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013227
Tony Barbour5781e8f2015-08-04 16:23:11 -060013228 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013229
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013230 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013231}
13232
Karl Schultz6addd812016-02-02 17:17:23 -070013233TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013234 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013235 "type of an fragment shader output variable, and the format of the corresponding attachment");
13236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013237
Chris Forbesa36d69e2015-05-25 11:13:44 +120013238 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013239
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013240 char const *vsSource = "#version 450\n"
13241 "\n"
13242 "out gl_PerVertex {\n"
13243 " vec4 gl_Position;\n"
13244 "};\n"
13245 "void main(){\n"
13246 " gl_Position = vec4(1);\n"
13247 "}\n";
13248 char const *fsSource = "#version 450\n"
13249 "\n"
13250 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13251 "void main(){\n"
13252 " x = ivec4(1);\n"
13253 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013254
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013255 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13256 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013257
13258 VkPipelineObj pipe(m_device);
13259 pipe.AddShader(&vs);
13260 pipe.AddShader(&fs);
13261
Chia-I Wu08accc62015-07-07 11:50:03 +080013262 /* set up CB 0; type is UNORM by default */
13263 pipe.AddColorAttachment();
13264 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013265
Chris Forbesa36d69e2015-05-25 11:13:44 +120013266 VkDescriptorSetObj descriptorSet(m_device);
13267 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013268 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013269
Tony Barbour5781e8f2015-08-04 16:23:11 -060013270 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013271
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013272 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013273}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013274
Karl Schultz6addd812016-02-02 17:17:23 -070013275TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013276 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13277 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013279
Chris Forbes556c76c2015-08-14 12:04:59 +120013280 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013281
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013282 char const *vsSource = "#version 450\n"
13283 "\n"
13284 "out gl_PerVertex {\n"
13285 " vec4 gl_Position;\n"
13286 "};\n"
13287 "void main(){\n"
13288 " gl_Position = vec4(1);\n"
13289 "}\n";
13290 char const *fsSource = "#version 450\n"
13291 "\n"
13292 "layout(location=0) out vec4 x;\n"
13293 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13294 "void main(){\n"
13295 " x = vec4(bar.y);\n"
13296 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013297
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013298 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13299 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013300
Chris Forbes556c76c2015-08-14 12:04:59 +120013301 VkPipelineObj pipe(m_device);
13302 pipe.AddShader(&vs);
13303 pipe.AddShader(&fs);
13304
13305 /* set up CB 0; type is UNORM by default */
13306 pipe.AddColorAttachment();
13307 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13308
13309 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013310 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013311
13312 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13313
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013314 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013315}
13316
Chris Forbes5c59e902016-02-26 16:56:09 +130013317TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013318 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13319 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013321
13322 ASSERT_NO_FATAL_FAILURE(InitState());
13323
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013324 char const *vsSource = "#version 450\n"
13325 "\n"
13326 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13327 "out gl_PerVertex {\n"
13328 " vec4 gl_Position;\n"
13329 "};\n"
13330 "void main(){\n"
13331 " gl_Position = vec4(consts.x);\n"
13332 "}\n";
13333 char const *fsSource = "#version 450\n"
13334 "\n"
13335 "layout(location=0) out vec4 x;\n"
13336 "void main(){\n"
13337 " x = vec4(1);\n"
13338 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013339
13340 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13341 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13342
13343 VkPipelineObj pipe(m_device);
13344 pipe.AddShader(&vs);
13345 pipe.AddShader(&fs);
13346
13347 /* set up CB 0; type is UNORM by default */
13348 pipe.AddColorAttachment();
13349 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13350
13351 VkDescriptorSetObj descriptorSet(m_device);
13352 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13353
13354 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13355
13356 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013357 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013358}
13359
Chris Forbes3fb17902016-08-22 14:57:55 +120013360TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13361 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13362 "which is not included in the subpass description");
13363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13364 "consumes input attachment index 0 but not provided in subpass");
13365
13366 ASSERT_NO_FATAL_FAILURE(InitState());
13367
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013368 char const *vsSource = "#version 450\n"
13369 "\n"
13370 "out gl_PerVertex {\n"
13371 " vec4 gl_Position;\n"
13372 "};\n"
13373 "void main(){\n"
13374 " gl_Position = vec4(1);\n"
13375 "}\n";
13376 char const *fsSource = "#version 450\n"
13377 "\n"
13378 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13379 "layout(location=0) out vec4 color;\n"
13380 "void main() {\n"
13381 " color = subpassLoad(x);\n"
13382 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013383
13384 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13385 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13386
13387 VkPipelineObj pipe(m_device);
13388 pipe.AddShader(&vs);
13389 pipe.AddShader(&fs);
13390 pipe.AddColorAttachment();
13391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13392
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013393 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13394 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013395 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013396 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013397 ASSERT_VK_SUCCESS(err);
13398
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013399 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013400 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013401 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013402 ASSERT_VK_SUCCESS(err);
13403
13404 // error here.
13405 pipe.CreateVKPipeline(pl, renderPass());
13406
13407 m_errorMonitor->VerifyFound();
13408
13409 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13410 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13411}
13412
Chris Forbes5a9a0472016-08-22 16:02:09 +120013413TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13414 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13415 "with a format having a different fundamental type");
13416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13417 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13418
13419 ASSERT_NO_FATAL_FAILURE(InitState());
13420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013421 char const *vsSource = "#version 450\n"
13422 "\n"
13423 "out gl_PerVertex {\n"
13424 " vec4 gl_Position;\n"
13425 "};\n"
13426 "void main(){\n"
13427 " gl_Position = vec4(1);\n"
13428 "}\n";
13429 char const *fsSource = "#version 450\n"
13430 "\n"
13431 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13432 "layout(location=0) out vec4 color;\n"
13433 "void main() {\n"
13434 " color = subpassLoad(x);\n"
13435 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013436
13437 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13438 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13439
13440 VkPipelineObj pipe(m_device);
13441 pipe.AddShader(&vs);
13442 pipe.AddShader(&fs);
13443 pipe.AddColorAttachment();
13444 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13445
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013446 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13447 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013448 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013449 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013450 ASSERT_VK_SUCCESS(err);
13451
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013452 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013453 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013454 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013455 ASSERT_VK_SUCCESS(err);
13456
13457 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013458 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13459 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13460 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13461 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13462 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 +120013463 };
13464 VkAttachmentReference color = {
13465 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13466 };
13467 VkAttachmentReference input = {
13468 1, VK_IMAGE_LAYOUT_GENERAL,
13469 };
13470
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013471 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013472
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013473 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013474 VkRenderPass rp;
13475 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13476 ASSERT_VK_SUCCESS(err);
13477
13478 // error here.
13479 pipe.CreateVKPipeline(pl, rp);
13480
13481 m_errorMonitor->VerifyFound();
13482
13483 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13484 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13485 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13486}
13487
Chris Forbes541f7b02016-08-22 15:30:27 +120013488TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13489 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13490 "which is not included in the subpass description -- array case");
13491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13492 "consumes input attachment index 1 but not provided in subpass");
13493
13494 ASSERT_NO_FATAL_FAILURE(InitState());
13495
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013496 char const *vsSource = "#version 450\n"
13497 "\n"
13498 "out gl_PerVertex {\n"
13499 " vec4 gl_Position;\n"
13500 "};\n"
13501 "void main(){\n"
13502 " gl_Position = vec4(1);\n"
13503 "}\n";
13504 char const *fsSource = "#version 450\n"
13505 "\n"
13506 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13507 "layout(location=0) out vec4 color;\n"
13508 "void main() {\n"
13509 " color = subpassLoad(xs[1]);\n"
13510 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013511
13512 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13513 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13514
13515 VkPipelineObj pipe(m_device);
13516 pipe.AddShader(&vs);
13517 pipe.AddShader(&fs);
13518 pipe.AddColorAttachment();
13519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13520
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013521 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13522 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013523 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013524 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013525 ASSERT_VK_SUCCESS(err);
13526
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013527 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013528 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013529 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013530 ASSERT_VK_SUCCESS(err);
13531
13532 // error here.
13533 pipe.CreateVKPipeline(pl, renderPass());
13534
13535 m_errorMonitor->VerifyFound();
13536
13537 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13538 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13539}
13540
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013541TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013542 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13543 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013545
13546 ASSERT_NO_FATAL_FAILURE(InitState());
13547
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013548 char const *csSource = "#version 450\n"
13549 "\n"
13550 "layout(local_size_x=1) in;\n"
13551 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13552 "void main(){\n"
13553 " x = vec4(1);\n"
13554 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013555
13556 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13557
13558 VkDescriptorSetObj descriptorSet(m_device);
13559 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13560
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013561 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13562 nullptr,
13563 0,
13564 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13565 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13566 descriptorSet.GetPipelineLayout(),
13567 VK_NULL_HANDLE,
13568 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013569
13570 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013571 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013572
13573 m_errorMonitor->VerifyFound();
13574
13575 if (err == VK_SUCCESS) {
13576 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13577 }
13578}
13579
Chris Forbes22a9b092016-07-19 14:34:05 +120013580TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013581 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13582 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13584 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013585
13586 ASSERT_NO_FATAL_FAILURE(InitState());
13587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013588 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13589 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013590 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013591 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013592 ASSERT_VK_SUCCESS(err);
13593
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013594 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013595 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013596 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013597 ASSERT_VK_SUCCESS(err);
13598
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013599 char const *csSource = "#version 450\n"
13600 "\n"
13601 "layout(local_size_x=1) in;\n"
13602 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13603 "void main() {\n"
13604 " x.x = 1.0f;\n"
13605 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013606 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13607
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013608 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13609 nullptr,
13610 0,
13611 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13612 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13613 pl,
13614 VK_NULL_HANDLE,
13615 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013616
13617 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013618 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013619
13620 m_errorMonitor->VerifyFound();
13621
13622 if (err == VK_SUCCESS) {
13623 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13624 }
13625
13626 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13627 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13628}
13629
Chris Forbes50020592016-07-27 13:52:41 +120013630TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13631 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13632 "does not match the dimensionality declared in the shader");
13633
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013634 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 +120013635
13636 ASSERT_NO_FATAL_FAILURE(InitState());
13637 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13638
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013639 char const *vsSource = "#version 450\n"
13640 "\n"
13641 "out gl_PerVertex { vec4 gl_Position; };\n"
13642 "void main() { gl_Position = vec4(0); }\n";
13643 char const *fsSource = "#version 450\n"
13644 "\n"
13645 "layout(set=0, binding=0) uniform sampler3D s;\n"
13646 "layout(location=0) out vec4 color;\n"
13647 "void main() {\n"
13648 " color = texture(s, vec3(0));\n"
13649 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013650 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
13658 VkTextureObj texture(m_device, nullptr);
13659 VkSamplerObj sampler(m_device);
13660
13661 VkDescriptorSetObj descriptorSet(m_device);
13662 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13663 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13664
13665 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13666 ASSERT_VK_SUCCESS(err);
13667
13668 BeginCommandBuffer();
13669
13670 m_commandBuffer->BindPipeline(pipe);
13671 m_commandBuffer->BindDescriptorSet(descriptorSet);
13672
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013673 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013674 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013675 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013676 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13677
13678 // error produced here.
13679 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13680
13681 m_errorMonitor->VerifyFound();
13682
13683 EndCommandBuffer();
13684}
13685
Chris Forbes5533bfc2016-07-27 14:12:34 +120013686TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13687 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13688 "are consumed via singlesample images types in the shader, or vice versa.");
13689
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013691
13692 ASSERT_NO_FATAL_FAILURE(InitState());
13693 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13694
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013695 char const *vsSource = "#version 450\n"
13696 "\n"
13697 "out gl_PerVertex { vec4 gl_Position; };\n"
13698 "void main() { gl_Position = vec4(0); }\n";
13699 char const *fsSource = "#version 450\n"
13700 "\n"
13701 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13702 "layout(location=0) out vec4 color;\n"
13703 "void main() {\n"
13704 " color = texelFetch(s, ivec2(0), 0);\n"
13705 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013706 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13707 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13708
13709 VkPipelineObj pipe(m_device);
13710 pipe.AddShader(&vs);
13711 pipe.AddShader(&fs);
13712 pipe.AddColorAttachment();
13713
13714 VkTextureObj texture(m_device, nullptr);
13715 VkSamplerObj sampler(m_device);
13716
13717 VkDescriptorSetObj descriptorSet(m_device);
13718 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13719 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13720
13721 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13722 ASSERT_VK_SUCCESS(err);
13723
13724 BeginCommandBuffer();
13725
13726 m_commandBuffer->BindPipeline(pipe);
13727 m_commandBuffer->BindDescriptorSet(descriptorSet);
13728
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013729 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013730 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013731 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013732 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13733
13734 // error produced here.
13735 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13736
13737 m_errorMonitor->VerifyFound();
13738
13739 EndCommandBuffer();
13740}
13741
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013742#endif // SHADER_CHECKER_TESTS
13743
13744#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013745TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013747
13748 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013749
13750 // Create an image
13751 VkImage image;
13752
Karl Schultz6addd812016-02-02 17:17:23 -070013753 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13754 const int32_t tex_width = 32;
13755 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013756
13757 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013758 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13759 image_create_info.pNext = NULL;
13760 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13761 image_create_info.format = tex_format;
13762 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013763 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013764 image_create_info.extent.depth = 1;
13765 image_create_info.mipLevels = 1;
13766 image_create_info.arrayLayers = 1;
13767 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13768 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13769 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13770 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013771
13772 // Introduce error by sending down a bogus width extent
13773 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013774 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013775
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013776 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013777}
13778
Mark Youngc48c4c12016-04-11 14:26:49 -060013779TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13781 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013782
13783 ASSERT_NO_FATAL_FAILURE(InitState());
13784
13785 // Create an image
13786 VkImage image;
13787
13788 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13789 const int32_t tex_width = 32;
13790 const int32_t tex_height = 32;
13791
13792 VkImageCreateInfo image_create_info = {};
13793 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13794 image_create_info.pNext = NULL;
13795 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13796 image_create_info.format = tex_format;
13797 image_create_info.extent.width = tex_width;
13798 image_create_info.extent.height = tex_height;
13799 image_create_info.extent.depth = 1;
13800 image_create_info.mipLevels = 1;
13801 image_create_info.arrayLayers = 1;
13802 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13803 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13804 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13805 image_create_info.flags = 0;
13806
13807 // Introduce error by sending down a bogus width extent
13808 image_create_info.extent.width = 0;
13809 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13810
13811 m_errorMonitor->VerifyFound();
13812}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013813#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013814
Tobin Ehliscde08892015-09-22 10:11:37 -060013815#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070013816
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013817TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13818 TEST_DESCRIPTION("Create a render pass with an attachment description "
13819 "format set to VK_FORMAT_UNDEFINED");
13820
13821 ASSERT_NO_FATAL_FAILURE(InitState());
13822 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13823
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013825
13826 VkAttachmentReference color_attach = {};
13827 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13828 color_attach.attachment = 0;
13829 VkSubpassDescription subpass = {};
13830 subpass.colorAttachmentCount = 1;
13831 subpass.pColorAttachments = &color_attach;
13832
13833 VkRenderPassCreateInfo rpci = {};
13834 rpci.subpassCount = 1;
13835 rpci.pSubpasses = &subpass;
13836 rpci.attachmentCount = 1;
13837 VkAttachmentDescription attach_desc = {};
13838 attach_desc.format = VK_FORMAT_UNDEFINED;
13839 rpci.pAttachments = &attach_desc;
13840 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13841 VkRenderPass rp;
13842 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13843
13844 m_errorMonitor->VerifyFound();
13845
13846 if (result == VK_SUCCESS) {
13847 vkDestroyRenderPass(m_device->device(), rp, NULL);
13848 }
13849}
13850
Karl Schultz6addd812016-02-02 17:17:23 -070013851TEST_F(VkLayerTest, InvalidImageView) {
13852 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013853
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013855
Tobin Ehliscde08892015-09-22 10:11:37 -060013856 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013857
Mike Stroyana3082432015-09-25 13:39:21 -060013858 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013859 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013860
Karl Schultz6addd812016-02-02 17:17:23 -070013861 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13862 const int32_t tex_width = 32;
13863 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013864
13865 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013866 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13867 image_create_info.pNext = NULL;
13868 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13869 image_create_info.format = tex_format;
13870 image_create_info.extent.width = tex_width;
13871 image_create_info.extent.height = tex_height;
13872 image_create_info.extent.depth = 1;
13873 image_create_info.mipLevels = 1;
13874 image_create_info.arrayLayers = 1;
13875 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13876 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13877 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13878 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013879
Chia-I Wuf7458c52015-10-26 21:10:41 +080013880 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013881 ASSERT_VK_SUCCESS(err);
13882
13883 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130013884 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070013885 image_view_create_info.image = image;
13886 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13887 image_view_create_info.format = tex_format;
13888 image_view_create_info.subresourceRange.layerCount = 1;
13889 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13890 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013891 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013892
13893 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013894 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013895
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013896 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013897 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013898}
Mike Stroyana3082432015-09-25 13:39:21 -060013899
Mark Youngd339ba32016-05-30 13:28:35 -060013900TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13901 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013903 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013904
13905 ASSERT_NO_FATAL_FAILURE(InitState());
13906
13907 // Create an image and try to create a view with no memory backing the image
13908 VkImage image;
13909
13910 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13911 const int32_t tex_width = 32;
13912 const int32_t tex_height = 32;
13913
13914 VkImageCreateInfo image_create_info = {};
13915 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13916 image_create_info.pNext = NULL;
13917 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13918 image_create_info.format = tex_format;
13919 image_create_info.extent.width = tex_width;
13920 image_create_info.extent.height = tex_height;
13921 image_create_info.extent.depth = 1;
13922 image_create_info.mipLevels = 1;
13923 image_create_info.arrayLayers = 1;
13924 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13925 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13926 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13927 image_create_info.flags = 0;
13928
13929 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13930 ASSERT_VK_SUCCESS(err);
13931
13932 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130013933 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060013934 image_view_create_info.image = image;
13935 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13936 image_view_create_info.format = tex_format;
13937 image_view_create_info.subresourceRange.layerCount = 1;
13938 image_view_create_info.subresourceRange.baseMipLevel = 0;
13939 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013940 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013941
13942 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013943 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013944
13945 m_errorMonitor->VerifyFound();
13946 vkDestroyImage(m_device->device(), image, NULL);
13947 // If last error is success, it still created the view, so delete it.
13948 if (err == VK_SUCCESS) {
13949 vkDestroyImageView(m_device->device(), view, NULL);
13950 }
Mark Youngd339ba32016-05-30 13:28:35 -060013951}
13952
Karl Schultz6addd812016-02-02 17:17:23 -070013953TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013954 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013956 "formats must have ONLY the "
13957 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13959 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013960
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013961 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013962
Karl Schultz6addd812016-02-02 17:17:23 -070013963 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013964 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013965 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013966 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013967
13968 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013969 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013970 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013971 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13972 image_view_create_info.format = tex_format;
13973 image_view_create_info.subresourceRange.baseMipLevel = 0;
13974 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013975 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013976 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013977 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013978
13979 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013980 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013981
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013982 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013983}
13984
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013985TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013986 VkResult err;
13987 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13990 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013991
Mike Stroyana3082432015-09-25 13:39:21 -060013992 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013993
13994 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013995 VkImage srcImage;
13996 VkImage dstImage;
13997 VkDeviceMemory srcMem;
13998 VkDeviceMemory destMem;
13999 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014000
14001 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014002 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14003 image_create_info.pNext = NULL;
14004 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14005 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14006 image_create_info.extent.width = 32;
14007 image_create_info.extent.height = 32;
14008 image_create_info.extent.depth = 1;
14009 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014010 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014011 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14012 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14013 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14014 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014016 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014017 ASSERT_VK_SUCCESS(err);
14018
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014019 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014020 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014021 ASSERT_VK_SUCCESS(err);
14022
14023 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014024 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014025 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14026 memAlloc.pNext = NULL;
14027 memAlloc.allocationSize = 0;
14028 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014029
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014030 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014031 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014032 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014033 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014034 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014035 ASSERT_VK_SUCCESS(err);
14036
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014037 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014038 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014039 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014040 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014041 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014042 ASSERT_VK_SUCCESS(err);
14043
14044 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14045 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014046 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014047 ASSERT_VK_SUCCESS(err);
14048
14049 BeginCommandBuffer();
14050 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014051 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014052 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014053 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014054 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014055 copyRegion.srcOffset.x = 0;
14056 copyRegion.srcOffset.y = 0;
14057 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014058 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014059 copyRegion.dstSubresource.mipLevel = 0;
14060 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014061 // Introduce failure by forcing the dst layerCount to differ from src
14062 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014063 copyRegion.dstOffset.x = 0;
14064 copyRegion.dstOffset.y = 0;
14065 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014066 copyRegion.extent.width = 1;
14067 copyRegion.extent.height = 1;
14068 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014069 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014070 EndCommandBuffer();
14071
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014072 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014073
Chia-I Wuf7458c52015-10-26 21:10:41 +080014074 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014075 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014076 vkFreeMemory(m_device->device(), srcMem, NULL);
14077 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014078}
14079
Tony Barbourd6673642016-05-05 14:46:39 -060014080TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14081
14082 TEST_DESCRIPTION("Creating images with unsuported formats ");
14083
14084 ASSERT_NO_FATAL_FAILURE(InitState());
14085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14086 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014087 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 -060014088 VK_IMAGE_TILING_OPTIMAL, 0);
14089 ASSERT_TRUE(image.initialized());
14090
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014091 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014092 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014093 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014094 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14095 image_create_info.format = VK_FORMAT_UNDEFINED;
14096 image_create_info.extent.width = 32;
14097 image_create_info.extent.height = 32;
14098 image_create_info.extent.depth = 1;
14099 image_create_info.mipLevels = 1;
14100 image_create_info.arrayLayers = 1;
14101 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14102 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14103 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014104
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14106 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014107
14108 VkImage localImage;
14109 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14110 m_errorMonitor->VerifyFound();
14111
Tony Barbourd6673642016-05-05 14:46:39 -060014112 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014113 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014114 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14115 VkFormat format = static_cast<VkFormat>(f);
14116 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014117 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014118 unsupported = format;
14119 break;
14120 }
14121 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014122
Tony Barbourd6673642016-05-05 14:46:39 -060014123 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014124 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014126
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014127 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014128 m_errorMonitor->VerifyFound();
14129 }
14130}
14131
14132TEST_F(VkLayerTest, ImageLayerViewTests) {
14133 VkResult ret;
14134 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14135
14136 ASSERT_NO_FATAL_FAILURE(InitState());
14137
14138 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014139 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 -060014140 VK_IMAGE_TILING_OPTIMAL, 0);
14141 ASSERT_TRUE(image.initialized());
14142
14143 VkImageView imgView;
14144 VkImageViewCreateInfo imgViewInfo = {};
14145 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14146 imgViewInfo.image = image.handle();
14147 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14148 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14149 imgViewInfo.subresourceRange.layerCount = 1;
14150 imgViewInfo.subresourceRange.baseMipLevel = 0;
14151 imgViewInfo.subresourceRange.levelCount = 1;
14152 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14153
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060014155 // View can't have baseMipLevel >= image's mipLevels - Expect
14156 // VIEW_CREATE_ERROR
14157 imgViewInfo.subresourceRange.baseMipLevel = 1;
14158 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14159 m_errorMonitor->VerifyFound();
14160 imgViewInfo.subresourceRange.baseMipLevel = 0;
14161
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014163 // View can't have baseArrayLayer >= image's arraySize - Expect
14164 // VIEW_CREATE_ERROR
14165 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14166 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14167 m_errorMonitor->VerifyFound();
14168 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14169
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14171 "pCreateInfo->subresourceRange."
14172 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014173 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14174 imgViewInfo.subresourceRange.levelCount = 0;
14175 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14176 m_errorMonitor->VerifyFound();
14177 imgViewInfo.subresourceRange.levelCount = 1;
14178
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14180 "pCreateInfo->subresourceRange."
14181 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014182 m_errorMonitor->SetDesiredFailureMsg(
14183 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14184 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014185 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14186 imgViewInfo.subresourceRange.layerCount = 0;
14187 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14188 m_errorMonitor->VerifyFound();
14189 imgViewInfo.subresourceRange.layerCount = 1;
14190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14193 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14194 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014195 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14196 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14197 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14198 m_errorMonitor->VerifyFound();
14199 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14200
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14202 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14203 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014204 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14205 // VIEW_CREATE_ERROR
14206 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14207 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14208 m_errorMonitor->VerifyFound();
14209 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14210
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14212 "differing formats but they must be "
14213 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014214 // TODO: Update framework to easily passing mutable flag into ImageObj init
14215 // For now just allowing image for this one test to not have memory bound
14216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14217 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014218 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14219 // VIEW_CREATE_ERROR
14220 VkImageCreateInfo mutImgInfo = image.create_info();
14221 VkImage mutImage;
14222 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014223 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014224 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14225 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14226 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14227 ASSERT_VK_SUCCESS(ret);
14228 imgViewInfo.image = mutImage;
14229 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14230 m_errorMonitor->VerifyFound();
14231 imgViewInfo.image = image.handle();
14232 vkDestroyImage(m_device->handle(), mutImage, NULL);
14233}
14234
14235TEST_F(VkLayerTest, MiscImageLayerTests) {
14236
14237 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14238
14239 ASSERT_NO_FATAL_FAILURE(InitState());
14240
14241 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014242 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 -060014243 VK_IMAGE_TILING_OPTIMAL, 0);
14244 ASSERT_TRUE(image.initialized());
14245
Tony Barbourd6673642016-05-05 14:46:39 -060014246 vk_testing::Buffer buffer;
14247 VkMemoryPropertyFlags reqs = 0;
14248 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14249 VkBufferImageCopy region = {};
14250 region.bufferRowLength = 128;
14251 region.bufferImageHeight = 128;
14252 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14253 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014254 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014255 region.imageExtent.height = 4;
14256 region.imageExtent.width = 4;
14257 region.imageExtent.depth = 1;
14258 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014259
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014260 // Image must have offset.z of 0 and extent.depth of 1
14261 // Introduce failure by setting imageExtent.depth to 0
14262 region.imageExtent.depth = 0;
14263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14264 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14265 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14266 m_errorMonitor->VerifyFound();
14267
14268 region.imageExtent.depth = 1;
14269
14270 // Image must have offset.z of 0 and extent.depth of 1
14271 // Introduce failure by setting imageOffset.z to 4
14272 region.imageOffset.z = 4;
14273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14274 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14275 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14276 m_errorMonitor->VerifyFound();
14277
14278 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014279 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14280 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14281 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014283 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14284 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014285 m_errorMonitor->VerifyFound();
14286
14287 // BufferOffset must be a multiple of 4
14288 // Introduce failure by setting bufferOffset to a value not divisible by 4
14289 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014291 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14292 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014293 m_errorMonitor->VerifyFound();
14294
14295 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14296 region.bufferOffset = 0;
14297 region.imageExtent.height = 128;
14298 region.imageExtent.width = 128;
14299 // Introduce failure by setting bufferRowLength > 0 but less than width
14300 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014302 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14303 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014304 m_errorMonitor->VerifyFound();
14305
14306 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14307 region.bufferRowLength = 128;
14308 // Introduce failure by setting bufferRowHeight > 0 but less than height
14309 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014311 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14312 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014313 m_errorMonitor->VerifyFound();
14314
14315 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14317 "If the format of srcImage is a depth, stencil, depth stencil or "
14318 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014319 // Expect INVALID_FILTER
14320 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014321 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 -060014322 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014323 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 -060014324 VkImageBlit blitRegion = {};
14325 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14326 blitRegion.srcSubresource.baseArrayLayer = 0;
14327 blitRegion.srcSubresource.layerCount = 1;
14328 blitRegion.srcSubresource.mipLevel = 0;
14329 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14330 blitRegion.dstSubresource.baseArrayLayer = 0;
14331 blitRegion.dstSubresource.layerCount = 1;
14332 blitRegion.dstSubresource.mipLevel = 0;
14333
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014334 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14335 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014336 m_errorMonitor->VerifyFound();
14337
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014338 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14340 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14341 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014342 m_errorMonitor->VerifyFound();
14343
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014345 VkImageMemoryBarrier img_barrier;
14346 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14347 img_barrier.pNext = NULL;
14348 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14349 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14350 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14351 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14352 img_barrier.image = image.handle();
14353 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14354 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14355 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14356 img_barrier.subresourceRange.baseArrayLayer = 0;
14357 img_barrier.subresourceRange.baseMipLevel = 0;
14358 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14359 img_barrier.subresourceRange.layerCount = 0;
14360 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014361 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14362 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014363 m_errorMonitor->VerifyFound();
14364 img_barrier.subresourceRange.layerCount = 1;
14365}
14366
14367TEST_F(VkLayerTest, ImageFormatLimits) {
14368
14369 TEST_DESCRIPTION("Exceed the limits of image format ");
14370
Cody Northropc31a84f2016-08-22 10:41:47 -060014371 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014373 VkImageCreateInfo image_create_info = {};
14374 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14375 image_create_info.pNext = NULL;
14376 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14377 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14378 image_create_info.extent.width = 32;
14379 image_create_info.extent.height = 32;
14380 image_create_info.extent.depth = 1;
14381 image_create_info.mipLevels = 1;
14382 image_create_info.arrayLayers = 1;
14383 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14384 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14385 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14386 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14387 image_create_info.flags = 0;
14388
14389 VkImage nullImg;
14390 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014391 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14392 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014393 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14394 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14395 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14396 m_errorMonitor->VerifyFound();
14397 image_create_info.extent.depth = 1;
14398
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014400 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14401 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14402 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14403 m_errorMonitor->VerifyFound();
14404 image_create_info.mipLevels = 1;
14405
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014407 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14408 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14409 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14410 m_errorMonitor->VerifyFound();
14411 image_create_info.arrayLayers = 1;
14412
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014414 int samples = imgFmtProps.sampleCounts >> 1;
14415 image_create_info.samples = (VkSampleCountFlagBits)samples;
14416 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14417 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14418 m_errorMonitor->VerifyFound();
14419 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14422 "VK_IMAGE_LAYOUT_UNDEFINED or "
14423 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014424 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14425 // Expect INVALID_LAYOUT
14426 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14427 m_errorMonitor->VerifyFound();
14428 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14429}
14430
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014431TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14432
14433 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014435
14436 ASSERT_NO_FATAL_FAILURE(InitState());
14437
14438 VkImageObj src_image(m_device);
14439 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14440 VkImageObj dst_image(m_device);
14441 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14442
14443 BeginCommandBuffer();
14444 VkImageCopy copy_region;
14445 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14446 copy_region.srcSubresource.mipLevel = 0;
14447 copy_region.srcSubresource.baseArrayLayer = 0;
14448 copy_region.srcSubresource.layerCount = 0;
14449 copy_region.srcOffset.x = 0;
14450 copy_region.srcOffset.y = 0;
14451 copy_region.srcOffset.z = 0;
14452 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14453 copy_region.dstSubresource.mipLevel = 0;
14454 copy_region.dstSubresource.baseArrayLayer = 0;
14455 copy_region.dstSubresource.layerCount = 0;
14456 copy_region.dstOffset.x = 0;
14457 copy_region.dstOffset.y = 0;
14458 copy_region.dstOffset.z = 0;
14459 copy_region.extent.width = 64;
14460 copy_region.extent.height = 64;
14461 copy_region.extent.depth = 1;
14462 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14463 &copy_region);
14464 EndCommandBuffer();
14465
14466 m_errorMonitor->VerifyFound();
14467}
14468
14469TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14470
14471 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014473
14474 ASSERT_NO_FATAL_FAILURE(InitState());
14475
14476 VkImageObj src_image(m_device);
14477 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14478 VkImageObj dst_image(m_device);
14479 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14480
14481 BeginCommandBuffer();
14482 VkImageCopy copy_region;
14483 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14484 copy_region.srcSubresource.mipLevel = 0;
14485 copy_region.srcSubresource.baseArrayLayer = 0;
14486 copy_region.srcSubresource.layerCount = 0;
14487 copy_region.srcOffset.x = 0;
14488 copy_region.srcOffset.y = 0;
14489 copy_region.srcOffset.z = 0;
14490 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14491 copy_region.dstSubresource.mipLevel = 0;
14492 copy_region.dstSubresource.baseArrayLayer = 0;
14493 copy_region.dstSubresource.layerCount = 0;
14494 copy_region.dstOffset.x = 0;
14495 copy_region.dstOffset.y = 0;
14496 copy_region.dstOffset.z = 0;
14497 copy_region.extent.width = 64;
14498 copy_region.extent.height = 64;
14499 copy_region.extent.depth = 1;
14500 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14501 &copy_region);
14502 EndCommandBuffer();
14503
14504 m_errorMonitor->VerifyFound();
14505}
14506
Karl Schultz6addd812016-02-02 17:17:23 -070014507TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014508 VkResult err;
14509 bool pass;
14510
14511 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14513 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014514
14515 ASSERT_NO_FATAL_FAILURE(InitState());
14516
14517 // Create two images of different types and try to copy between them
14518 VkImage srcImage;
14519 VkImage dstImage;
14520 VkDeviceMemory srcMem;
14521 VkDeviceMemory destMem;
14522 VkMemoryRequirements memReqs;
14523
14524 VkImageCreateInfo image_create_info = {};
14525 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14526 image_create_info.pNext = NULL;
14527 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14528 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14529 image_create_info.extent.width = 32;
14530 image_create_info.extent.height = 32;
14531 image_create_info.extent.depth = 1;
14532 image_create_info.mipLevels = 1;
14533 image_create_info.arrayLayers = 1;
14534 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14535 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14536 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14537 image_create_info.flags = 0;
14538
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014539 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014540 ASSERT_VK_SUCCESS(err);
14541
14542 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14543 // Introduce failure by creating second image with a different-sized format.
14544 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14545
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014546 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014547 ASSERT_VK_SUCCESS(err);
14548
14549 // Allocate memory
14550 VkMemoryAllocateInfo memAlloc = {};
14551 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14552 memAlloc.pNext = NULL;
14553 memAlloc.allocationSize = 0;
14554 memAlloc.memoryTypeIndex = 0;
14555
14556 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14557 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014558 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014559 ASSERT_TRUE(pass);
14560 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14561 ASSERT_VK_SUCCESS(err);
14562
14563 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14564 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014565 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014566 ASSERT_TRUE(pass);
14567 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14568 ASSERT_VK_SUCCESS(err);
14569
14570 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14571 ASSERT_VK_SUCCESS(err);
14572 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14573 ASSERT_VK_SUCCESS(err);
14574
14575 BeginCommandBuffer();
14576 VkImageCopy copyRegion;
14577 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14578 copyRegion.srcSubresource.mipLevel = 0;
14579 copyRegion.srcSubresource.baseArrayLayer = 0;
14580 copyRegion.srcSubresource.layerCount = 0;
14581 copyRegion.srcOffset.x = 0;
14582 copyRegion.srcOffset.y = 0;
14583 copyRegion.srcOffset.z = 0;
14584 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14585 copyRegion.dstSubresource.mipLevel = 0;
14586 copyRegion.dstSubresource.baseArrayLayer = 0;
14587 copyRegion.dstSubresource.layerCount = 0;
14588 copyRegion.dstOffset.x = 0;
14589 copyRegion.dstOffset.y = 0;
14590 copyRegion.dstOffset.z = 0;
14591 copyRegion.extent.width = 1;
14592 copyRegion.extent.height = 1;
14593 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014594 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014595 EndCommandBuffer();
14596
14597 m_errorMonitor->VerifyFound();
14598
14599 vkDestroyImage(m_device->device(), srcImage, NULL);
14600 vkDestroyImage(m_device->device(), dstImage, NULL);
14601 vkFreeMemory(m_device->device(), srcMem, NULL);
14602 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014603}
14604
Karl Schultz6addd812016-02-02 17:17:23 -070014605TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14606 VkResult err;
14607 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014608
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014609 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14611 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014612
Mike Stroyana3082432015-09-25 13:39:21 -060014613 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014614
14615 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014616 VkImage srcImage;
14617 VkImage dstImage;
14618 VkDeviceMemory srcMem;
14619 VkDeviceMemory destMem;
14620 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014621
14622 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014623 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14624 image_create_info.pNext = NULL;
14625 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14626 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14627 image_create_info.extent.width = 32;
14628 image_create_info.extent.height = 32;
14629 image_create_info.extent.depth = 1;
14630 image_create_info.mipLevels = 1;
14631 image_create_info.arrayLayers = 1;
14632 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14633 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14634 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14635 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014636
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014637 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014638 ASSERT_VK_SUCCESS(err);
14639
Karl Schultzbdb75952016-04-19 11:36:49 -060014640 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14641
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014642 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014643 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014644 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014645 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014646
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014647 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014648 ASSERT_VK_SUCCESS(err);
14649
14650 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014651 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014652 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14653 memAlloc.pNext = NULL;
14654 memAlloc.allocationSize = 0;
14655 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014656
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014657 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014658 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014659 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014660 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014661 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014662 ASSERT_VK_SUCCESS(err);
14663
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014664 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014665 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014666 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014667 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014668 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014669 ASSERT_VK_SUCCESS(err);
14670
14671 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14672 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014673 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014674 ASSERT_VK_SUCCESS(err);
14675
14676 BeginCommandBuffer();
14677 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014678 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014679 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014680 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014681 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014682 copyRegion.srcOffset.x = 0;
14683 copyRegion.srcOffset.y = 0;
14684 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014685 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014686 copyRegion.dstSubresource.mipLevel = 0;
14687 copyRegion.dstSubresource.baseArrayLayer = 0;
14688 copyRegion.dstSubresource.layerCount = 0;
14689 copyRegion.dstOffset.x = 0;
14690 copyRegion.dstOffset.y = 0;
14691 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014692 copyRegion.extent.width = 1;
14693 copyRegion.extent.height = 1;
14694 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014695 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014696 EndCommandBuffer();
14697
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014698 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014699
Chia-I Wuf7458c52015-10-26 21:10:41 +080014700 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014701 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014702 vkFreeMemory(m_device->device(), srcMem, NULL);
14703 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014704}
14705
Karl Schultz6addd812016-02-02 17:17:23 -070014706TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14707 VkResult err;
14708 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014709
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14711 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014712
Mike Stroyana3082432015-09-25 13:39:21 -060014713 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014714
14715 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014716 VkImage srcImage;
14717 VkImage dstImage;
14718 VkDeviceMemory srcMem;
14719 VkDeviceMemory destMem;
14720 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014721
14722 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014723 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14724 image_create_info.pNext = NULL;
14725 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14726 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14727 image_create_info.extent.width = 32;
14728 image_create_info.extent.height = 1;
14729 image_create_info.extent.depth = 1;
14730 image_create_info.mipLevels = 1;
14731 image_create_info.arrayLayers = 1;
14732 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14733 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14734 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14735 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014736
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014737 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014738 ASSERT_VK_SUCCESS(err);
14739
Karl Schultz6addd812016-02-02 17:17:23 -070014740 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014741
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014742 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014743 ASSERT_VK_SUCCESS(err);
14744
14745 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014746 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014747 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14748 memAlloc.pNext = NULL;
14749 memAlloc.allocationSize = 0;
14750 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014751
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014752 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014753 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014754 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014755 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014756 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014757 ASSERT_VK_SUCCESS(err);
14758
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014759 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014760 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014761 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014762 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014763 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014764 ASSERT_VK_SUCCESS(err);
14765
14766 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14767 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014768 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014769 ASSERT_VK_SUCCESS(err);
14770
14771 BeginCommandBuffer();
14772 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014773 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14774 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014775 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014776 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014777 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014778 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014779 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014780 resolveRegion.srcOffset.x = 0;
14781 resolveRegion.srcOffset.y = 0;
14782 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014783 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014784 resolveRegion.dstSubresource.mipLevel = 0;
14785 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014786 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014787 resolveRegion.dstOffset.x = 0;
14788 resolveRegion.dstOffset.y = 0;
14789 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014790 resolveRegion.extent.width = 1;
14791 resolveRegion.extent.height = 1;
14792 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014793 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014794 EndCommandBuffer();
14795
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014796 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014797
Chia-I Wuf7458c52015-10-26 21:10:41 +080014798 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014799 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014800 vkFreeMemory(m_device->device(), srcMem, NULL);
14801 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014802}
14803
Karl Schultz6addd812016-02-02 17:17:23 -070014804TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14805 VkResult err;
14806 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014807
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14809 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014810
Mike Stroyana3082432015-09-25 13:39:21 -060014811 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014812
Chris Forbesa7530692016-05-08 12:35:39 +120014813 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014814 VkImage srcImage;
14815 VkImage dstImage;
14816 VkDeviceMemory srcMem;
14817 VkDeviceMemory destMem;
14818 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014819
14820 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014821 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14822 image_create_info.pNext = NULL;
14823 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14824 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14825 image_create_info.extent.width = 32;
14826 image_create_info.extent.height = 1;
14827 image_create_info.extent.depth = 1;
14828 image_create_info.mipLevels = 1;
14829 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014830 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014831 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14832 // Note: Some implementations expect color attachment usage for any
14833 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014834 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014835 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014836
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014837 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014838 ASSERT_VK_SUCCESS(err);
14839
Karl Schultz6addd812016-02-02 17:17:23 -070014840 // Note: Some implementations expect color attachment usage for any
14841 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014842 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014843
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014844 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014845 ASSERT_VK_SUCCESS(err);
14846
14847 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014848 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014849 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14850 memAlloc.pNext = NULL;
14851 memAlloc.allocationSize = 0;
14852 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014853
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014854 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014855 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014856 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014857 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014858 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014859 ASSERT_VK_SUCCESS(err);
14860
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014861 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014862 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014863 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014864 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014865 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014866 ASSERT_VK_SUCCESS(err);
14867
14868 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14869 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014870 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014871 ASSERT_VK_SUCCESS(err);
14872
14873 BeginCommandBuffer();
14874 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014875 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14876 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014877 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014878 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014879 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014880 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014881 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014882 resolveRegion.srcOffset.x = 0;
14883 resolveRegion.srcOffset.y = 0;
14884 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014885 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014886 resolveRegion.dstSubresource.mipLevel = 0;
14887 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014888 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014889 resolveRegion.dstOffset.x = 0;
14890 resolveRegion.dstOffset.y = 0;
14891 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014892 resolveRegion.extent.width = 1;
14893 resolveRegion.extent.height = 1;
14894 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014895 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014896 EndCommandBuffer();
14897
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014898 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014899
Chia-I Wuf7458c52015-10-26 21:10:41 +080014900 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014901 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014902 vkFreeMemory(m_device->device(), srcMem, NULL);
14903 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014904}
14905
Karl Schultz6addd812016-02-02 17:17:23 -070014906TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14907 VkResult err;
14908 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014909
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14911 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014912
Mike Stroyana3082432015-09-25 13:39:21 -060014913 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014914
14915 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014916 VkImage srcImage;
14917 VkImage dstImage;
14918 VkDeviceMemory srcMem;
14919 VkDeviceMemory destMem;
14920 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014921
14922 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014923 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14924 image_create_info.pNext = NULL;
14925 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14926 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14927 image_create_info.extent.width = 32;
14928 image_create_info.extent.height = 1;
14929 image_create_info.extent.depth = 1;
14930 image_create_info.mipLevels = 1;
14931 image_create_info.arrayLayers = 1;
14932 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14933 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14934 // Note: Some implementations expect color attachment usage for any
14935 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014936 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014937 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014938
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014939 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014940 ASSERT_VK_SUCCESS(err);
14941
Karl Schultz6addd812016-02-02 17:17:23 -070014942 // Set format to something other than source image
14943 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14944 // Note: Some implementations expect color attachment usage for any
14945 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014946 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014947 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014948
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014949 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014950 ASSERT_VK_SUCCESS(err);
14951
14952 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014953 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014954 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14955 memAlloc.pNext = NULL;
14956 memAlloc.allocationSize = 0;
14957 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014958
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014959 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014960 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014961 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014962 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014963 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014964 ASSERT_VK_SUCCESS(err);
14965
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014966 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014967 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014968 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014969 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014970 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014971 ASSERT_VK_SUCCESS(err);
14972
14973 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14974 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014975 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014976 ASSERT_VK_SUCCESS(err);
14977
14978 BeginCommandBuffer();
14979 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014980 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14981 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014982 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014983 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014984 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014985 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014986 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014987 resolveRegion.srcOffset.x = 0;
14988 resolveRegion.srcOffset.y = 0;
14989 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014990 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014991 resolveRegion.dstSubresource.mipLevel = 0;
14992 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014993 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014994 resolveRegion.dstOffset.x = 0;
14995 resolveRegion.dstOffset.y = 0;
14996 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014997 resolveRegion.extent.width = 1;
14998 resolveRegion.extent.height = 1;
14999 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015000 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015001 EndCommandBuffer();
15002
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015003 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015004
Chia-I Wuf7458c52015-10-26 21:10:41 +080015005 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015006 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015007 vkFreeMemory(m_device->device(), srcMem, NULL);
15008 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015009}
15010
Karl Schultz6addd812016-02-02 17:17:23 -070015011TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15012 VkResult err;
15013 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015014
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15016 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015017
Mike Stroyana3082432015-09-25 13:39:21 -060015018 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015019
15020 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015021 VkImage srcImage;
15022 VkImage dstImage;
15023 VkDeviceMemory srcMem;
15024 VkDeviceMemory destMem;
15025 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015026
15027 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015028 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15029 image_create_info.pNext = NULL;
15030 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15031 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15032 image_create_info.extent.width = 32;
15033 image_create_info.extent.height = 1;
15034 image_create_info.extent.depth = 1;
15035 image_create_info.mipLevels = 1;
15036 image_create_info.arrayLayers = 1;
15037 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15038 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15039 // Note: Some implementations expect color attachment usage for any
15040 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015041 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015042 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015043
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015044 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015045 ASSERT_VK_SUCCESS(err);
15046
Karl Schultz6addd812016-02-02 17:17:23 -070015047 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15048 // Note: Some implementations expect color attachment usage for any
15049 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015050 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015051 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015052
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015053 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015054 ASSERT_VK_SUCCESS(err);
15055
15056 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015057 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015058 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15059 memAlloc.pNext = NULL;
15060 memAlloc.allocationSize = 0;
15061 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015062
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015063 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015064 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015065 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015066 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015067 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015068 ASSERT_VK_SUCCESS(err);
15069
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015070 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015071 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015072 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015073 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015074 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015075 ASSERT_VK_SUCCESS(err);
15076
15077 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15078 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015079 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015080 ASSERT_VK_SUCCESS(err);
15081
15082 BeginCommandBuffer();
15083 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015084 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15085 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015086 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015087 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015088 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015089 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015090 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015091 resolveRegion.srcOffset.x = 0;
15092 resolveRegion.srcOffset.y = 0;
15093 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015094 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015095 resolveRegion.dstSubresource.mipLevel = 0;
15096 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015097 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015098 resolveRegion.dstOffset.x = 0;
15099 resolveRegion.dstOffset.y = 0;
15100 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015101 resolveRegion.extent.width = 1;
15102 resolveRegion.extent.height = 1;
15103 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015104 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015105 EndCommandBuffer();
15106
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015107 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015108
Chia-I Wuf7458c52015-10-26 21:10:41 +080015109 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015110 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015111 vkFreeMemory(m_device->device(), srcMem, NULL);
15112 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015113}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015114
Karl Schultz6addd812016-02-02 17:17:23 -070015115TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015116 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015117 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15118 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015119 // The image format check comes 2nd in validation so we trigger it first,
15120 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015121 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015122
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15124 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015125
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015126 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015127
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015128 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015129 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15130 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015131
15132 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015133 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15134 ds_pool_ci.pNext = NULL;
15135 ds_pool_ci.maxSets = 1;
15136 ds_pool_ci.poolSizeCount = 1;
15137 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015138
15139 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015140 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015141 ASSERT_VK_SUCCESS(err);
15142
15143 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015144 dsl_binding.binding = 0;
15145 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15146 dsl_binding.descriptorCount = 1;
15147 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15148 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015149
15150 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015151 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15152 ds_layout_ci.pNext = NULL;
15153 ds_layout_ci.bindingCount = 1;
15154 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015155 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015156 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015157 ASSERT_VK_SUCCESS(err);
15158
15159 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015160 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015161 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015162 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015163 alloc_info.descriptorPool = ds_pool;
15164 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015165 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015166 ASSERT_VK_SUCCESS(err);
15167
Karl Schultz6addd812016-02-02 17:17:23 -070015168 VkImage image_bad;
15169 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015170 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015171 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015172 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015173 const int32_t tex_width = 32;
15174 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015175
15176 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015177 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15178 image_create_info.pNext = NULL;
15179 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15180 image_create_info.format = tex_format_bad;
15181 image_create_info.extent.width = tex_width;
15182 image_create_info.extent.height = tex_height;
15183 image_create_info.extent.depth = 1;
15184 image_create_info.mipLevels = 1;
15185 image_create_info.arrayLayers = 1;
15186 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15187 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015188 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015189 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015191 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015192 ASSERT_VK_SUCCESS(err);
15193 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015194 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15195 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015196 ASSERT_VK_SUCCESS(err);
15197
15198 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015199 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015200 image_view_create_info.image = image_bad;
15201 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15202 image_view_create_info.format = tex_format_bad;
15203 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15204 image_view_create_info.subresourceRange.baseMipLevel = 0;
15205 image_view_create_info.subresourceRange.layerCount = 1;
15206 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015207 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015208
15209 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015210 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015211
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015212 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015213
Chia-I Wuf7458c52015-10-26 21:10:41 +080015214 vkDestroyImage(m_device->device(), image_bad, NULL);
15215 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015216 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15217 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015218}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015219
15220TEST_F(VkLayerTest, ClearImageErrors) {
15221 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15222 "ClearDepthStencilImage with a color image.");
15223
15224 ASSERT_NO_FATAL_FAILURE(InitState());
15225 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15226
15227 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15228 BeginCommandBuffer();
15229 m_commandBuffer->EndRenderPass();
15230
15231 // Color image
15232 VkClearColorValue clear_color;
15233 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15234 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15235 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15236 const int32_t img_width = 32;
15237 const int32_t img_height = 32;
15238 VkImageCreateInfo image_create_info = {};
15239 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15240 image_create_info.pNext = NULL;
15241 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15242 image_create_info.format = color_format;
15243 image_create_info.extent.width = img_width;
15244 image_create_info.extent.height = img_height;
15245 image_create_info.extent.depth = 1;
15246 image_create_info.mipLevels = 1;
15247 image_create_info.arrayLayers = 1;
15248 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15249 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15250 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15251
15252 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015253 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015255 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015256
15257 // Depth/Stencil image
15258 VkClearDepthStencilValue clear_value = {0};
15259 reqs = 0; // don't need HOST_VISIBLE DS image
15260 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15261 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15262 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15263 ds_image_create_info.extent.width = 64;
15264 ds_image_create_info.extent.height = 64;
15265 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15266 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15267
15268 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015269 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015271 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 -060015272
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015274
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015275 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015276 &color_range);
15277
15278 m_errorMonitor->VerifyFound();
15279
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15281 "image created without "
15282 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015283
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015284 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015285 &color_range);
15286
15287 m_errorMonitor->VerifyFound();
15288
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015289 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15291 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015292
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015293 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15294 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015295
15296 m_errorMonitor->VerifyFound();
15297}
Tobin Ehliscde08892015-09-22 10:11:37 -060015298#endif // IMAGE_TESTS
15299
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015300
15301// WSI Enabled Tests
15302//
Chris Forbes09368e42016-10-13 11:59:22 +130015303#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015304TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15305
15306#if defined(VK_USE_PLATFORM_XCB_KHR)
15307 VkSurfaceKHR surface = VK_NULL_HANDLE;
15308
15309 VkResult err;
15310 bool pass;
15311 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15312 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15313 // uint32_t swapchain_image_count = 0;
15314 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15315 // uint32_t image_index = 0;
15316 // VkPresentInfoKHR present_info = {};
15317
15318 ASSERT_NO_FATAL_FAILURE(InitState());
15319
15320 // Use the create function from one of the VK_KHR_*_surface extension in
15321 // order to create a surface, testing all known errors in the process,
15322 // before successfully creating a surface:
15323 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15325 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15326 pass = (err != VK_SUCCESS);
15327 ASSERT_TRUE(pass);
15328 m_errorMonitor->VerifyFound();
15329
15330 // Next, try to create a surface with the wrong
15331 // VkXcbSurfaceCreateInfoKHR::sType:
15332 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15333 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15335 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15336 pass = (err != VK_SUCCESS);
15337 ASSERT_TRUE(pass);
15338 m_errorMonitor->VerifyFound();
15339
15340 // Create a native window, and then correctly create a surface:
15341 xcb_connection_t *connection;
15342 xcb_screen_t *screen;
15343 xcb_window_t xcb_window;
15344 xcb_intern_atom_reply_t *atom_wm_delete_window;
15345
15346 const xcb_setup_t *setup;
15347 xcb_screen_iterator_t iter;
15348 int scr;
15349 uint32_t value_mask, value_list[32];
15350 int width = 1;
15351 int height = 1;
15352
15353 connection = xcb_connect(NULL, &scr);
15354 ASSERT_TRUE(connection != NULL);
15355 setup = xcb_get_setup(connection);
15356 iter = xcb_setup_roots_iterator(setup);
15357 while (scr-- > 0)
15358 xcb_screen_next(&iter);
15359 screen = iter.data;
15360
15361 xcb_window = xcb_generate_id(connection);
15362
15363 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15364 value_list[0] = screen->black_pixel;
15365 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15366
15367 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15368 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15369
15370 /* Magic code that will send notification when window is destroyed */
15371 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15372 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15373
15374 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15375 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15376 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15377 free(reply);
15378
15379 xcb_map_window(connection, xcb_window);
15380
15381 // Force the x/y coordinates to 100,100 results are identical in consecutive
15382 // runs
15383 const uint32_t coords[] = { 100, 100 };
15384 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15385
15386 // Finally, try to correctly create a surface:
15387 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15388 xcb_create_info.pNext = NULL;
15389 xcb_create_info.flags = 0;
15390 xcb_create_info.connection = connection;
15391 xcb_create_info.window = xcb_window;
15392 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15393 pass = (err == VK_SUCCESS);
15394 ASSERT_TRUE(pass);
15395
15396 // Check if surface supports presentation:
15397
15398 // 1st, do so without having queried the queue families:
15399 VkBool32 supported = false;
15400 // TODO: Get the following error to come out:
15401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15402 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15403 "function");
15404 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15405 pass = (err != VK_SUCCESS);
15406 // ASSERT_TRUE(pass);
15407 // m_errorMonitor->VerifyFound();
15408
15409 // Next, query a queue family index that's too large:
15410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15411 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15412 pass = (err != VK_SUCCESS);
15413 ASSERT_TRUE(pass);
15414 m_errorMonitor->VerifyFound();
15415
15416 // Finally, do so correctly:
15417 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15418 // SUPPORTED
15419 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15420 pass = (err == VK_SUCCESS);
15421 ASSERT_TRUE(pass);
15422
15423 // Before proceeding, try to create a swapchain without having called
15424 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15425 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15426 swapchain_create_info.pNext = NULL;
15427 swapchain_create_info.flags = 0;
15428 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15429 swapchain_create_info.surface = surface;
15430 swapchain_create_info.imageArrayLayers = 1;
15431 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15432 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15434 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15435 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15436 pass = (err != VK_SUCCESS);
15437 ASSERT_TRUE(pass);
15438 m_errorMonitor->VerifyFound();
15439
15440 // Get the surface capabilities:
15441 VkSurfaceCapabilitiesKHR surface_capabilities;
15442
15443 // Do so correctly (only error logged by this entrypoint is if the
15444 // extension isn't enabled):
15445 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15446 pass = (err == VK_SUCCESS);
15447 ASSERT_TRUE(pass);
15448
15449 // Get the surface formats:
15450 uint32_t surface_format_count;
15451
15452 // First, try without a pointer to surface_format_count:
15453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15454 "specified as NULL");
15455 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15456 pass = (err == VK_SUCCESS);
15457 ASSERT_TRUE(pass);
15458 m_errorMonitor->VerifyFound();
15459
15460 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15461 // correctly done a 1st try (to get the count):
15462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15463 surface_format_count = 0;
15464 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15465 pass = (err == VK_SUCCESS);
15466 ASSERT_TRUE(pass);
15467 m_errorMonitor->VerifyFound();
15468
15469 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15470 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15471 pass = (err == VK_SUCCESS);
15472 ASSERT_TRUE(pass);
15473
15474 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15475 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15476
15477 // Next, do a 2nd try with surface_format_count being set too high:
15478 surface_format_count += 5;
15479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15480 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15481 pass = (err == VK_SUCCESS);
15482 ASSERT_TRUE(pass);
15483 m_errorMonitor->VerifyFound();
15484
15485 // Finally, do a correct 1st and 2nd try:
15486 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15487 pass = (err == VK_SUCCESS);
15488 ASSERT_TRUE(pass);
15489 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15490 pass = (err == VK_SUCCESS);
15491 ASSERT_TRUE(pass);
15492
15493 // Get the surface present modes:
15494 uint32_t surface_present_mode_count;
15495
15496 // First, try without a pointer to surface_format_count:
15497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15498 "specified as NULL");
15499
15500 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15501 pass = (err == VK_SUCCESS);
15502 ASSERT_TRUE(pass);
15503 m_errorMonitor->VerifyFound();
15504
15505 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15506 // correctly done a 1st try (to get the count):
15507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15508 surface_present_mode_count = 0;
15509 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15510 (VkPresentModeKHR *)&surface_present_mode_count);
15511 pass = (err == VK_SUCCESS);
15512 ASSERT_TRUE(pass);
15513 m_errorMonitor->VerifyFound();
15514
15515 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15516 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15517 pass = (err == VK_SUCCESS);
15518 ASSERT_TRUE(pass);
15519
15520 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15521 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15522
15523 // Next, do a 2nd try with surface_format_count being set too high:
15524 surface_present_mode_count += 5;
15525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15526 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15527 pass = (err == VK_SUCCESS);
15528 ASSERT_TRUE(pass);
15529 m_errorMonitor->VerifyFound();
15530
15531 // Finally, do a correct 1st and 2nd try:
15532 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15533 pass = (err == VK_SUCCESS);
15534 ASSERT_TRUE(pass);
15535 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15536 pass = (err == VK_SUCCESS);
15537 ASSERT_TRUE(pass);
15538
15539 // Create a swapchain:
15540
15541 // First, try without a pointer to swapchain_create_info:
15542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15543 "specified as NULL");
15544
15545 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15546 pass = (err != VK_SUCCESS);
15547 ASSERT_TRUE(pass);
15548 m_errorMonitor->VerifyFound();
15549
15550 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15551 // sType:
15552 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15554
15555 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15556 pass = (err != VK_SUCCESS);
15557 ASSERT_TRUE(pass);
15558 m_errorMonitor->VerifyFound();
15559
15560 // Next, call with a NULL swapchain pointer:
15561 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15562 swapchain_create_info.pNext = NULL;
15563 swapchain_create_info.flags = 0;
15564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15565 "specified as NULL");
15566
15567 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15568 pass = (err != VK_SUCCESS);
15569 ASSERT_TRUE(pass);
15570 m_errorMonitor->VerifyFound();
15571
15572 // TODO: Enhance swapchain layer so that
15573 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15574
15575 // Next, call with a queue family index that's too large:
15576 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15577 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15578 swapchain_create_info.queueFamilyIndexCount = 2;
15579 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15581 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15582 pass = (err != VK_SUCCESS);
15583 ASSERT_TRUE(pass);
15584 m_errorMonitor->VerifyFound();
15585
15586 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15587 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15588 swapchain_create_info.queueFamilyIndexCount = 1;
15589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15590 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15591 "pCreateInfo->pQueueFamilyIndices).");
15592 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15593 pass = (err != VK_SUCCESS);
15594 ASSERT_TRUE(pass);
15595 m_errorMonitor->VerifyFound();
15596
15597 // Next, call with an invalid imageSharingMode:
15598 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15599 swapchain_create_info.queueFamilyIndexCount = 1;
15600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15601 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15602 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15603 pass = (err != VK_SUCCESS);
15604 ASSERT_TRUE(pass);
15605 m_errorMonitor->VerifyFound();
15606 // Fix for the future:
15607 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15608 // SUPPORTED
15609 swapchain_create_info.queueFamilyIndexCount = 0;
15610 queueFamilyIndex[0] = 0;
15611 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15612
15613 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15614 // Get the images from a swapchain:
15615 // Acquire an image from a swapchain:
15616 // Present an image to a swapchain:
15617 // Destroy the swapchain:
15618
15619 // TODOs:
15620 //
15621 // - Try destroying the device without first destroying the swapchain
15622 //
15623 // - Try destroying the device without first destroying the surface
15624 //
15625 // - Try destroying the surface without first destroying the swapchain
15626
15627 // Destroy the surface:
15628 vkDestroySurfaceKHR(instance(), surface, NULL);
15629
15630 // Tear down the window:
15631 xcb_destroy_window(connection, xcb_window);
15632 xcb_disconnect(connection);
15633
15634#else // VK_USE_PLATFORM_XCB_KHR
15635 return;
15636#endif // VK_USE_PLATFORM_XCB_KHR
15637}
Chris Forbes09368e42016-10-13 11:59:22 +130015638#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015639
15640//
15641// POSITIVE VALIDATION TESTS
15642//
15643// These tests do not expect to encounter ANY validation errors pass only if this is true
15644
Tobin Ehlise0006882016-11-03 10:14:28 -060015645TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15646 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15647 "by a transition in the primary.");
15648 VkResult err;
15649 m_errorMonitor->ExpectSuccess();
15650 ASSERT_NO_FATAL_FAILURE(InitState());
15651 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15652 // Allocate a secondary and primary cmd buffer
15653 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15654 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15655 command_buffer_allocate_info.commandPool = m_commandPool;
15656 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15657 command_buffer_allocate_info.commandBufferCount = 1;
15658
15659 VkCommandBuffer secondary_command_buffer;
15660 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15661 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15662 VkCommandBuffer primary_command_buffer;
15663 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15664 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15665 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15666 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15667 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15668 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15669 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15670
15671 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15672 ASSERT_VK_SUCCESS(err);
15673 VkImageObj image(m_device);
15674 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15675 ASSERT_TRUE(image.initialized());
15676 VkImageMemoryBarrier img_barrier = {};
15677 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15678 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15679 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15680 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15681 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15682 img_barrier.image = image.handle();
15683 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15684 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15685 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15686 img_barrier.subresourceRange.baseArrayLayer = 0;
15687 img_barrier.subresourceRange.baseMipLevel = 0;
15688 img_barrier.subresourceRange.layerCount = 1;
15689 img_barrier.subresourceRange.levelCount = 1;
15690 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15691 0, nullptr, 1, &img_barrier);
15692 err = vkEndCommandBuffer(secondary_command_buffer);
15693 ASSERT_VK_SUCCESS(err);
15694
15695 // Now update primary cmd buffer to execute secondary and transitions image
15696 command_buffer_begin_info.pInheritanceInfo = nullptr;
15697 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15698 ASSERT_VK_SUCCESS(err);
15699 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15700 VkImageMemoryBarrier img_barrier2 = {};
15701 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15702 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15703 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15704 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15705 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15706 img_barrier2.image = image.handle();
15707 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15708 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15709 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15710 img_barrier2.subresourceRange.baseArrayLayer = 0;
15711 img_barrier2.subresourceRange.baseMipLevel = 0;
15712 img_barrier2.subresourceRange.layerCount = 1;
15713 img_barrier2.subresourceRange.levelCount = 1;
15714 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15715 nullptr, 1, &img_barrier2);
15716 err = vkEndCommandBuffer(primary_command_buffer);
15717 ASSERT_VK_SUCCESS(err);
15718 VkSubmitInfo submit_info = {};
15719 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15720 submit_info.commandBufferCount = 1;
15721 submit_info.pCommandBuffers = &primary_command_buffer;
15722 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15723 ASSERT_VK_SUCCESS(err);
15724 m_errorMonitor->VerifyNotFound();
15725 err = vkDeviceWaitIdle(m_device->device());
15726 ASSERT_VK_SUCCESS(err);
15727 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15728 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15729}
15730
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015731// This is a positive test. No failures are expected.
15732TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15733 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15734 "is ignoring VkWriteDescriptorSet members that are not "
15735 "related to the descriptor type specified by "
15736 "VkWriteDescriptorSet::descriptorType. Correct "
15737 "validation behavior will result in the test running to "
15738 "completion without validation errors.");
15739
15740 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15741
15742 ASSERT_NO_FATAL_FAILURE(InitState());
15743
15744 // Image Case
15745 {
15746 m_errorMonitor->ExpectSuccess();
15747
15748 VkImage image;
15749 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15750 const int32_t tex_width = 32;
15751 const int32_t tex_height = 32;
15752 VkImageCreateInfo image_create_info = {};
15753 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15754 image_create_info.pNext = NULL;
15755 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15756 image_create_info.format = tex_format;
15757 image_create_info.extent.width = tex_width;
15758 image_create_info.extent.height = tex_height;
15759 image_create_info.extent.depth = 1;
15760 image_create_info.mipLevels = 1;
15761 image_create_info.arrayLayers = 1;
15762 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15763 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15764 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15765 image_create_info.flags = 0;
15766 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15767 ASSERT_VK_SUCCESS(err);
15768
15769 VkMemoryRequirements memory_reqs;
15770 VkDeviceMemory image_memory;
15771 bool pass;
15772 VkMemoryAllocateInfo memory_info = {};
15773 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15774 memory_info.pNext = NULL;
15775 memory_info.allocationSize = 0;
15776 memory_info.memoryTypeIndex = 0;
15777 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15778 memory_info.allocationSize = memory_reqs.size;
15779 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15780 ASSERT_TRUE(pass);
15781 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15782 ASSERT_VK_SUCCESS(err);
15783 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15784 ASSERT_VK_SUCCESS(err);
15785
15786 VkImageViewCreateInfo image_view_create_info = {};
15787 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15788 image_view_create_info.image = image;
15789 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15790 image_view_create_info.format = tex_format;
15791 image_view_create_info.subresourceRange.layerCount = 1;
15792 image_view_create_info.subresourceRange.baseMipLevel = 0;
15793 image_view_create_info.subresourceRange.levelCount = 1;
15794 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15795
15796 VkImageView view;
15797 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15798 ASSERT_VK_SUCCESS(err);
15799
15800 VkDescriptorPoolSize ds_type_count = {};
15801 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15802 ds_type_count.descriptorCount = 1;
15803
15804 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15805 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15806 ds_pool_ci.pNext = NULL;
15807 ds_pool_ci.maxSets = 1;
15808 ds_pool_ci.poolSizeCount = 1;
15809 ds_pool_ci.pPoolSizes = &ds_type_count;
15810
15811 VkDescriptorPool ds_pool;
15812 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15813 ASSERT_VK_SUCCESS(err);
15814
15815 VkDescriptorSetLayoutBinding dsl_binding = {};
15816 dsl_binding.binding = 0;
15817 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15818 dsl_binding.descriptorCount = 1;
15819 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15820 dsl_binding.pImmutableSamplers = NULL;
15821
15822 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15823 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15824 ds_layout_ci.pNext = NULL;
15825 ds_layout_ci.bindingCount = 1;
15826 ds_layout_ci.pBindings = &dsl_binding;
15827 VkDescriptorSetLayout ds_layout;
15828 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15829 ASSERT_VK_SUCCESS(err);
15830
15831 VkDescriptorSet descriptor_set;
15832 VkDescriptorSetAllocateInfo alloc_info = {};
15833 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15834 alloc_info.descriptorSetCount = 1;
15835 alloc_info.descriptorPool = ds_pool;
15836 alloc_info.pSetLayouts = &ds_layout;
15837 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15838 ASSERT_VK_SUCCESS(err);
15839
15840 VkDescriptorImageInfo image_info = {};
15841 image_info.imageView = view;
15842 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15843
15844 VkWriteDescriptorSet descriptor_write;
15845 memset(&descriptor_write, 0, sizeof(descriptor_write));
15846 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15847 descriptor_write.dstSet = descriptor_set;
15848 descriptor_write.dstBinding = 0;
15849 descriptor_write.descriptorCount = 1;
15850 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15851 descriptor_write.pImageInfo = &image_info;
15852
15853 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15854 // be
15855 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15856 // This will most likely produce a crash if the parameter_validation
15857 // layer
15858 // does not correctly ignore pBufferInfo.
15859 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15860 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15861
15862 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15863
15864 m_errorMonitor->VerifyNotFound();
15865
15866 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15867 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15868 vkDestroyImageView(m_device->device(), view, NULL);
15869 vkDestroyImage(m_device->device(), image, NULL);
15870 vkFreeMemory(m_device->device(), image_memory, NULL);
15871 }
15872
15873 // Buffer Case
15874 {
15875 m_errorMonitor->ExpectSuccess();
15876
15877 VkBuffer buffer;
15878 uint32_t queue_family_index = 0;
15879 VkBufferCreateInfo buffer_create_info = {};
15880 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15881 buffer_create_info.size = 1024;
15882 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15883 buffer_create_info.queueFamilyIndexCount = 1;
15884 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15885
15886 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15887 ASSERT_VK_SUCCESS(err);
15888
15889 VkMemoryRequirements memory_reqs;
15890 VkDeviceMemory buffer_memory;
15891 bool pass;
15892 VkMemoryAllocateInfo memory_info = {};
15893 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15894 memory_info.pNext = NULL;
15895 memory_info.allocationSize = 0;
15896 memory_info.memoryTypeIndex = 0;
15897
15898 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15899 memory_info.allocationSize = memory_reqs.size;
15900 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15901 ASSERT_TRUE(pass);
15902
15903 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15904 ASSERT_VK_SUCCESS(err);
15905 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15906 ASSERT_VK_SUCCESS(err);
15907
15908 VkDescriptorPoolSize ds_type_count = {};
15909 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15910 ds_type_count.descriptorCount = 1;
15911
15912 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15913 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15914 ds_pool_ci.pNext = NULL;
15915 ds_pool_ci.maxSets = 1;
15916 ds_pool_ci.poolSizeCount = 1;
15917 ds_pool_ci.pPoolSizes = &ds_type_count;
15918
15919 VkDescriptorPool ds_pool;
15920 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15921 ASSERT_VK_SUCCESS(err);
15922
15923 VkDescriptorSetLayoutBinding dsl_binding = {};
15924 dsl_binding.binding = 0;
15925 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15926 dsl_binding.descriptorCount = 1;
15927 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15928 dsl_binding.pImmutableSamplers = NULL;
15929
15930 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15931 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15932 ds_layout_ci.pNext = NULL;
15933 ds_layout_ci.bindingCount = 1;
15934 ds_layout_ci.pBindings = &dsl_binding;
15935 VkDescriptorSetLayout ds_layout;
15936 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15937 ASSERT_VK_SUCCESS(err);
15938
15939 VkDescriptorSet descriptor_set;
15940 VkDescriptorSetAllocateInfo alloc_info = {};
15941 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15942 alloc_info.descriptorSetCount = 1;
15943 alloc_info.descriptorPool = ds_pool;
15944 alloc_info.pSetLayouts = &ds_layout;
15945 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15946 ASSERT_VK_SUCCESS(err);
15947
15948 VkDescriptorBufferInfo buffer_info = {};
15949 buffer_info.buffer = buffer;
15950 buffer_info.offset = 0;
15951 buffer_info.range = 1024;
15952
15953 VkWriteDescriptorSet descriptor_write;
15954 memset(&descriptor_write, 0, sizeof(descriptor_write));
15955 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15956 descriptor_write.dstSet = descriptor_set;
15957 descriptor_write.dstBinding = 0;
15958 descriptor_write.descriptorCount = 1;
15959 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15960 descriptor_write.pBufferInfo = &buffer_info;
15961
15962 // Set pImageInfo and pTexelBufferView to invalid values, which should
15963 // be
15964 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15965 // This will most likely produce a crash if the parameter_validation
15966 // layer
15967 // does not correctly ignore pImageInfo.
15968 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15969 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15970
15971 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15972
15973 m_errorMonitor->VerifyNotFound();
15974
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015975 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15976 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15977 vkDestroyBuffer(m_device->device(), buffer, NULL);
15978 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15979 }
15980
15981 // Texel Buffer Case
15982 {
15983 m_errorMonitor->ExpectSuccess();
15984
15985 VkBuffer buffer;
15986 uint32_t queue_family_index = 0;
15987 VkBufferCreateInfo buffer_create_info = {};
15988 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15989 buffer_create_info.size = 1024;
15990 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15991 buffer_create_info.queueFamilyIndexCount = 1;
15992 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15993
15994 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15995 ASSERT_VK_SUCCESS(err);
15996
15997 VkMemoryRequirements memory_reqs;
15998 VkDeviceMemory buffer_memory;
15999 bool pass;
16000 VkMemoryAllocateInfo memory_info = {};
16001 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16002 memory_info.pNext = NULL;
16003 memory_info.allocationSize = 0;
16004 memory_info.memoryTypeIndex = 0;
16005
16006 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16007 memory_info.allocationSize = memory_reqs.size;
16008 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16009 ASSERT_TRUE(pass);
16010
16011 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16012 ASSERT_VK_SUCCESS(err);
16013 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16014 ASSERT_VK_SUCCESS(err);
16015
16016 VkBufferViewCreateInfo buff_view_ci = {};
16017 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16018 buff_view_ci.buffer = buffer;
16019 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16020 buff_view_ci.range = VK_WHOLE_SIZE;
16021 VkBufferView buffer_view;
16022 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16023
16024 VkDescriptorPoolSize ds_type_count = {};
16025 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16026 ds_type_count.descriptorCount = 1;
16027
16028 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16029 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16030 ds_pool_ci.pNext = NULL;
16031 ds_pool_ci.maxSets = 1;
16032 ds_pool_ci.poolSizeCount = 1;
16033 ds_pool_ci.pPoolSizes = &ds_type_count;
16034
16035 VkDescriptorPool ds_pool;
16036 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16037 ASSERT_VK_SUCCESS(err);
16038
16039 VkDescriptorSetLayoutBinding dsl_binding = {};
16040 dsl_binding.binding = 0;
16041 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16042 dsl_binding.descriptorCount = 1;
16043 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16044 dsl_binding.pImmutableSamplers = NULL;
16045
16046 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16047 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16048 ds_layout_ci.pNext = NULL;
16049 ds_layout_ci.bindingCount = 1;
16050 ds_layout_ci.pBindings = &dsl_binding;
16051 VkDescriptorSetLayout ds_layout;
16052 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16053 ASSERT_VK_SUCCESS(err);
16054
16055 VkDescriptorSet descriptor_set;
16056 VkDescriptorSetAllocateInfo alloc_info = {};
16057 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16058 alloc_info.descriptorSetCount = 1;
16059 alloc_info.descriptorPool = ds_pool;
16060 alloc_info.pSetLayouts = &ds_layout;
16061 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16062 ASSERT_VK_SUCCESS(err);
16063
16064 VkWriteDescriptorSet descriptor_write;
16065 memset(&descriptor_write, 0, sizeof(descriptor_write));
16066 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16067 descriptor_write.dstSet = descriptor_set;
16068 descriptor_write.dstBinding = 0;
16069 descriptor_write.descriptorCount = 1;
16070 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16071 descriptor_write.pTexelBufferView = &buffer_view;
16072
16073 // Set pImageInfo and pBufferInfo to invalid values, which should be
16074 // ignored for descriptorType ==
16075 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16076 // This will most likely produce a crash if the parameter_validation
16077 // layer
16078 // does not correctly ignore pImageInfo and pBufferInfo.
16079 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16080 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16081
16082 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16083
16084 m_errorMonitor->VerifyNotFound();
16085
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016086 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16087 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16088 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16089 vkDestroyBuffer(m_device->device(), buffer, NULL);
16090 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16091 }
16092}
16093
Tobin Ehlisf7428442016-10-25 07:58:24 -060016094TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16095 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16096
16097 ASSERT_NO_FATAL_FAILURE(InitState());
16098 // Create layout where two binding #s are "1"
16099 static const uint32_t NUM_BINDINGS = 3;
16100 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16101 dsl_binding[0].binding = 1;
16102 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16103 dsl_binding[0].descriptorCount = 1;
16104 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16105 dsl_binding[0].pImmutableSamplers = NULL;
16106 dsl_binding[1].binding = 0;
16107 dsl_binding[1].descriptorCount = 1;
16108 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16109 dsl_binding[1].descriptorCount = 1;
16110 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16111 dsl_binding[1].pImmutableSamplers = NULL;
16112 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16113 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16114 dsl_binding[2].descriptorCount = 1;
16115 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16116 dsl_binding[2].pImmutableSamplers = NULL;
16117
16118 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16119 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16120 ds_layout_ci.pNext = NULL;
16121 ds_layout_ci.bindingCount = NUM_BINDINGS;
16122 ds_layout_ci.pBindings = dsl_binding;
16123 VkDescriptorSetLayout ds_layout;
16124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16125 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16126 m_errorMonitor->VerifyFound();
16127}
16128
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016129TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016130 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16131
16132 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016133
16134 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016135
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016136 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16137
16138 {
16139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16140 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16141 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16142 m_errorMonitor->VerifyFound();
16143 }
16144
16145 {
16146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16147 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16148 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16149 m_errorMonitor->VerifyFound();
16150 }
16151
16152 {
16153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16154 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16155 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16156 m_errorMonitor->VerifyFound();
16157 }
16158
16159 {
16160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16161 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16162 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16163 m_errorMonitor->VerifyFound();
16164 }
16165
16166 {
16167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16168 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16169 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16170 m_errorMonitor->VerifyFound();
16171 }
16172
16173 {
16174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16175 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16176 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16177 m_errorMonitor->VerifyFound();
16178 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016179
16180 {
16181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16182 VkRect2D scissor = {{-1, 0}, {16, 16}};
16183 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16184 m_errorMonitor->VerifyFound();
16185 }
16186
16187 {
16188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16189 VkRect2D scissor = {{0, -2}, {16, 16}};
16190 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16191 m_errorMonitor->VerifyFound();
16192 }
16193
16194 {
16195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16196 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16197 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16198 m_errorMonitor->VerifyFound();
16199 }
16200
16201 {
16202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16203 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16204 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16205 m_errorMonitor->VerifyFound();
16206 }
16207
16208 EndCommandBuffer();
16209}
16210
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016211// This is a positive test. No failures are expected.
16212TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16213 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16214 VkResult err;
16215
16216 ASSERT_NO_FATAL_FAILURE(InitState());
16217 m_errorMonitor->ExpectSuccess();
16218 VkDescriptorPoolSize ds_type_count = {};
16219 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16220 ds_type_count.descriptorCount = 2;
16221
16222 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16223 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16224 ds_pool_ci.pNext = NULL;
16225 ds_pool_ci.maxSets = 1;
16226 ds_pool_ci.poolSizeCount = 1;
16227 ds_pool_ci.pPoolSizes = &ds_type_count;
16228
16229 VkDescriptorPool ds_pool;
16230 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16231 ASSERT_VK_SUCCESS(err);
16232
16233 // Create layout with two uniform buffer descriptors w/ empty binding between them
16234 static const uint32_t NUM_BINDINGS = 3;
16235 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16236 dsl_binding[0].binding = 0;
16237 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16238 dsl_binding[0].descriptorCount = 1;
16239 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16240 dsl_binding[0].pImmutableSamplers = NULL;
16241 dsl_binding[1].binding = 1;
16242 dsl_binding[1].descriptorCount = 0; // empty binding
16243 dsl_binding[2].binding = 2;
16244 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16245 dsl_binding[2].descriptorCount = 1;
16246 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16247 dsl_binding[2].pImmutableSamplers = NULL;
16248
16249 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16250 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16251 ds_layout_ci.pNext = NULL;
16252 ds_layout_ci.bindingCount = NUM_BINDINGS;
16253 ds_layout_ci.pBindings = dsl_binding;
16254 VkDescriptorSetLayout ds_layout;
16255 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16256 ASSERT_VK_SUCCESS(err);
16257
16258 VkDescriptorSet descriptor_set = {};
16259 VkDescriptorSetAllocateInfo alloc_info = {};
16260 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16261 alloc_info.descriptorSetCount = 1;
16262 alloc_info.descriptorPool = ds_pool;
16263 alloc_info.pSetLayouts = &ds_layout;
16264 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16265 ASSERT_VK_SUCCESS(err);
16266
16267 // Create a buffer to be used for update
16268 VkBufferCreateInfo buff_ci = {};
16269 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16270 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16271 buff_ci.size = 256;
16272 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16273 VkBuffer buffer;
16274 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16275 ASSERT_VK_SUCCESS(err);
16276 // Have to bind memory to buffer before descriptor update
16277 VkMemoryAllocateInfo mem_alloc = {};
16278 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16279 mem_alloc.pNext = NULL;
16280 mem_alloc.allocationSize = 512; // one allocation for both buffers
16281 mem_alloc.memoryTypeIndex = 0;
16282
16283 VkMemoryRequirements mem_reqs;
16284 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16285 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16286 if (!pass) {
16287 vkDestroyBuffer(m_device->device(), buffer, NULL);
16288 return;
16289 }
16290
16291 VkDeviceMemory mem;
16292 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16293 ASSERT_VK_SUCCESS(err);
16294 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16295 ASSERT_VK_SUCCESS(err);
16296
16297 // Only update the descriptor at binding 2
16298 VkDescriptorBufferInfo buff_info = {};
16299 buff_info.buffer = buffer;
16300 buff_info.offset = 0;
16301 buff_info.range = VK_WHOLE_SIZE;
16302 VkWriteDescriptorSet descriptor_write = {};
16303 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16304 descriptor_write.dstBinding = 2;
16305 descriptor_write.descriptorCount = 1;
16306 descriptor_write.pTexelBufferView = nullptr;
16307 descriptor_write.pBufferInfo = &buff_info;
16308 descriptor_write.pImageInfo = nullptr;
16309 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16310 descriptor_write.dstSet = descriptor_set;
16311
16312 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16313
16314 m_errorMonitor->VerifyNotFound();
16315 // Cleanup
16316 vkFreeMemory(m_device->device(), mem, NULL);
16317 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16318 vkDestroyBuffer(m_device->device(), buffer, NULL);
16319 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16320}
16321
16322// This is a positive test. No failures are expected.
16323TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16324 VkResult err;
16325 bool pass;
16326
16327 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16328 "the buffer, create an image, and bind the same memory to "
16329 "it");
16330
16331 m_errorMonitor->ExpectSuccess();
16332
16333 ASSERT_NO_FATAL_FAILURE(InitState());
16334
16335 VkBuffer buffer;
16336 VkImage image;
16337 VkDeviceMemory mem;
16338 VkMemoryRequirements mem_reqs;
16339
16340 VkBufferCreateInfo buf_info = {};
16341 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16342 buf_info.pNext = NULL;
16343 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16344 buf_info.size = 256;
16345 buf_info.queueFamilyIndexCount = 0;
16346 buf_info.pQueueFamilyIndices = NULL;
16347 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16348 buf_info.flags = 0;
16349 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16350 ASSERT_VK_SUCCESS(err);
16351
16352 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16353
16354 VkMemoryAllocateInfo alloc_info = {};
16355 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16356 alloc_info.pNext = NULL;
16357 alloc_info.memoryTypeIndex = 0;
16358
16359 // Ensure memory is big enough for both bindings
16360 alloc_info.allocationSize = 0x10000;
16361
16362 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16363 if (!pass) {
16364 vkDestroyBuffer(m_device->device(), buffer, NULL);
16365 return;
16366 }
16367
16368 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16369 ASSERT_VK_SUCCESS(err);
16370
16371 uint8_t *pData;
16372 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16373 ASSERT_VK_SUCCESS(err);
16374
16375 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16376
16377 vkUnmapMemory(m_device->device(), mem);
16378
16379 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16380 ASSERT_VK_SUCCESS(err);
16381
16382 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16383 // memory. In fact, it was never used by the GPU.
16384 // Just be be sure, wait for idle.
16385 vkDestroyBuffer(m_device->device(), buffer, NULL);
16386 vkDeviceWaitIdle(m_device->device());
16387
16388 VkImageCreateInfo image_create_info = {};
16389 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16390 image_create_info.pNext = NULL;
16391 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16392 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16393 image_create_info.extent.width = 64;
16394 image_create_info.extent.height = 64;
16395 image_create_info.extent.depth = 1;
16396 image_create_info.mipLevels = 1;
16397 image_create_info.arrayLayers = 1;
16398 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16399 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16400 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16401 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16402 image_create_info.queueFamilyIndexCount = 0;
16403 image_create_info.pQueueFamilyIndices = NULL;
16404 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16405 image_create_info.flags = 0;
16406
16407 VkMemoryAllocateInfo mem_alloc = {};
16408 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16409 mem_alloc.pNext = NULL;
16410 mem_alloc.allocationSize = 0;
16411 mem_alloc.memoryTypeIndex = 0;
16412
16413 /* Create a mappable image. It will be the texture if linear images are ok
16414 * to be textures or it will be the staging image if they are not.
16415 */
16416 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16417 ASSERT_VK_SUCCESS(err);
16418
16419 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16420
16421 mem_alloc.allocationSize = mem_reqs.size;
16422
16423 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16424 if (!pass) {
16425 vkDestroyImage(m_device->device(), image, NULL);
16426 return;
16427 }
16428
16429 // VALIDATION FAILURE:
16430 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16431 ASSERT_VK_SUCCESS(err);
16432
16433 m_errorMonitor->VerifyNotFound();
16434
16435 vkFreeMemory(m_device->device(), mem, NULL);
16436 vkDestroyBuffer(m_device->device(), buffer, NULL);
16437 vkDestroyImage(m_device->device(), image, NULL);
16438}
16439
Tobin Ehlis953e8392016-11-17 10:54:13 -070016440TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16441 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16442 // We previously had a bug where dynamic offset of inactive bindings was still being used
16443 VkResult err;
16444 m_errorMonitor->ExpectSuccess();
16445
16446 ASSERT_NO_FATAL_FAILURE(InitState());
16447 ASSERT_NO_FATAL_FAILURE(InitViewport());
16448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16449
16450 VkDescriptorPoolSize ds_type_count = {};
16451 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16452 ds_type_count.descriptorCount = 3;
16453
16454 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16455 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16456 ds_pool_ci.pNext = NULL;
16457 ds_pool_ci.maxSets = 1;
16458 ds_pool_ci.poolSizeCount = 1;
16459 ds_pool_ci.pPoolSizes = &ds_type_count;
16460
16461 VkDescriptorPool ds_pool;
16462 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16463 ASSERT_VK_SUCCESS(err);
16464
16465 const uint32_t BINDING_COUNT = 3;
16466 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
16467 dsl_binding[0].binding = 0;
16468 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16469 dsl_binding[0].descriptorCount = 1;
16470 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16471 dsl_binding[0].pImmutableSamplers = NULL;
16472 dsl_binding[1].binding = 1;
16473 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16474 dsl_binding[1].descriptorCount = 1;
16475 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16476 dsl_binding[1].pImmutableSamplers = NULL;
16477 dsl_binding[2].binding = 2;
16478 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16479 dsl_binding[2].descriptorCount = 1;
16480 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16481 dsl_binding[2].pImmutableSamplers = NULL;
16482
16483 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16484 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16485 ds_layout_ci.pNext = NULL;
16486 ds_layout_ci.bindingCount = BINDING_COUNT;
16487 ds_layout_ci.pBindings = dsl_binding;
16488 VkDescriptorSetLayout ds_layout;
16489 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16490 ASSERT_VK_SUCCESS(err);
16491
16492 VkDescriptorSet descriptor_set;
16493 VkDescriptorSetAllocateInfo alloc_info = {};
16494 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16495 alloc_info.descriptorSetCount = 1;
16496 alloc_info.descriptorPool = ds_pool;
16497 alloc_info.pSetLayouts = &ds_layout;
16498 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16499 ASSERT_VK_SUCCESS(err);
16500
16501 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16502 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16503 pipeline_layout_ci.pNext = NULL;
16504 pipeline_layout_ci.setLayoutCount = 1;
16505 pipeline_layout_ci.pSetLayouts = &ds_layout;
16506
16507 VkPipelineLayout pipeline_layout;
16508 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16509 ASSERT_VK_SUCCESS(err);
16510
16511 // Create two buffers to update the descriptors with
16512 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16513 uint32_t qfi = 0;
16514 VkBufferCreateInfo buffCI = {};
16515 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16516 buffCI.size = 2048;
16517 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16518 buffCI.queueFamilyIndexCount = 1;
16519 buffCI.pQueueFamilyIndices = &qfi;
16520
16521 VkBuffer dyub1;
16522 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16523 ASSERT_VK_SUCCESS(err);
16524 // buffer2
16525 buffCI.size = 1024;
16526 VkBuffer dyub2;
16527 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16528 ASSERT_VK_SUCCESS(err);
16529 // Allocate memory and bind to buffers
16530 VkMemoryAllocateInfo mem_alloc[2] = {};
16531 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16532 mem_alloc[0].pNext = NULL;
16533 mem_alloc[0].memoryTypeIndex = 0;
16534 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16535 mem_alloc[1].pNext = NULL;
16536 mem_alloc[1].memoryTypeIndex = 0;
16537
16538 VkMemoryRequirements mem_reqs1;
16539 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16540 VkMemoryRequirements mem_reqs2;
16541 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16542 mem_alloc[0].allocationSize = mem_reqs1.size;
16543 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16544 mem_alloc[1].allocationSize = mem_reqs2.size;
16545 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16546 if (!pass) {
16547 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16548 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16549 return;
16550 }
16551
16552 VkDeviceMemory mem1;
16553 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16554 ASSERT_VK_SUCCESS(err);
16555 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
16556 ASSERT_VK_SUCCESS(err);
16557 VkDeviceMemory mem2;
16558 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
16559 ASSERT_VK_SUCCESS(err);
16560 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
16561 ASSERT_VK_SUCCESS(err);
16562 // Update descriptors
16563 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
16564 buff_info[0].buffer = dyub1;
16565 buff_info[0].offset = 0;
16566 buff_info[0].range = 256;
16567 buff_info[1].buffer = dyub1;
16568 buff_info[1].offset = 256;
16569 buff_info[1].range = 512;
16570 buff_info[2].buffer = dyub2;
16571 buff_info[2].offset = 0;
16572 buff_info[2].range = 512;
16573
16574 VkWriteDescriptorSet descriptor_write;
16575 memset(&descriptor_write, 0, sizeof(descriptor_write));
16576 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16577 descriptor_write.dstSet = descriptor_set;
16578 descriptor_write.dstBinding = 0;
16579 descriptor_write.descriptorCount = BINDING_COUNT;
16580 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16581 descriptor_write.pBufferInfo = buff_info;
16582
16583 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16584
16585 BeginCommandBuffer();
16586
16587 // Create PSO to be used for draw-time errors below
16588 char const *vsSource = "#version 450\n"
16589 "\n"
16590 "out gl_PerVertex { \n"
16591 " vec4 gl_Position;\n"
16592 "};\n"
16593 "void main(){\n"
16594 " gl_Position = vec4(1);\n"
16595 "}\n";
16596 char const *fsSource = "#version 450\n"
16597 "\n"
16598 "layout(location=0) out vec4 x;\n"
16599 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
16600 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
16601 "void main(){\n"
16602 " x = vec4(bar1.y) + vec4(bar2.y);\n"
16603 "}\n";
16604 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16605 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16606 VkPipelineObj pipe(m_device);
16607 pipe.SetViewport(m_viewports);
16608 pipe.SetScissor(m_scissors);
16609 pipe.AddShader(&vs);
16610 pipe.AddShader(&fs);
16611 pipe.AddColorAttachment();
16612 pipe.CreateVKPipeline(pipeline_layout, renderPass());
16613
16614 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
16615 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
16616 // we used to have a bug in this case.
16617 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
16618 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
16619 &descriptor_set, BINDING_COUNT, dyn_off);
16620 Draw(1, 0, 0, 0);
16621 m_errorMonitor->VerifyNotFound();
16622
16623 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16624 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16625 vkFreeMemory(m_device->device(), mem1, NULL);
16626 vkFreeMemory(m_device->device(), mem2, NULL);
16627
16628 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
16629 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16630 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16631}
16632
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016633TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16634
16635 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16636 "mapping while using VK_WHOLE_SIZE does not cause access "
16637 "violations");
16638 VkResult err;
16639 uint8_t *pData;
16640 ASSERT_NO_FATAL_FAILURE(InitState());
16641
16642 VkDeviceMemory mem;
16643 VkMemoryRequirements mem_reqs;
16644 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
16645 VkMemoryAllocateInfo alloc_info = {};
16646 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16647 alloc_info.pNext = NULL;
16648 alloc_info.memoryTypeIndex = 0;
16649
16650 static const VkDeviceSize allocation_size = 0x1000;
16651 alloc_info.allocationSize = allocation_size;
16652
16653 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16654 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16655 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16656 if (!pass) {
16657 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16658 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16659 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16660 if (!pass) {
16661 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16662 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16663 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16664 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16665 if (!pass) {
16666 return;
16667 }
16668 }
16669 }
16670
16671 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16672 ASSERT_VK_SUCCESS(err);
16673
16674 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16675 // mapped range
16676 m_errorMonitor->ExpectSuccess();
16677 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16678 ASSERT_VK_SUCCESS(err);
16679 VkMappedMemoryRange mmr = {};
16680 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16681 mmr.memory = mem;
16682 mmr.offset = 0;
16683 mmr.size = VK_WHOLE_SIZE;
16684 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16685 ASSERT_VK_SUCCESS(err);
16686 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16687 ASSERT_VK_SUCCESS(err);
16688 m_errorMonitor->VerifyNotFound();
16689 vkUnmapMemory(m_device->device(), mem);
16690
16691 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16692 // mapped range
16693 m_errorMonitor->ExpectSuccess();
16694 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16695 ASSERT_VK_SUCCESS(err);
16696 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16697 mmr.memory = mem;
16698 mmr.offset = 13;
16699 mmr.size = VK_WHOLE_SIZE;
16700 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16701 ASSERT_VK_SUCCESS(err);
16702 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16703 ASSERT_VK_SUCCESS(err);
16704 m_errorMonitor->VerifyNotFound();
16705 vkUnmapMemory(m_device->device(), mem);
16706
16707 // Map with prime offset and size
16708 // Flush/Invalidate subrange of mapped area with prime offset and size
16709 m_errorMonitor->ExpectSuccess();
16710 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16711 ASSERT_VK_SUCCESS(err);
16712 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16713 mmr.memory = mem;
16714 mmr.offset = allocation_size - 107;
16715 mmr.size = 61;
16716 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16717 ASSERT_VK_SUCCESS(err);
16718 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16719 ASSERT_VK_SUCCESS(err);
16720 m_errorMonitor->VerifyNotFound();
16721 vkUnmapMemory(m_device->device(), mem);
16722
16723 // Map without offset and flush WHOLE_SIZE with two separate offsets
16724 m_errorMonitor->ExpectSuccess();
16725 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16726 ASSERT_VK_SUCCESS(err);
16727 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16728 mmr.memory = mem;
16729 mmr.offset = allocation_size - 100;
16730 mmr.size = VK_WHOLE_SIZE;
16731 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16732 ASSERT_VK_SUCCESS(err);
16733 mmr.offset = allocation_size - 200;
16734 mmr.size = VK_WHOLE_SIZE;
16735 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16736 ASSERT_VK_SUCCESS(err);
16737 m_errorMonitor->VerifyNotFound();
16738 vkUnmapMemory(m_device->device(), mem);
16739
16740 vkFreeMemory(m_device->device(), mem, NULL);
16741}
16742
16743// This is a positive test. We used to expect error in this case but spec now allows it
16744TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16745 m_errorMonitor->ExpectSuccess();
16746 vk_testing::Fence testFence;
16747 VkFenceCreateInfo fenceInfo = {};
16748 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16749 fenceInfo.pNext = NULL;
16750
16751 ASSERT_NO_FATAL_FAILURE(InitState());
16752 testFence.init(*m_device, fenceInfo);
16753 VkFence fences[1] = { testFence.handle() };
16754 VkResult result = vkResetFences(m_device->device(), 1, fences);
16755 ASSERT_VK_SUCCESS(result);
16756
16757 m_errorMonitor->VerifyNotFound();
16758}
16759
16760TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16761 m_errorMonitor->ExpectSuccess();
16762
16763 ASSERT_NO_FATAL_FAILURE(InitState());
16764 VkResult err;
16765
16766 // Record (empty!) command buffer that can be submitted multiple times
16767 // simultaneously.
16768 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16769 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16770 m_commandBuffer->BeginCommandBuffer(&cbbi);
16771 m_commandBuffer->EndCommandBuffer();
16772
16773 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16774 VkFence fence;
16775 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16776 ASSERT_VK_SUCCESS(err);
16777
16778 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16779 VkSemaphore s1, s2;
16780 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16781 ASSERT_VK_SUCCESS(err);
16782 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16783 ASSERT_VK_SUCCESS(err);
16784
16785 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16786 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16787 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16788 ASSERT_VK_SUCCESS(err);
16789
16790 // Submit CB again, signaling s2.
16791 si.pSignalSemaphores = &s2;
16792 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16793 ASSERT_VK_SUCCESS(err);
16794
16795 // Wait for fence.
16796 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16797 ASSERT_VK_SUCCESS(err);
16798
16799 // CB is still in flight from second submission, but semaphore s1 is no
16800 // longer in flight. delete it.
16801 vkDestroySemaphore(m_device->device(), s1, nullptr);
16802
16803 m_errorMonitor->VerifyNotFound();
16804
16805 // Force device idle and clean up remaining objects
16806 vkDeviceWaitIdle(m_device->device());
16807 vkDestroySemaphore(m_device->device(), s2, nullptr);
16808 vkDestroyFence(m_device->device(), fence, nullptr);
16809}
16810
16811TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16812 m_errorMonitor->ExpectSuccess();
16813
16814 ASSERT_NO_FATAL_FAILURE(InitState());
16815 VkResult err;
16816
16817 // A fence created signaled
16818 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16819 VkFence f1;
16820 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16821 ASSERT_VK_SUCCESS(err);
16822
16823 // A fence created not
16824 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16825 VkFence f2;
16826 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16827 ASSERT_VK_SUCCESS(err);
16828
16829 // Submit the unsignaled fence
16830 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16831 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16832
16833 // Wait on both fences, with signaled first.
16834 VkFence fences[] = { f1, f2 };
16835 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16836
16837 // Should have both retired!
16838 vkDestroyFence(m_device->device(), f1, nullptr);
16839 vkDestroyFence(m_device->device(), f2, nullptr);
16840
16841 m_errorMonitor->VerifyNotFound();
16842}
16843
16844TEST_F(VkPositiveLayerTest, ValidUsage) {
16845 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16846 "doesn't generate validation errors");
16847
16848 ASSERT_NO_FATAL_FAILURE(InitState());
16849
16850 m_errorMonitor->ExpectSuccess();
16851 // Verify that we can create a view with usage INPUT_ATTACHMENT
16852 VkImageObj image(m_device);
16853 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16854 ASSERT_TRUE(image.initialized());
16855 VkImageView imageView;
16856 VkImageViewCreateInfo ivci = {};
16857 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16858 ivci.image = image.handle();
16859 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16860 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16861 ivci.subresourceRange.layerCount = 1;
16862 ivci.subresourceRange.baseMipLevel = 0;
16863 ivci.subresourceRange.levelCount = 1;
16864 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16865
16866 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16867 m_errorMonitor->VerifyNotFound();
16868 vkDestroyImageView(m_device->device(), imageView, NULL);
16869}
16870
16871// This is a positive test. No failures are expected.
16872TEST_F(VkPositiveLayerTest, BindSparse) {
16873 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16874 "and then free the memory");
16875
16876 ASSERT_NO_FATAL_FAILURE(InitState());
16877
16878 auto index = m_device->graphics_queue_node_index_;
16879 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16880 return;
16881
16882 m_errorMonitor->ExpectSuccess();
16883
16884 VkImage image;
16885 VkImageCreateInfo image_create_info = {};
16886 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16887 image_create_info.pNext = NULL;
16888 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16889 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16890 image_create_info.extent.width = 64;
16891 image_create_info.extent.height = 64;
16892 image_create_info.extent.depth = 1;
16893 image_create_info.mipLevels = 1;
16894 image_create_info.arrayLayers = 1;
16895 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16896 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16897 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16898 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16899 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16900 ASSERT_VK_SUCCESS(err);
16901
16902 VkMemoryRequirements memory_reqs;
16903 VkDeviceMemory memory_one, memory_two;
16904 bool pass;
16905 VkMemoryAllocateInfo memory_info = {};
16906 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16907 memory_info.pNext = NULL;
16908 memory_info.allocationSize = 0;
16909 memory_info.memoryTypeIndex = 0;
16910 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16911 // Find an image big enough to allow sparse mapping of 2 memory regions
16912 // Increase the image size until it is at least twice the
16913 // size of the required alignment, to ensure we can bind both
16914 // allocated memory blocks to the image on aligned offsets.
16915 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16916 vkDestroyImage(m_device->device(), image, nullptr);
16917 image_create_info.extent.width *= 2;
16918 image_create_info.extent.height *= 2;
16919 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16920 ASSERT_VK_SUCCESS(err);
16921 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16922 }
16923 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16924 // at the end of the first
16925 memory_info.allocationSize = memory_reqs.alignment;
16926 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16927 ASSERT_TRUE(pass);
16928 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16929 ASSERT_VK_SUCCESS(err);
16930 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16931 ASSERT_VK_SUCCESS(err);
16932 VkSparseMemoryBind binds[2];
16933 binds[0].flags = 0;
16934 binds[0].memory = memory_one;
16935 binds[0].memoryOffset = 0;
16936 binds[0].resourceOffset = 0;
16937 binds[0].size = memory_info.allocationSize;
16938 binds[1].flags = 0;
16939 binds[1].memory = memory_two;
16940 binds[1].memoryOffset = 0;
16941 binds[1].resourceOffset = memory_info.allocationSize;
16942 binds[1].size = memory_info.allocationSize;
16943
16944 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16945 opaqueBindInfo.image = image;
16946 opaqueBindInfo.bindCount = 2;
16947 opaqueBindInfo.pBinds = binds;
16948
16949 VkFence fence = VK_NULL_HANDLE;
16950 VkBindSparseInfo bindSparseInfo = {};
16951 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16952 bindSparseInfo.imageOpaqueBindCount = 1;
16953 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16954
16955 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16956 vkQueueWaitIdle(m_device->m_queue);
16957 vkDestroyImage(m_device->device(), image, NULL);
16958 vkFreeMemory(m_device->device(), memory_one, NULL);
16959 vkFreeMemory(m_device->device(), memory_two, NULL);
16960 m_errorMonitor->VerifyNotFound();
16961}
16962
16963TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16964 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16965 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16966 "the command buffer has prior knowledge of that "
16967 "attachment's layout.");
16968
16969 m_errorMonitor->ExpectSuccess();
16970
16971 ASSERT_NO_FATAL_FAILURE(InitState());
16972
16973 // A renderpass with one color attachment.
16974 VkAttachmentDescription attachment = { 0,
16975 VK_FORMAT_R8G8B8A8_UNORM,
16976 VK_SAMPLE_COUNT_1_BIT,
16977 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16978 VK_ATTACHMENT_STORE_OP_STORE,
16979 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16980 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16981 VK_IMAGE_LAYOUT_UNDEFINED,
16982 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16983
16984 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16985
16986 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16987
16988 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16989
16990 VkRenderPass rp;
16991 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16992 ASSERT_VK_SUCCESS(err);
16993
16994 // A compatible framebuffer.
16995 VkImageObj image(m_device);
16996 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16997 ASSERT_TRUE(image.initialized());
16998
16999 VkImageViewCreateInfo ivci = {
17000 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17001 nullptr,
17002 0,
17003 image.handle(),
17004 VK_IMAGE_VIEW_TYPE_2D,
17005 VK_FORMAT_R8G8B8A8_UNORM,
17006 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17007 VK_COMPONENT_SWIZZLE_IDENTITY },
17008 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17009 };
17010 VkImageView view;
17011 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17012 ASSERT_VK_SUCCESS(err);
17013
17014 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17015 VkFramebuffer fb;
17016 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17017 ASSERT_VK_SUCCESS(err);
17018
17019 // Record a single command buffer which uses this renderpass twice. The
17020 // bug is triggered at the beginning of the second renderpass, when the
17021 // command buffer already has a layout recorded for the attachment.
17022 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17023 BeginCommandBuffer();
17024 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17025 vkCmdEndRenderPass(m_commandBuffer->handle());
17026 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17027
17028 m_errorMonitor->VerifyNotFound();
17029
17030 vkCmdEndRenderPass(m_commandBuffer->handle());
17031 EndCommandBuffer();
17032
17033 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17034 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17035 vkDestroyImageView(m_device->device(), view, nullptr);
17036}
17037
17038TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17039 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17040 "command buffer, bind them together, then destroy "
17041 "command pool and framebuffer and verify there are no "
17042 "errors.");
17043
17044 m_errorMonitor->ExpectSuccess();
17045
17046 ASSERT_NO_FATAL_FAILURE(InitState());
17047
17048 // A renderpass with one color attachment.
17049 VkAttachmentDescription attachment = { 0,
17050 VK_FORMAT_R8G8B8A8_UNORM,
17051 VK_SAMPLE_COUNT_1_BIT,
17052 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17053 VK_ATTACHMENT_STORE_OP_STORE,
17054 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17055 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17056 VK_IMAGE_LAYOUT_UNDEFINED,
17057 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17058
17059 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17060
17061 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17062
17063 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17064
17065 VkRenderPass rp;
17066 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17067 ASSERT_VK_SUCCESS(err);
17068
17069 // A compatible framebuffer.
17070 VkImageObj image(m_device);
17071 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17072 ASSERT_TRUE(image.initialized());
17073
17074 VkImageViewCreateInfo ivci = {
17075 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17076 nullptr,
17077 0,
17078 image.handle(),
17079 VK_IMAGE_VIEW_TYPE_2D,
17080 VK_FORMAT_R8G8B8A8_UNORM,
17081 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17082 VK_COMPONENT_SWIZZLE_IDENTITY },
17083 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17084 };
17085 VkImageView view;
17086 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17087 ASSERT_VK_SUCCESS(err);
17088
17089 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17090 VkFramebuffer fb;
17091 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17092 ASSERT_VK_SUCCESS(err);
17093
17094 // Explicitly create a command buffer to bind the FB to so that we can then
17095 // destroy the command pool in order to implicitly free command buffer
17096 VkCommandPool command_pool;
17097 VkCommandPoolCreateInfo pool_create_info{};
17098 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17099 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17100 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17101 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17102
17103 VkCommandBuffer command_buffer;
17104 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17105 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17106 command_buffer_allocate_info.commandPool = command_pool;
17107 command_buffer_allocate_info.commandBufferCount = 1;
17108 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17109 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17110
17111 // Begin our cmd buffer with renderpass using our framebuffer
17112 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17113 VkCommandBufferBeginInfo begin_info{};
17114 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17115 vkBeginCommandBuffer(command_buffer, &begin_info);
17116
17117 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17118 vkCmdEndRenderPass(command_buffer);
17119 vkEndCommandBuffer(command_buffer);
17120 vkDestroyImageView(m_device->device(), view, nullptr);
17121 // Destroy command pool to implicitly free command buffer
17122 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17123 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17124 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17125 m_errorMonitor->VerifyNotFound();
17126}
17127
17128TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17129 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17130 "transitions for the first subpass");
17131
17132 m_errorMonitor->ExpectSuccess();
17133
17134 ASSERT_NO_FATAL_FAILURE(InitState());
17135
17136 // A renderpass with one color attachment.
17137 VkAttachmentDescription attachment = { 0,
17138 VK_FORMAT_R8G8B8A8_UNORM,
17139 VK_SAMPLE_COUNT_1_BIT,
17140 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17141 VK_ATTACHMENT_STORE_OP_STORE,
17142 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17143 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17144 VK_IMAGE_LAYOUT_UNDEFINED,
17145 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17146
17147 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17148
17149 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17150
17151 VkSubpassDependency dep = { 0,
17152 0,
17153 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17154 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17155 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17156 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17157 VK_DEPENDENCY_BY_REGION_BIT };
17158
17159 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17160
17161 VkResult err;
17162 VkRenderPass rp;
17163 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17164 ASSERT_VK_SUCCESS(err);
17165
17166 // A compatible framebuffer.
17167 VkImageObj image(m_device);
17168 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17169 ASSERT_TRUE(image.initialized());
17170
17171 VkImageViewCreateInfo ivci = {
17172 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17173 nullptr,
17174 0,
17175 image.handle(),
17176 VK_IMAGE_VIEW_TYPE_2D,
17177 VK_FORMAT_R8G8B8A8_UNORM,
17178 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17179 VK_COMPONENT_SWIZZLE_IDENTITY },
17180 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17181 };
17182 VkImageView view;
17183 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17184 ASSERT_VK_SUCCESS(err);
17185
17186 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17187 VkFramebuffer fb;
17188 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17189 ASSERT_VK_SUCCESS(err);
17190
17191 // Record a single command buffer which issues a pipeline barrier w/
17192 // image memory barrier for the attachment. This detects the previously
17193 // missing tracking of the subpass layout by throwing a validation error
17194 // if it doesn't occur.
17195 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17196 BeginCommandBuffer();
17197 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17198
17199 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17200 nullptr,
17201 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17202 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17203 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17204 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17205 VK_QUEUE_FAMILY_IGNORED,
17206 VK_QUEUE_FAMILY_IGNORED,
17207 image.handle(),
17208 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17209 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17210 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17211 &imb);
17212
17213 vkCmdEndRenderPass(m_commandBuffer->handle());
17214 m_errorMonitor->VerifyNotFound();
17215 EndCommandBuffer();
17216
17217 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17218 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17219 vkDestroyImageView(m_device->device(), view, nullptr);
17220}
17221
17222TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17223 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17224 "is used as a depth/stencil framebuffer attachment, the "
17225 "aspectMask is ignored and both depth and stencil image "
17226 "subresources are used.");
17227
17228 VkFormatProperties format_properties;
17229 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17230 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17231 return;
17232 }
17233
17234 m_errorMonitor->ExpectSuccess();
17235
17236 ASSERT_NO_FATAL_FAILURE(InitState());
17237
17238 VkAttachmentDescription attachment = { 0,
17239 VK_FORMAT_D32_SFLOAT_S8_UINT,
17240 VK_SAMPLE_COUNT_1_BIT,
17241 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17242 VK_ATTACHMENT_STORE_OP_STORE,
17243 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17244 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17245 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17246 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17247
17248 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17249
17250 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17251
17252 VkSubpassDependency dep = { 0,
17253 0,
17254 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17255 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17256 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17257 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17258 VK_DEPENDENCY_BY_REGION_BIT};
17259
17260 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17261
17262 VkResult err;
17263 VkRenderPass rp;
17264 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17265 ASSERT_VK_SUCCESS(err);
17266
17267 VkImageObj image(m_device);
17268 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17269 0x26, // usage
17270 VK_IMAGE_TILING_OPTIMAL, 0);
17271 ASSERT_TRUE(image.initialized());
17272 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17273
17274 VkImageViewCreateInfo ivci = {
17275 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17276 nullptr,
17277 0,
17278 image.handle(),
17279 VK_IMAGE_VIEW_TYPE_2D,
17280 VK_FORMAT_D32_SFLOAT_S8_UINT,
17281 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17282 { 0x2, 0, 1, 0, 1 },
17283 };
17284 VkImageView view;
17285 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17286 ASSERT_VK_SUCCESS(err);
17287
17288 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17289 VkFramebuffer fb;
17290 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17291 ASSERT_VK_SUCCESS(err);
17292
17293 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17294 BeginCommandBuffer();
17295 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17296
17297 VkImageMemoryBarrier imb = {};
17298 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17299 imb.pNext = nullptr;
17300 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17301 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17302 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17303 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17304 imb.srcQueueFamilyIndex = 0;
17305 imb.dstQueueFamilyIndex = 0;
17306 imb.image = image.handle();
17307 imb.subresourceRange.aspectMask = 0x6;
17308 imb.subresourceRange.baseMipLevel = 0;
17309 imb.subresourceRange.levelCount = 0x1;
17310 imb.subresourceRange.baseArrayLayer = 0;
17311 imb.subresourceRange.layerCount = 0x1;
17312
17313 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17314 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17315 &imb);
17316
17317 vkCmdEndRenderPass(m_commandBuffer->handle());
17318 EndCommandBuffer();
17319 QueueCommandBuffer(false);
17320 m_errorMonitor->VerifyNotFound();
17321
17322 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17323 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17324 vkDestroyImageView(m_device->device(), view, nullptr);
17325}
17326
17327TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17328 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17329 "errors, when an attachment reference is "
17330 "VK_ATTACHMENT_UNUSED");
17331
17332 m_errorMonitor->ExpectSuccess();
17333
17334 ASSERT_NO_FATAL_FAILURE(InitState());
17335
17336 // A renderpass with no attachments
17337 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17338
17339 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17340
17341 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17342
17343 VkRenderPass rp;
17344 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17345 ASSERT_VK_SUCCESS(err);
17346
17347 // A compatible framebuffer.
17348 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17349 VkFramebuffer fb;
17350 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17351 ASSERT_VK_SUCCESS(err);
17352
17353 // Record a command buffer which just begins and ends the renderpass. The
17354 // bug manifests in BeginRenderPass.
17355 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17356 BeginCommandBuffer();
17357 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17358 vkCmdEndRenderPass(m_commandBuffer->handle());
17359 m_errorMonitor->VerifyNotFound();
17360 EndCommandBuffer();
17361
17362 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17363 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17364}
17365
17366// This is a positive test. No errors are expected.
17367TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17368 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17369 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17370 VkResult result = VK_SUCCESS;
17371 VkImageFormatProperties formatProps;
17372 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17373 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17374 &formatProps);
17375 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17376 return;
17377 }
17378
17379 ASSERT_NO_FATAL_FAILURE(InitState());
17380 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17381 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17382 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17383 VkAttachmentDescription att = {};
17384 VkAttachmentReference ref = {};
17385 att.format = depth_stencil_fmt;
17386 att.samples = VK_SAMPLE_COUNT_1_BIT;
17387 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17388 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17389 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17390 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17391 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17392 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17393
17394 VkClearValue clear;
17395 clear.depthStencil.depth = 1.0;
17396 clear.depthStencil.stencil = 0;
17397 ref.attachment = 0;
17398 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17399
17400 VkSubpassDescription subpass = {};
17401 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17402 subpass.flags = 0;
17403 subpass.inputAttachmentCount = 0;
17404 subpass.pInputAttachments = NULL;
17405 subpass.colorAttachmentCount = 0;
17406 subpass.pColorAttachments = NULL;
17407 subpass.pResolveAttachments = NULL;
17408 subpass.pDepthStencilAttachment = &ref;
17409 subpass.preserveAttachmentCount = 0;
17410 subpass.pPreserveAttachments = NULL;
17411
17412 VkRenderPass rp;
17413 VkRenderPassCreateInfo rp_info = {};
17414 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17415 rp_info.attachmentCount = 1;
17416 rp_info.pAttachments = &att;
17417 rp_info.subpassCount = 1;
17418 rp_info.pSubpasses = &subpass;
17419 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17420 ASSERT_VK_SUCCESS(result);
17421
17422 VkImageView *depthView = m_depthStencil->BindInfo();
17423 VkFramebufferCreateInfo fb_info = {};
17424 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17425 fb_info.pNext = NULL;
17426 fb_info.renderPass = rp;
17427 fb_info.attachmentCount = 1;
17428 fb_info.pAttachments = depthView;
17429 fb_info.width = 100;
17430 fb_info.height = 100;
17431 fb_info.layers = 1;
17432 VkFramebuffer fb;
17433 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17434 ASSERT_VK_SUCCESS(result);
17435
17436 VkRenderPassBeginInfo rpbinfo = {};
17437 rpbinfo.clearValueCount = 1;
17438 rpbinfo.pClearValues = &clear;
17439 rpbinfo.pNext = NULL;
17440 rpbinfo.renderPass = rp;
17441 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17442 rpbinfo.renderArea.extent.width = 100;
17443 rpbinfo.renderArea.extent.height = 100;
17444 rpbinfo.renderArea.offset.x = 0;
17445 rpbinfo.renderArea.offset.y = 0;
17446 rpbinfo.framebuffer = fb;
17447
17448 VkFence fence = {};
17449 VkFenceCreateInfo fence_ci = {};
17450 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17451 fence_ci.pNext = nullptr;
17452 fence_ci.flags = 0;
17453 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17454 ASSERT_VK_SUCCESS(result);
17455
17456 m_commandBuffer->BeginCommandBuffer();
17457 m_commandBuffer->BeginRenderPass(rpbinfo);
17458 m_commandBuffer->EndRenderPass();
17459 m_commandBuffer->EndCommandBuffer();
17460 m_commandBuffer->QueueCommandBuffer(fence);
17461
17462 VkImageObj destImage(m_device);
17463 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17464 VK_IMAGE_TILING_OPTIMAL, 0);
17465 VkImageMemoryBarrier barrier = {};
17466 VkImageSubresourceRange range;
17467 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17468 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17469 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17470 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17471 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17472 barrier.image = m_depthStencil->handle();
17473 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17474 range.baseMipLevel = 0;
17475 range.levelCount = 1;
17476 range.baseArrayLayer = 0;
17477 range.layerCount = 1;
17478 barrier.subresourceRange = range;
17479 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17480 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17481 cmdbuf.BeginCommandBuffer();
17482 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17483 &barrier);
17484 barrier.srcAccessMask = 0;
17485 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17486 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17487 barrier.image = destImage.handle();
17488 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17489 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17490 &barrier);
17491 VkImageCopy cregion;
17492 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17493 cregion.srcSubresource.mipLevel = 0;
17494 cregion.srcSubresource.baseArrayLayer = 0;
17495 cregion.srcSubresource.layerCount = 1;
17496 cregion.srcOffset.x = 0;
17497 cregion.srcOffset.y = 0;
17498 cregion.srcOffset.z = 0;
17499 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17500 cregion.dstSubresource.mipLevel = 0;
17501 cregion.dstSubresource.baseArrayLayer = 0;
17502 cregion.dstSubresource.layerCount = 1;
17503 cregion.dstOffset.x = 0;
17504 cregion.dstOffset.y = 0;
17505 cregion.dstOffset.z = 0;
17506 cregion.extent.width = 100;
17507 cregion.extent.height = 100;
17508 cregion.extent.depth = 1;
17509 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17510 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17511 cmdbuf.EndCommandBuffer();
17512
17513 VkSubmitInfo submit_info;
17514 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17515 submit_info.pNext = NULL;
17516 submit_info.waitSemaphoreCount = 0;
17517 submit_info.pWaitSemaphores = NULL;
17518 submit_info.pWaitDstStageMask = NULL;
17519 submit_info.commandBufferCount = 1;
17520 submit_info.pCommandBuffers = &cmdbuf.handle();
17521 submit_info.signalSemaphoreCount = 0;
17522 submit_info.pSignalSemaphores = NULL;
17523
17524 m_errorMonitor->ExpectSuccess();
17525 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17526 m_errorMonitor->VerifyNotFound();
17527
17528 vkQueueWaitIdle(m_device->m_queue);
17529 vkDestroyFence(m_device->device(), fence, nullptr);
17530 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17531 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17532}
17533
17534// This is a positive test. No errors should be generated.
17535TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17536 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17537
17538 m_errorMonitor->ExpectSuccess();
17539 ASSERT_NO_FATAL_FAILURE(InitState());
17540
17541 VkEvent event;
17542 VkEventCreateInfo event_create_info{};
17543 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17544 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17545
17546 VkCommandPool command_pool;
17547 VkCommandPoolCreateInfo pool_create_info{};
17548 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17549 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17550 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17551 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17552
17553 VkCommandBuffer command_buffer;
17554 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17555 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17556 command_buffer_allocate_info.commandPool = command_pool;
17557 command_buffer_allocate_info.commandBufferCount = 1;
17558 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17559 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17560
17561 VkQueue queue = VK_NULL_HANDLE;
17562 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17563
17564 {
17565 VkCommandBufferBeginInfo begin_info{};
17566 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17567 vkBeginCommandBuffer(command_buffer, &begin_info);
17568
17569 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17570 nullptr, 0, nullptr);
17571 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17572 vkEndCommandBuffer(command_buffer);
17573 }
17574 {
17575 VkSubmitInfo submit_info{};
17576 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17577 submit_info.commandBufferCount = 1;
17578 submit_info.pCommandBuffers = &command_buffer;
17579 submit_info.signalSemaphoreCount = 0;
17580 submit_info.pSignalSemaphores = nullptr;
17581 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17582 }
17583 { vkSetEvent(m_device->device(), event); }
17584
17585 vkQueueWaitIdle(queue);
17586
17587 vkDestroyEvent(m_device->device(), event, nullptr);
17588 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17589 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17590
17591 m_errorMonitor->VerifyNotFound();
17592}
17593// This is a positive test. No errors should be generated.
17594TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17595 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17596
17597 ASSERT_NO_FATAL_FAILURE(InitState());
17598 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17599 return;
17600
17601 m_errorMonitor->ExpectSuccess();
17602
17603 VkQueryPool query_pool;
17604 VkQueryPoolCreateInfo query_pool_create_info{};
17605 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17606 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17607 query_pool_create_info.queryCount = 1;
17608 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17609
17610 VkCommandPool command_pool;
17611 VkCommandPoolCreateInfo pool_create_info{};
17612 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17613 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17614 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17615 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17616
17617 VkCommandBuffer command_buffer;
17618 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17619 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17620 command_buffer_allocate_info.commandPool = command_pool;
17621 command_buffer_allocate_info.commandBufferCount = 1;
17622 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17623 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17624
17625 VkCommandBuffer secondary_command_buffer;
17626 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17627 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17628
17629 VkQueue queue = VK_NULL_HANDLE;
17630 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17631
17632 uint32_t qfi = 0;
17633 VkBufferCreateInfo buff_create_info = {};
17634 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17635 buff_create_info.size = 1024;
17636 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17637 buff_create_info.queueFamilyIndexCount = 1;
17638 buff_create_info.pQueueFamilyIndices = &qfi;
17639
17640 VkResult err;
17641 VkBuffer buffer;
17642 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17643 ASSERT_VK_SUCCESS(err);
17644 VkMemoryAllocateInfo mem_alloc = {};
17645 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17646 mem_alloc.pNext = NULL;
17647 mem_alloc.allocationSize = 1024;
17648 mem_alloc.memoryTypeIndex = 0;
17649
17650 VkMemoryRequirements memReqs;
17651 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17652 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17653 if (!pass) {
17654 vkDestroyBuffer(m_device->device(), buffer, NULL);
17655 return;
17656 }
17657
17658 VkDeviceMemory mem;
17659 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17660 ASSERT_VK_SUCCESS(err);
17661 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17662 ASSERT_VK_SUCCESS(err);
17663
17664 VkCommandBufferInheritanceInfo hinfo = {};
17665 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17666 hinfo.renderPass = VK_NULL_HANDLE;
17667 hinfo.subpass = 0;
17668 hinfo.framebuffer = VK_NULL_HANDLE;
17669 hinfo.occlusionQueryEnable = VK_FALSE;
17670 hinfo.queryFlags = 0;
17671 hinfo.pipelineStatistics = 0;
17672
17673 {
17674 VkCommandBufferBeginInfo begin_info{};
17675 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17676 begin_info.pInheritanceInfo = &hinfo;
17677 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17678
17679 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17680 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17681
17682 vkEndCommandBuffer(secondary_command_buffer);
17683
17684 begin_info.pInheritanceInfo = nullptr;
17685 vkBeginCommandBuffer(command_buffer, &begin_info);
17686
17687 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17688 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17689
17690 vkEndCommandBuffer(command_buffer);
17691 }
17692 {
17693 VkSubmitInfo submit_info{};
17694 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17695 submit_info.commandBufferCount = 1;
17696 submit_info.pCommandBuffers = &command_buffer;
17697 submit_info.signalSemaphoreCount = 0;
17698 submit_info.pSignalSemaphores = nullptr;
17699 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17700 }
17701
17702 vkQueueWaitIdle(queue);
17703
17704 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17705 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17706 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17707 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17708 vkDestroyBuffer(m_device->device(), buffer, NULL);
17709 vkFreeMemory(m_device->device(), mem, NULL);
17710
17711 m_errorMonitor->VerifyNotFound();
17712}
17713
17714// This is a positive test. No errors should be generated.
17715TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17716 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17717
17718 ASSERT_NO_FATAL_FAILURE(InitState());
17719 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17720 return;
17721
17722 m_errorMonitor->ExpectSuccess();
17723
17724 VkQueryPool query_pool;
17725 VkQueryPoolCreateInfo query_pool_create_info{};
17726 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17727 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17728 query_pool_create_info.queryCount = 1;
17729 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17730
17731 VkCommandPool command_pool;
17732 VkCommandPoolCreateInfo pool_create_info{};
17733 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17734 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17735 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17736 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17737
17738 VkCommandBuffer command_buffer[2];
17739 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17740 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17741 command_buffer_allocate_info.commandPool = command_pool;
17742 command_buffer_allocate_info.commandBufferCount = 2;
17743 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17744 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17745
17746 VkQueue queue = VK_NULL_HANDLE;
17747 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17748
17749 uint32_t qfi = 0;
17750 VkBufferCreateInfo buff_create_info = {};
17751 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17752 buff_create_info.size = 1024;
17753 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17754 buff_create_info.queueFamilyIndexCount = 1;
17755 buff_create_info.pQueueFamilyIndices = &qfi;
17756
17757 VkResult err;
17758 VkBuffer buffer;
17759 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17760 ASSERT_VK_SUCCESS(err);
17761 VkMemoryAllocateInfo mem_alloc = {};
17762 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17763 mem_alloc.pNext = NULL;
17764 mem_alloc.allocationSize = 1024;
17765 mem_alloc.memoryTypeIndex = 0;
17766
17767 VkMemoryRequirements memReqs;
17768 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17769 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17770 if (!pass) {
17771 vkDestroyBuffer(m_device->device(), buffer, NULL);
17772 return;
17773 }
17774
17775 VkDeviceMemory mem;
17776 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17777 ASSERT_VK_SUCCESS(err);
17778 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17779 ASSERT_VK_SUCCESS(err);
17780
17781 {
17782 VkCommandBufferBeginInfo begin_info{};
17783 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17784 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17785
17786 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17787 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17788
17789 vkEndCommandBuffer(command_buffer[0]);
17790
17791 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17792
17793 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17794
17795 vkEndCommandBuffer(command_buffer[1]);
17796 }
17797 {
17798 VkSubmitInfo submit_info{};
17799 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17800 submit_info.commandBufferCount = 2;
17801 submit_info.pCommandBuffers = command_buffer;
17802 submit_info.signalSemaphoreCount = 0;
17803 submit_info.pSignalSemaphores = nullptr;
17804 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17805 }
17806
17807 vkQueueWaitIdle(queue);
17808
17809 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17810 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17811 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17812 vkDestroyBuffer(m_device->device(), buffer, NULL);
17813 vkFreeMemory(m_device->device(), mem, NULL);
17814
17815 m_errorMonitor->VerifyNotFound();
17816}
17817
Tony Barbourc46924f2016-11-04 11:49:52 -060017818TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017819 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17820
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017821 ASSERT_NO_FATAL_FAILURE(InitState());
17822 VkEvent event;
17823 VkEventCreateInfo event_create_info{};
17824 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17825 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17826
17827 VkCommandPool command_pool;
17828 VkCommandPoolCreateInfo pool_create_info{};
17829 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17830 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17831 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17832 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17833
17834 VkCommandBuffer command_buffer;
17835 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17836 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17837 command_buffer_allocate_info.commandPool = command_pool;
17838 command_buffer_allocate_info.commandBufferCount = 1;
17839 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17840 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17841
17842 VkQueue queue = VK_NULL_HANDLE;
17843 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17844
17845 {
17846 VkCommandBufferBeginInfo begin_info{};
17847 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17848 vkBeginCommandBuffer(command_buffer, &begin_info);
17849
17850 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017851 vkEndCommandBuffer(command_buffer);
17852 }
17853 {
17854 VkSubmitInfo submit_info{};
17855 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17856 submit_info.commandBufferCount = 1;
17857 submit_info.pCommandBuffers = &command_buffer;
17858 submit_info.signalSemaphoreCount = 0;
17859 submit_info.pSignalSemaphores = nullptr;
17860 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17861 }
17862 {
17863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17864 "command buffer.");
17865 vkSetEvent(m_device->device(), event);
17866 m_errorMonitor->VerifyFound();
17867 }
17868
17869 vkQueueWaitIdle(queue);
17870
17871 vkDestroyEvent(m_device->device(), event, nullptr);
17872 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17873 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17874}
17875
17876// This is a positive test. No errors should be generated.
17877TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17878 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17879 "run through a Submit & WaitForFences cycle 3 times. This "
17880 "previously revealed a bug so running this positive test "
17881 "to prevent a regression.");
17882 m_errorMonitor->ExpectSuccess();
17883
17884 ASSERT_NO_FATAL_FAILURE(InitState());
17885 VkQueue queue = VK_NULL_HANDLE;
17886 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17887
17888 static const uint32_t NUM_OBJECTS = 2;
17889 static const uint32_t NUM_FRAMES = 3;
17890 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17891 VkFence fences[NUM_OBJECTS] = {};
17892
17893 VkCommandPool cmd_pool;
17894 VkCommandPoolCreateInfo cmd_pool_ci = {};
17895 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17896 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17897 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17898 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17899 ASSERT_VK_SUCCESS(err);
17900
17901 VkCommandBufferAllocateInfo cmd_buf_info = {};
17902 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17903 cmd_buf_info.commandPool = cmd_pool;
17904 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17905 cmd_buf_info.commandBufferCount = 1;
17906
17907 VkFenceCreateInfo fence_ci = {};
17908 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17909 fence_ci.pNext = nullptr;
17910 fence_ci.flags = 0;
17911
17912 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17913 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17914 ASSERT_VK_SUCCESS(err);
17915 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17916 ASSERT_VK_SUCCESS(err);
17917 }
17918
17919 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17920 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17921 // Create empty cmd buffer
17922 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17923 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17924
17925 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17926 ASSERT_VK_SUCCESS(err);
17927 err = vkEndCommandBuffer(cmd_buffers[obj]);
17928 ASSERT_VK_SUCCESS(err);
17929
17930 VkSubmitInfo submit_info = {};
17931 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17932 submit_info.commandBufferCount = 1;
17933 submit_info.pCommandBuffers = &cmd_buffers[obj];
17934 // Submit cmd buffer and wait for fence
17935 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17936 ASSERT_VK_SUCCESS(err);
17937 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17938 ASSERT_VK_SUCCESS(err);
17939 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17940 ASSERT_VK_SUCCESS(err);
17941 }
17942 }
17943 m_errorMonitor->VerifyNotFound();
17944 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17945 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17946 vkDestroyFence(m_device->device(), fences[i], nullptr);
17947 }
17948}
17949// This is a positive test. No errors should be generated.
17950TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17951
17952 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17953 "submitted on separate queues followed by a QueueWaitIdle.");
17954
17955 ASSERT_NO_FATAL_FAILURE(InitState());
17956 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17957 return;
17958
17959 m_errorMonitor->ExpectSuccess();
17960
17961 VkSemaphore semaphore;
17962 VkSemaphoreCreateInfo semaphore_create_info{};
17963 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17964 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17965
17966 VkCommandPool command_pool;
17967 VkCommandPoolCreateInfo pool_create_info{};
17968 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17969 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17970 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17971 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17972
17973 VkCommandBuffer command_buffer[2];
17974 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17975 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17976 command_buffer_allocate_info.commandPool = command_pool;
17977 command_buffer_allocate_info.commandBufferCount = 2;
17978 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17979 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17980
17981 VkQueue queue = VK_NULL_HANDLE;
17982 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17983
17984 {
17985 VkCommandBufferBeginInfo begin_info{};
17986 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17987 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17988
17989 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17990 nullptr, 0, nullptr, 0, nullptr);
17991
17992 VkViewport viewport{};
17993 viewport.maxDepth = 1.0f;
17994 viewport.minDepth = 0.0f;
17995 viewport.width = 512;
17996 viewport.height = 512;
17997 viewport.x = 0;
17998 viewport.y = 0;
17999 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18000 vkEndCommandBuffer(command_buffer[0]);
18001 }
18002 {
18003 VkCommandBufferBeginInfo begin_info{};
18004 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18005 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18006
18007 VkViewport viewport{};
18008 viewport.maxDepth = 1.0f;
18009 viewport.minDepth = 0.0f;
18010 viewport.width = 512;
18011 viewport.height = 512;
18012 viewport.x = 0;
18013 viewport.y = 0;
18014 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18015 vkEndCommandBuffer(command_buffer[1]);
18016 }
18017 {
18018 VkSubmitInfo submit_info{};
18019 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18020 submit_info.commandBufferCount = 1;
18021 submit_info.pCommandBuffers = &command_buffer[0];
18022 submit_info.signalSemaphoreCount = 1;
18023 submit_info.pSignalSemaphores = &semaphore;
18024 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18025 }
18026 {
18027 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18028 VkSubmitInfo submit_info{};
18029 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18030 submit_info.commandBufferCount = 1;
18031 submit_info.pCommandBuffers = &command_buffer[1];
18032 submit_info.waitSemaphoreCount = 1;
18033 submit_info.pWaitSemaphores = &semaphore;
18034 submit_info.pWaitDstStageMask = flags;
18035 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18036 }
18037
18038 vkQueueWaitIdle(m_device->m_queue);
18039
18040 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18041 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18042 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18043
18044 m_errorMonitor->VerifyNotFound();
18045}
18046
18047// This is a positive test. No errors should be generated.
18048TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18049
18050 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18051 "submitted on separate queues, the second having a fence"
18052 "followed by a QueueWaitIdle.");
18053
18054 ASSERT_NO_FATAL_FAILURE(InitState());
18055 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18056 return;
18057
18058 m_errorMonitor->ExpectSuccess();
18059
18060 VkFence fence;
18061 VkFenceCreateInfo fence_create_info{};
18062 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18063 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18064
18065 VkSemaphore semaphore;
18066 VkSemaphoreCreateInfo semaphore_create_info{};
18067 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18068 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18069
18070 VkCommandPool command_pool;
18071 VkCommandPoolCreateInfo pool_create_info{};
18072 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18073 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18074 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18075 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18076
18077 VkCommandBuffer command_buffer[2];
18078 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18079 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18080 command_buffer_allocate_info.commandPool = command_pool;
18081 command_buffer_allocate_info.commandBufferCount = 2;
18082 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18083 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18084
18085 VkQueue queue = VK_NULL_HANDLE;
18086 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18087
18088 {
18089 VkCommandBufferBeginInfo begin_info{};
18090 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18091 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18092
18093 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18094 nullptr, 0, nullptr, 0, nullptr);
18095
18096 VkViewport viewport{};
18097 viewport.maxDepth = 1.0f;
18098 viewport.minDepth = 0.0f;
18099 viewport.width = 512;
18100 viewport.height = 512;
18101 viewport.x = 0;
18102 viewport.y = 0;
18103 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18104 vkEndCommandBuffer(command_buffer[0]);
18105 }
18106 {
18107 VkCommandBufferBeginInfo begin_info{};
18108 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18109 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18110
18111 VkViewport viewport{};
18112 viewport.maxDepth = 1.0f;
18113 viewport.minDepth = 0.0f;
18114 viewport.width = 512;
18115 viewport.height = 512;
18116 viewport.x = 0;
18117 viewport.y = 0;
18118 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18119 vkEndCommandBuffer(command_buffer[1]);
18120 }
18121 {
18122 VkSubmitInfo submit_info{};
18123 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18124 submit_info.commandBufferCount = 1;
18125 submit_info.pCommandBuffers = &command_buffer[0];
18126 submit_info.signalSemaphoreCount = 1;
18127 submit_info.pSignalSemaphores = &semaphore;
18128 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18129 }
18130 {
18131 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18132 VkSubmitInfo submit_info{};
18133 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18134 submit_info.commandBufferCount = 1;
18135 submit_info.pCommandBuffers = &command_buffer[1];
18136 submit_info.waitSemaphoreCount = 1;
18137 submit_info.pWaitSemaphores = &semaphore;
18138 submit_info.pWaitDstStageMask = flags;
18139 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18140 }
18141
18142 vkQueueWaitIdle(m_device->m_queue);
18143
18144 vkDestroyFence(m_device->device(), fence, nullptr);
18145 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18146 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18147 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18148
18149 m_errorMonitor->VerifyNotFound();
18150}
18151
18152// This is a positive test. No errors should be generated.
18153TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18154
18155 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18156 "submitted on separate queues, the second having a fence"
18157 "followed by two consecutive WaitForFences calls on the same fence.");
18158
18159 ASSERT_NO_FATAL_FAILURE(InitState());
18160 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18161 return;
18162
18163 m_errorMonitor->ExpectSuccess();
18164
18165 VkFence fence;
18166 VkFenceCreateInfo fence_create_info{};
18167 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18168 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18169
18170 VkSemaphore semaphore;
18171 VkSemaphoreCreateInfo semaphore_create_info{};
18172 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18173 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18174
18175 VkCommandPool command_pool;
18176 VkCommandPoolCreateInfo pool_create_info{};
18177 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18178 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18179 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18180 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18181
18182 VkCommandBuffer command_buffer[2];
18183 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18184 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18185 command_buffer_allocate_info.commandPool = command_pool;
18186 command_buffer_allocate_info.commandBufferCount = 2;
18187 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18188 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18189
18190 VkQueue queue = VK_NULL_HANDLE;
18191 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18192
18193 {
18194 VkCommandBufferBeginInfo begin_info{};
18195 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18196 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18197
18198 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18199 nullptr, 0, nullptr, 0, nullptr);
18200
18201 VkViewport viewport{};
18202 viewport.maxDepth = 1.0f;
18203 viewport.minDepth = 0.0f;
18204 viewport.width = 512;
18205 viewport.height = 512;
18206 viewport.x = 0;
18207 viewport.y = 0;
18208 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18209 vkEndCommandBuffer(command_buffer[0]);
18210 }
18211 {
18212 VkCommandBufferBeginInfo begin_info{};
18213 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18214 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18215
18216 VkViewport viewport{};
18217 viewport.maxDepth = 1.0f;
18218 viewport.minDepth = 0.0f;
18219 viewport.width = 512;
18220 viewport.height = 512;
18221 viewport.x = 0;
18222 viewport.y = 0;
18223 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18224 vkEndCommandBuffer(command_buffer[1]);
18225 }
18226 {
18227 VkSubmitInfo submit_info{};
18228 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18229 submit_info.commandBufferCount = 1;
18230 submit_info.pCommandBuffers = &command_buffer[0];
18231 submit_info.signalSemaphoreCount = 1;
18232 submit_info.pSignalSemaphores = &semaphore;
18233 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18234 }
18235 {
18236 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18237 VkSubmitInfo submit_info{};
18238 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18239 submit_info.commandBufferCount = 1;
18240 submit_info.pCommandBuffers = &command_buffer[1];
18241 submit_info.waitSemaphoreCount = 1;
18242 submit_info.pWaitSemaphores = &semaphore;
18243 submit_info.pWaitDstStageMask = flags;
18244 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18245 }
18246
18247 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18248 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18249
18250 vkDestroyFence(m_device->device(), fence, nullptr);
18251 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18252 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18253 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18254
18255 m_errorMonitor->VerifyNotFound();
18256}
18257
18258TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18259
18260 ASSERT_NO_FATAL_FAILURE(InitState());
18261 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18262 printf("Test requires two queues, skipping\n");
18263 return;
18264 }
18265
18266 VkResult err;
18267
18268 m_errorMonitor->ExpectSuccess();
18269
18270 VkQueue q0 = m_device->m_queue;
18271 VkQueue q1 = nullptr;
18272 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18273 ASSERT_NE(q1, nullptr);
18274
18275 // An (empty) command buffer. We must have work in the first submission --
18276 // the layer treats unfenced work differently from fenced work.
18277 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18278 VkCommandPool pool;
18279 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18280 ASSERT_VK_SUCCESS(err);
18281 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18282 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18283 VkCommandBuffer cb;
18284 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18285 ASSERT_VK_SUCCESS(err);
18286 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18287 err = vkBeginCommandBuffer(cb, &cbbi);
18288 ASSERT_VK_SUCCESS(err);
18289 err = vkEndCommandBuffer(cb);
18290 ASSERT_VK_SUCCESS(err);
18291
18292 // A semaphore
18293 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18294 VkSemaphore s;
18295 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18296 ASSERT_VK_SUCCESS(err);
18297
18298 // First submission, to q0
18299 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18300
18301 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18302 ASSERT_VK_SUCCESS(err);
18303
18304 // Second submission, to q1, waiting on s
18305 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18306 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18307
18308 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18309 ASSERT_VK_SUCCESS(err);
18310
18311 // Wait for q0 idle
18312 err = vkQueueWaitIdle(q0);
18313 ASSERT_VK_SUCCESS(err);
18314
18315 // Command buffer should have been completed (it was on q0); reset the pool.
18316 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18317
18318 m_errorMonitor->VerifyNotFound();
18319
18320 // Force device completely idle and clean up resources
18321 vkDeviceWaitIdle(m_device->device());
18322 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18323 vkDestroySemaphore(m_device->device(), s, nullptr);
18324}
18325
18326// This is a positive test. No errors should be generated.
18327TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18328
18329 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18330 "submitted on separate queues, the second having a fence, "
18331 "followed by a WaitForFences call.");
18332
18333 ASSERT_NO_FATAL_FAILURE(InitState());
18334 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18335 return;
18336
18337 m_errorMonitor->ExpectSuccess();
18338
18339 ASSERT_NO_FATAL_FAILURE(InitState());
18340 VkFence fence;
18341 VkFenceCreateInfo fence_create_info{};
18342 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18343 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18344
18345 VkSemaphore semaphore;
18346 VkSemaphoreCreateInfo semaphore_create_info{};
18347 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18348 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18349
18350 VkCommandPool command_pool;
18351 VkCommandPoolCreateInfo pool_create_info{};
18352 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18353 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18354 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18355 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18356
18357 VkCommandBuffer command_buffer[2];
18358 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18359 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18360 command_buffer_allocate_info.commandPool = command_pool;
18361 command_buffer_allocate_info.commandBufferCount = 2;
18362 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18363 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18364
18365 VkQueue queue = VK_NULL_HANDLE;
18366 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18367
18368 {
18369 VkCommandBufferBeginInfo begin_info{};
18370 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18371 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18372
18373 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18374 nullptr, 0, nullptr, 0, nullptr);
18375
18376 VkViewport viewport{};
18377 viewport.maxDepth = 1.0f;
18378 viewport.minDepth = 0.0f;
18379 viewport.width = 512;
18380 viewport.height = 512;
18381 viewport.x = 0;
18382 viewport.y = 0;
18383 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18384 vkEndCommandBuffer(command_buffer[0]);
18385 }
18386 {
18387 VkCommandBufferBeginInfo begin_info{};
18388 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18389 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18390
18391 VkViewport viewport{};
18392 viewport.maxDepth = 1.0f;
18393 viewport.minDepth = 0.0f;
18394 viewport.width = 512;
18395 viewport.height = 512;
18396 viewport.x = 0;
18397 viewport.y = 0;
18398 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18399 vkEndCommandBuffer(command_buffer[1]);
18400 }
18401 {
18402 VkSubmitInfo submit_info{};
18403 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18404 submit_info.commandBufferCount = 1;
18405 submit_info.pCommandBuffers = &command_buffer[0];
18406 submit_info.signalSemaphoreCount = 1;
18407 submit_info.pSignalSemaphores = &semaphore;
18408 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18409 }
18410 {
18411 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18412 VkSubmitInfo submit_info{};
18413 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18414 submit_info.commandBufferCount = 1;
18415 submit_info.pCommandBuffers = &command_buffer[1];
18416 submit_info.waitSemaphoreCount = 1;
18417 submit_info.pWaitSemaphores = &semaphore;
18418 submit_info.pWaitDstStageMask = flags;
18419 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18420 }
18421
18422 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18423
18424 vkDestroyFence(m_device->device(), fence, nullptr);
18425 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18426 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18427 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18428
18429 m_errorMonitor->VerifyNotFound();
18430}
18431
18432// This is a positive test. No errors should be generated.
18433TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18434
18435 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18436 "on the same queue, sharing a signal/wait semaphore, the "
18437 "second having a fence, "
18438 "followed by a WaitForFences call.");
18439
18440 m_errorMonitor->ExpectSuccess();
18441
18442 ASSERT_NO_FATAL_FAILURE(InitState());
18443 VkFence fence;
18444 VkFenceCreateInfo fence_create_info{};
18445 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18446 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18447
18448 VkSemaphore semaphore;
18449 VkSemaphoreCreateInfo semaphore_create_info{};
18450 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18451 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18452
18453 VkCommandPool command_pool;
18454 VkCommandPoolCreateInfo pool_create_info{};
18455 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18456 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18457 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18458 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18459
18460 VkCommandBuffer command_buffer[2];
18461 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18462 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18463 command_buffer_allocate_info.commandPool = command_pool;
18464 command_buffer_allocate_info.commandBufferCount = 2;
18465 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18466 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18467
18468 {
18469 VkCommandBufferBeginInfo begin_info{};
18470 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18471 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18472
18473 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18474 nullptr, 0, nullptr, 0, nullptr);
18475
18476 VkViewport viewport{};
18477 viewport.maxDepth = 1.0f;
18478 viewport.minDepth = 0.0f;
18479 viewport.width = 512;
18480 viewport.height = 512;
18481 viewport.x = 0;
18482 viewport.y = 0;
18483 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18484 vkEndCommandBuffer(command_buffer[0]);
18485 }
18486 {
18487 VkCommandBufferBeginInfo begin_info{};
18488 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18489 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18490
18491 VkViewport viewport{};
18492 viewport.maxDepth = 1.0f;
18493 viewport.minDepth = 0.0f;
18494 viewport.width = 512;
18495 viewport.height = 512;
18496 viewport.x = 0;
18497 viewport.y = 0;
18498 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18499 vkEndCommandBuffer(command_buffer[1]);
18500 }
18501 {
18502 VkSubmitInfo submit_info{};
18503 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18504 submit_info.commandBufferCount = 1;
18505 submit_info.pCommandBuffers = &command_buffer[0];
18506 submit_info.signalSemaphoreCount = 1;
18507 submit_info.pSignalSemaphores = &semaphore;
18508 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18509 }
18510 {
18511 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18512 VkSubmitInfo submit_info{};
18513 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18514 submit_info.commandBufferCount = 1;
18515 submit_info.pCommandBuffers = &command_buffer[1];
18516 submit_info.waitSemaphoreCount = 1;
18517 submit_info.pWaitSemaphores = &semaphore;
18518 submit_info.pWaitDstStageMask = flags;
18519 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18520 }
18521
18522 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18523
18524 vkDestroyFence(m_device->device(), fence, nullptr);
18525 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18526 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18527 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18528
18529 m_errorMonitor->VerifyNotFound();
18530}
18531
18532// This is a positive test. No errors should be generated.
18533TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18534
18535 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18536 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18537 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18538
18539 m_errorMonitor->ExpectSuccess();
18540
18541 ASSERT_NO_FATAL_FAILURE(InitState());
18542 VkFence fence;
18543 VkFenceCreateInfo fence_create_info{};
18544 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18545 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18546
18547 VkCommandPool command_pool;
18548 VkCommandPoolCreateInfo pool_create_info{};
18549 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18550 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18551 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18552 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18553
18554 VkCommandBuffer command_buffer[2];
18555 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18556 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18557 command_buffer_allocate_info.commandPool = command_pool;
18558 command_buffer_allocate_info.commandBufferCount = 2;
18559 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18560 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18561
18562 {
18563 VkCommandBufferBeginInfo begin_info{};
18564 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18565 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18566
18567 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18568 nullptr, 0, nullptr, 0, nullptr);
18569
18570 VkViewport viewport{};
18571 viewport.maxDepth = 1.0f;
18572 viewport.minDepth = 0.0f;
18573 viewport.width = 512;
18574 viewport.height = 512;
18575 viewport.x = 0;
18576 viewport.y = 0;
18577 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18578 vkEndCommandBuffer(command_buffer[0]);
18579 }
18580 {
18581 VkCommandBufferBeginInfo begin_info{};
18582 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18583 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18584
18585 VkViewport viewport{};
18586 viewport.maxDepth = 1.0f;
18587 viewport.minDepth = 0.0f;
18588 viewport.width = 512;
18589 viewport.height = 512;
18590 viewport.x = 0;
18591 viewport.y = 0;
18592 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18593 vkEndCommandBuffer(command_buffer[1]);
18594 }
18595 {
18596 VkSubmitInfo submit_info{};
18597 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18598 submit_info.commandBufferCount = 1;
18599 submit_info.pCommandBuffers = &command_buffer[0];
18600 submit_info.signalSemaphoreCount = 0;
18601 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18602 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18603 }
18604 {
18605 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18606 VkSubmitInfo submit_info{};
18607 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18608 submit_info.commandBufferCount = 1;
18609 submit_info.pCommandBuffers = &command_buffer[1];
18610 submit_info.waitSemaphoreCount = 0;
18611 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18612 submit_info.pWaitDstStageMask = flags;
18613 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18614 }
18615
18616 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18617
18618 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18619 ASSERT_VK_SUCCESS(err);
18620
18621 vkDestroyFence(m_device->device(), fence, nullptr);
18622 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18623 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18624
18625 m_errorMonitor->VerifyNotFound();
18626}
18627
18628// This is a positive test. No errors should be generated.
18629TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18630
18631 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18632 "on the same queue, the second having a fence, followed "
18633 "by a WaitForFences call.");
18634
18635 m_errorMonitor->ExpectSuccess();
18636
18637 ASSERT_NO_FATAL_FAILURE(InitState());
18638 VkFence fence;
18639 VkFenceCreateInfo fence_create_info{};
18640 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18641 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18642
18643 VkCommandPool command_pool;
18644 VkCommandPoolCreateInfo pool_create_info{};
18645 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18646 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18647 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18648 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18649
18650 VkCommandBuffer command_buffer[2];
18651 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18652 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18653 command_buffer_allocate_info.commandPool = command_pool;
18654 command_buffer_allocate_info.commandBufferCount = 2;
18655 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18656 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18657
18658 {
18659 VkCommandBufferBeginInfo begin_info{};
18660 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18661 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18662
18663 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18664 nullptr, 0, nullptr, 0, nullptr);
18665
18666 VkViewport viewport{};
18667 viewport.maxDepth = 1.0f;
18668 viewport.minDepth = 0.0f;
18669 viewport.width = 512;
18670 viewport.height = 512;
18671 viewport.x = 0;
18672 viewport.y = 0;
18673 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18674 vkEndCommandBuffer(command_buffer[0]);
18675 }
18676 {
18677 VkCommandBufferBeginInfo begin_info{};
18678 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18679 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18680
18681 VkViewport viewport{};
18682 viewport.maxDepth = 1.0f;
18683 viewport.minDepth = 0.0f;
18684 viewport.width = 512;
18685 viewport.height = 512;
18686 viewport.x = 0;
18687 viewport.y = 0;
18688 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18689 vkEndCommandBuffer(command_buffer[1]);
18690 }
18691 {
18692 VkSubmitInfo submit_info{};
18693 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18694 submit_info.commandBufferCount = 1;
18695 submit_info.pCommandBuffers = &command_buffer[0];
18696 submit_info.signalSemaphoreCount = 0;
18697 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18698 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18699 }
18700 {
18701 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18702 VkSubmitInfo submit_info{};
18703 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18704 submit_info.commandBufferCount = 1;
18705 submit_info.pCommandBuffers = &command_buffer[1];
18706 submit_info.waitSemaphoreCount = 0;
18707 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18708 submit_info.pWaitDstStageMask = flags;
18709 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18710 }
18711
18712 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18713
18714 vkDestroyFence(m_device->device(), fence, nullptr);
18715 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18716 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18717
18718 m_errorMonitor->VerifyNotFound();
18719}
18720
18721// This is a positive test. No errors should be generated.
18722TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18723
18724 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18725 "QueueSubmit call followed by a WaitForFences call.");
18726 ASSERT_NO_FATAL_FAILURE(InitState());
18727
18728 m_errorMonitor->ExpectSuccess();
18729
18730 VkFence fence;
18731 VkFenceCreateInfo fence_create_info{};
18732 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18733 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18734
18735 VkSemaphore semaphore;
18736 VkSemaphoreCreateInfo semaphore_create_info{};
18737 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18738 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18739
18740 VkCommandPool command_pool;
18741 VkCommandPoolCreateInfo pool_create_info{};
18742 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18743 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18744 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18745 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18746
18747 VkCommandBuffer command_buffer[2];
18748 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18749 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18750 command_buffer_allocate_info.commandPool = command_pool;
18751 command_buffer_allocate_info.commandBufferCount = 2;
18752 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18753 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18754
18755 {
18756 VkCommandBufferBeginInfo begin_info{};
18757 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18758 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18759
18760 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18761 nullptr, 0, nullptr, 0, nullptr);
18762
18763 VkViewport viewport{};
18764 viewport.maxDepth = 1.0f;
18765 viewport.minDepth = 0.0f;
18766 viewport.width = 512;
18767 viewport.height = 512;
18768 viewport.x = 0;
18769 viewport.y = 0;
18770 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18771 vkEndCommandBuffer(command_buffer[0]);
18772 }
18773 {
18774 VkCommandBufferBeginInfo begin_info{};
18775 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18776 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18777
18778 VkViewport viewport{};
18779 viewport.maxDepth = 1.0f;
18780 viewport.minDepth = 0.0f;
18781 viewport.width = 512;
18782 viewport.height = 512;
18783 viewport.x = 0;
18784 viewport.y = 0;
18785 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18786 vkEndCommandBuffer(command_buffer[1]);
18787 }
18788 {
18789 VkSubmitInfo submit_info[2];
18790 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18791
18792 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18793 submit_info[0].pNext = NULL;
18794 submit_info[0].commandBufferCount = 1;
18795 submit_info[0].pCommandBuffers = &command_buffer[0];
18796 submit_info[0].signalSemaphoreCount = 1;
18797 submit_info[0].pSignalSemaphores = &semaphore;
18798 submit_info[0].waitSemaphoreCount = 0;
18799 submit_info[0].pWaitSemaphores = NULL;
18800 submit_info[0].pWaitDstStageMask = 0;
18801
18802 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18803 submit_info[1].pNext = NULL;
18804 submit_info[1].commandBufferCount = 1;
18805 submit_info[1].pCommandBuffers = &command_buffer[1];
18806 submit_info[1].waitSemaphoreCount = 1;
18807 submit_info[1].pWaitSemaphores = &semaphore;
18808 submit_info[1].pWaitDstStageMask = flags;
18809 submit_info[1].signalSemaphoreCount = 0;
18810 submit_info[1].pSignalSemaphores = NULL;
18811 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18812 }
18813
18814 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18815
18816 vkDestroyFence(m_device->device(), fence, nullptr);
18817 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18818 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18819 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18820
18821 m_errorMonitor->VerifyNotFound();
18822}
18823
18824TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18825 m_errorMonitor->ExpectSuccess();
18826
18827 ASSERT_NO_FATAL_FAILURE(InitState());
18828 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18829
18830 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18831 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18832
18833 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18834 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18835 m_errorMonitor->VerifyNotFound();
18836 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18837 m_errorMonitor->VerifyNotFound();
18838 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18839 m_errorMonitor->VerifyNotFound();
18840
18841 m_commandBuffer->EndCommandBuffer();
18842 m_errorMonitor->VerifyNotFound();
18843}
18844
18845TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18846 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18847 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18848 "has a valid layout, and a second subpass then uses a "
18849 "valid *READ_ONLY* layout.");
18850 m_errorMonitor->ExpectSuccess();
18851 ASSERT_NO_FATAL_FAILURE(InitState());
18852
18853 VkAttachmentReference attach[2] = {};
18854 attach[0].attachment = 0;
18855 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18856 attach[1].attachment = 0;
18857 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18858 VkSubpassDescription subpasses[2] = {};
18859 // First subpass clears DS attach on load
18860 subpasses[0].pDepthStencilAttachment = &attach[0];
18861 // 2nd subpass reads in DS as input attachment
18862 subpasses[1].inputAttachmentCount = 1;
18863 subpasses[1].pInputAttachments = &attach[1];
18864 VkAttachmentDescription attach_desc = {};
18865 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18866 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18867 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18868 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18869 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18870 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18871 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18872 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18873 VkRenderPassCreateInfo rpci = {};
18874 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18875 rpci.attachmentCount = 1;
18876 rpci.pAttachments = &attach_desc;
18877 rpci.subpassCount = 2;
18878 rpci.pSubpasses = subpasses;
18879
18880 // Now create RenderPass and verify no errors
18881 VkRenderPass rp;
18882 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18883 m_errorMonitor->VerifyNotFound();
18884
18885 vkDestroyRenderPass(m_device->device(), rp, NULL);
18886}
18887
18888TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18889 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18890 "as vertex attributes");
18891 m_errorMonitor->ExpectSuccess();
18892
18893 ASSERT_NO_FATAL_FAILURE(InitState());
18894 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18895
18896 VkVertexInputBindingDescription input_binding;
18897 memset(&input_binding, 0, sizeof(input_binding));
18898
18899 VkVertexInputAttributeDescription input_attribs[2];
18900 memset(input_attribs, 0, sizeof(input_attribs));
18901
18902 for (int i = 0; i < 2; i++) {
18903 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18904 input_attribs[i].location = i;
18905 }
18906
18907 char const *vsSource = "#version 450\n"
18908 "\n"
18909 "layout(location=0) in mat2x4 x;\n"
18910 "out gl_PerVertex {\n"
18911 " vec4 gl_Position;\n"
18912 "};\n"
18913 "void main(){\n"
18914 " gl_Position = x[0] + x[1];\n"
18915 "}\n";
18916 char const *fsSource = "#version 450\n"
18917 "\n"
18918 "layout(location=0) out vec4 color;\n"
18919 "void main(){\n"
18920 " color = vec4(1);\n"
18921 "}\n";
18922
18923 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18924 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18925
18926 VkPipelineObj pipe(m_device);
18927 pipe.AddColorAttachment();
18928 pipe.AddShader(&vs);
18929 pipe.AddShader(&fs);
18930
18931 pipe.AddVertexInputBindings(&input_binding, 1);
18932 pipe.AddVertexInputAttribs(input_attribs, 2);
18933
18934 VkDescriptorSetObj descriptorSet(m_device);
18935 descriptorSet.AppendDummy();
18936 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18937
18938 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18939
18940 /* expect success */
18941 m_errorMonitor->VerifyNotFound();
18942}
18943
18944TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18945 m_errorMonitor->ExpectSuccess();
18946
18947 ASSERT_NO_FATAL_FAILURE(InitState());
18948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18949
18950 VkVertexInputBindingDescription input_binding;
18951 memset(&input_binding, 0, sizeof(input_binding));
18952
18953 VkVertexInputAttributeDescription input_attribs[2];
18954 memset(input_attribs, 0, sizeof(input_attribs));
18955
18956 for (int i = 0; i < 2; i++) {
18957 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18958 input_attribs[i].location = i;
18959 }
18960
18961 char const *vsSource = "#version 450\n"
18962 "\n"
18963 "layout(location=0) in vec4 x[2];\n"
18964 "out gl_PerVertex {\n"
18965 " vec4 gl_Position;\n"
18966 "};\n"
18967 "void main(){\n"
18968 " gl_Position = x[0] + x[1];\n"
18969 "}\n";
18970 char const *fsSource = "#version 450\n"
18971 "\n"
18972 "layout(location=0) out vec4 color;\n"
18973 "void main(){\n"
18974 " color = vec4(1);\n"
18975 "}\n";
18976
18977 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18978 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18979
18980 VkPipelineObj pipe(m_device);
18981 pipe.AddColorAttachment();
18982 pipe.AddShader(&vs);
18983 pipe.AddShader(&fs);
18984
18985 pipe.AddVertexInputBindings(&input_binding, 1);
18986 pipe.AddVertexInputAttribs(input_attribs, 2);
18987
18988 VkDescriptorSetObj descriptorSet(m_device);
18989 descriptorSet.AppendDummy();
18990 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18991
18992 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18993
18994 m_errorMonitor->VerifyNotFound();
18995}
18996
18997TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18998 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18999 "through multiple vertex shader inputs, each consuming a different "
19000 "subset of the components.");
19001 m_errorMonitor->ExpectSuccess();
19002
19003 ASSERT_NO_FATAL_FAILURE(InitState());
19004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19005
19006 VkVertexInputBindingDescription input_binding;
19007 memset(&input_binding, 0, sizeof(input_binding));
19008
19009 VkVertexInputAttributeDescription input_attribs[3];
19010 memset(input_attribs, 0, sizeof(input_attribs));
19011
19012 for (int i = 0; i < 3; i++) {
19013 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19014 input_attribs[i].location = i;
19015 }
19016
19017 char const *vsSource = "#version 450\n"
19018 "\n"
19019 "layout(location=0) in vec4 x;\n"
19020 "layout(location=1) in vec3 y1;\n"
19021 "layout(location=1, component=3) in float y2;\n"
19022 "layout(location=2) in vec4 z;\n"
19023 "out gl_PerVertex {\n"
19024 " vec4 gl_Position;\n"
19025 "};\n"
19026 "void main(){\n"
19027 " gl_Position = x + vec4(y1, y2) + z;\n"
19028 "}\n";
19029 char const *fsSource = "#version 450\n"
19030 "\n"
19031 "layout(location=0) out vec4 color;\n"
19032 "void main(){\n"
19033 " color = vec4(1);\n"
19034 "}\n";
19035
19036 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19037 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19038
19039 VkPipelineObj pipe(m_device);
19040 pipe.AddColorAttachment();
19041 pipe.AddShader(&vs);
19042 pipe.AddShader(&fs);
19043
19044 pipe.AddVertexInputBindings(&input_binding, 1);
19045 pipe.AddVertexInputAttribs(input_attribs, 3);
19046
19047 VkDescriptorSetObj descriptorSet(m_device);
19048 descriptorSet.AppendDummy();
19049 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19050
19051 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19052
19053 m_errorMonitor->VerifyNotFound();
19054}
19055
19056TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19057 m_errorMonitor->ExpectSuccess();
19058
19059 ASSERT_NO_FATAL_FAILURE(InitState());
19060 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19061
19062 char const *vsSource = "#version 450\n"
19063 "out gl_PerVertex {\n"
19064 " vec4 gl_Position;\n"
19065 "};\n"
19066 "void main(){\n"
19067 " gl_Position = vec4(0);\n"
19068 "}\n";
19069 char const *fsSource = "#version 450\n"
19070 "\n"
19071 "layout(location=0) out vec4 color;\n"
19072 "void main(){\n"
19073 " color = vec4(1);\n"
19074 "}\n";
19075
19076 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19077 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19078
19079 VkPipelineObj pipe(m_device);
19080 pipe.AddColorAttachment();
19081 pipe.AddShader(&vs);
19082 pipe.AddShader(&fs);
19083
19084 VkDescriptorSetObj descriptorSet(m_device);
19085 descriptorSet.AppendDummy();
19086 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19087
19088 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19089
19090 m_errorMonitor->VerifyNotFound();
19091}
19092
19093TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19094 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19095 "set out in 14.1.3: fundamental type must match, and producer side must "
19096 "have at least as many components");
19097 m_errorMonitor->ExpectSuccess();
19098
19099 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19100
19101 ASSERT_NO_FATAL_FAILURE(InitState());
19102 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19103
19104 char const *vsSource = "#version 450\n"
19105 "out gl_PerVertex {\n"
19106 " vec4 gl_Position;\n"
19107 "};\n"
19108 "layout(location=0) out vec3 x;\n"
19109 "layout(location=1) out ivec3 y;\n"
19110 "layout(location=2) out vec3 z;\n"
19111 "void main(){\n"
19112 " gl_Position = vec4(0);\n"
19113 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19114 "}\n";
19115 char const *fsSource = "#version 450\n"
19116 "\n"
19117 "layout(location=0) out vec4 color;\n"
19118 "layout(location=0) in float x;\n"
19119 "layout(location=1) flat in int y;\n"
19120 "layout(location=2) in vec2 z;\n"
19121 "void main(){\n"
19122 " color = vec4(1 + x + y + z.x);\n"
19123 "}\n";
19124
19125 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19126 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19127
19128 VkPipelineObj pipe(m_device);
19129 pipe.AddColorAttachment();
19130 pipe.AddShader(&vs);
19131 pipe.AddShader(&fs);
19132
19133 VkDescriptorSetObj descriptorSet(m_device);
19134 descriptorSet.AppendDummy();
19135 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19136
19137 VkResult err = VK_SUCCESS;
19138 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19139 ASSERT_VK_SUCCESS(err);
19140
19141 m_errorMonitor->VerifyNotFound();
19142}
19143
19144TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19145 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19146 "passed between the TCS and TES stages");
19147 m_errorMonitor->ExpectSuccess();
19148
19149 ASSERT_NO_FATAL_FAILURE(InitState());
19150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19151
19152 if (!m_device->phy().features().tessellationShader) {
19153 printf("Device does not support tessellation shaders; skipped.\n");
19154 return;
19155 }
19156
19157 char const *vsSource = "#version 450\n"
19158 "void main(){}\n";
19159 char const *tcsSource = "#version 450\n"
19160 "layout(location=0) out int x[];\n"
19161 "layout(vertices=3) out;\n"
19162 "void main(){\n"
19163 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19164 " gl_TessLevelInner[0] = 1;\n"
19165 " x[gl_InvocationID] = gl_InvocationID;\n"
19166 "}\n";
19167 char const *tesSource = "#version 450\n"
19168 "layout(triangles, equal_spacing, cw) in;\n"
19169 "layout(location=0) in int x[];\n"
19170 "out gl_PerVertex { vec4 gl_Position; };\n"
19171 "void main(){\n"
19172 " gl_Position.xyz = gl_TessCoord;\n"
19173 " gl_Position.w = x[0] + x[1] + x[2];\n"
19174 "}\n";
19175 char const *fsSource = "#version 450\n"
19176 "layout(location=0) out vec4 color;\n"
19177 "void main(){\n"
19178 " color = vec4(1);\n"
19179 "}\n";
19180
19181 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19182 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19183 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19184 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19185
19186 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19187 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19188
19189 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19190
19191 VkPipelineObj pipe(m_device);
19192 pipe.SetInputAssembly(&iasci);
19193 pipe.SetTessellation(&tsci);
19194 pipe.AddColorAttachment();
19195 pipe.AddShader(&vs);
19196 pipe.AddShader(&tcs);
19197 pipe.AddShader(&tes);
19198 pipe.AddShader(&fs);
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, CreatePipelineGeometryInputBlockPositive) {
19210 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19211 "interface block passed into the geometry shader. This "
19212 "is interesting because the 'extra' array level is not "
19213 "present on the member type, but on the block instance.");
19214 m_errorMonitor->ExpectSuccess();
19215
19216 ASSERT_NO_FATAL_FAILURE(InitState());
19217 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19218
19219 if (!m_device->phy().features().geometryShader) {
19220 printf("Device does not support geometry shaders; skipped.\n");
19221 return;
19222 }
19223
19224 char const *vsSource = "#version 450\n"
19225 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19226 "void main(){\n"
19227 " vs_out.x = vec4(1);\n"
19228 "}\n";
19229 char const *gsSource = "#version 450\n"
19230 "layout(triangles) in;\n"
19231 "layout(triangle_strip, max_vertices=3) out;\n"
19232 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19233 "out gl_PerVertex { vec4 gl_Position; };\n"
19234 "void main() {\n"
19235 " gl_Position = gs_in[0].x;\n"
19236 " EmitVertex();\n"
19237 "}\n";
19238 char const *fsSource = "#version 450\n"
19239 "layout(location=0) out vec4 color;\n"
19240 "void main(){\n"
19241 " color = vec4(1);\n"
19242 "}\n";
19243
19244 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19245 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19246 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19247
19248 VkPipelineObj pipe(m_device);
19249 pipe.AddColorAttachment();
19250 pipe.AddShader(&vs);
19251 pipe.AddShader(&gs);
19252 pipe.AddShader(&fs);
19253
19254 VkDescriptorSetObj descriptorSet(m_device);
19255 descriptorSet.AppendDummy();
19256 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19257
19258 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19259
19260 m_errorMonitor->VerifyNotFound();
19261}
19262
19263TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19264 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19265 "attributes. This is interesting because they consume multiple "
19266 "locations.");
19267 m_errorMonitor->ExpectSuccess();
19268
19269 ASSERT_NO_FATAL_FAILURE(InitState());
19270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19271
19272 if (!m_device->phy().features().shaderFloat64) {
19273 printf("Device does not support 64bit vertex attributes; skipped.\n");
19274 return;
19275 }
19276
19277 VkVertexInputBindingDescription input_bindings[1];
19278 memset(input_bindings, 0, sizeof(input_bindings));
19279
19280 VkVertexInputAttributeDescription input_attribs[4];
19281 memset(input_attribs, 0, sizeof(input_attribs));
19282 input_attribs[0].location = 0;
19283 input_attribs[0].offset = 0;
19284 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19285 input_attribs[1].location = 2;
19286 input_attribs[1].offset = 32;
19287 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19288 input_attribs[2].location = 4;
19289 input_attribs[2].offset = 64;
19290 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19291 input_attribs[3].location = 6;
19292 input_attribs[3].offset = 96;
19293 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19294
19295 char const *vsSource = "#version 450\n"
19296 "\n"
19297 "layout(location=0) in dmat4 x;\n"
19298 "out gl_PerVertex {\n"
19299 " vec4 gl_Position;\n"
19300 "};\n"
19301 "void main(){\n"
19302 " gl_Position = vec4(x[0][0]);\n"
19303 "}\n";
19304 char const *fsSource = "#version 450\n"
19305 "\n"
19306 "layout(location=0) out vec4 color;\n"
19307 "void main(){\n"
19308 " color = vec4(1);\n"
19309 "}\n";
19310
19311 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19312 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19313
19314 VkPipelineObj pipe(m_device);
19315 pipe.AddColorAttachment();
19316 pipe.AddShader(&vs);
19317 pipe.AddShader(&fs);
19318
19319 pipe.AddVertexInputBindings(input_bindings, 1);
19320 pipe.AddVertexInputAttribs(input_attribs, 4);
19321
19322 VkDescriptorSetObj descriptorSet(m_device);
19323 descriptorSet.AppendDummy();
19324 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19325
19326 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19327
19328 m_errorMonitor->VerifyNotFound();
19329}
19330
19331TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19332 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19333 m_errorMonitor->ExpectSuccess();
19334
19335 ASSERT_NO_FATAL_FAILURE(InitState());
19336
19337 char const *vsSource = "#version 450\n"
19338 "\n"
19339 "out gl_PerVertex {\n"
19340 " vec4 gl_Position;\n"
19341 "};\n"
19342 "void main(){\n"
19343 " gl_Position = vec4(1);\n"
19344 "}\n";
19345 char const *fsSource = "#version 450\n"
19346 "\n"
19347 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19348 "layout(location=0) out vec4 color;\n"
19349 "void main() {\n"
19350 " color = subpassLoad(x);\n"
19351 "}\n";
19352
19353 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19354 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19355
19356 VkPipelineObj pipe(m_device);
19357 pipe.AddShader(&vs);
19358 pipe.AddShader(&fs);
19359 pipe.AddColorAttachment();
19360 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19361
19362 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19363 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19364 VkDescriptorSetLayout dsl;
19365 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19366 ASSERT_VK_SUCCESS(err);
19367
19368 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19369 VkPipelineLayout pl;
19370 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19371 ASSERT_VK_SUCCESS(err);
19372
19373 VkAttachmentDescription descs[2] = {
19374 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19375 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19376 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19377 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19378 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19379 };
19380 VkAttachmentReference color = {
19381 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19382 };
19383 VkAttachmentReference input = {
19384 1, VK_IMAGE_LAYOUT_GENERAL,
19385 };
19386
19387 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19388
19389 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19390 VkRenderPass rp;
19391 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19392 ASSERT_VK_SUCCESS(err);
19393
19394 // should be OK. would go wrong here if it's going to...
19395 pipe.CreateVKPipeline(pl, rp);
19396
19397 m_errorMonitor->VerifyNotFound();
19398
19399 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19400 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19401 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19402}
19403
19404TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19405 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19406 "descriptor-backed resource which is not provided, but the shader does not "
19407 "statically use it. This is interesting because it requires compute pipelines "
19408 "to have a proper descriptor use walk, which they didn't for some time.");
19409 m_errorMonitor->ExpectSuccess();
19410
19411 ASSERT_NO_FATAL_FAILURE(InitState());
19412
19413 char const *csSource = "#version 450\n"
19414 "\n"
19415 "layout(local_size_x=1) in;\n"
19416 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19417 "void main(){\n"
19418 " // x is not used.\n"
19419 "}\n";
19420
19421 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19422
19423 VkDescriptorSetObj descriptorSet(m_device);
19424 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19425
19426 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19427 nullptr,
19428 0,
19429 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19430 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19431 descriptorSet.GetPipelineLayout(),
19432 VK_NULL_HANDLE,
19433 -1 };
19434
19435 VkPipeline pipe;
19436 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19437
19438 m_errorMonitor->VerifyNotFound();
19439
19440 if (err == VK_SUCCESS) {
19441 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19442 }
19443}
19444
19445TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19446 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19447 "sampler portion of a combined image + sampler");
19448 m_errorMonitor->ExpectSuccess();
19449
19450 ASSERT_NO_FATAL_FAILURE(InitState());
19451
19452 VkDescriptorSetLayoutBinding bindings[] = {
19453 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19454 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19455 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19456 };
19457 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19458 VkDescriptorSetLayout dsl;
19459 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19460 ASSERT_VK_SUCCESS(err);
19461
19462 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19463 VkPipelineLayout pl;
19464 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19465 ASSERT_VK_SUCCESS(err);
19466
19467 char const *csSource = "#version 450\n"
19468 "\n"
19469 "layout(local_size_x=1) in;\n"
19470 "layout(set=0, binding=0) uniform sampler s;\n"
19471 "layout(set=0, binding=1) uniform texture2D t;\n"
19472 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19473 "void main() {\n"
19474 " x = texture(sampler2D(t, s), vec2(0));\n"
19475 "}\n";
19476 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19477
19478 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19479 nullptr,
19480 0,
19481 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19482 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19483 pl,
19484 VK_NULL_HANDLE,
19485 -1 };
19486
19487 VkPipeline pipe;
19488 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19489
19490 m_errorMonitor->VerifyNotFound();
19491
19492 if (err == VK_SUCCESS) {
19493 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19494 }
19495
19496 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19497 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19498}
19499
19500TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19501 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19502 "image portion of a combined image + sampler");
19503 m_errorMonitor->ExpectSuccess();
19504
19505 ASSERT_NO_FATAL_FAILURE(InitState());
19506
19507 VkDescriptorSetLayoutBinding bindings[] = {
19508 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19509 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19510 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19511 };
19512 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19513 VkDescriptorSetLayout dsl;
19514 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19515 ASSERT_VK_SUCCESS(err);
19516
19517 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19518 VkPipelineLayout pl;
19519 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19520 ASSERT_VK_SUCCESS(err);
19521
19522 char const *csSource = "#version 450\n"
19523 "\n"
19524 "layout(local_size_x=1) in;\n"
19525 "layout(set=0, binding=0) uniform texture2D t;\n"
19526 "layout(set=0, binding=1) uniform sampler s;\n"
19527 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19528 "void main() {\n"
19529 " x = texture(sampler2D(t, s), vec2(0));\n"
19530 "}\n";
19531 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19532
19533 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19534 nullptr,
19535 0,
19536 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19537 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19538 pl,
19539 VK_NULL_HANDLE,
19540 -1 };
19541
19542 VkPipeline pipe;
19543 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19544
19545 m_errorMonitor->VerifyNotFound();
19546
19547 if (err == VK_SUCCESS) {
19548 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19549 }
19550
19551 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19552 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19553}
19554
19555TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19556 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19557 "both the sampler and the image of a combined image+sampler "
19558 "but via separate variables");
19559 m_errorMonitor->ExpectSuccess();
19560
19561 ASSERT_NO_FATAL_FAILURE(InitState());
19562
19563 VkDescriptorSetLayoutBinding bindings[] = {
19564 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19565 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19566 };
19567 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19568 VkDescriptorSetLayout dsl;
19569 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19570 ASSERT_VK_SUCCESS(err);
19571
19572 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19573 VkPipelineLayout pl;
19574 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19575 ASSERT_VK_SUCCESS(err);
19576
19577 char const *csSource = "#version 450\n"
19578 "\n"
19579 "layout(local_size_x=1) in;\n"
19580 "layout(set=0, binding=0) uniform texture2D t;\n"
19581 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19582 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19583 "void main() {\n"
19584 " x = texture(sampler2D(t, s), vec2(0));\n"
19585 "}\n";
19586 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19587
19588 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19589 nullptr,
19590 0,
19591 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19592 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19593 pl,
19594 VK_NULL_HANDLE,
19595 -1 };
19596
19597 VkPipeline pipe;
19598 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19599
19600 m_errorMonitor->VerifyNotFound();
19601
19602 if (err == VK_SUCCESS) {
19603 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19604 }
19605
19606 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19607 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19608}
19609
19610TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19611 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19612
19613 ASSERT_NO_FATAL_FAILURE(InitState());
19614
19615 // Positive test to check parameter_validation and unique_objects support
19616 // for NV_dedicated_allocation
19617 uint32_t extension_count = 0;
19618 bool supports_nv_dedicated_allocation = false;
19619 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19620 ASSERT_VK_SUCCESS(err);
19621
19622 if (extension_count > 0) {
19623 std::vector<VkExtensionProperties> available_extensions(extension_count);
19624
19625 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19626 ASSERT_VK_SUCCESS(err);
19627
19628 for (const auto &extension_props : available_extensions) {
19629 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19630 supports_nv_dedicated_allocation = true;
19631 }
19632 }
19633 }
19634
19635 if (supports_nv_dedicated_allocation) {
19636 m_errorMonitor->ExpectSuccess();
19637
19638 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19639 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19640 dedicated_buffer_create_info.pNext = nullptr;
19641 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19642
19643 uint32_t queue_family_index = 0;
19644 VkBufferCreateInfo buffer_create_info = {};
19645 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19646 buffer_create_info.pNext = &dedicated_buffer_create_info;
19647 buffer_create_info.size = 1024;
19648 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19649 buffer_create_info.queueFamilyIndexCount = 1;
19650 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19651
19652 VkBuffer buffer;
19653 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19654 ASSERT_VK_SUCCESS(err);
19655
19656 VkMemoryRequirements memory_reqs;
19657 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19658
19659 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19660 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19661 dedicated_memory_info.pNext = nullptr;
19662 dedicated_memory_info.buffer = buffer;
19663 dedicated_memory_info.image = VK_NULL_HANDLE;
19664
19665 VkMemoryAllocateInfo memory_info = {};
19666 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19667 memory_info.pNext = &dedicated_memory_info;
19668 memory_info.allocationSize = memory_reqs.size;
19669
19670 bool pass;
19671 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19672 ASSERT_TRUE(pass);
19673
19674 VkDeviceMemory buffer_memory;
19675 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19676 ASSERT_VK_SUCCESS(err);
19677
19678 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19679 ASSERT_VK_SUCCESS(err);
19680
19681 vkDestroyBuffer(m_device->device(), buffer, NULL);
19682 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19683
19684 m_errorMonitor->VerifyNotFound();
19685 }
19686}
19687
19688TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19689 VkResult err;
19690
19691 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19692
19693 ASSERT_NO_FATAL_FAILURE(InitState());
19694 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19695
19696 std::vector<const char *> device_extension_names;
19697 auto features = m_device->phy().features();
19698 // Artificially disable support for non-solid fill modes
19699 features.fillModeNonSolid = false;
19700 // The sacrificial device object
19701 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19702
19703 VkRenderpassObj render_pass(&test_device);
19704
19705 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19706 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19707 pipeline_layout_ci.setLayoutCount = 0;
19708 pipeline_layout_ci.pSetLayouts = NULL;
19709
19710 VkPipelineLayout pipeline_layout;
19711 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19712 ASSERT_VK_SUCCESS(err);
19713
19714 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19715 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19716 rs_ci.pNext = nullptr;
19717 rs_ci.lineWidth = 1.0f;
19718 rs_ci.rasterizerDiscardEnable = true;
19719
19720 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19721 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19722
19723 // Set polygonMode=FILL. No error is expected
19724 m_errorMonitor->ExpectSuccess();
19725 {
19726 VkPipelineObj pipe(&test_device);
19727 pipe.AddShader(&vs);
19728 pipe.AddShader(&fs);
19729 pipe.AddColorAttachment();
19730 // Set polygonMode to a good value
19731 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19732 pipe.SetRasterization(&rs_ci);
19733 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19734 }
19735 m_errorMonitor->VerifyNotFound();
19736
19737 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19738}
19739
19740TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19741 VkResult err;
19742 ASSERT_NO_FATAL_FAILURE(InitState());
19743 ASSERT_NO_FATAL_FAILURE(InitViewport());
19744 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19745
19746 VkPipelineLayout pipeline_layout;
19747 VkPushConstantRange pc_range = {};
19748 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19749 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19750 pipeline_layout_ci.pushConstantRangeCount = 1;
19751 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19752
19753 //
19754 // Check for invalid push constant ranges in pipeline layouts.
19755 //
19756 struct PipelineLayoutTestCase {
19757 VkPushConstantRange const range;
19758 char const *msg;
19759 };
19760
19761 // Check for overlapping ranges
19762 const uint32_t ranges_per_test = 5;
19763 struct OverlappingRangeTestCase {
19764 VkPushConstantRange const ranges[ranges_per_test];
19765 char const *msg;
19766 };
19767
19768 // Run some positive tests to make sure overlap checking in the layer is OK
19769 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19770 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19771 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19772 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19773 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19774 "" },
19775 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19776 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19777 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19778 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19779 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19780 "" } } };
19781 for (const auto &iter : overlapping_range_tests_pos) {
19782 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19783 m_errorMonitor->ExpectSuccess();
19784 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19785 m_errorMonitor->VerifyNotFound();
19786 if (VK_SUCCESS == err) {
19787 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19788 }
19789 }
19790
19791 //
19792 // CmdPushConstants tests
19793 //
19794 const uint8_t dummy_values[100] = {};
19795
19796 BeginCommandBuffer();
19797
19798 // positive overlapping range tests with cmd
19799 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19800 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19801 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19802 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19803 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19804 } };
19805
19806 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19807 const VkPushConstantRange pc_range4[] = {
19808 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19809 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19810 };
19811
19812 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19813 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19814 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19815 ASSERT_VK_SUCCESS(err);
19816 for (const auto &iter : cmd_overlap_tests_pos) {
19817 m_errorMonitor->ExpectSuccess();
19818 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19819 iter.range.size, dummy_values);
19820 m_errorMonitor->VerifyNotFound();
19821 }
19822 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19823
19824 EndCommandBuffer();
19825}
19826
19827
19828
19829
19830
19831
19832
19833#if 0 // A few devices have issues with this test so disabling for now
19834TEST_F(VkPositiveLayerTest, LongFenceChain)
19835{
19836 m_errorMonitor->ExpectSuccess();
19837
19838 ASSERT_NO_FATAL_FAILURE(InitState());
19839 VkResult err;
19840
19841 std::vector<VkFence> fences;
19842
19843 const int chainLength = 32768;
19844
19845 for (int i = 0; i < chainLength; i++) {
19846 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19847 VkFence fence;
19848 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19849 ASSERT_VK_SUCCESS(err);
19850
19851 fences.push_back(fence);
19852
19853 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19854 0, nullptr, 0, nullptr };
19855 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19856 ASSERT_VK_SUCCESS(err);
19857
19858 }
19859
19860 // BOOM, stack overflow.
19861 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19862
19863 for (auto fence : fences)
19864 vkDestroyFence(m_device->device(), fence, nullptr);
19865
19866 m_errorMonitor->VerifyNotFound();
19867}
19868#endif
19869
19870
Cody Northrop1242dfd2016-07-13 17:24:59 -060019871#if defined(ANDROID) && defined(VALIDATION_APK)
19872static bool initialized = false;
19873static bool active = false;
19874
19875// Convert Intents to argv
19876// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019877std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019878 std::vector<std::string> args;
19879 JavaVM &vm = *app.activity->vm;
19880 JNIEnv *p_env;
19881 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19882 return args;
19883
19884 JNIEnv &env = *p_env;
19885 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019886 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019887 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019888 jmethodID get_string_extra_method =
19889 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019890 jvalue get_string_extra_args;
19891 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019892 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019893
19894 std::string args_str;
19895 if (extra_str) {
19896 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19897 args_str = extra_utf;
19898 env.ReleaseStringUTFChars(extra_str, extra_utf);
19899 env.DeleteLocalRef(extra_str);
19900 }
19901
19902 env.DeleteLocalRef(get_string_extra_args.l);
19903 env.DeleteLocalRef(intent);
19904 vm.DetachCurrentThread();
19905
19906 // split args_str
19907 std::stringstream ss(args_str);
19908 std::string arg;
19909 while (std::getline(ss, arg, ' ')) {
19910 if (!arg.empty())
19911 args.push_back(arg);
19912 }
19913
19914 return args;
19915}
19916
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019917static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019918
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019919static void processCommand(struct android_app *app, int32_t cmd) {
19920 switch (cmd) {
19921 case APP_CMD_INIT_WINDOW: {
19922 if (app->window) {
19923 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019924 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019925 break;
19926 }
19927 case APP_CMD_GAINED_FOCUS: {
19928 active = true;
19929 break;
19930 }
19931 case APP_CMD_LOST_FOCUS: {
19932 active = false;
19933 break;
19934 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019935 }
19936}
19937
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019938void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019939 app_dummy();
19940
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019941 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019942
19943 int vulkanSupport = InitVulkan();
19944 if (vulkanSupport == 0) {
19945 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19946 return;
19947 }
19948
19949 app->onAppCmd = processCommand;
19950 app->onInputEvent = processInput;
19951
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019952 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019953 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019954 struct android_poll_source *source;
19955 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019956 if (source) {
19957 source->process(app, source);
19958 }
19959
19960 if (app->destroyRequested != 0) {
19961 VkTestFramework::Finish();
19962 return;
19963 }
19964 }
19965
19966 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019967 // Use the following key to send arguments to gtest, i.e.
19968 // --es args "--gtest_filter=-VkLayerTest.foo"
19969 const char key[] = "args";
19970 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019971
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019972 std::string filter = "";
19973 if (args.size() > 0) {
19974 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19975 filter += args[0];
19976 } else {
19977 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19978 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019979
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019980 int argc = 2;
19981 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19982 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019983
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019984 // Route output to files until we can override the gtest output
19985 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19986 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019987
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019988 ::testing::InitGoogleTest(&argc, argv);
19989 VkTestFramework::InitArgs(&argc, argv);
19990 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019991
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019992 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019993
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019994 if (result != 0) {
19995 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19996 } else {
19997 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19998 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019999
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020000 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020001
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020002 fclose(stdout);
20003 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020004
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020005 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020006
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020007 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020008 }
20009 }
20010}
20011#endif
20012
Tony Barbour300a6082015-04-07 13:44:53 -060020013int main(int argc, char **argv) {
20014 int result;
20015
Cody Northrop8e54a402016-03-08 22:25:52 -070020016#ifdef ANDROID
20017 int vulkanSupport = InitVulkan();
20018 if (vulkanSupport == 0)
20019 return 1;
20020#endif
20021
Tony Barbour300a6082015-04-07 13:44:53 -060020022 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020023 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020024
20025 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20026
20027 result = RUN_ALL_TESTS();
20028
Tony Barbour6918cd52015-04-09 12:58:51 -060020029 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020030 return result;
20031}