blob: c97dc90e73b3725023af1708f128c930f6c98325 [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;
Tony Barbourae58dba2016-12-13 16:30:36 -0700175 found_expected = true;
176 m_msgFound = VK_TRUE;
177 m_failure_message_strings.insert(errorString);
Karl Schultz05cc4e32016-10-12 13:25:23 -0600178 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600179 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600180 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600181 m_msgFound = VK_TRUE;
182 result = VK_TRUE;
183 // We only want one match for each expected error so remove from set here
184 // 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 -0600185 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600186 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600187 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600188 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600189 for (auto desired_id : m_desired_message_ids) {
190 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
191 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
192 // Return true to avoid calling layers/driver with this error.
193 result = VK_TRUE;
194 } else if (desired_id == message_code) {
195 // Double-check that the string matches the error enum
196 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
197 found_expected = true;
198 result = VK_TRUE;
199 m_msgFound = VK_TRUE;
200 m_desired_message_ids.erase(desired_id);
201 break;
202 } else {
203 // Treat this message as a regular unexpected error, but print a warning jic
204 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
205 errorString.c_str(), desired_id, validation_error_map[desired_id]);
206 }
207 }
208 }
209
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600210 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200211 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600212 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600213 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600214 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600215 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600216 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600217
Karl Schultz6addd812016-02-02 17:17:23 -0700218 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600219
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600220 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
221
Karl Schultz6addd812016-02-02 17:17:23 -0700222 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600223
Karl Schultz6addd812016-02-02 17:17:23 -0700224 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600225
Karl Schultz6addd812016-02-02 17:17:23 -0700226 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600227 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600228 if (otherMsgs.size()) {
229 cout << "Other error messages logged for this test were:" << endl;
230 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
231 cout << " " << *iter << endl;
232 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600233 }
234 }
235
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600236 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200237
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600238 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
239 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
240 m_msgFlags = message_flag_mask;
241 // Match ANY message matching specified type
242 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200243 }
244
245 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600246 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200247 if (!DesiredMsgFound()) {
248 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600249 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600250 FAIL() << "Did not receive expected error '" << desired_msg << "'";
251 }
Tony Barbour59b42282016-11-03 13:31:28 -0600252 for (auto desired_id : m_desired_message_ids) {
253 FAIL() << "Did not receive expected error '" << desired_id << "'";
254 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200255 }
256 }
257
258 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600259 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200260 if (DesiredMsgFound()) {
261 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600262 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600263 FAIL() << "Expected to succeed but got error: " << msg;
264 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200265 }
266 }
267
Karl Schultz6addd812016-02-02 17:17:23 -0700268 private:
269 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600270 std::unordered_set<uint32_t>m_desired_message_ids;
271 std::unordered_set<string> m_desired_message_strings;
272 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700273 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600274 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700275 bool *m_bailout;
276 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600277};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500278
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600279static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
280 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
281 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600282 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
283 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600284 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600285 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600286 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600287}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500288
Karl Schultz6addd812016-02-02 17:17:23 -0700289class VkLayerTest : public VkRenderFramework {
290 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800291 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
292 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
294 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700295 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600296 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
297 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700298 }
Tony Barbour300a6082015-04-07 13:44:53 -0600299
Tony Barbourfe3351b2015-07-28 10:17:20 -0600300 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600301 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800302 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
304 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700305 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600306 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700307 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600308 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700309 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600310 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
311 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
312 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700313 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
314 }
315 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
316 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
317 }
318
319 protected:
320 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600321 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600322
323 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600324 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600325 std::vector<const char *> instance_extension_names;
326 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600327
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700328 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600329 /*
330 * Since CreateDbgMsgCallback is an instance level extension call
331 * any extension / layer that utilizes that feature also needs
332 * to be enabled at create instance time.
333 */
Karl Schultz6addd812016-02-02 17:17:23 -0700334 // Use Threading layer first to protect others from
335 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700336 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600337 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800338 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700339 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800340 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600341 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700342 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600343
Ian Elliott2c1daf52016-05-12 09:41:46 -0600344 if (m_enableWSI) {
345 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
346 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
347#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
348#if defined(VK_USE_PLATFORM_ANDROID_KHR)
349 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_ANDROID_KHR
351#if defined(VK_USE_PLATFORM_MIR_KHR)
352 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
353#endif // VK_USE_PLATFORM_MIR_KHR
354#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
355 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_WAYLAND_KHR
357#if defined(VK_USE_PLATFORM_WIN32_KHR)
358 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
359#endif // VK_USE_PLATFORM_WIN32_KHR
360#endif // NEED_TO_TEST_THIS_ON_PLATFORM
361#if defined(VK_USE_PLATFORM_XCB_KHR)
362 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
363#elif defined(VK_USE_PLATFORM_XLIB_KHR)
364 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
365#endif // VK_USE_PLATFORM_XLIB_KHR
366 }
367
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600368 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600369 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800370 this->app_info.pApplicationName = "layer_tests";
371 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600372 this->app_info.pEngineName = "unittest";
373 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600374 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600375
Tony Barbour15524c32015-04-29 17:34:29 -0600376 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600377 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600378 }
379
380 virtual void TearDown() {
381 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600382 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600383 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600384 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600385
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600386 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600387};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500388
Karl Schultz6addd812016-02-02 17:17:23 -0700389VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600390 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600391
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800392 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600393
394 /*
395 * For render test all drawing happens in a single render pass
396 * on a single command buffer.
397 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200398 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800399 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600400 }
401
402 return result;
403}
404
Karl Schultz6addd812016-02-02 17:17:23 -0700405VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600406 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600407
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200408 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200410 }
Tony Barbour300a6082015-04-07 13:44:53 -0600411
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800412 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600413
414 return result;
415}
416
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600417void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500418 // Create identity matrix
419 int i;
420 struct vktriangle_vs_uniform data;
421
422 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700423 glm::mat4 View = glm::mat4(1.0f);
424 glm::mat4 Model = glm::mat4(1.0f);
425 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500426 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700427 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500428
429 memcpy(&data.mvp, &MVP[0][0], matrixSize);
430
Karl Schultz6addd812016-02-02 17:17:23 -0700431 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600432 {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 -0500433 };
434
Karl Schultz6addd812016-02-02 17:17:23 -0700435 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500436 data.position[i][0] = tri_data[i].posX;
437 data.position[i][1] = tri_data[i].posY;
438 data.position[i][2] = tri_data[i].posZ;
439 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700440 data.color[i][0] = tri_data[i].r;
441 data.color[i][1] = tri_data[i].g;
442 data.color[i][2] = tri_data[i].b;
443 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444 }
445
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500446 ASSERT_NO_FATAL_FAILURE(InitViewport());
447
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200448 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
449 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
Karl Schultz6addd812016-02-02 17:17:23 -0700451 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600452 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453
454 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800455 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500456 pipelineobj.AddShader(&vs);
457 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600458 if (failMask & BsoFailLineWidth) {
459 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600460 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600461 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600462 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
463 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600464 }
465 if (failMask & BsoFailDepthBias) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600467 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600468 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600469 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600470 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600471 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 }
Karl Schultz6addd812016-02-02 17:17:23 -0700473 // Viewport and scissors must stay in synch or other errors will occur than
474 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600475 if (failMask & BsoFailViewport) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
477 }
478 if (failMask & BsoFailScissor) {
479 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
480 }
481 if (failMask & BsoFailBlend) {
482 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600483 VkPipelineColorBlendAttachmentState att_state = {};
484 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
485 att_state.blendEnable = VK_TRUE;
486 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600487 }
488 if (failMask & BsoFailDepthBounds) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
490 }
491 if (failMask & BsoFailStencilReadMask) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
493 }
494 if (failMask & BsoFailStencilWriteMask) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
496 }
497 if (failMask & BsoFailStencilReference) {
498 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
499 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600502 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600505 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500506
Tony Barbourfe3351b2015-07-28 10:17:20 -0600507 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500508
509 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600510 if (failMask & BsoFailIndexBuffer) {
511 // Use DrawIndexed w/o an index buffer bound
512 DrawIndexed(3, 1, 0, 0, 0);
513 } else {
514 Draw(3, 1, 0, 0);
515 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516
Mark Muellerd4914412016-06-13 17:52:06 -0600517 if (failMask & BsoFailCmdClearAttachments) {
518 VkClearAttachment color_attachment = {};
519 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
520 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
521 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
522
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600523 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600524 }
525
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500526 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600527 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500528
Tony Barbourfe3351b2015-07-28 10:17:20 -0600529 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500530}
531
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
533 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600535 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500536 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600537 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538 }
539
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800540 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700541 // Make sure depthWriteEnable is set so that Depth fail test will work
542 // correctly
543 // Make sure stencilTestEnable is set so that Stencil fail test will work
544 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600545 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800546 stencil.failOp = VK_STENCIL_OP_KEEP;
547 stencil.passOp = VK_STENCIL_OP_KEEP;
548 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
549 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600550
551 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
552 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600553 ds_ci.pNext = NULL;
554 ds_ci.depthTestEnable = VK_FALSE;
555 ds_ci.depthWriteEnable = VK_TRUE;
556 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
557 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600558 if (failMask & BsoFailDepthBounds) {
559 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600560 ds_ci.maxDepthBounds = 0.0f;
561 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600562 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600563 ds_ci.stencilTestEnable = VK_TRUE;
564 ds_ci.front = stencil;
565 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600566
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600567 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600568 pipelineobj.SetViewport(m_viewports);
569 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800570 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600571 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600572 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800573 commandBuffer->BindPipeline(pipelineobj);
574 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500575}
576
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600577class VkPositiveLayerTest : public VkLayerTest {
578 public:
579 protected:
580};
581
Ian Elliott2c1daf52016-05-12 09:41:46 -0600582class VkWsiEnabledLayerTest : public VkLayerTest {
583 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600584 protected:
585 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600586};
587
Mark Muellerdfe37552016-07-07 14:47:42 -0600588class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600589 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600590 enum eTestEnFlags {
591 eDoubleDelete,
592 eInvalidDeviceOffset,
593 eInvalidMemoryOffset,
594 eBindNullBuffer,
595 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600596 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600597 };
598
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600599 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600600
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600601 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
602 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600603 return true;
604 }
605 VkDeviceSize offset_limit = 0;
606 if (eInvalidMemoryOffset == aTestFlag) {
607 VkBuffer vulkanBuffer;
608 VkBufferCreateInfo buffer_create_info = {};
609 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
610 buffer_create_info.size = 32;
611 buffer_create_info.usage = aBufferUsage;
612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600614 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600615
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600617 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
618 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
620 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600621 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600622 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600623 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 }
626 if (eOffsetAlignment < offset_limit) {
627 return true;
628 }
629 return false;
630 }
631
632 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600633 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
634 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600635
636 if (eBindNullBuffer == aTestFlag) {
637 VulkanMemory = 0;
638 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
639 } else {
640 VkBufferCreateInfo buffer_create_info = {};
641 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
642 buffer_create_info.size = 32;
643 buffer_create_info.usage = aBufferUsage;
644
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600645 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600646
647 CreateCurrent = true;
648
649 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600650 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600651
652 VkMemoryAllocateInfo memory_allocate_info = {};
653 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
654 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600655 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
656 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600657 if (!pass) {
658 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
659 return;
660 }
661
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600663 AllocateCurrent = true;
664 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600665 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
666 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600667 BoundCurrent = true;
668
669 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
670 }
671 }
672
673 ~VkBufferTest() {
674 if (CreateCurrent) {
675 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
676 }
677 if (AllocateCurrent) {
678 if (InvalidDeleteEn) {
679 union {
680 VkDeviceMemory device_memory;
681 unsigned long long index_access;
682 } bad_index;
683
684 bad_index.device_memory = VulkanMemory;
685 bad_index.index_access++;
686
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600687 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600688 }
689 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
690 }
691 }
692
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600693 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600694
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600695 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600696
697 void TestDoubleDestroy() {
698 // Destroy the buffer but leave the flag set, which will cause
699 // the buffer to be destroyed again in the destructor.
700 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
701 }
702
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600703 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600704 bool AllocateCurrent;
705 bool BoundCurrent;
706 bool CreateCurrent;
707 bool InvalidDeleteEn;
708
709 VkBuffer VulkanBuffer;
710 VkDevice VulkanDevice;
711 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600712};
713
714class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 public:
716 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600717 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600720 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
721 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600722 BindIdGenerator++; // NB: This can wrap w/misuse
723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
725 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600726
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600727 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
728 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
729 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
730 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
731 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600732
733 unsigned i = 0;
734 do {
735 VertexInputAttributeDescription[i].binding = BindId;
736 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600737 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
738 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600739 i++;
740 } while (AttributeCount < i);
741
742 i = 0;
743 do {
744 VertexInputBindingDescription[i].binding = BindId;
745 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600746 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600747 i++;
748 } while (BindingCount < i);
749 }
750
751 ~VkVerticesObj() {
752 if (VertexInputAttributeDescription) {
753 delete[] VertexInputAttributeDescription;
754 }
755 if (VertexInputBindingDescription) {
756 delete[] VertexInputBindingDescription;
757 }
758 }
759
760 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600761 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
762 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600763 return true;
764 }
765
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600766 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600767 VkDeviceSize *offsetList;
768 unsigned offsetCount;
769
770 if (aOffsetCount) {
771 offsetList = aOffsetList;
772 offsetCount = aOffsetCount;
773 } else {
774 offsetList = new VkDeviceSize[1]();
775 offsetCount = 1;
776 }
777
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600778 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600779 BoundCurrent = true;
780
781 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600782 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600783 }
784 }
785
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600786 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600787 static uint32_t BindIdGenerator;
788
789 bool BoundCurrent;
790 unsigned AttributeCount;
791 unsigned BindingCount;
792 uint32_t BindId;
793
794 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
795 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
796 VkVertexInputBindingDescription *VertexInputBindingDescription;
797 VkConstantBufferObj VulkanMemoryBuffer;
798};
799
800uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500801// ********************************************************************************************************************
802// ********************************************************************************************************************
803// ********************************************************************************************************************
804// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600805#if PARAMETER_VALIDATION_TESTS
806TEST_F(VkLayerTest, RequiredParameter) {
807 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
808 "pointer, array, and array count parameters");
809
810 ASSERT_NO_FATAL_FAILURE(InitState());
811
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600813 // Specify NULL for a pointer to a handle
814 // Expected to trigger an error with
815 // parameter_validation::validate_required_pointer
816 vkGetPhysicalDeviceFeatures(gpu(), NULL);
817 m_errorMonitor->VerifyFound();
818
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
820 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600821 // Specify NULL for pointer to array count
822 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600823 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 m_errorMonitor->VerifyFound();
825
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600827 // Specify 0 for a required array count
828 // Expected to trigger an error with parameter_validation::validate_array
829 VkViewport view_port = {};
830 m_commandBuffer->SetViewport(0, 0, &view_port);
831 m_errorMonitor->VerifyFound();
832
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600834 // Specify NULL for a required array
835 // Expected to trigger an error with parameter_validation::validate_array
836 m_commandBuffer->SetViewport(0, 1, NULL);
837 m_errorMonitor->VerifyFound();
838
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600840 // Specify VK_NULL_HANDLE for a required handle
841 // Expected to trigger an error with
842 // parameter_validation::validate_required_handle
843 vkUnmapMemory(device(), VK_NULL_HANDLE);
844 m_errorMonitor->VerifyFound();
845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
847 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600848 // Specify VK_NULL_HANDLE for a required handle array entry
849 // Expected to trigger an error with
850 // parameter_validation::validate_required_handle_array
851 VkFence fence = VK_NULL_HANDLE;
852 vkResetFences(device(), 1, &fence);
853 m_errorMonitor->VerifyFound();
854
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600856 // Specify NULL for a required struct pointer
857 // Expected to trigger an error with
858 // parameter_validation::validate_struct_type
859 VkDeviceMemory memory = VK_NULL_HANDLE;
860 vkAllocateMemory(device(), NULL, NULL, &memory);
861 m_errorMonitor->VerifyFound();
862
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600864 // Specify 0 for a required VkFlags parameter
865 // Expected to trigger an error with parameter_validation::validate_flags
866 m_commandBuffer->SetStencilReference(0, 0);
867 m_errorMonitor->VerifyFound();
868
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600869 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 -0600870 // Specify 0 for a required VkFlags array entry
871 // Expected to trigger an error with
872 // parameter_validation::validate_flags_array
873 VkSemaphore semaphore = VK_NULL_HANDLE;
874 VkPipelineStageFlags stageFlags = 0;
875 VkSubmitInfo submitInfo = {};
876 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
877 submitInfo.waitSemaphoreCount = 1;
878 submitInfo.pWaitSemaphores = &semaphore;
879 submitInfo.pWaitDstStageMask = &stageFlags;
880 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
881 m_errorMonitor->VerifyFound();
882}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600883
Dustin Gravesfce74c02016-05-10 11:42:58 -0600884TEST_F(VkLayerTest, ReservedParameter) {
885 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
886
887 ASSERT_NO_FATAL_FAILURE(InitState());
888
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600890 // Specify 0 for a reserved VkFlags parameter
891 // Expected to trigger an error with
892 // parameter_validation::validate_reserved_flags
893 VkEvent event_handle = VK_NULL_HANDLE;
894 VkEventCreateInfo event_info = {};
895 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
896 event_info.flags = 1;
897 vkCreateEvent(device(), &event_info, NULL, &event_handle);
898 m_errorMonitor->VerifyFound();
899}
900
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600901TEST_F(VkLayerTest, InvalidStructSType) {
902 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
903 "structure's sType field");
904
905 ASSERT_NO_FATAL_FAILURE(InitState());
906
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600908 // Zero struct memory, effectively setting sType to
909 // VK_STRUCTURE_TYPE_APPLICATION_INFO
910 // Expected to trigger an error with
911 // parameter_validation::validate_struct_type
912 VkMemoryAllocateInfo alloc_info = {};
913 VkDeviceMemory memory = VK_NULL_HANDLE;
914 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
915 m_errorMonitor->VerifyFound();
916
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600918 // Zero struct memory, effectively setting sType to
919 // VK_STRUCTURE_TYPE_APPLICATION_INFO
920 // Expected to trigger an error with
921 // parameter_validation::validate_struct_type_array
922 VkSubmitInfo submit_info = {};
923 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
924 m_errorMonitor->VerifyFound();
925}
926
927TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600929
930 ASSERT_NO_FATAL_FAILURE(InitState());
931
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600933 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600934 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600935 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600936 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600937 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600938 // Zero-initialization will provide the correct sType
939 VkApplicationInfo app_info = {};
940 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
941 event_alloc_info.pNext = &app_info;
942 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
943 m_errorMonitor->VerifyFound();
944
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
946 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600947 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
948 // a function that has allowed pNext structure types and specify
949 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600950 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600951 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600952 VkMemoryAllocateInfo memory_alloc_info = {};
953 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
954 memory_alloc_info.pNext = &app_info;
955 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600956 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600957}
Dustin Graves5d33d532016-05-09 16:21:12 -0600958
959TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600960 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600961
962 ASSERT_NO_FATAL_FAILURE(InitState());
963
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
965 "range of the core VkFormat "
966 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600967 // Specify an invalid VkFormat value
968 // Expected to trigger an error with
969 // parameter_validation::validate_ranged_enum
970 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 m_errorMonitor->VerifyFound();
973
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600974 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 -0600975 // Specify an invalid VkFlags bitmask value
976 // Expected to trigger an error with parameter_validation::validate_flags
977 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600978 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
979 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 m_errorMonitor->VerifyFound();
981
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600982 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 -0600983 // Specify an invalid VkFlags array entry
984 // Expected to trigger an error with
985 // parameter_validation::validate_flags_array
986 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600987 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600988 VkSubmitInfo submit_info = {};
989 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
990 submit_info.waitSemaphoreCount = 1;
991 submit_info.pWaitSemaphores = &semaphore;
992 submit_info.pWaitDstStageMask = &stage_flags;
993 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
994 m_errorMonitor->VerifyFound();
995
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600997 // Specify an invalid VkBool32 value
998 // Expected to trigger a warning with
999 // parameter_validation::validate_bool32
1000 VkSampler sampler = VK_NULL_HANDLE;
1001 VkSamplerCreateInfo sampler_info = {};
1002 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1003 sampler_info.pNext = NULL;
1004 sampler_info.magFilter = VK_FILTER_NEAREST;
1005 sampler_info.minFilter = VK_FILTER_NEAREST;
1006 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1007 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1008 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1009 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1010 sampler_info.mipLodBias = 1.0;
1011 sampler_info.maxAnisotropy = 1;
1012 sampler_info.compareEnable = VK_FALSE;
1013 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1014 sampler_info.minLod = 1.0;
1015 sampler_info.maxLod = 1.0;
1016 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1017 sampler_info.unnormalizedCoordinates = VK_FALSE;
1018 // Not VK_TRUE or VK_FALSE
1019 sampler_info.anisotropyEnable = 3;
1020 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1021 m_errorMonitor->VerifyFound();
1022}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001023
1024TEST_F(VkLayerTest, FailedReturnValue) {
1025 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1026
1027 ASSERT_NO_FATAL_FAILURE(InitState());
1028
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001029 // Find an unsupported image format
1030 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1031 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1032 VkFormat format = static_cast<VkFormat>(f);
1033 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001034 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001035 unsupported = format;
1036 break;
1037 }
1038 }
1039
1040 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1042 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001043 // Specify an unsupported VkFormat value to generate a
1044 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1045 // Expected to trigger a warning from
1046 // parameter_validation::validate_result
1047 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001048 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1049 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001050 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1051 m_errorMonitor->VerifyFound();
1052 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001053}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001054
1055TEST_F(VkLayerTest, UpdateBufferAlignment) {
1056 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001057 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001058
1059 ASSERT_NO_FATAL_FAILURE(InitState());
1060
1061 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1062 vk_testing::Buffer buffer;
1063 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1064
1065 BeginCommandBuffer();
1066 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001068 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1069 m_errorMonitor->VerifyFound();
1070
1071 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001073 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1074 m_errorMonitor->VerifyFound();
1075
1076 // Introduce failure by using dataSize that is < 0
1077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001078 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001079 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1080 m_errorMonitor->VerifyFound();
1081
1082 // Introduce failure by using dataSize that is > 65536
1083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1086 m_errorMonitor->VerifyFound();
1087
1088 EndCommandBuffer();
1089}
1090
1091TEST_F(VkLayerTest, FillBufferAlignment) {
1092 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1093
1094 ASSERT_NO_FATAL_FAILURE(InitState());
1095
1096 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1097 vk_testing::Buffer buffer;
1098 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1099
1100 BeginCommandBuffer();
1101
1102 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001104 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1105 m_errorMonitor->VerifyFound();
1106
1107 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001109 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1110 m_errorMonitor->VerifyFound();
1111
1112 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001114 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1115 m_errorMonitor->VerifyFound();
1116
1117 EndCommandBuffer();
1118}
Dustin Graves40f35822016-06-23 11:12:53 -06001119
Cortd889ff92016-07-27 09:51:27 -07001120TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1121 VkResult err;
1122
1123 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001124 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001125
1126 ASSERT_NO_FATAL_FAILURE(InitState());
1127 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1128
1129 std::vector<const char *> device_extension_names;
1130 auto features = m_device->phy().features();
1131 // Artificially disable support for non-solid fill modes
1132 features.fillModeNonSolid = false;
1133 // The sacrificial device object
1134 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1135
1136 VkRenderpassObj render_pass(&test_device);
1137
1138 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1139 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1140 pipeline_layout_ci.setLayoutCount = 0;
1141 pipeline_layout_ci.pSetLayouts = NULL;
1142
1143 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001144 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001145 ASSERT_VK_SUCCESS(err);
1146
1147 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1148 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1149 rs_ci.pNext = nullptr;
1150 rs_ci.lineWidth = 1.0f;
1151 rs_ci.rasterizerDiscardEnable = true;
1152
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001153 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1154 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001155
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001156 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1158 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001159 {
1160 VkPipelineObj pipe(&test_device);
1161 pipe.AddShader(&vs);
1162 pipe.AddShader(&fs);
1163 pipe.AddColorAttachment();
1164 // Introduce failure by setting unsupported polygon mode
1165 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1166 pipe.SetRasterization(&rs_ci);
1167 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1168 }
1169 m_errorMonitor->VerifyFound();
1170
1171 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1173 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001174 {
1175 VkPipelineObj pipe(&test_device);
1176 pipe.AddShader(&vs);
1177 pipe.AddShader(&fs);
1178 pipe.AddColorAttachment();
1179 // Introduce failure by setting unsupported polygon mode
1180 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1181 pipe.SetRasterization(&rs_ci);
1182 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1183 }
1184 m_errorMonitor->VerifyFound();
1185
Cortd889ff92016-07-27 09:51:27 -07001186 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1187}
1188
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001189#endif // PARAMETER_VALIDATION_TESTS
1190
Tobin Ehlis0788f522015-05-26 16:11:58 -06001191#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001192#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001193TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001194{
1195 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001196 VkFenceCreateInfo fenceInfo = {};
1197 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1198 fenceInfo.pNext = NULL;
1199 fenceInfo.flags = 0;
1200
Mike Weiblencce7ec72016-10-17 19:33:05 -06001201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001202
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001203 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001204
1205 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1206 vk_testing::Buffer buffer;
1207 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001208
Tony Barbourfe3351b2015-07-28 10:17:20 -06001209 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001210 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001211 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001212
1213 testFence.init(*m_device, fenceInfo);
1214
1215 // Bypass framework since it does the waits automatically
1216 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001217 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001218 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1219 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001220 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001221 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001222 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001223 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001224 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001225 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001226 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001227
1228 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001229 ASSERT_VK_SUCCESS( err );
1230
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001231 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001232 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001233
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001234 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001235}
1236
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001237TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001238{
1239 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001240 VkFenceCreateInfo fenceInfo = {};
1241 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1242 fenceInfo.pNext = NULL;
1243 fenceInfo.flags = 0;
1244
Mike Weiblencce7ec72016-10-17 19:33:05 -06001245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001246
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001247 ASSERT_NO_FATAL_FAILURE(InitState());
1248 ASSERT_NO_FATAL_FAILURE(InitViewport());
1249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1250
Tony Barbourfe3351b2015-07-28 10:17:20 -06001251 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001252 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001253 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001254
1255 testFence.init(*m_device, fenceInfo);
1256
1257 // Bypass framework since it does the waits automatically
1258 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001259 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001260 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1261 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001262 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001263 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001264 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001265 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001266 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001267 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001268 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001269
1270 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001271 ASSERT_VK_SUCCESS( err );
1272
Jon Ashburnf19916e2016-01-11 13:12:43 -07001273 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001274 VkCommandBufferBeginInfo info = {};
1275 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1276 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001277 info.renderPass = VK_NULL_HANDLE;
1278 info.subpass = 0;
1279 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001280 info.occlusionQueryEnable = VK_FALSE;
1281 info.queryFlags = 0;
1282 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001283
1284 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001285 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001286
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001287 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001288}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001289#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001290
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001291TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1292 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1293
1294 ASSERT_NO_FATAL_FAILURE(InitState());
1295
1296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1297 VkBuffer buffer;
1298 VkBufferCreateInfo buf_info = {};
1299 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1300 buf_info.pNext = NULL;
1301 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1302 buf_info.size = 2048;
1303 buf_info.queueFamilyIndexCount = 0;
1304 buf_info.pQueueFamilyIndices = NULL;
1305 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1306 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1307 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1308 m_errorMonitor->VerifyFound();
1309
1310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1311 VkImage image;
1312 VkImageCreateInfo image_create_info = {};
1313 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1314 image_create_info.pNext = NULL;
1315 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1316 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1317 image_create_info.extent.width = 512;
1318 image_create_info.extent.height = 64;
1319 image_create_info.extent.depth = 1;
1320 image_create_info.mipLevels = 1;
1321 image_create_info.arrayLayers = 1;
1322 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1323 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1324 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1325 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1326 image_create_info.queueFamilyIndexCount = 0;
1327 image_create_info.pQueueFamilyIndices = NULL;
1328 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1329 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1330 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1331 m_errorMonitor->VerifyFound();
1332}
1333
Tobin Ehlisf11be982016-05-11 13:52:53 -06001334TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1335 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1336 "buffer and image to memory such that they will alias.");
1337 VkResult err;
1338 bool pass;
1339 ASSERT_NO_FATAL_FAILURE(InitState());
1340
Tobin Ehlis077ded32016-05-12 17:39:13 -06001341 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001342 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001343 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001344 VkDeviceMemory mem; // buffer will be bound first
1345 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001346 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001347
1348 VkBufferCreateInfo buf_info = {};
1349 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1350 buf_info.pNext = NULL;
1351 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1352 buf_info.size = 256;
1353 buf_info.queueFamilyIndexCount = 0;
1354 buf_info.pQueueFamilyIndices = NULL;
1355 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1356 buf_info.flags = 0;
1357 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1358 ASSERT_VK_SUCCESS(err);
1359
Tobin Ehlis077ded32016-05-12 17:39:13 -06001360 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001361
1362 VkImageCreateInfo image_create_info = {};
1363 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1364 image_create_info.pNext = NULL;
1365 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1366 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1367 image_create_info.extent.width = 64;
1368 image_create_info.extent.height = 64;
1369 image_create_info.extent.depth = 1;
1370 image_create_info.mipLevels = 1;
1371 image_create_info.arrayLayers = 1;
1372 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001373 // Image tiling must be optimal to trigger error when aliasing linear buffer
1374 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001375 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1376 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1377 image_create_info.queueFamilyIndexCount = 0;
1378 image_create_info.pQueueFamilyIndices = NULL;
1379 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1380 image_create_info.flags = 0;
1381
Tobin Ehlisf11be982016-05-11 13:52:53 -06001382 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1383 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001384 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1385 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001386
Tobin Ehlis077ded32016-05-12 17:39:13 -06001387 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1388
1389 VkMemoryAllocateInfo alloc_info = {};
1390 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1391 alloc_info.pNext = NULL;
1392 alloc_info.memoryTypeIndex = 0;
1393 // Ensure memory is big enough for both bindings
1394 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001395 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1396 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001397 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001398 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001399 vkDestroyImage(m_device->device(), image, NULL);
1400 return;
1401 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001402 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1403 ASSERT_VK_SUCCESS(err);
1404 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1405 ASSERT_VK_SUCCESS(err);
1406
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001408 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001409 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1410 m_errorMonitor->VerifyFound();
1411
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001412 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001413 // aliasing buffer2
1414 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1415 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001416 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1417 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001418 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001419 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001421 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001422 m_errorMonitor->VerifyFound();
1423
1424 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001425 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001426 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001427 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001428 vkFreeMemory(m_device->device(), mem, NULL);
1429 vkFreeMemory(m_device->device(), mem_img, NULL);
1430}
1431
Tobin Ehlis35372522016-05-12 08:32:31 -06001432TEST_F(VkLayerTest, InvalidMemoryMapping) {
1433 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1434 VkResult err;
1435 bool pass;
1436 ASSERT_NO_FATAL_FAILURE(InitState());
1437
1438 VkBuffer buffer;
1439 VkDeviceMemory mem;
1440 VkMemoryRequirements mem_reqs;
1441
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001442 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1443
Tobin Ehlis35372522016-05-12 08:32:31 -06001444 VkBufferCreateInfo buf_info = {};
1445 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1446 buf_info.pNext = NULL;
1447 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1448 buf_info.size = 256;
1449 buf_info.queueFamilyIndexCount = 0;
1450 buf_info.pQueueFamilyIndices = NULL;
1451 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1452 buf_info.flags = 0;
1453 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1454 ASSERT_VK_SUCCESS(err);
1455
1456 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1457 VkMemoryAllocateInfo alloc_info = {};
1458 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1459 alloc_info.pNext = NULL;
1460 alloc_info.memoryTypeIndex = 0;
1461
1462 // Ensure memory is big enough for both bindings
1463 static const VkDeviceSize allocation_size = 0x10000;
1464 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001465 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 -06001466 if (!pass) {
1467 vkDestroyBuffer(m_device->device(), buffer, NULL);
1468 return;
1469 }
1470 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1471 ASSERT_VK_SUCCESS(err);
1472
1473 uint8_t *pData;
1474 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001475 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 -06001476 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1477 m_errorMonitor->VerifyFound();
1478 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001479 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001480 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1482 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1483 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001484 m_errorMonitor->VerifyFound();
1485
1486 // Unmap the memory to avoid re-map error
1487 vkUnmapMemory(m_device->device(), mem);
1488 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1490 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1491 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001492 m_errorMonitor->VerifyFound();
1493 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1495 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001496 m_errorMonitor->VerifyFound();
1497 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001499 vkUnmapMemory(m_device->device(), mem);
1500 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001501
Tobin Ehlis35372522016-05-12 08:32:31 -06001502 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001503 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001504 ASSERT_VK_SUCCESS(err);
1505 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001506 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001507 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001508 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001510 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1511 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001512
Tobin Ehlis35372522016-05-12 08:32:31 -06001513 // Now flush range that oversteps mapped range
1514 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001515 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001516 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001517 mmr.offset = atom_size;
1518 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1520 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1521 m_errorMonitor->VerifyFound();
1522
1523 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1524 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001525 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001526 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001527 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001528 mmr.size = VK_WHOLE_SIZE;
1529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001530 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1531 m_errorMonitor->VerifyFound();
1532
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001533 // Some platforms have an atomsize of 1 which makes the test meaningless
1534 if (atom_size > 3) {
1535 // Now with an offset NOT a multiple of the device limit
1536 vkUnmapMemory(m_device->device(), mem);
1537 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1538 ASSERT_VK_SUCCESS(err);
1539 mmr.offset = 3; // Not a multiple of atom_size
1540 mmr.size = VK_WHOLE_SIZE;
1541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1542 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1543 m_errorMonitor->VerifyFound();
1544
1545 // Now with a size NOT a multiple of the device limit
1546 vkUnmapMemory(m_device->device(), mem);
1547 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1548 ASSERT_VK_SUCCESS(err);
1549 mmr.offset = atom_size;
1550 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1552 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1553 m_errorMonitor->VerifyFound();
1554 }
1555
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001556 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1557 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001558 if (!pass) {
1559 vkFreeMemory(m_device->device(), mem, NULL);
1560 vkDestroyBuffer(m_device->device(), buffer, NULL);
1561 return;
1562 }
1563 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1564 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1565
1566 vkDestroyBuffer(m_device->device(), buffer, NULL);
1567 vkFreeMemory(m_device->device(), mem, NULL);
1568}
1569
Chris Forbes09368e42016-10-13 11:59:22 +13001570#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001571TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1572 VkResult err;
1573 bool pass;
1574
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001575 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1576 // following declaration (which is temporarily being moved below):
1577 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001578 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001579 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001580 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001581 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001582 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001583 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001584
1585 ASSERT_NO_FATAL_FAILURE(InitState());
1586
Ian Elliott3f06ce52016-04-29 14:46:21 -06001587#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1588#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1589 // Use the functions from the VK_KHR_android_surface extension without
1590 // enabling that extension:
1591
1592 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001593 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1595 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001596 pass = (err != VK_SUCCESS);
1597 ASSERT_TRUE(pass);
1598 m_errorMonitor->VerifyFound();
1599#endif // VK_USE_PLATFORM_ANDROID_KHR
1600
Ian Elliott3f06ce52016-04-29 14:46:21 -06001601#if defined(VK_USE_PLATFORM_MIR_KHR)
1602 // Use the functions from the VK_KHR_mir_surface extension without enabling
1603 // that extension:
1604
1605 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001606 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001608 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1609 pass = (err != VK_SUCCESS);
1610 ASSERT_TRUE(pass);
1611 m_errorMonitor->VerifyFound();
1612
1613 // Tell whether an mir_connection supports presentation:
1614 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1616 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001617 m_errorMonitor->VerifyFound();
1618#endif // VK_USE_PLATFORM_MIR_KHR
1619
Ian Elliott3f06ce52016-04-29 14:46:21 -06001620#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1621 // Use the functions from the VK_KHR_wayland_surface extension without
1622 // enabling that extension:
1623
1624 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001625 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1627 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001628 pass = (err != VK_SUCCESS);
1629 ASSERT_TRUE(pass);
1630 m_errorMonitor->VerifyFound();
1631
1632 // Tell whether an wayland_display supports presentation:
1633 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1635 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001636 m_errorMonitor->VerifyFound();
1637#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001638#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001639
Ian Elliott3f06ce52016-04-29 14:46:21 -06001640#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001641 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1642 // TO NON-LINUX PLATFORMS:
1643 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001644 // Use the functions from the VK_KHR_win32_surface extension without
1645 // enabling that extension:
1646
1647 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001648 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_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");
1650 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001651 pass = (err != VK_SUCCESS);
1652 ASSERT_TRUE(pass);
1653 m_errorMonitor->VerifyFound();
1654
1655 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001657 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001658 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001659// Set this (for now, until all platforms are supported and tested):
1660#define NEED_TO_TEST_THIS_ON_PLATFORM
1661#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001662#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001663 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1664 // TO NON-LINUX PLATFORMS:
1665 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001666#endif
1667#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001668 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1669 // that extension:
1670
1671 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001672 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001674 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1675 pass = (err != VK_SUCCESS);
1676 ASSERT_TRUE(pass);
1677 m_errorMonitor->VerifyFound();
1678
1679 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001680 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001681 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1683 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001684 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001685// Set this (for now, until all platforms are supported and tested):
1686#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001687#endif // VK_USE_PLATFORM_XCB_KHR
1688
Ian Elliott12630812016-04-29 14:35:43 -06001689#if defined(VK_USE_PLATFORM_XLIB_KHR)
1690 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1691 // that extension:
1692
1693 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001694 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001696 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1697 pass = (err != VK_SUCCESS);
1698 ASSERT_TRUE(pass);
1699 m_errorMonitor->VerifyFound();
1700
1701 // Tell whether an Xlib VisualID supports presentation:
1702 Display *dpy = NULL;
1703 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001705 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1706 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001707// Set this (for now, until all platforms are supported and tested):
1708#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001709#endif // VK_USE_PLATFORM_XLIB_KHR
1710
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001711// Use the functions from the VK_KHR_surface extension without enabling
1712// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001713
Ian Elliott489eec02016-05-05 14:12:44 -06001714#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001715 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001717 vkDestroySurfaceKHR(instance(), surface, NULL);
1718 m_errorMonitor->VerifyFound();
1719
1720 // Check if surface supports presentation:
1721 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001723 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1724 pass = (err != VK_SUCCESS);
1725 ASSERT_TRUE(pass);
1726 m_errorMonitor->VerifyFound();
1727
1728 // Check surface capabilities:
1729 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1731 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001732 pass = (err != VK_SUCCESS);
1733 ASSERT_TRUE(pass);
1734 m_errorMonitor->VerifyFound();
1735
1736 // Check surface formats:
1737 uint32_t format_count = 0;
1738 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1740 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001741 pass = (err != VK_SUCCESS);
1742 ASSERT_TRUE(pass);
1743 m_errorMonitor->VerifyFound();
1744
1745 // Check surface present modes:
1746 uint32_t present_mode_count = 0;
1747 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1749 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001750 pass = (err != VK_SUCCESS);
1751 ASSERT_TRUE(pass);
1752 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001753#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001754
Ian Elliott1c32c772016-04-28 14:47:13 -06001755 // Use the functions from the VK_KHR_swapchain extension without enabling
1756 // that extension:
1757
1758 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001760 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1761 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001762 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001763 pass = (err != VK_SUCCESS);
1764 ASSERT_TRUE(pass);
1765 m_errorMonitor->VerifyFound();
1766
1767 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1769 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001770 pass = (err != VK_SUCCESS);
1771 ASSERT_TRUE(pass);
1772 m_errorMonitor->VerifyFound();
1773
Chris Forbeseb7d5502016-09-13 18:19:21 +12001774 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1775 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1776 VkFence fence;
1777 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1778
Ian Elliott1c32c772016-04-28 14:47:13 -06001779 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001781 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001782 pass = (err != VK_SUCCESS);
1783 ASSERT_TRUE(pass);
1784 m_errorMonitor->VerifyFound();
1785
Chris Forbeseb7d5502016-09-13 18:19:21 +12001786 vkDestroyFence(m_device->device(), fence, nullptr);
1787
Ian Elliott1c32c772016-04-28 14:47:13 -06001788 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001789 //
1790 // NOTE: Currently can't test this because a real swapchain is needed (as
1791 // opposed to the fake one we created) in order for the layer to lookup the
1792 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001793
1794 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001796 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1797 m_errorMonitor->VerifyFound();
1798}
Chris Forbes09368e42016-10-13 11:59:22 +13001799#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001800
Karl Schultz6addd812016-02-02 17:17:23 -07001801TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1802 VkResult err;
1803 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001804
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1806 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001807
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001808 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001809
1810 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001811 VkImage image;
1812 VkDeviceMemory mem;
1813 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001814
Karl Schultz6addd812016-02-02 17:17:23 -07001815 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1816 const int32_t tex_width = 32;
1817 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001818
Tony Barboureb254902015-07-15 12:50:33 -06001819 VkImageCreateInfo image_create_info = {};
1820 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001821 image_create_info.pNext = NULL;
1822 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1823 image_create_info.format = tex_format;
1824 image_create_info.extent.width = tex_width;
1825 image_create_info.extent.height = tex_height;
1826 image_create_info.extent.depth = 1;
1827 image_create_info.mipLevels = 1;
1828 image_create_info.arrayLayers = 1;
1829 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1830 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1831 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1832 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001833 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001834
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001835 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001836 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001837 mem_alloc.pNext = NULL;
1838 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001839
Chia-I Wuf7458c52015-10-26 21:10:41 +08001840 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001841 ASSERT_VK_SUCCESS(err);
1842
Karl Schultz6addd812016-02-02 17:17:23 -07001843 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001844
Mark Lobodzinski23065352015-05-29 09:32:35 -05001845 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001846
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001847 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 -07001848 if (!pass) { // If we can't find any unmappable memory this test doesn't
1849 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001850 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001851 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001852 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001853
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001854 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001855 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001856 ASSERT_VK_SUCCESS(err);
1857
1858 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001859 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001860 ASSERT_VK_SUCCESS(err);
1861
1862 // Map memory as if to initialize the image
1863 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001864 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001865
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001866 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001867
Chia-I Wuf7458c52015-10-26 21:10:41 +08001868 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001869 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001870}
1871
Karl Schultz6addd812016-02-02 17:17:23 -07001872TEST_F(VkLayerTest, RebindMemory) {
1873 VkResult err;
1874 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001875
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001877
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001878 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001879
1880 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001881 VkImage image;
1882 VkDeviceMemory mem1;
1883 VkDeviceMemory mem2;
1884 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001885
Karl Schultz6addd812016-02-02 17:17:23 -07001886 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1887 const int32_t tex_width = 32;
1888 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001889
Tony Barboureb254902015-07-15 12:50:33 -06001890 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001891 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1892 image_create_info.pNext = NULL;
1893 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1894 image_create_info.format = tex_format;
1895 image_create_info.extent.width = tex_width;
1896 image_create_info.extent.height = tex_height;
1897 image_create_info.extent.depth = 1;
1898 image_create_info.mipLevels = 1;
1899 image_create_info.arrayLayers = 1;
1900 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1901 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1902 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1903 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001904
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001905 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001906 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1907 mem_alloc.pNext = NULL;
1908 mem_alloc.allocationSize = 0;
1909 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001910
Karl Schultz6addd812016-02-02 17:17:23 -07001911 // Introduce failure, do NOT set memProps to
1912 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001913 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001914 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001915 ASSERT_VK_SUCCESS(err);
1916
Karl Schultz6addd812016-02-02 17:17:23 -07001917 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001918
1919 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001920 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001921 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001922
1923 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001924 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001925 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001926 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001927 ASSERT_VK_SUCCESS(err);
1928
1929 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001930 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001931 ASSERT_VK_SUCCESS(err);
1932
Karl Schultz6addd812016-02-02 17:17:23 -07001933 // Introduce validation failure, try to bind a different memory object to
1934 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001935 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001936
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001937 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001938
Chia-I Wuf7458c52015-10-26 21:10:41 +08001939 vkDestroyImage(m_device->device(), image, NULL);
1940 vkFreeMemory(m_device->device(), mem1, NULL);
1941 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001942}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001943
Karl Schultz6addd812016-02-02 17:17:23 -07001944TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001945 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001946
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1948 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001949
1950 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001951 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1952 fenceInfo.pNext = NULL;
1953 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001954
Tony Barbour300a6082015-04-07 13:44:53 -06001955 ASSERT_NO_FATAL_FAILURE(InitState());
1956 ASSERT_NO_FATAL_FAILURE(InitViewport());
1957 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1958
Tony Barbourfe3351b2015-07-28 10:17:20 -06001959 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001960 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001961 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001962
1963 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001964
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001965 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001966 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1967 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001968 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001969 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001970 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001971 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001972 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001973 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001974 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001975
1976 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001977 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001978
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001979 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001980}
Chris Forbes4e44c912016-06-16 10:20:00 +12001981
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001982TEST_F(VkLayerTest, InvalidUsageBits) {
1983 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1984 "Initialize buffer with wrong usage then perform copy expecting errors "
1985 "from both the image and the buffer (2 calls)");
1986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001987
1988 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001989
1990 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
1991
Tony Barbourf92621a2016-05-02 14:28:12 -06001992 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001993 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001994 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001995 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001996
Tony Barbourf92621a2016-05-02 14:28:12 -06001997 VkImageView dsv;
1998 VkImageViewCreateInfo dsvci = {};
1999 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2000 dsvci.image = image.handle();
2001 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002002 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002003 dsvci.subresourceRange.layerCount = 1;
2004 dsvci.subresourceRange.baseMipLevel = 0;
2005 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002006 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002007
Tony Barbourf92621a2016-05-02 14:28:12 -06002008 // Create a view with depth / stencil aspect for image with different usage
2009 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002010
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002011 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002012
2013 // Initialize buffer with TRANSFER_DST usage
2014 vk_testing::Buffer buffer;
2015 VkMemoryPropertyFlags reqs = 0;
2016 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2017 VkBufferImageCopy region = {};
2018 region.bufferRowLength = 128;
2019 region.bufferImageHeight = 128;
2020 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2021 region.imageSubresource.layerCount = 1;
2022 region.imageExtent.height = 16;
2023 region.imageExtent.width = 16;
2024 region.imageExtent.depth = 1;
2025
Tony Barbourf92621a2016-05-02 14:28:12 -06002026 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2027 // TRANSFER_DST
2028 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002029
Chris Forbesda581202016-10-06 18:25:26 +13002030 // two separate errors from this call:
2031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002034 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2035 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002036 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002037}
Tony Barbour75d79f02016-08-30 09:39:07 -06002038
Tony Barbour75d79f02016-08-30 09:39:07 -06002039
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002040#endif // MEM_TRACKER_TESTS
2041
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002042#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002043
2044TEST_F(VkLayerTest, LeakAnObject) {
2045 VkResult err;
2046
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002047 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002048
2049 // Note that we have to create a new device since destroying the
2050 // framework's device causes Teardown() to fail and just calling Teardown
2051 // will destroy the errorMonitor.
2052
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002054
2055 ASSERT_NO_FATAL_FAILURE(InitState());
2056
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002057 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002058 std::vector<VkDeviceQueueCreateInfo> queue_info;
2059 queue_info.reserve(queue_props.size());
2060 std::vector<std::vector<float>> queue_priorities;
2061 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2062 VkDeviceQueueCreateInfo qi = {};
2063 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2064 qi.pNext = NULL;
2065 qi.queueFamilyIndex = i;
2066 qi.queueCount = queue_props[i].queueCount;
2067 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2068 qi.pQueuePriorities = queue_priorities[i].data();
2069 queue_info.push_back(qi);
2070 }
2071
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002072 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002073
2074 // The sacrificial device object
2075 VkDevice testDevice;
2076 VkDeviceCreateInfo device_create_info = {};
2077 auto features = m_device->phy().features();
2078 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2079 device_create_info.pNext = NULL;
2080 device_create_info.queueCreateInfoCount = queue_info.size();
2081 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002082 device_create_info.enabledLayerCount = 0;
2083 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002084 device_create_info.pEnabledFeatures = &features;
2085 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2086 ASSERT_VK_SUCCESS(err);
2087
2088 VkFence fence;
2089 VkFenceCreateInfo fence_create_info = {};
2090 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2091 fence_create_info.pNext = NULL;
2092 fence_create_info.flags = 0;
2093 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2094 ASSERT_VK_SUCCESS(err);
2095
2096 // Induce failure by not calling vkDestroyFence
2097 vkDestroyDevice(testDevice, NULL);
2098 m_errorMonitor->VerifyFound();
2099}
2100
2101TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2102
2103 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2104 "attempt to delete them from another.");
2105
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002107
Cody Northropc31a84f2016-08-22 10:41:47 -06002108 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002109 VkCommandPool command_pool_one;
2110 VkCommandPool command_pool_two;
2111
2112 VkCommandPoolCreateInfo pool_create_info{};
2113 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2114 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2115 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2116
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002117 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002118
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002119 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002120
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002121 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002122 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002123 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002124 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002125 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002126 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002127 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002128
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002129 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002130
2131 m_errorMonitor->VerifyFound();
2132
2133 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2134 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2135}
2136
2137TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2138 VkResult err;
2139
2140 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002141 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002142
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002144
2145 ASSERT_NO_FATAL_FAILURE(InitState());
2146 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2147
2148 VkDescriptorPoolSize ds_type_count = {};
2149 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2150 ds_type_count.descriptorCount = 1;
2151
2152 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2153 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2154 ds_pool_ci.pNext = NULL;
2155 ds_pool_ci.flags = 0;
2156 ds_pool_ci.maxSets = 1;
2157 ds_pool_ci.poolSizeCount = 1;
2158 ds_pool_ci.pPoolSizes = &ds_type_count;
2159
2160 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002161 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002162 ASSERT_VK_SUCCESS(err);
2163
2164 // Create a second descriptor pool
2165 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002166 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002167 ASSERT_VK_SUCCESS(err);
2168
2169 VkDescriptorSetLayoutBinding dsl_binding = {};
2170 dsl_binding.binding = 0;
2171 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2172 dsl_binding.descriptorCount = 1;
2173 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2174 dsl_binding.pImmutableSamplers = NULL;
2175
2176 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2177 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2178 ds_layout_ci.pNext = NULL;
2179 ds_layout_ci.bindingCount = 1;
2180 ds_layout_ci.pBindings = &dsl_binding;
2181
2182 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002183 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002184 ASSERT_VK_SUCCESS(err);
2185
2186 VkDescriptorSet descriptorSet;
2187 VkDescriptorSetAllocateInfo alloc_info = {};
2188 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2189 alloc_info.descriptorSetCount = 1;
2190 alloc_info.descriptorPool = ds_pool_one;
2191 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002192 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002193 ASSERT_VK_SUCCESS(err);
2194
2195 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2196
2197 m_errorMonitor->VerifyFound();
2198
2199 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2200 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2201 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2202}
2203
2204TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002206
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002207 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002208
2209 ASSERT_NO_FATAL_FAILURE(InitState());
2210
2211 // Pass bogus handle into GetImageMemoryRequirements
2212 VkMemoryRequirements mem_reqs;
2213 uint64_t fakeImageHandle = 0xCADECADE;
2214 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2215
2216 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2217
2218 m_errorMonitor->VerifyFound();
2219}
2220
Karl Schultz6addd812016-02-02 17:17:23 -07002221TEST_F(VkLayerTest, PipelineNotBound) {
2222 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002223
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002224 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002225
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002227
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002228 ASSERT_NO_FATAL_FAILURE(InitState());
2229 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002230
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002231 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002232 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2233 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002234
2235 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002236 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2237 ds_pool_ci.pNext = NULL;
2238 ds_pool_ci.maxSets = 1;
2239 ds_pool_ci.poolSizeCount = 1;
2240 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002241
2242 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002243 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002244 ASSERT_VK_SUCCESS(err);
2245
2246 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002247 dsl_binding.binding = 0;
2248 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2249 dsl_binding.descriptorCount = 1;
2250 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2251 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002252
2253 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002254 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2255 ds_layout_ci.pNext = NULL;
2256 ds_layout_ci.bindingCount = 1;
2257 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002258
2259 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002260 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002261 ASSERT_VK_SUCCESS(err);
2262
2263 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002264 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002265 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002266 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002267 alloc_info.descriptorPool = ds_pool;
2268 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002269 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002270 ASSERT_VK_SUCCESS(err);
2271
2272 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002273 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2274 pipeline_layout_ci.pNext = NULL;
2275 pipeline_layout_ci.setLayoutCount = 1;
2276 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002277
2278 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002279 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002280 ASSERT_VK_SUCCESS(err);
2281
Mark Youngad779052016-01-06 14:26:04 -07002282 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002283
2284 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002285 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002286
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002287 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002288
Chia-I Wuf7458c52015-10-26 21:10:41 +08002289 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2290 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2291 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002292}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002293
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002294TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2295 VkResult err;
2296
2297 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2298 "during bind[Buffer|Image]Memory time");
2299
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002300 ASSERT_NO_FATAL_FAILURE(InitState());
2301
2302 // Create an image, allocate memory, set a bad typeIndex and then try to
2303 // bind it
2304 VkImage image;
2305 VkDeviceMemory mem;
2306 VkMemoryRequirements mem_reqs;
2307 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2308 const int32_t tex_width = 32;
2309 const int32_t tex_height = 32;
2310
2311 VkImageCreateInfo image_create_info = {};
2312 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2313 image_create_info.pNext = NULL;
2314 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2315 image_create_info.format = tex_format;
2316 image_create_info.extent.width = tex_width;
2317 image_create_info.extent.height = tex_height;
2318 image_create_info.extent.depth = 1;
2319 image_create_info.mipLevels = 1;
2320 image_create_info.arrayLayers = 1;
2321 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2322 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2323 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2324 image_create_info.flags = 0;
2325
2326 VkMemoryAllocateInfo mem_alloc = {};
2327 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2328 mem_alloc.pNext = NULL;
2329 mem_alloc.allocationSize = 0;
2330 mem_alloc.memoryTypeIndex = 0;
2331
2332 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2333 ASSERT_VK_SUCCESS(err);
2334
2335 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2336 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002337
2338 // Introduce Failure, select invalid TypeIndex
2339 VkPhysicalDeviceMemoryProperties memory_info;
2340
2341 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2342 unsigned int i;
2343 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2344 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2345 mem_alloc.memoryTypeIndex = i;
2346 break;
2347 }
2348 }
2349 if (i >= memory_info.memoryTypeCount) {
2350 printf("No invalid memory type index could be found; skipped.\n");
2351 vkDestroyImage(m_device->device(), image, NULL);
2352 return;
2353 }
2354
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002355 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 -06002356
2357 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2358 ASSERT_VK_SUCCESS(err);
2359
2360 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2361 (void)err;
2362
2363 m_errorMonitor->VerifyFound();
2364
2365 vkDestroyImage(m_device->device(), image, NULL);
2366 vkFreeMemory(m_device->device(), mem, NULL);
2367}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002368
Karl Schultz6addd812016-02-02 17:17:23 -07002369TEST_F(VkLayerTest, BindInvalidMemory) {
2370 VkResult err;
2371 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002372
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002374
Tobin Ehlisec598302015-09-15 15:02:17 -06002375 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002376
2377 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002378 VkImage image;
2379 VkDeviceMemory mem;
2380 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002381
Karl Schultz6addd812016-02-02 17:17:23 -07002382 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2383 const int32_t tex_width = 32;
2384 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002385
2386 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002387 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2388 image_create_info.pNext = NULL;
2389 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2390 image_create_info.format = tex_format;
2391 image_create_info.extent.width = tex_width;
2392 image_create_info.extent.height = tex_height;
2393 image_create_info.extent.depth = 1;
2394 image_create_info.mipLevels = 1;
2395 image_create_info.arrayLayers = 1;
2396 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2397 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2398 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2399 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002400
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002401 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002402 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2403 mem_alloc.pNext = NULL;
2404 mem_alloc.allocationSize = 0;
2405 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002406
Chia-I Wuf7458c52015-10-26 21:10:41 +08002407 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002408 ASSERT_VK_SUCCESS(err);
2409
Karl Schultz6addd812016-02-02 17:17:23 -07002410 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002411
2412 mem_alloc.allocationSize = mem_reqs.size;
2413
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002414 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002415 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002416
2417 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002418 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002419 ASSERT_VK_SUCCESS(err);
2420
2421 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002422 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002423
2424 // Try to bind free memory that has been freed
2425 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2426 // This may very well return an error.
2427 (void)err;
2428
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002429 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002430
Chia-I Wuf7458c52015-10-26 21:10:41 +08002431 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002432}
2433
Karl Schultz6addd812016-02-02 17:17:23 -07002434TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2435 VkResult err;
2436 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002437
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002439
Tobin Ehlisec598302015-09-15 15:02:17 -06002440 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002441
Karl Schultz6addd812016-02-02 17:17:23 -07002442 // Create an image object, allocate memory, destroy the object and then try
2443 // to bind it
2444 VkImage image;
2445 VkDeviceMemory mem;
2446 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002447
Karl Schultz6addd812016-02-02 17:17:23 -07002448 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2449 const int32_t tex_width = 32;
2450 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002451
2452 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002453 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2454 image_create_info.pNext = NULL;
2455 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2456 image_create_info.format = tex_format;
2457 image_create_info.extent.width = tex_width;
2458 image_create_info.extent.height = tex_height;
2459 image_create_info.extent.depth = 1;
2460 image_create_info.mipLevels = 1;
2461 image_create_info.arrayLayers = 1;
2462 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2463 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2464 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2465 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002466
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002467 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002468 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2469 mem_alloc.pNext = NULL;
2470 mem_alloc.allocationSize = 0;
2471 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002472
Chia-I Wuf7458c52015-10-26 21:10:41 +08002473 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002474 ASSERT_VK_SUCCESS(err);
2475
Karl Schultz6addd812016-02-02 17:17:23 -07002476 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002477
2478 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002479 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002480 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002481
2482 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002483 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002484 ASSERT_VK_SUCCESS(err);
2485
2486 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002487 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002488 ASSERT_VK_SUCCESS(err);
2489
2490 // Now Try to bind memory to this destroyed object
2491 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2492 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002493 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002494
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002495 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002496
Chia-I Wuf7458c52015-10-26 21:10:41 +08002497 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002498}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002499
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002500#endif // OBJ_TRACKER_TESTS
2501
Tobin Ehlis0788f522015-05-26 16:11:58 -06002502#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002503
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002504TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2505 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2506
2507 ASSERT_NO_FATAL_FAILURE(InitState());
2508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2509
2510 VkVertexInputBindingDescription input_binding;
2511 memset(&input_binding, 0, sizeof(input_binding));
2512
2513 VkVertexInputAttributeDescription input_attribs;
2514 memset(&input_attribs, 0, sizeof(input_attribs));
2515
2516 // Pick a really bad format for this purpose and make sure it should fail
2517 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2518 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2519 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2520 printf("Format unsuitable for test; skipped.\n");
2521 return;
2522 }
2523
2524 input_attribs.location = 0;
2525 char const *vsSource = "#version 450\n"
2526 "\n"
2527 "out gl_PerVertex {\n"
2528 " vec4 gl_Position;\n"
2529 "};\n"
2530 "void main(){\n"
2531 " gl_Position = vec4(1);\n"
2532 "}\n";
2533 char const *fsSource = "#version 450\n"
2534 "\n"
2535 "layout(location=0) out vec4 color;\n"
2536 "void main(){\n"
2537 " color = vec4(1);\n"
2538 "}\n";
2539
2540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2541 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2542 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2543
2544 VkPipelineObj pipe(m_device);
2545 pipe.AddColorAttachment();
2546 pipe.AddShader(&vs);
2547 pipe.AddShader(&fs);
2548
2549 pipe.AddVertexInputBindings(&input_binding, 1);
2550 pipe.AddVertexInputAttribs(&input_attribs, 1);
2551
2552 VkDescriptorSetObj descriptorSet(m_device);
2553 descriptorSet.AppendDummy();
2554 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2555
2556 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2557
2558 m_errorMonitor->VerifyFound();
2559}
2560
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002561TEST_F(VkLayerTest, ImageSampleCounts) {
2562
2563 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2564 "validation errors.");
2565 ASSERT_NO_FATAL_FAILURE(InitState());
2566
2567 VkMemoryPropertyFlags reqs = 0;
2568 VkImageCreateInfo image_create_info = {};
2569 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2570 image_create_info.pNext = NULL;
2571 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2572 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2573 image_create_info.extent.width = 256;
2574 image_create_info.extent.height = 256;
2575 image_create_info.extent.depth = 1;
2576 image_create_info.mipLevels = 1;
2577 image_create_info.arrayLayers = 1;
2578 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2579 image_create_info.flags = 0;
2580
2581 VkImageBlit blit_region = {};
2582 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2583 blit_region.srcSubresource.baseArrayLayer = 0;
2584 blit_region.srcSubresource.layerCount = 1;
2585 blit_region.srcSubresource.mipLevel = 0;
2586 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2587 blit_region.dstSubresource.baseArrayLayer = 0;
2588 blit_region.dstSubresource.layerCount = 1;
2589 blit_region.dstSubresource.mipLevel = 0;
2590
2591 // Create two images, the source with sampleCount = 2, and attempt to blit
2592 // between them
2593 {
2594 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002595 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002596 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002597 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002598 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002599 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002600 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002601 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002602 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2604 "of VK_SAMPLE_COUNT_2_BIT but "
2605 "must be VK_SAMPLE_COUNT_1_BIT");
2606 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2607 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002608 m_errorMonitor->VerifyFound();
2609 m_commandBuffer->EndCommandBuffer();
2610 }
2611
2612 // Create two images, the dest with sampleCount = 4, and attempt to blit
2613 // between them
2614 {
2615 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002616 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002617 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002618 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002619 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002620 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002621 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002622 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002623 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2625 "of VK_SAMPLE_COUNT_4_BIT but "
2626 "must be VK_SAMPLE_COUNT_1_BIT");
2627 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2628 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002629 m_errorMonitor->VerifyFound();
2630 m_commandBuffer->EndCommandBuffer();
2631 }
2632
2633 VkBufferImageCopy copy_region = {};
2634 copy_region.bufferRowLength = 128;
2635 copy_region.bufferImageHeight = 128;
2636 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2637 copy_region.imageSubresource.layerCount = 1;
2638 copy_region.imageExtent.height = 64;
2639 copy_region.imageExtent.width = 64;
2640 copy_region.imageExtent.depth = 1;
2641
2642 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2643 // buffer to image
2644 {
2645 vk_testing::Buffer src_buffer;
2646 VkMemoryPropertyFlags reqs = 0;
2647 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2648 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002649 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002650 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002651 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002652 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2654 "of VK_SAMPLE_COUNT_8_BIT but "
2655 "must be VK_SAMPLE_COUNT_1_BIT");
2656 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2657 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002658 m_errorMonitor->VerifyFound();
2659 m_commandBuffer->EndCommandBuffer();
2660 }
2661
2662 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2663 // image to buffer
2664 {
2665 vk_testing::Buffer dst_buffer;
2666 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2667 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002668 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002669 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002670 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002671 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2673 "of VK_SAMPLE_COUNT_2_BIT but "
2674 "must be VK_SAMPLE_COUNT_1_BIT");
2675 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002676 dst_buffer.handle(), 1, &copy_region);
2677 m_errorMonitor->VerifyFound();
2678 m_commandBuffer->EndCommandBuffer();
2679 }
2680}
2681
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002682TEST_F(VkLayerTest, BlitImageFormats) {
2683
2684 // Image blit with mismatched formats
2685 const char * expected_message =
2686 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2687 " the other one must also have signed/unsigned integer format";
2688
2689 ASSERT_NO_FATAL_FAILURE(InitState());
2690
2691 VkImageObj src_image(m_device);
2692 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2693 VkImageObj dst_image(m_device);
2694 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2695 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002696 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 -06002697
2698 VkImageBlit blitRegion = {};
2699 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2700 blitRegion.srcSubresource.baseArrayLayer = 0;
2701 blitRegion.srcSubresource.layerCount = 1;
2702 blitRegion.srcSubresource.mipLevel = 0;
2703 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2704 blitRegion.dstSubresource.baseArrayLayer = 0;
2705 blitRegion.dstSubresource.layerCount = 1;
2706 blitRegion.dstSubresource.mipLevel = 0;
2707
2708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2709
2710 // Unsigned int vs not an int
2711 BeginCommandBuffer();
2712 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2713 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2714
2715 m_errorMonitor->VerifyFound();
2716
2717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2718
2719 // Unsigned int vs signed int
2720 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2721 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2722
2723 m_errorMonitor->VerifyFound();
2724
2725 EndCommandBuffer();
2726}
2727
2728
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002729TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2730 VkResult err;
2731 bool pass;
2732
2733 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2734 ASSERT_NO_FATAL_FAILURE(InitState());
2735
2736 // If w/d/h granularity is 1, test is not meaningful
2737 // TODO: When virtual device limits are available, create a set of limits for this test that
2738 // will always have a granularity of > 1 for w, h, and d
2739 auto index = m_device->graphics_queue_node_index_;
2740 auto queue_family_properties = m_device->phy().queue_properties();
2741
2742 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2743 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2744 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2745 return;
2746 }
2747
2748 // Create two images of different types and try to copy between them
2749 VkImage srcImage;
2750 VkImage dstImage;
2751 VkDeviceMemory srcMem;
2752 VkDeviceMemory destMem;
2753 VkMemoryRequirements memReqs;
2754
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002755 VkImageCreateInfo image_create_info = {};
2756 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2757 image_create_info.pNext = NULL;
2758 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2759 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2760 image_create_info.extent.width = 32;
2761 image_create_info.extent.height = 32;
2762 image_create_info.extent.depth = 1;
2763 image_create_info.mipLevels = 1;
2764 image_create_info.arrayLayers = 4;
2765 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2766 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2767 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2768 image_create_info.flags = 0;
2769
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002770 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002771 ASSERT_VK_SUCCESS(err);
2772
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002773 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002774 ASSERT_VK_SUCCESS(err);
2775
2776 // Allocate memory
2777 VkMemoryAllocateInfo memAlloc = {};
2778 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2779 memAlloc.pNext = NULL;
2780 memAlloc.allocationSize = 0;
2781 memAlloc.memoryTypeIndex = 0;
2782
2783 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2784 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002785 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002786 ASSERT_TRUE(pass);
2787 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2788 ASSERT_VK_SUCCESS(err);
2789
2790 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2791 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002792 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002793 ASSERT_VK_SUCCESS(err);
2794 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2795 ASSERT_VK_SUCCESS(err);
2796
2797 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2798 ASSERT_VK_SUCCESS(err);
2799 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2800 ASSERT_VK_SUCCESS(err);
2801
2802 BeginCommandBuffer();
2803 VkImageCopy copyRegion;
2804 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2805 copyRegion.srcSubresource.mipLevel = 0;
2806 copyRegion.srcSubresource.baseArrayLayer = 0;
2807 copyRegion.srcSubresource.layerCount = 1;
2808 copyRegion.srcOffset.x = 0;
2809 copyRegion.srcOffset.y = 0;
2810 copyRegion.srcOffset.z = 0;
2811 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2812 copyRegion.dstSubresource.mipLevel = 0;
2813 copyRegion.dstSubresource.baseArrayLayer = 0;
2814 copyRegion.dstSubresource.layerCount = 1;
2815 copyRegion.dstOffset.x = 0;
2816 copyRegion.dstOffset.y = 0;
2817 copyRegion.dstOffset.z = 0;
2818 copyRegion.extent.width = 1;
2819 copyRegion.extent.height = 1;
2820 copyRegion.extent.depth = 1;
2821
2822 // Introduce failure by setting srcOffset to a bad granularity value
2823 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2825 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002826 m_errorMonitor->VerifyFound();
2827
2828 // Introduce failure by setting extent to a bad granularity value
2829 copyRegion.srcOffset.y = 0;
2830 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2832 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002833 m_errorMonitor->VerifyFound();
2834
2835 // Now do some buffer/image copies
2836 vk_testing::Buffer buffer;
2837 VkMemoryPropertyFlags reqs = 0;
2838 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2839 VkBufferImageCopy region = {};
2840 region.bufferOffset = 0;
2841 region.bufferRowLength = 3;
2842 region.bufferImageHeight = 128;
2843 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2844 region.imageSubresource.layerCount = 1;
2845 region.imageExtent.height = 16;
2846 region.imageExtent.width = 16;
2847 region.imageExtent.depth = 1;
2848 region.imageOffset.x = 0;
2849 region.imageOffset.y = 0;
2850 region.imageOffset.z = 0;
2851
2852 // Introduce failure by setting bufferRowLength to a bad granularity value
2853 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2855 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2856 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002857 m_errorMonitor->VerifyFound();
2858 region.bufferRowLength = 128;
2859
2860 // Introduce failure by setting bufferOffset to a bad granularity value
2861 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2863 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2864 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002865 m_errorMonitor->VerifyFound();
2866 region.bufferOffset = 0;
2867
2868 // Introduce failure by setting bufferImageHeight to a bad granularity value
2869 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2871 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2872 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002873 m_errorMonitor->VerifyFound();
2874 region.bufferImageHeight = 128;
2875
2876 // Introduce failure by setting imageExtent to a bad granularity value
2877 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2879 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2880 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002881 m_errorMonitor->VerifyFound();
2882 region.imageExtent.width = 16;
2883
2884 // Introduce failure by setting imageOffset to a bad granularity value
2885 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2887 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2888 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002889 m_errorMonitor->VerifyFound();
2890
2891 EndCommandBuffer();
2892
2893 vkDestroyImage(m_device->device(), srcImage, NULL);
2894 vkDestroyImage(m_device->device(), dstImage, NULL);
2895 vkFreeMemory(m_device->device(), srcMem, NULL);
2896 vkFreeMemory(m_device->device(), destMem, NULL);
2897}
2898
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002899TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002900 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2901 "attempt to submit them on a queue created in a different "
2902 "queue family.");
2903
Cody Northropc31a84f2016-08-22 10:41:47 -06002904 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002905 // This test is meaningless unless we have multiple queue families
2906 auto queue_family_properties = m_device->phy().queue_properties();
2907 if (queue_family_properties.size() < 2) {
2908 return;
2909 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002911 // Get safe index of another queue family
2912 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2913 ASSERT_NO_FATAL_FAILURE(InitState());
2914 // Create a second queue using a different queue family
2915 VkQueue other_queue;
2916 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2917
2918 // Record an empty cmd buffer
2919 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2920 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2921 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2922 vkEndCommandBuffer(m_commandBuffer->handle());
2923
2924 // And submit on the wrong queue
2925 VkSubmitInfo submit_info = {};
2926 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2927 submit_info.commandBufferCount = 1;
2928 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002929 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002930
2931 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002932}
2933
Chris Forbes4c24a922016-11-16 08:59:10 +13002934TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2935 ASSERT_NO_FATAL_FAILURE(InitState());
2936
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002937 // There are no attachments, but refer to attachment 0.
2938 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002939 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002940 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2941 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002942 };
2943
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002944 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2945 nullptr,
2946 0,
2947 0,
2948 nullptr,
2949 1,
2950 subpasses,
2951 0,
2952 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002953 VkRenderPass rp;
2954
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002955 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002957 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002958 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2959 m_errorMonitor->VerifyFound();
2960}
2961
Chris Forbesa58c4522016-09-28 15:19:39 +13002962TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2963 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2964 ASSERT_NO_FATAL_FAILURE(InitState());
2965
2966 // A renderpass with two subpasses, both writing the same attachment.
2967 VkAttachmentDescription attach[] = {
2968 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2969 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2970 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2971 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2972 },
2973 };
2974 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2975 VkSubpassDescription subpasses[] = {
2976 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2977 1, &ref, nullptr, nullptr, 0, nullptr },
2978 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2979 1, &ref, nullptr, nullptr, 0, nullptr },
2980 };
2981 VkSubpassDependency dep = {
2982 0, 1,
2983 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2984 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2985 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2986 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2987 VK_DEPENDENCY_BY_REGION_BIT
2988 };
2989 VkRenderPassCreateInfo rpci = {
2990 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2991 0, 1, attach, 2, subpasses, 1, &dep
2992 };
2993 VkRenderPass rp;
2994 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2995 ASSERT_VK_SUCCESS(err);
2996
2997 VkImageObj image(m_device);
2998 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2999 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
3000 VK_IMAGE_TILING_OPTIMAL, 0);
3001 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3002
3003 VkFramebufferCreateInfo fbci = {
3004 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
3005 0, rp, 1, &imageView, 32, 32, 1
3006 };
3007 VkFramebuffer fb;
3008 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3009 ASSERT_VK_SUCCESS(err);
3010
3011 char const *vsSource =
3012 "#version 450\n"
3013 "void main() { gl_Position = vec4(1); }\n";
3014 char const *fsSource =
3015 "#version 450\n"
3016 "layout(location=0) out vec4 color;\n"
3017 "void main() { color = vec4(1); }\n";
3018
3019 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3020 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3021 VkPipelineObj pipe(m_device);
3022 pipe.AddColorAttachment();
3023 pipe.AddShader(&vs);
3024 pipe.AddShader(&fs);
3025 VkViewport view_port = {};
3026 m_viewports.push_back(view_port);
3027 pipe.SetViewport(m_viewports);
3028 VkRect2D rect = {};
3029 m_scissors.push_back(rect);
3030 pipe.SetScissor(m_scissors);
3031
3032 VkPipelineLayoutCreateInfo plci = {
3033 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
3034 0, 0, nullptr, 0, nullptr
3035 };
3036 VkPipelineLayout pl;
3037 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3038 ASSERT_VK_SUCCESS(err);
3039 pipe.CreateVKPipeline(pl, rp);
3040
3041 BeginCommandBuffer();
3042
3043 VkRenderPassBeginInfo rpbi = {
3044 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
3045 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
3046 };
3047
3048 // subtest 1: bind in the wrong subpass
3049 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3050 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3052 "built for subpass 0 but used in subpass 1");
3053 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3054 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3055 m_errorMonitor->VerifyFound();
3056
3057 vkCmdEndRenderPass(m_commandBuffer->handle());
3058
3059 // subtest 2: bind in correct subpass, then transition to next subpass
3060 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3061 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3062 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3064 "built for subpass 0 but used in subpass 1");
3065 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3066 m_errorMonitor->VerifyFound();
3067
3068 vkCmdEndRenderPass(m_commandBuffer->handle());
3069
3070 EndCommandBuffer();
3071
3072 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3073 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3074 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3075}
3076
Tony Barbour4e919972016-08-09 13:27:40 -06003077TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3078 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3079 "with extent outside of framebuffer");
3080 ASSERT_NO_FATAL_FAILURE(InitState());
3081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3082
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3084 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003085
3086 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3087 m_renderPassBeginInfo.renderArea.extent.width = 257;
3088 m_renderPassBeginInfo.renderArea.extent.height = 257;
3089 BeginCommandBuffer();
3090 m_errorMonitor->VerifyFound();
3091}
3092
3093TEST_F(VkLayerTest, DisabledIndependentBlend) {
3094 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3095 "blend and then specifying different blend states for two "
3096 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003097 VkPhysicalDeviceFeatures features = {};
3098 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003099 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003100
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3102 "Invalid Pipeline CreateInfo: If independent blend feature not "
3103 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003104
Cody Northropc31a84f2016-08-22 10:41:47 -06003105 VkDescriptorSetObj descriptorSet(m_device);
3106 descriptorSet.AppendDummy();
3107 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003108
Cody Northropc31a84f2016-08-22 10:41:47 -06003109 VkPipelineObj pipeline(m_device);
3110 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003111 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003112 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003113
Cody Northropc31a84f2016-08-22 10:41:47 -06003114 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3115 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3116 att_state1.blendEnable = VK_TRUE;
3117 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3118 att_state2.blendEnable = VK_FALSE;
3119 pipeline.AddColorAttachment(0, &att_state1);
3120 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003121 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003122 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003123}
3124
Chris Forbes26ec2122016-11-29 08:58:33 +13003125#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003126TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3127 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3128 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003129 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003130
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3132 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003133
3134 // Create a renderPass with a single color attachment
3135 VkAttachmentReference attach = {};
3136 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3137 VkSubpassDescription subpass = {};
3138 VkRenderPassCreateInfo rpci = {};
3139 rpci.subpassCount = 1;
3140 rpci.pSubpasses = &subpass;
3141 rpci.attachmentCount = 1;
3142 VkAttachmentDescription attach_desc = {};
3143 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3144 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3145 rpci.pAttachments = &attach_desc;
3146 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3147 VkRenderPass rp;
3148 subpass.pDepthStencilAttachment = &attach;
3149 subpass.pColorAttachments = NULL;
3150 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3151 m_errorMonitor->VerifyFound();
3152}
Chris Forbes26ec2122016-11-29 08:58:33 +13003153#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003154
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003155TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3156 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3157 "attachment reference of VK_ATTACHMENT_UNUSED");
3158
3159 ASSERT_NO_FATAL_FAILURE(InitState());
3160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3161
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003163
3164 VkAttachmentReference color_attach = {};
3165 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3166 color_attach.attachment = 0;
3167 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3168 VkSubpassDescription subpass = {};
3169 subpass.colorAttachmentCount = 1;
3170 subpass.pColorAttachments = &color_attach;
3171 subpass.preserveAttachmentCount = 1;
3172 subpass.pPreserveAttachments = &preserve_attachment;
3173
3174 VkRenderPassCreateInfo rpci = {};
3175 rpci.subpassCount = 1;
3176 rpci.pSubpasses = &subpass;
3177 rpci.attachmentCount = 1;
3178 VkAttachmentDescription attach_desc = {};
3179 attach_desc.format = VK_FORMAT_UNDEFINED;
3180 rpci.pAttachments = &attach_desc;
3181 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3182 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003183 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003184
3185 m_errorMonitor->VerifyFound();
3186
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003187 if (result == VK_SUCCESS) {
3188 vkDestroyRenderPass(m_device->device(), rp, NULL);
3189 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003190}
3191
Chris Forbesc5389742016-06-29 11:49:23 +12003192TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003193 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3194 "when the source of a subpass multisample resolve "
3195 "does not have multiple samples.");
3196
Chris Forbesc5389742016-06-29 11:49:23 +12003197 ASSERT_NO_FATAL_FAILURE(InitState());
3198
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3200 "Subpass 0 requests multisample resolve from attachment 0 which has "
3201 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003202
3203 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003204 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3205 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3206 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3207 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3208 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3209 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003210 };
3211
3212 VkAttachmentReference color = {
3213 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3214 };
3215
3216 VkAttachmentReference resolve = {
3217 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3218 };
3219
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003220 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003221
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003222 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003223
3224 VkRenderPass rp;
3225 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3226
3227 m_errorMonitor->VerifyFound();
3228
3229 if (err == VK_SUCCESS)
3230 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3231}
3232
3233TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003234 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3235 "when a subpass multisample resolve operation is "
3236 "requested, and the destination of that resolve has "
3237 "multiple samples.");
3238
Chris Forbesc5389742016-06-29 11:49:23 +12003239 ASSERT_NO_FATAL_FAILURE(InitState());
3240
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3242 "Subpass 0 requests multisample resolve into attachment 1, which "
3243 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003244
3245 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003246 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3247 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3248 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3249 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3250 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3251 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003252 };
3253
3254 VkAttachmentReference color = {
3255 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3256 };
3257
3258 VkAttachmentReference resolve = {
3259 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3260 };
3261
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003262 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003263
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003264 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003265
3266 VkRenderPass rp;
3267 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3268
3269 m_errorMonitor->VerifyFound();
3270
3271 if (err == VK_SUCCESS)
3272 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3273}
3274
Chris Forbes3f128ef2016-06-29 14:58:53 +12003275TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003276 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3277 "when the color and depth attachments used by a subpass "
3278 "have inconsistent sample counts");
3279
Chris Forbes3f128ef2016-06-29 14:58:53 +12003280 ASSERT_NO_FATAL_FAILURE(InitState());
3281
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3283 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003284
3285 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003286 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3287 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3288 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3289 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3290 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3291 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003292 };
3293
3294 VkAttachmentReference color[] = {
3295 {
3296 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3297 },
3298 {
3299 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3300 },
3301 };
3302
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003303 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003304
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003305 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003306
3307 VkRenderPass rp;
3308 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3309
3310 m_errorMonitor->VerifyFound();
3311
3312 if (err == VK_SUCCESS)
3313 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3314}
3315
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003316TEST_F(VkLayerTest, FramebufferCreateErrors) {
3317 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003318 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003319 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003320 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3321 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3322 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3323 " 6. Framebuffer attachment where dimensions don't match\n"
3324 " 7. Framebuffer attachment w/o identity swizzle\n"
3325 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003326
3327 ASSERT_NO_FATAL_FAILURE(InitState());
3328 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3329
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3331 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3332 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003333
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003334 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003335 VkAttachmentReference attach = {};
3336 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3337 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003338 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003339 VkRenderPassCreateInfo rpci = {};
3340 rpci.subpassCount = 1;
3341 rpci.pSubpasses = &subpass;
3342 rpci.attachmentCount = 1;
3343 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003344 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003345 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003346 rpci.pAttachments = &attach_desc;
3347 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3348 VkRenderPass rp;
3349 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3350 ASSERT_VK_SUCCESS(err);
3351
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003352 VkImageView ivs[2];
3353 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3354 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003355 VkFramebufferCreateInfo fb_info = {};
3356 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3357 fb_info.pNext = NULL;
3358 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003359 // Set mis-matching attachmentCount
3360 fb_info.attachmentCount = 2;
3361 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003362 fb_info.width = 100;
3363 fb_info.height = 100;
3364 fb_info.layers = 1;
3365
3366 VkFramebuffer fb;
3367 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3368
3369 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003370 if (err == VK_SUCCESS) {
3371 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3372 }
3373 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003374
3375 // Create a renderPass with a depth-stencil attachment created with
3376 // IMAGE_USAGE_COLOR_ATTACHMENT
3377 // Add our color attachment to pDepthStencilAttachment
3378 subpass.pDepthStencilAttachment = &attach;
3379 subpass.pColorAttachments = NULL;
3380 VkRenderPass rp_ds;
3381 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3382 ASSERT_VK_SUCCESS(err);
3383 // Set correct attachment count, but attachment has COLOR usage bit set
3384 fb_info.attachmentCount = 1;
3385 fb_info.renderPass = rp_ds;
3386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003388 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3389
3390 m_errorMonitor->VerifyFound();
3391 if (err == VK_SUCCESS) {
3392 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3393 }
3394 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003395
3396 // Create new renderpass with alternate attachment format from fb
3397 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3398 subpass.pDepthStencilAttachment = NULL;
3399 subpass.pColorAttachments = &attach;
3400 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3401 ASSERT_VK_SUCCESS(err);
3402
3403 // Cause error due to mis-matched formats between rp & fb
3404 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3405 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3407 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003408 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3409
3410 m_errorMonitor->VerifyFound();
3411 if (err == VK_SUCCESS) {
3412 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3413 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003414 vkDestroyRenderPass(m_device->device(), rp, NULL);
3415
3416 // Create new renderpass with alternate sample count from fb
3417 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3418 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3419 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3420 ASSERT_VK_SUCCESS(err);
3421
3422 // Cause error due to mis-matched sample count between rp & fb
3423 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3425 "that do not match the "
3426 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003427 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3428
3429 m_errorMonitor->VerifyFound();
3430 if (err == VK_SUCCESS) {
3431 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3432 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003433
3434 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003435
3436 // Create a custom imageView with non-1 mip levels
3437 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003438 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 -06003439 ASSERT_TRUE(image.initialized());
3440
3441 VkImageView view;
3442 VkImageViewCreateInfo ivci = {};
3443 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3444 ivci.image = image.handle();
3445 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3446 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3447 ivci.subresourceRange.layerCount = 1;
3448 ivci.subresourceRange.baseMipLevel = 0;
3449 // Set level count 2 (only 1 is allowed for FB attachment)
3450 ivci.subresourceRange.levelCount = 2;
3451 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3452 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3453 ASSERT_VK_SUCCESS(err);
3454 // Re-create renderpass to have matching sample count
3455 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3456 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3457 ASSERT_VK_SUCCESS(err);
3458
3459 fb_info.renderPass = rp;
3460 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003462 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3463
3464 m_errorMonitor->VerifyFound();
3465 if (err == VK_SUCCESS) {
3466 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3467 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003468 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003469 // Update view to original color buffer and grow FB dimensions too big
3470 fb_info.pAttachments = ivs;
3471 fb_info.height = 1024;
3472 fb_info.width = 1024;
3473 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3475 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003476 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3477
3478 m_errorMonitor->VerifyFound();
3479 if (err == VK_SUCCESS) {
3480 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3481 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003482 // Create view attachment with non-identity swizzle
3483 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3484 ivci.image = image.handle();
3485 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3486 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3487 ivci.subresourceRange.layerCount = 1;
3488 ivci.subresourceRange.baseMipLevel = 0;
3489 ivci.subresourceRange.levelCount = 1;
3490 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3491 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3492 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3493 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3494 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3495 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3496 ASSERT_VK_SUCCESS(err);
3497
3498 fb_info.pAttachments = &view;
3499 fb_info.height = 100;
3500 fb_info.width = 100;
3501 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3503 "framebuffer attachments must have "
3504 "been created with the identity "
3505 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003506 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3507
3508 m_errorMonitor->VerifyFound();
3509 if (err == VK_SUCCESS) {
3510 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3511 }
3512 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003513 // Request fb that exceeds max dimensions
3514 // reset attachment to color attachment
3515 fb_info.pAttachments = ivs;
3516 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3517 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3518 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3520 "dimensions exceed physical device "
3521 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003522 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3523
3524 m_errorMonitor->VerifyFound();
3525 if (err == VK_SUCCESS) {
3526 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3527 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003528
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003529 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003530}
3531
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003532TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003533 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3534 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003535
Cody Northropc31a84f2016-08-22 10:41:47 -06003536 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003537 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3539 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003540 m_errorMonitor->VerifyFound();
3541}
3542
3543TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003544 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3545 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003546
Cody Northropc31a84f2016-08-22 10:41:47 -06003547 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003548 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3550 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003551 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003552}
3553
3554TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003555 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3556 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003557
Cody Northropc31a84f2016-08-22 10:41:47 -06003558 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003559 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003560 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 -06003561 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003562 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003563}
3564
3565TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003566 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3567 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003568
Cody Northropc31a84f2016-08-22 10:41:47 -06003569 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003570 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003571 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 -06003572 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003573 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003574}
3575
Cortd713fe82016-07-27 09:51:27 -07003576TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003577 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3578 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003579
3580 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003581 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3583 "Dynamic blend constants state not set for this command buffer");
3584 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003585 m_errorMonitor->VerifyFound();
3586}
3587
3588TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003589 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3590 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003591
3592 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003593 if (!m_device->phy().features().depthBounds) {
3594 printf("Device does not support depthBounds test; skipped.\n");
3595 return;
3596 }
3597 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3599 "Dynamic depth bounds state not set for this command buffer");
3600 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003601 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003602}
3603
3604TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003605 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3606 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003607
3608 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003609 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3611 "Dynamic stencil read mask state not set for this command buffer");
3612 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003613 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003614}
3615
3616TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003617 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3618 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003619
3620 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003621 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3623 "Dynamic stencil write mask state not set for this command buffer");
3624 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003625 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003626}
3627
3628TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003629 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3630 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003631
3632 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003633 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3635 "Dynamic stencil reference state not set for this command buffer");
3636 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003637 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003638}
3639
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003640TEST_F(VkLayerTest, IndexBufferNotBound) {
3641 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003642
3643 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3645 "Index buffer object not bound to this command buffer when Indexed ");
3646 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003647 m_errorMonitor->VerifyFound();
3648}
3649
Karl Schultz6addd812016-02-02 17:17:23 -07003650TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3652 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3653 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003654
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003655 ASSERT_NO_FATAL_FAILURE(InitState());
3656 ASSERT_NO_FATAL_FAILURE(InitViewport());
3657 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3658
Karl Schultz6addd812016-02-02 17:17:23 -07003659 // We luck out b/c by default the framework creates CB w/ the
3660 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003661 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003662 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003663 EndCommandBuffer();
3664
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003665 // Bypass framework since it does the waits automatically
3666 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003667 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003668 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3669 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003670 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003671 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003672 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003673 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003674 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003675 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003676 submit_info.pSignalSemaphores = NULL;
3677
Chris Forbes40028e22016-06-13 09:59:34 +12003678 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003679 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003680 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003681
Karl Schultz6addd812016-02-02 17:17:23 -07003682 // Cause validation error by re-submitting cmd buffer that should only be
3683 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003684 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003685 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003686
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003687 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003688}
3689
Karl Schultz6addd812016-02-02 17:17:23 -07003690TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003691 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003692 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003693
3694 ASSERT_NO_FATAL_FAILURE(InitState());
3695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003696
Karl Schultz6addd812016-02-02 17:17:23 -07003697 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3698 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003699 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003700 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003701 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003702
3703 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003704 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3705 ds_pool_ci.pNext = NULL;
3706 ds_pool_ci.flags = 0;
3707 ds_pool_ci.maxSets = 1;
3708 ds_pool_ci.poolSizeCount = 1;
3709 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003710
3711 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003712 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003713 ASSERT_VK_SUCCESS(err);
3714
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003715 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3716 dsl_binding_samp.binding = 0;
3717 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3718 dsl_binding_samp.descriptorCount = 1;
3719 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3720 dsl_binding_samp.pImmutableSamplers = NULL;
3721
3722 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3723 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3724 ds_layout_ci.pNext = NULL;
3725 ds_layout_ci.bindingCount = 1;
3726 ds_layout_ci.pBindings = &dsl_binding_samp;
3727
3728 VkDescriptorSetLayout ds_layout_samp;
3729 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3730 ASSERT_VK_SUCCESS(err);
3731
3732 // Try to allocate 2 sets when pool only has 1 set
3733 VkDescriptorSet descriptor_sets[2];
3734 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3735 VkDescriptorSetAllocateInfo alloc_info = {};
3736 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3737 alloc_info.descriptorSetCount = 2;
3738 alloc_info.descriptorPool = ds_pool;
3739 alloc_info.pSetLayouts = set_layouts;
3740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3741 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3742 m_errorMonitor->VerifyFound();
3743
3744 alloc_info.descriptorSetCount = 1;
3745 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003746 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003747 dsl_binding.binding = 0;
3748 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3749 dsl_binding.descriptorCount = 1;
3750 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3751 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003752
Karl Schultz6addd812016-02-02 17:17:23 -07003753 ds_layout_ci.bindingCount = 1;
3754 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003755
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003756 VkDescriptorSetLayout ds_layout_ub;
3757 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003758 ASSERT_VK_SUCCESS(err);
3759
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003760 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003761 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003762 alloc_info.pSetLayouts = &ds_layout_ub;
3763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3764 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003765
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003766 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003767
Karl Schultz2825ab92016-12-02 08:23:14 -07003768 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003769 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003770 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003771}
3772
Karl Schultz6addd812016-02-02 17:17:23 -07003773TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3774 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003775
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3777 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3778 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003779
Tobin Ehlise735c692015-10-08 13:13:50 -06003780 ASSERT_NO_FATAL_FAILURE(InitState());
3781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003782
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003783 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003784 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3785 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003786
3787 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003788 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3789 ds_pool_ci.pNext = NULL;
3790 ds_pool_ci.maxSets = 1;
3791 ds_pool_ci.poolSizeCount = 1;
3792 ds_pool_ci.flags = 0;
3793 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3794 // app can only call vkResetDescriptorPool on this pool.;
3795 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003796
3797 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003798 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003799 ASSERT_VK_SUCCESS(err);
3800
3801 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003802 dsl_binding.binding = 0;
3803 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3804 dsl_binding.descriptorCount = 1;
3805 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3806 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003807
3808 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003809 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3810 ds_layout_ci.pNext = NULL;
3811 ds_layout_ci.bindingCount = 1;
3812 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003813
3814 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003815 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003816 ASSERT_VK_SUCCESS(err);
3817
3818 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003819 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003820 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003821 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003822 alloc_info.descriptorPool = ds_pool;
3823 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003824 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003825 ASSERT_VK_SUCCESS(err);
3826
3827 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003828 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003829
Chia-I Wuf7458c52015-10-26 21:10:41 +08003830 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3831 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003832}
3833
Karl Schultz6addd812016-02-02 17:17:23 -07003834TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003835 // Attempt to clear Descriptor Pool with bad object.
3836 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003837
3838 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003840 uint64_t fake_pool_handle = 0xbaad6001;
3841 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3842 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003843 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003844}
3845
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003846TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003847 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3848 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003849 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003850 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003851
3852 uint64_t fake_set_handle = 0xbaad6001;
3853 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003854 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06003856
3857 ASSERT_NO_FATAL_FAILURE(InitState());
3858
3859 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3860 layout_bindings[0].binding = 0;
3861 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3862 layout_bindings[0].descriptorCount = 1;
3863 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3864 layout_bindings[0].pImmutableSamplers = NULL;
3865
3866 VkDescriptorSetLayout descriptor_set_layout;
3867 VkDescriptorSetLayoutCreateInfo dslci = {};
3868 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3869 dslci.pNext = NULL;
3870 dslci.bindingCount = 1;
3871 dslci.pBindings = layout_bindings;
3872 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003873 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003874
3875 VkPipelineLayout pipeline_layout;
3876 VkPipelineLayoutCreateInfo plci = {};
3877 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3878 plci.pNext = NULL;
3879 plci.setLayoutCount = 1;
3880 plci.pSetLayouts = &descriptor_set_layout;
3881 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003882 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003883
3884 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003885 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3886 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003887 m_errorMonitor->VerifyFound();
3888 EndCommandBuffer();
3889 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3890 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003891}
3892
Karl Schultz6addd812016-02-02 17:17:23 -07003893TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003894 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3895 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003896 uint64_t fake_layout_handle = 0xbaad6001;
3897 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06003899 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003900 VkPipelineLayout pipeline_layout;
3901 VkPipelineLayoutCreateInfo plci = {};
3902 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3903 plci.pNext = NULL;
3904 plci.setLayoutCount = 1;
3905 plci.pSetLayouts = &bad_layout;
3906 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3907
3908 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003909}
3910
Mark Muellerd4914412016-06-13 17:52:06 -06003911TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3912 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3913 "1) A uniform buffer update must have a valid buffer index."
3914 "2) When using an array of descriptors in a single WriteDescriptor,"
3915 " the descriptor types and stageflags must all be the same."
3916 "3) Immutable Sampler state must match across descriptors");
3917
3918 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003919 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3920 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3921 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3922 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3923 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003924
Mark Muellerd4914412016-06-13 17:52:06 -06003925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3926
3927 ASSERT_NO_FATAL_FAILURE(InitState());
3928 VkDescriptorPoolSize ds_type_count[4] = {};
3929 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3930 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003931 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003932 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003933 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003934 ds_type_count[2].descriptorCount = 1;
3935 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3936 ds_type_count[3].descriptorCount = 1;
3937
3938 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3939 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3940 ds_pool_ci.maxSets = 1;
3941 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3942 ds_pool_ci.pPoolSizes = ds_type_count;
3943
3944 VkDescriptorPool ds_pool;
3945 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3946 ASSERT_VK_SUCCESS(err);
3947
Mark Muellerb9896722016-06-16 09:54:29 -06003948 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003949 layout_binding[0].binding = 0;
3950 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3951 layout_binding[0].descriptorCount = 1;
3952 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3953 layout_binding[0].pImmutableSamplers = NULL;
3954
3955 layout_binding[1].binding = 1;
3956 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3957 layout_binding[1].descriptorCount = 1;
3958 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3959 layout_binding[1].pImmutableSamplers = NULL;
3960
3961 VkSamplerCreateInfo sampler_ci = {};
3962 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3963 sampler_ci.pNext = NULL;
3964 sampler_ci.magFilter = VK_FILTER_NEAREST;
3965 sampler_ci.minFilter = VK_FILTER_NEAREST;
3966 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3967 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3968 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3969 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3970 sampler_ci.mipLodBias = 1.0;
3971 sampler_ci.anisotropyEnable = VK_FALSE;
3972 sampler_ci.maxAnisotropy = 1;
3973 sampler_ci.compareEnable = VK_FALSE;
3974 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3975 sampler_ci.minLod = 1.0;
3976 sampler_ci.maxLod = 1.0;
3977 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3978 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3979 VkSampler sampler;
3980
3981 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3982 ASSERT_VK_SUCCESS(err);
3983
3984 layout_binding[2].binding = 2;
3985 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3986 layout_binding[2].descriptorCount = 1;
3987 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3988 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3989
Mark Muellerd4914412016-06-13 17:52:06 -06003990 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3991 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3992 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3993 ds_layout_ci.pBindings = layout_binding;
3994 VkDescriptorSetLayout ds_layout;
3995 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3996 ASSERT_VK_SUCCESS(err);
3997
3998 VkDescriptorSetAllocateInfo alloc_info = {};
3999 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4000 alloc_info.descriptorSetCount = 1;
4001 alloc_info.descriptorPool = ds_pool;
4002 alloc_info.pSetLayouts = &ds_layout;
4003 VkDescriptorSet descriptorSet;
4004 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4005 ASSERT_VK_SUCCESS(err);
4006
4007 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4008 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4009 pipeline_layout_ci.pNext = NULL;
4010 pipeline_layout_ci.setLayoutCount = 1;
4011 pipeline_layout_ci.pSetLayouts = &ds_layout;
4012
4013 VkPipelineLayout pipeline_layout;
4014 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4015 ASSERT_VK_SUCCESS(err);
4016
Mark Mueller5c838ce2016-06-16 09:54:29 -06004017 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004018 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4019 descriptor_write.dstSet = descriptorSet;
4020 descriptor_write.dstBinding = 0;
4021 descriptor_write.descriptorCount = 1;
4022 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4023
Mark Mueller5c838ce2016-06-16 09:54:29 -06004024 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004025 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4026 m_errorMonitor->VerifyFound();
4027
4028 // Create a buffer to update the descriptor with
4029 uint32_t qfi = 0;
4030 VkBufferCreateInfo buffCI = {};
4031 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4032 buffCI.size = 1024;
4033 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4034 buffCI.queueFamilyIndexCount = 1;
4035 buffCI.pQueueFamilyIndices = &qfi;
4036
4037 VkBuffer dyub;
4038 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4039 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004040
Tony Barboure132c5f2016-12-12 11:50:20 -07004041 VkDeviceMemory mem;
4042 VkMemoryRequirements mem_reqs;
4043 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4044
4045 VkMemoryAllocateInfo mem_alloc_info = {};
4046 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4047 mem_alloc_info.allocationSize = mem_reqs.size;
4048 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4049 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4050 ASSERT_VK_SUCCESS(err);
4051
4052 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4053 ASSERT_VK_SUCCESS(err);
4054
4055 VkDescriptorBufferInfo buffInfo[2] = {};
4056 buffInfo[0].buffer = dyub;
4057 buffInfo[0].offset = 0;
4058 buffInfo[0].range = 1024;
4059 buffInfo[1].buffer = dyub;
4060 buffInfo[1].offset = 0;
4061 buffInfo[1].range = 1024;
4062 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004063 descriptor_write.descriptorCount = 2;
4064
Mark Mueller5c838ce2016-06-16 09:54:29 -06004065 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4067 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4068 m_errorMonitor->VerifyFound();
4069
Mark Mueller5c838ce2016-06-16 09:54:29 -06004070 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4071 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004072 descriptor_write.dstBinding = 1;
4073 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004074
Mark Mueller5c838ce2016-06-16 09:54:29 -06004075 // Make pImageInfo index non-null to avoid complaints of it missing
4076 VkDescriptorImageInfo imageInfo = {};
4077 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4078 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4080 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4081 m_errorMonitor->VerifyFound();
4082
Mark Muellerd4914412016-06-13 17:52:06 -06004083 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004084 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004085 vkDestroySampler(m_device->device(), sampler, NULL);
4086 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4087 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4088 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4089}
4090
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004091TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4092 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4093 "due to a buffer dependency being destroyed.");
4094 ASSERT_NO_FATAL_FAILURE(InitState());
4095
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004096 VkBuffer buffer;
4097 VkDeviceMemory mem;
4098 VkMemoryRequirements mem_reqs;
4099
4100 VkBufferCreateInfo buf_info = {};
4101 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004102 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004103 buf_info.size = 256;
4104 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4105 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4106 ASSERT_VK_SUCCESS(err);
4107
4108 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4109
4110 VkMemoryAllocateInfo alloc_info = {};
4111 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4112 alloc_info.allocationSize = 256;
4113 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004114 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 -06004115 if (!pass) {
4116 vkDestroyBuffer(m_device->device(), buffer, NULL);
4117 return;
4118 }
4119 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4120 ASSERT_VK_SUCCESS(err);
4121
4122 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4123 ASSERT_VK_SUCCESS(err);
4124
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004125 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004126 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004127 m_commandBuffer->EndCommandBuffer();
4128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004130 // Destroy buffer dependency prior to submit to cause ERROR
4131 vkDestroyBuffer(m_device->device(), buffer, NULL);
4132
4133 VkSubmitInfo submit_info = {};
4134 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4135 submit_info.commandBufferCount = 1;
4136 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4137 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4138
4139 m_errorMonitor->VerifyFound();
4140 vkFreeMemory(m_device->handle(), mem, NULL);
4141}
4142
Tobin Ehlisea413442016-09-28 10:23:59 -06004143TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4144 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4145
4146 ASSERT_NO_FATAL_FAILURE(InitState());
4147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4148
4149 VkDescriptorPoolSize ds_type_count;
4150 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4151 ds_type_count.descriptorCount = 1;
4152
4153 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4154 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4155 ds_pool_ci.maxSets = 1;
4156 ds_pool_ci.poolSizeCount = 1;
4157 ds_pool_ci.pPoolSizes = &ds_type_count;
4158
4159 VkDescriptorPool ds_pool;
4160 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4161 ASSERT_VK_SUCCESS(err);
4162
4163 VkDescriptorSetLayoutBinding layout_binding;
4164 layout_binding.binding = 0;
4165 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4166 layout_binding.descriptorCount = 1;
4167 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4168 layout_binding.pImmutableSamplers = NULL;
4169
4170 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4171 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4172 ds_layout_ci.bindingCount = 1;
4173 ds_layout_ci.pBindings = &layout_binding;
4174 VkDescriptorSetLayout ds_layout;
4175 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4176 ASSERT_VK_SUCCESS(err);
4177
4178 VkDescriptorSetAllocateInfo alloc_info = {};
4179 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4180 alloc_info.descriptorSetCount = 1;
4181 alloc_info.descriptorPool = ds_pool;
4182 alloc_info.pSetLayouts = &ds_layout;
4183 VkDescriptorSet descriptor_set;
4184 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4185 ASSERT_VK_SUCCESS(err);
4186
4187 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4188 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4189 pipeline_layout_ci.pNext = NULL;
4190 pipeline_layout_ci.setLayoutCount = 1;
4191 pipeline_layout_ci.pSetLayouts = &ds_layout;
4192
4193 VkPipelineLayout pipeline_layout;
4194 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4195 ASSERT_VK_SUCCESS(err);
4196
4197 VkBuffer buffer;
4198 uint32_t queue_family_index = 0;
4199 VkBufferCreateInfo buffer_create_info = {};
4200 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4201 buffer_create_info.size = 1024;
4202 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4203 buffer_create_info.queueFamilyIndexCount = 1;
4204 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4205
4206 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4207 ASSERT_VK_SUCCESS(err);
4208
4209 VkMemoryRequirements memory_reqs;
4210 VkDeviceMemory buffer_memory;
4211
4212 VkMemoryAllocateInfo memory_info = {};
4213 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4214 memory_info.allocationSize = 0;
4215 memory_info.memoryTypeIndex = 0;
4216
4217 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4218 memory_info.allocationSize = memory_reqs.size;
4219 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4220 ASSERT_TRUE(pass);
4221
4222 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4223 ASSERT_VK_SUCCESS(err);
4224 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4225 ASSERT_VK_SUCCESS(err);
4226
4227 VkBufferView view;
4228 VkBufferViewCreateInfo bvci = {};
4229 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4230 bvci.buffer = buffer;
4231 bvci.format = VK_FORMAT_R8_UNORM;
4232 bvci.range = VK_WHOLE_SIZE;
4233
4234 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4235 ASSERT_VK_SUCCESS(err);
4236
4237 VkWriteDescriptorSet descriptor_write = {};
4238 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4239 descriptor_write.dstSet = descriptor_set;
4240 descriptor_write.dstBinding = 0;
4241 descriptor_write.descriptorCount = 1;
4242 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4243 descriptor_write.pTexelBufferView = &view;
4244
4245 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4246
4247 char const *vsSource = "#version 450\n"
4248 "\n"
4249 "out gl_PerVertex { \n"
4250 " vec4 gl_Position;\n"
4251 "};\n"
4252 "void main(){\n"
4253 " gl_Position = vec4(1);\n"
4254 "}\n";
4255 char const *fsSource = "#version 450\n"
4256 "\n"
4257 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4258 "layout(location=0) out vec4 x;\n"
4259 "void main(){\n"
4260 " x = imageLoad(s, 0);\n"
4261 "}\n";
4262 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4263 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4264 VkPipelineObj pipe(m_device);
4265 pipe.AddShader(&vs);
4266 pipe.AddShader(&fs);
4267 pipe.AddColorAttachment();
4268 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4269
4270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4272
4273 BeginCommandBuffer();
4274 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4275 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4276 VkRect2D scissor = {{0, 0}, {16, 16}};
4277 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4278 // Bind pipeline to cmd buffer
4279 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4280 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4281 &descriptor_set, 0, nullptr);
4282 Draw(1, 0, 0, 0);
4283 EndCommandBuffer();
4284
4285 // Delete BufferView in order to invalidate cmd buffer
4286 vkDestroyBufferView(m_device->device(), view, NULL);
4287 // Now attempt submit of cmd buffer
4288 VkSubmitInfo submit_info = {};
4289 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4290 submit_info.commandBufferCount = 1;
4291 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4292 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4293 m_errorMonitor->VerifyFound();
4294
4295 // Clean-up
4296 vkDestroyBuffer(m_device->device(), buffer, NULL);
4297 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4298 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4299 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4300 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4301}
4302
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004303TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4304 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4305 "due to an image dependency being destroyed.");
4306 ASSERT_NO_FATAL_FAILURE(InitState());
4307
4308 VkImage image;
4309 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4310 VkImageCreateInfo image_create_info = {};
4311 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4312 image_create_info.pNext = NULL;
4313 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4314 image_create_info.format = tex_format;
4315 image_create_info.extent.width = 32;
4316 image_create_info.extent.height = 32;
4317 image_create_info.extent.depth = 1;
4318 image_create_info.mipLevels = 1;
4319 image_create_info.arrayLayers = 1;
4320 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4321 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004322 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004323 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004324 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004325 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004326 // Have to bind memory to image before recording cmd in cmd buffer using it
4327 VkMemoryRequirements mem_reqs;
4328 VkDeviceMemory image_mem;
4329 bool pass;
4330 VkMemoryAllocateInfo mem_alloc = {};
4331 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4332 mem_alloc.pNext = NULL;
4333 mem_alloc.memoryTypeIndex = 0;
4334 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4335 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004336 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004337 ASSERT_TRUE(pass);
4338 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4339 ASSERT_VK_SUCCESS(err);
4340 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4341 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004342
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004343 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004344 VkClearColorValue ccv;
4345 ccv.float32[0] = 1.0f;
4346 ccv.float32[1] = 1.0f;
4347 ccv.float32[2] = 1.0f;
4348 ccv.float32[3] = 1.0f;
4349 VkImageSubresourceRange isr = {};
4350 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004351 isr.baseArrayLayer = 0;
4352 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004353 isr.layerCount = 1;
4354 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004355 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004356 m_commandBuffer->EndCommandBuffer();
4357
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004359 // Destroy image dependency prior to submit to cause ERROR
4360 vkDestroyImage(m_device->device(), image, NULL);
4361
4362 VkSubmitInfo submit_info = {};
4363 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4364 submit_info.commandBufferCount = 1;
4365 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4366 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4367
4368 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004369 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004370}
4371
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004372TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4373 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4374 "due to a framebuffer image dependency being destroyed.");
4375 VkFormatProperties format_properties;
4376 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004377 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4378 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004379 return;
4380 }
4381
4382 ASSERT_NO_FATAL_FAILURE(InitState());
4383 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4384
4385 VkImageCreateInfo image_ci = {};
4386 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4387 image_ci.pNext = NULL;
4388 image_ci.imageType = VK_IMAGE_TYPE_2D;
4389 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4390 image_ci.extent.width = 32;
4391 image_ci.extent.height = 32;
4392 image_ci.extent.depth = 1;
4393 image_ci.mipLevels = 1;
4394 image_ci.arrayLayers = 1;
4395 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4396 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004397 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004398 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4399 image_ci.flags = 0;
4400 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004401 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004402
4403 VkMemoryRequirements memory_reqs;
4404 VkDeviceMemory image_memory;
4405 bool pass;
4406 VkMemoryAllocateInfo memory_info = {};
4407 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4408 memory_info.pNext = NULL;
4409 memory_info.allocationSize = 0;
4410 memory_info.memoryTypeIndex = 0;
4411 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4412 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004413 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004414 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004415 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004416 ASSERT_VK_SUCCESS(err);
4417 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4418 ASSERT_VK_SUCCESS(err);
4419
4420 VkImageViewCreateInfo ivci = {
4421 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4422 nullptr,
4423 0,
4424 image,
4425 VK_IMAGE_VIEW_TYPE_2D,
4426 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004427 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004428 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4429 };
4430 VkImageView view;
4431 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4432 ASSERT_VK_SUCCESS(err);
4433
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004434 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004435 VkFramebuffer fb;
4436 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4437 ASSERT_VK_SUCCESS(err);
4438
4439 // Just use default renderpass with our framebuffer
4440 m_renderPassBeginInfo.framebuffer = fb;
4441 // Create Null cmd buffer for submit
4442 BeginCommandBuffer();
4443 EndCommandBuffer();
4444 // Destroy image attached to framebuffer to invalidate cmd buffer
4445 vkDestroyImage(m_device->device(), image, NULL);
4446 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004448 QueueCommandBuffer(false);
4449 m_errorMonitor->VerifyFound();
4450
4451 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4452 vkDestroyImageView(m_device->device(), view, nullptr);
4453 vkFreeMemory(m_device->device(), image_memory, nullptr);
4454}
4455
Tobin Ehlisb329f992016-10-12 13:20:29 -06004456TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4457 TEST_DESCRIPTION("Delete in-use framebuffer.");
4458 VkFormatProperties format_properties;
4459 VkResult err = VK_SUCCESS;
4460 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4461
4462 ASSERT_NO_FATAL_FAILURE(InitState());
4463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4464
4465 VkImageObj image(m_device);
4466 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4467 ASSERT_TRUE(image.initialized());
4468 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4469
4470 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4471 VkFramebuffer fb;
4472 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4473 ASSERT_VK_SUCCESS(err);
4474
4475 // Just use default renderpass with our framebuffer
4476 m_renderPassBeginInfo.framebuffer = fb;
4477 // Create Null cmd buffer for submit
4478 BeginCommandBuffer();
4479 EndCommandBuffer();
4480 // Submit cmd buffer to put it in-flight
4481 VkSubmitInfo submit_info = {};
4482 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4483 submit_info.commandBufferCount = 1;
4484 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4485 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4486 // Destroy framebuffer while in-flight
4487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4488 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4489 m_errorMonitor->VerifyFound();
4490 // Wait for queue to complete so we can safely destroy everything
4491 vkQueueWaitIdle(m_device->m_queue);
4492 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4493}
4494
Tobin Ehlis88becd72016-09-21 14:33:41 -06004495TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4496 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4497 VkFormatProperties format_properties;
4498 VkResult err = VK_SUCCESS;
4499 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004500
4501 ASSERT_NO_FATAL_FAILURE(InitState());
4502 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4503
4504 VkImageCreateInfo image_ci = {};
4505 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4506 image_ci.pNext = NULL;
4507 image_ci.imageType = VK_IMAGE_TYPE_2D;
4508 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4509 image_ci.extent.width = 256;
4510 image_ci.extent.height = 256;
4511 image_ci.extent.depth = 1;
4512 image_ci.mipLevels = 1;
4513 image_ci.arrayLayers = 1;
4514 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4515 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004516 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004517 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4518 image_ci.flags = 0;
4519 VkImage image;
4520 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4521
4522 VkMemoryRequirements memory_reqs;
4523 VkDeviceMemory image_memory;
4524 bool pass;
4525 VkMemoryAllocateInfo memory_info = {};
4526 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4527 memory_info.pNext = NULL;
4528 memory_info.allocationSize = 0;
4529 memory_info.memoryTypeIndex = 0;
4530 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4531 memory_info.allocationSize = memory_reqs.size;
4532 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4533 ASSERT_TRUE(pass);
4534 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4535 ASSERT_VK_SUCCESS(err);
4536 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4537 ASSERT_VK_SUCCESS(err);
4538
4539 VkImageViewCreateInfo ivci = {
4540 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4541 nullptr,
4542 0,
4543 image,
4544 VK_IMAGE_VIEW_TYPE_2D,
4545 VK_FORMAT_B8G8R8A8_UNORM,
4546 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4547 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4548 };
4549 VkImageView view;
4550 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4551 ASSERT_VK_SUCCESS(err);
4552
4553 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4554 VkFramebuffer fb;
4555 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4556 ASSERT_VK_SUCCESS(err);
4557
4558 // Just use default renderpass with our framebuffer
4559 m_renderPassBeginInfo.framebuffer = fb;
4560 // Create Null cmd buffer for submit
4561 BeginCommandBuffer();
4562 EndCommandBuffer();
4563 // Submit cmd buffer to put it (and attached imageView) in-flight
4564 VkSubmitInfo submit_info = {};
4565 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4566 submit_info.commandBufferCount = 1;
4567 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4568 // Submit cmd buffer to put framebuffer and children in-flight
4569 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4570 // Destroy image attached to framebuffer while in-flight
4571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4572 vkDestroyImage(m_device->device(), image, NULL);
4573 m_errorMonitor->VerifyFound();
4574 // Wait for queue to complete so we can safely destroy image and other objects
4575 vkQueueWaitIdle(m_device->m_queue);
4576 vkDestroyImage(m_device->device(), image, NULL);
4577 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4578 vkDestroyImageView(m_device->device(), view, nullptr);
4579 vkFreeMemory(m_device->device(), image_memory, nullptr);
4580}
4581
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004582TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4583 TEST_DESCRIPTION("Delete in-use renderPass.");
4584
4585 ASSERT_NO_FATAL_FAILURE(InitState());
4586 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4587
4588 // Create simple renderpass
4589 VkAttachmentReference attach = {};
4590 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4591 VkSubpassDescription subpass = {};
4592 subpass.pColorAttachments = &attach;
4593 VkRenderPassCreateInfo rpci = {};
4594 rpci.subpassCount = 1;
4595 rpci.pSubpasses = &subpass;
4596 rpci.attachmentCount = 1;
4597 VkAttachmentDescription attach_desc = {};
4598 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4599 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4600 rpci.pAttachments = &attach_desc;
4601 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4602 VkRenderPass rp;
4603 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4604 ASSERT_VK_SUCCESS(err);
4605
4606 // Create a pipeline that uses the given renderpass
4607 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4608 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4609
4610 VkPipelineLayout pipeline_layout;
4611 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4612 ASSERT_VK_SUCCESS(err);
4613
4614 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4615 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4616 vp_state_ci.viewportCount = 1;
4617 VkViewport vp = {}; // Just need dummy vp to point to
4618 vp_state_ci.pViewports = &vp;
4619 vp_state_ci.scissorCount = 1;
4620 VkRect2D scissors = {}; // Dummy scissors to point to
4621 vp_state_ci.pScissors = &scissors;
4622
4623 VkPipelineShaderStageCreateInfo shaderStages[2];
4624 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4625
4626 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4627 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4628 // but add it to be able to run on more devices
4629 shaderStages[0] = vs.GetStageCreateInfo();
4630 shaderStages[1] = fs.GetStageCreateInfo();
4631
4632 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4633 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4634
4635 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4636 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4637 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4638
4639 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4640 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4641 rs_ci.rasterizerDiscardEnable = true;
4642 rs_ci.lineWidth = 1.0f;
4643
4644 VkPipelineColorBlendAttachmentState att = {};
4645 att.blendEnable = VK_FALSE;
4646 att.colorWriteMask = 0xf;
4647
4648 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4649 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4650 cb_ci.attachmentCount = 1;
4651 cb_ci.pAttachments = &att;
4652
4653 VkGraphicsPipelineCreateInfo gp_ci = {};
4654 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4655 gp_ci.stageCount = 2;
4656 gp_ci.pStages = shaderStages;
4657 gp_ci.pVertexInputState = &vi_ci;
4658 gp_ci.pInputAssemblyState = &ia_ci;
4659 gp_ci.pViewportState = &vp_state_ci;
4660 gp_ci.pRasterizationState = &rs_ci;
4661 gp_ci.pColorBlendState = &cb_ci;
4662 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4663 gp_ci.layout = pipeline_layout;
4664 gp_ci.renderPass = rp;
4665
4666 VkPipelineCacheCreateInfo pc_ci = {};
4667 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4668
4669 VkPipeline pipeline;
4670 VkPipelineCache pipe_cache;
4671 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4672 ASSERT_VK_SUCCESS(err);
4673
4674 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4675 ASSERT_VK_SUCCESS(err);
4676 // Bind pipeline to cmd buffer, will also bind renderpass
4677 m_commandBuffer->BeginCommandBuffer();
4678 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4679 m_commandBuffer->EndCommandBuffer();
4680
4681 VkSubmitInfo submit_info = {};
4682 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4683 submit_info.commandBufferCount = 1;
4684 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4685 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4686
4687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4688 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4689 m_errorMonitor->VerifyFound();
4690
4691 // Wait for queue to complete so we can safely destroy everything
4692 vkQueueWaitIdle(m_device->m_queue);
4693 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4694 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4695 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4696 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4697}
4698
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004699TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004700 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004701 ASSERT_NO_FATAL_FAILURE(InitState());
4702
4703 VkImage image;
4704 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4705 VkImageCreateInfo image_create_info = {};
4706 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4707 image_create_info.pNext = NULL;
4708 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4709 image_create_info.format = tex_format;
4710 image_create_info.extent.width = 32;
4711 image_create_info.extent.height = 32;
4712 image_create_info.extent.depth = 1;
4713 image_create_info.mipLevels = 1;
4714 image_create_info.arrayLayers = 1;
4715 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4716 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004717 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004718 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004719 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004720 ASSERT_VK_SUCCESS(err);
4721 // Have to bind memory to image before recording cmd in cmd buffer using it
4722 VkMemoryRequirements mem_reqs;
4723 VkDeviceMemory image_mem;
4724 bool pass;
4725 VkMemoryAllocateInfo mem_alloc = {};
4726 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4727 mem_alloc.pNext = NULL;
4728 mem_alloc.memoryTypeIndex = 0;
4729 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4730 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004731 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004732 ASSERT_TRUE(pass);
4733 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4734 ASSERT_VK_SUCCESS(err);
4735
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004736 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004738 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004739
4740 m_commandBuffer->BeginCommandBuffer();
4741 VkClearColorValue ccv;
4742 ccv.float32[0] = 1.0f;
4743 ccv.float32[1] = 1.0f;
4744 ccv.float32[2] = 1.0f;
4745 ccv.float32[3] = 1.0f;
4746 VkImageSubresourceRange isr = {};
4747 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4748 isr.baseArrayLayer = 0;
4749 isr.baseMipLevel = 0;
4750 isr.layerCount = 1;
4751 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004752 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004753 m_commandBuffer->EndCommandBuffer();
4754
4755 m_errorMonitor->VerifyFound();
4756 vkDestroyImage(m_device->device(), image, NULL);
4757 vkFreeMemory(m_device->device(), image_mem, nullptr);
4758}
4759
4760TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004761 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004762 ASSERT_NO_FATAL_FAILURE(InitState());
4763
4764 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004765 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 -06004766 VK_IMAGE_TILING_OPTIMAL, 0);
4767 ASSERT_TRUE(image.initialized());
4768
4769 VkBuffer buffer;
4770 VkDeviceMemory mem;
4771 VkMemoryRequirements mem_reqs;
4772
4773 VkBufferCreateInfo buf_info = {};
4774 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004775 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004776 buf_info.size = 256;
4777 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4778 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4779 ASSERT_VK_SUCCESS(err);
4780
4781 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4782
4783 VkMemoryAllocateInfo alloc_info = {};
4784 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4785 alloc_info.allocationSize = 256;
4786 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004787 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 -06004788 if (!pass) {
4789 vkDestroyBuffer(m_device->device(), buffer, NULL);
4790 return;
4791 }
4792 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4793 ASSERT_VK_SUCCESS(err);
4794
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004795 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004797 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004798 VkBufferImageCopy region = {};
4799 region.bufferRowLength = 128;
4800 region.bufferImageHeight = 128;
4801 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4802
4803 region.imageSubresource.layerCount = 1;
4804 region.imageExtent.height = 4;
4805 region.imageExtent.width = 4;
4806 region.imageExtent.depth = 1;
4807 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004808 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4809 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004810 m_commandBuffer->EndCommandBuffer();
4811
4812 m_errorMonitor->VerifyFound();
4813
4814 vkDestroyBuffer(m_device->device(), buffer, NULL);
4815 vkFreeMemory(m_device->handle(), mem, NULL);
4816}
4817
Tobin Ehlis85940f52016-07-07 16:57:21 -06004818TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4819 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4820 "due to an event dependency being destroyed.");
4821 ASSERT_NO_FATAL_FAILURE(InitState());
4822
4823 VkEvent event;
4824 VkEventCreateInfo evci = {};
4825 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4826 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4827 ASSERT_VK_SUCCESS(result);
4828
4829 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004830 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004831 m_commandBuffer->EndCommandBuffer();
4832
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004834 // Destroy event dependency prior to submit to cause ERROR
4835 vkDestroyEvent(m_device->device(), event, NULL);
4836
4837 VkSubmitInfo submit_info = {};
4838 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4839 submit_info.commandBufferCount = 1;
4840 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4841 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4842
4843 m_errorMonitor->VerifyFound();
4844}
4845
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004846TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4847 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4848 "due to a query pool dependency being destroyed.");
4849 ASSERT_NO_FATAL_FAILURE(InitState());
4850
4851 VkQueryPool query_pool;
4852 VkQueryPoolCreateInfo qpci{};
4853 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4854 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4855 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004856 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004857 ASSERT_VK_SUCCESS(result);
4858
4859 m_commandBuffer->BeginCommandBuffer();
4860 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4861 m_commandBuffer->EndCommandBuffer();
4862
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004864 // Destroy query pool dependency prior to submit to cause ERROR
4865 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4866
4867 VkSubmitInfo submit_info = {};
4868 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4869 submit_info.commandBufferCount = 1;
4870 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4871 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4872
4873 m_errorMonitor->VerifyFound();
4874}
4875
Tobin Ehlis24130d92016-07-08 15:50:53 -06004876TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4877 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4878 "due to a pipeline dependency being destroyed.");
4879 ASSERT_NO_FATAL_FAILURE(InitState());
4880 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4881
4882 VkResult err;
4883
4884 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4885 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4886
4887 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004888 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004889 ASSERT_VK_SUCCESS(err);
4890
4891 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4892 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4893 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004894 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004895 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004896 vp_state_ci.scissorCount = 1;
4897 VkRect2D scissors = {}; // Dummy scissors to point to
4898 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004899
4900 VkPipelineShaderStageCreateInfo shaderStages[2];
4901 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4902
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004903 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4904 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4905 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004906 shaderStages[0] = vs.GetStageCreateInfo();
4907 shaderStages[1] = fs.GetStageCreateInfo();
4908
4909 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4910 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4911
4912 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4913 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4914 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4915
4916 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4917 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004918 rs_ci.rasterizerDiscardEnable = true;
4919 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004920
4921 VkPipelineColorBlendAttachmentState att = {};
4922 att.blendEnable = VK_FALSE;
4923 att.colorWriteMask = 0xf;
4924
4925 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4926 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4927 cb_ci.attachmentCount = 1;
4928 cb_ci.pAttachments = &att;
4929
4930 VkGraphicsPipelineCreateInfo gp_ci = {};
4931 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4932 gp_ci.stageCount = 2;
4933 gp_ci.pStages = shaderStages;
4934 gp_ci.pVertexInputState = &vi_ci;
4935 gp_ci.pInputAssemblyState = &ia_ci;
4936 gp_ci.pViewportState = &vp_state_ci;
4937 gp_ci.pRasterizationState = &rs_ci;
4938 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004939 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4940 gp_ci.layout = pipeline_layout;
4941 gp_ci.renderPass = renderPass();
4942
4943 VkPipelineCacheCreateInfo pc_ci = {};
4944 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4945
4946 VkPipeline pipeline;
4947 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004948 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004949 ASSERT_VK_SUCCESS(err);
4950
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004951 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004952 ASSERT_VK_SUCCESS(err);
4953
4954 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004955 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004956 m_commandBuffer->EndCommandBuffer();
4957 // Now destroy pipeline in order to cause error when submitting
4958 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4959
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004961
4962 VkSubmitInfo submit_info = {};
4963 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4964 submit_info.commandBufferCount = 1;
4965 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4966 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4967
4968 m_errorMonitor->VerifyFound();
4969 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4970 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4971}
4972
Tobin Ehlis31289162016-08-17 14:57:58 -06004973TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4974 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4975 "due to a bound descriptor set with a buffer dependency "
4976 "being destroyed.");
4977 ASSERT_NO_FATAL_FAILURE(InitState());
4978 ASSERT_NO_FATAL_FAILURE(InitViewport());
4979 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4980
4981 VkDescriptorPoolSize ds_type_count = {};
4982 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4983 ds_type_count.descriptorCount = 1;
4984
4985 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4986 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4987 ds_pool_ci.pNext = NULL;
4988 ds_pool_ci.maxSets = 1;
4989 ds_pool_ci.poolSizeCount = 1;
4990 ds_pool_ci.pPoolSizes = &ds_type_count;
4991
4992 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004993 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004994 ASSERT_VK_SUCCESS(err);
4995
4996 VkDescriptorSetLayoutBinding dsl_binding = {};
4997 dsl_binding.binding = 0;
4998 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4999 dsl_binding.descriptorCount = 1;
5000 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5001 dsl_binding.pImmutableSamplers = NULL;
5002
5003 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5004 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5005 ds_layout_ci.pNext = NULL;
5006 ds_layout_ci.bindingCount = 1;
5007 ds_layout_ci.pBindings = &dsl_binding;
5008 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005009 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005010 ASSERT_VK_SUCCESS(err);
5011
5012 VkDescriptorSet descriptorSet;
5013 VkDescriptorSetAllocateInfo alloc_info = {};
5014 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5015 alloc_info.descriptorSetCount = 1;
5016 alloc_info.descriptorPool = ds_pool;
5017 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005018 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005019 ASSERT_VK_SUCCESS(err);
5020
5021 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5022 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5023 pipeline_layout_ci.pNext = NULL;
5024 pipeline_layout_ci.setLayoutCount = 1;
5025 pipeline_layout_ci.pSetLayouts = &ds_layout;
5026
5027 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005028 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005029 ASSERT_VK_SUCCESS(err);
5030
5031 // Create a buffer to update the descriptor with
5032 uint32_t qfi = 0;
5033 VkBufferCreateInfo buffCI = {};
5034 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5035 buffCI.size = 1024;
5036 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5037 buffCI.queueFamilyIndexCount = 1;
5038 buffCI.pQueueFamilyIndices = &qfi;
5039
5040 VkBuffer buffer;
5041 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5042 ASSERT_VK_SUCCESS(err);
5043 // Allocate memory and bind to buffer so we can make it to the appropriate
5044 // error
5045 VkMemoryAllocateInfo mem_alloc = {};
5046 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5047 mem_alloc.pNext = NULL;
5048 mem_alloc.allocationSize = 1024;
5049 mem_alloc.memoryTypeIndex = 0;
5050
5051 VkMemoryRequirements memReqs;
5052 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005053 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005054 if (!pass) {
5055 vkDestroyBuffer(m_device->device(), buffer, NULL);
5056 return;
5057 }
5058
5059 VkDeviceMemory mem;
5060 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5061 ASSERT_VK_SUCCESS(err);
5062 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5063 ASSERT_VK_SUCCESS(err);
5064 // Correctly update descriptor to avoid "NOT_UPDATED" error
5065 VkDescriptorBufferInfo buffInfo = {};
5066 buffInfo.buffer = buffer;
5067 buffInfo.offset = 0;
5068 buffInfo.range = 1024;
5069
5070 VkWriteDescriptorSet descriptor_write;
5071 memset(&descriptor_write, 0, sizeof(descriptor_write));
5072 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5073 descriptor_write.dstSet = descriptorSet;
5074 descriptor_write.dstBinding = 0;
5075 descriptor_write.descriptorCount = 1;
5076 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5077 descriptor_write.pBufferInfo = &buffInfo;
5078
5079 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5080
5081 // Create PSO to be used for draw-time errors below
5082 char const *vsSource = "#version 450\n"
5083 "\n"
5084 "out gl_PerVertex { \n"
5085 " vec4 gl_Position;\n"
5086 "};\n"
5087 "void main(){\n"
5088 " gl_Position = vec4(1);\n"
5089 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005090 char const *fsSource = "#version 450\n"
5091 "\n"
5092 "layout(location=0) out vec4 x;\n"
5093 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5094 "void main(){\n"
5095 " x = vec4(bar.y);\n"
5096 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005097 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5098 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5099 VkPipelineObj pipe(m_device);
5100 pipe.AddShader(&vs);
5101 pipe.AddShader(&fs);
5102 pipe.AddColorAttachment();
5103 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5104
5105 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005106 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5107 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5108 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005109 Draw(1, 0, 0, 0);
5110 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005112 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5113 vkDestroyBuffer(m_device->device(), buffer, NULL);
5114 // Attempt to submit cmd buffer
5115 VkSubmitInfo submit_info = {};
5116 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5117 submit_info.commandBufferCount = 1;
5118 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5119 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5120 m_errorMonitor->VerifyFound();
5121 // Cleanup
5122 vkFreeMemory(m_device->device(), mem, NULL);
5123
5124 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5125 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5126 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5127}
5128
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005129TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5130 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5131 "due to a bound descriptor sets with a combined image "
5132 "sampler having their image, sampler, and descriptor set "
5133 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005134 "submit associated cmd buffers. Attempt to destroy a "
5135 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005136 ASSERT_NO_FATAL_FAILURE(InitState());
5137 ASSERT_NO_FATAL_FAILURE(InitViewport());
5138 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5139
5140 VkDescriptorPoolSize ds_type_count = {};
5141 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5142 ds_type_count.descriptorCount = 1;
5143
5144 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5145 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5146 ds_pool_ci.pNext = NULL;
5147 ds_pool_ci.maxSets = 1;
5148 ds_pool_ci.poolSizeCount = 1;
5149 ds_pool_ci.pPoolSizes = &ds_type_count;
5150
5151 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005152 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005153 ASSERT_VK_SUCCESS(err);
5154
5155 VkDescriptorSetLayoutBinding dsl_binding = {};
5156 dsl_binding.binding = 0;
5157 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5158 dsl_binding.descriptorCount = 1;
5159 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5160 dsl_binding.pImmutableSamplers = NULL;
5161
5162 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5163 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5164 ds_layout_ci.pNext = NULL;
5165 ds_layout_ci.bindingCount = 1;
5166 ds_layout_ci.pBindings = &dsl_binding;
5167 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005168 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005169 ASSERT_VK_SUCCESS(err);
5170
5171 VkDescriptorSet descriptorSet;
5172 VkDescriptorSetAllocateInfo alloc_info = {};
5173 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5174 alloc_info.descriptorSetCount = 1;
5175 alloc_info.descriptorPool = ds_pool;
5176 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005177 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005178 ASSERT_VK_SUCCESS(err);
5179
5180 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5181 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5182 pipeline_layout_ci.pNext = NULL;
5183 pipeline_layout_ci.setLayoutCount = 1;
5184 pipeline_layout_ci.pSetLayouts = &ds_layout;
5185
5186 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005187 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005188 ASSERT_VK_SUCCESS(err);
5189
5190 // Create images to update the descriptor with
5191 VkImage image;
5192 VkImage image2;
5193 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5194 const int32_t tex_width = 32;
5195 const int32_t tex_height = 32;
5196 VkImageCreateInfo image_create_info = {};
5197 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5198 image_create_info.pNext = NULL;
5199 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5200 image_create_info.format = tex_format;
5201 image_create_info.extent.width = tex_width;
5202 image_create_info.extent.height = tex_height;
5203 image_create_info.extent.depth = 1;
5204 image_create_info.mipLevels = 1;
5205 image_create_info.arrayLayers = 1;
5206 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5207 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5208 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5209 image_create_info.flags = 0;
5210 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5211 ASSERT_VK_SUCCESS(err);
5212 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5213 ASSERT_VK_SUCCESS(err);
5214
5215 VkMemoryRequirements memory_reqs;
5216 VkDeviceMemory image_memory;
5217 bool pass;
5218 VkMemoryAllocateInfo memory_info = {};
5219 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5220 memory_info.pNext = NULL;
5221 memory_info.allocationSize = 0;
5222 memory_info.memoryTypeIndex = 0;
5223 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5224 // Allocate enough memory for both images
5225 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005226 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005227 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005228 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005229 ASSERT_VK_SUCCESS(err);
5230 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5231 ASSERT_VK_SUCCESS(err);
5232 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005233 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005234 ASSERT_VK_SUCCESS(err);
5235
5236 VkImageViewCreateInfo image_view_create_info = {};
5237 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5238 image_view_create_info.image = image;
5239 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5240 image_view_create_info.format = tex_format;
5241 image_view_create_info.subresourceRange.layerCount = 1;
5242 image_view_create_info.subresourceRange.baseMipLevel = 0;
5243 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005244 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005245
5246 VkImageView view;
5247 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005248 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005249 ASSERT_VK_SUCCESS(err);
5250 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005251 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005252 ASSERT_VK_SUCCESS(err);
5253 // Create Samplers
5254 VkSamplerCreateInfo sampler_ci = {};
5255 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5256 sampler_ci.pNext = NULL;
5257 sampler_ci.magFilter = VK_FILTER_NEAREST;
5258 sampler_ci.minFilter = VK_FILTER_NEAREST;
5259 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5260 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5261 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5262 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5263 sampler_ci.mipLodBias = 1.0;
5264 sampler_ci.anisotropyEnable = VK_FALSE;
5265 sampler_ci.maxAnisotropy = 1;
5266 sampler_ci.compareEnable = VK_FALSE;
5267 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5268 sampler_ci.minLod = 1.0;
5269 sampler_ci.maxLod = 1.0;
5270 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5271 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5272 VkSampler sampler;
5273 VkSampler sampler2;
5274 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5275 ASSERT_VK_SUCCESS(err);
5276 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5277 ASSERT_VK_SUCCESS(err);
5278 // Update descriptor with image and sampler
5279 VkDescriptorImageInfo img_info = {};
5280 img_info.sampler = sampler;
5281 img_info.imageView = view;
5282 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5283
5284 VkWriteDescriptorSet descriptor_write;
5285 memset(&descriptor_write, 0, sizeof(descriptor_write));
5286 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5287 descriptor_write.dstSet = descriptorSet;
5288 descriptor_write.dstBinding = 0;
5289 descriptor_write.descriptorCount = 1;
5290 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5291 descriptor_write.pImageInfo = &img_info;
5292
5293 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5294
5295 // Create PSO to be used for draw-time errors below
5296 char const *vsSource = "#version 450\n"
5297 "\n"
5298 "out gl_PerVertex { \n"
5299 " vec4 gl_Position;\n"
5300 "};\n"
5301 "void main(){\n"
5302 " gl_Position = vec4(1);\n"
5303 "}\n";
5304 char const *fsSource = "#version 450\n"
5305 "\n"
5306 "layout(set=0, binding=0) uniform sampler2D s;\n"
5307 "layout(location=0) out vec4 x;\n"
5308 "void main(){\n"
5309 " x = texture(s, vec2(1));\n"
5310 "}\n";
5311 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5312 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5313 VkPipelineObj pipe(m_device);
5314 pipe.AddShader(&vs);
5315 pipe.AddShader(&fs);
5316 pipe.AddColorAttachment();
5317 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5318
5319 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005321 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005322 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5323 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5324 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005325 Draw(1, 0, 0, 0);
5326 EndCommandBuffer();
5327 // Destroy sampler invalidates the cmd buffer, causing error on submit
5328 vkDestroySampler(m_device->device(), sampler, NULL);
5329 // Attempt to submit cmd buffer
5330 VkSubmitInfo submit_info = {};
5331 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5332 submit_info.commandBufferCount = 1;
5333 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5334 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5335 m_errorMonitor->VerifyFound();
5336 // Now re-update descriptor with valid sampler and delete image
5337 img_info.sampler = sampler2;
5338 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005340 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005341 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5342 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5343 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005344 Draw(1, 0, 0, 0);
5345 EndCommandBuffer();
5346 // Destroy image invalidates the cmd buffer, causing error on submit
5347 vkDestroyImage(m_device->device(), image, NULL);
5348 // Attempt to submit cmd buffer
5349 submit_info = {};
5350 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5351 submit_info.commandBufferCount = 1;
5352 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5353 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5354 m_errorMonitor->VerifyFound();
5355 // Now update descriptor to be valid, but then free descriptor
5356 img_info.imageView = view2;
5357 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005359 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005360 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5361 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5362 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005363 Draw(1, 0, 0, 0);
5364 EndCommandBuffer();
5365 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005367 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005368 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005369 // Attempt to submit cmd buffer
5370 submit_info = {};
5371 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5372 submit_info.commandBufferCount = 1;
5373 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5374 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5375 m_errorMonitor->VerifyFound();
5376 // Cleanup
5377 vkFreeMemory(m_device->device(), image_memory, NULL);
5378 vkDestroySampler(m_device->device(), sampler2, NULL);
5379 vkDestroyImage(m_device->device(), image2, NULL);
5380 vkDestroyImageView(m_device->device(), view, NULL);
5381 vkDestroyImageView(m_device->device(), view2, NULL);
5382 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5383 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5384 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5385}
5386
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005387TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5388 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5389 ASSERT_NO_FATAL_FAILURE(InitState());
5390 ASSERT_NO_FATAL_FAILURE(InitViewport());
5391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5392
5393 VkDescriptorPoolSize ds_type_count = {};
5394 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5395 ds_type_count.descriptorCount = 1;
5396
5397 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5398 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5399 ds_pool_ci.pNext = NULL;
5400 ds_pool_ci.maxSets = 1;
5401 ds_pool_ci.poolSizeCount = 1;
5402 ds_pool_ci.pPoolSizes = &ds_type_count;
5403
5404 VkDescriptorPool ds_pool;
5405 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5406 ASSERT_VK_SUCCESS(err);
5407
5408 VkDescriptorSetLayoutBinding dsl_binding = {};
5409 dsl_binding.binding = 0;
5410 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5411 dsl_binding.descriptorCount = 1;
5412 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5413 dsl_binding.pImmutableSamplers = NULL;
5414
5415 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5416 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5417 ds_layout_ci.pNext = NULL;
5418 ds_layout_ci.bindingCount = 1;
5419 ds_layout_ci.pBindings = &dsl_binding;
5420 VkDescriptorSetLayout ds_layout;
5421 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5422 ASSERT_VK_SUCCESS(err);
5423
5424 VkDescriptorSet descriptor_set;
5425 VkDescriptorSetAllocateInfo alloc_info = {};
5426 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5427 alloc_info.descriptorSetCount = 1;
5428 alloc_info.descriptorPool = ds_pool;
5429 alloc_info.pSetLayouts = &ds_layout;
5430 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5431 ASSERT_VK_SUCCESS(err);
5432
5433 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5434 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5435 pipeline_layout_ci.pNext = NULL;
5436 pipeline_layout_ci.setLayoutCount = 1;
5437 pipeline_layout_ci.pSetLayouts = &ds_layout;
5438
5439 VkPipelineLayout pipeline_layout;
5440 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5441 ASSERT_VK_SUCCESS(err);
5442
5443 // Create image to update the descriptor with
5444 VkImageObj image(m_device);
5445 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5446 ASSERT_TRUE(image.initialized());
5447
5448 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5449 // Create Sampler
5450 VkSamplerCreateInfo sampler_ci = {};
5451 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5452 sampler_ci.pNext = NULL;
5453 sampler_ci.magFilter = VK_FILTER_NEAREST;
5454 sampler_ci.minFilter = VK_FILTER_NEAREST;
5455 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5456 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5457 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5458 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5459 sampler_ci.mipLodBias = 1.0;
5460 sampler_ci.anisotropyEnable = VK_FALSE;
5461 sampler_ci.maxAnisotropy = 1;
5462 sampler_ci.compareEnable = VK_FALSE;
5463 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5464 sampler_ci.minLod = 1.0;
5465 sampler_ci.maxLod = 1.0;
5466 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5467 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5468 VkSampler sampler;
5469 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5470 ASSERT_VK_SUCCESS(err);
5471 // Update descriptor with image and sampler
5472 VkDescriptorImageInfo img_info = {};
5473 img_info.sampler = sampler;
5474 img_info.imageView = view;
5475 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5476
5477 VkWriteDescriptorSet descriptor_write;
5478 memset(&descriptor_write, 0, sizeof(descriptor_write));
5479 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5480 descriptor_write.dstSet = descriptor_set;
5481 descriptor_write.dstBinding = 0;
5482 descriptor_write.descriptorCount = 1;
5483 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5484 descriptor_write.pImageInfo = &img_info;
5485
5486 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5487
5488 // Create PSO to be used for draw-time errors below
5489 char const *vsSource = "#version 450\n"
5490 "\n"
5491 "out gl_PerVertex { \n"
5492 " vec4 gl_Position;\n"
5493 "};\n"
5494 "void main(){\n"
5495 " gl_Position = vec4(1);\n"
5496 "}\n";
5497 char const *fsSource = "#version 450\n"
5498 "\n"
5499 "layout(set=0, binding=0) uniform sampler2D s;\n"
5500 "layout(location=0) out vec4 x;\n"
5501 "void main(){\n"
5502 " x = texture(s, vec2(1));\n"
5503 "}\n";
5504 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5505 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5506 VkPipelineObj pipe(m_device);
5507 pipe.AddShader(&vs);
5508 pipe.AddShader(&fs);
5509 pipe.AddColorAttachment();
5510 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5511
5512 BeginCommandBuffer();
5513 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5514 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5515 &descriptor_set, 0, NULL);
5516 Draw(1, 0, 0, 0);
5517 EndCommandBuffer();
5518 // Submit cmd buffer to put pool in-flight
5519 VkSubmitInfo submit_info = {};
5520 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5521 submit_info.commandBufferCount = 1;
5522 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5523 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5524 // Destroy pool while in-flight, causing error
5525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5526 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5527 m_errorMonitor->VerifyFound();
5528 vkQueueWaitIdle(m_device->m_queue);
5529 // Cleanup
5530 vkDestroySampler(m_device->device(), sampler, NULL);
5531 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5532 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5533 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5534}
5535
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005536TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5537 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5538 ASSERT_NO_FATAL_FAILURE(InitState());
5539 ASSERT_NO_FATAL_FAILURE(InitViewport());
5540 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5541
5542 VkDescriptorPoolSize ds_type_count = {};
5543 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5544 ds_type_count.descriptorCount = 1;
5545
5546 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5547 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5548 ds_pool_ci.pNext = NULL;
5549 ds_pool_ci.maxSets = 1;
5550 ds_pool_ci.poolSizeCount = 1;
5551 ds_pool_ci.pPoolSizes = &ds_type_count;
5552
5553 VkDescriptorPool ds_pool;
5554 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5555 ASSERT_VK_SUCCESS(err);
5556
5557 VkDescriptorSetLayoutBinding dsl_binding = {};
5558 dsl_binding.binding = 0;
5559 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5560 dsl_binding.descriptorCount = 1;
5561 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5562 dsl_binding.pImmutableSamplers = NULL;
5563
5564 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5565 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5566 ds_layout_ci.pNext = NULL;
5567 ds_layout_ci.bindingCount = 1;
5568 ds_layout_ci.pBindings = &dsl_binding;
5569 VkDescriptorSetLayout ds_layout;
5570 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5571 ASSERT_VK_SUCCESS(err);
5572
5573 VkDescriptorSet descriptorSet;
5574 VkDescriptorSetAllocateInfo alloc_info = {};
5575 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5576 alloc_info.descriptorSetCount = 1;
5577 alloc_info.descriptorPool = ds_pool;
5578 alloc_info.pSetLayouts = &ds_layout;
5579 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5580 ASSERT_VK_SUCCESS(err);
5581
5582 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5583 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5584 pipeline_layout_ci.pNext = NULL;
5585 pipeline_layout_ci.setLayoutCount = 1;
5586 pipeline_layout_ci.pSetLayouts = &ds_layout;
5587
5588 VkPipelineLayout pipeline_layout;
5589 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5590 ASSERT_VK_SUCCESS(err);
5591
5592 // Create images to update the descriptor with
5593 VkImage image;
5594 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5595 const int32_t tex_width = 32;
5596 const int32_t tex_height = 32;
5597 VkImageCreateInfo image_create_info = {};
5598 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5599 image_create_info.pNext = NULL;
5600 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5601 image_create_info.format = tex_format;
5602 image_create_info.extent.width = tex_width;
5603 image_create_info.extent.height = tex_height;
5604 image_create_info.extent.depth = 1;
5605 image_create_info.mipLevels = 1;
5606 image_create_info.arrayLayers = 1;
5607 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5608 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5609 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5610 image_create_info.flags = 0;
5611 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5612 ASSERT_VK_SUCCESS(err);
5613 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5614 VkMemoryRequirements memory_reqs;
5615 VkDeviceMemory image_memory;
5616 bool pass;
5617 VkMemoryAllocateInfo memory_info = {};
5618 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5619 memory_info.pNext = NULL;
5620 memory_info.allocationSize = 0;
5621 memory_info.memoryTypeIndex = 0;
5622 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5623 // Allocate enough memory for image
5624 memory_info.allocationSize = memory_reqs.size;
5625 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5626 ASSERT_TRUE(pass);
5627 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5628 ASSERT_VK_SUCCESS(err);
5629 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5630 ASSERT_VK_SUCCESS(err);
5631
5632 VkImageViewCreateInfo image_view_create_info = {};
5633 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5634 image_view_create_info.image = image;
5635 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5636 image_view_create_info.format = tex_format;
5637 image_view_create_info.subresourceRange.layerCount = 1;
5638 image_view_create_info.subresourceRange.baseMipLevel = 0;
5639 image_view_create_info.subresourceRange.levelCount = 1;
5640 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5641
5642 VkImageView view;
5643 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5644 ASSERT_VK_SUCCESS(err);
5645 // Create Samplers
5646 VkSamplerCreateInfo sampler_ci = {};
5647 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5648 sampler_ci.pNext = NULL;
5649 sampler_ci.magFilter = VK_FILTER_NEAREST;
5650 sampler_ci.minFilter = VK_FILTER_NEAREST;
5651 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5652 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5653 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5654 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5655 sampler_ci.mipLodBias = 1.0;
5656 sampler_ci.anisotropyEnable = VK_FALSE;
5657 sampler_ci.maxAnisotropy = 1;
5658 sampler_ci.compareEnable = VK_FALSE;
5659 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5660 sampler_ci.minLod = 1.0;
5661 sampler_ci.maxLod = 1.0;
5662 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5663 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5664 VkSampler sampler;
5665 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5666 ASSERT_VK_SUCCESS(err);
5667 // Update descriptor with image and sampler
5668 VkDescriptorImageInfo img_info = {};
5669 img_info.sampler = sampler;
5670 img_info.imageView = view;
5671 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5672
5673 VkWriteDescriptorSet descriptor_write;
5674 memset(&descriptor_write, 0, sizeof(descriptor_write));
5675 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5676 descriptor_write.dstSet = descriptorSet;
5677 descriptor_write.dstBinding = 0;
5678 descriptor_write.descriptorCount = 1;
5679 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5680 descriptor_write.pImageInfo = &img_info;
5681 // Break memory binding and attempt update
5682 vkFreeMemory(m_device->device(), image_memory, nullptr);
5683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005684 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5686 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5687 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5688 m_errorMonitor->VerifyFound();
5689 // Cleanup
5690 vkDestroyImage(m_device->device(), image, NULL);
5691 vkDestroySampler(m_device->device(), sampler, NULL);
5692 vkDestroyImageView(m_device->device(), view, NULL);
5693 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5694 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5695 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5696}
5697
Karl Schultz6addd812016-02-02 17:17:23 -07005698TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005699 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5700 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005701 // Create a valid cmd buffer
5702 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005703 uint64_t fake_pipeline_handle = 0xbaad6001;
5704 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005705 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005706 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5707
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Karl Schultzbdb75952016-04-19 11:36:49 -06005709 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005710 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005711 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005712
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005713 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005714 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 -06005715 Draw(1, 0, 0, 0);
5716 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005717
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005718 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005719 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 +12005720 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005721 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5722 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005723}
5724
Karl Schultz6addd812016-02-02 17:17:23 -07005725TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005726 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005727 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005728
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005730
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005731 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005732 ASSERT_NO_FATAL_FAILURE(InitViewport());
5733 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005734 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005735 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5736 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005737
5738 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005739 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5740 ds_pool_ci.pNext = NULL;
5741 ds_pool_ci.maxSets = 1;
5742 ds_pool_ci.poolSizeCount = 1;
5743 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005744
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005745 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005746 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005747 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005748
Tony Barboureb254902015-07-15 12:50:33 -06005749 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005750 dsl_binding.binding = 0;
5751 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5752 dsl_binding.descriptorCount = 1;
5753 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5754 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005755
Tony Barboureb254902015-07-15 12:50:33 -06005756 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005757 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5758 ds_layout_ci.pNext = NULL;
5759 ds_layout_ci.bindingCount = 1;
5760 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005761 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005762 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005763 ASSERT_VK_SUCCESS(err);
5764
5765 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005766 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005767 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005768 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005769 alloc_info.descriptorPool = ds_pool;
5770 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005771 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005772 ASSERT_VK_SUCCESS(err);
5773
Tony Barboureb254902015-07-15 12:50:33 -06005774 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005775 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5776 pipeline_layout_ci.pNext = NULL;
5777 pipeline_layout_ci.setLayoutCount = 1;
5778 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005779
5780 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005781 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005782 ASSERT_VK_SUCCESS(err);
5783
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005784 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005785 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005786 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005787 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005788
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005789 VkPipelineObj pipe(m_device);
5790 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005791 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005792 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005793 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005794
5795 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005796 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5797 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5798 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005799
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005800 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005801
Chia-I Wuf7458c52015-10-26 21:10:41 +08005802 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5803 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5804 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005805}
5806
Karl Schultz6addd812016-02-02 17:17:23 -07005807TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005808 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005809 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005810
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005812
5813 ASSERT_NO_FATAL_FAILURE(InitState());
5814 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005815 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5816 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005817
5818 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005819 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5820 ds_pool_ci.pNext = NULL;
5821 ds_pool_ci.maxSets = 1;
5822 ds_pool_ci.poolSizeCount = 1;
5823 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005824
5825 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005826 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005827 ASSERT_VK_SUCCESS(err);
5828
5829 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005830 dsl_binding.binding = 0;
5831 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5832 dsl_binding.descriptorCount = 1;
5833 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5834 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005835
5836 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005837 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5838 ds_layout_ci.pNext = NULL;
5839 ds_layout_ci.bindingCount = 1;
5840 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005841 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005842 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005843 ASSERT_VK_SUCCESS(err);
5844
5845 VkDescriptorSet descriptorSet;
5846 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005847 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005848 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005849 alloc_info.descriptorPool = ds_pool;
5850 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005851 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005852 ASSERT_VK_SUCCESS(err);
5853
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005854 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005855 VkWriteDescriptorSet descriptor_write;
5856 memset(&descriptor_write, 0, sizeof(descriptor_write));
5857 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5858 descriptor_write.dstSet = descriptorSet;
5859 descriptor_write.dstBinding = 0;
5860 descriptor_write.descriptorCount = 1;
5861 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5862 descriptor_write.pTexelBufferView = &view;
5863
5864 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5865
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005866 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005867
5868 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5869 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5870}
5871
Mark Youngd339ba32016-05-30 13:28:35 -06005872TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005873 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 -06005874
5875 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005877 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005878
5879 ASSERT_NO_FATAL_FAILURE(InitState());
5880
5881 // Create a buffer with no bound memory and then attempt to create
5882 // a buffer view.
5883 VkBufferCreateInfo buff_ci = {};
5884 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005885 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005886 buff_ci.size = 256;
5887 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5888 VkBuffer buffer;
5889 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5890 ASSERT_VK_SUCCESS(err);
5891
5892 VkBufferViewCreateInfo buff_view_ci = {};
5893 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5894 buff_view_ci.buffer = buffer;
5895 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5896 buff_view_ci.range = VK_WHOLE_SIZE;
5897 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005898 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005899
5900 m_errorMonitor->VerifyFound();
5901 vkDestroyBuffer(m_device->device(), buffer, NULL);
5902 // If last error is success, it still created the view, so delete it.
5903 if (err == VK_SUCCESS) {
5904 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5905 }
5906}
5907
Karl Schultz6addd812016-02-02 17:17:23 -07005908TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5909 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5910 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005911 // 1. No dynamicOffset supplied
5912 // 2. Too many dynamicOffsets supplied
5913 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005914 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5916 "0 dynamicOffsets are left in "
5917 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005918
5919 ASSERT_NO_FATAL_FAILURE(InitState());
5920 ASSERT_NO_FATAL_FAILURE(InitViewport());
5921 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5922
5923 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005924 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5925 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005926
5927 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005928 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5929 ds_pool_ci.pNext = NULL;
5930 ds_pool_ci.maxSets = 1;
5931 ds_pool_ci.poolSizeCount = 1;
5932 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005933
5934 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005935 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005936 ASSERT_VK_SUCCESS(err);
5937
5938 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005939 dsl_binding.binding = 0;
5940 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5941 dsl_binding.descriptorCount = 1;
5942 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5943 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005944
5945 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005946 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5947 ds_layout_ci.pNext = NULL;
5948 ds_layout_ci.bindingCount = 1;
5949 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005950 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005951 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005952 ASSERT_VK_SUCCESS(err);
5953
5954 VkDescriptorSet descriptorSet;
5955 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005956 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005957 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005958 alloc_info.descriptorPool = ds_pool;
5959 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005960 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005961 ASSERT_VK_SUCCESS(err);
5962
5963 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005964 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5965 pipeline_layout_ci.pNext = NULL;
5966 pipeline_layout_ci.setLayoutCount = 1;
5967 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005968
5969 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005970 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005971 ASSERT_VK_SUCCESS(err);
5972
5973 // Create a buffer to update the descriptor with
5974 uint32_t qfi = 0;
5975 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005976 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5977 buffCI.size = 1024;
5978 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5979 buffCI.queueFamilyIndexCount = 1;
5980 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005981
5982 VkBuffer dyub;
5983 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5984 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005985 // Allocate memory and bind to buffer so we can make it to the appropriate
5986 // error
5987 VkMemoryAllocateInfo mem_alloc = {};
5988 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5989 mem_alloc.pNext = NULL;
5990 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005991 mem_alloc.memoryTypeIndex = 0;
5992
5993 VkMemoryRequirements memReqs;
5994 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005995 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005996 if (!pass) {
5997 vkDestroyBuffer(m_device->device(), dyub, NULL);
5998 return;
5999 }
6000
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006001 VkDeviceMemory mem;
6002 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6003 ASSERT_VK_SUCCESS(err);
6004 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6005 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006006 // Correctly update descriptor to avoid "NOT_UPDATED" error
6007 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006008 buffInfo.buffer = dyub;
6009 buffInfo.offset = 0;
6010 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006011
6012 VkWriteDescriptorSet descriptor_write;
6013 memset(&descriptor_write, 0, sizeof(descriptor_write));
6014 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6015 descriptor_write.dstSet = descriptorSet;
6016 descriptor_write.dstBinding = 0;
6017 descriptor_write.descriptorCount = 1;
6018 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6019 descriptor_write.pBufferInfo = &buffInfo;
6020
6021 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6022
6023 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006024 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6025 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006026 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006027 uint32_t pDynOff[2] = {512, 756};
6028 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6030 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6031 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6032 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006033 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006034 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
6036 "offset 0 and range 1024 that "
6037 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006038 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006039 char const *vsSource = "#version 450\n"
6040 "\n"
6041 "out gl_PerVertex { \n"
6042 " vec4 gl_Position;\n"
6043 "};\n"
6044 "void main(){\n"
6045 " gl_Position = vec4(1);\n"
6046 "}\n";
6047 char const *fsSource = "#version 450\n"
6048 "\n"
6049 "layout(location=0) out vec4 x;\n"
6050 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6051 "void main(){\n"
6052 " x = vec4(bar.y);\n"
6053 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006054 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6055 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6056 VkPipelineObj pipe(m_device);
6057 pipe.AddShader(&vs);
6058 pipe.AddShader(&fs);
6059 pipe.AddColorAttachment();
6060 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6061
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006062 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006063 // This update should succeed, but offset size of 512 will overstep buffer
6064 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006065 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6066 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006067 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006068 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006069
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006070 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006071 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006072
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006073 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006074 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006075 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6076}
6077
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006078TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6079 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6080 "that doesn't have memory bound");
6081 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006083 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6085 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006086
6087 ASSERT_NO_FATAL_FAILURE(InitState());
6088 ASSERT_NO_FATAL_FAILURE(InitViewport());
6089 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6090
6091 VkDescriptorPoolSize ds_type_count = {};
6092 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6093 ds_type_count.descriptorCount = 1;
6094
6095 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6096 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6097 ds_pool_ci.pNext = NULL;
6098 ds_pool_ci.maxSets = 1;
6099 ds_pool_ci.poolSizeCount = 1;
6100 ds_pool_ci.pPoolSizes = &ds_type_count;
6101
6102 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006103 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006104 ASSERT_VK_SUCCESS(err);
6105
6106 VkDescriptorSetLayoutBinding dsl_binding = {};
6107 dsl_binding.binding = 0;
6108 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6109 dsl_binding.descriptorCount = 1;
6110 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6111 dsl_binding.pImmutableSamplers = NULL;
6112
6113 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6114 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6115 ds_layout_ci.pNext = NULL;
6116 ds_layout_ci.bindingCount = 1;
6117 ds_layout_ci.pBindings = &dsl_binding;
6118 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006119 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006120 ASSERT_VK_SUCCESS(err);
6121
6122 VkDescriptorSet descriptorSet;
6123 VkDescriptorSetAllocateInfo alloc_info = {};
6124 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6125 alloc_info.descriptorSetCount = 1;
6126 alloc_info.descriptorPool = ds_pool;
6127 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006128 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006129 ASSERT_VK_SUCCESS(err);
6130
6131 // Create a buffer to update the descriptor with
6132 uint32_t qfi = 0;
6133 VkBufferCreateInfo buffCI = {};
6134 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6135 buffCI.size = 1024;
6136 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6137 buffCI.queueFamilyIndexCount = 1;
6138 buffCI.pQueueFamilyIndices = &qfi;
6139
6140 VkBuffer dyub;
6141 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6142 ASSERT_VK_SUCCESS(err);
6143
6144 // Attempt to update descriptor without binding memory to it
6145 VkDescriptorBufferInfo buffInfo = {};
6146 buffInfo.buffer = dyub;
6147 buffInfo.offset = 0;
6148 buffInfo.range = 1024;
6149
6150 VkWriteDescriptorSet descriptor_write;
6151 memset(&descriptor_write, 0, sizeof(descriptor_write));
6152 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6153 descriptor_write.dstSet = descriptorSet;
6154 descriptor_write.dstBinding = 0;
6155 descriptor_write.descriptorCount = 1;
6156 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6157 descriptor_write.pBufferInfo = &buffInfo;
6158
6159 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6160 m_errorMonitor->VerifyFound();
6161
6162 vkDestroyBuffer(m_device->device(), dyub, NULL);
6163 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6164 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6165}
6166
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006167TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006168 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006169 ASSERT_NO_FATAL_FAILURE(InitState());
6170 ASSERT_NO_FATAL_FAILURE(InitViewport());
6171 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6172
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006173 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006174 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006175 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6176 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6177 pipeline_layout_ci.pushConstantRangeCount = 1;
6178 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6179
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006180 //
6181 // Check for invalid push constant ranges in pipeline layouts.
6182 //
6183 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006184 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006185 char const *msg;
6186 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006187
Karl Schultzc81037d2016-05-12 08:11:23 -06006188 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6189 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6190 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6191 "vkCreatePipelineLayout() call has push constants index 0 with "
6192 "size 0."},
6193 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6194 "vkCreatePipelineLayout() call has push constants index 0 with "
6195 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006196 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006197 "vkCreatePipelineLayout() call has push constants index 0 with "
6198 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006199 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006200 "vkCreatePipelineLayout() call has push constants index 0 with "
6201 "size 0."},
6202 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6203 "vkCreatePipelineLayout() call has push constants index 0 with "
6204 "offset 1. Offset must"},
6205 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6206 "vkCreatePipelineLayout() call has push constants index 0 "
6207 "with offset "},
6208 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6209 "vkCreatePipelineLayout() call has push constants "
6210 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006211 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006212 "vkCreatePipelineLayout() call has push constants index 0 "
6213 "with offset "},
6214 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6215 "vkCreatePipelineLayout() call has push "
6216 "constants index 0 with offset "},
6217 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6218 "vkCreatePipelineLayout() call has push "
6219 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006220 }};
6221
6222 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006223 for (const auto &iter : range_tests) {
6224 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6226 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006227 m_errorMonitor->VerifyFound();
6228 if (VK_SUCCESS == err) {
6229 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6230 }
6231 }
6232
6233 // Check for invalid stage flag
6234 pc_range.offset = 0;
6235 pc_range.size = 16;
6236 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006237 m_errorMonitor->SetDesiredFailureMsg(
6238 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6239 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006240 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006241 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006242 if (VK_SUCCESS == err) {
6243 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6244 }
6245
6246 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006247 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006248 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006249 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006250 char const *msg;
6251 };
6252
Karl Schultzc81037d2016-05-12 08:11:23 -06006253 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006254 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6255 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6256 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6257 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6258 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006259 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006260 {
6261 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6262 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6263 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6264 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6265 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006266 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006267 },
6268 {
6269 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6270 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6271 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6272 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6273 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006274 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006275 },
6276 {
6277 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6278 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6279 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6280 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6281 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006282 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006283 },
6284 {
6285 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6286 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6287 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6288 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6289 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006290 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006291 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006292
Karl Schultzc81037d2016-05-12 08:11:23 -06006293 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006294 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006295 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6297 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006298 m_errorMonitor->VerifyFound();
6299 if (VK_SUCCESS == err) {
6300 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6301 }
6302 }
6303
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006304 //
6305 // CmdPushConstants tests
6306 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006307 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006308
6309 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006310 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6311 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006312 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6313 "vkCmdPushConstants() call has push constants with size 1. Size "
6314 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006315 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006316 "vkCmdPushConstants() call has push constants with size 1. Size "
6317 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006318 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006319 "vkCmdPushConstants() call has push constants with offset 1. "
6320 "Offset must be a multiple of 4."},
6321 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6322 "vkCmdPushConstants() call has push constants with offset 1. "
6323 "Offset must be a multiple of 4."},
6324 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6325 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6326 "0x1 not within flag-matching ranges in pipeline layout"},
6327 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6328 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6329 "0x1 not within flag-matching ranges in pipeline layout"},
6330 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6331 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6332 "0x1 not within flag-matching ranges in pipeline layout"},
6333 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6334 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6335 "0x1 not within flag-matching ranges in pipeline layout"},
6336 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6337 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6338 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006339 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006340 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6341 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006342 }};
6343
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006344 BeginCommandBuffer();
6345
6346 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006347 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006348 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006349 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006350 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006351 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006352 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006353 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006354 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6356 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006357 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006358 m_errorMonitor->VerifyFound();
6359 }
6360
6361 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006363 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006364 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006365 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006366
Karl Schultzc81037d2016-05-12 08:11:23 -06006367 // overlapping range tests with cmd
6368 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6369 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6370 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6371 "0x1 not within flag-matching ranges in pipeline layout"},
6372 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6373 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6374 "0x1 not within flag-matching ranges in pipeline layout"},
6375 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6376 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6377 "0x1 not within flag-matching ranges in pipeline layout"},
6378 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006379 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006380 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006381 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6382 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006383 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006384 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006385 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006386 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006387 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006388 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6390 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006391 iter.range.size, dummy_values);
6392 m_errorMonitor->VerifyFound();
6393 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006394 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6395
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006396 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006397}
6398
Karl Schultz6addd812016-02-02 17:17:23 -07006399TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006400 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006401 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006402
6403 ASSERT_NO_FATAL_FAILURE(InitState());
6404 ASSERT_NO_FATAL_FAILURE(InitViewport());
6405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6406
Mike Stroyanb8a61002016-06-20 16:00:28 -06006407 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6408 VkImageTiling tiling;
6409 VkFormatProperties format_properties;
6410 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006411 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006412 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006413 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006414 tiling = VK_IMAGE_TILING_OPTIMAL;
6415 } else {
6416 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6417 "skipped.\n");
6418 return;
6419 }
6420
Tobin Ehlis559c6382015-11-05 09:52:49 -07006421 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6422 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006423 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6424 ds_type_count[0].descriptorCount = 10;
6425 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6426 ds_type_count[1].descriptorCount = 2;
6427 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6428 ds_type_count[2].descriptorCount = 2;
6429 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6430 ds_type_count[3].descriptorCount = 5;
6431 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6432 // type
6433 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6434 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6435 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006436
6437 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006438 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6439 ds_pool_ci.pNext = NULL;
6440 ds_pool_ci.maxSets = 5;
6441 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6442 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006443
6444 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006445 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006446 ASSERT_VK_SUCCESS(err);
6447
6448 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6449 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006450 dsl_binding[0].binding = 0;
6451 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6452 dsl_binding[0].descriptorCount = 5;
6453 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6454 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006455
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006456 // Create layout identical to set0 layout but w/ different stageFlags
6457 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006458 dsl_fs_stage_only.binding = 0;
6459 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6460 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006461 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6462 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006463 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006464 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006465 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6466 ds_layout_ci.pNext = NULL;
6467 ds_layout_ci.bindingCount = 1;
6468 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006469 static const uint32_t NUM_LAYOUTS = 4;
6470 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006471 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006472 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6473 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006474 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006475 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006476 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006477 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006478 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006479 dsl_binding[0].binding = 0;
6480 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006481 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006482 dsl_binding[1].binding = 1;
6483 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6484 dsl_binding[1].descriptorCount = 2;
6485 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6486 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006487 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006488 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006489 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006490 ASSERT_VK_SUCCESS(err);
6491 dsl_binding[0].binding = 0;
6492 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006493 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006494 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006495 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006496 ASSERT_VK_SUCCESS(err);
6497 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006498 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006499 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006500 ASSERT_VK_SUCCESS(err);
6501
6502 static const uint32_t NUM_SETS = 4;
6503 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6504 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006505 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006506 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006507 alloc_info.descriptorPool = ds_pool;
6508 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006509 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006510 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006511 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006512 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006513 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006514 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006515 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006516
6517 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006518 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6519 pipeline_layout_ci.pNext = NULL;
6520 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6521 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006522
6523 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006524 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006525 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006526 // Create pipelineLayout with only one setLayout
6527 pipeline_layout_ci.setLayoutCount = 1;
6528 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006529 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006530 ASSERT_VK_SUCCESS(err);
6531 // Create pipelineLayout with 2 descriptor setLayout at index 0
6532 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6533 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006534 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006535 ASSERT_VK_SUCCESS(err);
6536 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6537 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6538 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006539 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006540 ASSERT_VK_SUCCESS(err);
6541 // Create pipelineLayout with UB type, but stageFlags for FS only
6542 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6543 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006544 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006545 ASSERT_VK_SUCCESS(err);
6546 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6547 VkDescriptorSetLayout pl_bad_s0[2] = {};
6548 pl_bad_s0[0] = ds_layout_fs_only;
6549 pl_bad_s0[1] = ds_layout[1];
6550 pipeline_layout_ci.setLayoutCount = 2;
6551 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6552 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006553 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006554 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006555
6556 // Create a buffer to update the descriptor with
6557 uint32_t qfi = 0;
6558 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006559 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6560 buffCI.size = 1024;
6561 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6562 buffCI.queueFamilyIndexCount = 1;
6563 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006564
6565 VkBuffer dyub;
6566 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6567 ASSERT_VK_SUCCESS(err);
6568 // Correctly update descriptor to avoid "NOT_UPDATED" error
6569 static const uint32_t NUM_BUFFS = 5;
6570 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006571 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006572 buffInfo[i].buffer = dyub;
6573 buffInfo[i].offset = 0;
6574 buffInfo[i].range = 1024;
6575 }
Karl Schultz6addd812016-02-02 17:17:23 -07006576 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006577 const int32_t tex_width = 32;
6578 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006579 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006580 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6581 image_create_info.pNext = NULL;
6582 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6583 image_create_info.format = tex_format;
6584 image_create_info.extent.width = tex_width;
6585 image_create_info.extent.height = tex_height;
6586 image_create_info.extent.depth = 1;
6587 image_create_info.mipLevels = 1;
6588 image_create_info.arrayLayers = 1;
6589 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006590 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006591 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006592 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006593 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6594 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006595
Karl Schultz6addd812016-02-02 17:17:23 -07006596 VkMemoryRequirements memReqs;
6597 VkDeviceMemory imageMem;
6598 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006599 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006600 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6601 memAlloc.pNext = NULL;
6602 memAlloc.allocationSize = 0;
6603 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006604 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6605 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006606 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006607 ASSERT_TRUE(pass);
6608 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6609 ASSERT_VK_SUCCESS(err);
6610 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6611 ASSERT_VK_SUCCESS(err);
6612
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006613 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006614 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6615 image_view_create_info.image = image;
6616 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6617 image_view_create_info.format = tex_format;
6618 image_view_create_info.subresourceRange.layerCount = 1;
6619 image_view_create_info.subresourceRange.baseMipLevel = 0;
6620 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006621 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006622
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006623 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006624 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006625 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006626 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006627 imageInfo[0].imageView = view;
6628 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6629 imageInfo[1].imageView = view;
6630 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006631 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006632 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006633 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006634 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006635
6636 static const uint32_t NUM_SET_UPDATES = 3;
6637 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6638 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6639 descriptor_write[0].dstSet = descriptorSet[0];
6640 descriptor_write[0].dstBinding = 0;
6641 descriptor_write[0].descriptorCount = 5;
6642 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6643 descriptor_write[0].pBufferInfo = buffInfo;
6644 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6645 descriptor_write[1].dstSet = descriptorSet[1];
6646 descriptor_write[1].dstBinding = 0;
6647 descriptor_write[1].descriptorCount = 2;
6648 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6649 descriptor_write[1].pImageInfo = imageInfo;
6650 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6651 descriptor_write[2].dstSet = descriptorSet[1];
6652 descriptor_write[2].dstBinding = 1;
6653 descriptor_write[2].descriptorCount = 2;
6654 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006655 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006656
6657 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006658
Tobin Ehlis88452832015-12-03 09:40:56 -07006659 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006660 char const *vsSource = "#version 450\n"
6661 "\n"
6662 "out gl_PerVertex {\n"
6663 " vec4 gl_Position;\n"
6664 "};\n"
6665 "void main(){\n"
6666 " gl_Position = vec4(1);\n"
6667 "}\n";
6668 char const *fsSource = "#version 450\n"
6669 "\n"
6670 "layout(location=0) out vec4 x;\n"
6671 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6672 "void main(){\n"
6673 " x = vec4(bar.y);\n"
6674 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006675 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6676 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006677 VkPipelineObj pipe(m_device);
6678 pipe.AddShader(&vs);
6679 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006680 pipe.AddColorAttachment();
6681 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006682
6683 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006684
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006685 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006686 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6687 // of PSO
6688 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6689 // cmd_pipeline.c
6690 // due to the fact that cmd_alloc_dset_data() has not been called in
6691 // cmd_bind_graphics_pipeline()
6692 // TODO : Want to cause various binding incompatibility issues here to test
6693 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006694 // First cause various verify_layout_compatibility() fails
6695 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006696 // verify_set_layout_compatibility fail cases:
6697 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006699 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6700 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006701 m_errorMonitor->VerifyFound();
6702
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006703 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6705 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6706 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006707 m_errorMonitor->VerifyFound();
6708
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006709 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006710 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6711 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6713 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6714 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006715 m_errorMonitor->VerifyFound();
6716
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006717 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6718 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6720 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6721 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006722 m_errorMonitor->VerifyFound();
6723
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006724 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6725 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6727 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6728 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6729 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006730 m_errorMonitor->VerifyFound();
6731
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006732 // Cause INFO messages due to disturbing previously bound Sets
6733 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006734 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6735 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006736 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6738 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6739 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006740 m_errorMonitor->VerifyFound();
6741
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006742 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6743 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006744 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6746 "any subsequent sets were disturbed ");
6747 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6748 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006749 m_errorMonitor->VerifyFound();
6750
Tobin Ehlis10fad692016-07-07 12:00:36 -06006751 // Now that we're done actively using the pipelineLayout that gfx pipeline
6752 // was created with, we should be able to delete it. Do that now to verify
6753 // that validation obeys pipelineLayout lifetime
6754 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6755
Tobin Ehlis88452832015-12-03 09:40:56 -07006756 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006757 // 1. Error due to not binding required set (we actually use same code as
6758 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006759 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6760 &descriptorSet[0], 0, NULL);
6761 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6762 &descriptorSet[1], 0, NULL);
6763 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 -07006764 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006765 m_errorMonitor->VerifyFound();
6766
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006767 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006768 // 2. Error due to bound set not being compatible with PSO's
6769 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006770 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6771 &descriptorSet[0], 0, NULL);
6772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006773 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006774 m_errorMonitor->VerifyFound();
6775
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006776 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006777 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006778 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6779 }
6780 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006781 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006782 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6783 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006784 vkFreeMemory(m_device->device(), imageMem, NULL);
6785 vkDestroyImage(m_device->device(), image, NULL);
6786 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006787}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006788
Karl Schultz6addd812016-02-02 17:17:23 -07006789TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006790
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6792 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006793
6794 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006795 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006796 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006797 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006798
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006799 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006800}
6801
Karl Schultz6addd812016-02-02 17:17:23 -07006802TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6803 VkResult err;
6804 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006805
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006807
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006808 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006809
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006810 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006811 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006812 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006813 cmd.commandPool = m_commandPool;
6814 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006815 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006816
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006817 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006818 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006819
6820 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006821 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006822 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006823 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006824 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006825 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 -07006826 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006827
6828 // The error should be caught by validation of the BeginCommandBuffer call
6829 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6830
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006831 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006832 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006833}
6834
Karl Schultz6addd812016-02-02 17:17:23 -07006835TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006836 // Cause error due to Begin while recording CB
6837 // Then cause 2 errors for attempting to reset CB w/o having
6838 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6839 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006841
6842 ASSERT_NO_FATAL_FAILURE(InitState());
6843
6844 // Calls AllocateCommandBuffers
6845 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6846
Karl Schultz6addd812016-02-02 17:17:23 -07006847 // Force the failure by setting the Renderpass and Framebuffer fields with
6848 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006849 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006850 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006851 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6852 cmd_buf_info.pNext = NULL;
6853 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006854 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006855
6856 // Begin CB to transition to recording state
6857 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6858 // Can't re-begin. This should trigger error
6859 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006860 m_errorMonitor->VerifyFound();
6861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006863 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6864 // Reset attempt will trigger error due to incorrect CommandPool state
6865 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006866 m_errorMonitor->VerifyFound();
6867
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006869 // Transition CB to RECORDED state
6870 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6871 // Now attempting to Begin will implicitly reset, which triggers error
6872 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006873 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006874}
6875
Karl Schultz6addd812016-02-02 17:17:23 -07006876TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006877 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006878 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006879
Mike Weiblencce7ec72016-10-17 19:33:05 -06006880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006881
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006882 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006883 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006884
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006885 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006886 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6887 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006888
6889 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006890 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6891 ds_pool_ci.pNext = NULL;
6892 ds_pool_ci.maxSets = 1;
6893 ds_pool_ci.poolSizeCount = 1;
6894 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006895
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006896 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006897 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006898 ASSERT_VK_SUCCESS(err);
6899
Tony Barboureb254902015-07-15 12:50:33 -06006900 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006901 dsl_binding.binding = 0;
6902 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6903 dsl_binding.descriptorCount = 1;
6904 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6905 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006906
Tony Barboureb254902015-07-15 12:50:33 -06006907 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006908 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6909 ds_layout_ci.pNext = NULL;
6910 ds_layout_ci.bindingCount = 1;
6911 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006912
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006913 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006914 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006915 ASSERT_VK_SUCCESS(err);
6916
6917 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006918 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006919 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006920 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006921 alloc_info.descriptorPool = ds_pool;
6922 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006923 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006924 ASSERT_VK_SUCCESS(err);
6925
Tony Barboureb254902015-07-15 12:50:33 -06006926 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006927 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6928 pipeline_layout_ci.setLayoutCount = 1;
6929 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006930
6931 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006932 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006933 ASSERT_VK_SUCCESS(err);
6934
Tobin Ehlise68360f2015-10-01 11:15:13 -06006935 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006936 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006937
6938 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006939 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6940 vp_state_ci.scissorCount = 1;
6941 vp_state_ci.pScissors = &sc;
6942 vp_state_ci.viewportCount = 1;
6943 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006944
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006945 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6946 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6947 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6948 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6949 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6950 rs_state_ci.depthClampEnable = VK_FALSE;
6951 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6952 rs_state_ci.depthBiasEnable = VK_FALSE;
6953
Tony Barboureb254902015-07-15 12:50:33 -06006954 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006955 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6956 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006957 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006958 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6959 gp_ci.layout = pipeline_layout;
6960 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006961
6962 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006963 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6964 pc_ci.initialDataSize = 0;
6965 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006966
6967 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006968 VkPipelineCache pipelineCache;
6969
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006970 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006971 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006972 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006973
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006974 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006975
Chia-I Wuf7458c52015-10-26 21:10:41 +08006976 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6977 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6978 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6979 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006980}
Tobin Ehlis912df022015-09-17 08:46:18 -06006981/*// TODO : This test should be good, but needs Tess support in compiler to run
6982TEST_F(VkLayerTest, InvalidPatchControlPoints)
6983{
6984 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006985 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006986
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006988 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6989primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006990
Tobin Ehlis912df022015-09-17 08:46:18 -06006991 ASSERT_NO_FATAL_FAILURE(InitState());
6992 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006993
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006994 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006995 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006996 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006997
6998 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6999 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7000 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007001 ds_pool_ci.poolSizeCount = 1;
7002 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007003
7004 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007005 err = vkCreateDescriptorPool(m_device->device(),
7006VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007007 ASSERT_VK_SUCCESS(err);
7008
7009 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007010 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007011 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007012 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007013 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7014 dsl_binding.pImmutableSamplers = NULL;
7015
7016 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007017 ds_layout_ci.sType =
7018VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007019 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007020 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007021 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007022
7023 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007024 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7025&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007026 ASSERT_VK_SUCCESS(err);
7027
7028 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007029 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7030VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007031 ASSERT_VK_SUCCESS(err);
7032
7033 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007034 pipeline_layout_ci.sType =
7035VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007036 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007037 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007038 pipeline_layout_ci.pSetLayouts = &ds_layout;
7039
7040 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007041 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7042&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007043 ASSERT_VK_SUCCESS(err);
7044
7045 VkPipelineShaderStageCreateInfo shaderStages[3];
7046 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7047
Karl Schultz6addd812016-02-02 17:17:23 -07007048 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7049this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007050 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007051 VkShaderObj
7052tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7053this);
7054 VkShaderObj
7055te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7056this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007057
Karl Schultz6addd812016-02-02 17:17:23 -07007058 shaderStages[0].sType =
7059VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007060 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007061 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007062 shaderStages[1].sType =
7063VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007064 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007065 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007066 shaderStages[2].sType =
7067VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007068 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007069 shaderStages[2].shader = te.handle();
7070
7071 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007072 iaCI.sType =
7073VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007074 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007075
7076 VkPipelineTessellationStateCreateInfo tsCI = {};
7077 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7078 tsCI.patchControlPoints = 0; // This will cause an error
7079
7080 VkGraphicsPipelineCreateInfo gp_ci = {};
7081 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7082 gp_ci.pNext = NULL;
7083 gp_ci.stageCount = 3;
7084 gp_ci.pStages = shaderStages;
7085 gp_ci.pVertexInputState = NULL;
7086 gp_ci.pInputAssemblyState = &iaCI;
7087 gp_ci.pTessellationState = &tsCI;
7088 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007089 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007090 gp_ci.pMultisampleState = NULL;
7091 gp_ci.pDepthStencilState = NULL;
7092 gp_ci.pColorBlendState = NULL;
7093 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7094 gp_ci.layout = pipeline_layout;
7095 gp_ci.renderPass = renderPass();
7096
7097 VkPipelineCacheCreateInfo pc_ci = {};
7098 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7099 pc_ci.pNext = NULL;
7100 pc_ci.initialSize = 0;
7101 pc_ci.initialData = 0;
7102 pc_ci.maxSize = 0;
7103
7104 VkPipeline pipeline;
7105 VkPipelineCache pipelineCache;
7106
Karl Schultz6addd812016-02-02 17:17:23 -07007107 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7108&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007109 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007110 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7111&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007112
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007113 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007114
Chia-I Wuf7458c52015-10-26 21:10:41 +08007115 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7116 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7117 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7118 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007119}
7120*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06007121// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07007122TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007123 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007124
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7126 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007127
Tobin Ehlise68360f2015-10-01 11:15:13 -06007128 ASSERT_NO_FATAL_FAILURE(InitState());
7129 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007130
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007131 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007132 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7133 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007134
7135 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007136 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7137 ds_pool_ci.maxSets = 1;
7138 ds_pool_ci.poolSizeCount = 1;
7139 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007140
7141 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007142 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007143 ASSERT_VK_SUCCESS(err);
7144
7145 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007146 dsl_binding.binding = 0;
7147 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7148 dsl_binding.descriptorCount = 1;
7149 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007150
7151 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007152 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7153 ds_layout_ci.bindingCount = 1;
7154 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007155
7156 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007157 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007158 ASSERT_VK_SUCCESS(err);
7159
7160 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007161 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007162 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007163 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007164 alloc_info.descriptorPool = ds_pool;
7165 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007166 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007167 ASSERT_VK_SUCCESS(err);
7168
7169 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007170 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7171 pipeline_layout_ci.setLayoutCount = 1;
7172 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007173
7174 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007175 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007176 ASSERT_VK_SUCCESS(err);
7177
7178 VkViewport vp = {}; // Just need dummy vp to point to
7179
7180 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007181 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7182 vp_state_ci.scissorCount = 0;
7183 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7184 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007185
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007186 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7187 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7188 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7189 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7190 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7191 rs_state_ci.depthClampEnable = VK_FALSE;
7192 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7193 rs_state_ci.depthBiasEnable = VK_FALSE;
7194
Cody Northropeb3a6c12015-10-05 14:44:45 -06007195 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007196 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007197
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007198 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7199 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7200 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007201 shaderStages[0] = vs.GetStageCreateInfo();
7202 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007203
7204 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007205 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7206 gp_ci.stageCount = 2;
7207 gp_ci.pStages = shaderStages;
7208 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007209 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007210 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7211 gp_ci.layout = pipeline_layout;
7212 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007213
7214 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007215 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007216
7217 VkPipeline pipeline;
7218 VkPipelineCache pipelineCache;
7219
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007220 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007221 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007222 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007223
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007224 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007225
Chia-I Wuf7458c52015-10-26 21:10:41 +08007226 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7227 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7228 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7229 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007230}
Karl Schultz6addd812016-02-02 17:17:23 -07007231// Don't set viewport state in PSO. This is an error b/c we always need this
7232// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007233// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007234TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007235 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007236 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007237
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007239
Tobin Ehlise68360f2015-10-01 11:15:13 -06007240 ASSERT_NO_FATAL_FAILURE(InitState());
7241 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007242
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007243 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007244 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7245 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007246
7247 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007248 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7249 ds_pool_ci.maxSets = 1;
7250 ds_pool_ci.poolSizeCount = 1;
7251 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007252
7253 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007254 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007255 ASSERT_VK_SUCCESS(err);
7256
7257 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007258 dsl_binding.binding = 0;
7259 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7260 dsl_binding.descriptorCount = 1;
7261 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007262
7263 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007264 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7265 ds_layout_ci.bindingCount = 1;
7266 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007267
7268 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007269 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007270 ASSERT_VK_SUCCESS(err);
7271
7272 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007273 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007274 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007275 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007276 alloc_info.descriptorPool = ds_pool;
7277 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007278 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007279 ASSERT_VK_SUCCESS(err);
7280
7281 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007282 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7283 pipeline_layout_ci.setLayoutCount = 1;
7284 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007285
7286 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007287 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007288 ASSERT_VK_SUCCESS(err);
7289
7290 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7291 // Set scissor as dynamic to avoid second error
7292 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007293 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7294 dyn_state_ci.dynamicStateCount = 1;
7295 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007296
Cody Northropeb3a6c12015-10-05 14:44:45 -06007297 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007298 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007299
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007300 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7301 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7302 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007303 shaderStages[0] = vs.GetStageCreateInfo();
7304 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007305
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007306 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7307 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7308 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7309 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7310 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7311 rs_state_ci.depthClampEnable = VK_FALSE;
7312 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7313 rs_state_ci.depthBiasEnable = VK_FALSE;
7314
Tobin Ehlise68360f2015-10-01 11:15:13 -06007315 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007316 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7317 gp_ci.stageCount = 2;
7318 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007319 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007320 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7321 // should cause validation error
7322 gp_ci.pDynamicState = &dyn_state_ci;
7323 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7324 gp_ci.layout = pipeline_layout;
7325 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007326
7327 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007328 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007329
7330 VkPipeline pipeline;
7331 VkPipelineCache pipelineCache;
7332
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007333 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007334 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007335 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007336
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007337 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007338
Chia-I Wuf7458c52015-10-26 21:10:41 +08007339 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7340 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7341 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7342 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007343}
7344// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007345// Then run second test where dynamic scissor count doesn't match PSO scissor
7346// count
7347TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7348 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007349
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7351 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007352
Tobin Ehlise68360f2015-10-01 11:15:13 -06007353 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007354
7355 if (!m_device->phy().features().multiViewport) {
7356 printf("Device does not support multiple viewports/scissors; skipped.\n");
7357 return;
7358 }
7359
Tobin Ehlise68360f2015-10-01 11:15:13 -06007360 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007361
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007362 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007363 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7364 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007365
7366 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007367 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7368 ds_pool_ci.maxSets = 1;
7369 ds_pool_ci.poolSizeCount = 1;
7370 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007371
7372 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007373 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007374 ASSERT_VK_SUCCESS(err);
7375
7376 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007377 dsl_binding.binding = 0;
7378 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7379 dsl_binding.descriptorCount = 1;
7380 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007381
7382 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007383 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7384 ds_layout_ci.bindingCount = 1;
7385 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007386
7387 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007388 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007389 ASSERT_VK_SUCCESS(err);
7390
7391 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007392 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007393 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007394 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007395 alloc_info.descriptorPool = ds_pool;
7396 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007397 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007398 ASSERT_VK_SUCCESS(err);
7399
7400 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007401 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7402 pipeline_layout_ci.setLayoutCount = 1;
7403 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007404
7405 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007406 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007407 ASSERT_VK_SUCCESS(err);
7408
7409 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007410 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7411 vp_state_ci.viewportCount = 1;
7412 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7413 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007414 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007415
7416 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7417 // Set scissor as dynamic to avoid that error
7418 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007419 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7420 dyn_state_ci.dynamicStateCount = 1;
7421 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007422
Cody Northropeb3a6c12015-10-05 14:44:45 -06007423 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007424 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007425
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007426 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7427 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7428 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007429 shaderStages[0] = vs.GetStageCreateInfo();
7430 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007431
Cody Northropf6622dc2015-10-06 10:33:21 -06007432 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7433 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7434 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007435 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007436 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007437 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007438 vi_ci.pVertexAttributeDescriptions = nullptr;
7439
7440 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7441 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7442 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7443
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007444 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007445 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007446 rs_ci.pNext = nullptr;
7447
Mark Youngc89c6312016-03-31 16:03:20 -06007448 VkPipelineColorBlendAttachmentState att = {};
7449 att.blendEnable = VK_FALSE;
7450 att.colorWriteMask = 0xf;
7451
Cody Northropf6622dc2015-10-06 10:33:21 -06007452 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7453 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7454 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007455 cb_ci.attachmentCount = 1;
7456 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007457
Tobin Ehlise68360f2015-10-01 11:15:13 -06007458 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007459 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7460 gp_ci.stageCount = 2;
7461 gp_ci.pStages = shaderStages;
7462 gp_ci.pVertexInputState = &vi_ci;
7463 gp_ci.pInputAssemblyState = &ia_ci;
7464 gp_ci.pViewportState = &vp_state_ci;
7465 gp_ci.pRasterizationState = &rs_ci;
7466 gp_ci.pColorBlendState = &cb_ci;
7467 gp_ci.pDynamicState = &dyn_state_ci;
7468 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7469 gp_ci.layout = pipeline_layout;
7470 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007471
7472 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007473 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007474
7475 VkPipeline pipeline;
7476 VkPipelineCache pipelineCache;
7477
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007478 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007479 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007480 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007481
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007482 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007483
Tobin Ehlisd332f282015-10-02 11:00:56 -06007484 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007485 // First need to successfully create the PSO from above by setting
7486 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007487 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 -07007488
7489 VkViewport vp = {}; // Just need dummy vp to point to
7490 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007491 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007492 ASSERT_VK_SUCCESS(err);
7493 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007494 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007495 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007496 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007497 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007498 Draw(1, 0, 0, 0);
7499
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007500 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007501
7502 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7503 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7504 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7505 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007506 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007507}
7508// Create PSO w/o non-zero scissorCount but no scissor data
7509// Then run second test where dynamic viewportCount doesn't match PSO
7510// viewportCount
7511TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7512 VkResult err;
7513
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007514 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 -07007515
7516 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007517
7518 if (!m_device->phy().features().multiViewport) {
7519 printf("Device does not support multiple viewports/scissors; skipped.\n");
7520 return;
7521 }
7522
Karl Schultz6addd812016-02-02 17:17:23 -07007523 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7524
7525 VkDescriptorPoolSize ds_type_count = {};
7526 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7527 ds_type_count.descriptorCount = 1;
7528
7529 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7530 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7531 ds_pool_ci.maxSets = 1;
7532 ds_pool_ci.poolSizeCount = 1;
7533 ds_pool_ci.pPoolSizes = &ds_type_count;
7534
7535 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007536 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007537 ASSERT_VK_SUCCESS(err);
7538
7539 VkDescriptorSetLayoutBinding dsl_binding = {};
7540 dsl_binding.binding = 0;
7541 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7542 dsl_binding.descriptorCount = 1;
7543 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7544
7545 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7546 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7547 ds_layout_ci.bindingCount = 1;
7548 ds_layout_ci.pBindings = &dsl_binding;
7549
7550 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007551 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007552 ASSERT_VK_SUCCESS(err);
7553
7554 VkDescriptorSet descriptorSet;
7555 VkDescriptorSetAllocateInfo alloc_info = {};
7556 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7557 alloc_info.descriptorSetCount = 1;
7558 alloc_info.descriptorPool = ds_pool;
7559 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007560 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007561 ASSERT_VK_SUCCESS(err);
7562
7563 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7564 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7565 pipeline_layout_ci.setLayoutCount = 1;
7566 pipeline_layout_ci.pSetLayouts = &ds_layout;
7567
7568 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007569 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007570 ASSERT_VK_SUCCESS(err);
7571
7572 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7573 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7574 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007575 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007576 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007577 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007578
7579 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7580 // Set scissor as dynamic to avoid that error
7581 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7582 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7583 dyn_state_ci.dynamicStateCount = 1;
7584 dyn_state_ci.pDynamicStates = &vp_state;
7585
7586 VkPipelineShaderStageCreateInfo shaderStages[2];
7587 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7588
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007589 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7590 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7591 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007592 shaderStages[0] = vs.GetStageCreateInfo();
7593 shaderStages[1] = fs.GetStageCreateInfo();
7594
7595 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7596 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7597 vi_ci.pNext = nullptr;
7598 vi_ci.vertexBindingDescriptionCount = 0;
7599 vi_ci.pVertexBindingDescriptions = nullptr;
7600 vi_ci.vertexAttributeDescriptionCount = 0;
7601 vi_ci.pVertexAttributeDescriptions = nullptr;
7602
7603 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7604 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7605 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7606
7607 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7608 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7609 rs_ci.pNext = nullptr;
7610
Mark Youngc89c6312016-03-31 16:03:20 -06007611 VkPipelineColorBlendAttachmentState att = {};
7612 att.blendEnable = VK_FALSE;
7613 att.colorWriteMask = 0xf;
7614
Karl Schultz6addd812016-02-02 17:17:23 -07007615 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7616 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7617 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007618 cb_ci.attachmentCount = 1;
7619 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007620
7621 VkGraphicsPipelineCreateInfo gp_ci = {};
7622 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7623 gp_ci.stageCount = 2;
7624 gp_ci.pStages = shaderStages;
7625 gp_ci.pVertexInputState = &vi_ci;
7626 gp_ci.pInputAssemblyState = &ia_ci;
7627 gp_ci.pViewportState = &vp_state_ci;
7628 gp_ci.pRasterizationState = &rs_ci;
7629 gp_ci.pColorBlendState = &cb_ci;
7630 gp_ci.pDynamicState = &dyn_state_ci;
7631 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7632 gp_ci.layout = pipeline_layout;
7633 gp_ci.renderPass = renderPass();
7634
7635 VkPipelineCacheCreateInfo pc_ci = {};
7636 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7637
7638 VkPipeline pipeline;
7639 VkPipelineCache pipelineCache;
7640
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007641 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007642 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007643 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007644
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007645 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007646
7647 // Now hit second fail case where we set scissor w/ different count than PSO
7648 // First need to successfully create the PSO from above by setting
7649 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007650 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 -06007651
Tobin Ehlisd332f282015-10-02 11:00:56 -06007652 VkRect2D sc = {}; // Just need dummy vp to point to
7653 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007654 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007655 ASSERT_VK_SUCCESS(err);
7656 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007657 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007658 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007659 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007660 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007661 Draw(1, 0, 0, 0);
7662
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007663 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007664
Chia-I Wuf7458c52015-10-26 21:10:41 +08007665 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7666 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7667 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7668 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007669 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007670}
7671
Mark Young7394fdd2016-03-31 14:56:43 -06007672TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7673 VkResult err;
7674
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007676
7677 ASSERT_NO_FATAL_FAILURE(InitState());
7678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7679
7680 VkDescriptorPoolSize ds_type_count = {};
7681 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7682 ds_type_count.descriptorCount = 1;
7683
7684 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7685 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7686 ds_pool_ci.maxSets = 1;
7687 ds_pool_ci.poolSizeCount = 1;
7688 ds_pool_ci.pPoolSizes = &ds_type_count;
7689
7690 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007691 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007692 ASSERT_VK_SUCCESS(err);
7693
7694 VkDescriptorSetLayoutBinding dsl_binding = {};
7695 dsl_binding.binding = 0;
7696 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7697 dsl_binding.descriptorCount = 1;
7698 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7699
7700 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7701 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7702 ds_layout_ci.bindingCount = 1;
7703 ds_layout_ci.pBindings = &dsl_binding;
7704
7705 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007706 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007707 ASSERT_VK_SUCCESS(err);
7708
7709 VkDescriptorSet descriptorSet;
7710 VkDescriptorSetAllocateInfo alloc_info = {};
7711 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7712 alloc_info.descriptorSetCount = 1;
7713 alloc_info.descriptorPool = ds_pool;
7714 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007715 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007716 ASSERT_VK_SUCCESS(err);
7717
7718 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7719 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7720 pipeline_layout_ci.setLayoutCount = 1;
7721 pipeline_layout_ci.pSetLayouts = &ds_layout;
7722
7723 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007724 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007725 ASSERT_VK_SUCCESS(err);
7726
7727 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7728 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7729 vp_state_ci.scissorCount = 1;
7730 vp_state_ci.pScissors = NULL;
7731 vp_state_ci.viewportCount = 1;
7732 vp_state_ci.pViewports = NULL;
7733
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007734 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007735 // Set scissor as dynamic to avoid that error
7736 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7737 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7738 dyn_state_ci.dynamicStateCount = 2;
7739 dyn_state_ci.pDynamicStates = dynamic_states;
7740
7741 VkPipelineShaderStageCreateInfo shaderStages[2];
7742 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007744 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7745 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007746 this); // TODO - We shouldn't need a fragment shader
7747 // but add it to be able to run on more devices
7748 shaderStages[0] = vs.GetStageCreateInfo();
7749 shaderStages[1] = fs.GetStageCreateInfo();
7750
7751 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7752 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7753 vi_ci.pNext = nullptr;
7754 vi_ci.vertexBindingDescriptionCount = 0;
7755 vi_ci.pVertexBindingDescriptions = nullptr;
7756 vi_ci.vertexAttributeDescriptionCount = 0;
7757 vi_ci.pVertexAttributeDescriptions = nullptr;
7758
7759 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7760 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7761 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7762
7763 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7764 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7765 rs_ci.pNext = nullptr;
7766
Mark Young47107952016-05-02 15:59:55 -06007767 // Check too low (line width of -1.0f).
7768 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007769
7770 VkPipelineColorBlendAttachmentState att = {};
7771 att.blendEnable = VK_FALSE;
7772 att.colorWriteMask = 0xf;
7773
7774 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7775 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7776 cb_ci.pNext = nullptr;
7777 cb_ci.attachmentCount = 1;
7778 cb_ci.pAttachments = &att;
7779
7780 VkGraphicsPipelineCreateInfo gp_ci = {};
7781 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7782 gp_ci.stageCount = 2;
7783 gp_ci.pStages = shaderStages;
7784 gp_ci.pVertexInputState = &vi_ci;
7785 gp_ci.pInputAssemblyState = &ia_ci;
7786 gp_ci.pViewportState = &vp_state_ci;
7787 gp_ci.pRasterizationState = &rs_ci;
7788 gp_ci.pColorBlendState = &cb_ci;
7789 gp_ci.pDynamicState = &dyn_state_ci;
7790 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7791 gp_ci.layout = pipeline_layout;
7792 gp_ci.renderPass = renderPass();
7793
7794 VkPipelineCacheCreateInfo pc_ci = {};
7795 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7796
7797 VkPipeline pipeline;
7798 VkPipelineCache pipelineCache;
7799
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007800 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007801 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007802 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007803
7804 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007805 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007806
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007808
7809 // Check too high (line width of 65536.0f).
7810 rs_ci.lineWidth = 65536.0f;
7811
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007812 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007813 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007814 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007815
7816 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007817 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007818
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007820
7821 dyn_state_ci.dynamicStateCount = 3;
7822
7823 rs_ci.lineWidth = 1.0f;
7824
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007825 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007826 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007827 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007828 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007829 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007830
7831 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007832 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007833 m_errorMonitor->VerifyFound();
7834
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007836
7837 // Check too high with dynamic setting.
7838 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7839 m_errorMonitor->VerifyFound();
7840 EndCommandBuffer();
7841
7842 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7843 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7844 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7845 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007846 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007847}
7848
Karl Schultz6addd812016-02-02 17:17:23 -07007849TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007850 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7852 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007853
7854 ASSERT_NO_FATAL_FAILURE(InitState());
7855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007856
Tony Barbourfe3351b2015-07-28 10:17:20 -06007857 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007858 // Don't care about RenderPass handle b/c error should be flagged before
7859 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007860 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007861
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007862 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007863}
7864
Karl Schultz6addd812016-02-02 17:17:23 -07007865TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007866 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7868 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007869
7870 ASSERT_NO_FATAL_FAILURE(InitState());
7871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007872
Tony Barbourfe3351b2015-07-28 10:17:20 -06007873 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007874 // Just create a dummy Renderpass that's non-NULL so we can get to the
7875 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007876 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007877
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007878 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007879}
7880
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007881TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7882 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7883 "the number of renderPass attachments that use loadOp"
7884 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7885
7886 ASSERT_NO_FATAL_FAILURE(InitState());
7887 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7888
7889 // Create a renderPass with a single attachment that uses loadOp CLEAR
7890 VkAttachmentReference attach = {};
7891 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7892 VkSubpassDescription subpass = {};
7893 subpass.inputAttachmentCount = 1;
7894 subpass.pInputAttachments = &attach;
7895 VkRenderPassCreateInfo rpci = {};
7896 rpci.subpassCount = 1;
7897 rpci.pSubpasses = &subpass;
7898 rpci.attachmentCount = 1;
7899 VkAttachmentDescription attach_desc = {};
7900 attach_desc.format = VK_FORMAT_UNDEFINED;
7901 // Set loadOp to CLEAR
7902 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7903 rpci.pAttachments = &attach_desc;
7904 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7905 VkRenderPass rp;
7906 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7907
7908 VkCommandBufferInheritanceInfo hinfo = {};
7909 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7910 hinfo.renderPass = VK_NULL_HANDLE;
7911 hinfo.subpass = 0;
7912 hinfo.framebuffer = VK_NULL_HANDLE;
7913 hinfo.occlusionQueryEnable = VK_FALSE;
7914 hinfo.queryFlags = 0;
7915 hinfo.pipelineStatistics = 0;
7916 VkCommandBufferBeginInfo info = {};
7917 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7918 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7919 info.pInheritanceInfo = &hinfo;
7920
7921 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7922 VkRenderPassBeginInfo rp_begin = {};
7923 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7924 rp_begin.pNext = NULL;
7925 rp_begin.renderPass = renderPass();
7926 rp_begin.framebuffer = framebuffer();
7927 rp_begin.clearValueCount = 0; // Should be 1
7928
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7930 "there must be at least 1 entries in "
7931 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007933 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007934
7935 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007936
7937 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007938}
7939
Slawomir Cygan0808f392016-11-28 17:53:23 +01007940TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
7941 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is greater than"
7942 "the number of renderPass attachments that use loadOp"
7943 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7944
7945 ASSERT_NO_FATAL_FAILURE(InitState());
7946 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7947
7948 // Create a renderPass with a single attachment that uses loadOp CLEAR
7949 VkAttachmentReference attach = {};
7950 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7951 VkSubpassDescription subpass = {};
7952 subpass.inputAttachmentCount = 1;
7953 subpass.pInputAttachments = &attach;
7954 VkRenderPassCreateInfo rpci = {};
7955 rpci.subpassCount = 1;
7956 rpci.pSubpasses = &subpass;
7957 rpci.attachmentCount = 1;
7958 VkAttachmentDescription attach_desc = {};
7959 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
7960 // Set loadOp to CLEAR
7961 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7962 rpci.pAttachments = &attach_desc;
7963 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7964 VkRenderPass rp;
7965 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7966
7967 VkCommandBufferBeginInfo info = {};
7968 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7969 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7970
7971 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7972 VkRenderPassBeginInfo rp_begin = {};
7973 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7974 rp_begin.pNext = NULL;
7975 rp_begin.renderPass = renderPass();
7976 rp_begin.framebuffer = framebuffer();
7977 rp_begin.clearValueCount = 2; // Should be 1
7978
7979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " has a clearValueCount of"
7980 " 2 but only first 1 entries in pClearValues array are used");
7981
7982 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
7983
7984 m_errorMonitor->VerifyFound();
7985
7986 vkDestroyRenderPass(m_device->device(), rp, NULL);
7987}
7988
7989
Cody Northrop3bb4d962016-05-09 16:15:57 -06007990TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7991
7992 TEST_DESCRIPTION("End a command buffer with an active render pass");
7993
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7995 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007996
7997 ASSERT_NO_FATAL_FAILURE(InitState());
7998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7999
8000 // The framework's BeginCommandBuffer calls CreateRenderPass
8001 BeginCommandBuffer();
8002
8003 // Call directly into vkEndCommandBuffer instead of the
8004 // the framework's EndCommandBuffer, which inserts a
8005 // vkEndRenderPass
8006 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
8007
8008 m_errorMonitor->VerifyFound();
8009
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008010 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8011 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008012}
8013
Karl Schultz6addd812016-02-02 17:17:23 -07008014TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008015 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8017 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008018
8019 ASSERT_NO_FATAL_FAILURE(InitState());
8020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008021
8022 // Renderpass is started here
8023 BeginCommandBuffer();
8024
8025 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008026 vk_testing::Buffer dstBuffer;
8027 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008028
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008029 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008030
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008031 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008032}
8033
Karl Schultz6addd812016-02-02 17:17:23 -07008034TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008035 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8037 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008038
8039 ASSERT_NO_FATAL_FAILURE(InitState());
8040 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008041
8042 // Renderpass is started here
8043 BeginCommandBuffer();
8044
8045 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008046 vk_testing::Buffer dstBuffer;
8047 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008048
Karl Schultz6addd812016-02-02 17:17:23 -07008049 VkDeviceSize dstOffset = 0;
8050 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008051 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008052
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008053 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008054
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008055 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008056}
8057
Karl Schultz6addd812016-02-02 17:17:23 -07008058TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008059 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8061 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008062
8063 ASSERT_NO_FATAL_FAILURE(InitState());
8064 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008065
8066 // Renderpass is started here
8067 BeginCommandBuffer();
8068
Michael Lentine0a369f62016-02-03 16:51:46 -06008069 VkClearColorValue clear_color;
8070 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008071 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8072 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8073 const int32_t tex_width = 32;
8074 const int32_t tex_height = 32;
8075 VkImageCreateInfo image_create_info = {};
8076 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8077 image_create_info.pNext = NULL;
8078 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8079 image_create_info.format = tex_format;
8080 image_create_info.extent.width = tex_width;
8081 image_create_info.extent.height = tex_height;
8082 image_create_info.extent.depth = 1;
8083 image_create_info.mipLevels = 1;
8084 image_create_info.arrayLayers = 1;
8085 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8086 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8087 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008088
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008089 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008090 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008091
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008092 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008093
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008094 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008095
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008096 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008097}
8098
Karl Schultz6addd812016-02-02 17:17:23 -07008099TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008100 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8102 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008103
8104 ASSERT_NO_FATAL_FAILURE(InitState());
8105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008106
8107 // Renderpass is started here
8108 BeginCommandBuffer();
8109
8110 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008111 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008112 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8113 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8114 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8115 image_create_info.extent.width = 64;
8116 image_create_info.extent.height = 64;
8117 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8118 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008119
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008120 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008121 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008122
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008123 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008124
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008125 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8126 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008127
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008128 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008129}
8130
Karl Schultz6addd812016-02-02 17:17:23 -07008131TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008132 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008133 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008134
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8136 "must be issued inside an active "
8137 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008138
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008139 ASSERT_NO_FATAL_FAILURE(InitState());
8140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008141
8142 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008143 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008144 ASSERT_VK_SUCCESS(err);
8145
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008146 VkClearAttachment color_attachment;
8147 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8148 color_attachment.clearValue.color.float32[0] = 0;
8149 color_attachment.clearValue.color.float32[1] = 0;
8150 color_attachment.clearValue.color.float32[2] = 0;
8151 color_attachment.clearValue.color.float32[3] = 0;
8152 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008153 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008154 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008155
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008156 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008157}
8158
Chris Forbes3b97e932016-09-07 11:29:24 +12008159TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8160 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8161 "called too many times in a renderpass instance");
8162
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8164 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008165
8166 ASSERT_NO_FATAL_FAILURE(InitState());
8167 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8168
8169 BeginCommandBuffer();
8170
8171 // error here.
8172 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8173 m_errorMonitor->VerifyFound();
8174
8175 EndCommandBuffer();
8176}
8177
Chris Forbes6d624702016-09-07 13:57:05 +12008178TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8179 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8180 "called before the final subpass has been reached");
8181
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8183 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008184
8185 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008186 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8187 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008188
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008189 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008190
8191 VkRenderPass rp;
8192 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8193 ASSERT_VK_SUCCESS(err);
8194
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008195 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008196
8197 VkFramebuffer fb;
8198 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8199 ASSERT_VK_SUCCESS(err);
8200
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008201 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008202
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008203 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 +12008204
8205 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8206
8207 // Error here.
8208 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8209 m_errorMonitor->VerifyFound();
8210
8211 // Clean up.
8212 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8213 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8214}
8215
Karl Schultz9e66a292016-04-21 15:57:51 -06008216TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8217 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8219 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008220
8221 ASSERT_NO_FATAL_FAILURE(InitState());
8222 BeginCommandBuffer();
8223
8224 VkBufferMemoryBarrier buf_barrier = {};
8225 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8226 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8227 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8228 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8229 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8230 buf_barrier.buffer = VK_NULL_HANDLE;
8231 buf_barrier.offset = 0;
8232 buf_barrier.size = VK_WHOLE_SIZE;
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, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008235
8236 m_errorMonitor->VerifyFound();
8237}
8238
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008239TEST_F(VkLayerTest, InvalidBarriers) {
8240 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8241
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008243
8244 ASSERT_NO_FATAL_FAILURE(InitState());
8245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8246
8247 VkMemoryBarrier mem_barrier = {};
8248 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8249 mem_barrier.pNext = NULL;
8250 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8251 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8252 BeginCommandBuffer();
8253 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008254 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008255 &mem_barrier, 0, nullptr, 0, nullptr);
8256 m_errorMonitor->VerifyFound();
8257
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008259 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008260 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 -06008261 ASSERT_TRUE(image.initialized());
8262 VkImageMemoryBarrier img_barrier = {};
8263 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8264 img_barrier.pNext = NULL;
8265 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8266 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8267 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8268 // New layout can't be UNDEFINED
8269 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8270 img_barrier.image = image.handle();
8271 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8272 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8273 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8274 img_barrier.subresourceRange.baseArrayLayer = 0;
8275 img_barrier.subresourceRange.baseMipLevel = 0;
8276 img_barrier.subresourceRange.layerCount = 1;
8277 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008278 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8279 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008280 m_errorMonitor->VerifyFound();
8281 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8282
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8284 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008285 // baseArrayLayer + layerCount must be <= image's arrayLayers
8286 img_barrier.subresourceRange.baseArrayLayer = 1;
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);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008289 m_errorMonitor->VerifyFound();
8290 img_barrier.subresourceRange.baseArrayLayer = 0;
8291
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008293 // baseMipLevel + levelCount must be <= image's mipLevels
8294 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008295 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8296 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008297 m_errorMonitor->VerifyFound();
8298 img_barrier.subresourceRange.baseMipLevel = 0;
8299
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008300 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 -06008301 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008302 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8303 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008304 VkBufferMemoryBarrier buf_barrier = {};
8305 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8306 buf_barrier.pNext = NULL;
8307 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8308 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8309 buf_barrier.buffer = buffer.handle();
8310 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8311 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8312 buf_barrier.offset = 0;
8313 buf_barrier.size = VK_WHOLE_SIZE;
8314 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008315 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8316 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008317 m_errorMonitor->VerifyFound();
8318 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8319
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008321 buf_barrier.offset = 257;
8322 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008323 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8324 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008325 m_errorMonitor->VerifyFound();
8326 buf_barrier.offset = 0;
8327
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008329 buf_barrier.size = 257;
8330 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008331 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8332 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008333 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008334
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008335 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008336 m_errorMonitor->SetDesiredFailureMsg(
8337 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8338 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8339 m_errorMonitor->SetDesiredFailureMsg(
8340 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8341 "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 -06008342 VkDepthStencilObj ds_image(m_device);
8343 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8344 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008345 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8346 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008347 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008348 // Use of COLOR aspect on DS image is error
8349 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008350 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8351 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008352 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008353 // Now test depth-only
8354 VkFormatProperties format_props;
8355
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008356 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8357 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8359 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8361 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008362 VkDepthStencilObj d_image(m_device);
8363 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8364 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008365 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008366 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008367 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008368 // Use of COLOR aspect on depth image is error
8369 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008370 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8371 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008372 m_errorMonitor->VerifyFound();
8373 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008374 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8375 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008376 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8378 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008379 VkDepthStencilObj s_image(m_device);
8380 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8381 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008382 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008383 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008384 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008385 // Use of COLOR aspect on depth image is error
8386 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008387 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8388 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008389 m_errorMonitor->VerifyFound();
8390 }
8391 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8393 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8395 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008396 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008397 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 -06008398 ASSERT_TRUE(c_image.initialized());
8399 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8400 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8401 img_barrier.image = c_image.handle();
8402 // Set aspect to depth (non-color)
8403 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008404 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8405 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008406 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008407
8408 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8409
8410 // Create command pool with incompatible queueflags
8411 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8412 uint32_t queue_family_index = UINT32_MAX;
8413 for (uint32_t i = 0; i < queue_props.size(); i++) {
8414 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8415 queue_family_index = i;
8416 break;
8417 }
8418 }
8419 if (queue_family_index == UINT32_MAX) {
8420 printf("No non-compute queue found; skipped.\n");
8421 return;
8422 }
8423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8424
8425 VkCommandPool command_pool;
8426 VkCommandPoolCreateInfo pool_create_info{};
8427 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8428 pool_create_info.queueFamilyIndex = queue_family_index;
8429 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8430 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8431
8432 // Allocate a command buffer
8433 VkCommandBuffer bad_command_buffer;
8434 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8435 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8436 command_buffer_allocate_info.commandPool = command_pool;
8437 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8438 command_buffer_allocate_info.commandBufferCount = 1;
8439 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8440
8441 VkCommandBufferBeginInfo cbbi = {};
8442 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8443 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8444 buf_barrier.offset = 0;
8445 buf_barrier.size = VK_WHOLE_SIZE;
8446 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8447 &buf_barrier, 0, nullptr);
8448 m_errorMonitor->VerifyFound();
8449
8450 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8451 vkEndCommandBuffer(bad_command_buffer);
8452 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8453 printf("The non-compute queue does not support graphics; skipped.\n");
8454 return;
8455 }
8456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8457 VkEvent event;
8458 VkEventCreateInfo event_create_info{};
8459 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8460 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8461 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8462 nullptr, 0, nullptr);
8463 m_errorMonitor->VerifyFound();
8464
8465 vkEndCommandBuffer(bad_command_buffer);
8466 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008467}
8468
Tony Barbour18ba25c2016-09-29 13:42:40 -06008469TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8470 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8471
8472 m_errorMonitor->SetDesiredFailureMsg(
8473 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8474 "must have required access bit");
8475 ASSERT_NO_FATAL_FAILURE(InitState());
8476 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008477 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 -06008478 ASSERT_TRUE(image.initialized());
8479
8480 VkImageMemoryBarrier barrier = {};
8481 VkImageSubresourceRange range;
8482 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8483 barrier.srcAccessMask = 0;
8484 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8485 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8486 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8487 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8488 barrier.image = image.handle();
8489 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8490 range.baseMipLevel = 0;
8491 range.levelCount = 1;
8492 range.baseArrayLayer = 0;
8493 range.layerCount = 1;
8494 barrier.subresourceRange = range;
8495 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8496 cmdbuf.BeginCommandBuffer();
8497 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8498 &barrier);
8499 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8500 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8501 barrier.srcAccessMask = 0;
8502 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8503 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8504 &barrier);
8505
8506 m_errorMonitor->VerifyFound();
8507}
8508
Karl Schultz6addd812016-02-02 17:17:23 -07008509TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008510 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008511 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008512
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008514
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008515 ASSERT_NO_FATAL_FAILURE(InitState());
8516 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008517 uint32_t qfi = 0;
8518 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008519 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8520 buffCI.size = 1024;
8521 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8522 buffCI.queueFamilyIndexCount = 1;
8523 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008524
8525 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008526 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008527 ASSERT_VK_SUCCESS(err);
8528
8529 BeginCommandBuffer();
8530 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008531 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8532 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008533 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008534 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008535
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008536 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008537
Chia-I Wuf7458c52015-10-26 21:10:41 +08008538 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008539}
8540
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008541TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8542 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8544 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8545 "of the indices specified when the device was created, via the "
8546 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008547
8548 ASSERT_NO_FATAL_FAILURE(InitState());
8549 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8550 VkBufferCreateInfo buffCI = {};
8551 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8552 buffCI.size = 1024;
8553 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8554 buffCI.queueFamilyIndexCount = 1;
8555 // Introduce failure by specifying invalid queue_family_index
8556 uint32_t qfi = 777;
8557 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008558 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008559
8560 VkBuffer ib;
8561 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8562
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008563 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008564 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008565}
8566
Karl Schultz6addd812016-02-02 17:17:23 -07008567TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008568TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008569 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008570
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008571 ASSERT_NO_FATAL_FAILURE(InitState());
8572 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008573
Chris Forbesf29a84f2016-10-06 18:39:28 +13008574 // An empty primary command buffer
8575 VkCommandBufferObj cb(m_device, m_commandPool);
8576 cb.BeginCommandBuffer();
8577 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008578
Chris Forbesf29a84f2016-10-06 18:39:28 +13008579 m_commandBuffer->BeginCommandBuffer();
8580 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8581 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008582
Chris Forbesf29a84f2016-10-06 18:39:28 +13008583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8584 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008585 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008586}
8587
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008588TEST_F(VkLayerTest, DSUsageBitsErrors) {
8589 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8590 "that do not have correct usage bits sets.");
8591 VkResult err;
8592
8593 ASSERT_NO_FATAL_FAILURE(InitState());
8594 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8595 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8596 ds_type_count[i].type = VkDescriptorType(i);
8597 ds_type_count[i].descriptorCount = 1;
8598 }
8599 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8600 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8601 ds_pool_ci.pNext = NULL;
8602 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8603 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8604 ds_pool_ci.pPoolSizes = ds_type_count;
8605
8606 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008607 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008608 ASSERT_VK_SUCCESS(err);
8609
8610 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008611 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008612 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8613 dsl_binding[i].binding = 0;
8614 dsl_binding[i].descriptorType = VkDescriptorType(i);
8615 dsl_binding[i].descriptorCount = 1;
8616 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8617 dsl_binding[i].pImmutableSamplers = NULL;
8618 }
8619
8620 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8621 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8622 ds_layout_ci.pNext = NULL;
8623 ds_layout_ci.bindingCount = 1;
8624 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8625 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8626 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008627 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008628 ASSERT_VK_SUCCESS(err);
8629 }
8630 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8631 VkDescriptorSetAllocateInfo alloc_info = {};
8632 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8633 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8634 alloc_info.descriptorPool = ds_pool;
8635 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008636 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008637 ASSERT_VK_SUCCESS(err);
8638
8639 // Create a buffer & bufferView to be used for invalid updates
8640 VkBufferCreateInfo buff_ci = {};
8641 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8642 // This usage is not valid for any descriptor type
8643 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8644 buff_ci.size = 256;
8645 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8646 VkBuffer buffer;
8647 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8648 ASSERT_VK_SUCCESS(err);
8649
8650 VkBufferViewCreateInfo buff_view_ci = {};
8651 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8652 buff_view_ci.buffer = buffer;
8653 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8654 buff_view_ci.range = VK_WHOLE_SIZE;
8655 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008656 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008657 ASSERT_VK_SUCCESS(err);
8658
8659 // Create an image to be used for invalid updates
8660 VkImageCreateInfo image_ci = {};
8661 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8662 image_ci.imageType = VK_IMAGE_TYPE_2D;
8663 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8664 image_ci.extent.width = 64;
8665 image_ci.extent.height = 64;
8666 image_ci.extent.depth = 1;
8667 image_ci.mipLevels = 1;
8668 image_ci.arrayLayers = 1;
8669 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8670 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8671 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8672 // This usage is not valid for any descriptor type
8673 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8674 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8675 VkImage image;
8676 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8677 ASSERT_VK_SUCCESS(err);
8678 // Bind memory to image
8679 VkMemoryRequirements mem_reqs;
8680 VkDeviceMemory image_mem;
8681 bool pass;
8682 VkMemoryAllocateInfo mem_alloc = {};
8683 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8684 mem_alloc.pNext = NULL;
8685 mem_alloc.allocationSize = 0;
8686 mem_alloc.memoryTypeIndex = 0;
8687 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8688 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008689 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008690 ASSERT_TRUE(pass);
8691 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8692 ASSERT_VK_SUCCESS(err);
8693 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8694 ASSERT_VK_SUCCESS(err);
8695 // Now create view for image
8696 VkImageViewCreateInfo image_view_ci = {};
8697 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8698 image_view_ci.image = image;
8699 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8700 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8701 image_view_ci.subresourceRange.layerCount = 1;
8702 image_view_ci.subresourceRange.baseArrayLayer = 0;
8703 image_view_ci.subresourceRange.levelCount = 1;
8704 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8705 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008706 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008707 ASSERT_VK_SUCCESS(err);
8708
8709 VkDescriptorBufferInfo buff_info = {};
8710 buff_info.buffer = buffer;
8711 VkDescriptorImageInfo img_info = {};
8712 img_info.imageView = image_view;
8713 VkWriteDescriptorSet descriptor_write = {};
8714 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8715 descriptor_write.dstBinding = 0;
8716 descriptor_write.descriptorCount = 1;
8717 descriptor_write.pTexelBufferView = &buff_view;
8718 descriptor_write.pBufferInfo = &buff_info;
8719 descriptor_write.pImageInfo = &img_info;
8720
8721 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008722 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8723 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8724 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8725 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8726 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8727 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8728 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8729 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8730 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8731 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8732 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008733 // Start loop at 1 as SAMPLER desc type has no usage bit error
8734 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8735 descriptor_write.descriptorType = VkDescriptorType(i);
8736 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008738
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008739 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008740
8741 m_errorMonitor->VerifyFound();
8742 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8743 }
8744 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8745 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008746 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008747 vkDestroyImageView(m_device->device(), image_view, NULL);
8748 vkDestroyBuffer(m_device->device(), buffer, NULL);
8749 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008750 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008751 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8752}
8753
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008754TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008755 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8756 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8757 "1. offset value greater than buffer size\n"
8758 "2. range value of 0\n"
8759 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008760 VkResult err;
8761
8762 ASSERT_NO_FATAL_FAILURE(InitState());
8763 VkDescriptorPoolSize ds_type_count = {};
8764 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8765 ds_type_count.descriptorCount = 1;
8766
8767 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8768 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8769 ds_pool_ci.pNext = NULL;
8770 ds_pool_ci.maxSets = 1;
8771 ds_pool_ci.poolSizeCount = 1;
8772 ds_pool_ci.pPoolSizes = &ds_type_count;
8773
8774 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008775 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008776 ASSERT_VK_SUCCESS(err);
8777
8778 // Create layout with single uniform buffer descriptor
8779 VkDescriptorSetLayoutBinding dsl_binding = {};
8780 dsl_binding.binding = 0;
8781 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8782 dsl_binding.descriptorCount = 1;
8783 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8784 dsl_binding.pImmutableSamplers = NULL;
8785
8786 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8787 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8788 ds_layout_ci.pNext = NULL;
8789 ds_layout_ci.bindingCount = 1;
8790 ds_layout_ci.pBindings = &dsl_binding;
8791 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008792 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008793 ASSERT_VK_SUCCESS(err);
8794
8795 VkDescriptorSet descriptor_set = {};
8796 VkDescriptorSetAllocateInfo alloc_info = {};
8797 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8798 alloc_info.descriptorSetCount = 1;
8799 alloc_info.descriptorPool = ds_pool;
8800 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008801 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008802 ASSERT_VK_SUCCESS(err);
8803
8804 // Create a buffer to be used for invalid updates
8805 VkBufferCreateInfo buff_ci = {};
8806 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8807 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8808 buff_ci.size = 256;
8809 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8810 VkBuffer buffer;
8811 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8812 ASSERT_VK_SUCCESS(err);
8813 // Have to bind memory to buffer before descriptor update
8814 VkMemoryAllocateInfo mem_alloc = {};
8815 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8816 mem_alloc.pNext = NULL;
8817 mem_alloc.allocationSize = 256;
8818 mem_alloc.memoryTypeIndex = 0;
8819
8820 VkMemoryRequirements mem_reqs;
8821 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008822 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008823 if (!pass) {
8824 vkDestroyBuffer(m_device->device(), buffer, NULL);
8825 return;
8826 }
8827
8828 VkDeviceMemory mem;
8829 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8830 ASSERT_VK_SUCCESS(err);
8831 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8832 ASSERT_VK_SUCCESS(err);
8833
8834 VkDescriptorBufferInfo buff_info = {};
8835 buff_info.buffer = buffer;
8836 // First make offset 1 larger than buffer size
8837 buff_info.offset = 257;
8838 buff_info.range = VK_WHOLE_SIZE;
8839 VkWriteDescriptorSet descriptor_write = {};
8840 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8841 descriptor_write.dstBinding = 0;
8842 descriptor_write.descriptorCount = 1;
8843 descriptor_write.pTexelBufferView = nullptr;
8844 descriptor_write.pBufferInfo = &buff_info;
8845 descriptor_write.pImageInfo = nullptr;
8846
8847 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8848 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008850
8851 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8852
8853 m_errorMonitor->VerifyFound();
8854 // Now cause error due to range of 0
8855 buff_info.offset = 0;
8856 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8858 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008859
8860 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8861
8862 m_errorMonitor->VerifyFound();
8863 // Now cause error due to range exceeding buffer size - offset
8864 buff_info.offset = 128;
8865 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008866 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 -06008867
8868 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8869
8870 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008871 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008872 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8873 vkDestroyBuffer(m_device->device(), buffer, NULL);
8874 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8875 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8876}
8877
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008878TEST_F(VkLayerTest, DSAspectBitsErrors) {
8879 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8880 // are set, but could expand this test to hit more cases.
8881 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8882 "that do not have correct aspect bits sets.");
8883 VkResult err;
8884
8885 ASSERT_NO_FATAL_FAILURE(InitState());
8886 VkDescriptorPoolSize ds_type_count = {};
8887 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8888 ds_type_count.descriptorCount = 1;
8889
8890 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8891 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8892 ds_pool_ci.pNext = NULL;
8893 ds_pool_ci.maxSets = 5;
8894 ds_pool_ci.poolSizeCount = 1;
8895 ds_pool_ci.pPoolSizes = &ds_type_count;
8896
8897 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008898 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008899 ASSERT_VK_SUCCESS(err);
8900
8901 VkDescriptorSetLayoutBinding dsl_binding = {};
8902 dsl_binding.binding = 0;
8903 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8904 dsl_binding.descriptorCount = 1;
8905 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8906 dsl_binding.pImmutableSamplers = NULL;
8907
8908 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8909 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8910 ds_layout_ci.pNext = NULL;
8911 ds_layout_ci.bindingCount = 1;
8912 ds_layout_ci.pBindings = &dsl_binding;
8913 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008914 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008915 ASSERT_VK_SUCCESS(err);
8916
8917 VkDescriptorSet descriptor_set = {};
8918 VkDescriptorSetAllocateInfo alloc_info = {};
8919 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8920 alloc_info.descriptorSetCount = 1;
8921 alloc_info.descriptorPool = ds_pool;
8922 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008923 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008924 ASSERT_VK_SUCCESS(err);
8925
8926 // Create an image to be used for invalid updates
8927 VkImageCreateInfo image_ci = {};
8928 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8929 image_ci.imageType = VK_IMAGE_TYPE_2D;
8930 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8931 image_ci.extent.width = 64;
8932 image_ci.extent.height = 64;
8933 image_ci.extent.depth = 1;
8934 image_ci.mipLevels = 1;
8935 image_ci.arrayLayers = 1;
8936 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8937 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8938 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8939 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8940 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8941 VkImage image;
8942 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8943 ASSERT_VK_SUCCESS(err);
8944 // Bind memory to image
8945 VkMemoryRequirements mem_reqs;
8946 VkDeviceMemory image_mem;
8947 bool pass;
8948 VkMemoryAllocateInfo mem_alloc = {};
8949 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8950 mem_alloc.pNext = NULL;
8951 mem_alloc.allocationSize = 0;
8952 mem_alloc.memoryTypeIndex = 0;
8953 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8954 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008955 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008956 ASSERT_TRUE(pass);
8957 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8958 ASSERT_VK_SUCCESS(err);
8959 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8960 ASSERT_VK_SUCCESS(err);
8961 // Now create view for image
8962 VkImageViewCreateInfo image_view_ci = {};
8963 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8964 image_view_ci.image = image;
8965 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8966 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8967 image_view_ci.subresourceRange.layerCount = 1;
8968 image_view_ci.subresourceRange.baseArrayLayer = 0;
8969 image_view_ci.subresourceRange.levelCount = 1;
8970 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008971 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008972
8973 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008974 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008975 ASSERT_VK_SUCCESS(err);
8976
8977 VkDescriptorImageInfo img_info = {};
8978 img_info.imageView = image_view;
8979 VkWriteDescriptorSet descriptor_write = {};
8980 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8981 descriptor_write.dstBinding = 0;
8982 descriptor_write.descriptorCount = 1;
8983 descriptor_write.pTexelBufferView = NULL;
8984 descriptor_write.pBufferInfo = NULL;
8985 descriptor_write.pImageInfo = &img_info;
8986 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8987 descriptor_write.dstSet = descriptor_set;
8988 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8989 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008991
8992 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8993
8994 m_errorMonitor->VerifyFound();
8995 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8996 vkDestroyImage(m_device->device(), image, NULL);
8997 vkFreeMemory(m_device->device(), image_mem, NULL);
8998 vkDestroyImageView(m_device->device(), image_view, NULL);
8999 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9000 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9001}
9002
Karl Schultz6addd812016-02-02 17:17:23 -07009003TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009004 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009005 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009006
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9008 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9009 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009010
Tobin Ehlis3b780662015-05-28 12:11:26 -06009011 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009012 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009013 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009014 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9015 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009016
9017 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009018 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9019 ds_pool_ci.pNext = NULL;
9020 ds_pool_ci.maxSets = 1;
9021 ds_pool_ci.poolSizeCount = 1;
9022 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009023
Tobin Ehlis3b780662015-05-28 12:11:26 -06009024 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009025 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009026 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009027 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009028 dsl_binding.binding = 0;
9029 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9030 dsl_binding.descriptorCount = 1;
9031 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9032 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009033
Tony Barboureb254902015-07-15 12:50:33 -06009034 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009035 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9036 ds_layout_ci.pNext = NULL;
9037 ds_layout_ci.bindingCount = 1;
9038 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009039
Tobin Ehlis3b780662015-05-28 12:11:26 -06009040 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009041 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009042 ASSERT_VK_SUCCESS(err);
9043
9044 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009045 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009046 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009047 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009048 alloc_info.descriptorPool = ds_pool;
9049 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009050 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009051 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009052
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009053 VkSamplerCreateInfo sampler_ci = {};
9054 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9055 sampler_ci.pNext = NULL;
9056 sampler_ci.magFilter = VK_FILTER_NEAREST;
9057 sampler_ci.minFilter = VK_FILTER_NEAREST;
9058 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9059 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9060 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9061 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9062 sampler_ci.mipLodBias = 1.0;
9063 sampler_ci.anisotropyEnable = VK_FALSE;
9064 sampler_ci.maxAnisotropy = 1;
9065 sampler_ci.compareEnable = VK_FALSE;
9066 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9067 sampler_ci.minLod = 1.0;
9068 sampler_ci.maxLod = 1.0;
9069 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9070 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9071 VkSampler sampler;
9072 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9073 ASSERT_VK_SUCCESS(err);
9074
9075 VkDescriptorImageInfo info = {};
9076 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009077
9078 VkWriteDescriptorSet descriptor_write;
9079 memset(&descriptor_write, 0, sizeof(descriptor_write));
9080 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009081 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009082 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009083 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009084 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009085 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009086
9087 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9088
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009089 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009090
Chia-I Wuf7458c52015-10-26 21:10:41 +08009091 vkDestroySampler(m_device->device(), sampler, NULL);
9092 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9093 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009094}
9095
Karl Schultz6addd812016-02-02 17:17:23 -07009096TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009097 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009098 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009099
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009101
Tobin Ehlis3b780662015-05-28 12:11:26 -06009102 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009103 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009104 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009105 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9106 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009107
9108 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009109 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9110 ds_pool_ci.pNext = NULL;
9111 ds_pool_ci.maxSets = 1;
9112 ds_pool_ci.poolSizeCount = 1;
9113 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009114
Tobin Ehlis3b780662015-05-28 12:11:26 -06009115 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009116 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009117 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009118
Tony Barboureb254902015-07-15 12:50:33 -06009119 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009120 dsl_binding.binding = 0;
9121 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9122 dsl_binding.descriptorCount = 1;
9123 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9124 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009125
9126 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009127 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9128 ds_layout_ci.pNext = NULL;
9129 ds_layout_ci.bindingCount = 1;
9130 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009131
Tobin Ehlis3b780662015-05-28 12:11:26 -06009132 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009133 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009134 ASSERT_VK_SUCCESS(err);
9135
9136 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009137 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009138 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009139 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009140 alloc_info.descriptorPool = ds_pool;
9141 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009142 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009143 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009144
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009145 // Correctly update descriptor to avoid "NOT_UPDATED" error
9146 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009147 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009148 buff_info.offset = 0;
9149 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009150
9151 VkWriteDescriptorSet descriptor_write;
9152 memset(&descriptor_write, 0, sizeof(descriptor_write));
9153 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009154 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009155 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009156 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009157 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9158 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009159
9160 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9161
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009162 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009163
Chia-I Wuf7458c52015-10-26 21:10:41 +08009164 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9165 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009166}
9167
Karl Schultz6addd812016-02-02 17:17:23 -07009168TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009169 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009170 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009171
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009173
Tobin Ehlis3b780662015-05-28 12:11:26 -06009174 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009175 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009176 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009177 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9178 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009179
9180 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009181 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9182 ds_pool_ci.pNext = NULL;
9183 ds_pool_ci.maxSets = 1;
9184 ds_pool_ci.poolSizeCount = 1;
9185 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009186
Tobin Ehlis3b780662015-05-28 12:11:26 -06009187 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009188 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009189 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009190
Tony Barboureb254902015-07-15 12:50:33 -06009191 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009192 dsl_binding.binding = 0;
9193 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9194 dsl_binding.descriptorCount = 1;
9195 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9196 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009197
9198 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009199 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9200 ds_layout_ci.pNext = NULL;
9201 ds_layout_ci.bindingCount = 1;
9202 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009203 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009204 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009205 ASSERT_VK_SUCCESS(err);
9206
9207 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009208 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009209 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009210 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009211 alloc_info.descriptorPool = ds_pool;
9212 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009213 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009214 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009215
Tony Barboureb254902015-07-15 12:50:33 -06009216 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009217 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9218 sampler_ci.pNext = NULL;
9219 sampler_ci.magFilter = VK_FILTER_NEAREST;
9220 sampler_ci.minFilter = VK_FILTER_NEAREST;
9221 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9222 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9223 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9224 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9225 sampler_ci.mipLodBias = 1.0;
9226 sampler_ci.anisotropyEnable = VK_FALSE;
9227 sampler_ci.maxAnisotropy = 1;
9228 sampler_ci.compareEnable = VK_FALSE;
9229 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9230 sampler_ci.minLod = 1.0;
9231 sampler_ci.maxLod = 1.0;
9232 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9233 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009234
Tobin Ehlis3b780662015-05-28 12:11:26 -06009235 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009236 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009237 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009238
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009239 VkDescriptorImageInfo info = {};
9240 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009241
9242 VkWriteDescriptorSet descriptor_write;
9243 memset(&descriptor_write, 0, sizeof(descriptor_write));
9244 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009245 descriptor_write.dstSet = descriptorSet;
9246 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009247 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009248 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009249 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009250 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009251
9252 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9253
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009254 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009255
Chia-I Wuf7458c52015-10-26 21:10:41 +08009256 vkDestroySampler(m_device->device(), sampler, NULL);
9257 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9258 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009259}
9260
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009261TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9262 // Create layout w/ empty binding and attempt to update it
9263 VkResult err;
9264
9265 ASSERT_NO_FATAL_FAILURE(InitState());
9266
9267 VkDescriptorPoolSize ds_type_count = {};
9268 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9269 ds_type_count.descriptorCount = 1;
9270
9271 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9272 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9273 ds_pool_ci.pNext = NULL;
9274 ds_pool_ci.maxSets = 1;
9275 ds_pool_ci.poolSizeCount = 1;
9276 ds_pool_ci.pPoolSizes = &ds_type_count;
9277
9278 VkDescriptorPool ds_pool;
9279 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9280 ASSERT_VK_SUCCESS(err);
9281
9282 VkDescriptorSetLayoutBinding dsl_binding = {};
9283 dsl_binding.binding = 0;
9284 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9285 dsl_binding.descriptorCount = 0;
9286 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9287 dsl_binding.pImmutableSamplers = NULL;
9288
9289 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9290 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9291 ds_layout_ci.pNext = NULL;
9292 ds_layout_ci.bindingCount = 1;
9293 ds_layout_ci.pBindings = &dsl_binding;
9294 VkDescriptorSetLayout ds_layout;
9295 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9296 ASSERT_VK_SUCCESS(err);
9297
9298 VkDescriptorSet descriptor_set;
9299 VkDescriptorSetAllocateInfo alloc_info = {};
9300 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9301 alloc_info.descriptorSetCount = 1;
9302 alloc_info.descriptorPool = ds_pool;
9303 alloc_info.pSetLayouts = &ds_layout;
9304 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9305 ASSERT_VK_SUCCESS(err);
9306
9307 VkSamplerCreateInfo sampler_ci = {};
9308 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9309 sampler_ci.magFilter = VK_FILTER_NEAREST;
9310 sampler_ci.minFilter = VK_FILTER_NEAREST;
9311 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9312 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9313 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9314 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9315 sampler_ci.mipLodBias = 1.0;
9316 sampler_ci.maxAnisotropy = 1;
9317 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9318 sampler_ci.minLod = 1.0;
9319 sampler_ci.maxLod = 1.0;
9320 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9321
9322 VkSampler sampler;
9323 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9324 ASSERT_VK_SUCCESS(err);
9325
9326 VkDescriptorImageInfo info = {};
9327 info.sampler = sampler;
9328
9329 VkWriteDescriptorSet descriptor_write;
9330 memset(&descriptor_write, 0, sizeof(descriptor_write));
9331 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9332 descriptor_write.dstSet = descriptor_set;
9333 descriptor_write.dstBinding = 0;
9334 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9335 // This is the wrong type, but empty binding error will be flagged first
9336 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9337 descriptor_write.pImageInfo = &info;
9338
9339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9340 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9341 m_errorMonitor->VerifyFound();
9342
9343 vkDestroySampler(m_device->device(), sampler, NULL);
9344 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9345 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9346}
9347
Karl Schultz6addd812016-02-02 17:17:23 -07009348TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9349 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9350 // types
9351 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009352
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009353 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 -06009354
Tobin Ehlis3b780662015-05-28 12:11:26 -06009355 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009356
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009357 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009358 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9359 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009360
9361 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009362 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9363 ds_pool_ci.pNext = NULL;
9364 ds_pool_ci.maxSets = 1;
9365 ds_pool_ci.poolSizeCount = 1;
9366 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009367
Tobin Ehlis3b780662015-05-28 12:11:26 -06009368 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009369 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009370 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009371 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009372 dsl_binding.binding = 0;
9373 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9374 dsl_binding.descriptorCount = 1;
9375 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9376 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009377
Tony Barboureb254902015-07-15 12:50:33 -06009378 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009379 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9380 ds_layout_ci.pNext = NULL;
9381 ds_layout_ci.bindingCount = 1;
9382 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009383
Tobin Ehlis3b780662015-05-28 12:11:26 -06009384 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009385 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009386 ASSERT_VK_SUCCESS(err);
9387
9388 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009389 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009390 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009391 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009392 alloc_info.descriptorPool = ds_pool;
9393 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009394 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009395 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009396
Tony Barboureb254902015-07-15 12:50:33 -06009397 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009398 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9399 sampler_ci.pNext = NULL;
9400 sampler_ci.magFilter = VK_FILTER_NEAREST;
9401 sampler_ci.minFilter = VK_FILTER_NEAREST;
9402 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9403 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9404 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9405 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9406 sampler_ci.mipLodBias = 1.0;
9407 sampler_ci.anisotropyEnable = VK_FALSE;
9408 sampler_ci.maxAnisotropy = 1;
9409 sampler_ci.compareEnable = VK_FALSE;
9410 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9411 sampler_ci.minLod = 1.0;
9412 sampler_ci.maxLod = 1.0;
9413 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9414 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009415 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009416 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009417 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009418
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009419 VkDescriptorImageInfo info = {};
9420 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009421
9422 VkWriteDescriptorSet descriptor_write;
9423 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009424 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009425 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009426 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009427 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009428 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009429 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009430
9431 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9432
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009433 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009434
Chia-I Wuf7458c52015-10-26 21:10:41 +08009435 vkDestroySampler(m_device->device(), sampler, NULL);
9436 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9437 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009438}
9439
Karl Schultz6addd812016-02-02 17:17:23 -07009440TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009441 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009442 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009443
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9445 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009446
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009447 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009448 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9449 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009450 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009451 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9452 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -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 = 1;
9459 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -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 Ehlisa1c28562015-10-23 16:00:08 -06009463 ASSERT_VK_SUCCESS(err);
9464
9465 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009466 dsl_binding.binding = 0;
9467 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9468 dsl_binding.descriptorCount = 1;
9469 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9470 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009471
9472 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009473 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9474 ds_layout_ci.pNext = NULL;
9475 ds_layout_ci.bindingCount = 1;
9476 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009477 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009478 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009479 ASSERT_VK_SUCCESS(err);
9480
9481 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009482 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009483 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009484 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009485 alloc_info.descriptorPool = ds_pool;
9486 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009487 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009488 ASSERT_VK_SUCCESS(err);
9489
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009490 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009491
9492 VkDescriptorImageInfo descriptor_info;
9493 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9494 descriptor_info.sampler = sampler;
9495
9496 VkWriteDescriptorSet descriptor_write;
9497 memset(&descriptor_write, 0, sizeof(descriptor_write));
9498 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009499 descriptor_write.dstSet = descriptorSet;
9500 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009501 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009502 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9503 descriptor_write.pImageInfo = &descriptor_info;
9504
9505 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9506
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009507 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009508
Chia-I Wuf7458c52015-10-26 21:10:41 +08009509 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9510 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009511}
9512
Karl Schultz6addd812016-02-02 17:17:23 -07009513TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9514 // Create a single combined Image/Sampler descriptor and send it an invalid
9515 // imageView
9516 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009517
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009519
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009520 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009521 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009522 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9523 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009524
9525 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009526 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9527 ds_pool_ci.pNext = NULL;
9528 ds_pool_ci.maxSets = 1;
9529 ds_pool_ci.poolSizeCount = 1;
9530 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009531
9532 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009533 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009534 ASSERT_VK_SUCCESS(err);
9535
9536 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009537 dsl_binding.binding = 0;
9538 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9539 dsl_binding.descriptorCount = 1;
9540 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9541 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009542
9543 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009544 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9545 ds_layout_ci.pNext = NULL;
9546 ds_layout_ci.bindingCount = 1;
9547 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009548 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009549 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009550 ASSERT_VK_SUCCESS(err);
9551
9552 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009553 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009554 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009555 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009556 alloc_info.descriptorPool = ds_pool;
9557 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009558 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009559 ASSERT_VK_SUCCESS(err);
9560
9561 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009562 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9563 sampler_ci.pNext = NULL;
9564 sampler_ci.magFilter = VK_FILTER_NEAREST;
9565 sampler_ci.minFilter = VK_FILTER_NEAREST;
9566 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9567 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9568 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9569 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9570 sampler_ci.mipLodBias = 1.0;
9571 sampler_ci.anisotropyEnable = VK_FALSE;
9572 sampler_ci.maxAnisotropy = 1;
9573 sampler_ci.compareEnable = VK_FALSE;
9574 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9575 sampler_ci.minLod = 1.0;
9576 sampler_ci.maxLod = 1.0;
9577 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9578 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009579
9580 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009581 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009582 ASSERT_VK_SUCCESS(err);
9583
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009584 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009585
9586 VkDescriptorImageInfo descriptor_info;
9587 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9588 descriptor_info.sampler = sampler;
9589 descriptor_info.imageView = view;
9590
9591 VkWriteDescriptorSet descriptor_write;
9592 memset(&descriptor_write, 0, sizeof(descriptor_write));
9593 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009594 descriptor_write.dstSet = descriptorSet;
9595 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009596 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009597 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9598 descriptor_write.pImageInfo = &descriptor_info;
9599
9600 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9601
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009602 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009603
Chia-I Wuf7458c52015-10-26 21:10:41 +08009604 vkDestroySampler(m_device->device(), sampler, NULL);
9605 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9606 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009607}
9608
Karl Schultz6addd812016-02-02 17:17:23 -07009609TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9610 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9611 // into the other
9612 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009613
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9615 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9616 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009617
Tobin Ehlis04356f92015-10-27 16:35:27 -06009618 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009619 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009620 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009621 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9622 ds_type_count[0].descriptorCount = 1;
9623 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9624 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009625
9626 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009627 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9628 ds_pool_ci.pNext = NULL;
9629 ds_pool_ci.maxSets = 1;
9630 ds_pool_ci.poolSizeCount = 2;
9631 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009632
9633 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009634 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009635 ASSERT_VK_SUCCESS(err);
9636 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009637 dsl_binding[0].binding = 0;
9638 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9639 dsl_binding[0].descriptorCount = 1;
9640 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9641 dsl_binding[0].pImmutableSamplers = NULL;
9642 dsl_binding[1].binding = 1;
9643 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9644 dsl_binding[1].descriptorCount = 1;
9645 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9646 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009647
9648 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009649 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9650 ds_layout_ci.pNext = NULL;
9651 ds_layout_ci.bindingCount = 2;
9652 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009653
9654 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009655 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009656 ASSERT_VK_SUCCESS(err);
9657
9658 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009659 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009660 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009661 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009662 alloc_info.descriptorPool = ds_pool;
9663 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009664 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009665 ASSERT_VK_SUCCESS(err);
9666
9667 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009668 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9669 sampler_ci.pNext = NULL;
9670 sampler_ci.magFilter = VK_FILTER_NEAREST;
9671 sampler_ci.minFilter = VK_FILTER_NEAREST;
9672 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9673 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9674 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9675 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9676 sampler_ci.mipLodBias = 1.0;
9677 sampler_ci.anisotropyEnable = VK_FALSE;
9678 sampler_ci.maxAnisotropy = 1;
9679 sampler_ci.compareEnable = VK_FALSE;
9680 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9681 sampler_ci.minLod = 1.0;
9682 sampler_ci.maxLod = 1.0;
9683 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9684 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009685
9686 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009687 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009688 ASSERT_VK_SUCCESS(err);
9689
9690 VkDescriptorImageInfo info = {};
9691 info.sampler = sampler;
9692
9693 VkWriteDescriptorSet descriptor_write;
9694 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9695 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009696 descriptor_write.dstSet = descriptorSet;
9697 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009698 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009699 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9700 descriptor_write.pImageInfo = &info;
9701 // This write update should succeed
9702 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9703 // Now perform a copy update that fails due to type mismatch
9704 VkCopyDescriptorSet copy_ds_update;
9705 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9706 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9707 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009708 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009709 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009710 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009711 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009712 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9713
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009714 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009715 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009716 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 -06009717 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9718 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9719 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009720 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009721 copy_ds_update.dstSet = descriptorSet;
9722 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009723 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009724 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9725
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009726 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009727
Tobin Ehlis04356f92015-10-27 16:35:27 -06009728 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9730 "update array offset of 0 and update of "
9731 "5 descriptors oversteps total number "
9732 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009733
Tobin Ehlis04356f92015-10-27 16:35:27 -06009734 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9735 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9736 copy_ds_update.srcSet = descriptorSet;
9737 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009738 copy_ds_update.dstSet = descriptorSet;
9739 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009740 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009741 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9742
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009743 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009744
Chia-I Wuf7458c52015-10-26 21:10:41 +08009745 vkDestroySampler(m_device->device(), sampler, NULL);
9746 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9747 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009748}
9749
Karl Schultz6addd812016-02-02 17:17:23 -07009750TEST_F(VkLayerTest, NumSamplesMismatch) {
9751 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9752 // sampleCount
9753 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009754
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009756
Tobin Ehlis3b780662015-05-28 12:11:26 -06009757 ASSERT_NO_FATAL_FAILURE(InitState());
9758 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009759 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009760 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009761 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009762
9763 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009764 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9765 ds_pool_ci.pNext = NULL;
9766 ds_pool_ci.maxSets = 1;
9767 ds_pool_ci.poolSizeCount = 1;
9768 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009769
Tobin Ehlis3b780662015-05-28 12:11:26 -06009770 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009771 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009772 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009773
Tony Barboureb254902015-07-15 12:50:33 -06009774 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009775 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009776 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009777 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009778 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9779 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009780
Tony Barboureb254902015-07-15 12:50:33 -06009781 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9782 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9783 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009784 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009785 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009786
Tobin Ehlis3b780662015-05-28 12:11:26 -06009787 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009788 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009789 ASSERT_VK_SUCCESS(err);
9790
9791 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009792 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009793 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009794 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009795 alloc_info.descriptorPool = ds_pool;
9796 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009797 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009798 ASSERT_VK_SUCCESS(err);
9799
Tony Barboureb254902015-07-15 12:50:33 -06009800 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009801 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009802 pipe_ms_state_ci.pNext = NULL;
9803 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9804 pipe_ms_state_ci.sampleShadingEnable = 0;
9805 pipe_ms_state_ci.minSampleShading = 1.0;
9806 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009807
Tony Barboureb254902015-07-15 12:50:33 -06009808 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009809 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9810 pipeline_layout_ci.pNext = NULL;
9811 pipeline_layout_ci.setLayoutCount = 1;
9812 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009813
9814 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009815 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009816 ASSERT_VK_SUCCESS(err);
9817
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009818 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9819 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9820 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009821 VkPipelineObj pipe(m_device);
9822 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009823 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009824 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009825 pipe.SetMSAA(&pipe_ms_state_ci);
9826 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009827
Tony Barbourfe3351b2015-07-28 10:17:20 -06009828 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009829 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009830
Mark Young29927482016-05-04 14:38:51 -06009831 // Render triangle (the error should trigger on the attempt to draw).
9832 Draw(3, 1, 0, 0);
9833
9834 // Finalize recording of the command buffer
9835 EndCommandBuffer();
9836
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009837 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009838
Chia-I Wuf7458c52015-10-26 21:10:41 +08009839 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9840 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9841 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009842}
Mark Young29927482016-05-04 14:38:51 -06009843
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009844TEST_F(VkLayerTest, RenderPassIncompatible) {
9845 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9846 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009847 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009848 VkResult err;
9849
9850 ASSERT_NO_FATAL_FAILURE(InitState());
9851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9852
9853 VkDescriptorSetLayoutBinding dsl_binding = {};
9854 dsl_binding.binding = 0;
9855 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9856 dsl_binding.descriptorCount = 1;
9857 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9858 dsl_binding.pImmutableSamplers = NULL;
9859
9860 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9861 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9862 ds_layout_ci.pNext = NULL;
9863 ds_layout_ci.bindingCount = 1;
9864 ds_layout_ci.pBindings = &dsl_binding;
9865
9866 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009867 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009868 ASSERT_VK_SUCCESS(err);
9869
9870 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9871 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9872 pipeline_layout_ci.pNext = NULL;
9873 pipeline_layout_ci.setLayoutCount = 1;
9874 pipeline_layout_ci.pSetLayouts = &ds_layout;
9875
9876 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009877 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009878 ASSERT_VK_SUCCESS(err);
9879
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009880 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9881 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9882 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009883 // Create a renderpass that will be incompatible with default renderpass
9884 VkAttachmentReference attach = {};
9885 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9886 VkAttachmentReference color_att = {};
9887 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9888 VkSubpassDescription subpass = {};
9889 subpass.inputAttachmentCount = 1;
9890 subpass.pInputAttachments = &attach;
9891 subpass.colorAttachmentCount = 1;
9892 subpass.pColorAttachments = &color_att;
9893 VkRenderPassCreateInfo rpci = {};
9894 rpci.subpassCount = 1;
9895 rpci.pSubpasses = &subpass;
9896 rpci.attachmentCount = 1;
9897 VkAttachmentDescription attach_desc = {};
9898 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009899 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9900 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009901 rpci.pAttachments = &attach_desc;
9902 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9903 VkRenderPass rp;
9904 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9905 VkPipelineObj pipe(m_device);
9906 pipe.AddShader(&vs);
9907 pipe.AddShader(&fs);
9908 pipe.AddColorAttachment();
9909 VkViewport view_port = {};
9910 m_viewports.push_back(view_port);
9911 pipe.SetViewport(m_viewports);
9912 VkRect2D rect = {};
9913 m_scissors.push_back(rect);
9914 pipe.SetScissor(m_scissors);
9915 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9916
9917 VkCommandBufferInheritanceInfo cbii = {};
9918 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9919 cbii.renderPass = rp;
9920 cbii.subpass = 0;
9921 VkCommandBufferBeginInfo cbbi = {};
9922 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9923 cbbi.pInheritanceInfo = &cbii;
9924 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9925 VkRenderPassBeginInfo rpbi = {};
9926 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9927 rpbi.framebuffer = m_framebuffer;
9928 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009929 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9930 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009931
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009933 // Render triangle (the error should trigger on the attempt to draw).
9934 Draw(3, 1, 0, 0);
9935
9936 // Finalize recording of the command buffer
9937 EndCommandBuffer();
9938
9939 m_errorMonitor->VerifyFound();
9940
9941 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9942 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9943 vkDestroyRenderPass(m_device->device(), rp, NULL);
9944}
9945
Mark Youngc89c6312016-03-31 16:03:20 -06009946TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9947 // Create Pipeline where the number of blend attachments doesn't match the
9948 // number of color attachments. In this case, we don't add any color
9949 // blend attachments even though we have a color attachment.
9950 VkResult err;
9951
9952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009953 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009954
9955 ASSERT_NO_FATAL_FAILURE(InitState());
9956 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9957 VkDescriptorPoolSize ds_type_count = {};
9958 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9959 ds_type_count.descriptorCount = 1;
9960
9961 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9962 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9963 ds_pool_ci.pNext = NULL;
9964 ds_pool_ci.maxSets = 1;
9965 ds_pool_ci.poolSizeCount = 1;
9966 ds_pool_ci.pPoolSizes = &ds_type_count;
9967
9968 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009969 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009970 ASSERT_VK_SUCCESS(err);
9971
9972 VkDescriptorSetLayoutBinding dsl_binding = {};
9973 dsl_binding.binding = 0;
9974 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9975 dsl_binding.descriptorCount = 1;
9976 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9977 dsl_binding.pImmutableSamplers = NULL;
9978
9979 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9980 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9981 ds_layout_ci.pNext = NULL;
9982 ds_layout_ci.bindingCount = 1;
9983 ds_layout_ci.pBindings = &dsl_binding;
9984
9985 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009986 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009987 ASSERT_VK_SUCCESS(err);
9988
9989 VkDescriptorSet descriptorSet;
9990 VkDescriptorSetAllocateInfo alloc_info = {};
9991 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9992 alloc_info.descriptorSetCount = 1;
9993 alloc_info.descriptorPool = ds_pool;
9994 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009995 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009996 ASSERT_VK_SUCCESS(err);
9997
9998 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009999 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010000 pipe_ms_state_ci.pNext = NULL;
10001 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10002 pipe_ms_state_ci.sampleShadingEnable = 0;
10003 pipe_ms_state_ci.minSampleShading = 1.0;
10004 pipe_ms_state_ci.pSampleMask = NULL;
10005
10006 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10007 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10008 pipeline_layout_ci.pNext = NULL;
10009 pipeline_layout_ci.setLayoutCount = 1;
10010 pipeline_layout_ci.pSetLayouts = &ds_layout;
10011
10012 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010013 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010014 ASSERT_VK_SUCCESS(err);
10015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010016 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10017 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10018 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010019 VkPipelineObj pipe(m_device);
10020 pipe.AddShader(&vs);
10021 pipe.AddShader(&fs);
10022 pipe.SetMSAA(&pipe_ms_state_ci);
10023 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10024
10025 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010026 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060010027
Mark Young29927482016-05-04 14:38:51 -060010028 // Render triangle (the error should trigger on the attempt to draw).
10029 Draw(3, 1, 0, 0);
10030
10031 // Finalize recording of the command buffer
10032 EndCommandBuffer();
10033
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010034 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010035
10036 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10037 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10038 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10039}
Mark Young29927482016-05-04 14:38:51 -060010040
Mark Muellerd4914412016-06-13 17:52:06 -060010041TEST_F(VkLayerTest, MissingClearAttachment) {
10042 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
10043 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010044 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120010045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +130010046 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -060010047
10048 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10049 m_errorMonitor->VerifyFound();
10050}
10051
Karl Schultz6addd812016-02-02 17:17:23 -070010052TEST_F(VkLayerTest, ClearCmdNoDraw) {
10053 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
10054 // to issuing a Draw
10055 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010056
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060010058 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010059
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010060 ASSERT_NO_FATAL_FAILURE(InitState());
10061 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010062
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010063 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010064 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10065 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010066
10067 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010068 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10069 ds_pool_ci.pNext = NULL;
10070 ds_pool_ci.maxSets = 1;
10071 ds_pool_ci.poolSizeCount = 1;
10072 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010073
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010074 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010075 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010076 ASSERT_VK_SUCCESS(err);
10077
Tony Barboureb254902015-07-15 12:50:33 -060010078 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010079 dsl_binding.binding = 0;
10080 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10081 dsl_binding.descriptorCount = 1;
10082 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10083 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010084
Tony Barboureb254902015-07-15 12:50:33 -060010085 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010086 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10087 ds_layout_ci.pNext = NULL;
10088 ds_layout_ci.bindingCount = 1;
10089 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010090
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010091 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010092 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010093 ASSERT_VK_SUCCESS(err);
10094
10095 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010096 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010097 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010098 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010099 alloc_info.descriptorPool = ds_pool;
10100 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010101 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010102 ASSERT_VK_SUCCESS(err);
10103
Tony Barboureb254902015-07-15 12:50:33 -060010104 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010105 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010106 pipe_ms_state_ci.pNext = NULL;
10107 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10108 pipe_ms_state_ci.sampleShadingEnable = 0;
10109 pipe_ms_state_ci.minSampleShading = 1.0;
10110 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010111
Tony Barboureb254902015-07-15 12:50:33 -060010112 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010113 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10114 pipeline_layout_ci.pNext = NULL;
10115 pipeline_layout_ci.setLayoutCount = 1;
10116 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010117
10118 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010119 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010120 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010121
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010122 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010123 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010124 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010125 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010126
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010127 VkPipelineObj pipe(m_device);
10128 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010129 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010130 pipe.SetMSAA(&pipe_ms_state_ci);
10131 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010132
10133 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010134
Karl Schultz6addd812016-02-02 17:17:23 -070010135 // Main thing we care about for this test is that the VkImage obj we're
10136 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010137 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010138 VkClearAttachment color_attachment;
10139 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10140 color_attachment.clearValue.color.float32[0] = 1.0;
10141 color_attachment.clearValue.color.float32[1] = 1.0;
10142 color_attachment.clearValue.color.float32[2] = 1.0;
10143 color_attachment.clearValue.color.float32[3] = 1.0;
10144 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010145 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010146
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010147 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010148
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010149 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010150
Chia-I Wuf7458c52015-10-26 21:10:41 +080010151 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10152 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10153 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010154}
10155
Karl Schultz6addd812016-02-02 17:17:23 -070010156TEST_F(VkLayerTest, VtxBufferBadIndex) {
10157 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010158
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10160 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010161
Tobin Ehlis502480b2015-06-24 15:53:07 -060010162 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010163 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010165
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010166 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010167 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10168 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010169
10170 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010171 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10172 ds_pool_ci.pNext = NULL;
10173 ds_pool_ci.maxSets = 1;
10174 ds_pool_ci.poolSizeCount = 1;
10175 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010176
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010177 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010178 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010179 ASSERT_VK_SUCCESS(err);
10180
Tony Barboureb254902015-07-15 12:50:33 -060010181 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010182 dsl_binding.binding = 0;
10183 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10184 dsl_binding.descriptorCount = 1;
10185 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10186 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010187
Tony Barboureb254902015-07-15 12:50:33 -060010188 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010189 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10190 ds_layout_ci.pNext = NULL;
10191 ds_layout_ci.bindingCount = 1;
10192 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010193
Tobin Ehlis502480b2015-06-24 15:53:07 -060010194 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010195 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010196 ASSERT_VK_SUCCESS(err);
10197
10198 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010199 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010200 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010201 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010202 alloc_info.descriptorPool = ds_pool;
10203 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010204 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010205 ASSERT_VK_SUCCESS(err);
10206
Tony Barboureb254902015-07-15 12:50:33 -060010207 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010208 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010209 pipe_ms_state_ci.pNext = NULL;
10210 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10211 pipe_ms_state_ci.sampleShadingEnable = 0;
10212 pipe_ms_state_ci.minSampleShading = 1.0;
10213 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010214
Tony Barboureb254902015-07-15 12:50:33 -060010215 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010216 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10217 pipeline_layout_ci.pNext = NULL;
10218 pipeline_layout_ci.setLayoutCount = 1;
10219 pipeline_layout_ci.pSetLayouts = &ds_layout;
10220 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010221
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010222 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010223 ASSERT_VK_SUCCESS(err);
10224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010225 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10226 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10227 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010228 VkPipelineObj pipe(m_device);
10229 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010230 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010231 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010232 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010233 pipe.SetViewport(m_viewports);
10234 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010235 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010236
10237 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010238 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010239 // Don't care about actual data, just need to get to draw to flag error
10240 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010241 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010242 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010243 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010244
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010245 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010246
Chia-I Wuf7458c52015-10-26 21:10:41 +080010247 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10248 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10249 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010250}
Mark Muellerdfe37552016-07-07 14:47:42 -060010251
Mark Mueller2ee294f2016-08-04 12:59:48 -060010252TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10253 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10254 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010255 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010256
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010257 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10258 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010260 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10261 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010262
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010263 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010266 // The following test fails with recent NVidia drivers.
10267 // By the time core_validation is reached, the NVidia
10268 // driver has sanitized the invalid condition and core_validation
10269 // is not introduced to the failure condition. This is not the case
10270 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010271 // uint32_t count = static_cast<uint32_t>(~0);
10272 // VkPhysicalDevice physical_device;
10273 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10274 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010275
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010277 float queue_priority = 0.0;
10278
10279 VkDeviceQueueCreateInfo queue_create_info = {};
10280 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10281 queue_create_info.queueCount = 1;
10282 queue_create_info.pQueuePriorities = &queue_priority;
10283 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10284
10285 VkPhysicalDeviceFeatures features = m_device->phy().features();
10286 VkDevice testDevice;
10287 VkDeviceCreateInfo device_create_info = {};
10288 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10289 device_create_info.queueCreateInfoCount = 1;
10290 device_create_info.pQueueCreateInfos = &queue_create_info;
10291 device_create_info.pEnabledFeatures = &features;
10292 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10293 m_errorMonitor->VerifyFound();
10294
10295 queue_create_info.queueFamilyIndex = 1;
10296
10297 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10298 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10299 for (unsigned i = 0; i < feature_count; i++) {
10300 if (VK_FALSE == feature_array[i]) {
10301 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010303 device_create_info.pEnabledFeatures = &features;
10304 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10305 m_errorMonitor->VerifyFound();
10306 break;
10307 }
10308 }
10309}
10310
Tobin Ehlis16edf082016-11-21 12:33:49 -070010311TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10312 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10313
10314 ASSERT_NO_FATAL_FAILURE(InitState());
10315
10316 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10317 std::vector<VkDeviceQueueCreateInfo> queue_info;
10318 queue_info.reserve(queue_props.size());
10319 std::vector<std::vector<float>> queue_priorities;
10320 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10321 VkDeviceQueueCreateInfo qi{};
10322 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10323 qi.queueFamilyIndex = i;
10324 qi.queueCount = queue_props[i].queueCount;
10325 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10326 qi.pQueuePriorities = queue_priorities[i].data();
10327 queue_info.push_back(qi);
10328 }
10329
10330 std::vector<const char *> device_extension_names;
10331
10332 VkDevice local_device;
10333 VkDeviceCreateInfo device_create_info = {};
10334 auto features = m_device->phy().features();
10335 // Intentionally disable pipeline stats
10336 features.pipelineStatisticsQuery = VK_FALSE;
10337 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10338 device_create_info.pNext = NULL;
10339 device_create_info.queueCreateInfoCount = queue_info.size();
10340 device_create_info.pQueueCreateInfos = queue_info.data();
10341 device_create_info.enabledLayerCount = 0;
10342 device_create_info.ppEnabledLayerNames = NULL;
10343 device_create_info.pEnabledFeatures = &features;
10344 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10345 ASSERT_VK_SUCCESS(err);
10346
10347 VkQueryPoolCreateInfo qpci{};
10348 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10349 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10350 qpci.queryCount = 1;
10351 VkQueryPool query_pool;
10352
10353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10354 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10355 m_errorMonitor->VerifyFound();
10356
10357 vkDestroyDevice(local_device, nullptr);
10358}
10359
Mark Mueller2ee294f2016-08-04 12:59:48 -060010360TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10361 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10362 "End a command buffer with a query still in progress.");
10363
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010364 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10365 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10366 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010367
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010368 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010369
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010371
10372 ASSERT_NO_FATAL_FAILURE(InitState());
10373
10374 VkEvent event;
10375 VkEventCreateInfo event_create_info{};
10376 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10377 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10378
Mark Mueller2ee294f2016-08-04 12:59:48 -060010379 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010380 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010381
10382 BeginCommandBuffer();
10383
10384 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010385 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 -060010386 ASSERT_TRUE(image.initialized());
10387 VkImageMemoryBarrier img_barrier = {};
10388 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10389 img_barrier.pNext = NULL;
10390 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10391 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10392 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10393 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10394 img_barrier.image = image.handle();
10395 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010396
10397 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10398 // that layer validation catches the case when it is not.
10399 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010400 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10401 img_barrier.subresourceRange.baseArrayLayer = 0;
10402 img_barrier.subresourceRange.baseMipLevel = 0;
10403 img_barrier.subresourceRange.layerCount = 1;
10404 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010405 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10406 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010407 m_errorMonitor->VerifyFound();
10408
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010410
10411 VkQueryPool query_pool;
10412 VkQueryPoolCreateInfo query_pool_create_info = {};
10413 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10414 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10415 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010416 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010418 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010419 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10420
10421 vkEndCommandBuffer(m_commandBuffer->handle());
10422 m_errorMonitor->VerifyFound();
10423
10424 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10425 vkDestroyEvent(m_device->device(), event, nullptr);
10426}
10427
Mark Muellerdfe37552016-07-07 14:47:42 -060010428TEST_F(VkLayerTest, VertexBufferInvalid) {
10429 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10430 "delete a buffer twice, use an invalid offset for each "
10431 "buffer type, and attempt to bind a null buffer");
10432
10433 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10434 "using deleted buffer ";
Mark Muellerdfe37552016-07-07 14:47:42 -060010435 const char *invalid_offset_message = "vkBindBufferMemory(): "
10436 "memoryOffset is 0x";
10437 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10438 "storage memoryOffset "
10439 "is 0x";
10440 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10441 "texel memoryOffset "
10442 "is 0x";
10443 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10444 "uniform memoryOffset "
10445 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010446
10447 ASSERT_NO_FATAL_FAILURE(InitState());
10448 ASSERT_NO_FATAL_FAILURE(InitViewport());
10449 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10450
10451 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010452 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010453 pipe_ms_state_ci.pNext = NULL;
10454 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10455 pipe_ms_state_ci.sampleShadingEnable = 0;
10456 pipe_ms_state_ci.minSampleShading = 1.0;
10457 pipe_ms_state_ci.pSampleMask = nullptr;
10458
10459 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10460 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10461 VkPipelineLayout pipeline_layout;
10462
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010463 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010464 ASSERT_VK_SUCCESS(err);
10465
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010466 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10467 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010468 VkPipelineObj pipe(m_device);
10469 pipe.AddShader(&vs);
10470 pipe.AddShader(&fs);
10471 pipe.AddColorAttachment();
10472 pipe.SetMSAA(&pipe_ms_state_ci);
10473 pipe.SetViewport(m_viewports);
10474 pipe.SetScissor(m_scissors);
10475 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10476
10477 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010478 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010479
10480 {
10481 // Create and bind a vertex buffer in a reduced scope, which will cause
10482 // it to be deleted upon leaving this scope
10483 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010484 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010485 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10486 draw_verticies.AddVertexInputToPipe(pipe);
10487 }
10488
10489 Draw(1, 0, 0, 0);
10490
10491 EndCommandBuffer();
10492
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010494 QueueCommandBuffer(false);
10495 m_errorMonitor->VerifyFound();
10496
10497 {
10498 // Create and bind a vertex buffer in a reduced scope, and delete it
10499 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010500 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010502 buffer_test.TestDoubleDestroy();
10503 }
10504 m_errorMonitor->VerifyFound();
10505
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010506 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010507 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10509 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10510 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010511 m_errorMonitor->VerifyFound();
10512 }
10513
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010514 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10515 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010516 // Create and bind a memory buffer with an invalid offset again,
10517 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10519 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10520 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010521 m_errorMonitor->VerifyFound();
10522 }
10523
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010524 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010525 // Create and bind a memory buffer with an invalid offset again, but
10526 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10528 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10529 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010530 m_errorMonitor->VerifyFound();
10531 }
10532
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010533 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010534 // Create and bind a memory buffer with an invalid offset again, but
10535 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10537 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10538 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010539 m_errorMonitor->VerifyFound();
10540 }
10541
10542 {
10543 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010545 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10546 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010547 m_errorMonitor->VerifyFound();
10548 }
10549
10550 {
10551 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010553 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10554 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010555 }
10556 m_errorMonitor->VerifyFound();
10557
10558 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10559}
10560
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010561// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10562TEST_F(VkLayerTest, InvalidImageLayout) {
10563 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010564 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10565 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010566 // 3 in ValidateCmdBufImageLayouts
10567 // * -1 Attempt to submit cmd buf w/ deleted image
10568 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10569 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010570
10571 ASSERT_NO_FATAL_FAILURE(InitState());
10572 // Create src & dst images to use for copy operations
10573 VkImage src_image;
10574 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010575 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010576
10577 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10578 const int32_t tex_width = 32;
10579 const int32_t tex_height = 32;
10580
10581 VkImageCreateInfo image_create_info = {};
10582 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10583 image_create_info.pNext = NULL;
10584 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10585 image_create_info.format = tex_format;
10586 image_create_info.extent.width = tex_width;
10587 image_create_info.extent.height = tex_height;
10588 image_create_info.extent.depth = 1;
10589 image_create_info.mipLevels = 1;
10590 image_create_info.arrayLayers = 4;
10591 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10592 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10593 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010594 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010595 image_create_info.flags = 0;
10596
10597 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10598 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010599 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010600 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10601 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010602 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10603 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10604 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10605 ASSERT_VK_SUCCESS(err);
10606
10607 // Allocate memory
10608 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010609 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010610 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010611 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10612 mem_alloc.pNext = NULL;
10613 mem_alloc.allocationSize = 0;
10614 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010615
10616 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010617 mem_alloc.allocationSize = img_mem_reqs.size;
10618 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010619 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010620 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010621 ASSERT_VK_SUCCESS(err);
10622
10623 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010624 mem_alloc.allocationSize = img_mem_reqs.size;
10625 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010626 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010627 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010628 ASSERT_VK_SUCCESS(err);
10629
10630 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010631 mem_alloc.allocationSize = img_mem_reqs.size;
10632 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010633 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010634 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010635 ASSERT_VK_SUCCESS(err);
10636
10637 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10638 ASSERT_VK_SUCCESS(err);
10639 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10640 ASSERT_VK_SUCCESS(err);
10641 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10642 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010643
10644 BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010645 VkImageCopy copy_region;
10646 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10647 copy_region.srcSubresource.mipLevel = 0;
10648 copy_region.srcSubresource.baseArrayLayer = 0;
10649 copy_region.srcSubresource.layerCount = 1;
10650 copy_region.srcOffset.x = 0;
10651 copy_region.srcOffset.y = 0;
10652 copy_region.srcOffset.z = 0;
10653 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10654 copy_region.dstSubresource.mipLevel = 0;
10655 copy_region.dstSubresource.baseArrayLayer = 0;
10656 copy_region.dstSubresource.layerCount = 1;
10657 copy_region.dstOffset.x = 0;
10658 copy_region.dstOffset.y = 0;
10659 copy_region.dstOffset.z = 0;
10660 copy_region.extent.width = 1;
10661 copy_region.extent.height = 1;
10662 copy_region.extent.depth = 1;
10663
10664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10665 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10666 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010667 m_errorMonitor->VerifyFound();
10668 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10670 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10671 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010672 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010673 m_errorMonitor->VerifyFound();
10674 // Final src error is due to bad layout type
10675 m_errorMonitor->SetDesiredFailureMsg(
10676 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10677 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010678 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010679 m_errorMonitor->VerifyFound();
10680 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10682 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010683 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010684 m_errorMonitor->VerifyFound();
10685 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10687 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10688 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010689 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010690 m_errorMonitor->VerifyFound();
10691 m_errorMonitor->SetDesiredFailureMsg(
10692 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10693 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010694 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010695 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010696
Cort3b021012016-12-07 12:00:57 -080010697 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10698 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10699 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10700 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10701 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10702 transfer_dst_image_barrier[0].srcAccessMask = 0;
10703 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10704 transfer_dst_image_barrier[0].image = dst_image;
10705 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10706 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10707 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10708 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10709 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10710 transfer_dst_image_barrier[0].image = depth_image;
10711 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10712 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10713 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10714
10715 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010716 VkClearColorValue color_clear_value = {};
10717 VkImageSubresourceRange clear_range;
10718 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10719 clear_range.baseMipLevel = 0;
10720 clear_range.baseArrayLayer = 0;
10721 clear_range.layerCount = 1;
10722 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010723
Cort3b021012016-12-07 12:00:57 -080010724 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10725 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010728 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010729 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010730 // Fail due to provided layout not matching actual current layout for color clear.
10731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010732 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010733 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010734
Cort530cf382016-12-08 09:59:47 -080010735 VkClearDepthStencilValue depth_clear_value = {};
10736 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010737
10738 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10739 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010742 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010743 m_errorMonitor->VerifyFound();
10744 // Fail due to provided layout not matching actual current layout for depth clear.
10745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010746 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010747 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010748
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010749 // Now cause error due to bad image layout transition in PipelineBarrier
10750 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010751 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010752 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010753 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010754 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010755 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10756 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010757 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10759 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10760 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10761 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10762 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010763 m_errorMonitor->VerifyFound();
10764
10765 // Finally some layout errors at RenderPass create time
10766 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10767 VkAttachmentReference attach = {};
10768 // perf warning for GENERAL layout w/ non-DS input attachment
10769 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10770 VkSubpassDescription subpass = {};
10771 subpass.inputAttachmentCount = 1;
10772 subpass.pInputAttachments = &attach;
10773 VkRenderPassCreateInfo rpci = {};
10774 rpci.subpassCount = 1;
10775 rpci.pSubpasses = &subpass;
10776 rpci.attachmentCount = 1;
10777 VkAttachmentDescription attach_desc = {};
10778 attach_desc.format = VK_FORMAT_UNDEFINED;
10779 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010780 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010781 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10783 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010784 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10785 m_errorMonitor->VerifyFound();
10786 // error w/ non-general layout
10787 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10788
10789 m_errorMonitor->SetDesiredFailureMsg(
10790 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10791 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10792 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10793 m_errorMonitor->VerifyFound();
10794 subpass.inputAttachmentCount = 0;
10795 subpass.colorAttachmentCount = 1;
10796 subpass.pColorAttachments = &attach;
10797 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10798 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10800 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010801 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10802 m_errorMonitor->VerifyFound();
10803 // error w/ non-color opt or GENERAL layout for color attachment
10804 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10805 m_errorMonitor->SetDesiredFailureMsg(
10806 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10807 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10808 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10809 m_errorMonitor->VerifyFound();
10810 subpass.colorAttachmentCount = 0;
10811 subpass.pDepthStencilAttachment = &attach;
10812 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10813 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10815 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010816 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10817 m_errorMonitor->VerifyFound();
10818 // error w/ non-ds opt or GENERAL layout for color attachment
10819 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10821 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10822 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010823 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10824 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010825 // For this error we need a valid renderpass so create default one
10826 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10827 attach.attachment = 0;
10828 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10829 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10830 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10831 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10832 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10833 // Can't do a CLEAR load on READ_ONLY initialLayout
10834 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10835 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10836 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10838 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10839 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010840 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10841 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010842
Cort3b021012016-12-07 12:00:57 -080010843 vkFreeMemory(m_device->device(), src_image_mem, NULL);
10844 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
10845 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010846 vkDestroyImage(m_device->device(), src_image, NULL);
10847 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080010848 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010849}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010850
Tobin Ehlise0936662016-10-11 08:10:51 -060010851TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10852 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10853 VkResult err;
10854
10855 ASSERT_NO_FATAL_FAILURE(InitState());
10856
10857 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10858 VkImageTiling tiling;
10859 VkFormatProperties format_properties;
10860 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10861 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10862 tiling = VK_IMAGE_TILING_LINEAR;
10863 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10864 tiling = VK_IMAGE_TILING_OPTIMAL;
10865 } else {
10866 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10867 "skipped.\n");
10868 return;
10869 }
10870
10871 VkDescriptorPoolSize ds_type = {};
10872 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10873 ds_type.descriptorCount = 1;
10874
10875 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10876 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10877 ds_pool_ci.maxSets = 1;
10878 ds_pool_ci.poolSizeCount = 1;
10879 ds_pool_ci.pPoolSizes = &ds_type;
10880 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10881
10882 VkDescriptorPool ds_pool;
10883 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10884 ASSERT_VK_SUCCESS(err);
10885
10886 VkDescriptorSetLayoutBinding dsl_binding = {};
10887 dsl_binding.binding = 0;
10888 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10889 dsl_binding.descriptorCount = 1;
10890 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10891 dsl_binding.pImmutableSamplers = NULL;
10892
10893 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10894 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10895 ds_layout_ci.pNext = NULL;
10896 ds_layout_ci.bindingCount = 1;
10897 ds_layout_ci.pBindings = &dsl_binding;
10898
10899 VkDescriptorSetLayout ds_layout;
10900 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10901 ASSERT_VK_SUCCESS(err);
10902
10903 VkDescriptorSetAllocateInfo alloc_info = {};
10904 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10905 alloc_info.descriptorSetCount = 1;
10906 alloc_info.descriptorPool = ds_pool;
10907 alloc_info.pSetLayouts = &ds_layout;
10908 VkDescriptorSet descriptor_set;
10909 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10910 ASSERT_VK_SUCCESS(err);
10911
10912 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10913 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10914 pipeline_layout_ci.pNext = NULL;
10915 pipeline_layout_ci.setLayoutCount = 1;
10916 pipeline_layout_ci.pSetLayouts = &ds_layout;
10917 VkPipelineLayout pipeline_layout;
10918 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10919 ASSERT_VK_SUCCESS(err);
10920
10921 VkImageObj image(m_device);
10922 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10923 ASSERT_TRUE(image.initialized());
10924 VkImageView view = image.targetView(tex_format);
10925
10926 VkDescriptorImageInfo image_info = {};
10927 image_info.imageView = view;
10928 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10929
10930 VkWriteDescriptorSet descriptor_write = {};
10931 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10932 descriptor_write.dstSet = descriptor_set;
10933 descriptor_write.dstBinding = 0;
10934 descriptor_write.descriptorCount = 1;
10935 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10936 descriptor_write.pImageInfo = &image_info;
10937
10938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10939 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10940 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10941 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10942 m_errorMonitor->VerifyFound();
10943
10944 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10945 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10946 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10947 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10948}
10949
Mark Mueller93b938f2016-08-18 10:27:40 -060010950TEST_F(VkLayerTest, SimultaneousUse) {
10951 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10952 "in primary and secondary command buffers.");
10953
10954 ASSERT_NO_FATAL_FAILURE(InitState());
10955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10956
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010957 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010958 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10959 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010960
10961 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010962 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010963 command_buffer_allocate_info.commandPool = m_commandPool;
10964 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10965 command_buffer_allocate_info.commandBufferCount = 1;
10966
10967 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010968 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010969 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10970 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010971 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010972 command_buffer_inheritance_info.renderPass = m_renderPass;
10973 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10974 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010975 command_buffer_begin_info.flags =
10976 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010977 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10978
10979 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010980 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10981 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010982 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010983 vkEndCommandBuffer(secondary_command_buffer);
10984
Mark Mueller93b938f2016-08-18 10:27:40 -060010985 VkSubmitInfo submit_info = {};
10986 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10987 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010988 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010989 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010990
Mark Mueller4042b652016-09-05 22:52:21 -060010991 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010992 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10994 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010995 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010996 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10997 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010998
10999 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060011000 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11001
Mark Mueller4042b652016-09-05 22:52:21 -060011002 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011003 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011004 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11007 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011008 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011009 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11010 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011011}
11012
Mark Mueller917f6bc2016-08-30 10:57:19 -060011013TEST_F(VkLayerTest, InUseDestroyedSignaled) {
11014 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11015 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060011016 "Delete objects that are inuse. Call VkQueueSubmit "
11017 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011018
11019 ASSERT_NO_FATAL_FAILURE(InitState());
11020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011022 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
11023 const char *cannot_delete_event_message = "Cannot delete event 0x";
11024 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
11025 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011026
11027 BeginCommandBuffer();
11028
11029 VkEvent event;
11030 VkEventCreateInfo event_create_info = {};
11031 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11032 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011033 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011034
Mark Muellerc8d441e2016-08-23 17:36:00 -060011035 EndCommandBuffer();
11036 vkDestroyEvent(m_device->device(), event, nullptr);
11037
11038 VkSubmitInfo submit_info = {};
11039 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11040 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011041 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011043 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11044 m_errorMonitor->VerifyFound();
11045
11046 m_errorMonitor->SetDesiredFailureMsg(0, "");
11047 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11048
11049 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11050
Mark Mueller917f6bc2016-08-30 10:57:19 -060011051 VkSemaphoreCreateInfo semaphore_create_info = {};
11052 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11053 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011054 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011055 VkFenceCreateInfo fence_create_info = {};
11056 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11057 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011058 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011059
11060 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011061 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011062 descriptor_pool_type_count.descriptorCount = 1;
11063
11064 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11065 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11066 descriptor_pool_create_info.maxSets = 1;
11067 descriptor_pool_create_info.poolSizeCount = 1;
11068 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011069 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011070
11071 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011072 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011073
11074 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011075 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011076 descriptorset_layout_binding.descriptorCount = 1;
11077 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11078
11079 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011080 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011081 descriptorset_layout_create_info.bindingCount = 1;
11082 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11083
11084 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011085 ASSERT_VK_SUCCESS(
11086 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011087
11088 VkDescriptorSet descriptorset;
11089 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011090 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011091 descriptorset_allocate_info.descriptorSetCount = 1;
11092 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11093 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011094 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011095
Mark Mueller4042b652016-09-05 22:52:21 -060011096 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11097
11098 VkDescriptorBufferInfo buffer_info = {};
11099 buffer_info.buffer = buffer_test.GetBuffer();
11100 buffer_info.offset = 0;
11101 buffer_info.range = 1024;
11102
11103 VkWriteDescriptorSet write_descriptor_set = {};
11104 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11105 write_descriptor_set.dstSet = descriptorset;
11106 write_descriptor_set.descriptorCount = 1;
11107 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11108 write_descriptor_set.pBufferInfo = &buffer_info;
11109
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011110 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011111
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011112 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11113 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011114
11115 VkPipelineObj pipe(m_device);
11116 pipe.AddColorAttachment();
11117 pipe.AddShader(&vs);
11118 pipe.AddShader(&fs);
11119
11120 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011121 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011122 pipeline_layout_create_info.setLayoutCount = 1;
11123 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11124
11125 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011126 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011127
11128 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11129
Mark Muellerc8d441e2016-08-23 17:36:00 -060011130 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011131 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011132
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011133 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11134 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11135 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011136
Mark Muellerc8d441e2016-08-23 17:36:00 -060011137 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011138
Mark Mueller917f6bc2016-08-30 10:57:19 -060011139 submit_info.signalSemaphoreCount = 1;
11140 submit_info.pSignalSemaphores = &semaphore;
11141 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011142
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011144 vkDestroyEvent(m_device->device(), event, nullptr);
11145 m_errorMonitor->VerifyFound();
11146
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011148 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11149 m_errorMonitor->VerifyFound();
11150
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011152 vkDestroyFence(m_device->device(), fence, nullptr);
11153 m_errorMonitor->VerifyFound();
11154
Tobin Ehlis122207b2016-09-01 08:50:06 -070011155 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011156 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11157 vkDestroyFence(m_device->device(), fence, nullptr);
11158 vkDestroyEvent(m_device->device(), event, nullptr);
11159 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011160 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011161 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11162}
11163
Tobin Ehlis2adda372016-09-01 08:51:06 -070011164TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11165 TEST_DESCRIPTION("Delete in-use query pool.");
11166
11167 ASSERT_NO_FATAL_FAILURE(InitState());
11168 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11169
11170 VkQueryPool query_pool;
11171 VkQueryPoolCreateInfo query_pool_ci{};
11172 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11173 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11174 query_pool_ci.queryCount = 1;
11175 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
11176 BeginCommandBuffer();
11177 // Reset query pool to create binding with cmd buffer
11178 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11179
11180 EndCommandBuffer();
11181
11182 VkSubmitInfo submit_info = {};
11183 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11184 submit_info.commandBufferCount = 1;
11185 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11186 // Submit cmd buffer and then destroy query pool while in-flight
11187 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070011190 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11191 m_errorMonitor->VerifyFound();
11192
11193 vkQueueWaitIdle(m_device->m_queue);
11194 // Now that cmd buffer done we can safely destroy query_pool
11195 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11196}
11197
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011198TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11199 TEST_DESCRIPTION("Delete in-use pipeline.");
11200
11201 ASSERT_NO_FATAL_FAILURE(InitState());
11202 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11203
11204 // Empty pipeline layout used for binding PSO
11205 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11206 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11207 pipeline_layout_ci.setLayoutCount = 0;
11208 pipeline_layout_ci.pSetLayouts = NULL;
11209
11210 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011211 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011212 ASSERT_VK_SUCCESS(err);
11213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011215 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011216 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11217 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011218 // Store pipeline handle so we can actually delete it before test finishes
11219 VkPipeline delete_this_pipeline;
11220 { // Scope pipeline so it will be auto-deleted
11221 VkPipelineObj pipe(m_device);
11222 pipe.AddShader(&vs);
11223 pipe.AddShader(&fs);
11224 pipe.AddColorAttachment();
11225 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11226 delete_this_pipeline = pipe.handle();
11227
11228 BeginCommandBuffer();
11229 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011230 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011231
11232 EndCommandBuffer();
11233
11234 VkSubmitInfo submit_info = {};
11235 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11236 submit_info.commandBufferCount = 1;
11237 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11238 // Submit cmd buffer and then pipeline destroyed while in-flight
11239 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11240 } // Pipeline deletion triggered here
11241 m_errorMonitor->VerifyFound();
11242 // Make sure queue finished and then actually delete pipeline
11243 vkQueueWaitIdle(m_device->m_queue);
11244 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11245 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11246}
11247
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011248TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11249 TEST_DESCRIPTION("Delete in-use imageView.");
11250
11251 ASSERT_NO_FATAL_FAILURE(InitState());
11252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11253
11254 VkDescriptorPoolSize ds_type_count;
11255 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11256 ds_type_count.descriptorCount = 1;
11257
11258 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11259 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11260 ds_pool_ci.maxSets = 1;
11261 ds_pool_ci.poolSizeCount = 1;
11262 ds_pool_ci.pPoolSizes = &ds_type_count;
11263
11264 VkDescriptorPool ds_pool;
11265 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11266 ASSERT_VK_SUCCESS(err);
11267
11268 VkSamplerCreateInfo sampler_ci = {};
11269 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11270 sampler_ci.pNext = NULL;
11271 sampler_ci.magFilter = VK_FILTER_NEAREST;
11272 sampler_ci.minFilter = VK_FILTER_NEAREST;
11273 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11274 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11275 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11276 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11277 sampler_ci.mipLodBias = 1.0;
11278 sampler_ci.anisotropyEnable = VK_FALSE;
11279 sampler_ci.maxAnisotropy = 1;
11280 sampler_ci.compareEnable = VK_FALSE;
11281 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11282 sampler_ci.minLod = 1.0;
11283 sampler_ci.maxLod = 1.0;
11284 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11285 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11286 VkSampler sampler;
11287
11288 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11289 ASSERT_VK_SUCCESS(err);
11290
11291 VkDescriptorSetLayoutBinding layout_binding;
11292 layout_binding.binding = 0;
11293 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11294 layout_binding.descriptorCount = 1;
11295 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11296 layout_binding.pImmutableSamplers = NULL;
11297
11298 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11299 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11300 ds_layout_ci.bindingCount = 1;
11301 ds_layout_ci.pBindings = &layout_binding;
11302 VkDescriptorSetLayout ds_layout;
11303 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11304 ASSERT_VK_SUCCESS(err);
11305
11306 VkDescriptorSetAllocateInfo alloc_info = {};
11307 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11308 alloc_info.descriptorSetCount = 1;
11309 alloc_info.descriptorPool = ds_pool;
11310 alloc_info.pSetLayouts = &ds_layout;
11311 VkDescriptorSet descriptor_set;
11312 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11313 ASSERT_VK_SUCCESS(err);
11314
11315 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11316 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11317 pipeline_layout_ci.pNext = NULL;
11318 pipeline_layout_ci.setLayoutCount = 1;
11319 pipeline_layout_ci.pSetLayouts = &ds_layout;
11320
11321 VkPipelineLayout pipeline_layout;
11322 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11323 ASSERT_VK_SUCCESS(err);
11324
11325 VkImageObj image(m_device);
11326 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11327 ASSERT_TRUE(image.initialized());
11328
11329 VkImageView view;
11330 VkImageViewCreateInfo ivci = {};
11331 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11332 ivci.image = image.handle();
11333 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11334 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11335 ivci.subresourceRange.layerCount = 1;
11336 ivci.subresourceRange.baseMipLevel = 0;
11337 ivci.subresourceRange.levelCount = 1;
11338 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11339
11340 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11341 ASSERT_VK_SUCCESS(err);
11342
11343 VkDescriptorImageInfo image_info{};
11344 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11345 image_info.imageView = view;
11346 image_info.sampler = sampler;
11347
11348 VkWriteDescriptorSet descriptor_write = {};
11349 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11350 descriptor_write.dstSet = descriptor_set;
11351 descriptor_write.dstBinding = 0;
11352 descriptor_write.descriptorCount = 1;
11353 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11354 descriptor_write.pImageInfo = &image_info;
11355
11356 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11357
11358 // Create PSO to use the sampler
11359 char const *vsSource = "#version 450\n"
11360 "\n"
11361 "out gl_PerVertex { \n"
11362 " vec4 gl_Position;\n"
11363 "};\n"
11364 "void main(){\n"
11365 " gl_Position = vec4(1);\n"
11366 "}\n";
11367 char const *fsSource = "#version 450\n"
11368 "\n"
11369 "layout(set=0, binding=0) uniform sampler2D s;\n"
11370 "layout(location=0) out vec4 x;\n"
11371 "void main(){\n"
11372 " x = texture(s, vec2(1));\n"
11373 "}\n";
11374 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11375 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11376 VkPipelineObj pipe(m_device);
11377 pipe.AddShader(&vs);
11378 pipe.AddShader(&fs);
11379 pipe.AddColorAttachment();
11380 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11381
11382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
11383
11384 BeginCommandBuffer();
11385 // Bind pipeline to cmd buffer
11386 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11387 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11388 &descriptor_set, 0, nullptr);
11389 Draw(1, 0, 0, 0);
11390 EndCommandBuffer();
11391 // Submit cmd buffer then destroy sampler
11392 VkSubmitInfo submit_info = {};
11393 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11394 submit_info.commandBufferCount = 1;
11395 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11396 // Submit cmd buffer and then destroy imageView while in-flight
11397 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11398
11399 vkDestroyImageView(m_device->device(), view, nullptr);
11400 m_errorMonitor->VerifyFound();
11401 vkQueueWaitIdle(m_device->m_queue);
11402 // Now we can actually destroy imageView
11403 vkDestroyImageView(m_device->device(), view, NULL);
11404 vkDestroySampler(m_device->device(), sampler, nullptr);
11405 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11406 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11407 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11408}
11409
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011410TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11411 TEST_DESCRIPTION("Delete in-use bufferView.");
11412
11413 ASSERT_NO_FATAL_FAILURE(InitState());
11414 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11415
11416 VkDescriptorPoolSize ds_type_count;
11417 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11418 ds_type_count.descriptorCount = 1;
11419
11420 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11421 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11422 ds_pool_ci.maxSets = 1;
11423 ds_pool_ci.poolSizeCount = 1;
11424 ds_pool_ci.pPoolSizes = &ds_type_count;
11425
11426 VkDescriptorPool ds_pool;
11427 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11428 ASSERT_VK_SUCCESS(err);
11429
11430 VkDescriptorSetLayoutBinding layout_binding;
11431 layout_binding.binding = 0;
11432 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11433 layout_binding.descriptorCount = 1;
11434 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11435 layout_binding.pImmutableSamplers = NULL;
11436
11437 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11438 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11439 ds_layout_ci.bindingCount = 1;
11440 ds_layout_ci.pBindings = &layout_binding;
11441 VkDescriptorSetLayout ds_layout;
11442 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11443 ASSERT_VK_SUCCESS(err);
11444
11445 VkDescriptorSetAllocateInfo alloc_info = {};
11446 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11447 alloc_info.descriptorSetCount = 1;
11448 alloc_info.descriptorPool = ds_pool;
11449 alloc_info.pSetLayouts = &ds_layout;
11450 VkDescriptorSet descriptor_set;
11451 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11452 ASSERT_VK_SUCCESS(err);
11453
11454 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11455 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11456 pipeline_layout_ci.pNext = NULL;
11457 pipeline_layout_ci.setLayoutCount = 1;
11458 pipeline_layout_ci.pSetLayouts = &ds_layout;
11459
11460 VkPipelineLayout pipeline_layout;
11461 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11462 ASSERT_VK_SUCCESS(err);
11463
11464 VkBuffer buffer;
11465 uint32_t queue_family_index = 0;
11466 VkBufferCreateInfo buffer_create_info = {};
11467 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11468 buffer_create_info.size = 1024;
11469 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11470 buffer_create_info.queueFamilyIndexCount = 1;
11471 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11472
11473 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11474 ASSERT_VK_SUCCESS(err);
11475
11476 VkMemoryRequirements memory_reqs;
11477 VkDeviceMemory buffer_memory;
11478
11479 VkMemoryAllocateInfo memory_info = {};
11480 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11481 memory_info.allocationSize = 0;
11482 memory_info.memoryTypeIndex = 0;
11483
11484 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11485 memory_info.allocationSize = memory_reqs.size;
11486 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11487 ASSERT_TRUE(pass);
11488
11489 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11490 ASSERT_VK_SUCCESS(err);
11491 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11492 ASSERT_VK_SUCCESS(err);
11493
11494 VkBufferView view;
11495 VkBufferViewCreateInfo bvci = {};
11496 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11497 bvci.buffer = buffer;
11498 bvci.format = VK_FORMAT_R8_UNORM;
11499 bvci.range = VK_WHOLE_SIZE;
11500
11501 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11502 ASSERT_VK_SUCCESS(err);
11503
11504 VkWriteDescriptorSet descriptor_write = {};
11505 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11506 descriptor_write.dstSet = descriptor_set;
11507 descriptor_write.dstBinding = 0;
11508 descriptor_write.descriptorCount = 1;
11509 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11510 descriptor_write.pTexelBufferView = &view;
11511
11512 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11513
11514 char const *vsSource = "#version 450\n"
11515 "\n"
11516 "out gl_PerVertex { \n"
11517 " vec4 gl_Position;\n"
11518 "};\n"
11519 "void main(){\n"
11520 " gl_Position = vec4(1);\n"
11521 "}\n";
11522 char const *fsSource = "#version 450\n"
11523 "\n"
11524 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11525 "layout(location=0) out vec4 x;\n"
11526 "void main(){\n"
11527 " x = imageLoad(s, 0);\n"
11528 "}\n";
11529 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11530 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11531 VkPipelineObj pipe(m_device);
11532 pipe.AddShader(&vs);
11533 pipe.AddShader(&fs);
11534 pipe.AddColorAttachment();
11535 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11536
11537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11538
11539 BeginCommandBuffer();
11540 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11541 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11542 VkRect2D scissor = {{0, 0}, {16, 16}};
11543 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11544 // Bind pipeline to cmd buffer
11545 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11546 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11547 &descriptor_set, 0, nullptr);
11548 Draw(1, 0, 0, 0);
11549 EndCommandBuffer();
11550
11551 VkSubmitInfo submit_info = {};
11552 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11553 submit_info.commandBufferCount = 1;
11554 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11555 // Submit cmd buffer and then destroy bufferView while in-flight
11556 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11557
11558 vkDestroyBufferView(m_device->device(), view, nullptr);
11559 m_errorMonitor->VerifyFound();
11560 vkQueueWaitIdle(m_device->m_queue);
11561 // Now we can actually destroy bufferView
11562 vkDestroyBufferView(m_device->device(), view, NULL);
11563 vkDestroyBuffer(m_device->device(), buffer, NULL);
11564 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11565 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11566 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11567 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11568}
11569
Tobin Ehlis209532e2016-09-07 13:52:18 -060011570TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11571 TEST_DESCRIPTION("Delete in-use sampler.");
11572
11573 ASSERT_NO_FATAL_FAILURE(InitState());
11574 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11575
11576 VkDescriptorPoolSize ds_type_count;
11577 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11578 ds_type_count.descriptorCount = 1;
11579
11580 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11581 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11582 ds_pool_ci.maxSets = 1;
11583 ds_pool_ci.poolSizeCount = 1;
11584 ds_pool_ci.pPoolSizes = &ds_type_count;
11585
11586 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011587 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011588 ASSERT_VK_SUCCESS(err);
11589
11590 VkSamplerCreateInfo sampler_ci = {};
11591 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11592 sampler_ci.pNext = NULL;
11593 sampler_ci.magFilter = VK_FILTER_NEAREST;
11594 sampler_ci.minFilter = VK_FILTER_NEAREST;
11595 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11596 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11597 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11598 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11599 sampler_ci.mipLodBias = 1.0;
11600 sampler_ci.anisotropyEnable = VK_FALSE;
11601 sampler_ci.maxAnisotropy = 1;
11602 sampler_ci.compareEnable = VK_FALSE;
11603 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11604 sampler_ci.minLod = 1.0;
11605 sampler_ci.maxLod = 1.0;
11606 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11607 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11608 VkSampler sampler;
11609
11610 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11611 ASSERT_VK_SUCCESS(err);
11612
11613 VkDescriptorSetLayoutBinding layout_binding;
11614 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011615 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011616 layout_binding.descriptorCount = 1;
11617 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11618 layout_binding.pImmutableSamplers = NULL;
11619
11620 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11621 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11622 ds_layout_ci.bindingCount = 1;
11623 ds_layout_ci.pBindings = &layout_binding;
11624 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011625 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011626 ASSERT_VK_SUCCESS(err);
11627
11628 VkDescriptorSetAllocateInfo alloc_info = {};
11629 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11630 alloc_info.descriptorSetCount = 1;
11631 alloc_info.descriptorPool = ds_pool;
11632 alloc_info.pSetLayouts = &ds_layout;
11633 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011634 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011635 ASSERT_VK_SUCCESS(err);
11636
11637 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11638 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11639 pipeline_layout_ci.pNext = NULL;
11640 pipeline_layout_ci.setLayoutCount = 1;
11641 pipeline_layout_ci.pSetLayouts = &ds_layout;
11642
11643 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011644 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011645 ASSERT_VK_SUCCESS(err);
11646
11647 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011648 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 -060011649 ASSERT_TRUE(image.initialized());
11650
11651 VkImageView view;
11652 VkImageViewCreateInfo ivci = {};
11653 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11654 ivci.image = image.handle();
11655 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11656 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11657 ivci.subresourceRange.layerCount = 1;
11658 ivci.subresourceRange.baseMipLevel = 0;
11659 ivci.subresourceRange.levelCount = 1;
11660 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11661
11662 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11663 ASSERT_VK_SUCCESS(err);
11664
11665 VkDescriptorImageInfo image_info{};
11666 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11667 image_info.imageView = view;
11668 image_info.sampler = sampler;
11669
11670 VkWriteDescriptorSet descriptor_write = {};
11671 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11672 descriptor_write.dstSet = descriptor_set;
11673 descriptor_write.dstBinding = 0;
11674 descriptor_write.descriptorCount = 1;
11675 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11676 descriptor_write.pImageInfo = &image_info;
11677
11678 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11679
11680 // Create PSO to use the sampler
11681 char const *vsSource = "#version 450\n"
11682 "\n"
11683 "out gl_PerVertex { \n"
11684 " vec4 gl_Position;\n"
11685 "};\n"
11686 "void main(){\n"
11687 " gl_Position = vec4(1);\n"
11688 "}\n";
11689 char const *fsSource = "#version 450\n"
11690 "\n"
11691 "layout(set=0, binding=0) uniform sampler2D s;\n"
11692 "layout(location=0) out vec4 x;\n"
11693 "void main(){\n"
11694 " x = texture(s, vec2(1));\n"
11695 "}\n";
11696 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11697 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11698 VkPipelineObj pipe(m_device);
11699 pipe.AddShader(&vs);
11700 pipe.AddShader(&fs);
11701 pipe.AddColorAttachment();
11702 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11703
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011705
11706 BeginCommandBuffer();
11707 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011708 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11709 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11710 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011711 Draw(1, 0, 0, 0);
11712 EndCommandBuffer();
11713 // Submit cmd buffer then destroy sampler
11714 VkSubmitInfo submit_info = {};
11715 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11716 submit_info.commandBufferCount = 1;
11717 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11718 // Submit cmd buffer and then destroy sampler while in-flight
11719 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11720
11721 vkDestroySampler(m_device->device(), sampler, nullptr);
11722 m_errorMonitor->VerifyFound();
11723 vkQueueWaitIdle(m_device->m_queue);
11724 // Now we can actually destroy sampler
11725 vkDestroySampler(m_device->device(), sampler, nullptr);
11726 vkDestroyImageView(m_device->device(), view, NULL);
11727 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11728 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11729 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11730}
11731
Mark Mueller1cd9f412016-08-25 13:23:52 -060011732TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011733 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011734 "signaled but not waited on by the queue. Wait on a "
11735 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011736
11737 ASSERT_NO_FATAL_FAILURE(InitState());
11738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11739
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011740 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11741 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11742 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011743
11744 BeginCommandBuffer();
11745 EndCommandBuffer();
11746
11747 VkSemaphoreCreateInfo semaphore_create_info = {};
11748 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11749 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011750 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011751 VkSubmitInfo submit_info = {};
11752 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11753 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011754 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011755 submit_info.signalSemaphoreCount = 1;
11756 submit_info.pSignalSemaphores = &semaphore;
11757 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11758 m_errorMonitor->SetDesiredFailureMsg(0, "");
11759 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11760 BeginCommandBuffer();
11761 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011763 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11764 m_errorMonitor->VerifyFound();
11765
Mark Mueller1cd9f412016-08-25 13:23:52 -060011766 VkFenceCreateInfo fence_create_info = {};
11767 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11768 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011769 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011770
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011772 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11773 m_errorMonitor->VerifyFound();
11774
Mark Mueller4042b652016-09-05 22:52:21 -060011775 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011776 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011777 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11778}
11779
Tobin Ehlis4af23302016-07-19 10:50:30 -060011780TEST_F(VkLayerTest, FramebufferIncompatible) {
11781 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11782 "that does not match the framebuffer for the active "
11783 "renderpass.");
11784 ASSERT_NO_FATAL_FAILURE(InitState());
11785 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11786
11787 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011788 VkAttachmentDescription attachment = {0,
11789 VK_FORMAT_B8G8R8A8_UNORM,
11790 VK_SAMPLE_COUNT_1_BIT,
11791 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11792 VK_ATTACHMENT_STORE_OP_STORE,
11793 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11794 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11795 VK_IMAGE_LAYOUT_UNDEFINED,
11796 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011797
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011798 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011799
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011800 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011801
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011802 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011803
11804 VkRenderPass rp;
11805 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11806 ASSERT_VK_SUCCESS(err);
11807
11808 // A compatible framebuffer.
11809 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011810 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 -060011811 ASSERT_TRUE(image.initialized());
11812
11813 VkImageViewCreateInfo ivci = {
11814 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11815 nullptr,
11816 0,
11817 image.handle(),
11818 VK_IMAGE_VIEW_TYPE_2D,
11819 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011820 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11821 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011822 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11823 };
11824 VkImageView view;
11825 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11826 ASSERT_VK_SUCCESS(err);
11827
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011828 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011829 VkFramebuffer fb;
11830 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11831 ASSERT_VK_SUCCESS(err);
11832
11833 VkCommandBufferAllocateInfo cbai = {};
11834 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11835 cbai.commandPool = m_commandPool;
11836 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11837 cbai.commandBufferCount = 1;
11838
11839 VkCommandBuffer sec_cb;
11840 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11841 ASSERT_VK_SUCCESS(err);
11842 VkCommandBufferBeginInfo cbbi = {};
11843 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130011844 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060011845 cbii.renderPass = renderPass();
11846 cbii.framebuffer = fb;
11847 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11848 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011849 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 -060011850 cbbi.pInheritanceInfo = &cbii;
11851 vkBeginCommandBuffer(sec_cb, &cbbi);
11852 vkEndCommandBuffer(sec_cb);
11853
Chris Forbes3400bc52016-09-13 18:10:34 +120011854 VkCommandBufferBeginInfo cbbi2 = {
11855 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11856 0, nullptr
11857 };
11858 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11859 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011860
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011862 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011863 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11864 m_errorMonitor->VerifyFound();
11865 // Cleanup
11866 vkDestroyImageView(m_device->device(), view, NULL);
11867 vkDestroyRenderPass(m_device->device(), rp, NULL);
11868 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11869}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011870
11871TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11872 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11873 "invalid value. If logicOp is not available, attempt to "
11874 "use it and verify that we see the correct error.");
11875 ASSERT_NO_FATAL_FAILURE(InitState());
11876 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11877
11878 auto features = m_device->phy().features();
11879 // Set the expected error depending on whether or not logicOp available
11880 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11882 "enabled, logicOpEnable must be "
11883 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011884 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011886 }
11887 // Create a pipeline using logicOp
11888 VkResult err;
11889
11890 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11891 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11892
11893 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011894 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011895 ASSERT_VK_SUCCESS(err);
11896
11897 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11898 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11899 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011900 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011901 vp_state_ci.pViewports = &vp;
11902 vp_state_ci.scissorCount = 1;
11903 VkRect2D scissors = {}; // Dummy scissors to point to
11904 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011905
11906 VkPipelineShaderStageCreateInfo shaderStages[2];
11907 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11908
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011909 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11910 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011911 shaderStages[0] = vs.GetStageCreateInfo();
11912 shaderStages[1] = fs.GetStageCreateInfo();
11913
11914 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11915 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11916
11917 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11918 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11919 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11920
11921 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11922 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011923 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011924
11925 VkPipelineColorBlendAttachmentState att = {};
11926 att.blendEnable = VK_FALSE;
11927 att.colorWriteMask = 0xf;
11928
11929 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11930 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11931 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11932 cb_ci.logicOpEnable = VK_TRUE;
11933 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11934 cb_ci.attachmentCount = 1;
11935 cb_ci.pAttachments = &att;
11936
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011937 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11938 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11939 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11940
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011941 VkGraphicsPipelineCreateInfo gp_ci = {};
11942 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11943 gp_ci.stageCount = 2;
11944 gp_ci.pStages = shaderStages;
11945 gp_ci.pVertexInputState = &vi_ci;
11946 gp_ci.pInputAssemblyState = &ia_ci;
11947 gp_ci.pViewportState = &vp_state_ci;
11948 gp_ci.pRasterizationState = &rs_ci;
11949 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011950 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011951 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11952 gp_ci.layout = pipeline_layout;
11953 gp_ci.renderPass = renderPass();
11954
11955 VkPipelineCacheCreateInfo pc_ci = {};
11956 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11957
11958 VkPipeline pipeline;
11959 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011960 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011961 ASSERT_VK_SUCCESS(err);
11962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011963 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011964 m_errorMonitor->VerifyFound();
11965 if (VK_SUCCESS == err) {
11966 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11967 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011968 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11969 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11970}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011971#endif // DRAW_STATE_TESTS
11972
Tobin Ehlis0788f522015-05-26 16:11:58 -060011973#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011974#if GTEST_IS_THREADSAFE
11975struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011976 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011977 VkEvent event;
11978 bool bailout;
11979};
11980
Karl Schultz6addd812016-02-02 17:17:23 -070011981extern "C" void *AddToCommandBuffer(void *arg) {
11982 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011983
Mike Stroyana6d14942016-07-13 15:10:05 -060011984 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011985 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011986 if (data->bailout) {
11987 break;
11988 }
11989 }
11990 return NULL;
11991}
11992
Karl Schultz6addd812016-02-02 17:17:23 -070011993TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011994 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011995
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011997
Mike Stroyanaccf7692015-05-12 16:00:45 -060011998 ASSERT_NO_FATAL_FAILURE(InitState());
11999 ASSERT_NO_FATAL_FAILURE(InitViewport());
12000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12001
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012002 // Calls AllocateCommandBuffers
12003 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012004
12005 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012006 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012007
12008 VkEventCreateInfo event_info;
12009 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012010 VkResult err;
12011
12012 memset(&event_info, 0, sizeof(event_info));
12013 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12014
Chia-I Wuf7458c52015-10-26 21:10:41 +080012015 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012016 ASSERT_VK_SUCCESS(err);
12017
Mike Stroyanaccf7692015-05-12 16:00:45 -060012018 err = vkResetEvent(device(), event);
12019 ASSERT_VK_SUCCESS(err);
12020
12021 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012022 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012023 data.event = event;
12024 data.bailout = false;
12025 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012026
12027 // First do some correct operations using multiple threads.
12028 // Add many entries to command buffer from another thread.
12029 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12030 // Make non-conflicting calls from this thread at the same time.
12031 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012032 uint32_t count;
12033 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012034 }
12035 test_platform_thread_join(thread, NULL);
12036
12037 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012038 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012039 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012040 // Add many entries to command buffer from this thread at the same time.
12041 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012042
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012043 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012044 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012045
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012046 m_errorMonitor->SetBailout(NULL);
12047
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012048 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012049
Chia-I Wuf7458c52015-10-26 21:10:41 +080012050 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012051}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012052#endif // GTEST_IS_THREADSAFE
12053#endif // THREADING_TESTS
12054
Chris Forbes9f7ff632015-05-25 11:13:08 +120012055#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012056TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012057 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12058 "with an impossible code size");
12059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012061
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012062 ASSERT_NO_FATAL_FAILURE(InitState());
12063 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12064
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012065 VkShaderModule module;
12066 VkShaderModuleCreateInfo moduleCreateInfo;
12067 struct icd_spv_header spv;
12068
12069 spv.magic = ICD_SPV_MAGIC;
12070 spv.version = ICD_SPV_VERSION;
12071 spv.gen_magic = 0;
12072
12073 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12074 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012075 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012076 moduleCreateInfo.codeSize = 4;
12077 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012078 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012079
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012080 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012081}
12082
Karl Schultz6addd812016-02-02 17:17:23 -070012083TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012084 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12085 "with a bad magic number");
12086
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012088
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012089 ASSERT_NO_FATAL_FAILURE(InitState());
12090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12091
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012092 VkShaderModule module;
12093 VkShaderModuleCreateInfo moduleCreateInfo;
12094 struct icd_spv_header spv;
12095
12096 spv.magic = ~ICD_SPV_MAGIC;
12097 spv.version = ICD_SPV_VERSION;
12098 spv.gen_magic = 0;
12099
12100 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12101 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012102 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012103 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12104 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012105 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012106
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012107 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012108}
12109
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012110#if 0
12111// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012112TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012114 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012115
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012116 ASSERT_NO_FATAL_FAILURE(InitState());
12117 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12118
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012119 VkShaderModule module;
12120 VkShaderModuleCreateInfo moduleCreateInfo;
12121 struct icd_spv_header spv;
12122
12123 spv.magic = ICD_SPV_MAGIC;
12124 spv.version = ~ICD_SPV_VERSION;
12125 spv.gen_magic = 0;
12126
12127 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12128 moduleCreateInfo.pNext = NULL;
12129
Karl Schultz6addd812016-02-02 17:17:23 -070012130 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012131 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12132 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012133 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012134
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012135 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012136}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012137#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012138
Karl Schultz6addd812016-02-02 17:17:23 -070012139TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012140 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
12141 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012143
Chris Forbes9f7ff632015-05-25 11:13:08 +120012144 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012145 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012146
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012147 char const *vsSource = "#version 450\n"
12148 "\n"
12149 "layout(location=0) out float x;\n"
12150 "out gl_PerVertex {\n"
12151 " vec4 gl_Position;\n"
12152 "};\n"
12153 "void main(){\n"
12154 " gl_Position = vec4(1);\n"
12155 " x = 0;\n"
12156 "}\n";
12157 char const *fsSource = "#version 450\n"
12158 "\n"
12159 "layout(location=0) out vec4 color;\n"
12160 "void main(){\n"
12161 " color = vec4(1);\n"
12162 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012163
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012164 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12165 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012166
12167 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012168 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012169 pipe.AddShader(&vs);
12170 pipe.AddShader(&fs);
12171
Chris Forbes9f7ff632015-05-25 11:13:08 +120012172 VkDescriptorSetObj descriptorSet(m_device);
12173 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012174 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012175
Tony Barbour5781e8f2015-08-04 16:23:11 -060012176 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012177
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012178 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012179}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012180
Mark Mueller098c9cb2016-09-08 09:01:57 -060012181TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12182 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12183
12184 ASSERT_NO_FATAL_FAILURE(InitState());
12185 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12186
12187 const char *bad_specialization_message =
12188 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
12189
12190 char const *vsSource =
12191 "#version 450\n"
12192 "\n"
12193 "out gl_PerVertex {\n"
12194 " vec4 gl_Position;\n"
12195 "};\n"
12196 "void main(){\n"
12197 " gl_Position = vec4(1);\n"
12198 "}\n";
12199
12200 char const *fsSource =
12201 "#version 450\n"
12202 "\n"
12203 "layout (constant_id = 0) const float r = 0.0f;\n"
12204 "layout(location = 0) out vec4 uFragColor;\n"
12205 "void main(){\n"
12206 " uFragColor = vec4(r,1,0,1);\n"
12207 "}\n";
12208
12209 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12210 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12211
12212 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12213 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12214
12215 VkPipelineLayout pipeline_layout;
12216 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12217
12218 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12219 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12220 vp_state_create_info.viewportCount = 1;
12221 VkViewport viewport = {};
12222 vp_state_create_info.pViewports = &viewport;
12223 vp_state_create_info.scissorCount = 1;
12224 VkRect2D scissors = {};
12225 vp_state_create_info.pScissors = &scissors;
12226
12227 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12228
12229 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12230 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12231 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12232 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12233
12234 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
12235 vs.GetStageCreateInfo(),
12236 fs.GetStageCreateInfo()
12237 };
12238
12239 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12240 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12241
12242 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12243 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12244 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12245
12246 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12247 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12248 rasterization_state_create_info.pNext = nullptr;
12249 rasterization_state_create_info.lineWidth = 1.0f;
12250 rasterization_state_create_info.rasterizerDiscardEnable = true;
12251
12252 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12253 color_blend_attachment_state.blendEnable = VK_FALSE;
12254 color_blend_attachment_state.colorWriteMask = 0xf;
12255
12256 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12257 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12258 color_blend_state_create_info.attachmentCount = 1;
12259 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12260
12261 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12262 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12263 graphicspipe_create_info.stageCount = 2;
12264 graphicspipe_create_info.pStages = shader_stage_create_info;
12265 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12266 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12267 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12268 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12269 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12270 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12271 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12272 graphicspipe_create_info.layout = pipeline_layout;
12273 graphicspipe_create_info.renderPass = renderPass();
12274
12275 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12276 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12277
12278 VkPipelineCache pipelineCache;
12279 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12280
12281 // This structure maps constant ids to data locations.
12282 const VkSpecializationMapEntry entry =
12283 // id, offset, size
12284 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12285
12286 uint32_t data = 1;
12287
12288 // Set up the info describing spec map and data
12289 const VkSpecializationInfo specialization_info = {
12290 1,
12291 &entry,
12292 1 * sizeof(float),
12293 &data,
12294 };
12295 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12296
12297 VkPipeline pipeline;
12298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12299 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12300 m_errorMonitor->VerifyFound();
12301
12302 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12303 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12304}
12305
12306TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12307 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12308
12309 ASSERT_NO_FATAL_FAILURE(InitState());
12310 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12311
12312 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12313
12314 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12315 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12316 descriptor_pool_type_count[0].descriptorCount = 1;
12317 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12318 descriptor_pool_type_count[1].descriptorCount = 1;
12319
12320 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12321 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12322 descriptor_pool_create_info.maxSets = 1;
12323 descriptor_pool_create_info.poolSizeCount = 2;
12324 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12325 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12326
12327 VkDescriptorPool descriptorset_pool;
12328 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12329
12330 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12331 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12332 descriptorset_layout_binding.descriptorCount = 1;
12333 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12334
12335 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12336 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12337 descriptorset_layout_create_info.bindingCount = 1;
12338 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12339
12340 VkDescriptorSetLayout descriptorset_layout;
12341 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12342
12343 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12344 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12345 descriptorset_allocate_info.descriptorSetCount = 1;
12346 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12347 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12348 VkDescriptorSet descriptorset;
12349 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12350
12351 // Challenge core_validation with a non uniform buffer type.
12352 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12353
Mark Mueller098c9cb2016-09-08 09:01:57 -060012354 char const *vsSource =
12355 "#version 450\n"
12356 "\n"
12357 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12358 " mat4 mvp;\n"
12359 "} ubuf;\n"
12360 "out gl_PerVertex {\n"
12361 " vec4 gl_Position;\n"
12362 "};\n"
12363 "void main(){\n"
12364 " gl_Position = ubuf.mvp * vec4(1);\n"
12365 "}\n";
12366
12367 char const *fsSource =
12368 "#version 450\n"
12369 "\n"
12370 "layout(location = 0) out vec4 uFragColor;\n"
12371 "void main(){\n"
12372 " uFragColor = vec4(0,1,0,1);\n"
12373 "}\n";
12374
12375 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12376 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12377
12378 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12379 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12380 pipeline_layout_create_info.setLayoutCount = 1;
12381 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12382
12383 VkPipelineLayout pipeline_layout;
12384 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12385
12386 VkPipelineObj pipe(m_device);
12387 pipe.AddColorAttachment();
12388 pipe.AddShader(&vs);
12389 pipe.AddShader(&fs);
12390
12391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12392 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12393 m_errorMonitor->VerifyFound();
12394
12395 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12396 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12397 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12398}
12399
12400TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12401 TEST_DESCRIPTION(
12402 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12403
12404 ASSERT_NO_FATAL_FAILURE(InitState());
12405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12406
12407 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12408
12409 VkDescriptorPoolSize descriptor_pool_type_count = {};
12410 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12411 descriptor_pool_type_count.descriptorCount = 1;
12412
12413 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12414 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12415 descriptor_pool_create_info.maxSets = 1;
12416 descriptor_pool_create_info.poolSizeCount = 1;
12417 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12418 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12419
12420 VkDescriptorPool descriptorset_pool;
12421 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12422
12423 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12424 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12425 descriptorset_layout_binding.descriptorCount = 1;
12426 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12427 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12428
12429 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12430 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12431 descriptorset_layout_create_info.bindingCount = 1;
12432 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12433
12434 VkDescriptorSetLayout descriptorset_layout;
12435 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12436 nullptr, &descriptorset_layout));
12437
12438 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12439 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12440 descriptorset_allocate_info.descriptorSetCount = 1;
12441 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12442 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12443 VkDescriptorSet descriptorset;
12444 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12445
12446 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12447
Mark Mueller098c9cb2016-09-08 09:01:57 -060012448 char const *vsSource =
12449 "#version 450\n"
12450 "\n"
12451 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12452 " mat4 mvp;\n"
12453 "} ubuf;\n"
12454 "out gl_PerVertex {\n"
12455 " vec4 gl_Position;\n"
12456 "};\n"
12457 "void main(){\n"
12458 " gl_Position = ubuf.mvp * vec4(1);\n"
12459 "}\n";
12460
12461 char const *fsSource =
12462 "#version 450\n"
12463 "\n"
12464 "layout(location = 0) out vec4 uFragColor;\n"
12465 "void main(){\n"
12466 " uFragColor = vec4(0,1,0,1);\n"
12467 "}\n";
12468
12469 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12470 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12471
12472 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12473 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12474 pipeline_layout_create_info.setLayoutCount = 1;
12475 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12476
12477 VkPipelineLayout pipeline_layout;
12478 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12479
12480 VkPipelineObj pipe(m_device);
12481 pipe.AddColorAttachment();
12482 pipe.AddShader(&vs);
12483 pipe.AddShader(&fs);
12484
12485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12486 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12487 m_errorMonitor->VerifyFound();
12488
12489 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12490 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12491 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12492}
12493
12494TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12495 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12496 "accessible from the current shader stage.");
12497
12498 ASSERT_NO_FATAL_FAILURE(InitState());
12499 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12500
12501 const char *push_constant_not_accessible_message =
12502 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12503
12504 char const *vsSource =
12505 "#version 450\n"
12506 "\n"
12507 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12508 "out gl_PerVertex {\n"
12509 " vec4 gl_Position;\n"
12510 "};\n"
12511 "void main(){\n"
12512 " gl_Position = vec4(consts.x);\n"
12513 "}\n";
12514
12515 char const *fsSource =
12516 "#version 450\n"
12517 "\n"
12518 "layout(location = 0) out vec4 uFragColor;\n"
12519 "void main(){\n"
12520 " uFragColor = vec4(0,1,0,1);\n"
12521 "}\n";
12522
12523 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12524 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12525
12526 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12527 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12528
12529 // Set up a push constant range
12530 VkPushConstantRange push_constant_ranges = {};
12531 // Set to the wrong stage to challenge core_validation
12532 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12533 push_constant_ranges.size = 4;
12534
12535 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12536 pipeline_layout_create_info.pushConstantRangeCount = 1;
12537
12538 VkPipelineLayout pipeline_layout;
12539 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12540
12541 VkPipelineObj pipe(m_device);
12542 pipe.AddColorAttachment();
12543 pipe.AddShader(&vs);
12544 pipe.AddShader(&fs);
12545
12546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12547 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12548 m_errorMonitor->VerifyFound();
12549
12550 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12551}
12552
12553TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12554 TEST_DESCRIPTION(
12555 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12556
12557 ASSERT_NO_FATAL_FAILURE(InitState());
12558 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12559
12560 const char *feature_not_enabled_message =
12561 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12562
12563 // Some awkward steps are required to test with custom device features.
12564 std::vector<const char *> device_extension_names;
12565 auto features = m_device->phy().features();
12566 // Disable support for 64 bit floats
12567 features.shaderFloat64 = false;
12568 // The sacrificial device object
12569 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12570
12571 char const *vsSource = "#version 450\n"
12572 "\n"
12573 "out gl_PerVertex {\n"
12574 " vec4 gl_Position;\n"
12575 "};\n"
12576 "void main(){\n"
12577 " gl_Position = vec4(1);\n"
12578 "}\n";
12579 char const *fsSource = "#version 450\n"
12580 "\n"
12581 "layout(location=0) out vec4 color;\n"
12582 "void main(){\n"
12583 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12584 " color = vec4(green);\n"
12585 "}\n";
12586
12587 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12588 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12589
12590 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012591
12592 VkPipelineObj pipe(&test_device);
12593 pipe.AddColorAttachment();
12594 pipe.AddShader(&vs);
12595 pipe.AddShader(&fs);
12596
12597 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12598 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12599 VkPipelineLayout pipeline_layout;
12600 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12601
12602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12603 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12604 m_errorMonitor->VerifyFound();
12605
12606 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12607}
12608
12609TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12610 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12611
12612 ASSERT_NO_FATAL_FAILURE(InitState());
12613 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12614
12615 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12616
12617 char const *vsSource = "#version 450\n"
12618 "\n"
12619 "out gl_PerVertex {\n"
12620 " vec4 gl_Position;\n"
12621 "};\n"
12622 "layout(xfb_buffer = 1) out;"
12623 "void main(){\n"
12624 " gl_Position = vec4(1);\n"
12625 "}\n";
12626 char const *fsSource = "#version 450\n"
12627 "\n"
12628 "layout(location=0) out vec4 color;\n"
12629 "void main(){\n"
12630 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12631 " color = vec4(green);\n"
12632 "}\n";
12633
12634 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12635 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12636
12637 VkPipelineObj pipe(m_device);
12638 pipe.AddColorAttachment();
12639 pipe.AddShader(&vs);
12640 pipe.AddShader(&fs);
12641
12642 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12643 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12644 VkPipelineLayout pipeline_layout;
12645 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12646
12647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12648 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12649 m_errorMonitor->VerifyFound();
12650
12651 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12652}
12653
Karl Schultz6addd812016-02-02 17:17:23 -070012654TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012655 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12656 "which is not present in the outputs of the previous stage");
12657
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012659
Chris Forbes59cb88d2015-05-25 11:13:13 +120012660 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012661 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012662
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012663 char const *vsSource = "#version 450\n"
12664 "\n"
12665 "out gl_PerVertex {\n"
12666 " vec4 gl_Position;\n"
12667 "};\n"
12668 "void main(){\n"
12669 " gl_Position = vec4(1);\n"
12670 "}\n";
12671 char const *fsSource = "#version 450\n"
12672 "\n"
12673 "layout(location=0) in float x;\n"
12674 "layout(location=0) out vec4 color;\n"
12675 "void main(){\n"
12676 " color = vec4(x);\n"
12677 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012678
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012679 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12680 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012681
12682 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012683 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012684 pipe.AddShader(&vs);
12685 pipe.AddShader(&fs);
12686
Chris Forbes59cb88d2015-05-25 11:13:13 +120012687 VkDescriptorSetObj descriptorSet(m_device);
12688 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012689 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012690
Tony Barbour5781e8f2015-08-04 16:23:11 -060012691 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012692
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012693 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012694}
12695
Karl Schultz6addd812016-02-02 17:17:23 -070012696TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012697 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12698 "within an interace block, which is not present in the outputs "
12699 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012701
12702 ASSERT_NO_FATAL_FAILURE(InitState());
12703 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12704
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012705 char const *vsSource = "#version 450\n"
12706 "\n"
12707 "out gl_PerVertex {\n"
12708 " vec4 gl_Position;\n"
12709 "};\n"
12710 "void main(){\n"
12711 " gl_Position = vec4(1);\n"
12712 "}\n";
12713 char const *fsSource = "#version 450\n"
12714 "\n"
12715 "in block { layout(location=0) float x; } ins;\n"
12716 "layout(location=0) out vec4 color;\n"
12717 "void main(){\n"
12718 " color = vec4(ins.x);\n"
12719 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012720
12721 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12722 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12723
12724 VkPipelineObj pipe(m_device);
12725 pipe.AddColorAttachment();
12726 pipe.AddShader(&vs);
12727 pipe.AddShader(&fs);
12728
12729 VkDescriptorSetObj descriptorSet(m_device);
12730 descriptorSet.AppendDummy();
12731 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12732
12733 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12734
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012735 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012736}
12737
Karl Schultz6addd812016-02-02 17:17:23 -070012738TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012739 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012740 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12742 "output arr[2] of float32' vs 'ptr to "
12743 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012744
12745 ASSERT_NO_FATAL_FAILURE(InitState());
12746 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12747
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012748 char const *vsSource = "#version 450\n"
12749 "\n"
12750 "layout(location=0) out float x[2];\n"
12751 "out gl_PerVertex {\n"
12752 " vec4 gl_Position;\n"
12753 "};\n"
12754 "void main(){\n"
12755 " x[0] = 0; x[1] = 0;\n"
12756 " gl_Position = vec4(1);\n"
12757 "}\n";
12758 char const *fsSource = "#version 450\n"
12759 "\n"
12760 "layout(location=0) in float x[3];\n"
12761 "layout(location=0) out vec4 color;\n"
12762 "void main(){\n"
12763 " color = vec4(x[0] + x[1] + x[2]);\n"
12764 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012765
12766 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12767 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12768
12769 VkPipelineObj pipe(m_device);
12770 pipe.AddColorAttachment();
12771 pipe.AddShader(&vs);
12772 pipe.AddShader(&fs);
12773
12774 VkDescriptorSetObj descriptorSet(m_device);
12775 descriptorSet.AppendDummy();
12776 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12777
12778 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12779
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012780 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012781}
12782
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012783
Karl Schultz6addd812016-02-02 17:17:23 -070012784TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012785 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012786 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012788
Chris Forbesb56af562015-05-25 11:13:17 +120012789 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012791
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012792 char const *vsSource = "#version 450\n"
12793 "\n"
12794 "layout(location=0) out int x;\n"
12795 "out gl_PerVertex {\n"
12796 " vec4 gl_Position;\n"
12797 "};\n"
12798 "void main(){\n"
12799 " x = 0;\n"
12800 " gl_Position = vec4(1);\n"
12801 "}\n";
12802 char const *fsSource = "#version 450\n"
12803 "\n"
12804 "layout(location=0) in float x;\n" /* VS writes int */
12805 "layout(location=0) out vec4 color;\n"
12806 "void main(){\n"
12807 " color = vec4(x);\n"
12808 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012809
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012810 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12811 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012812
12813 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012814 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012815 pipe.AddShader(&vs);
12816 pipe.AddShader(&fs);
12817
Chris Forbesb56af562015-05-25 11:13:17 +120012818 VkDescriptorSetObj descriptorSet(m_device);
12819 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012820 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012821
Tony Barbour5781e8f2015-08-04 16:23:11 -060012822 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012823
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012824 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012825}
12826
Karl Schultz6addd812016-02-02 17:17:23 -070012827TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012828 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012829 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012830 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012832
12833 ASSERT_NO_FATAL_FAILURE(InitState());
12834 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12835
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012836 char const *vsSource = "#version 450\n"
12837 "\n"
12838 "out block { layout(location=0) int x; } outs;\n"
12839 "out gl_PerVertex {\n"
12840 " vec4 gl_Position;\n"
12841 "};\n"
12842 "void main(){\n"
12843 " outs.x = 0;\n"
12844 " gl_Position = vec4(1);\n"
12845 "}\n";
12846 char const *fsSource = "#version 450\n"
12847 "\n"
12848 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12849 "layout(location=0) out vec4 color;\n"
12850 "void main(){\n"
12851 " color = vec4(ins.x);\n"
12852 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012853
12854 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12855 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12856
12857 VkPipelineObj pipe(m_device);
12858 pipe.AddColorAttachment();
12859 pipe.AddShader(&vs);
12860 pipe.AddShader(&fs);
12861
12862 VkDescriptorSetObj descriptorSet(m_device);
12863 descriptorSet.AppendDummy();
12864 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12865
12866 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12867
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012868 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012869}
12870
12871TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012872 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012873 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012874 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012875 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 +130012876
12877 ASSERT_NO_FATAL_FAILURE(InitState());
12878 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12879
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012880 char const *vsSource = "#version 450\n"
12881 "\n"
12882 "out block { layout(location=1) float x; } outs;\n"
12883 "out gl_PerVertex {\n"
12884 " vec4 gl_Position;\n"
12885 "};\n"
12886 "void main(){\n"
12887 " outs.x = 0;\n"
12888 " gl_Position = vec4(1);\n"
12889 "}\n";
12890 char const *fsSource = "#version 450\n"
12891 "\n"
12892 "in block { layout(location=0) float x; } ins;\n"
12893 "layout(location=0) out vec4 color;\n"
12894 "void main(){\n"
12895 " color = vec4(ins.x);\n"
12896 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012897
12898 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12899 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12900
12901 VkPipelineObj pipe(m_device);
12902 pipe.AddColorAttachment();
12903 pipe.AddShader(&vs);
12904 pipe.AddShader(&fs);
12905
12906 VkDescriptorSetObj descriptorSet(m_device);
12907 descriptorSet.AppendDummy();
12908 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12909
12910 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12911
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012912 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012913}
12914
12915TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012916 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012917 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012918 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012919 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 +130012920
12921 ASSERT_NO_FATAL_FAILURE(InitState());
12922 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12923
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012924 char const *vsSource = "#version 450\n"
12925 "\n"
12926 "out block { layout(location=0, component=0) float x; } outs;\n"
12927 "out gl_PerVertex {\n"
12928 " vec4 gl_Position;\n"
12929 "};\n"
12930 "void main(){\n"
12931 " outs.x = 0;\n"
12932 " gl_Position = vec4(1);\n"
12933 "}\n";
12934 char const *fsSource = "#version 450\n"
12935 "\n"
12936 "in block { layout(location=0, component=1) float x; } ins;\n"
12937 "layout(location=0) out vec4 color;\n"
12938 "void main(){\n"
12939 " color = vec4(ins.x);\n"
12940 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012941
12942 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12943 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12944
12945 VkPipelineObj pipe(m_device);
12946 pipe.AddColorAttachment();
12947 pipe.AddShader(&vs);
12948 pipe.AddShader(&fs);
12949
12950 VkDescriptorSetObj descriptorSet(m_device);
12951 descriptorSet.AppendDummy();
12952 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12953
12954 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12955
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012956 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012957}
12958
Chris Forbes1f3b0152016-11-30 12:48:40 +130012959TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
12960 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
12961
12962 ASSERT_NO_FATAL_FAILURE(InitState());
12963 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12964
12965 char const *vsSource = "#version 450\n"
12966 "layout(location=0) out mediump float x;\n"
12967 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
12968 char const *fsSource = "#version 450\n"
12969 "layout(location=0) in highp float x;\n"
12970 "layout(location=0) out vec4 color;\n"
12971 "void main() { color = vec4(x); }\n";
12972
12973 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12974 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12975
12976 VkPipelineObj pipe(m_device);
12977 pipe.AddColorAttachment();
12978 pipe.AddShader(&vs);
12979 pipe.AddShader(&fs);
12980
12981 VkDescriptorSetObj descriptorSet(m_device);
12982 descriptorSet.AppendDummy();
12983 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12984
12985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
12986
12987 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12988
12989 m_errorMonitor->VerifyFound();
12990}
12991
Chris Forbes870a39e2016-11-30 12:55:56 +130012992TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
12993 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
12994
12995 ASSERT_NO_FATAL_FAILURE(InitState());
12996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12997
12998 char const *vsSource = "#version 450\n"
12999 "out block { layout(location=0) mediump float x; };\n"
13000 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13001 char const *fsSource = "#version 450\n"
13002 "in block { layout(location=0) highp float x; };\n"
13003 "layout(location=0) out vec4 color;\n"
13004 "void main() { color = vec4(x); }\n";
13005
13006 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13007 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13008
13009 VkPipelineObj pipe(m_device);
13010 pipe.AddColorAttachment();
13011 pipe.AddShader(&vs);
13012 pipe.AddShader(&fs);
13013
13014 VkDescriptorSetObj descriptorSet(m_device);
13015 descriptorSet.AppendDummy();
13016 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13017
13018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13019
13020 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13021
13022 m_errorMonitor->VerifyFound();
13023}
13024
Karl Schultz6addd812016-02-02 17:17:23 -070013025TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013026 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13027 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013029
Chris Forbesde136e02015-05-25 11:13:28 +120013030 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013031 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013032
13033 VkVertexInputBindingDescription input_binding;
13034 memset(&input_binding, 0, sizeof(input_binding));
13035
13036 VkVertexInputAttributeDescription input_attrib;
13037 memset(&input_attrib, 0, sizeof(input_attrib));
13038 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13039
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013040 char const *vsSource = "#version 450\n"
13041 "\n"
13042 "out gl_PerVertex {\n"
13043 " vec4 gl_Position;\n"
13044 "};\n"
13045 "void main(){\n"
13046 " gl_Position = vec4(1);\n"
13047 "}\n";
13048 char const *fsSource = "#version 450\n"
13049 "\n"
13050 "layout(location=0) out vec4 color;\n"
13051 "void main(){\n"
13052 " color = vec4(1);\n"
13053 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013054
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013055 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13056 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013057
13058 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013059 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013060 pipe.AddShader(&vs);
13061 pipe.AddShader(&fs);
13062
13063 pipe.AddVertexInputBindings(&input_binding, 1);
13064 pipe.AddVertexInputAttribs(&input_attrib, 1);
13065
Chris Forbesde136e02015-05-25 11:13:28 +120013066 VkDescriptorSetObj descriptorSet(m_device);
13067 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013068 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013069
Tony Barbour5781e8f2015-08-04 16:23:11 -060013070 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013071
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013072 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013073}
13074
Karl Schultz6addd812016-02-02 17:17:23 -070013075TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013076 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13077 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013079
13080 ASSERT_NO_FATAL_FAILURE(InitState());
13081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13082
13083 VkVertexInputBindingDescription input_binding;
13084 memset(&input_binding, 0, sizeof(input_binding));
13085
13086 VkVertexInputAttributeDescription input_attrib;
13087 memset(&input_attrib, 0, sizeof(input_attrib));
13088 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13089
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013090 char const *vsSource = "#version 450\n"
13091 "\n"
13092 "layout(location=1) in float x;\n"
13093 "out gl_PerVertex {\n"
13094 " vec4 gl_Position;\n"
13095 "};\n"
13096 "void main(){\n"
13097 " gl_Position = vec4(x);\n"
13098 "}\n";
13099 char const *fsSource = "#version 450\n"
13100 "\n"
13101 "layout(location=0) out vec4 color;\n"
13102 "void main(){\n"
13103 " color = vec4(1);\n"
13104 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013105
13106 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13107 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13108
13109 VkPipelineObj pipe(m_device);
13110 pipe.AddColorAttachment();
13111 pipe.AddShader(&vs);
13112 pipe.AddShader(&fs);
13113
13114 pipe.AddVertexInputBindings(&input_binding, 1);
13115 pipe.AddVertexInputAttribs(&input_attrib, 1);
13116
13117 VkDescriptorSetObj descriptorSet(m_device);
13118 descriptorSet.AppendDummy();
13119 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13120
13121 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13122
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013123 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013124}
13125
Karl Schultz6addd812016-02-02 17:17:23 -070013126TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013127 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013128 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013129 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 -060013130
Chris Forbes62e8e502015-05-25 11:13:29 +120013131 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013134 char const *vsSource = "#version 450\n"
13135 "\n"
13136 "layout(location=0) in vec4 x;\n" /* not provided */
13137 "out gl_PerVertex {\n"
13138 " vec4 gl_Position;\n"
13139 "};\n"
13140 "void main(){\n"
13141 " gl_Position = x;\n"
13142 "}\n";
13143 char const *fsSource = "#version 450\n"
13144 "\n"
13145 "layout(location=0) out vec4 color;\n"
13146 "void main(){\n"
13147 " color = vec4(1);\n"
13148 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013149
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013150 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13151 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013152
13153 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013154 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013155 pipe.AddShader(&vs);
13156 pipe.AddShader(&fs);
13157
Chris Forbes62e8e502015-05-25 11:13:29 +120013158 VkDescriptorSetObj descriptorSet(m_device);
13159 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013160 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013161
Tony Barbour5781e8f2015-08-04 16:23:11 -060013162 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013163
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013164 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013165}
13166
Karl Schultz6addd812016-02-02 17:17:23 -070013167TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013168 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13169 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013170 "vertex shader input that consumes it");
13171 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 -060013172
Chris Forbesc97d98e2015-05-25 11:13:31 +120013173 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013174 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013175
13176 VkVertexInputBindingDescription input_binding;
13177 memset(&input_binding, 0, sizeof(input_binding));
13178
13179 VkVertexInputAttributeDescription input_attrib;
13180 memset(&input_attrib, 0, sizeof(input_attrib));
13181 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013183 char const *vsSource = "#version 450\n"
13184 "\n"
13185 "layout(location=0) in int x;\n" /* attrib provided float */
13186 "out gl_PerVertex {\n"
13187 " vec4 gl_Position;\n"
13188 "};\n"
13189 "void main(){\n"
13190 " gl_Position = vec4(x);\n"
13191 "}\n";
13192 char const *fsSource = "#version 450\n"
13193 "\n"
13194 "layout(location=0) out vec4 color;\n"
13195 "void main(){\n"
13196 " color = vec4(1);\n"
13197 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013198
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013199 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13200 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013201
13202 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013203 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013204 pipe.AddShader(&vs);
13205 pipe.AddShader(&fs);
13206
13207 pipe.AddVertexInputBindings(&input_binding, 1);
13208 pipe.AddVertexInputAttribs(&input_attrib, 1);
13209
Chris Forbesc97d98e2015-05-25 11:13:31 +120013210 VkDescriptorSetObj descriptorSet(m_device);
13211 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013212 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013213
Tony Barbour5781e8f2015-08-04 16:23:11 -060013214 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013215
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013216 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013217}
13218
Chris Forbesc68b43c2016-04-06 11:18:47 +120013219TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013220 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13221 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13223 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013224
13225 ASSERT_NO_FATAL_FAILURE(InitState());
13226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13227
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013228 char const *vsSource = "#version 450\n"
13229 "\n"
13230 "out gl_PerVertex {\n"
13231 " vec4 gl_Position;\n"
13232 "};\n"
13233 "void main(){\n"
13234 " gl_Position = vec4(1);\n"
13235 "}\n";
13236 char const *fsSource = "#version 450\n"
13237 "\n"
13238 "layout(location=0) out vec4 color;\n"
13239 "void main(){\n"
13240 " color = vec4(1);\n"
13241 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013242
13243 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13244 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13245
13246 VkPipelineObj pipe(m_device);
13247 pipe.AddColorAttachment();
13248 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060013249 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013250 pipe.AddShader(&fs);
13251
13252 VkDescriptorSetObj descriptorSet(m_device);
13253 descriptorSet.AppendDummy();
13254 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13255
13256 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13257
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013258 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013259}
13260
Chris Forbes82ff92a2016-09-09 10:50:24 +120013261TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
13262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13263 "No entrypoint found named `foo`");
13264
13265 ASSERT_NO_FATAL_FAILURE(InitState());
13266 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13267
13268 char const *vsSource = "#version 450\n"
13269 "out gl_PerVertex {\n"
13270 " vec4 gl_Position;\n"
13271 "};\n"
13272 "void main(){\n"
13273 " gl_Position = vec4(0);\n"
13274 "}\n";
13275 char const *fsSource = "#version 450\n"
13276 "\n"
13277 "layout(location=0) out vec4 color;\n"
13278 "void main(){\n"
13279 " color = vec4(1);\n"
13280 "}\n";
13281
13282 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13283 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13284
13285 VkPipelineObj pipe(m_device);
13286 pipe.AddColorAttachment();
13287 pipe.AddShader(&vs);
13288 pipe.AddShader(&fs);
13289
13290 VkDescriptorSetObj descriptorSet(m_device);
13291 descriptorSet.AppendDummy();
13292 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13293
13294 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13295
13296 m_errorMonitor->VerifyFound();
13297}
13298
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013299TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
13300 m_errorMonitor->SetDesiredFailureMsg(
13301 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13302 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13303 "uses a depth/stencil attachment");
13304
13305 ASSERT_NO_FATAL_FAILURE(InitState());
13306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13307
13308 char const *vsSource = "#version 450\n"
13309 "void main(){ gl_Position = vec4(0); }\n";
13310 char const *fsSource = "#version 450\n"
13311 "\n"
13312 "layout(location=0) out vec4 color;\n"
13313 "void main(){\n"
13314 " color = vec4(1);\n"
13315 "}\n";
13316
13317 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13318 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13319
13320 VkPipelineObj pipe(m_device);
13321 pipe.AddColorAttachment();
13322 pipe.AddShader(&vs);
13323 pipe.AddShader(&fs);
13324
13325 VkDescriptorSetObj descriptorSet(m_device);
13326 descriptorSet.AppendDummy();
13327 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13328
13329 VkAttachmentDescription attachments[] = {
13330 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
13331 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13332 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13333 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13334 },
13335 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
13336 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13337 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13338 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13339 },
13340 };
13341 VkAttachmentReference refs[] = {
13342 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13343 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13344 };
13345 VkSubpassDescription subpass = {
13346 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13347 1, &refs[0], nullptr, &refs[1],
13348 0, nullptr
13349 };
13350 VkRenderPassCreateInfo rpci = {
13351 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13352 0, 2, attachments, 1, &subpass, 0, nullptr
13353 };
13354 VkRenderPass rp;
13355 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13356 ASSERT_VK_SUCCESS(err);
13357
13358 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13359
13360 m_errorMonitor->VerifyFound();
13361
13362 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13363}
13364
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013365TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013366 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13367 "the TCS without the patch decoration, but consumed in the TES "
13368 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13370 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013371
13372 ASSERT_NO_FATAL_FAILURE(InitState());
13373 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13374
Chris Forbesc1e852d2016-04-04 19:26:42 +120013375 if (!m_device->phy().features().tessellationShader) {
13376 printf("Device does not support tessellation shaders; skipped.\n");
13377 return;
13378 }
13379
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013380 char const *vsSource = "#version 450\n"
13381 "void main(){}\n";
13382 char const *tcsSource = "#version 450\n"
13383 "layout(location=0) out int x[];\n"
13384 "layout(vertices=3) out;\n"
13385 "void main(){\n"
13386 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13387 " gl_TessLevelInner[0] = 1;\n"
13388 " x[gl_InvocationID] = gl_InvocationID;\n"
13389 "}\n";
13390 char const *tesSource = "#version 450\n"
13391 "layout(triangles, equal_spacing, cw) in;\n"
13392 "layout(location=0) patch in int x;\n"
13393 "out gl_PerVertex { vec4 gl_Position; };\n"
13394 "void main(){\n"
13395 " gl_Position.xyz = gl_TessCoord;\n"
13396 " gl_Position.w = x;\n"
13397 "}\n";
13398 char const *fsSource = "#version 450\n"
13399 "layout(location=0) out vec4 color;\n"
13400 "void main(){\n"
13401 " color = vec4(1);\n"
13402 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013403
13404 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13405 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13406 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13407 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13408
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013409 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13410 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013411
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013412 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013413
13414 VkPipelineObj pipe(m_device);
13415 pipe.SetInputAssembly(&iasci);
13416 pipe.SetTessellation(&tsci);
13417 pipe.AddColorAttachment();
13418 pipe.AddShader(&vs);
13419 pipe.AddShader(&tcs);
13420 pipe.AddShader(&tes);
13421 pipe.AddShader(&fs);
13422
13423 VkDescriptorSetObj descriptorSet(m_device);
13424 descriptorSet.AppendDummy();
13425 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13426
13427 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13428
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013429 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013430}
13431
Karl Schultz6addd812016-02-02 17:17:23 -070013432TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013433 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13434 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13436 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013437
Chris Forbes280ba2c2015-06-12 11:16:41 +120013438 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013439 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013440
13441 /* Two binding descriptions for binding 0 */
13442 VkVertexInputBindingDescription input_bindings[2];
13443 memset(input_bindings, 0, sizeof(input_bindings));
13444
13445 VkVertexInputAttributeDescription input_attrib;
13446 memset(&input_attrib, 0, sizeof(input_attrib));
13447 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13448
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013449 char const *vsSource = "#version 450\n"
13450 "\n"
13451 "layout(location=0) in float x;\n" /* attrib provided float */
13452 "out gl_PerVertex {\n"
13453 " vec4 gl_Position;\n"
13454 "};\n"
13455 "void main(){\n"
13456 " gl_Position = vec4(x);\n"
13457 "}\n";
13458 char const *fsSource = "#version 450\n"
13459 "\n"
13460 "layout(location=0) out vec4 color;\n"
13461 "void main(){\n"
13462 " color = vec4(1);\n"
13463 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013464
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013465 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13466 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013467
13468 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013469 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013470 pipe.AddShader(&vs);
13471 pipe.AddShader(&fs);
13472
13473 pipe.AddVertexInputBindings(input_bindings, 2);
13474 pipe.AddVertexInputAttribs(&input_attrib, 1);
13475
Chris Forbes280ba2c2015-06-12 11:16:41 +120013476 VkDescriptorSetObj descriptorSet(m_device);
13477 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013478 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013479
Tony Barbour5781e8f2015-08-04 16:23:11 -060013480 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013481
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013482 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013483}
Chris Forbes8f68b562015-05-25 11:13:32 +120013484
Karl Schultz6addd812016-02-02 17:17:23 -070013485TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013486 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013487 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013489
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013490 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013492 char const *vsSource = "#version 450\n"
13493 "\n"
13494 "out gl_PerVertex {\n"
13495 " vec4 gl_Position;\n"
13496 "};\n"
13497 "void main(){\n"
13498 " gl_Position = vec4(1);\n"
13499 "}\n";
13500 char const *fsSource = "#version 450\n"
13501 "\n"
13502 "void main(){\n"
13503 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013504
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013505 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13506 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013507
13508 VkPipelineObj pipe(m_device);
13509 pipe.AddShader(&vs);
13510 pipe.AddShader(&fs);
13511
Chia-I Wu08accc62015-07-07 11:50:03 +080013512 /* set up CB 0, not written */
13513 pipe.AddColorAttachment();
13514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013515
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013516 VkDescriptorSetObj descriptorSet(m_device);
13517 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013518 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013519
Tony Barbour5781e8f2015-08-04 16:23:11 -060013520 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013521
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013522 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013523}
13524
Karl Schultz6addd812016-02-02 17:17:23 -070013525TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013526 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013527 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013529 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013530
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013531 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013532
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013533 char const *vsSource = "#version 450\n"
13534 "\n"
13535 "out gl_PerVertex {\n"
13536 " vec4 gl_Position;\n"
13537 "};\n"
13538 "void main(){\n"
13539 " gl_Position = vec4(1);\n"
13540 "}\n";
13541 char const *fsSource = "#version 450\n"
13542 "\n"
13543 "layout(location=0) out vec4 x;\n"
13544 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13545 "void main(){\n"
13546 " x = vec4(1);\n"
13547 " y = vec4(1);\n"
13548 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013549
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013550 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13551 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013552
13553 VkPipelineObj pipe(m_device);
13554 pipe.AddShader(&vs);
13555 pipe.AddShader(&fs);
13556
Chia-I Wu08accc62015-07-07 11:50:03 +080013557 /* set up CB 0, not written */
13558 pipe.AddColorAttachment();
13559 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013560 /* FS writes CB 1, but we don't configure it */
13561
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013562 VkDescriptorSetObj descriptorSet(m_device);
13563 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013564 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013565
Tony Barbour5781e8f2015-08-04 16:23:11 -060013566 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013567
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013568 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013569}
13570
Karl Schultz6addd812016-02-02 17:17:23 -070013571TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013572 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013573 "type of an fragment shader output variable, and the format of the corresponding attachment");
13574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013575
Chris Forbesa36d69e2015-05-25 11:13:44 +120013576 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013577
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013578 char const *vsSource = "#version 450\n"
13579 "\n"
13580 "out gl_PerVertex {\n"
13581 " vec4 gl_Position;\n"
13582 "};\n"
13583 "void main(){\n"
13584 " gl_Position = vec4(1);\n"
13585 "}\n";
13586 char const *fsSource = "#version 450\n"
13587 "\n"
13588 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13589 "void main(){\n"
13590 " x = ivec4(1);\n"
13591 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013592
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013593 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13594 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013595
13596 VkPipelineObj pipe(m_device);
13597 pipe.AddShader(&vs);
13598 pipe.AddShader(&fs);
13599
Chia-I Wu08accc62015-07-07 11:50:03 +080013600 /* set up CB 0; type is UNORM by default */
13601 pipe.AddColorAttachment();
13602 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013603
Chris Forbesa36d69e2015-05-25 11:13:44 +120013604 VkDescriptorSetObj descriptorSet(m_device);
13605 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013606 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013607
Tony Barbour5781e8f2015-08-04 16:23:11 -060013608 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013609
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013610 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013611}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013612
Karl Schultz6addd812016-02-02 17:17:23 -070013613TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013614 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13615 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013617
Chris Forbes556c76c2015-08-14 12:04:59 +120013618 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013619
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013620 char const *vsSource = "#version 450\n"
13621 "\n"
13622 "out gl_PerVertex {\n"
13623 " vec4 gl_Position;\n"
13624 "};\n"
13625 "void main(){\n"
13626 " gl_Position = vec4(1);\n"
13627 "}\n";
13628 char const *fsSource = "#version 450\n"
13629 "\n"
13630 "layout(location=0) out vec4 x;\n"
13631 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13632 "void main(){\n"
13633 " x = vec4(bar.y);\n"
13634 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013635
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013636 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13637 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013638
Chris Forbes556c76c2015-08-14 12:04:59 +120013639 VkPipelineObj pipe(m_device);
13640 pipe.AddShader(&vs);
13641 pipe.AddShader(&fs);
13642
13643 /* set up CB 0; type is UNORM by default */
13644 pipe.AddColorAttachment();
13645 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13646
13647 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013648 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013649
13650 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13651
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013652 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013653}
13654
Chris Forbes5c59e902016-02-26 16:56:09 +130013655TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013656 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13657 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013659
13660 ASSERT_NO_FATAL_FAILURE(InitState());
13661
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013662 char const *vsSource = "#version 450\n"
13663 "\n"
13664 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13665 "out gl_PerVertex {\n"
13666 " vec4 gl_Position;\n"
13667 "};\n"
13668 "void main(){\n"
13669 " gl_Position = vec4(consts.x);\n"
13670 "}\n";
13671 char const *fsSource = "#version 450\n"
13672 "\n"
13673 "layout(location=0) out vec4 x;\n"
13674 "void main(){\n"
13675 " x = vec4(1);\n"
13676 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013677
13678 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13679 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13680
13681 VkPipelineObj pipe(m_device);
13682 pipe.AddShader(&vs);
13683 pipe.AddShader(&fs);
13684
13685 /* set up CB 0; type is UNORM by default */
13686 pipe.AddColorAttachment();
13687 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13688
13689 VkDescriptorSetObj descriptorSet(m_device);
13690 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13691
13692 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13693
13694 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013695 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013696}
13697
Chris Forbes3fb17902016-08-22 14:57:55 +120013698TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13699 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13700 "which is not included in the subpass description");
13701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13702 "consumes input attachment index 0 but not provided in subpass");
13703
13704 ASSERT_NO_FATAL_FAILURE(InitState());
13705
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013706 char const *vsSource = "#version 450\n"
13707 "\n"
13708 "out gl_PerVertex {\n"
13709 " vec4 gl_Position;\n"
13710 "};\n"
13711 "void main(){\n"
13712 " gl_Position = vec4(1);\n"
13713 "}\n";
13714 char const *fsSource = "#version 450\n"
13715 "\n"
13716 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13717 "layout(location=0) out vec4 color;\n"
13718 "void main() {\n"
13719 " color = subpassLoad(x);\n"
13720 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013721
13722 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13723 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13724
13725 VkPipelineObj pipe(m_device);
13726 pipe.AddShader(&vs);
13727 pipe.AddShader(&fs);
13728 pipe.AddColorAttachment();
13729 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13730
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013731 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13732 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013733 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013734 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013735 ASSERT_VK_SUCCESS(err);
13736
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013737 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013738 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013739 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013740 ASSERT_VK_SUCCESS(err);
13741
13742 // error here.
13743 pipe.CreateVKPipeline(pl, renderPass());
13744
13745 m_errorMonitor->VerifyFound();
13746
13747 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13748 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13749}
13750
Chris Forbes5a9a0472016-08-22 16:02:09 +120013751TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13752 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13753 "with a format having a different fundamental type");
13754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13755 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13756
13757 ASSERT_NO_FATAL_FAILURE(InitState());
13758
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013759 char const *vsSource = "#version 450\n"
13760 "\n"
13761 "out gl_PerVertex {\n"
13762 " vec4 gl_Position;\n"
13763 "};\n"
13764 "void main(){\n"
13765 " gl_Position = vec4(1);\n"
13766 "}\n";
13767 char const *fsSource = "#version 450\n"
13768 "\n"
13769 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13770 "layout(location=0) out vec4 color;\n"
13771 "void main() {\n"
13772 " color = subpassLoad(x);\n"
13773 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013774
13775 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13776 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13777
13778 VkPipelineObj pipe(m_device);
13779 pipe.AddShader(&vs);
13780 pipe.AddShader(&fs);
13781 pipe.AddColorAttachment();
13782 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13783
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013784 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13785 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013786 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013787 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013788 ASSERT_VK_SUCCESS(err);
13789
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013790 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013791 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013792 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013793 ASSERT_VK_SUCCESS(err);
13794
13795 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013796 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13797 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13798 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13799 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13800 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 +120013801 };
13802 VkAttachmentReference color = {
13803 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13804 };
13805 VkAttachmentReference input = {
13806 1, VK_IMAGE_LAYOUT_GENERAL,
13807 };
13808
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013809 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013810
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013811 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013812 VkRenderPass rp;
13813 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13814 ASSERT_VK_SUCCESS(err);
13815
13816 // error here.
13817 pipe.CreateVKPipeline(pl, rp);
13818
13819 m_errorMonitor->VerifyFound();
13820
13821 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13822 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13823 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13824}
13825
Chris Forbes541f7b02016-08-22 15:30:27 +120013826TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13827 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13828 "which is not included in the subpass description -- array case");
13829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13830 "consumes input attachment index 1 but not provided in subpass");
13831
13832 ASSERT_NO_FATAL_FAILURE(InitState());
13833
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013834 char const *vsSource = "#version 450\n"
13835 "\n"
13836 "out gl_PerVertex {\n"
13837 " vec4 gl_Position;\n"
13838 "};\n"
13839 "void main(){\n"
13840 " gl_Position = vec4(1);\n"
13841 "}\n";
13842 char const *fsSource = "#version 450\n"
13843 "\n"
13844 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13845 "layout(location=0) out vec4 color;\n"
13846 "void main() {\n"
13847 " color = subpassLoad(xs[1]);\n"
13848 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013849
13850 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13851 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13852
13853 VkPipelineObj pipe(m_device);
13854 pipe.AddShader(&vs);
13855 pipe.AddShader(&fs);
13856 pipe.AddColorAttachment();
13857 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13858
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013859 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13860 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013861 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013862 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013863 ASSERT_VK_SUCCESS(err);
13864
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013865 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013866 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013867 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013868 ASSERT_VK_SUCCESS(err);
13869
13870 // error here.
13871 pipe.CreateVKPipeline(pl, renderPass());
13872
13873 m_errorMonitor->VerifyFound();
13874
13875 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13876 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13877}
13878
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013879TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013880 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13881 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013883
13884 ASSERT_NO_FATAL_FAILURE(InitState());
13885
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013886 char const *csSource = "#version 450\n"
13887 "\n"
13888 "layout(local_size_x=1) in;\n"
13889 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13890 "void main(){\n"
13891 " x = vec4(1);\n"
13892 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013893
13894 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13895
13896 VkDescriptorSetObj descriptorSet(m_device);
13897 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013899 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13900 nullptr,
13901 0,
13902 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13903 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13904 descriptorSet.GetPipelineLayout(),
13905 VK_NULL_HANDLE,
13906 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013907
13908 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013909 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013910
13911 m_errorMonitor->VerifyFound();
13912
13913 if (err == VK_SUCCESS) {
13914 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13915 }
13916}
13917
Chris Forbes22a9b092016-07-19 14:34:05 +120013918TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013919 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13920 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13922 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013923
13924 ASSERT_NO_FATAL_FAILURE(InitState());
13925
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013926 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13927 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013928 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013929 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013930 ASSERT_VK_SUCCESS(err);
13931
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013932 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013933 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013934 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013935 ASSERT_VK_SUCCESS(err);
13936
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013937 char const *csSource = "#version 450\n"
13938 "\n"
13939 "layout(local_size_x=1) in;\n"
13940 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13941 "void main() {\n"
13942 " x.x = 1.0f;\n"
13943 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013944 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13945
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013946 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13947 nullptr,
13948 0,
13949 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13950 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13951 pl,
13952 VK_NULL_HANDLE,
13953 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013954
13955 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013956 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013957
13958 m_errorMonitor->VerifyFound();
13959
13960 if (err == VK_SUCCESS) {
13961 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13962 }
13963
13964 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13965 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13966}
13967
Chris Forbes50020592016-07-27 13:52:41 +120013968TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13969 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13970 "does not match the dimensionality declared in the shader");
13971
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013972 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 +120013973
13974 ASSERT_NO_FATAL_FAILURE(InitState());
13975 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13976
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013977 char const *vsSource = "#version 450\n"
13978 "\n"
13979 "out gl_PerVertex { vec4 gl_Position; };\n"
13980 "void main() { gl_Position = vec4(0); }\n";
13981 char const *fsSource = "#version 450\n"
13982 "\n"
13983 "layout(set=0, binding=0) uniform sampler3D s;\n"
13984 "layout(location=0) out vec4 color;\n"
13985 "void main() {\n"
13986 " color = texture(s, vec3(0));\n"
13987 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013988 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13989 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13990
13991 VkPipelineObj pipe(m_device);
13992 pipe.AddShader(&vs);
13993 pipe.AddShader(&fs);
13994 pipe.AddColorAttachment();
13995
13996 VkTextureObj texture(m_device, nullptr);
13997 VkSamplerObj sampler(m_device);
13998
13999 VkDescriptorSetObj descriptorSet(m_device);
14000 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14001 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14002
14003 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14004 ASSERT_VK_SUCCESS(err);
14005
14006 BeginCommandBuffer();
14007
14008 m_commandBuffer->BindPipeline(pipe);
14009 m_commandBuffer->BindDescriptorSet(descriptorSet);
14010
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014011 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014012 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014013 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014014 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14015
14016 // error produced here.
14017 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14018
14019 m_errorMonitor->VerifyFound();
14020
14021 EndCommandBuffer();
14022}
14023
Chris Forbes5533bfc2016-07-27 14:12:34 +120014024TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
14025 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
14026 "are consumed via singlesample images types in the shader, or vice versa.");
14027
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014029
14030 ASSERT_NO_FATAL_FAILURE(InitState());
14031 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14032
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014033 char const *vsSource = "#version 450\n"
14034 "\n"
14035 "out gl_PerVertex { vec4 gl_Position; };\n"
14036 "void main() { gl_Position = vec4(0); }\n";
14037 char const *fsSource = "#version 450\n"
14038 "\n"
14039 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14040 "layout(location=0) out vec4 color;\n"
14041 "void main() {\n"
14042 " color = texelFetch(s, ivec2(0), 0);\n"
14043 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014044 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14045 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14046
14047 VkPipelineObj pipe(m_device);
14048 pipe.AddShader(&vs);
14049 pipe.AddShader(&fs);
14050 pipe.AddColorAttachment();
14051
14052 VkTextureObj texture(m_device, nullptr);
14053 VkSamplerObj sampler(m_device);
14054
14055 VkDescriptorSetObj descriptorSet(m_device);
14056 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14057 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14058
14059 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14060 ASSERT_VK_SUCCESS(err);
14061
14062 BeginCommandBuffer();
14063
14064 m_commandBuffer->BindPipeline(pipe);
14065 m_commandBuffer->BindDescriptorSet(descriptorSet);
14066
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014067 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014068 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014069 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014070 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14071
14072 // error produced here.
14073 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14074
14075 m_errorMonitor->VerifyFound();
14076
14077 EndCommandBuffer();
14078}
14079
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014080#endif // SHADER_CHECKER_TESTS
14081
14082#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014083TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014085
14086 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014087
14088 // Create an image
14089 VkImage image;
14090
Karl Schultz6addd812016-02-02 17:17:23 -070014091 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14092 const int32_t tex_width = 32;
14093 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014094
14095 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014096 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14097 image_create_info.pNext = NULL;
14098 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14099 image_create_info.format = tex_format;
14100 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014101 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014102 image_create_info.extent.depth = 1;
14103 image_create_info.mipLevels = 1;
14104 image_create_info.arrayLayers = 1;
14105 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14106 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14107 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14108 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014109
14110 // Introduce error by sending down a bogus width extent
14111 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014112 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014113
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014114 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014115}
14116
Mark Youngc48c4c12016-04-11 14:26:49 -060014117TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14119 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014120
14121 ASSERT_NO_FATAL_FAILURE(InitState());
14122
14123 // Create an image
14124 VkImage image;
14125
14126 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14127 const int32_t tex_width = 32;
14128 const int32_t tex_height = 32;
14129
14130 VkImageCreateInfo image_create_info = {};
14131 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14132 image_create_info.pNext = NULL;
14133 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14134 image_create_info.format = tex_format;
14135 image_create_info.extent.width = tex_width;
14136 image_create_info.extent.height = tex_height;
14137 image_create_info.extent.depth = 1;
14138 image_create_info.mipLevels = 1;
14139 image_create_info.arrayLayers = 1;
14140 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14141 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14142 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14143 image_create_info.flags = 0;
14144
14145 // Introduce error by sending down a bogus width extent
14146 image_create_info.extent.width = 0;
14147 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14148
14149 m_errorMonitor->VerifyFound();
14150}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014151#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014152
Tobin Ehliscde08892015-09-22 10:11:37 -060014153#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014154
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014155TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
14156 TEST_DESCRIPTION("Create a render pass with an attachment description "
14157 "format set to VK_FORMAT_UNDEFINED");
14158
14159 ASSERT_NO_FATAL_FAILURE(InitState());
14160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14161
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014163
14164 VkAttachmentReference color_attach = {};
14165 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14166 color_attach.attachment = 0;
14167 VkSubpassDescription subpass = {};
14168 subpass.colorAttachmentCount = 1;
14169 subpass.pColorAttachments = &color_attach;
14170
14171 VkRenderPassCreateInfo rpci = {};
14172 rpci.subpassCount = 1;
14173 rpci.pSubpasses = &subpass;
14174 rpci.attachmentCount = 1;
14175 VkAttachmentDescription attach_desc = {};
14176 attach_desc.format = VK_FORMAT_UNDEFINED;
14177 rpci.pAttachments = &attach_desc;
14178 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14179 VkRenderPass rp;
14180 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14181
14182 m_errorMonitor->VerifyFound();
14183
14184 if (result == VK_SUCCESS) {
14185 vkDestroyRenderPass(m_device->device(), rp, NULL);
14186 }
14187}
14188
Karl Schultz6addd812016-02-02 17:17:23 -070014189TEST_F(VkLayerTest, InvalidImageView) {
14190 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014191
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014193
Tobin Ehliscde08892015-09-22 10:11:37 -060014194 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014195
Mike Stroyana3082432015-09-25 13:39:21 -060014196 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014197 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014198
Karl Schultz6addd812016-02-02 17:17:23 -070014199 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14200 const int32_t tex_width = 32;
14201 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014202
14203 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014204 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14205 image_create_info.pNext = NULL;
14206 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14207 image_create_info.format = tex_format;
14208 image_create_info.extent.width = tex_width;
14209 image_create_info.extent.height = tex_height;
14210 image_create_info.extent.depth = 1;
14211 image_create_info.mipLevels = 1;
14212 image_create_info.arrayLayers = 1;
14213 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14214 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14215 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14216 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014217
Chia-I Wuf7458c52015-10-26 21:10:41 +080014218 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014219 ASSERT_VK_SUCCESS(err);
14220
14221 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014222 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014223 image_view_create_info.image = image;
14224 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14225 image_view_create_info.format = tex_format;
14226 image_view_create_info.subresourceRange.layerCount = 1;
14227 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
14228 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014229 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014230
14231 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014232 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014233
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014234 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014235 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014236}
Mike Stroyana3082432015-09-25 13:39:21 -060014237
Mark Youngd339ba32016-05-30 13:28:35 -060014238TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14239 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014241 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014242
14243 ASSERT_NO_FATAL_FAILURE(InitState());
14244
14245 // Create an image and try to create a view with no memory backing the image
14246 VkImage image;
14247
14248 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14249 const int32_t tex_width = 32;
14250 const int32_t tex_height = 32;
14251
14252 VkImageCreateInfo image_create_info = {};
14253 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14254 image_create_info.pNext = NULL;
14255 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14256 image_create_info.format = tex_format;
14257 image_create_info.extent.width = tex_width;
14258 image_create_info.extent.height = tex_height;
14259 image_create_info.extent.depth = 1;
14260 image_create_info.mipLevels = 1;
14261 image_create_info.arrayLayers = 1;
14262 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14263 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14264 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14265 image_create_info.flags = 0;
14266
14267 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14268 ASSERT_VK_SUCCESS(err);
14269
14270 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014271 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014272 image_view_create_info.image = image;
14273 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14274 image_view_create_info.format = tex_format;
14275 image_view_create_info.subresourceRange.layerCount = 1;
14276 image_view_create_info.subresourceRange.baseMipLevel = 0;
14277 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014278 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014279
14280 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014281 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014282
14283 m_errorMonitor->VerifyFound();
14284 vkDestroyImage(m_device->device(), image, NULL);
14285 // If last error is success, it still created the view, so delete it.
14286 if (err == VK_SUCCESS) {
14287 vkDestroyImageView(m_device->device(), view, NULL);
14288 }
Mark Youngd339ba32016-05-30 13:28:35 -060014289}
14290
Karl Schultz6addd812016-02-02 17:17:23 -070014291TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014292 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014294 "formats must have ONLY the "
14295 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14297 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014298
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014299 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014300
Karl Schultz6addd812016-02-02 17:17:23 -070014301 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014302 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014303 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014304 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014305
14306 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014307 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014308 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014309 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14310 image_view_create_info.format = tex_format;
14311 image_view_create_info.subresourceRange.baseMipLevel = 0;
14312 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014313 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014314 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014315 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014316
14317 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014318 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014319
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014320 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014321}
14322
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014323TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014324 VkResult err;
14325 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014326
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14328 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014329
Mike Stroyana3082432015-09-25 13:39:21 -060014330 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014331
14332 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014333 VkImage srcImage;
14334 VkImage dstImage;
14335 VkDeviceMemory srcMem;
14336 VkDeviceMemory destMem;
14337 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014338
14339 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014340 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14341 image_create_info.pNext = NULL;
14342 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14343 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14344 image_create_info.extent.width = 32;
14345 image_create_info.extent.height = 32;
14346 image_create_info.extent.depth = 1;
14347 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014348 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014349 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14350 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14351 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14352 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014353
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014354 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014355 ASSERT_VK_SUCCESS(err);
14356
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014357 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014358 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014359 ASSERT_VK_SUCCESS(err);
14360
14361 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014362 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014363 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14364 memAlloc.pNext = NULL;
14365 memAlloc.allocationSize = 0;
14366 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014367
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014368 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014369 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014370 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014371 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014372 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014373 ASSERT_VK_SUCCESS(err);
14374
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014375 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014376 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014377 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014378 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014379 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014380 ASSERT_VK_SUCCESS(err);
14381
14382 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14383 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014384 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014385 ASSERT_VK_SUCCESS(err);
14386
14387 BeginCommandBuffer();
14388 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014389 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014390 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014391 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014392 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014393 copyRegion.srcOffset.x = 0;
14394 copyRegion.srcOffset.y = 0;
14395 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014396 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014397 copyRegion.dstSubresource.mipLevel = 0;
14398 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014399 // Introduce failure by forcing the dst layerCount to differ from src
14400 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014401 copyRegion.dstOffset.x = 0;
14402 copyRegion.dstOffset.y = 0;
14403 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014404 copyRegion.extent.width = 1;
14405 copyRegion.extent.height = 1;
14406 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014407 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014408 EndCommandBuffer();
14409
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014410 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014411
Chia-I Wuf7458c52015-10-26 21:10:41 +080014412 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014413 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014414 vkFreeMemory(m_device->device(), srcMem, NULL);
14415 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014416}
14417
Tony Barbourd6673642016-05-05 14:46:39 -060014418TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14419
14420 TEST_DESCRIPTION("Creating images with unsuported formats ");
14421
14422 ASSERT_NO_FATAL_FAILURE(InitState());
14423 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14424 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014425 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 -060014426 VK_IMAGE_TILING_OPTIMAL, 0);
14427 ASSERT_TRUE(image.initialized());
14428
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014429 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014430 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014431 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014432 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14433 image_create_info.format = VK_FORMAT_UNDEFINED;
14434 image_create_info.extent.width = 32;
14435 image_create_info.extent.height = 32;
14436 image_create_info.extent.depth = 1;
14437 image_create_info.mipLevels = 1;
14438 image_create_info.arrayLayers = 1;
14439 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14440 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14441 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14444 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014445
14446 VkImage localImage;
14447 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14448 m_errorMonitor->VerifyFound();
14449
Tony Barbourd6673642016-05-05 14:46:39 -060014450 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014451 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014452 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14453 VkFormat format = static_cast<VkFormat>(f);
14454 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014455 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014456 unsupported = format;
14457 break;
14458 }
14459 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014460
Tony Barbourd6673642016-05-05 14:46:39 -060014461 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014462 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014464
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014465 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014466 m_errorMonitor->VerifyFound();
14467 }
14468}
14469
14470TEST_F(VkLayerTest, ImageLayerViewTests) {
14471 VkResult ret;
14472 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14473
14474 ASSERT_NO_FATAL_FAILURE(InitState());
14475
14476 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014477 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 -060014478 VK_IMAGE_TILING_OPTIMAL, 0);
14479 ASSERT_TRUE(image.initialized());
14480
14481 VkImageView imgView;
14482 VkImageViewCreateInfo imgViewInfo = {};
14483 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14484 imgViewInfo.image = image.handle();
14485 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14486 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14487 imgViewInfo.subresourceRange.layerCount = 1;
14488 imgViewInfo.subresourceRange.baseMipLevel = 0;
14489 imgViewInfo.subresourceRange.levelCount = 1;
14490 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060014493 // View can't have baseMipLevel >= image's mipLevels - Expect
14494 // VIEW_CREATE_ERROR
14495 imgViewInfo.subresourceRange.baseMipLevel = 1;
14496 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14497 m_errorMonitor->VerifyFound();
14498 imgViewInfo.subresourceRange.baseMipLevel = 0;
14499
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014501 // View can't have baseArrayLayer >= image's arraySize - Expect
14502 // VIEW_CREATE_ERROR
14503 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14504 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14505 m_errorMonitor->VerifyFound();
14506 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14507
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14509 "pCreateInfo->subresourceRange."
14510 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014511 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14512 imgViewInfo.subresourceRange.levelCount = 0;
14513 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14514 m_errorMonitor->VerifyFound();
14515 imgViewInfo.subresourceRange.levelCount = 1;
14516
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14518 "pCreateInfo->subresourceRange."
14519 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014520 m_errorMonitor->SetDesiredFailureMsg(
14521 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14522 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014523 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14524 imgViewInfo.subresourceRange.layerCount = 0;
14525 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14526 m_errorMonitor->VerifyFound();
14527 imgViewInfo.subresourceRange.layerCount = 1;
14528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14531 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14532 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014533 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14534 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14535 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14536 m_errorMonitor->VerifyFound();
14537 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14538
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14540 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14541 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014542 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14543 // VIEW_CREATE_ERROR
14544 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14545 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14546 m_errorMonitor->VerifyFound();
14547 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14548
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14550 "differing formats but they must be "
14551 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014552 // TODO: Update framework to easily passing mutable flag into ImageObj init
14553 // For now just allowing image for this one test to not have memory bound
14554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14555 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014556 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14557 // VIEW_CREATE_ERROR
14558 VkImageCreateInfo mutImgInfo = image.create_info();
14559 VkImage mutImage;
14560 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014561 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014562 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14563 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14564 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14565 ASSERT_VK_SUCCESS(ret);
14566 imgViewInfo.image = mutImage;
14567 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14568 m_errorMonitor->VerifyFound();
14569 imgViewInfo.image = image.handle();
14570 vkDestroyImage(m_device->handle(), mutImage, NULL);
14571}
14572
14573TEST_F(VkLayerTest, MiscImageLayerTests) {
14574
14575 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14576
14577 ASSERT_NO_FATAL_FAILURE(InitState());
14578
14579 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014580 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 -060014581 VK_IMAGE_TILING_OPTIMAL, 0);
14582 ASSERT_TRUE(image.initialized());
14583
Tony Barbourd6673642016-05-05 14:46:39 -060014584 vk_testing::Buffer buffer;
14585 VkMemoryPropertyFlags reqs = 0;
14586 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14587 VkBufferImageCopy region = {};
14588 region.bufferRowLength = 128;
14589 region.bufferImageHeight = 128;
14590 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14591 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014592 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014593 region.imageExtent.height = 4;
14594 region.imageExtent.width = 4;
14595 region.imageExtent.depth = 1;
14596 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014597
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014598 // Image must have offset.z of 0 and extent.depth of 1
14599 // Introduce failure by setting imageExtent.depth to 0
14600 region.imageExtent.depth = 0;
14601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14602 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14603 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14604 m_errorMonitor->VerifyFound();
14605
14606 region.imageExtent.depth = 1;
14607
14608 // Image must have offset.z of 0 and extent.depth of 1
14609 // Introduce failure by setting imageOffset.z to 4
14610 region.imageOffset.z = 4;
14611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14612 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14613 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14614 m_errorMonitor->VerifyFound();
14615
14616 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014617 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14618 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14619 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014621 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14622 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014623 m_errorMonitor->VerifyFound();
14624
14625 // BufferOffset must be a multiple of 4
14626 // Introduce failure by setting bufferOffset to a value not divisible by 4
14627 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014629 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14630 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014631 m_errorMonitor->VerifyFound();
14632
14633 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14634 region.bufferOffset = 0;
14635 region.imageExtent.height = 128;
14636 region.imageExtent.width = 128;
14637 // Introduce failure by setting bufferRowLength > 0 but less than width
14638 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014640 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14641 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014642 m_errorMonitor->VerifyFound();
14643
14644 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14645 region.bufferRowLength = 128;
14646 // Introduce failure by setting bufferRowHeight > 0 but less than height
14647 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014649 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14650 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014651 m_errorMonitor->VerifyFound();
14652
14653 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14655 "If the format of srcImage is a depth, stencil, depth stencil or "
14656 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014657 // Expect INVALID_FILTER
14658 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014659 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 -060014660 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014661 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 -060014662 VkImageBlit blitRegion = {};
14663 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14664 blitRegion.srcSubresource.baseArrayLayer = 0;
14665 blitRegion.srcSubresource.layerCount = 1;
14666 blitRegion.srcSubresource.mipLevel = 0;
14667 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14668 blitRegion.dstSubresource.baseArrayLayer = 0;
14669 blitRegion.dstSubresource.layerCount = 1;
14670 blitRegion.dstSubresource.mipLevel = 0;
14671
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014672 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14673 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014674 m_errorMonitor->VerifyFound();
14675
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014676 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14678 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14679 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014680 m_errorMonitor->VerifyFound();
14681
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014683 VkImageMemoryBarrier img_barrier;
14684 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14685 img_barrier.pNext = NULL;
14686 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14687 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14688 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14689 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14690 img_barrier.image = image.handle();
14691 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14692 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14693 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14694 img_barrier.subresourceRange.baseArrayLayer = 0;
14695 img_barrier.subresourceRange.baseMipLevel = 0;
14696 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14697 img_barrier.subresourceRange.layerCount = 0;
14698 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014699 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14700 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014701 m_errorMonitor->VerifyFound();
14702 img_barrier.subresourceRange.layerCount = 1;
14703}
14704
14705TEST_F(VkLayerTest, ImageFormatLimits) {
14706
14707 TEST_DESCRIPTION("Exceed the limits of image format ");
14708
Cody Northropc31a84f2016-08-22 10:41:47 -060014709 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014711 VkImageCreateInfo image_create_info = {};
14712 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14713 image_create_info.pNext = NULL;
14714 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14715 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14716 image_create_info.extent.width = 32;
14717 image_create_info.extent.height = 32;
14718 image_create_info.extent.depth = 1;
14719 image_create_info.mipLevels = 1;
14720 image_create_info.arrayLayers = 1;
14721 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14722 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14723 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14724 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14725 image_create_info.flags = 0;
14726
14727 VkImage nullImg;
14728 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014729 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14730 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014731 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14732 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14733 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14734 m_errorMonitor->VerifyFound();
14735 image_create_info.extent.depth = 1;
14736
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014738 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14739 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14740 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14741 m_errorMonitor->VerifyFound();
14742 image_create_info.mipLevels = 1;
14743
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014745 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14746 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14747 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14748 m_errorMonitor->VerifyFound();
14749 image_create_info.arrayLayers = 1;
14750
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014752 int samples = imgFmtProps.sampleCounts >> 1;
14753 image_create_info.samples = (VkSampleCountFlagBits)samples;
14754 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14755 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14756 m_errorMonitor->VerifyFound();
14757 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14758
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14760 "VK_IMAGE_LAYOUT_UNDEFINED or "
14761 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014762 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14763 // Expect INVALID_LAYOUT
14764 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14765 m_errorMonitor->VerifyFound();
14766 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14767}
14768
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014769TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14770
14771 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014773
14774 ASSERT_NO_FATAL_FAILURE(InitState());
14775
14776 VkImageObj src_image(m_device);
14777 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14778 VkImageObj dst_image(m_device);
14779 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14780
14781 BeginCommandBuffer();
14782 VkImageCopy copy_region;
14783 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14784 copy_region.srcSubresource.mipLevel = 0;
14785 copy_region.srcSubresource.baseArrayLayer = 0;
14786 copy_region.srcSubresource.layerCount = 0;
14787 copy_region.srcOffset.x = 0;
14788 copy_region.srcOffset.y = 0;
14789 copy_region.srcOffset.z = 0;
14790 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14791 copy_region.dstSubresource.mipLevel = 0;
14792 copy_region.dstSubresource.baseArrayLayer = 0;
14793 copy_region.dstSubresource.layerCount = 0;
14794 copy_region.dstOffset.x = 0;
14795 copy_region.dstOffset.y = 0;
14796 copy_region.dstOffset.z = 0;
14797 copy_region.extent.width = 64;
14798 copy_region.extent.height = 64;
14799 copy_region.extent.depth = 1;
14800 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14801 &copy_region);
14802 EndCommandBuffer();
14803
14804 m_errorMonitor->VerifyFound();
14805}
14806
14807TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14808
14809 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014811
14812 ASSERT_NO_FATAL_FAILURE(InitState());
14813
14814 VkImageObj src_image(m_device);
14815 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14816 VkImageObj dst_image(m_device);
14817 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14818
14819 BeginCommandBuffer();
14820 VkImageCopy copy_region;
14821 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14822 copy_region.srcSubresource.mipLevel = 0;
14823 copy_region.srcSubresource.baseArrayLayer = 0;
14824 copy_region.srcSubresource.layerCount = 0;
14825 copy_region.srcOffset.x = 0;
14826 copy_region.srcOffset.y = 0;
14827 copy_region.srcOffset.z = 0;
14828 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14829 copy_region.dstSubresource.mipLevel = 0;
14830 copy_region.dstSubresource.baseArrayLayer = 0;
14831 copy_region.dstSubresource.layerCount = 0;
14832 copy_region.dstOffset.x = 0;
14833 copy_region.dstOffset.y = 0;
14834 copy_region.dstOffset.z = 0;
14835 copy_region.extent.width = 64;
14836 copy_region.extent.height = 64;
14837 copy_region.extent.depth = 1;
14838 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14839 &copy_region);
14840 EndCommandBuffer();
14841
14842 m_errorMonitor->VerifyFound();
14843}
14844
Karl Schultz6addd812016-02-02 17:17:23 -070014845TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014846 VkResult err;
14847 bool pass;
14848
14849 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14851 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014852
14853 ASSERT_NO_FATAL_FAILURE(InitState());
14854
14855 // Create two images of different types and try to copy between them
14856 VkImage srcImage;
14857 VkImage dstImage;
14858 VkDeviceMemory srcMem;
14859 VkDeviceMemory destMem;
14860 VkMemoryRequirements memReqs;
14861
14862 VkImageCreateInfo image_create_info = {};
14863 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14864 image_create_info.pNext = NULL;
14865 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14866 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14867 image_create_info.extent.width = 32;
14868 image_create_info.extent.height = 32;
14869 image_create_info.extent.depth = 1;
14870 image_create_info.mipLevels = 1;
14871 image_create_info.arrayLayers = 1;
14872 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14873 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14874 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14875 image_create_info.flags = 0;
14876
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014877 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014878 ASSERT_VK_SUCCESS(err);
14879
14880 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14881 // Introduce failure by creating second image with a different-sized format.
14882 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14883
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014884 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014885 ASSERT_VK_SUCCESS(err);
14886
14887 // Allocate memory
14888 VkMemoryAllocateInfo memAlloc = {};
14889 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14890 memAlloc.pNext = NULL;
14891 memAlloc.allocationSize = 0;
14892 memAlloc.memoryTypeIndex = 0;
14893
14894 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14895 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014896 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014897 ASSERT_TRUE(pass);
14898 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14899 ASSERT_VK_SUCCESS(err);
14900
14901 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14902 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014903 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014904 ASSERT_TRUE(pass);
14905 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14906 ASSERT_VK_SUCCESS(err);
14907
14908 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14909 ASSERT_VK_SUCCESS(err);
14910 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14911 ASSERT_VK_SUCCESS(err);
14912
14913 BeginCommandBuffer();
14914 VkImageCopy copyRegion;
14915 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14916 copyRegion.srcSubresource.mipLevel = 0;
14917 copyRegion.srcSubresource.baseArrayLayer = 0;
14918 copyRegion.srcSubresource.layerCount = 0;
14919 copyRegion.srcOffset.x = 0;
14920 copyRegion.srcOffset.y = 0;
14921 copyRegion.srcOffset.z = 0;
14922 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14923 copyRegion.dstSubresource.mipLevel = 0;
14924 copyRegion.dstSubresource.baseArrayLayer = 0;
14925 copyRegion.dstSubresource.layerCount = 0;
14926 copyRegion.dstOffset.x = 0;
14927 copyRegion.dstOffset.y = 0;
14928 copyRegion.dstOffset.z = 0;
14929 copyRegion.extent.width = 1;
14930 copyRegion.extent.height = 1;
14931 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014932 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014933 EndCommandBuffer();
14934
14935 m_errorMonitor->VerifyFound();
14936
14937 vkDestroyImage(m_device->device(), srcImage, NULL);
14938 vkDestroyImage(m_device->device(), dstImage, NULL);
14939 vkFreeMemory(m_device->device(), srcMem, NULL);
14940 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014941}
14942
Karl Schultz6addd812016-02-02 17:17:23 -070014943TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14944 VkResult err;
14945 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014946
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014947 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14949 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014950
Mike Stroyana3082432015-09-25 13:39:21 -060014951 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014952
14953 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014954 VkImage srcImage;
14955 VkImage dstImage;
14956 VkDeviceMemory srcMem;
14957 VkDeviceMemory destMem;
14958 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014959
14960 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014961 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14962 image_create_info.pNext = NULL;
14963 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14964 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14965 image_create_info.extent.width = 32;
14966 image_create_info.extent.height = 32;
14967 image_create_info.extent.depth = 1;
14968 image_create_info.mipLevels = 1;
14969 image_create_info.arrayLayers = 1;
14970 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14971 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14972 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14973 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014974
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014975 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014976 ASSERT_VK_SUCCESS(err);
14977
Karl Schultzbdb75952016-04-19 11:36:49 -060014978 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14979
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014980 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014981 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014982 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014983 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014985 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014986 ASSERT_VK_SUCCESS(err);
14987
14988 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014989 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014990 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14991 memAlloc.pNext = NULL;
14992 memAlloc.allocationSize = 0;
14993 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014994
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014995 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014996 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014997 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014998 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014999 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015000 ASSERT_VK_SUCCESS(err);
15001
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015002 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015003 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015004 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015005 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015006 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015007 ASSERT_VK_SUCCESS(err);
15008
15009 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15010 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015011 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015012 ASSERT_VK_SUCCESS(err);
15013
15014 BeginCommandBuffer();
15015 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015016 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015017 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015018 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015019 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015020 copyRegion.srcOffset.x = 0;
15021 copyRegion.srcOffset.y = 0;
15022 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015023 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015024 copyRegion.dstSubresource.mipLevel = 0;
15025 copyRegion.dstSubresource.baseArrayLayer = 0;
15026 copyRegion.dstSubresource.layerCount = 0;
15027 copyRegion.dstOffset.x = 0;
15028 copyRegion.dstOffset.y = 0;
15029 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015030 copyRegion.extent.width = 1;
15031 copyRegion.extent.height = 1;
15032 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015033 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015034 EndCommandBuffer();
15035
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015036 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015037
Chia-I Wuf7458c52015-10-26 21:10:41 +080015038 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015039 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015040 vkFreeMemory(m_device->device(), srcMem, NULL);
15041 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015042}
15043
Karl Schultz6addd812016-02-02 17:17:23 -070015044TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15045 VkResult err;
15046 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015047
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15049 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015050
Mike Stroyana3082432015-09-25 13:39:21 -060015051 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015052
15053 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015054 VkImage srcImage;
15055 VkImage dstImage;
15056 VkDeviceMemory srcMem;
15057 VkDeviceMemory destMem;
15058 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015059
15060 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015061 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15062 image_create_info.pNext = NULL;
15063 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15064 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15065 image_create_info.extent.width = 32;
15066 image_create_info.extent.height = 1;
15067 image_create_info.extent.depth = 1;
15068 image_create_info.mipLevels = 1;
15069 image_create_info.arrayLayers = 1;
15070 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15071 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15072 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15073 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015074
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015075 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015076 ASSERT_VK_SUCCESS(err);
15077
Karl Schultz6addd812016-02-02 17:17:23 -070015078 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015079
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015080 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015081 ASSERT_VK_SUCCESS(err);
15082
15083 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015084 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015085 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15086 memAlloc.pNext = NULL;
15087 memAlloc.allocationSize = 0;
15088 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015089
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015090 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015091 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015092 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015093 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015094 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015095 ASSERT_VK_SUCCESS(err);
15096
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015097 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015098 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015099 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015100 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015101 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015102 ASSERT_VK_SUCCESS(err);
15103
15104 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15105 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015106 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015107 ASSERT_VK_SUCCESS(err);
15108
15109 BeginCommandBuffer();
15110 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015111 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15112 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015113 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015114 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015115 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015116 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015117 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015118 resolveRegion.srcOffset.x = 0;
15119 resolveRegion.srcOffset.y = 0;
15120 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015121 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015122 resolveRegion.dstSubresource.mipLevel = 0;
15123 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015124 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015125 resolveRegion.dstOffset.x = 0;
15126 resolveRegion.dstOffset.y = 0;
15127 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015128 resolveRegion.extent.width = 1;
15129 resolveRegion.extent.height = 1;
15130 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015131 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015132 EndCommandBuffer();
15133
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015134 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015135
Chia-I Wuf7458c52015-10-26 21:10:41 +080015136 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015137 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015138 vkFreeMemory(m_device->device(), srcMem, NULL);
15139 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015140}
15141
Karl Schultz6addd812016-02-02 17:17:23 -070015142TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15143 VkResult err;
15144 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015145
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15147 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015148
Mike Stroyana3082432015-09-25 13:39:21 -060015149 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015150
Chris Forbesa7530692016-05-08 12:35:39 +120015151 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015152 VkImage srcImage;
15153 VkImage dstImage;
15154 VkDeviceMemory srcMem;
15155 VkDeviceMemory destMem;
15156 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015157
15158 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015159 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15160 image_create_info.pNext = NULL;
15161 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15162 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15163 image_create_info.extent.width = 32;
15164 image_create_info.extent.height = 1;
15165 image_create_info.extent.depth = 1;
15166 image_create_info.mipLevels = 1;
15167 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015168 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015169 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15170 // Note: Some implementations expect color attachment usage for any
15171 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015172 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015173 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015175 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015176 ASSERT_VK_SUCCESS(err);
15177
Karl Schultz6addd812016-02-02 17:17:23 -070015178 // Note: Some implementations expect color attachment usage for any
15179 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015180 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015181
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015182 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015183 ASSERT_VK_SUCCESS(err);
15184
15185 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015186 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015187 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15188 memAlloc.pNext = NULL;
15189 memAlloc.allocationSize = 0;
15190 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015191
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015192 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015193 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015194 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015195 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015196 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015197 ASSERT_VK_SUCCESS(err);
15198
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015199 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015200 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015201 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015202 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015203 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015204 ASSERT_VK_SUCCESS(err);
15205
15206 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15207 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015208 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015209 ASSERT_VK_SUCCESS(err);
15210
15211 BeginCommandBuffer();
15212 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015213 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15214 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015215 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015216 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015217 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015218 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015219 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015220 resolveRegion.srcOffset.x = 0;
15221 resolveRegion.srcOffset.y = 0;
15222 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015223 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015224 resolveRegion.dstSubresource.mipLevel = 0;
15225 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015226 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015227 resolveRegion.dstOffset.x = 0;
15228 resolveRegion.dstOffset.y = 0;
15229 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015230 resolveRegion.extent.width = 1;
15231 resolveRegion.extent.height = 1;
15232 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015233 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015234 EndCommandBuffer();
15235
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015236 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015237
Chia-I Wuf7458c52015-10-26 21:10:41 +080015238 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015239 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015240 vkFreeMemory(m_device->device(), srcMem, NULL);
15241 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015242}
15243
Karl Schultz6addd812016-02-02 17:17:23 -070015244TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15245 VkResult err;
15246 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015247
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15249 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015250
Mike Stroyana3082432015-09-25 13:39:21 -060015251 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015252
15253 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015254 VkImage srcImage;
15255 VkImage dstImage;
15256 VkDeviceMemory srcMem;
15257 VkDeviceMemory destMem;
15258 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015259
15260 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015261 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15262 image_create_info.pNext = NULL;
15263 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15264 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15265 image_create_info.extent.width = 32;
15266 image_create_info.extent.height = 1;
15267 image_create_info.extent.depth = 1;
15268 image_create_info.mipLevels = 1;
15269 image_create_info.arrayLayers = 1;
15270 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15271 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15272 // Note: Some implementations expect color attachment usage for any
15273 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015274 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015275 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015276
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015277 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015278 ASSERT_VK_SUCCESS(err);
15279
Karl Schultz6addd812016-02-02 17:17:23 -070015280 // Set format to something other than source image
15281 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15282 // Note: Some implementations expect color attachment usage for any
15283 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015284 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015285 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015286
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015287 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015288 ASSERT_VK_SUCCESS(err);
15289
15290 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015291 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015292 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15293 memAlloc.pNext = NULL;
15294 memAlloc.allocationSize = 0;
15295 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015296
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015297 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015298 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015299 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015300 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015301 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015302 ASSERT_VK_SUCCESS(err);
15303
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015304 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015305 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015306 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015307 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015308 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015309 ASSERT_VK_SUCCESS(err);
15310
15311 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15312 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015313 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015314 ASSERT_VK_SUCCESS(err);
15315
15316 BeginCommandBuffer();
15317 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015318 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15319 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015320 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015321 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015322 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015323 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015324 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015325 resolveRegion.srcOffset.x = 0;
15326 resolveRegion.srcOffset.y = 0;
15327 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015328 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015329 resolveRegion.dstSubresource.mipLevel = 0;
15330 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015331 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015332 resolveRegion.dstOffset.x = 0;
15333 resolveRegion.dstOffset.y = 0;
15334 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015335 resolveRegion.extent.width = 1;
15336 resolveRegion.extent.height = 1;
15337 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015338 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015339 EndCommandBuffer();
15340
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015341 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015342
Chia-I Wuf7458c52015-10-26 21:10:41 +080015343 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015344 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015345 vkFreeMemory(m_device->device(), srcMem, NULL);
15346 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015347}
15348
Karl Schultz6addd812016-02-02 17:17:23 -070015349TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15350 VkResult err;
15351 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15354 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015355
Mike Stroyana3082432015-09-25 13:39:21 -060015356 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015357
15358 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015359 VkImage srcImage;
15360 VkImage dstImage;
15361 VkDeviceMemory srcMem;
15362 VkDeviceMemory destMem;
15363 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015364
15365 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015366 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15367 image_create_info.pNext = NULL;
15368 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15369 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15370 image_create_info.extent.width = 32;
15371 image_create_info.extent.height = 1;
15372 image_create_info.extent.depth = 1;
15373 image_create_info.mipLevels = 1;
15374 image_create_info.arrayLayers = 1;
15375 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15376 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15377 // Note: Some implementations expect color attachment usage for any
15378 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015379 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015380 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015381
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015382 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015383 ASSERT_VK_SUCCESS(err);
15384
Karl Schultz6addd812016-02-02 17:17:23 -070015385 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15386 // Note: Some implementations expect color attachment usage for any
15387 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015388 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015389 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015390
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015391 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015392 ASSERT_VK_SUCCESS(err);
15393
15394 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015395 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015396 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15397 memAlloc.pNext = NULL;
15398 memAlloc.allocationSize = 0;
15399 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015400
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015401 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015402 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015403 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015404 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015405 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015406 ASSERT_VK_SUCCESS(err);
15407
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015408 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015409 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015410 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015411 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015412 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015413 ASSERT_VK_SUCCESS(err);
15414
15415 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15416 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015417 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015418 ASSERT_VK_SUCCESS(err);
15419
15420 BeginCommandBuffer();
15421 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015422 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15423 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015424 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015425 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015426 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015427 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015428 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015429 resolveRegion.srcOffset.x = 0;
15430 resolveRegion.srcOffset.y = 0;
15431 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015432 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015433 resolveRegion.dstSubresource.mipLevel = 0;
15434 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015435 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015436 resolveRegion.dstOffset.x = 0;
15437 resolveRegion.dstOffset.y = 0;
15438 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015439 resolveRegion.extent.width = 1;
15440 resolveRegion.extent.height = 1;
15441 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015442 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015443 EndCommandBuffer();
15444
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015445 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015446
Chia-I Wuf7458c52015-10-26 21:10:41 +080015447 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015448 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015449 vkFreeMemory(m_device->device(), srcMem, NULL);
15450 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015451}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015452
Karl Schultz6addd812016-02-02 17:17:23 -070015453TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015454 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015455 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15456 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015457 // The image format check comes 2nd in validation so we trigger it first,
15458 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015459 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015460
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15462 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015463
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015464 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015465
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015466 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015467 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15468 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015469
15470 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015471 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15472 ds_pool_ci.pNext = NULL;
15473 ds_pool_ci.maxSets = 1;
15474 ds_pool_ci.poolSizeCount = 1;
15475 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015476
15477 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015478 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015479 ASSERT_VK_SUCCESS(err);
15480
15481 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015482 dsl_binding.binding = 0;
15483 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15484 dsl_binding.descriptorCount = 1;
15485 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15486 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015487
15488 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015489 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15490 ds_layout_ci.pNext = NULL;
15491 ds_layout_ci.bindingCount = 1;
15492 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015493 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015494 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015495 ASSERT_VK_SUCCESS(err);
15496
15497 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015498 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015499 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015500 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015501 alloc_info.descriptorPool = ds_pool;
15502 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015503 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015504 ASSERT_VK_SUCCESS(err);
15505
Karl Schultz6addd812016-02-02 17:17:23 -070015506 VkImage image_bad;
15507 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015508 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015509 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015510 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015511 const int32_t tex_width = 32;
15512 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015513
15514 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015515 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15516 image_create_info.pNext = NULL;
15517 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15518 image_create_info.format = tex_format_bad;
15519 image_create_info.extent.width = tex_width;
15520 image_create_info.extent.height = tex_height;
15521 image_create_info.extent.depth = 1;
15522 image_create_info.mipLevels = 1;
15523 image_create_info.arrayLayers = 1;
15524 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15525 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015526 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015527 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015529 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015530 ASSERT_VK_SUCCESS(err);
15531 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015532 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15533 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015534 ASSERT_VK_SUCCESS(err);
15535
15536 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015537 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015538 image_view_create_info.image = image_bad;
15539 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15540 image_view_create_info.format = tex_format_bad;
15541 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15542 image_view_create_info.subresourceRange.baseMipLevel = 0;
15543 image_view_create_info.subresourceRange.layerCount = 1;
15544 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015545 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015546
15547 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015548 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015549
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015550 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015551
Chia-I Wuf7458c52015-10-26 21:10:41 +080015552 vkDestroyImage(m_device->device(), image_bad, NULL);
15553 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015554 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15555 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015556}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015557
15558TEST_F(VkLayerTest, ClearImageErrors) {
15559 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15560 "ClearDepthStencilImage with a color image.");
15561
15562 ASSERT_NO_FATAL_FAILURE(InitState());
15563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15564
15565 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15566 BeginCommandBuffer();
15567 m_commandBuffer->EndRenderPass();
15568
15569 // Color image
15570 VkClearColorValue clear_color;
15571 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15572 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15573 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15574 const int32_t img_width = 32;
15575 const int32_t img_height = 32;
15576 VkImageCreateInfo image_create_info = {};
15577 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15578 image_create_info.pNext = NULL;
15579 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15580 image_create_info.format = color_format;
15581 image_create_info.extent.width = img_width;
15582 image_create_info.extent.height = img_height;
15583 image_create_info.extent.depth = 1;
15584 image_create_info.mipLevels = 1;
15585 image_create_info.arrayLayers = 1;
15586 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15587 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15588 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15589
15590 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015591 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015592
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015593 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015594
15595 // Depth/Stencil image
15596 VkClearDepthStencilValue clear_value = {0};
15597 reqs = 0; // don't need HOST_VISIBLE DS image
15598 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15599 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15600 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15601 ds_image_create_info.extent.width = 64;
15602 ds_image_create_info.extent.height = 64;
15603 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15604 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15605
15606 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015607 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015608
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015609 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 -060015610
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015612
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015613 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015614 &color_range);
15615
15616 m_errorMonitor->VerifyFound();
15617
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15619 "image created without "
15620 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015621
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015622 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015623 &color_range);
15624
15625 m_errorMonitor->VerifyFound();
15626
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015627 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15629 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015630
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015631 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15632 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015633
15634 m_errorMonitor->VerifyFound();
15635}
Tobin Ehliscde08892015-09-22 10:11:37 -060015636#endif // IMAGE_TESTS
15637
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015638
15639// WSI Enabled Tests
15640//
Chris Forbes09368e42016-10-13 11:59:22 +130015641#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015642TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15643
15644#if defined(VK_USE_PLATFORM_XCB_KHR)
15645 VkSurfaceKHR surface = VK_NULL_HANDLE;
15646
15647 VkResult err;
15648 bool pass;
15649 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15650 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15651 // uint32_t swapchain_image_count = 0;
15652 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15653 // uint32_t image_index = 0;
15654 // VkPresentInfoKHR present_info = {};
15655
15656 ASSERT_NO_FATAL_FAILURE(InitState());
15657
15658 // Use the create function from one of the VK_KHR_*_surface extension in
15659 // order to create a surface, testing all known errors in the process,
15660 // before successfully creating a surface:
15661 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15663 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15664 pass = (err != VK_SUCCESS);
15665 ASSERT_TRUE(pass);
15666 m_errorMonitor->VerifyFound();
15667
15668 // Next, try to create a surface with the wrong
15669 // VkXcbSurfaceCreateInfoKHR::sType:
15670 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15671 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15673 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15674 pass = (err != VK_SUCCESS);
15675 ASSERT_TRUE(pass);
15676 m_errorMonitor->VerifyFound();
15677
15678 // Create a native window, and then correctly create a surface:
15679 xcb_connection_t *connection;
15680 xcb_screen_t *screen;
15681 xcb_window_t xcb_window;
15682 xcb_intern_atom_reply_t *atom_wm_delete_window;
15683
15684 const xcb_setup_t *setup;
15685 xcb_screen_iterator_t iter;
15686 int scr;
15687 uint32_t value_mask, value_list[32];
15688 int width = 1;
15689 int height = 1;
15690
15691 connection = xcb_connect(NULL, &scr);
15692 ASSERT_TRUE(connection != NULL);
15693 setup = xcb_get_setup(connection);
15694 iter = xcb_setup_roots_iterator(setup);
15695 while (scr-- > 0)
15696 xcb_screen_next(&iter);
15697 screen = iter.data;
15698
15699 xcb_window = xcb_generate_id(connection);
15700
15701 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15702 value_list[0] = screen->black_pixel;
15703 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15704
15705 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15706 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15707
15708 /* Magic code that will send notification when window is destroyed */
15709 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15710 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15711
15712 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15713 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15714 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15715 free(reply);
15716
15717 xcb_map_window(connection, xcb_window);
15718
15719 // Force the x/y coordinates to 100,100 results are identical in consecutive
15720 // runs
15721 const uint32_t coords[] = { 100, 100 };
15722 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15723
15724 // Finally, try to correctly create a surface:
15725 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15726 xcb_create_info.pNext = NULL;
15727 xcb_create_info.flags = 0;
15728 xcb_create_info.connection = connection;
15729 xcb_create_info.window = xcb_window;
15730 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15731 pass = (err == VK_SUCCESS);
15732 ASSERT_TRUE(pass);
15733
15734 // Check if surface supports presentation:
15735
15736 // 1st, do so without having queried the queue families:
15737 VkBool32 supported = false;
15738 // TODO: Get the following error to come out:
15739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15740 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15741 "function");
15742 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15743 pass = (err != VK_SUCCESS);
15744 // ASSERT_TRUE(pass);
15745 // m_errorMonitor->VerifyFound();
15746
15747 // Next, query a queue family index that's too large:
15748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15749 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15750 pass = (err != VK_SUCCESS);
15751 ASSERT_TRUE(pass);
15752 m_errorMonitor->VerifyFound();
15753
15754 // Finally, do so correctly:
15755 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15756 // SUPPORTED
15757 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15758 pass = (err == VK_SUCCESS);
15759 ASSERT_TRUE(pass);
15760
15761 // Before proceeding, try to create a swapchain without having called
15762 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15763 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15764 swapchain_create_info.pNext = NULL;
15765 swapchain_create_info.flags = 0;
15766 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15767 swapchain_create_info.surface = surface;
15768 swapchain_create_info.imageArrayLayers = 1;
15769 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15770 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15772 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15773 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15774 pass = (err != VK_SUCCESS);
15775 ASSERT_TRUE(pass);
15776 m_errorMonitor->VerifyFound();
15777
15778 // Get the surface capabilities:
15779 VkSurfaceCapabilitiesKHR surface_capabilities;
15780
15781 // Do so correctly (only error logged by this entrypoint is if the
15782 // extension isn't enabled):
15783 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15784 pass = (err == VK_SUCCESS);
15785 ASSERT_TRUE(pass);
15786
15787 // Get the surface formats:
15788 uint32_t surface_format_count;
15789
15790 // First, try without a pointer to surface_format_count:
15791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15792 "specified as NULL");
15793 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15794 pass = (err == VK_SUCCESS);
15795 ASSERT_TRUE(pass);
15796 m_errorMonitor->VerifyFound();
15797
15798 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15799 // correctly done a 1st try (to get the count):
15800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15801 surface_format_count = 0;
15802 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15803 pass = (err == VK_SUCCESS);
15804 ASSERT_TRUE(pass);
15805 m_errorMonitor->VerifyFound();
15806
15807 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15808 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15809 pass = (err == VK_SUCCESS);
15810 ASSERT_TRUE(pass);
15811
15812 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15813 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15814
15815 // Next, do a 2nd try with surface_format_count being set too high:
15816 surface_format_count += 5;
15817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15818 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15819 pass = (err == VK_SUCCESS);
15820 ASSERT_TRUE(pass);
15821 m_errorMonitor->VerifyFound();
15822
15823 // Finally, do a correct 1st and 2nd try:
15824 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15825 pass = (err == VK_SUCCESS);
15826 ASSERT_TRUE(pass);
15827 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15828 pass = (err == VK_SUCCESS);
15829 ASSERT_TRUE(pass);
15830
15831 // Get the surface present modes:
15832 uint32_t surface_present_mode_count;
15833
15834 // First, try without a pointer to surface_format_count:
15835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15836 "specified as NULL");
15837
15838 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15839 pass = (err == VK_SUCCESS);
15840 ASSERT_TRUE(pass);
15841 m_errorMonitor->VerifyFound();
15842
15843 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15844 // correctly done a 1st try (to get the count):
15845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15846 surface_present_mode_count = 0;
15847 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15848 (VkPresentModeKHR *)&surface_present_mode_count);
15849 pass = (err == VK_SUCCESS);
15850 ASSERT_TRUE(pass);
15851 m_errorMonitor->VerifyFound();
15852
15853 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15854 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15855 pass = (err == VK_SUCCESS);
15856 ASSERT_TRUE(pass);
15857
15858 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15859 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15860
15861 // Next, do a 2nd try with surface_format_count being set too high:
15862 surface_present_mode_count += 5;
15863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15864 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15865 pass = (err == VK_SUCCESS);
15866 ASSERT_TRUE(pass);
15867 m_errorMonitor->VerifyFound();
15868
15869 // Finally, do a correct 1st and 2nd try:
15870 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15871 pass = (err == VK_SUCCESS);
15872 ASSERT_TRUE(pass);
15873 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15874 pass = (err == VK_SUCCESS);
15875 ASSERT_TRUE(pass);
15876
15877 // Create a swapchain:
15878
15879 // First, try without a pointer to swapchain_create_info:
15880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15881 "specified as NULL");
15882
15883 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15884 pass = (err != VK_SUCCESS);
15885 ASSERT_TRUE(pass);
15886 m_errorMonitor->VerifyFound();
15887
15888 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15889 // sType:
15890 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15892
15893 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15894 pass = (err != VK_SUCCESS);
15895 ASSERT_TRUE(pass);
15896 m_errorMonitor->VerifyFound();
15897
15898 // Next, call with a NULL swapchain pointer:
15899 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15900 swapchain_create_info.pNext = NULL;
15901 swapchain_create_info.flags = 0;
15902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15903 "specified as NULL");
15904
15905 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15906 pass = (err != VK_SUCCESS);
15907 ASSERT_TRUE(pass);
15908 m_errorMonitor->VerifyFound();
15909
15910 // TODO: Enhance swapchain layer so that
15911 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15912
15913 // Next, call with a queue family index that's too large:
15914 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15915 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15916 swapchain_create_info.queueFamilyIndexCount = 2;
15917 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15919 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15920 pass = (err != VK_SUCCESS);
15921 ASSERT_TRUE(pass);
15922 m_errorMonitor->VerifyFound();
15923
15924 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15925 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15926 swapchain_create_info.queueFamilyIndexCount = 1;
15927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15928 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15929 "pCreateInfo->pQueueFamilyIndices).");
15930 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15931 pass = (err != VK_SUCCESS);
15932 ASSERT_TRUE(pass);
15933 m_errorMonitor->VerifyFound();
15934
15935 // Next, call with an invalid imageSharingMode:
15936 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15937 swapchain_create_info.queueFamilyIndexCount = 1;
15938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15939 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15940 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15941 pass = (err != VK_SUCCESS);
15942 ASSERT_TRUE(pass);
15943 m_errorMonitor->VerifyFound();
15944 // Fix for the future:
15945 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15946 // SUPPORTED
15947 swapchain_create_info.queueFamilyIndexCount = 0;
15948 queueFamilyIndex[0] = 0;
15949 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15950
15951 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15952 // Get the images from a swapchain:
15953 // Acquire an image from a swapchain:
15954 // Present an image to a swapchain:
15955 // Destroy the swapchain:
15956
15957 // TODOs:
15958 //
15959 // - Try destroying the device without first destroying the swapchain
15960 //
15961 // - Try destroying the device without first destroying the surface
15962 //
15963 // - Try destroying the surface without first destroying the swapchain
15964
15965 // Destroy the surface:
15966 vkDestroySurfaceKHR(instance(), surface, NULL);
15967
15968 // Tear down the window:
15969 xcb_destroy_window(connection, xcb_window);
15970 xcb_disconnect(connection);
15971
15972#else // VK_USE_PLATFORM_XCB_KHR
15973 return;
15974#endif // VK_USE_PLATFORM_XCB_KHR
15975}
Chris Forbes09368e42016-10-13 11:59:22 +130015976#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015977
15978//
15979// POSITIVE VALIDATION TESTS
15980//
15981// These tests do not expect to encounter ANY validation errors pass only if this is true
15982
Tobin Ehlise0006882016-11-03 10:14:28 -060015983TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15984 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15985 "by a transition in the primary.");
15986 VkResult err;
15987 m_errorMonitor->ExpectSuccess();
15988 ASSERT_NO_FATAL_FAILURE(InitState());
15989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15990 // Allocate a secondary and primary cmd buffer
15991 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15992 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15993 command_buffer_allocate_info.commandPool = m_commandPool;
15994 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15995 command_buffer_allocate_info.commandBufferCount = 1;
15996
15997 VkCommandBuffer secondary_command_buffer;
15998 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15999 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16000 VkCommandBuffer primary_command_buffer;
16001 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16002 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16003 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16004 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16005 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16006 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16007 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16008
16009 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16010 ASSERT_VK_SUCCESS(err);
16011 VkImageObj image(m_device);
16012 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16013 ASSERT_TRUE(image.initialized());
16014 VkImageMemoryBarrier img_barrier = {};
16015 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16016 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16017 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16018 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16019 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16020 img_barrier.image = image.handle();
16021 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16022 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16023 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16024 img_barrier.subresourceRange.baseArrayLayer = 0;
16025 img_barrier.subresourceRange.baseMipLevel = 0;
16026 img_barrier.subresourceRange.layerCount = 1;
16027 img_barrier.subresourceRange.levelCount = 1;
16028 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16029 0, nullptr, 1, &img_barrier);
16030 err = vkEndCommandBuffer(secondary_command_buffer);
16031 ASSERT_VK_SUCCESS(err);
16032
16033 // Now update primary cmd buffer to execute secondary and transitions image
16034 command_buffer_begin_info.pInheritanceInfo = nullptr;
16035 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16036 ASSERT_VK_SUCCESS(err);
16037 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16038 VkImageMemoryBarrier img_barrier2 = {};
16039 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16040 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16041 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16042 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16043 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16044 img_barrier2.image = image.handle();
16045 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16046 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16047 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16048 img_barrier2.subresourceRange.baseArrayLayer = 0;
16049 img_barrier2.subresourceRange.baseMipLevel = 0;
16050 img_barrier2.subresourceRange.layerCount = 1;
16051 img_barrier2.subresourceRange.levelCount = 1;
16052 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16053 nullptr, 1, &img_barrier2);
16054 err = vkEndCommandBuffer(primary_command_buffer);
16055 ASSERT_VK_SUCCESS(err);
16056 VkSubmitInfo submit_info = {};
16057 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16058 submit_info.commandBufferCount = 1;
16059 submit_info.pCommandBuffers = &primary_command_buffer;
16060 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16061 ASSERT_VK_SUCCESS(err);
16062 m_errorMonitor->VerifyNotFound();
16063 err = vkDeviceWaitIdle(m_device->device());
16064 ASSERT_VK_SUCCESS(err);
16065 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16066 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16067}
16068
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016069// This is a positive test. No failures are expected.
16070TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
16071 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
16072 "is ignoring VkWriteDescriptorSet members that are not "
16073 "related to the descriptor type specified by "
16074 "VkWriteDescriptorSet::descriptorType. Correct "
16075 "validation behavior will result in the test running to "
16076 "completion without validation errors.");
16077
16078 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16079
16080 ASSERT_NO_FATAL_FAILURE(InitState());
16081
16082 // Image Case
16083 {
16084 m_errorMonitor->ExpectSuccess();
16085
16086 VkImage image;
16087 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16088 const int32_t tex_width = 32;
16089 const int32_t tex_height = 32;
16090 VkImageCreateInfo image_create_info = {};
16091 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16092 image_create_info.pNext = NULL;
16093 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16094 image_create_info.format = tex_format;
16095 image_create_info.extent.width = tex_width;
16096 image_create_info.extent.height = tex_height;
16097 image_create_info.extent.depth = 1;
16098 image_create_info.mipLevels = 1;
16099 image_create_info.arrayLayers = 1;
16100 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16101 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16102 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16103 image_create_info.flags = 0;
16104 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16105 ASSERT_VK_SUCCESS(err);
16106
16107 VkMemoryRequirements memory_reqs;
16108 VkDeviceMemory image_memory;
16109 bool pass;
16110 VkMemoryAllocateInfo memory_info = {};
16111 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16112 memory_info.pNext = NULL;
16113 memory_info.allocationSize = 0;
16114 memory_info.memoryTypeIndex = 0;
16115 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16116 memory_info.allocationSize = memory_reqs.size;
16117 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16118 ASSERT_TRUE(pass);
16119 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16120 ASSERT_VK_SUCCESS(err);
16121 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16122 ASSERT_VK_SUCCESS(err);
16123
16124 VkImageViewCreateInfo image_view_create_info = {};
16125 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16126 image_view_create_info.image = image;
16127 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16128 image_view_create_info.format = tex_format;
16129 image_view_create_info.subresourceRange.layerCount = 1;
16130 image_view_create_info.subresourceRange.baseMipLevel = 0;
16131 image_view_create_info.subresourceRange.levelCount = 1;
16132 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16133
16134 VkImageView view;
16135 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16136 ASSERT_VK_SUCCESS(err);
16137
16138 VkDescriptorPoolSize ds_type_count = {};
16139 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16140 ds_type_count.descriptorCount = 1;
16141
16142 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16143 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16144 ds_pool_ci.pNext = NULL;
16145 ds_pool_ci.maxSets = 1;
16146 ds_pool_ci.poolSizeCount = 1;
16147 ds_pool_ci.pPoolSizes = &ds_type_count;
16148
16149 VkDescriptorPool ds_pool;
16150 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16151 ASSERT_VK_SUCCESS(err);
16152
16153 VkDescriptorSetLayoutBinding dsl_binding = {};
16154 dsl_binding.binding = 0;
16155 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16156 dsl_binding.descriptorCount = 1;
16157 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16158 dsl_binding.pImmutableSamplers = NULL;
16159
16160 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16161 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16162 ds_layout_ci.pNext = NULL;
16163 ds_layout_ci.bindingCount = 1;
16164 ds_layout_ci.pBindings = &dsl_binding;
16165 VkDescriptorSetLayout ds_layout;
16166 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16167 ASSERT_VK_SUCCESS(err);
16168
16169 VkDescriptorSet descriptor_set;
16170 VkDescriptorSetAllocateInfo alloc_info = {};
16171 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16172 alloc_info.descriptorSetCount = 1;
16173 alloc_info.descriptorPool = ds_pool;
16174 alloc_info.pSetLayouts = &ds_layout;
16175 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16176 ASSERT_VK_SUCCESS(err);
16177
16178 VkDescriptorImageInfo image_info = {};
16179 image_info.imageView = view;
16180 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16181
16182 VkWriteDescriptorSet descriptor_write;
16183 memset(&descriptor_write, 0, sizeof(descriptor_write));
16184 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16185 descriptor_write.dstSet = descriptor_set;
16186 descriptor_write.dstBinding = 0;
16187 descriptor_write.descriptorCount = 1;
16188 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16189 descriptor_write.pImageInfo = &image_info;
16190
16191 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16192 // be
16193 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16194 // This will most likely produce a crash if the parameter_validation
16195 // layer
16196 // does not correctly ignore pBufferInfo.
16197 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16198 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16199
16200 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16201
16202 m_errorMonitor->VerifyNotFound();
16203
16204 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16205 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16206 vkDestroyImageView(m_device->device(), view, NULL);
16207 vkDestroyImage(m_device->device(), image, NULL);
16208 vkFreeMemory(m_device->device(), image_memory, NULL);
16209 }
16210
16211 // Buffer Case
16212 {
16213 m_errorMonitor->ExpectSuccess();
16214
16215 VkBuffer buffer;
16216 uint32_t queue_family_index = 0;
16217 VkBufferCreateInfo buffer_create_info = {};
16218 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16219 buffer_create_info.size = 1024;
16220 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16221 buffer_create_info.queueFamilyIndexCount = 1;
16222 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16223
16224 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16225 ASSERT_VK_SUCCESS(err);
16226
16227 VkMemoryRequirements memory_reqs;
16228 VkDeviceMemory buffer_memory;
16229 bool pass;
16230 VkMemoryAllocateInfo memory_info = {};
16231 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16232 memory_info.pNext = NULL;
16233 memory_info.allocationSize = 0;
16234 memory_info.memoryTypeIndex = 0;
16235
16236 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16237 memory_info.allocationSize = memory_reqs.size;
16238 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16239 ASSERT_TRUE(pass);
16240
16241 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16242 ASSERT_VK_SUCCESS(err);
16243 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16244 ASSERT_VK_SUCCESS(err);
16245
16246 VkDescriptorPoolSize ds_type_count = {};
16247 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16248 ds_type_count.descriptorCount = 1;
16249
16250 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16251 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16252 ds_pool_ci.pNext = NULL;
16253 ds_pool_ci.maxSets = 1;
16254 ds_pool_ci.poolSizeCount = 1;
16255 ds_pool_ci.pPoolSizes = &ds_type_count;
16256
16257 VkDescriptorPool ds_pool;
16258 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16259 ASSERT_VK_SUCCESS(err);
16260
16261 VkDescriptorSetLayoutBinding dsl_binding = {};
16262 dsl_binding.binding = 0;
16263 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16264 dsl_binding.descriptorCount = 1;
16265 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16266 dsl_binding.pImmutableSamplers = NULL;
16267
16268 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16269 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16270 ds_layout_ci.pNext = NULL;
16271 ds_layout_ci.bindingCount = 1;
16272 ds_layout_ci.pBindings = &dsl_binding;
16273 VkDescriptorSetLayout ds_layout;
16274 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16275 ASSERT_VK_SUCCESS(err);
16276
16277 VkDescriptorSet descriptor_set;
16278 VkDescriptorSetAllocateInfo alloc_info = {};
16279 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16280 alloc_info.descriptorSetCount = 1;
16281 alloc_info.descriptorPool = ds_pool;
16282 alloc_info.pSetLayouts = &ds_layout;
16283 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16284 ASSERT_VK_SUCCESS(err);
16285
16286 VkDescriptorBufferInfo buffer_info = {};
16287 buffer_info.buffer = buffer;
16288 buffer_info.offset = 0;
16289 buffer_info.range = 1024;
16290
16291 VkWriteDescriptorSet descriptor_write;
16292 memset(&descriptor_write, 0, sizeof(descriptor_write));
16293 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16294 descriptor_write.dstSet = descriptor_set;
16295 descriptor_write.dstBinding = 0;
16296 descriptor_write.descriptorCount = 1;
16297 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16298 descriptor_write.pBufferInfo = &buffer_info;
16299
16300 // Set pImageInfo and pTexelBufferView to invalid values, which should
16301 // be
16302 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16303 // This will most likely produce a crash if the parameter_validation
16304 // layer
16305 // does not correctly ignore pImageInfo.
16306 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16307 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16308
16309 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16310
16311 m_errorMonitor->VerifyNotFound();
16312
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016313 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16314 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16315 vkDestroyBuffer(m_device->device(), buffer, NULL);
16316 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16317 }
16318
16319 // Texel Buffer Case
16320 {
16321 m_errorMonitor->ExpectSuccess();
16322
16323 VkBuffer buffer;
16324 uint32_t queue_family_index = 0;
16325 VkBufferCreateInfo buffer_create_info = {};
16326 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16327 buffer_create_info.size = 1024;
16328 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16329 buffer_create_info.queueFamilyIndexCount = 1;
16330 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16331
16332 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16333 ASSERT_VK_SUCCESS(err);
16334
16335 VkMemoryRequirements memory_reqs;
16336 VkDeviceMemory buffer_memory;
16337 bool pass;
16338 VkMemoryAllocateInfo memory_info = {};
16339 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16340 memory_info.pNext = NULL;
16341 memory_info.allocationSize = 0;
16342 memory_info.memoryTypeIndex = 0;
16343
16344 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16345 memory_info.allocationSize = memory_reqs.size;
16346 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16347 ASSERT_TRUE(pass);
16348
16349 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16350 ASSERT_VK_SUCCESS(err);
16351 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16352 ASSERT_VK_SUCCESS(err);
16353
16354 VkBufferViewCreateInfo buff_view_ci = {};
16355 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16356 buff_view_ci.buffer = buffer;
16357 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16358 buff_view_ci.range = VK_WHOLE_SIZE;
16359 VkBufferView buffer_view;
16360 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16361
16362 VkDescriptorPoolSize ds_type_count = {};
16363 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16364 ds_type_count.descriptorCount = 1;
16365
16366 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16367 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16368 ds_pool_ci.pNext = NULL;
16369 ds_pool_ci.maxSets = 1;
16370 ds_pool_ci.poolSizeCount = 1;
16371 ds_pool_ci.pPoolSizes = &ds_type_count;
16372
16373 VkDescriptorPool ds_pool;
16374 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16375 ASSERT_VK_SUCCESS(err);
16376
16377 VkDescriptorSetLayoutBinding dsl_binding = {};
16378 dsl_binding.binding = 0;
16379 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16380 dsl_binding.descriptorCount = 1;
16381 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16382 dsl_binding.pImmutableSamplers = NULL;
16383
16384 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16385 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16386 ds_layout_ci.pNext = NULL;
16387 ds_layout_ci.bindingCount = 1;
16388 ds_layout_ci.pBindings = &dsl_binding;
16389 VkDescriptorSetLayout ds_layout;
16390 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16391 ASSERT_VK_SUCCESS(err);
16392
16393 VkDescriptorSet descriptor_set;
16394 VkDescriptorSetAllocateInfo alloc_info = {};
16395 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16396 alloc_info.descriptorSetCount = 1;
16397 alloc_info.descriptorPool = ds_pool;
16398 alloc_info.pSetLayouts = &ds_layout;
16399 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16400 ASSERT_VK_SUCCESS(err);
16401
16402 VkWriteDescriptorSet descriptor_write;
16403 memset(&descriptor_write, 0, sizeof(descriptor_write));
16404 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16405 descriptor_write.dstSet = descriptor_set;
16406 descriptor_write.dstBinding = 0;
16407 descriptor_write.descriptorCount = 1;
16408 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16409 descriptor_write.pTexelBufferView = &buffer_view;
16410
16411 // Set pImageInfo and pBufferInfo to invalid values, which should be
16412 // ignored for descriptorType ==
16413 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16414 // This will most likely produce a crash if the parameter_validation
16415 // layer
16416 // does not correctly ignore pImageInfo and pBufferInfo.
16417 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16418 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16419
16420 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16421
16422 m_errorMonitor->VerifyNotFound();
16423
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016424 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16425 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16426 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16427 vkDestroyBuffer(m_device->device(), buffer, NULL);
16428 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16429 }
16430}
16431
Tobin Ehlisf7428442016-10-25 07:58:24 -060016432TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16433 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16434
16435 ASSERT_NO_FATAL_FAILURE(InitState());
16436 // Create layout where two binding #s are "1"
16437 static const uint32_t NUM_BINDINGS = 3;
16438 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16439 dsl_binding[0].binding = 1;
16440 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16441 dsl_binding[0].descriptorCount = 1;
16442 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16443 dsl_binding[0].pImmutableSamplers = NULL;
16444 dsl_binding[1].binding = 0;
16445 dsl_binding[1].descriptorCount = 1;
16446 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16447 dsl_binding[1].descriptorCount = 1;
16448 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16449 dsl_binding[1].pImmutableSamplers = NULL;
16450 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16451 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16452 dsl_binding[2].descriptorCount = 1;
16453 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16454 dsl_binding[2].pImmutableSamplers = NULL;
16455
16456 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16457 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16458 ds_layout_ci.pNext = NULL;
16459 ds_layout_ci.bindingCount = NUM_BINDINGS;
16460 ds_layout_ci.pBindings = dsl_binding;
16461 VkDescriptorSetLayout ds_layout;
16462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16463 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16464 m_errorMonitor->VerifyFound();
16465}
16466
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016467TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016468 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16469
16470 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016471
16472 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016473
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016474 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16475
16476 {
16477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16478 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16479 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16480 m_errorMonitor->VerifyFound();
16481 }
16482
16483 {
16484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16485 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16486 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16487 m_errorMonitor->VerifyFound();
16488 }
16489
16490 {
16491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16492 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16493 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16494 m_errorMonitor->VerifyFound();
16495 }
16496
16497 {
16498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16499 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16500 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16501 m_errorMonitor->VerifyFound();
16502 }
16503
16504 {
16505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16506 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16507 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16508 m_errorMonitor->VerifyFound();
16509 }
16510
16511 {
16512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16513 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16514 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16515 m_errorMonitor->VerifyFound();
16516 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016517
16518 {
16519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16520 VkRect2D scissor = {{-1, 0}, {16, 16}};
16521 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16522 m_errorMonitor->VerifyFound();
16523 }
16524
16525 {
16526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16527 VkRect2D scissor = {{0, -2}, {16, 16}};
16528 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16529 m_errorMonitor->VerifyFound();
16530 }
16531
16532 {
16533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16534 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16535 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16536 m_errorMonitor->VerifyFound();
16537 }
16538
16539 {
16540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16541 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16542 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16543 m_errorMonitor->VerifyFound();
16544 }
16545
16546 EndCommandBuffer();
16547}
16548
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016549// This is a positive test. No failures are expected.
16550TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16551 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16552 VkResult err;
16553
16554 ASSERT_NO_FATAL_FAILURE(InitState());
16555 m_errorMonitor->ExpectSuccess();
16556 VkDescriptorPoolSize ds_type_count = {};
16557 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16558 ds_type_count.descriptorCount = 2;
16559
16560 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16561 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16562 ds_pool_ci.pNext = NULL;
16563 ds_pool_ci.maxSets = 1;
16564 ds_pool_ci.poolSizeCount = 1;
16565 ds_pool_ci.pPoolSizes = &ds_type_count;
16566
16567 VkDescriptorPool ds_pool;
16568 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16569 ASSERT_VK_SUCCESS(err);
16570
16571 // Create layout with two uniform buffer descriptors w/ empty binding between them
16572 static const uint32_t NUM_BINDINGS = 3;
16573 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16574 dsl_binding[0].binding = 0;
16575 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16576 dsl_binding[0].descriptorCount = 1;
16577 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16578 dsl_binding[0].pImmutableSamplers = NULL;
16579 dsl_binding[1].binding = 1;
16580 dsl_binding[1].descriptorCount = 0; // empty binding
16581 dsl_binding[2].binding = 2;
16582 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16583 dsl_binding[2].descriptorCount = 1;
16584 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16585 dsl_binding[2].pImmutableSamplers = NULL;
16586
16587 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16588 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16589 ds_layout_ci.pNext = NULL;
16590 ds_layout_ci.bindingCount = NUM_BINDINGS;
16591 ds_layout_ci.pBindings = dsl_binding;
16592 VkDescriptorSetLayout ds_layout;
16593 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16594 ASSERT_VK_SUCCESS(err);
16595
16596 VkDescriptorSet descriptor_set = {};
16597 VkDescriptorSetAllocateInfo alloc_info = {};
16598 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16599 alloc_info.descriptorSetCount = 1;
16600 alloc_info.descriptorPool = ds_pool;
16601 alloc_info.pSetLayouts = &ds_layout;
16602 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16603 ASSERT_VK_SUCCESS(err);
16604
16605 // Create a buffer to be used for update
16606 VkBufferCreateInfo buff_ci = {};
16607 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16608 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16609 buff_ci.size = 256;
16610 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16611 VkBuffer buffer;
16612 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16613 ASSERT_VK_SUCCESS(err);
16614 // Have to bind memory to buffer before descriptor update
16615 VkMemoryAllocateInfo mem_alloc = {};
16616 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16617 mem_alloc.pNext = NULL;
16618 mem_alloc.allocationSize = 512; // one allocation for both buffers
16619 mem_alloc.memoryTypeIndex = 0;
16620
16621 VkMemoryRequirements mem_reqs;
16622 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16623 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16624 if (!pass) {
16625 vkDestroyBuffer(m_device->device(), buffer, NULL);
16626 return;
16627 }
16628
16629 VkDeviceMemory mem;
16630 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16631 ASSERT_VK_SUCCESS(err);
16632 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16633 ASSERT_VK_SUCCESS(err);
16634
16635 // Only update the descriptor at binding 2
16636 VkDescriptorBufferInfo buff_info = {};
16637 buff_info.buffer = buffer;
16638 buff_info.offset = 0;
16639 buff_info.range = VK_WHOLE_SIZE;
16640 VkWriteDescriptorSet descriptor_write = {};
16641 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16642 descriptor_write.dstBinding = 2;
16643 descriptor_write.descriptorCount = 1;
16644 descriptor_write.pTexelBufferView = nullptr;
16645 descriptor_write.pBufferInfo = &buff_info;
16646 descriptor_write.pImageInfo = nullptr;
16647 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16648 descriptor_write.dstSet = descriptor_set;
16649
16650 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16651
16652 m_errorMonitor->VerifyNotFound();
16653 // Cleanup
16654 vkFreeMemory(m_device->device(), mem, NULL);
16655 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16656 vkDestroyBuffer(m_device->device(), buffer, NULL);
16657 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16658}
16659
16660// This is a positive test. No failures are expected.
16661TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16662 VkResult err;
16663 bool pass;
16664
16665 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16666 "the buffer, create an image, and bind the same memory to "
16667 "it");
16668
16669 m_errorMonitor->ExpectSuccess();
16670
16671 ASSERT_NO_FATAL_FAILURE(InitState());
16672
16673 VkBuffer buffer;
16674 VkImage image;
16675 VkDeviceMemory mem;
16676 VkMemoryRequirements mem_reqs;
16677
16678 VkBufferCreateInfo buf_info = {};
16679 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16680 buf_info.pNext = NULL;
16681 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16682 buf_info.size = 256;
16683 buf_info.queueFamilyIndexCount = 0;
16684 buf_info.pQueueFamilyIndices = NULL;
16685 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16686 buf_info.flags = 0;
16687 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16688 ASSERT_VK_SUCCESS(err);
16689
16690 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16691
16692 VkMemoryAllocateInfo alloc_info = {};
16693 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16694 alloc_info.pNext = NULL;
16695 alloc_info.memoryTypeIndex = 0;
16696
16697 // Ensure memory is big enough for both bindings
16698 alloc_info.allocationSize = 0x10000;
16699
16700 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16701 if (!pass) {
16702 vkDestroyBuffer(m_device->device(), buffer, NULL);
16703 return;
16704 }
16705
16706 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16707 ASSERT_VK_SUCCESS(err);
16708
16709 uint8_t *pData;
16710 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16711 ASSERT_VK_SUCCESS(err);
16712
16713 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16714
16715 vkUnmapMemory(m_device->device(), mem);
16716
16717 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16718 ASSERT_VK_SUCCESS(err);
16719
16720 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16721 // memory. In fact, it was never used by the GPU.
16722 // Just be be sure, wait for idle.
16723 vkDestroyBuffer(m_device->device(), buffer, NULL);
16724 vkDeviceWaitIdle(m_device->device());
16725
16726 VkImageCreateInfo image_create_info = {};
16727 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16728 image_create_info.pNext = NULL;
16729 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16730 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16731 image_create_info.extent.width = 64;
16732 image_create_info.extent.height = 64;
16733 image_create_info.extent.depth = 1;
16734 image_create_info.mipLevels = 1;
16735 image_create_info.arrayLayers = 1;
16736 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16737 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16738 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16739 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16740 image_create_info.queueFamilyIndexCount = 0;
16741 image_create_info.pQueueFamilyIndices = NULL;
16742 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16743 image_create_info.flags = 0;
16744
16745 VkMemoryAllocateInfo mem_alloc = {};
16746 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16747 mem_alloc.pNext = NULL;
16748 mem_alloc.allocationSize = 0;
16749 mem_alloc.memoryTypeIndex = 0;
16750
16751 /* Create a mappable image. It will be the texture if linear images are ok
16752 * to be textures or it will be the staging image if they are not.
16753 */
16754 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16755 ASSERT_VK_SUCCESS(err);
16756
16757 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16758
16759 mem_alloc.allocationSize = mem_reqs.size;
16760
16761 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16762 if (!pass) {
16763 vkDestroyImage(m_device->device(), image, NULL);
16764 return;
16765 }
16766
16767 // VALIDATION FAILURE:
16768 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16769 ASSERT_VK_SUCCESS(err);
16770
16771 m_errorMonitor->VerifyNotFound();
16772
16773 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016774 vkDestroyImage(m_device->device(), image, NULL);
16775}
16776
Tobin Ehlis953e8392016-11-17 10:54:13 -070016777TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16778 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16779 // We previously had a bug where dynamic offset of inactive bindings was still being used
16780 VkResult err;
16781 m_errorMonitor->ExpectSuccess();
16782
16783 ASSERT_NO_FATAL_FAILURE(InitState());
16784 ASSERT_NO_FATAL_FAILURE(InitViewport());
16785 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16786
16787 VkDescriptorPoolSize ds_type_count = {};
16788 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16789 ds_type_count.descriptorCount = 3;
16790
16791 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16792 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16793 ds_pool_ci.pNext = NULL;
16794 ds_pool_ci.maxSets = 1;
16795 ds_pool_ci.poolSizeCount = 1;
16796 ds_pool_ci.pPoolSizes = &ds_type_count;
16797
16798 VkDescriptorPool ds_pool;
16799 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16800 ASSERT_VK_SUCCESS(err);
16801
16802 const uint32_t BINDING_COUNT = 3;
16803 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016804 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016805 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16806 dsl_binding[0].descriptorCount = 1;
16807 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16808 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016809 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016810 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16811 dsl_binding[1].descriptorCount = 1;
16812 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16813 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016814 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016815 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16816 dsl_binding[2].descriptorCount = 1;
16817 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16818 dsl_binding[2].pImmutableSamplers = NULL;
16819
16820 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16821 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16822 ds_layout_ci.pNext = NULL;
16823 ds_layout_ci.bindingCount = BINDING_COUNT;
16824 ds_layout_ci.pBindings = dsl_binding;
16825 VkDescriptorSetLayout ds_layout;
16826 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16827 ASSERT_VK_SUCCESS(err);
16828
16829 VkDescriptorSet descriptor_set;
16830 VkDescriptorSetAllocateInfo alloc_info = {};
16831 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16832 alloc_info.descriptorSetCount = 1;
16833 alloc_info.descriptorPool = ds_pool;
16834 alloc_info.pSetLayouts = &ds_layout;
16835 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16836 ASSERT_VK_SUCCESS(err);
16837
16838 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16839 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16840 pipeline_layout_ci.pNext = NULL;
16841 pipeline_layout_ci.setLayoutCount = 1;
16842 pipeline_layout_ci.pSetLayouts = &ds_layout;
16843
16844 VkPipelineLayout pipeline_layout;
16845 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16846 ASSERT_VK_SUCCESS(err);
16847
16848 // Create two buffers to update the descriptors with
16849 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16850 uint32_t qfi = 0;
16851 VkBufferCreateInfo buffCI = {};
16852 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16853 buffCI.size = 2048;
16854 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16855 buffCI.queueFamilyIndexCount = 1;
16856 buffCI.pQueueFamilyIndices = &qfi;
16857
16858 VkBuffer dyub1;
16859 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16860 ASSERT_VK_SUCCESS(err);
16861 // buffer2
16862 buffCI.size = 1024;
16863 VkBuffer dyub2;
16864 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16865 ASSERT_VK_SUCCESS(err);
16866 // Allocate memory and bind to buffers
16867 VkMemoryAllocateInfo mem_alloc[2] = {};
16868 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16869 mem_alloc[0].pNext = NULL;
16870 mem_alloc[0].memoryTypeIndex = 0;
16871 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16872 mem_alloc[1].pNext = NULL;
16873 mem_alloc[1].memoryTypeIndex = 0;
16874
16875 VkMemoryRequirements mem_reqs1;
16876 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16877 VkMemoryRequirements mem_reqs2;
16878 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16879 mem_alloc[0].allocationSize = mem_reqs1.size;
16880 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16881 mem_alloc[1].allocationSize = mem_reqs2.size;
16882 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16883 if (!pass) {
16884 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16885 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16886 return;
16887 }
16888
16889 VkDeviceMemory mem1;
16890 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16891 ASSERT_VK_SUCCESS(err);
16892 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
16893 ASSERT_VK_SUCCESS(err);
16894 VkDeviceMemory mem2;
16895 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
16896 ASSERT_VK_SUCCESS(err);
16897 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
16898 ASSERT_VK_SUCCESS(err);
16899 // Update descriptors
16900 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
16901 buff_info[0].buffer = dyub1;
16902 buff_info[0].offset = 0;
16903 buff_info[0].range = 256;
16904 buff_info[1].buffer = dyub1;
16905 buff_info[1].offset = 256;
16906 buff_info[1].range = 512;
16907 buff_info[2].buffer = dyub2;
16908 buff_info[2].offset = 0;
16909 buff_info[2].range = 512;
16910
16911 VkWriteDescriptorSet descriptor_write;
16912 memset(&descriptor_write, 0, sizeof(descriptor_write));
16913 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16914 descriptor_write.dstSet = descriptor_set;
16915 descriptor_write.dstBinding = 0;
16916 descriptor_write.descriptorCount = BINDING_COUNT;
16917 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16918 descriptor_write.pBufferInfo = buff_info;
16919
16920 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16921
16922 BeginCommandBuffer();
16923
16924 // Create PSO to be used for draw-time errors below
16925 char const *vsSource = "#version 450\n"
16926 "\n"
16927 "out gl_PerVertex { \n"
16928 " vec4 gl_Position;\n"
16929 "};\n"
16930 "void main(){\n"
16931 " gl_Position = vec4(1);\n"
16932 "}\n";
16933 char const *fsSource = "#version 450\n"
16934 "\n"
16935 "layout(location=0) out vec4 x;\n"
16936 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
16937 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
16938 "void main(){\n"
16939 " x = vec4(bar1.y) + vec4(bar2.y);\n"
16940 "}\n";
16941 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16942 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16943 VkPipelineObj pipe(m_device);
16944 pipe.SetViewport(m_viewports);
16945 pipe.SetScissor(m_scissors);
16946 pipe.AddShader(&vs);
16947 pipe.AddShader(&fs);
16948 pipe.AddColorAttachment();
16949 pipe.CreateVKPipeline(pipeline_layout, renderPass());
16950
16951 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
16952 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
16953 // we used to have a bug in this case.
16954 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
16955 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
16956 &descriptor_set, BINDING_COUNT, dyn_off);
16957 Draw(1, 0, 0, 0);
16958 m_errorMonitor->VerifyNotFound();
16959
16960 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16961 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16962 vkFreeMemory(m_device->device(), mem1, NULL);
16963 vkFreeMemory(m_device->device(), mem2, NULL);
16964
16965 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
16966 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16967 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16968}
16969
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016970TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16971
16972 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16973 "mapping while using VK_WHOLE_SIZE does not cause access "
16974 "violations");
16975 VkResult err;
16976 uint8_t *pData;
16977 ASSERT_NO_FATAL_FAILURE(InitState());
16978
16979 VkDeviceMemory mem;
16980 VkMemoryRequirements mem_reqs;
16981 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016982 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016983 VkMemoryAllocateInfo alloc_info = {};
16984 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16985 alloc_info.pNext = NULL;
16986 alloc_info.memoryTypeIndex = 0;
16987
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016988 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016989 alloc_info.allocationSize = allocation_size;
16990
16991 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16992 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16993 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16994 if (!pass) {
16995 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16996 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16997 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16998 if (!pass) {
16999 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17000 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
17001 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17002 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17003 if (!pass) {
17004 return;
17005 }
17006 }
17007 }
17008
17009 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17010 ASSERT_VK_SUCCESS(err);
17011
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017012 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017013 m_errorMonitor->ExpectSuccess();
17014 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17015 ASSERT_VK_SUCCESS(err);
17016 VkMappedMemoryRange mmr = {};
17017 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17018 mmr.memory = mem;
17019 mmr.offset = 0;
17020 mmr.size = VK_WHOLE_SIZE;
17021 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17022 ASSERT_VK_SUCCESS(err);
17023 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17024 ASSERT_VK_SUCCESS(err);
17025 m_errorMonitor->VerifyNotFound();
17026 vkUnmapMemory(m_device->device(), mem);
17027
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017028 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017029 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017030 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017031 ASSERT_VK_SUCCESS(err);
17032 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17033 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017034 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017035 mmr.size = VK_WHOLE_SIZE;
17036 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17037 ASSERT_VK_SUCCESS(err);
17038 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17039 ASSERT_VK_SUCCESS(err);
17040 m_errorMonitor->VerifyNotFound();
17041 vkUnmapMemory(m_device->device(), mem);
17042
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017043 // Map with offset and size
17044 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017045 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017046 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017047 ASSERT_VK_SUCCESS(err);
17048 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17049 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017050 mmr.offset = 4 * atom_size;
17051 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017052 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17053 ASSERT_VK_SUCCESS(err);
17054 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17055 ASSERT_VK_SUCCESS(err);
17056 m_errorMonitor->VerifyNotFound();
17057 vkUnmapMemory(m_device->device(), mem);
17058
17059 // Map without offset and flush WHOLE_SIZE with two separate offsets
17060 m_errorMonitor->ExpectSuccess();
17061 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17062 ASSERT_VK_SUCCESS(err);
17063 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17064 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017065 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017066 mmr.size = VK_WHOLE_SIZE;
17067 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17068 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017069 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017070 mmr.size = VK_WHOLE_SIZE;
17071 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17072 ASSERT_VK_SUCCESS(err);
17073 m_errorMonitor->VerifyNotFound();
17074 vkUnmapMemory(m_device->device(), mem);
17075
17076 vkFreeMemory(m_device->device(), mem, NULL);
17077}
17078
17079// This is a positive test. We used to expect error in this case but spec now allows it
17080TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17081 m_errorMonitor->ExpectSuccess();
17082 vk_testing::Fence testFence;
17083 VkFenceCreateInfo fenceInfo = {};
17084 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17085 fenceInfo.pNext = NULL;
17086
17087 ASSERT_NO_FATAL_FAILURE(InitState());
17088 testFence.init(*m_device, fenceInfo);
17089 VkFence fences[1] = { testFence.handle() };
17090 VkResult result = vkResetFences(m_device->device(), 1, fences);
17091 ASSERT_VK_SUCCESS(result);
17092
17093 m_errorMonitor->VerifyNotFound();
17094}
17095
17096TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17097 m_errorMonitor->ExpectSuccess();
17098
17099 ASSERT_NO_FATAL_FAILURE(InitState());
17100 VkResult err;
17101
17102 // Record (empty!) command buffer that can be submitted multiple times
17103 // simultaneously.
17104 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17105 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
17106 m_commandBuffer->BeginCommandBuffer(&cbbi);
17107 m_commandBuffer->EndCommandBuffer();
17108
17109 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17110 VkFence fence;
17111 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17112 ASSERT_VK_SUCCESS(err);
17113
17114 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17115 VkSemaphore s1, s2;
17116 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17117 ASSERT_VK_SUCCESS(err);
17118 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17119 ASSERT_VK_SUCCESS(err);
17120
17121 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
17122 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
17123 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17124 ASSERT_VK_SUCCESS(err);
17125
17126 // Submit CB again, signaling s2.
17127 si.pSignalSemaphores = &s2;
17128 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17129 ASSERT_VK_SUCCESS(err);
17130
17131 // Wait for fence.
17132 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17133 ASSERT_VK_SUCCESS(err);
17134
17135 // CB is still in flight from second submission, but semaphore s1 is no
17136 // longer in flight. delete it.
17137 vkDestroySemaphore(m_device->device(), s1, nullptr);
17138
17139 m_errorMonitor->VerifyNotFound();
17140
17141 // Force device idle and clean up remaining objects
17142 vkDeviceWaitIdle(m_device->device());
17143 vkDestroySemaphore(m_device->device(), s2, nullptr);
17144 vkDestroyFence(m_device->device(), fence, nullptr);
17145}
17146
17147TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17148 m_errorMonitor->ExpectSuccess();
17149
17150 ASSERT_NO_FATAL_FAILURE(InitState());
17151 VkResult err;
17152
17153 // A fence created signaled
17154 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
17155 VkFence f1;
17156 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17157 ASSERT_VK_SUCCESS(err);
17158
17159 // A fence created not
17160 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17161 VkFence f2;
17162 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17163 ASSERT_VK_SUCCESS(err);
17164
17165 // Submit the unsignaled fence
17166 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
17167 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17168
17169 // Wait on both fences, with signaled first.
17170 VkFence fences[] = { f1, f2 };
17171 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17172
17173 // Should have both retired!
17174 vkDestroyFence(m_device->device(), f1, nullptr);
17175 vkDestroyFence(m_device->device(), f2, nullptr);
17176
17177 m_errorMonitor->VerifyNotFound();
17178}
17179
17180TEST_F(VkPositiveLayerTest, ValidUsage) {
17181 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
17182 "doesn't generate validation errors");
17183
17184 ASSERT_NO_FATAL_FAILURE(InitState());
17185
17186 m_errorMonitor->ExpectSuccess();
17187 // Verify that we can create a view with usage INPUT_ATTACHMENT
17188 VkImageObj image(m_device);
17189 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17190 ASSERT_TRUE(image.initialized());
17191 VkImageView imageView;
17192 VkImageViewCreateInfo ivci = {};
17193 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17194 ivci.image = image.handle();
17195 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17196 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17197 ivci.subresourceRange.layerCount = 1;
17198 ivci.subresourceRange.baseMipLevel = 0;
17199 ivci.subresourceRange.levelCount = 1;
17200 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17201
17202 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17203 m_errorMonitor->VerifyNotFound();
17204 vkDestroyImageView(m_device->device(), imageView, NULL);
17205}
17206
17207// This is a positive test. No failures are expected.
17208TEST_F(VkPositiveLayerTest, BindSparse) {
17209 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17210 "and then free the memory");
17211
17212 ASSERT_NO_FATAL_FAILURE(InitState());
17213
17214 auto index = m_device->graphics_queue_node_index_;
17215 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
17216 return;
17217
17218 m_errorMonitor->ExpectSuccess();
17219
17220 VkImage image;
17221 VkImageCreateInfo image_create_info = {};
17222 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17223 image_create_info.pNext = NULL;
17224 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17225 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17226 image_create_info.extent.width = 64;
17227 image_create_info.extent.height = 64;
17228 image_create_info.extent.depth = 1;
17229 image_create_info.mipLevels = 1;
17230 image_create_info.arrayLayers = 1;
17231 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17232 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17233 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17234 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17235 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17236 ASSERT_VK_SUCCESS(err);
17237
17238 VkMemoryRequirements memory_reqs;
17239 VkDeviceMemory memory_one, memory_two;
17240 bool pass;
17241 VkMemoryAllocateInfo memory_info = {};
17242 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17243 memory_info.pNext = NULL;
17244 memory_info.allocationSize = 0;
17245 memory_info.memoryTypeIndex = 0;
17246 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17247 // Find an image big enough to allow sparse mapping of 2 memory regions
17248 // Increase the image size until it is at least twice the
17249 // size of the required alignment, to ensure we can bind both
17250 // allocated memory blocks to the image on aligned offsets.
17251 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17252 vkDestroyImage(m_device->device(), image, nullptr);
17253 image_create_info.extent.width *= 2;
17254 image_create_info.extent.height *= 2;
17255 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17256 ASSERT_VK_SUCCESS(err);
17257 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17258 }
17259 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17260 // at the end of the first
17261 memory_info.allocationSize = memory_reqs.alignment;
17262 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17263 ASSERT_TRUE(pass);
17264 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17265 ASSERT_VK_SUCCESS(err);
17266 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17267 ASSERT_VK_SUCCESS(err);
17268 VkSparseMemoryBind binds[2];
17269 binds[0].flags = 0;
17270 binds[0].memory = memory_one;
17271 binds[0].memoryOffset = 0;
17272 binds[0].resourceOffset = 0;
17273 binds[0].size = memory_info.allocationSize;
17274 binds[1].flags = 0;
17275 binds[1].memory = memory_two;
17276 binds[1].memoryOffset = 0;
17277 binds[1].resourceOffset = memory_info.allocationSize;
17278 binds[1].size = memory_info.allocationSize;
17279
17280 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17281 opaqueBindInfo.image = image;
17282 opaqueBindInfo.bindCount = 2;
17283 opaqueBindInfo.pBinds = binds;
17284
17285 VkFence fence = VK_NULL_HANDLE;
17286 VkBindSparseInfo bindSparseInfo = {};
17287 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17288 bindSparseInfo.imageOpaqueBindCount = 1;
17289 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17290
17291 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17292 vkQueueWaitIdle(m_device->m_queue);
17293 vkDestroyImage(m_device->device(), image, NULL);
17294 vkFreeMemory(m_device->device(), memory_one, NULL);
17295 vkFreeMemory(m_device->device(), memory_two, NULL);
17296 m_errorMonitor->VerifyNotFound();
17297}
17298
17299TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
17300 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
17301 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17302 "the command buffer has prior knowledge of that "
17303 "attachment's layout.");
17304
17305 m_errorMonitor->ExpectSuccess();
17306
17307 ASSERT_NO_FATAL_FAILURE(InitState());
17308
17309 // A renderpass with one color attachment.
17310 VkAttachmentDescription attachment = { 0,
17311 VK_FORMAT_R8G8B8A8_UNORM,
17312 VK_SAMPLE_COUNT_1_BIT,
17313 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17314 VK_ATTACHMENT_STORE_OP_STORE,
17315 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17316 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17317 VK_IMAGE_LAYOUT_UNDEFINED,
17318 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17319
17320 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17321
17322 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17323
17324 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17325
17326 VkRenderPass rp;
17327 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17328 ASSERT_VK_SUCCESS(err);
17329
17330 // A compatible framebuffer.
17331 VkImageObj image(m_device);
17332 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17333 ASSERT_TRUE(image.initialized());
17334
17335 VkImageViewCreateInfo ivci = {
17336 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17337 nullptr,
17338 0,
17339 image.handle(),
17340 VK_IMAGE_VIEW_TYPE_2D,
17341 VK_FORMAT_R8G8B8A8_UNORM,
17342 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17343 VK_COMPONENT_SWIZZLE_IDENTITY },
17344 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17345 };
17346 VkImageView view;
17347 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17348 ASSERT_VK_SUCCESS(err);
17349
17350 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17351 VkFramebuffer fb;
17352 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17353 ASSERT_VK_SUCCESS(err);
17354
17355 // Record a single command buffer which uses this renderpass twice. The
17356 // bug is triggered at the beginning of the second renderpass, when the
17357 // command buffer already has a layout recorded for the attachment.
17358 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17359 BeginCommandBuffer();
17360 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17361 vkCmdEndRenderPass(m_commandBuffer->handle());
17362 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17363
17364 m_errorMonitor->VerifyNotFound();
17365
17366 vkCmdEndRenderPass(m_commandBuffer->handle());
17367 EndCommandBuffer();
17368
17369 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17370 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17371 vkDestroyImageView(m_device->device(), view, nullptr);
17372}
17373
17374TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17375 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17376 "command buffer, bind them together, then destroy "
17377 "command pool and framebuffer and verify there are no "
17378 "errors.");
17379
17380 m_errorMonitor->ExpectSuccess();
17381
17382 ASSERT_NO_FATAL_FAILURE(InitState());
17383
17384 // A renderpass with one color attachment.
17385 VkAttachmentDescription attachment = { 0,
17386 VK_FORMAT_R8G8B8A8_UNORM,
17387 VK_SAMPLE_COUNT_1_BIT,
17388 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17389 VK_ATTACHMENT_STORE_OP_STORE,
17390 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17391 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17392 VK_IMAGE_LAYOUT_UNDEFINED,
17393 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17394
17395 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17396
17397 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17398
17399 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17400
17401 VkRenderPass rp;
17402 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17403 ASSERT_VK_SUCCESS(err);
17404
17405 // A compatible framebuffer.
17406 VkImageObj image(m_device);
17407 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17408 ASSERT_TRUE(image.initialized());
17409
17410 VkImageViewCreateInfo ivci = {
17411 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17412 nullptr,
17413 0,
17414 image.handle(),
17415 VK_IMAGE_VIEW_TYPE_2D,
17416 VK_FORMAT_R8G8B8A8_UNORM,
17417 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17418 VK_COMPONENT_SWIZZLE_IDENTITY },
17419 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17420 };
17421 VkImageView view;
17422 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17423 ASSERT_VK_SUCCESS(err);
17424
17425 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17426 VkFramebuffer fb;
17427 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17428 ASSERT_VK_SUCCESS(err);
17429
17430 // Explicitly create a command buffer to bind the FB to so that we can then
17431 // destroy the command pool in order to implicitly free command buffer
17432 VkCommandPool command_pool;
17433 VkCommandPoolCreateInfo pool_create_info{};
17434 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17435 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17436 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17437 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17438
17439 VkCommandBuffer command_buffer;
17440 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17441 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17442 command_buffer_allocate_info.commandPool = command_pool;
17443 command_buffer_allocate_info.commandBufferCount = 1;
17444 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17445 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17446
17447 // Begin our cmd buffer with renderpass using our framebuffer
17448 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17449 VkCommandBufferBeginInfo begin_info{};
17450 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17451 vkBeginCommandBuffer(command_buffer, &begin_info);
17452
17453 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17454 vkCmdEndRenderPass(command_buffer);
17455 vkEndCommandBuffer(command_buffer);
17456 vkDestroyImageView(m_device->device(), view, nullptr);
17457 // Destroy command pool to implicitly free command buffer
17458 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17459 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17460 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17461 m_errorMonitor->VerifyNotFound();
17462}
17463
17464TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17465 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17466 "transitions for the first subpass");
17467
17468 m_errorMonitor->ExpectSuccess();
17469
17470 ASSERT_NO_FATAL_FAILURE(InitState());
17471
17472 // A renderpass with one color attachment.
17473 VkAttachmentDescription attachment = { 0,
17474 VK_FORMAT_R8G8B8A8_UNORM,
17475 VK_SAMPLE_COUNT_1_BIT,
17476 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17477 VK_ATTACHMENT_STORE_OP_STORE,
17478 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17479 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17480 VK_IMAGE_LAYOUT_UNDEFINED,
17481 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17482
17483 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17484
17485 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17486
17487 VkSubpassDependency dep = { 0,
17488 0,
17489 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17490 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17491 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17492 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17493 VK_DEPENDENCY_BY_REGION_BIT };
17494
17495 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17496
17497 VkResult err;
17498 VkRenderPass rp;
17499 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17500 ASSERT_VK_SUCCESS(err);
17501
17502 // A compatible framebuffer.
17503 VkImageObj image(m_device);
17504 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17505 ASSERT_TRUE(image.initialized());
17506
17507 VkImageViewCreateInfo ivci = {
17508 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17509 nullptr,
17510 0,
17511 image.handle(),
17512 VK_IMAGE_VIEW_TYPE_2D,
17513 VK_FORMAT_R8G8B8A8_UNORM,
17514 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17515 VK_COMPONENT_SWIZZLE_IDENTITY },
17516 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17517 };
17518 VkImageView view;
17519 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17520 ASSERT_VK_SUCCESS(err);
17521
17522 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17523 VkFramebuffer fb;
17524 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17525 ASSERT_VK_SUCCESS(err);
17526
17527 // Record a single command buffer which issues a pipeline barrier w/
17528 // image memory barrier for the attachment. This detects the previously
17529 // missing tracking of the subpass layout by throwing a validation error
17530 // if it doesn't occur.
17531 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17532 BeginCommandBuffer();
17533 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17534
17535 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17536 nullptr,
17537 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17538 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17539 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17540 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17541 VK_QUEUE_FAMILY_IGNORED,
17542 VK_QUEUE_FAMILY_IGNORED,
17543 image.handle(),
17544 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17545 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17546 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17547 &imb);
17548
17549 vkCmdEndRenderPass(m_commandBuffer->handle());
17550 m_errorMonitor->VerifyNotFound();
17551 EndCommandBuffer();
17552
17553 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17554 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17555 vkDestroyImageView(m_device->device(), view, nullptr);
17556}
17557
17558TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17559 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17560 "is used as a depth/stencil framebuffer attachment, the "
17561 "aspectMask is ignored and both depth and stencil image "
17562 "subresources are used.");
17563
17564 VkFormatProperties format_properties;
17565 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17566 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17567 return;
17568 }
17569
17570 m_errorMonitor->ExpectSuccess();
17571
17572 ASSERT_NO_FATAL_FAILURE(InitState());
17573
17574 VkAttachmentDescription attachment = { 0,
17575 VK_FORMAT_D32_SFLOAT_S8_UINT,
17576 VK_SAMPLE_COUNT_1_BIT,
17577 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17578 VK_ATTACHMENT_STORE_OP_STORE,
17579 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17580 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17581 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17582 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17583
17584 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17585
17586 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17587
17588 VkSubpassDependency dep = { 0,
17589 0,
17590 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17591 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17592 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17593 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17594 VK_DEPENDENCY_BY_REGION_BIT};
17595
17596 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17597
17598 VkResult err;
17599 VkRenderPass rp;
17600 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17601 ASSERT_VK_SUCCESS(err);
17602
17603 VkImageObj image(m_device);
17604 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17605 0x26, // usage
17606 VK_IMAGE_TILING_OPTIMAL, 0);
17607 ASSERT_TRUE(image.initialized());
17608 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17609
17610 VkImageViewCreateInfo ivci = {
17611 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17612 nullptr,
17613 0,
17614 image.handle(),
17615 VK_IMAGE_VIEW_TYPE_2D,
17616 VK_FORMAT_D32_SFLOAT_S8_UINT,
17617 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17618 { 0x2, 0, 1, 0, 1 },
17619 };
17620 VkImageView view;
17621 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17622 ASSERT_VK_SUCCESS(err);
17623
17624 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17625 VkFramebuffer fb;
17626 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17627 ASSERT_VK_SUCCESS(err);
17628
17629 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17630 BeginCommandBuffer();
17631 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17632
17633 VkImageMemoryBarrier imb = {};
17634 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17635 imb.pNext = nullptr;
17636 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17637 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17638 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17639 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17640 imb.srcQueueFamilyIndex = 0;
17641 imb.dstQueueFamilyIndex = 0;
17642 imb.image = image.handle();
17643 imb.subresourceRange.aspectMask = 0x6;
17644 imb.subresourceRange.baseMipLevel = 0;
17645 imb.subresourceRange.levelCount = 0x1;
17646 imb.subresourceRange.baseArrayLayer = 0;
17647 imb.subresourceRange.layerCount = 0x1;
17648
17649 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17650 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17651 &imb);
17652
17653 vkCmdEndRenderPass(m_commandBuffer->handle());
17654 EndCommandBuffer();
17655 QueueCommandBuffer(false);
17656 m_errorMonitor->VerifyNotFound();
17657
17658 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17659 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17660 vkDestroyImageView(m_device->device(), view, nullptr);
17661}
17662
17663TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17664 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17665 "errors, when an attachment reference is "
17666 "VK_ATTACHMENT_UNUSED");
17667
17668 m_errorMonitor->ExpectSuccess();
17669
17670 ASSERT_NO_FATAL_FAILURE(InitState());
17671
17672 // A renderpass with no attachments
17673 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17674
17675 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17676
17677 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17678
17679 VkRenderPass rp;
17680 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17681 ASSERT_VK_SUCCESS(err);
17682
17683 // A compatible framebuffer.
17684 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17685 VkFramebuffer fb;
17686 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17687 ASSERT_VK_SUCCESS(err);
17688
17689 // Record a command buffer which just begins and ends the renderpass. The
17690 // bug manifests in BeginRenderPass.
17691 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17692 BeginCommandBuffer();
17693 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17694 vkCmdEndRenderPass(m_commandBuffer->handle());
17695 m_errorMonitor->VerifyNotFound();
17696 EndCommandBuffer();
17697
17698 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17699 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17700}
17701
17702// This is a positive test. No errors are expected.
17703TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17704 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17705 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17706 VkResult result = VK_SUCCESS;
17707 VkImageFormatProperties formatProps;
17708 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17709 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17710 &formatProps);
17711 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17712 return;
17713 }
17714
17715 ASSERT_NO_FATAL_FAILURE(InitState());
17716 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17717 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17718 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17719 VkAttachmentDescription att = {};
17720 VkAttachmentReference ref = {};
17721 att.format = depth_stencil_fmt;
17722 att.samples = VK_SAMPLE_COUNT_1_BIT;
17723 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17724 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17725 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17726 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17727 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17728 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17729
17730 VkClearValue clear;
17731 clear.depthStencil.depth = 1.0;
17732 clear.depthStencil.stencil = 0;
17733 ref.attachment = 0;
17734 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17735
17736 VkSubpassDescription subpass = {};
17737 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17738 subpass.flags = 0;
17739 subpass.inputAttachmentCount = 0;
17740 subpass.pInputAttachments = NULL;
17741 subpass.colorAttachmentCount = 0;
17742 subpass.pColorAttachments = NULL;
17743 subpass.pResolveAttachments = NULL;
17744 subpass.pDepthStencilAttachment = &ref;
17745 subpass.preserveAttachmentCount = 0;
17746 subpass.pPreserveAttachments = NULL;
17747
17748 VkRenderPass rp;
17749 VkRenderPassCreateInfo rp_info = {};
17750 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17751 rp_info.attachmentCount = 1;
17752 rp_info.pAttachments = &att;
17753 rp_info.subpassCount = 1;
17754 rp_info.pSubpasses = &subpass;
17755 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17756 ASSERT_VK_SUCCESS(result);
17757
17758 VkImageView *depthView = m_depthStencil->BindInfo();
17759 VkFramebufferCreateInfo fb_info = {};
17760 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17761 fb_info.pNext = NULL;
17762 fb_info.renderPass = rp;
17763 fb_info.attachmentCount = 1;
17764 fb_info.pAttachments = depthView;
17765 fb_info.width = 100;
17766 fb_info.height = 100;
17767 fb_info.layers = 1;
17768 VkFramebuffer fb;
17769 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17770 ASSERT_VK_SUCCESS(result);
17771
17772 VkRenderPassBeginInfo rpbinfo = {};
17773 rpbinfo.clearValueCount = 1;
17774 rpbinfo.pClearValues = &clear;
17775 rpbinfo.pNext = NULL;
17776 rpbinfo.renderPass = rp;
17777 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17778 rpbinfo.renderArea.extent.width = 100;
17779 rpbinfo.renderArea.extent.height = 100;
17780 rpbinfo.renderArea.offset.x = 0;
17781 rpbinfo.renderArea.offset.y = 0;
17782 rpbinfo.framebuffer = fb;
17783
17784 VkFence fence = {};
17785 VkFenceCreateInfo fence_ci = {};
17786 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17787 fence_ci.pNext = nullptr;
17788 fence_ci.flags = 0;
17789 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17790 ASSERT_VK_SUCCESS(result);
17791
17792 m_commandBuffer->BeginCommandBuffer();
17793 m_commandBuffer->BeginRenderPass(rpbinfo);
17794 m_commandBuffer->EndRenderPass();
17795 m_commandBuffer->EndCommandBuffer();
17796 m_commandBuffer->QueueCommandBuffer(fence);
17797
17798 VkImageObj destImage(m_device);
17799 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17800 VK_IMAGE_TILING_OPTIMAL, 0);
17801 VkImageMemoryBarrier barrier = {};
17802 VkImageSubresourceRange range;
17803 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17804 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17805 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17806 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17807 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17808 barrier.image = m_depthStencil->handle();
17809 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17810 range.baseMipLevel = 0;
17811 range.levelCount = 1;
17812 range.baseArrayLayer = 0;
17813 range.layerCount = 1;
17814 barrier.subresourceRange = range;
17815 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17816 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17817 cmdbuf.BeginCommandBuffer();
17818 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17819 &barrier);
17820 barrier.srcAccessMask = 0;
17821 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17822 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17823 barrier.image = destImage.handle();
17824 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17825 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17826 &barrier);
17827 VkImageCopy cregion;
17828 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17829 cregion.srcSubresource.mipLevel = 0;
17830 cregion.srcSubresource.baseArrayLayer = 0;
17831 cregion.srcSubresource.layerCount = 1;
17832 cregion.srcOffset.x = 0;
17833 cregion.srcOffset.y = 0;
17834 cregion.srcOffset.z = 0;
17835 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17836 cregion.dstSubresource.mipLevel = 0;
17837 cregion.dstSubresource.baseArrayLayer = 0;
17838 cregion.dstSubresource.layerCount = 1;
17839 cregion.dstOffset.x = 0;
17840 cregion.dstOffset.y = 0;
17841 cregion.dstOffset.z = 0;
17842 cregion.extent.width = 100;
17843 cregion.extent.height = 100;
17844 cregion.extent.depth = 1;
17845 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17846 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17847 cmdbuf.EndCommandBuffer();
17848
17849 VkSubmitInfo submit_info;
17850 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17851 submit_info.pNext = NULL;
17852 submit_info.waitSemaphoreCount = 0;
17853 submit_info.pWaitSemaphores = NULL;
17854 submit_info.pWaitDstStageMask = NULL;
17855 submit_info.commandBufferCount = 1;
17856 submit_info.pCommandBuffers = &cmdbuf.handle();
17857 submit_info.signalSemaphoreCount = 0;
17858 submit_info.pSignalSemaphores = NULL;
17859
17860 m_errorMonitor->ExpectSuccess();
17861 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17862 m_errorMonitor->VerifyNotFound();
17863
17864 vkQueueWaitIdle(m_device->m_queue);
17865 vkDestroyFence(m_device->device(), fence, nullptr);
17866 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17867 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17868}
17869
17870// This is a positive test. No errors should be generated.
17871TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17872 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17873
17874 m_errorMonitor->ExpectSuccess();
17875 ASSERT_NO_FATAL_FAILURE(InitState());
17876
17877 VkEvent event;
17878 VkEventCreateInfo event_create_info{};
17879 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17880 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17881
17882 VkCommandPool command_pool;
17883 VkCommandPoolCreateInfo pool_create_info{};
17884 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17885 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17886 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17887 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17888
17889 VkCommandBuffer command_buffer;
17890 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17891 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17892 command_buffer_allocate_info.commandPool = command_pool;
17893 command_buffer_allocate_info.commandBufferCount = 1;
17894 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17895 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17896
17897 VkQueue queue = VK_NULL_HANDLE;
17898 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17899
17900 {
17901 VkCommandBufferBeginInfo begin_info{};
17902 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17903 vkBeginCommandBuffer(command_buffer, &begin_info);
17904
17905 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17906 nullptr, 0, nullptr);
17907 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17908 vkEndCommandBuffer(command_buffer);
17909 }
17910 {
17911 VkSubmitInfo submit_info{};
17912 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17913 submit_info.commandBufferCount = 1;
17914 submit_info.pCommandBuffers = &command_buffer;
17915 submit_info.signalSemaphoreCount = 0;
17916 submit_info.pSignalSemaphores = nullptr;
17917 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17918 }
17919 { vkSetEvent(m_device->device(), event); }
17920
17921 vkQueueWaitIdle(queue);
17922
17923 vkDestroyEvent(m_device->device(), event, nullptr);
17924 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17925 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17926
17927 m_errorMonitor->VerifyNotFound();
17928}
17929// This is a positive test. No errors should be generated.
17930TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17931 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17932
17933 ASSERT_NO_FATAL_FAILURE(InitState());
17934 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17935 return;
17936
17937 m_errorMonitor->ExpectSuccess();
17938
17939 VkQueryPool query_pool;
17940 VkQueryPoolCreateInfo query_pool_create_info{};
17941 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17942 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17943 query_pool_create_info.queryCount = 1;
17944 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17945
17946 VkCommandPool command_pool;
17947 VkCommandPoolCreateInfo pool_create_info{};
17948 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17949 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17950 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17951 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17952
17953 VkCommandBuffer command_buffer;
17954 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17955 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17956 command_buffer_allocate_info.commandPool = command_pool;
17957 command_buffer_allocate_info.commandBufferCount = 1;
17958 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17959 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17960
17961 VkCommandBuffer secondary_command_buffer;
17962 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17963 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17964
17965 VkQueue queue = VK_NULL_HANDLE;
17966 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17967
17968 uint32_t qfi = 0;
17969 VkBufferCreateInfo buff_create_info = {};
17970 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17971 buff_create_info.size = 1024;
17972 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17973 buff_create_info.queueFamilyIndexCount = 1;
17974 buff_create_info.pQueueFamilyIndices = &qfi;
17975
17976 VkResult err;
17977 VkBuffer buffer;
17978 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17979 ASSERT_VK_SUCCESS(err);
17980 VkMemoryAllocateInfo mem_alloc = {};
17981 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17982 mem_alloc.pNext = NULL;
17983 mem_alloc.allocationSize = 1024;
17984 mem_alloc.memoryTypeIndex = 0;
17985
17986 VkMemoryRequirements memReqs;
17987 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17988 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17989 if (!pass) {
17990 vkDestroyBuffer(m_device->device(), buffer, NULL);
17991 return;
17992 }
17993
17994 VkDeviceMemory mem;
17995 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17996 ASSERT_VK_SUCCESS(err);
17997 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17998 ASSERT_VK_SUCCESS(err);
17999
18000 VkCommandBufferInheritanceInfo hinfo = {};
18001 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18002 hinfo.renderPass = VK_NULL_HANDLE;
18003 hinfo.subpass = 0;
18004 hinfo.framebuffer = VK_NULL_HANDLE;
18005 hinfo.occlusionQueryEnable = VK_FALSE;
18006 hinfo.queryFlags = 0;
18007 hinfo.pipelineStatistics = 0;
18008
18009 {
18010 VkCommandBufferBeginInfo begin_info{};
18011 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18012 begin_info.pInheritanceInfo = &hinfo;
18013 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18014
18015 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18016 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18017
18018 vkEndCommandBuffer(secondary_command_buffer);
18019
18020 begin_info.pInheritanceInfo = nullptr;
18021 vkBeginCommandBuffer(command_buffer, &begin_info);
18022
18023 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18024 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18025
18026 vkEndCommandBuffer(command_buffer);
18027 }
18028 {
18029 VkSubmitInfo submit_info{};
18030 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18031 submit_info.commandBufferCount = 1;
18032 submit_info.pCommandBuffers = &command_buffer;
18033 submit_info.signalSemaphoreCount = 0;
18034 submit_info.pSignalSemaphores = nullptr;
18035 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18036 }
18037
18038 vkQueueWaitIdle(queue);
18039
18040 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18041 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18042 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18043 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18044 vkDestroyBuffer(m_device->device(), buffer, NULL);
18045 vkFreeMemory(m_device->device(), mem, NULL);
18046
18047 m_errorMonitor->VerifyNotFound();
18048}
18049
18050// This is a positive test. No errors should be generated.
18051TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18052 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
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 VkQueryPool query_pool;
18061 VkQueryPoolCreateInfo query_pool_create_info{};
18062 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18063 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18064 query_pool_create_info.queryCount = 1;
18065 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18066
18067 VkCommandPool command_pool;
18068 VkCommandPoolCreateInfo pool_create_info{};
18069 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18070 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18071 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18072 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18073
18074 VkCommandBuffer command_buffer[2];
18075 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18076 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18077 command_buffer_allocate_info.commandPool = command_pool;
18078 command_buffer_allocate_info.commandBufferCount = 2;
18079 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18080 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18081
18082 VkQueue queue = VK_NULL_HANDLE;
18083 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18084
18085 uint32_t qfi = 0;
18086 VkBufferCreateInfo buff_create_info = {};
18087 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18088 buff_create_info.size = 1024;
18089 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18090 buff_create_info.queueFamilyIndexCount = 1;
18091 buff_create_info.pQueueFamilyIndices = &qfi;
18092
18093 VkResult err;
18094 VkBuffer buffer;
18095 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18096 ASSERT_VK_SUCCESS(err);
18097 VkMemoryAllocateInfo mem_alloc = {};
18098 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18099 mem_alloc.pNext = NULL;
18100 mem_alloc.allocationSize = 1024;
18101 mem_alloc.memoryTypeIndex = 0;
18102
18103 VkMemoryRequirements memReqs;
18104 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18105 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18106 if (!pass) {
18107 vkDestroyBuffer(m_device->device(), buffer, NULL);
18108 return;
18109 }
18110
18111 VkDeviceMemory mem;
18112 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18113 ASSERT_VK_SUCCESS(err);
18114 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18115 ASSERT_VK_SUCCESS(err);
18116
18117 {
18118 VkCommandBufferBeginInfo begin_info{};
18119 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18120 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18121
18122 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18123 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18124
18125 vkEndCommandBuffer(command_buffer[0]);
18126
18127 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18128
18129 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18130
18131 vkEndCommandBuffer(command_buffer[1]);
18132 }
18133 {
18134 VkSubmitInfo submit_info{};
18135 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18136 submit_info.commandBufferCount = 2;
18137 submit_info.pCommandBuffers = command_buffer;
18138 submit_info.signalSemaphoreCount = 0;
18139 submit_info.pSignalSemaphores = nullptr;
18140 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18141 }
18142
18143 vkQueueWaitIdle(queue);
18144
18145 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18146 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18147 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18148 vkDestroyBuffer(m_device->device(), buffer, NULL);
18149 vkFreeMemory(m_device->device(), mem, NULL);
18150
18151 m_errorMonitor->VerifyNotFound();
18152}
18153
Tony Barbourc46924f2016-11-04 11:49:52 -060018154TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018155 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18156
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018157 ASSERT_NO_FATAL_FAILURE(InitState());
18158 VkEvent event;
18159 VkEventCreateInfo event_create_info{};
18160 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18161 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18162
18163 VkCommandPool command_pool;
18164 VkCommandPoolCreateInfo pool_create_info{};
18165 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18166 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18167 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18168 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18169
18170 VkCommandBuffer command_buffer;
18171 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18172 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18173 command_buffer_allocate_info.commandPool = command_pool;
18174 command_buffer_allocate_info.commandBufferCount = 1;
18175 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18176 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18177
18178 VkQueue queue = VK_NULL_HANDLE;
18179 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18180
18181 {
18182 VkCommandBufferBeginInfo begin_info{};
18183 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18184 vkBeginCommandBuffer(command_buffer, &begin_info);
18185
18186 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018187 vkEndCommandBuffer(command_buffer);
18188 }
18189 {
18190 VkSubmitInfo submit_info{};
18191 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18192 submit_info.commandBufferCount = 1;
18193 submit_info.pCommandBuffers = &command_buffer;
18194 submit_info.signalSemaphoreCount = 0;
18195 submit_info.pSignalSemaphores = nullptr;
18196 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18197 }
18198 {
18199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
18200 "command buffer.");
18201 vkSetEvent(m_device->device(), event);
18202 m_errorMonitor->VerifyFound();
18203 }
18204
18205 vkQueueWaitIdle(queue);
18206
18207 vkDestroyEvent(m_device->device(), event, nullptr);
18208 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18209 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18210}
18211
18212// This is a positive test. No errors should be generated.
18213TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
18214 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
18215 "run through a Submit & WaitForFences cycle 3 times. This "
18216 "previously revealed a bug so running this positive test "
18217 "to prevent a regression.");
18218 m_errorMonitor->ExpectSuccess();
18219
18220 ASSERT_NO_FATAL_FAILURE(InitState());
18221 VkQueue queue = VK_NULL_HANDLE;
18222 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18223
18224 static const uint32_t NUM_OBJECTS = 2;
18225 static const uint32_t NUM_FRAMES = 3;
18226 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18227 VkFence fences[NUM_OBJECTS] = {};
18228
18229 VkCommandPool cmd_pool;
18230 VkCommandPoolCreateInfo cmd_pool_ci = {};
18231 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18232 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18233 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18234 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18235 ASSERT_VK_SUCCESS(err);
18236
18237 VkCommandBufferAllocateInfo cmd_buf_info = {};
18238 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18239 cmd_buf_info.commandPool = cmd_pool;
18240 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18241 cmd_buf_info.commandBufferCount = 1;
18242
18243 VkFenceCreateInfo fence_ci = {};
18244 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18245 fence_ci.pNext = nullptr;
18246 fence_ci.flags = 0;
18247
18248 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18249 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18250 ASSERT_VK_SUCCESS(err);
18251 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18252 ASSERT_VK_SUCCESS(err);
18253 }
18254
18255 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18256 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18257 // Create empty cmd buffer
18258 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18259 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18260
18261 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18262 ASSERT_VK_SUCCESS(err);
18263 err = vkEndCommandBuffer(cmd_buffers[obj]);
18264 ASSERT_VK_SUCCESS(err);
18265
18266 VkSubmitInfo submit_info = {};
18267 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18268 submit_info.commandBufferCount = 1;
18269 submit_info.pCommandBuffers = &cmd_buffers[obj];
18270 // Submit cmd buffer and wait for fence
18271 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18272 ASSERT_VK_SUCCESS(err);
18273 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18274 ASSERT_VK_SUCCESS(err);
18275 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18276 ASSERT_VK_SUCCESS(err);
18277 }
18278 }
18279 m_errorMonitor->VerifyNotFound();
18280 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18281 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18282 vkDestroyFence(m_device->device(), fences[i], nullptr);
18283 }
18284}
18285// This is a positive test. No errors should be generated.
18286TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
18287
18288 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18289 "submitted on separate queues followed by a QueueWaitIdle.");
18290
18291 ASSERT_NO_FATAL_FAILURE(InitState());
18292 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18293 return;
18294
18295 m_errorMonitor->ExpectSuccess();
18296
18297 VkSemaphore semaphore;
18298 VkSemaphoreCreateInfo semaphore_create_info{};
18299 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18300 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18301
18302 VkCommandPool command_pool;
18303 VkCommandPoolCreateInfo pool_create_info{};
18304 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18305 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18306 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18307 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18308
18309 VkCommandBuffer command_buffer[2];
18310 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18311 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18312 command_buffer_allocate_info.commandPool = command_pool;
18313 command_buffer_allocate_info.commandBufferCount = 2;
18314 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18315 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18316
18317 VkQueue queue = VK_NULL_HANDLE;
18318 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18319
18320 {
18321 VkCommandBufferBeginInfo begin_info{};
18322 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18323 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18324
18325 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18326 nullptr, 0, nullptr, 0, nullptr);
18327
18328 VkViewport viewport{};
18329 viewport.maxDepth = 1.0f;
18330 viewport.minDepth = 0.0f;
18331 viewport.width = 512;
18332 viewport.height = 512;
18333 viewport.x = 0;
18334 viewport.y = 0;
18335 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18336 vkEndCommandBuffer(command_buffer[0]);
18337 }
18338 {
18339 VkCommandBufferBeginInfo begin_info{};
18340 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18341 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18342
18343 VkViewport viewport{};
18344 viewport.maxDepth = 1.0f;
18345 viewport.minDepth = 0.0f;
18346 viewport.width = 512;
18347 viewport.height = 512;
18348 viewport.x = 0;
18349 viewport.y = 0;
18350 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18351 vkEndCommandBuffer(command_buffer[1]);
18352 }
18353 {
18354 VkSubmitInfo submit_info{};
18355 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18356 submit_info.commandBufferCount = 1;
18357 submit_info.pCommandBuffers = &command_buffer[0];
18358 submit_info.signalSemaphoreCount = 1;
18359 submit_info.pSignalSemaphores = &semaphore;
18360 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18361 }
18362 {
18363 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18364 VkSubmitInfo submit_info{};
18365 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18366 submit_info.commandBufferCount = 1;
18367 submit_info.pCommandBuffers = &command_buffer[1];
18368 submit_info.waitSemaphoreCount = 1;
18369 submit_info.pWaitSemaphores = &semaphore;
18370 submit_info.pWaitDstStageMask = flags;
18371 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18372 }
18373
18374 vkQueueWaitIdle(m_device->m_queue);
18375
18376 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18377 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18378 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18379
18380 m_errorMonitor->VerifyNotFound();
18381}
18382
18383// This is a positive test. No errors should be generated.
18384TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18385
18386 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18387 "submitted on separate queues, the second having a fence"
18388 "followed by a QueueWaitIdle.");
18389
18390 ASSERT_NO_FATAL_FAILURE(InitState());
18391 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18392 return;
18393
18394 m_errorMonitor->ExpectSuccess();
18395
18396 VkFence fence;
18397 VkFenceCreateInfo fence_create_info{};
18398 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18399 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18400
18401 VkSemaphore semaphore;
18402 VkSemaphoreCreateInfo semaphore_create_info{};
18403 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18404 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18405
18406 VkCommandPool command_pool;
18407 VkCommandPoolCreateInfo pool_create_info{};
18408 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18409 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18410 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18411 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18412
18413 VkCommandBuffer command_buffer[2];
18414 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18415 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18416 command_buffer_allocate_info.commandPool = command_pool;
18417 command_buffer_allocate_info.commandBufferCount = 2;
18418 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18419 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18420
18421 VkQueue queue = VK_NULL_HANDLE;
18422 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18423
18424 {
18425 VkCommandBufferBeginInfo begin_info{};
18426 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18427 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18428
18429 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18430 nullptr, 0, nullptr, 0, nullptr);
18431
18432 VkViewport viewport{};
18433 viewport.maxDepth = 1.0f;
18434 viewport.minDepth = 0.0f;
18435 viewport.width = 512;
18436 viewport.height = 512;
18437 viewport.x = 0;
18438 viewport.y = 0;
18439 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18440 vkEndCommandBuffer(command_buffer[0]);
18441 }
18442 {
18443 VkCommandBufferBeginInfo begin_info{};
18444 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18445 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18446
18447 VkViewport viewport{};
18448 viewport.maxDepth = 1.0f;
18449 viewport.minDepth = 0.0f;
18450 viewport.width = 512;
18451 viewport.height = 512;
18452 viewport.x = 0;
18453 viewport.y = 0;
18454 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18455 vkEndCommandBuffer(command_buffer[1]);
18456 }
18457 {
18458 VkSubmitInfo submit_info{};
18459 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18460 submit_info.commandBufferCount = 1;
18461 submit_info.pCommandBuffers = &command_buffer[0];
18462 submit_info.signalSemaphoreCount = 1;
18463 submit_info.pSignalSemaphores = &semaphore;
18464 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18465 }
18466 {
18467 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18468 VkSubmitInfo submit_info{};
18469 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18470 submit_info.commandBufferCount = 1;
18471 submit_info.pCommandBuffers = &command_buffer[1];
18472 submit_info.waitSemaphoreCount = 1;
18473 submit_info.pWaitSemaphores = &semaphore;
18474 submit_info.pWaitDstStageMask = flags;
18475 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18476 }
18477
18478 vkQueueWaitIdle(m_device->m_queue);
18479
18480 vkDestroyFence(m_device->device(), fence, nullptr);
18481 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18482 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18483 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18484
18485 m_errorMonitor->VerifyNotFound();
18486}
18487
18488// This is a positive test. No errors should be generated.
18489TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18490
18491 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18492 "submitted on separate queues, the second having a fence"
18493 "followed by two consecutive WaitForFences calls on the same fence.");
18494
18495 ASSERT_NO_FATAL_FAILURE(InitState());
18496 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18497 return;
18498
18499 m_errorMonitor->ExpectSuccess();
18500
18501 VkFence fence;
18502 VkFenceCreateInfo fence_create_info{};
18503 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18504 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18505
18506 VkSemaphore semaphore;
18507 VkSemaphoreCreateInfo semaphore_create_info{};
18508 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18509 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18510
18511 VkCommandPool command_pool;
18512 VkCommandPoolCreateInfo pool_create_info{};
18513 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18514 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18515 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18516 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18517
18518 VkCommandBuffer command_buffer[2];
18519 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18520 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18521 command_buffer_allocate_info.commandPool = command_pool;
18522 command_buffer_allocate_info.commandBufferCount = 2;
18523 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18524 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18525
18526 VkQueue queue = VK_NULL_HANDLE;
18527 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18528
18529 {
18530 VkCommandBufferBeginInfo begin_info{};
18531 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18532 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18533
18534 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18535 nullptr, 0, nullptr, 0, nullptr);
18536
18537 VkViewport viewport{};
18538 viewport.maxDepth = 1.0f;
18539 viewport.minDepth = 0.0f;
18540 viewport.width = 512;
18541 viewport.height = 512;
18542 viewport.x = 0;
18543 viewport.y = 0;
18544 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18545 vkEndCommandBuffer(command_buffer[0]);
18546 }
18547 {
18548 VkCommandBufferBeginInfo begin_info{};
18549 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18550 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18551
18552 VkViewport viewport{};
18553 viewport.maxDepth = 1.0f;
18554 viewport.minDepth = 0.0f;
18555 viewport.width = 512;
18556 viewport.height = 512;
18557 viewport.x = 0;
18558 viewport.y = 0;
18559 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18560 vkEndCommandBuffer(command_buffer[1]);
18561 }
18562 {
18563 VkSubmitInfo submit_info{};
18564 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18565 submit_info.commandBufferCount = 1;
18566 submit_info.pCommandBuffers = &command_buffer[0];
18567 submit_info.signalSemaphoreCount = 1;
18568 submit_info.pSignalSemaphores = &semaphore;
18569 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18570 }
18571 {
18572 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18573 VkSubmitInfo submit_info{};
18574 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18575 submit_info.commandBufferCount = 1;
18576 submit_info.pCommandBuffers = &command_buffer[1];
18577 submit_info.waitSemaphoreCount = 1;
18578 submit_info.pWaitSemaphores = &semaphore;
18579 submit_info.pWaitDstStageMask = flags;
18580 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18581 }
18582
18583 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18584 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18585
18586 vkDestroyFence(m_device->device(), fence, nullptr);
18587 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18588 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18589 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18590
18591 m_errorMonitor->VerifyNotFound();
18592}
18593
18594TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18595
18596 ASSERT_NO_FATAL_FAILURE(InitState());
18597 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18598 printf("Test requires two queues, skipping\n");
18599 return;
18600 }
18601
18602 VkResult err;
18603
18604 m_errorMonitor->ExpectSuccess();
18605
18606 VkQueue q0 = m_device->m_queue;
18607 VkQueue q1 = nullptr;
18608 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18609 ASSERT_NE(q1, nullptr);
18610
18611 // An (empty) command buffer. We must have work in the first submission --
18612 // the layer treats unfenced work differently from fenced work.
18613 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18614 VkCommandPool pool;
18615 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18616 ASSERT_VK_SUCCESS(err);
18617 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18618 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18619 VkCommandBuffer cb;
18620 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18621 ASSERT_VK_SUCCESS(err);
18622 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18623 err = vkBeginCommandBuffer(cb, &cbbi);
18624 ASSERT_VK_SUCCESS(err);
18625 err = vkEndCommandBuffer(cb);
18626 ASSERT_VK_SUCCESS(err);
18627
18628 // A semaphore
18629 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18630 VkSemaphore s;
18631 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18632 ASSERT_VK_SUCCESS(err);
18633
18634 // First submission, to q0
18635 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18636
18637 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18638 ASSERT_VK_SUCCESS(err);
18639
18640 // Second submission, to q1, waiting on s
18641 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18642 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18643
18644 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18645 ASSERT_VK_SUCCESS(err);
18646
18647 // Wait for q0 idle
18648 err = vkQueueWaitIdle(q0);
18649 ASSERT_VK_SUCCESS(err);
18650
18651 // Command buffer should have been completed (it was on q0); reset the pool.
18652 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18653
18654 m_errorMonitor->VerifyNotFound();
18655
18656 // Force device completely idle and clean up resources
18657 vkDeviceWaitIdle(m_device->device());
18658 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18659 vkDestroySemaphore(m_device->device(), s, nullptr);
18660}
18661
18662// This is a positive test. No errors should be generated.
18663TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18664
18665 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18666 "submitted on separate queues, the second having a fence, "
18667 "followed by a WaitForFences call.");
18668
18669 ASSERT_NO_FATAL_FAILURE(InitState());
18670 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18671 return;
18672
18673 m_errorMonitor->ExpectSuccess();
18674
18675 ASSERT_NO_FATAL_FAILURE(InitState());
18676 VkFence fence;
18677 VkFenceCreateInfo fence_create_info{};
18678 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18679 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18680
18681 VkSemaphore semaphore;
18682 VkSemaphoreCreateInfo semaphore_create_info{};
18683 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18684 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18685
18686 VkCommandPool command_pool;
18687 VkCommandPoolCreateInfo pool_create_info{};
18688 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18689 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18690 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18691 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18692
18693 VkCommandBuffer command_buffer[2];
18694 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18695 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18696 command_buffer_allocate_info.commandPool = command_pool;
18697 command_buffer_allocate_info.commandBufferCount = 2;
18698 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18699 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18700
18701 VkQueue queue = VK_NULL_HANDLE;
18702 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18703
18704 {
18705 VkCommandBufferBeginInfo begin_info{};
18706 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18707 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18708
18709 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18710 nullptr, 0, nullptr, 0, nullptr);
18711
18712 VkViewport viewport{};
18713 viewport.maxDepth = 1.0f;
18714 viewport.minDepth = 0.0f;
18715 viewport.width = 512;
18716 viewport.height = 512;
18717 viewport.x = 0;
18718 viewport.y = 0;
18719 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18720 vkEndCommandBuffer(command_buffer[0]);
18721 }
18722 {
18723 VkCommandBufferBeginInfo begin_info{};
18724 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18725 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18726
18727 VkViewport viewport{};
18728 viewport.maxDepth = 1.0f;
18729 viewport.minDepth = 0.0f;
18730 viewport.width = 512;
18731 viewport.height = 512;
18732 viewport.x = 0;
18733 viewport.y = 0;
18734 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18735 vkEndCommandBuffer(command_buffer[1]);
18736 }
18737 {
18738 VkSubmitInfo submit_info{};
18739 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18740 submit_info.commandBufferCount = 1;
18741 submit_info.pCommandBuffers = &command_buffer[0];
18742 submit_info.signalSemaphoreCount = 1;
18743 submit_info.pSignalSemaphores = &semaphore;
18744 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18745 }
18746 {
18747 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18748 VkSubmitInfo submit_info{};
18749 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18750 submit_info.commandBufferCount = 1;
18751 submit_info.pCommandBuffers = &command_buffer[1];
18752 submit_info.waitSemaphoreCount = 1;
18753 submit_info.pWaitSemaphores = &semaphore;
18754 submit_info.pWaitDstStageMask = flags;
18755 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18756 }
18757
18758 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18759
18760 vkDestroyFence(m_device->device(), fence, nullptr);
18761 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18762 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18763 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18764
18765 m_errorMonitor->VerifyNotFound();
18766}
18767
18768// This is a positive test. No errors should be generated.
18769TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18770
18771 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18772 "on the same queue, sharing a signal/wait semaphore, the "
18773 "second having a fence, "
18774 "followed by a WaitForFences call.");
18775
18776 m_errorMonitor->ExpectSuccess();
18777
18778 ASSERT_NO_FATAL_FAILURE(InitState());
18779 VkFence fence;
18780 VkFenceCreateInfo fence_create_info{};
18781 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18782 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18783
18784 VkSemaphore semaphore;
18785 VkSemaphoreCreateInfo semaphore_create_info{};
18786 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18787 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18788
18789 VkCommandPool command_pool;
18790 VkCommandPoolCreateInfo pool_create_info{};
18791 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18792 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18793 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18794 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18795
18796 VkCommandBuffer command_buffer[2];
18797 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18798 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18799 command_buffer_allocate_info.commandPool = command_pool;
18800 command_buffer_allocate_info.commandBufferCount = 2;
18801 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18802 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18803
18804 {
18805 VkCommandBufferBeginInfo begin_info{};
18806 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18807 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18808
18809 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18810 nullptr, 0, nullptr, 0, nullptr);
18811
18812 VkViewport viewport{};
18813 viewport.maxDepth = 1.0f;
18814 viewport.minDepth = 0.0f;
18815 viewport.width = 512;
18816 viewport.height = 512;
18817 viewport.x = 0;
18818 viewport.y = 0;
18819 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18820 vkEndCommandBuffer(command_buffer[0]);
18821 }
18822 {
18823 VkCommandBufferBeginInfo begin_info{};
18824 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18825 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18826
18827 VkViewport viewport{};
18828 viewport.maxDepth = 1.0f;
18829 viewport.minDepth = 0.0f;
18830 viewport.width = 512;
18831 viewport.height = 512;
18832 viewport.x = 0;
18833 viewport.y = 0;
18834 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18835 vkEndCommandBuffer(command_buffer[1]);
18836 }
18837 {
18838 VkSubmitInfo submit_info{};
18839 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18840 submit_info.commandBufferCount = 1;
18841 submit_info.pCommandBuffers = &command_buffer[0];
18842 submit_info.signalSemaphoreCount = 1;
18843 submit_info.pSignalSemaphores = &semaphore;
18844 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18845 }
18846 {
18847 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18848 VkSubmitInfo submit_info{};
18849 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18850 submit_info.commandBufferCount = 1;
18851 submit_info.pCommandBuffers = &command_buffer[1];
18852 submit_info.waitSemaphoreCount = 1;
18853 submit_info.pWaitSemaphores = &semaphore;
18854 submit_info.pWaitDstStageMask = flags;
18855 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18856 }
18857
18858 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18859
18860 vkDestroyFence(m_device->device(), fence, nullptr);
18861 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18862 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18863 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18864
18865 m_errorMonitor->VerifyNotFound();
18866}
18867
18868// This is a positive test. No errors should be generated.
18869TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18870
18871 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18872 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18873 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18874
18875 m_errorMonitor->ExpectSuccess();
18876
18877 ASSERT_NO_FATAL_FAILURE(InitState());
18878 VkFence fence;
18879 VkFenceCreateInfo fence_create_info{};
18880 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18881 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18882
18883 VkCommandPool command_pool;
18884 VkCommandPoolCreateInfo pool_create_info{};
18885 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18886 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18887 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18888 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18889
18890 VkCommandBuffer command_buffer[2];
18891 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18892 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18893 command_buffer_allocate_info.commandPool = command_pool;
18894 command_buffer_allocate_info.commandBufferCount = 2;
18895 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18896 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18897
18898 {
18899 VkCommandBufferBeginInfo begin_info{};
18900 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18901 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18902
18903 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18904 nullptr, 0, nullptr, 0, nullptr);
18905
18906 VkViewport viewport{};
18907 viewport.maxDepth = 1.0f;
18908 viewport.minDepth = 0.0f;
18909 viewport.width = 512;
18910 viewport.height = 512;
18911 viewport.x = 0;
18912 viewport.y = 0;
18913 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18914 vkEndCommandBuffer(command_buffer[0]);
18915 }
18916 {
18917 VkCommandBufferBeginInfo begin_info{};
18918 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18919 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18920
18921 VkViewport viewport{};
18922 viewport.maxDepth = 1.0f;
18923 viewport.minDepth = 0.0f;
18924 viewport.width = 512;
18925 viewport.height = 512;
18926 viewport.x = 0;
18927 viewport.y = 0;
18928 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18929 vkEndCommandBuffer(command_buffer[1]);
18930 }
18931 {
18932 VkSubmitInfo submit_info{};
18933 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18934 submit_info.commandBufferCount = 1;
18935 submit_info.pCommandBuffers = &command_buffer[0];
18936 submit_info.signalSemaphoreCount = 0;
18937 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18938 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18939 }
18940 {
18941 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18942 VkSubmitInfo submit_info{};
18943 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18944 submit_info.commandBufferCount = 1;
18945 submit_info.pCommandBuffers = &command_buffer[1];
18946 submit_info.waitSemaphoreCount = 0;
18947 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18948 submit_info.pWaitDstStageMask = flags;
18949 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18950 }
18951
18952 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18953
18954 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18955 ASSERT_VK_SUCCESS(err);
18956
18957 vkDestroyFence(m_device->device(), fence, nullptr);
18958 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18959 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18960
18961 m_errorMonitor->VerifyNotFound();
18962}
18963
18964// This is a positive test. No errors should be generated.
18965TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18966
18967 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18968 "on the same queue, the second having a fence, followed "
18969 "by a WaitForFences call.");
18970
18971 m_errorMonitor->ExpectSuccess();
18972
18973 ASSERT_NO_FATAL_FAILURE(InitState());
18974 VkFence fence;
18975 VkFenceCreateInfo fence_create_info{};
18976 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18977 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18978
18979 VkCommandPool command_pool;
18980 VkCommandPoolCreateInfo pool_create_info{};
18981 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18982 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18983 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18984 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18985
18986 VkCommandBuffer command_buffer[2];
18987 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18988 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18989 command_buffer_allocate_info.commandPool = command_pool;
18990 command_buffer_allocate_info.commandBufferCount = 2;
18991 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18992 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18993
18994 {
18995 VkCommandBufferBeginInfo begin_info{};
18996 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18997 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18998
18999 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19000 nullptr, 0, nullptr, 0, nullptr);
19001
19002 VkViewport viewport{};
19003 viewport.maxDepth = 1.0f;
19004 viewport.minDepth = 0.0f;
19005 viewport.width = 512;
19006 viewport.height = 512;
19007 viewport.x = 0;
19008 viewport.y = 0;
19009 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19010 vkEndCommandBuffer(command_buffer[0]);
19011 }
19012 {
19013 VkCommandBufferBeginInfo begin_info{};
19014 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19015 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19016
19017 VkViewport viewport{};
19018 viewport.maxDepth = 1.0f;
19019 viewport.minDepth = 0.0f;
19020 viewport.width = 512;
19021 viewport.height = 512;
19022 viewport.x = 0;
19023 viewport.y = 0;
19024 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19025 vkEndCommandBuffer(command_buffer[1]);
19026 }
19027 {
19028 VkSubmitInfo submit_info{};
19029 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19030 submit_info.commandBufferCount = 1;
19031 submit_info.pCommandBuffers = &command_buffer[0];
19032 submit_info.signalSemaphoreCount = 0;
19033 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19034 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19035 }
19036 {
19037 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19038 VkSubmitInfo submit_info{};
19039 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19040 submit_info.commandBufferCount = 1;
19041 submit_info.pCommandBuffers = &command_buffer[1];
19042 submit_info.waitSemaphoreCount = 0;
19043 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19044 submit_info.pWaitDstStageMask = flags;
19045 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19046 }
19047
19048 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19049
19050 vkDestroyFence(m_device->device(), fence, nullptr);
19051 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19052 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19053
19054 m_errorMonitor->VerifyNotFound();
19055}
19056
19057// This is a positive test. No errors should be generated.
19058TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
19059
19060 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
19061 "QueueSubmit call followed by a WaitForFences call.");
19062 ASSERT_NO_FATAL_FAILURE(InitState());
19063
19064 m_errorMonitor->ExpectSuccess();
19065
19066 VkFence fence;
19067 VkFenceCreateInfo fence_create_info{};
19068 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19069 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19070
19071 VkSemaphore semaphore;
19072 VkSemaphoreCreateInfo semaphore_create_info{};
19073 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19074 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19075
19076 VkCommandPool command_pool;
19077 VkCommandPoolCreateInfo pool_create_info{};
19078 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19079 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19080 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19081 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19082
19083 VkCommandBuffer command_buffer[2];
19084 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19085 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19086 command_buffer_allocate_info.commandPool = command_pool;
19087 command_buffer_allocate_info.commandBufferCount = 2;
19088 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19089 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19090
19091 {
19092 VkCommandBufferBeginInfo begin_info{};
19093 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19094 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19095
19096 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19097 nullptr, 0, nullptr, 0, nullptr);
19098
19099 VkViewport viewport{};
19100 viewport.maxDepth = 1.0f;
19101 viewport.minDepth = 0.0f;
19102 viewport.width = 512;
19103 viewport.height = 512;
19104 viewport.x = 0;
19105 viewport.y = 0;
19106 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19107 vkEndCommandBuffer(command_buffer[0]);
19108 }
19109 {
19110 VkCommandBufferBeginInfo begin_info{};
19111 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19112 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19113
19114 VkViewport viewport{};
19115 viewport.maxDepth = 1.0f;
19116 viewport.minDepth = 0.0f;
19117 viewport.width = 512;
19118 viewport.height = 512;
19119 viewport.x = 0;
19120 viewport.y = 0;
19121 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19122 vkEndCommandBuffer(command_buffer[1]);
19123 }
19124 {
19125 VkSubmitInfo submit_info[2];
19126 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19127
19128 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19129 submit_info[0].pNext = NULL;
19130 submit_info[0].commandBufferCount = 1;
19131 submit_info[0].pCommandBuffers = &command_buffer[0];
19132 submit_info[0].signalSemaphoreCount = 1;
19133 submit_info[0].pSignalSemaphores = &semaphore;
19134 submit_info[0].waitSemaphoreCount = 0;
19135 submit_info[0].pWaitSemaphores = NULL;
19136 submit_info[0].pWaitDstStageMask = 0;
19137
19138 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19139 submit_info[1].pNext = NULL;
19140 submit_info[1].commandBufferCount = 1;
19141 submit_info[1].pCommandBuffers = &command_buffer[1];
19142 submit_info[1].waitSemaphoreCount = 1;
19143 submit_info[1].pWaitSemaphores = &semaphore;
19144 submit_info[1].pWaitDstStageMask = flags;
19145 submit_info[1].signalSemaphoreCount = 0;
19146 submit_info[1].pSignalSemaphores = NULL;
19147 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19148 }
19149
19150 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19151
19152 vkDestroyFence(m_device->device(), fence, nullptr);
19153 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19154 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19155 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19156
19157 m_errorMonitor->VerifyNotFound();
19158}
19159
19160TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19161 m_errorMonitor->ExpectSuccess();
19162
19163 ASSERT_NO_FATAL_FAILURE(InitState());
19164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19165
19166 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
19167 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
19168
19169 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19170 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19171 m_errorMonitor->VerifyNotFound();
19172 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19173 m_errorMonitor->VerifyNotFound();
19174 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19175 m_errorMonitor->VerifyNotFound();
19176
19177 m_commandBuffer->EndCommandBuffer();
19178 m_errorMonitor->VerifyNotFound();
19179}
19180
19181TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
19182 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
19183 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19184 "has a valid layout, and a second subpass then uses a "
19185 "valid *READ_ONLY* layout.");
19186 m_errorMonitor->ExpectSuccess();
19187 ASSERT_NO_FATAL_FAILURE(InitState());
19188
19189 VkAttachmentReference attach[2] = {};
19190 attach[0].attachment = 0;
19191 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19192 attach[1].attachment = 0;
19193 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19194 VkSubpassDescription subpasses[2] = {};
19195 // First subpass clears DS attach on load
19196 subpasses[0].pDepthStencilAttachment = &attach[0];
19197 // 2nd subpass reads in DS as input attachment
19198 subpasses[1].inputAttachmentCount = 1;
19199 subpasses[1].pInputAttachments = &attach[1];
19200 VkAttachmentDescription attach_desc = {};
19201 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19202 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19203 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19204 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19205 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19206 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19207 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19208 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19209 VkRenderPassCreateInfo rpci = {};
19210 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19211 rpci.attachmentCount = 1;
19212 rpci.pAttachments = &attach_desc;
19213 rpci.subpassCount = 2;
19214 rpci.pSubpasses = subpasses;
19215
19216 // Now create RenderPass and verify no errors
19217 VkRenderPass rp;
19218 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19219 m_errorMonitor->VerifyNotFound();
19220
19221 vkDestroyRenderPass(m_device->device(), rp, NULL);
19222}
19223
19224TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
19225 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
19226 "as vertex attributes");
19227 m_errorMonitor->ExpectSuccess();
19228
19229 ASSERT_NO_FATAL_FAILURE(InitState());
19230 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19231
19232 VkVertexInputBindingDescription input_binding;
19233 memset(&input_binding, 0, sizeof(input_binding));
19234
19235 VkVertexInputAttributeDescription input_attribs[2];
19236 memset(input_attribs, 0, sizeof(input_attribs));
19237
19238 for (int i = 0; i < 2; i++) {
19239 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19240 input_attribs[i].location = i;
19241 }
19242
19243 char const *vsSource = "#version 450\n"
19244 "\n"
19245 "layout(location=0) in mat2x4 x;\n"
19246 "out gl_PerVertex {\n"
19247 " vec4 gl_Position;\n"
19248 "};\n"
19249 "void main(){\n"
19250 " gl_Position = x[0] + x[1];\n"
19251 "}\n";
19252 char const *fsSource = "#version 450\n"
19253 "\n"
19254 "layout(location=0) out vec4 color;\n"
19255 "void main(){\n"
19256 " color = vec4(1);\n"
19257 "}\n";
19258
19259 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19260 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19261
19262 VkPipelineObj pipe(m_device);
19263 pipe.AddColorAttachment();
19264 pipe.AddShader(&vs);
19265 pipe.AddShader(&fs);
19266
19267 pipe.AddVertexInputBindings(&input_binding, 1);
19268 pipe.AddVertexInputAttribs(input_attribs, 2);
19269
19270 VkDescriptorSetObj descriptorSet(m_device);
19271 descriptorSet.AppendDummy();
19272 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19273
19274 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19275
19276 /* expect success */
19277 m_errorMonitor->VerifyNotFound();
19278}
19279
19280TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19281 m_errorMonitor->ExpectSuccess();
19282
19283 ASSERT_NO_FATAL_FAILURE(InitState());
19284 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19285
19286 VkVertexInputBindingDescription input_binding;
19287 memset(&input_binding, 0, sizeof(input_binding));
19288
19289 VkVertexInputAttributeDescription input_attribs[2];
19290 memset(input_attribs, 0, sizeof(input_attribs));
19291
19292 for (int i = 0; i < 2; i++) {
19293 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19294 input_attribs[i].location = i;
19295 }
19296
19297 char const *vsSource = "#version 450\n"
19298 "\n"
19299 "layout(location=0) in vec4 x[2];\n"
19300 "out gl_PerVertex {\n"
19301 " vec4 gl_Position;\n"
19302 "};\n"
19303 "void main(){\n"
19304 " gl_Position = x[0] + x[1];\n"
19305 "}\n";
19306 char const *fsSource = "#version 450\n"
19307 "\n"
19308 "layout(location=0) out vec4 color;\n"
19309 "void main(){\n"
19310 " color = vec4(1);\n"
19311 "}\n";
19312
19313 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19314 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19315
19316 VkPipelineObj pipe(m_device);
19317 pipe.AddColorAttachment();
19318 pipe.AddShader(&vs);
19319 pipe.AddShader(&fs);
19320
19321 pipe.AddVertexInputBindings(&input_binding, 1);
19322 pipe.AddVertexInputAttribs(input_attribs, 2);
19323
19324 VkDescriptorSetObj descriptorSet(m_device);
19325 descriptorSet.AppendDummy();
19326 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19327
19328 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19329
19330 m_errorMonitor->VerifyNotFound();
19331}
19332
19333TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
19334 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
19335 "through multiple vertex shader inputs, each consuming a different "
19336 "subset of the components.");
19337 m_errorMonitor->ExpectSuccess();
19338
19339 ASSERT_NO_FATAL_FAILURE(InitState());
19340 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19341
19342 VkVertexInputBindingDescription input_binding;
19343 memset(&input_binding, 0, sizeof(input_binding));
19344
19345 VkVertexInputAttributeDescription input_attribs[3];
19346 memset(input_attribs, 0, sizeof(input_attribs));
19347
19348 for (int i = 0; i < 3; i++) {
19349 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19350 input_attribs[i].location = i;
19351 }
19352
19353 char const *vsSource = "#version 450\n"
19354 "\n"
19355 "layout(location=0) in vec4 x;\n"
19356 "layout(location=1) in vec3 y1;\n"
19357 "layout(location=1, component=3) in float y2;\n"
19358 "layout(location=2) in vec4 z;\n"
19359 "out gl_PerVertex {\n"
19360 " vec4 gl_Position;\n"
19361 "};\n"
19362 "void main(){\n"
19363 " gl_Position = x + vec4(y1, y2) + z;\n"
19364 "}\n";
19365 char const *fsSource = "#version 450\n"
19366 "\n"
19367 "layout(location=0) out vec4 color;\n"
19368 "void main(){\n"
19369 " color = vec4(1);\n"
19370 "}\n";
19371
19372 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19373 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19374
19375 VkPipelineObj pipe(m_device);
19376 pipe.AddColorAttachment();
19377 pipe.AddShader(&vs);
19378 pipe.AddShader(&fs);
19379
19380 pipe.AddVertexInputBindings(&input_binding, 1);
19381 pipe.AddVertexInputAttribs(input_attribs, 3);
19382
19383 VkDescriptorSetObj descriptorSet(m_device);
19384 descriptorSet.AppendDummy();
19385 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19386
19387 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19388
19389 m_errorMonitor->VerifyNotFound();
19390}
19391
19392TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19393 m_errorMonitor->ExpectSuccess();
19394
19395 ASSERT_NO_FATAL_FAILURE(InitState());
19396 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19397
19398 char const *vsSource = "#version 450\n"
19399 "out gl_PerVertex {\n"
19400 " vec4 gl_Position;\n"
19401 "};\n"
19402 "void main(){\n"
19403 " gl_Position = vec4(0);\n"
19404 "}\n";
19405 char const *fsSource = "#version 450\n"
19406 "\n"
19407 "layout(location=0) out vec4 color;\n"
19408 "void main(){\n"
19409 " color = vec4(1);\n"
19410 "}\n";
19411
19412 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19413 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19414
19415 VkPipelineObj pipe(m_device);
19416 pipe.AddColorAttachment();
19417 pipe.AddShader(&vs);
19418 pipe.AddShader(&fs);
19419
19420 VkDescriptorSetObj descriptorSet(m_device);
19421 descriptorSet.AppendDummy();
19422 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19423
19424 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19425
19426 m_errorMonitor->VerifyNotFound();
19427}
19428
19429TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19430 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19431 "set out in 14.1.3: fundamental type must match, and producer side must "
19432 "have at least as many components");
19433 m_errorMonitor->ExpectSuccess();
19434
19435 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19436
19437 ASSERT_NO_FATAL_FAILURE(InitState());
19438 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19439
19440 char const *vsSource = "#version 450\n"
19441 "out gl_PerVertex {\n"
19442 " vec4 gl_Position;\n"
19443 "};\n"
19444 "layout(location=0) out vec3 x;\n"
19445 "layout(location=1) out ivec3 y;\n"
19446 "layout(location=2) out vec3 z;\n"
19447 "void main(){\n"
19448 " gl_Position = vec4(0);\n"
19449 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19450 "}\n";
19451 char const *fsSource = "#version 450\n"
19452 "\n"
19453 "layout(location=0) out vec4 color;\n"
19454 "layout(location=0) in float x;\n"
19455 "layout(location=1) flat in int y;\n"
19456 "layout(location=2) in vec2 z;\n"
19457 "void main(){\n"
19458 " color = vec4(1 + x + y + z.x);\n"
19459 "}\n";
19460
19461 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19462 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19463
19464 VkPipelineObj pipe(m_device);
19465 pipe.AddColorAttachment();
19466 pipe.AddShader(&vs);
19467 pipe.AddShader(&fs);
19468
19469 VkDescriptorSetObj descriptorSet(m_device);
19470 descriptorSet.AppendDummy();
19471 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19472
19473 VkResult err = VK_SUCCESS;
19474 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19475 ASSERT_VK_SUCCESS(err);
19476
19477 m_errorMonitor->VerifyNotFound();
19478}
19479
19480TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19481 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19482 "passed between the TCS and TES stages");
19483 m_errorMonitor->ExpectSuccess();
19484
19485 ASSERT_NO_FATAL_FAILURE(InitState());
19486 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19487
19488 if (!m_device->phy().features().tessellationShader) {
19489 printf("Device does not support tessellation shaders; skipped.\n");
19490 return;
19491 }
19492
19493 char const *vsSource = "#version 450\n"
19494 "void main(){}\n";
19495 char const *tcsSource = "#version 450\n"
19496 "layout(location=0) out int x[];\n"
19497 "layout(vertices=3) out;\n"
19498 "void main(){\n"
19499 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19500 " gl_TessLevelInner[0] = 1;\n"
19501 " x[gl_InvocationID] = gl_InvocationID;\n"
19502 "}\n";
19503 char const *tesSource = "#version 450\n"
19504 "layout(triangles, equal_spacing, cw) in;\n"
19505 "layout(location=0) in int x[];\n"
19506 "out gl_PerVertex { vec4 gl_Position; };\n"
19507 "void main(){\n"
19508 " gl_Position.xyz = gl_TessCoord;\n"
19509 " gl_Position.w = x[0] + x[1] + x[2];\n"
19510 "}\n";
19511 char const *fsSource = "#version 450\n"
19512 "layout(location=0) out vec4 color;\n"
19513 "void main(){\n"
19514 " color = vec4(1);\n"
19515 "}\n";
19516
19517 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19518 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19519 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19520 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19521
19522 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19523 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19524
19525 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19526
19527 VkPipelineObj pipe(m_device);
19528 pipe.SetInputAssembly(&iasci);
19529 pipe.SetTessellation(&tsci);
19530 pipe.AddColorAttachment();
19531 pipe.AddShader(&vs);
19532 pipe.AddShader(&tcs);
19533 pipe.AddShader(&tes);
19534 pipe.AddShader(&fs);
19535
19536 VkDescriptorSetObj descriptorSet(m_device);
19537 descriptorSet.AppendDummy();
19538 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19539
19540 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19541
19542 m_errorMonitor->VerifyNotFound();
19543}
19544
19545TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19546 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19547 "interface block passed into the geometry shader. This "
19548 "is interesting because the 'extra' array level is not "
19549 "present on the member type, but on the block instance.");
19550 m_errorMonitor->ExpectSuccess();
19551
19552 ASSERT_NO_FATAL_FAILURE(InitState());
19553 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19554
19555 if (!m_device->phy().features().geometryShader) {
19556 printf("Device does not support geometry shaders; skipped.\n");
19557 return;
19558 }
19559
19560 char const *vsSource = "#version 450\n"
19561 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19562 "void main(){\n"
19563 " vs_out.x = vec4(1);\n"
19564 "}\n";
19565 char const *gsSource = "#version 450\n"
19566 "layout(triangles) in;\n"
19567 "layout(triangle_strip, max_vertices=3) out;\n"
19568 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19569 "out gl_PerVertex { vec4 gl_Position; };\n"
19570 "void main() {\n"
19571 " gl_Position = gs_in[0].x;\n"
19572 " EmitVertex();\n"
19573 "}\n";
19574 char const *fsSource = "#version 450\n"
19575 "layout(location=0) out vec4 color;\n"
19576 "void main(){\n"
19577 " color = vec4(1);\n"
19578 "}\n";
19579
19580 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19581 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19582 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19583
19584 VkPipelineObj pipe(m_device);
19585 pipe.AddColorAttachment();
19586 pipe.AddShader(&vs);
19587 pipe.AddShader(&gs);
19588 pipe.AddShader(&fs);
19589
19590 VkDescriptorSetObj descriptorSet(m_device);
19591 descriptorSet.AppendDummy();
19592 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19593
19594 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19595
19596 m_errorMonitor->VerifyNotFound();
19597}
19598
19599TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19600 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19601 "attributes. This is interesting because they consume multiple "
19602 "locations.");
19603 m_errorMonitor->ExpectSuccess();
19604
19605 ASSERT_NO_FATAL_FAILURE(InitState());
19606 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19607
19608 if (!m_device->phy().features().shaderFloat64) {
19609 printf("Device does not support 64bit vertex attributes; skipped.\n");
19610 return;
19611 }
19612
19613 VkVertexInputBindingDescription input_bindings[1];
19614 memset(input_bindings, 0, sizeof(input_bindings));
19615
19616 VkVertexInputAttributeDescription input_attribs[4];
19617 memset(input_attribs, 0, sizeof(input_attribs));
19618 input_attribs[0].location = 0;
19619 input_attribs[0].offset = 0;
19620 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19621 input_attribs[1].location = 2;
19622 input_attribs[1].offset = 32;
19623 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19624 input_attribs[2].location = 4;
19625 input_attribs[2].offset = 64;
19626 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19627 input_attribs[3].location = 6;
19628 input_attribs[3].offset = 96;
19629 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19630
19631 char const *vsSource = "#version 450\n"
19632 "\n"
19633 "layout(location=0) in dmat4 x;\n"
19634 "out gl_PerVertex {\n"
19635 " vec4 gl_Position;\n"
19636 "};\n"
19637 "void main(){\n"
19638 " gl_Position = vec4(x[0][0]);\n"
19639 "}\n";
19640 char const *fsSource = "#version 450\n"
19641 "\n"
19642 "layout(location=0) out vec4 color;\n"
19643 "void main(){\n"
19644 " color = vec4(1);\n"
19645 "}\n";
19646
19647 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19648 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19649
19650 VkPipelineObj pipe(m_device);
19651 pipe.AddColorAttachment();
19652 pipe.AddShader(&vs);
19653 pipe.AddShader(&fs);
19654
19655 pipe.AddVertexInputBindings(input_bindings, 1);
19656 pipe.AddVertexInputAttribs(input_attribs, 4);
19657
19658 VkDescriptorSetObj descriptorSet(m_device);
19659 descriptorSet.AppendDummy();
19660 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19661
19662 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19663
19664 m_errorMonitor->VerifyNotFound();
19665}
19666
19667TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19668 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19669 m_errorMonitor->ExpectSuccess();
19670
19671 ASSERT_NO_FATAL_FAILURE(InitState());
19672
19673 char const *vsSource = "#version 450\n"
19674 "\n"
19675 "out gl_PerVertex {\n"
19676 " vec4 gl_Position;\n"
19677 "};\n"
19678 "void main(){\n"
19679 " gl_Position = vec4(1);\n"
19680 "}\n";
19681 char const *fsSource = "#version 450\n"
19682 "\n"
19683 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19684 "layout(location=0) out vec4 color;\n"
19685 "void main() {\n"
19686 " color = subpassLoad(x);\n"
19687 "}\n";
19688
19689 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19690 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19691
19692 VkPipelineObj pipe(m_device);
19693 pipe.AddShader(&vs);
19694 pipe.AddShader(&fs);
19695 pipe.AddColorAttachment();
19696 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19697
19698 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19699 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19700 VkDescriptorSetLayout dsl;
19701 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19702 ASSERT_VK_SUCCESS(err);
19703
19704 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19705 VkPipelineLayout pl;
19706 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19707 ASSERT_VK_SUCCESS(err);
19708
19709 VkAttachmentDescription descs[2] = {
19710 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19711 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19712 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19713 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19714 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19715 };
19716 VkAttachmentReference color = {
19717 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19718 };
19719 VkAttachmentReference input = {
19720 1, VK_IMAGE_LAYOUT_GENERAL,
19721 };
19722
19723 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19724
19725 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19726 VkRenderPass rp;
19727 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19728 ASSERT_VK_SUCCESS(err);
19729
19730 // should be OK. would go wrong here if it's going to...
19731 pipe.CreateVKPipeline(pl, rp);
19732
19733 m_errorMonitor->VerifyNotFound();
19734
19735 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19736 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19737 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19738}
19739
19740TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19741 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19742 "descriptor-backed resource which is not provided, but the shader does not "
19743 "statically use it. This is interesting because it requires compute pipelines "
19744 "to have a proper descriptor use walk, which they didn't for some time.");
19745 m_errorMonitor->ExpectSuccess();
19746
19747 ASSERT_NO_FATAL_FAILURE(InitState());
19748
19749 char const *csSource = "#version 450\n"
19750 "\n"
19751 "layout(local_size_x=1) in;\n"
19752 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19753 "void main(){\n"
19754 " // x is not used.\n"
19755 "}\n";
19756
19757 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19758
19759 VkDescriptorSetObj descriptorSet(m_device);
19760 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19761
19762 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19763 nullptr,
19764 0,
19765 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19766 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19767 descriptorSet.GetPipelineLayout(),
19768 VK_NULL_HANDLE,
19769 -1 };
19770
19771 VkPipeline pipe;
19772 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19773
19774 m_errorMonitor->VerifyNotFound();
19775
19776 if (err == VK_SUCCESS) {
19777 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19778 }
19779}
19780
19781TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19782 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19783 "sampler portion of a combined image + sampler");
19784 m_errorMonitor->ExpectSuccess();
19785
19786 ASSERT_NO_FATAL_FAILURE(InitState());
19787
19788 VkDescriptorSetLayoutBinding bindings[] = {
19789 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19790 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19791 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19792 };
19793 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19794 VkDescriptorSetLayout dsl;
19795 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19796 ASSERT_VK_SUCCESS(err);
19797
19798 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19799 VkPipelineLayout pl;
19800 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19801 ASSERT_VK_SUCCESS(err);
19802
19803 char const *csSource = "#version 450\n"
19804 "\n"
19805 "layout(local_size_x=1) in;\n"
19806 "layout(set=0, binding=0) uniform sampler s;\n"
19807 "layout(set=0, binding=1) uniform texture2D t;\n"
19808 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19809 "void main() {\n"
19810 " x = texture(sampler2D(t, s), vec2(0));\n"
19811 "}\n";
19812 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19813
19814 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19815 nullptr,
19816 0,
19817 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19818 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19819 pl,
19820 VK_NULL_HANDLE,
19821 -1 };
19822
19823 VkPipeline pipe;
19824 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19825
19826 m_errorMonitor->VerifyNotFound();
19827
19828 if (err == VK_SUCCESS) {
19829 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19830 }
19831
19832 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19833 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19834}
19835
19836TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19837 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19838 "image portion of a combined image + sampler");
19839 m_errorMonitor->ExpectSuccess();
19840
19841 ASSERT_NO_FATAL_FAILURE(InitState());
19842
19843 VkDescriptorSetLayoutBinding bindings[] = {
19844 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19845 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19846 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19847 };
19848 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19849 VkDescriptorSetLayout dsl;
19850 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19851 ASSERT_VK_SUCCESS(err);
19852
19853 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19854 VkPipelineLayout pl;
19855 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19856 ASSERT_VK_SUCCESS(err);
19857
19858 char const *csSource = "#version 450\n"
19859 "\n"
19860 "layout(local_size_x=1) in;\n"
19861 "layout(set=0, binding=0) uniform texture2D t;\n"
19862 "layout(set=0, binding=1) uniform sampler s;\n"
19863 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19864 "void main() {\n"
19865 " x = texture(sampler2D(t, s), vec2(0));\n"
19866 "}\n";
19867 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19868
19869 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19870 nullptr,
19871 0,
19872 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19873 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19874 pl,
19875 VK_NULL_HANDLE,
19876 -1 };
19877
19878 VkPipeline pipe;
19879 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19880
19881 m_errorMonitor->VerifyNotFound();
19882
19883 if (err == VK_SUCCESS) {
19884 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19885 }
19886
19887 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19888 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19889}
19890
19891TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19892 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19893 "both the sampler and the image of a combined image+sampler "
19894 "but via separate variables");
19895 m_errorMonitor->ExpectSuccess();
19896
19897 ASSERT_NO_FATAL_FAILURE(InitState());
19898
19899 VkDescriptorSetLayoutBinding bindings[] = {
19900 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19901 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19902 };
19903 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19904 VkDescriptorSetLayout dsl;
19905 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19906 ASSERT_VK_SUCCESS(err);
19907
19908 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19909 VkPipelineLayout pl;
19910 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19911 ASSERT_VK_SUCCESS(err);
19912
19913 char const *csSource = "#version 450\n"
19914 "\n"
19915 "layout(local_size_x=1) in;\n"
19916 "layout(set=0, binding=0) uniform texture2D t;\n"
19917 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19918 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19919 "void main() {\n"
19920 " x = texture(sampler2D(t, s), vec2(0));\n"
19921 "}\n";
19922 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19923
19924 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19925 nullptr,
19926 0,
19927 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19928 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19929 pl,
19930 VK_NULL_HANDLE,
19931 -1 };
19932
19933 VkPipeline pipe;
19934 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19935
19936 m_errorMonitor->VerifyNotFound();
19937
19938 if (err == VK_SUCCESS) {
19939 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19940 }
19941
19942 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19943 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19944}
19945
19946TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19947 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19948
19949 ASSERT_NO_FATAL_FAILURE(InitState());
19950
19951 // Positive test to check parameter_validation and unique_objects support
19952 // for NV_dedicated_allocation
19953 uint32_t extension_count = 0;
19954 bool supports_nv_dedicated_allocation = false;
19955 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19956 ASSERT_VK_SUCCESS(err);
19957
19958 if (extension_count > 0) {
19959 std::vector<VkExtensionProperties> available_extensions(extension_count);
19960
19961 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19962 ASSERT_VK_SUCCESS(err);
19963
19964 for (const auto &extension_props : available_extensions) {
19965 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19966 supports_nv_dedicated_allocation = true;
19967 }
19968 }
19969 }
19970
19971 if (supports_nv_dedicated_allocation) {
19972 m_errorMonitor->ExpectSuccess();
19973
19974 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19975 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19976 dedicated_buffer_create_info.pNext = nullptr;
19977 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19978
19979 uint32_t queue_family_index = 0;
19980 VkBufferCreateInfo buffer_create_info = {};
19981 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19982 buffer_create_info.pNext = &dedicated_buffer_create_info;
19983 buffer_create_info.size = 1024;
19984 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19985 buffer_create_info.queueFamilyIndexCount = 1;
19986 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19987
19988 VkBuffer buffer;
19989 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19990 ASSERT_VK_SUCCESS(err);
19991
19992 VkMemoryRequirements memory_reqs;
19993 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19994
19995 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19996 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19997 dedicated_memory_info.pNext = nullptr;
19998 dedicated_memory_info.buffer = buffer;
19999 dedicated_memory_info.image = VK_NULL_HANDLE;
20000
20001 VkMemoryAllocateInfo memory_info = {};
20002 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20003 memory_info.pNext = &dedicated_memory_info;
20004 memory_info.allocationSize = memory_reqs.size;
20005
20006 bool pass;
20007 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20008 ASSERT_TRUE(pass);
20009
20010 VkDeviceMemory buffer_memory;
20011 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20012 ASSERT_VK_SUCCESS(err);
20013
20014 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20015 ASSERT_VK_SUCCESS(err);
20016
20017 vkDestroyBuffer(m_device->device(), buffer, NULL);
20018 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20019
20020 m_errorMonitor->VerifyNotFound();
20021 }
20022}
20023
20024TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20025 VkResult err;
20026
20027 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20028
20029 ASSERT_NO_FATAL_FAILURE(InitState());
20030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20031
20032 std::vector<const char *> device_extension_names;
20033 auto features = m_device->phy().features();
20034 // Artificially disable support for non-solid fill modes
20035 features.fillModeNonSolid = false;
20036 // The sacrificial device object
20037 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20038
20039 VkRenderpassObj render_pass(&test_device);
20040
20041 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20042 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20043 pipeline_layout_ci.setLayoutCount = 0;
20044 pipeline_layout_ci.pSetLayouts = NULL;
20045
20046 VkPipelineLayout pipeline_layout;
20047 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20048 ASSERT_VK_SUCCESS(err);
20049
20050 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20051 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20052 rs_ci.pNext = nullptr;
20053 rs_ci.lineWidth = 1.0f;
20054 rs_ci.rasterizerDiscardEnable = true;
20055
20056 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20057 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20058
20059 // Set polygonMode=FILL. No error is expected
20060 m_errorMonitor->ExpectSuccess();
20061 {
20062 VkPipelineObj pipe(&test_device);
20063 pipe.AddShader(&vs);
20064 pipe.AddShader(&fs);
20065 pipe.AddColorAttachment();
20066 // Set polygonMode to a good value
20067 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20068 pipe.SetRasterization(&rs_ci);
20069 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20070 }
20071 m_errorMonitor->VerifyNotFound();
20072
20073 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20074}
20075
20076TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20077 VkResult err;
20078 ASSERT_NO_FATAL_FAILURE(InitState());
20079 ASSERT_NO_FATAL_FAILURE(InitViewport());
20080 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20081
20082 VkPipelineLayout pipeline_layout;
20083 VkPushConstantRange pc_range = {};
20084 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20085 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20086 pipeline_layout_ci.pushConstantRangeCount = 1;
20087 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20088
20089 //
20090 // Check for invalid push constant ranges in pipeline layouts.
20091 //
20092 struct PipelineLayoutTestCase {
20093 VkPushConstantRange const range;
20094 char const *msg;
20095 };
20096
20097 // Check for overlapping ranges
20098 const uint32_t ranges_per_test = 5;
20099 struct OverlappingRangeTestCase {
20100 VkPushConstantRange const ranges[ranges_per_test];
20101 char const *msg;
20102 };
20103
20104 // Run some positive tests to make sure overlap checking in the layer is OK
20105 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
20106 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
20107 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
20108 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
20109 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
20110 "" },
20111 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
20112 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
20113 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
20114 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
20115 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
20116 "" } } };
20117 for (const auto &iter : overlapping_range_tests_pos) {
20118 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20119 m_errorMonitor->ExpectSuccess();
20120 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20121 m_errorMonitor->VerifyNotFound();
20122 if (VK_SUCCESS == err) {
20123 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20124 }
20125 }
20126
20127 //
20128 // CmdPushConstants tests
20129 //
20130 const uint8_t dummy_values[100] = {};
20131
20132 BeginCommandBuffer();
20133
20134 // positive overlapping range tests with cmd
20135 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
20136 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
20137 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
20138 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
20139 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
20140 } };
20141
20142 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20143 const VkPushConstantRange pc_range4[] = {
20144 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
20145 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
20146 };
20147
20148 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20149 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20150 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20151 ASSERT_VK_SUCCESS(err);
20152 for (const auto &iter : cmd_overlap_tests_pos) {
20153 m_errorMonitor->ExpectSuccess();
20154 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
20155 iter.range.size, dummy_values);
20156 m_errorMonitor->VerifyNotFound();
20157 }
20158 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20159
20160 EndCommandBuffer();
20161}
20162
20163
20164
20165
20166
20167
20168
20169#if 0 // A few devices have issues with this test so disabling for now
20170TEST_F(VkPositiveLayerTest, LongFenceChain)
20171{
20172 m_errorMonitor->ExpectSuccess();
20173
20174 ASSERT_NO_FATAL_FAILURE(InitState());
20175 VkResult err;
20176
20177 std::vector<VkFence> fences;
20178
20179 const int chainLength = 32768;
20180
20181 for (int i = 0; i < chainLength; i++) {
20182 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20183 VkFence fence;
20184 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20185 ASSERT_VK_SUCCESS(err);
20186
20187 fences.push_back(fence);
20188
20189 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20190 0, nullptr, 0, nullptr };
20191 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20192 ASSERT_VK_SUCCESS(err);
20193
20194 }
20195
20196 // BOOM, stack overflow.
20197 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20198
20199 for (auto fence : fences)
20200 vkDestroyFence(m_device->device(), fence, nullptr);
20201
20202 m_errorMonitor->VerifyNotFound();
20203}
20204#endif
20205
20206
Cody Northrop1242dfd2016-07-13 17:24:59 -060020207#if defined(ANDROID) && defined(VALIDATION_APK)
20208static bool initialized = false;
20209static bool active = false;
20210
20211// Convert Intents to argv
20212// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020213std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020214 std::vector<std::string> args;
20215 JavaVM &vm = *app.activity->vm;
20216 JNIEnv *p_env;
20217 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
20218 return args;
20219
20220 JNIEnv &env = *p_env;
20221 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020222 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020223 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020224 jmethodID get_string_extra_method =
20225 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020226 jvalue get_string_extra_args;
20227 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020228 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020229
20230 std::string args_str;
20231 if (extra_str) {
20232 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20233 args_str = extra_utf;
20234 env.ReleaseStringUTFChars(extra_str, extra_utf);
20235 env.DeleteLocalRef(extra_str);
20236 }
20237
20238 env.DeleteLocalRef(get_string_extra_args.l);
20239 env.DeleteLocalRef(intent);
20240 vm.DetachCurrentThread();
20241
20242 // split args_str
20243 std::stringstream ss(args_str);
20244 std::string arg;
20245 while (std::getline(ss, arg, ' ')) {
20246 if (!arg.empty())
20247 args.push_back(arg);
20248 }
20249
20250 return args;
20251}
20252
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020253static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020255static void processCommand(struct android_app *app, int32_t cmd) {
20256 switch (cmd) {
20257 case APP_CMD_INIT_WINDOW: {
20258 if (app->window) {
20259 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020260 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020261 break;
20262 }
20263 case APP_CMD_GAINED_FOCUS: {
20264 active = true;
20265 break;
20266 }
20267 case APP_CMD_LOST_FOCUS: {
20268 active = false;
20269 break;
20270 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020271 }
20272}
20273
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020274void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020275 app_dummy();
20276
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020277 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020278
20279 int vulkanSupport = InitVulkan();
20280 if (vulkanSupport == 0) {
20281 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20282 return;
20283 }
20284
20285 app->onAppCmd = processCommand;
20286 app->onInputEvent = processInput;
20287
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020288 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020289 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020290 struct android_poll_source *source;
20291 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020292 if (source) {
20293 source->process(app, source);
20294 }
20295
20296 if (app->destroyRequested != 0) {
20297 VkTestFramework::Finish();
20298 return;
20299 }
20300 }
20301
20302 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020303 // Use the following key to send arguments to gtest, i.e.
20304 // --es args "--gtest_filter=-VkLayerTest.foo"
20305 const char key[] = "args";
20306 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020307
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020308 std::string filter = "";
20309 if (args.size() > 0) {
20310 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20311 filter += args[0];
20312 } else {
20313 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20314 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020315
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020316 int argc = 2;
20317 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20318 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020319
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020320 // Route output to files until we can override the gtest output
20321 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20322 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020323
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020324 ::testing::InitGoogleTest(&argc, argv);
20325 VkTestFramework::InitArgs(&argc, argv);
20326 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020328 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020330 if (result != 0) {
20331 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20332 } else {
20333 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20334 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020335
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020336 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020337
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020338 fclose(stdout);
20339 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020340
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020341 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020342
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020343 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020344 }
20345 }
20346}
20347#endif
20348
Tony Barbour300a6082015-04-07 13:44:53 -060020349int main(int argc, char **argv) {
20350 int result;
20351
Cody Northrop8e54a402016-03-08 22:25:52 -070020352#ifdef ANDROID
20353 int vulkanSupport = InitVulkan();
20354 if (vulkanSupport == 0)
20355 return 1;
20356#endif
20357
Tony Barbour300a6082015-04-07 13:44:53 -060020358 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020359 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020360
20361 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20362
20363 result = RUN_ALL_TESTS();
20364
Tony Barbour6918cd52015-04-09 12:58:51 -060020365 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020366 return result;
20367}